View mode: basic / threaded / horizontal-split · Log in · Help
October 08, 2008
Re: Static argument optimization
Don wrote:
> Janderson wrote:
>> Vladimir Panteleev wrote:
>>> Hello,
>>>
>>> Often I encounter cases where I have a function taking some 
>>> arguments, and I'd like for the compiler to generate separate code 
>>> for the function when some of the arguments are known at compile 
>>> time. For example, consider this function:
>>>
>>> int pow(int n, int power)
>>> {
>>>     return power==0 ? 1 : n*pow(n, power-1);
>>> }
>>>
>>> I am looking for a way to make the function work at runtime, while 
>>> pow(n, 3) to be inlined as n*n*n, and pow(2, 3) to be precalculated 
>>> as 8. Is it possible to do this with some template trickery without 
>>> having to write three versions of the function? I know macros should 
>>> be able to do this in theory...
>>>
>>
>> Walter has talked about adding the keyword static in the past to 
>> generate templates ie:
>>
>> int pow(static int n, static int power)
>> {
>>
>> }
>>
>> I'm not sure if all the params needed to be constant for it to 
>> generate a template.  I can't see why your proposal wouldn't work with 
>> this.
>>
>> -Joel
> 
> No, they don't all need to be constant. The classic example is a regexp, 
> where the regexp itself is a literal, but the other parameters are all 
> variables.

That's good to know.  I was thinking that something like with regexpr 
all parameters would be marked as static and it would pick-and-choose 
which are actually static/constant based on the call.

Off-topic:

The game I'm working on was finally announced today 
http://www.leagueoflegends.com/

I'm excited because I can now talk about it :)
October 08, 2008
Re: Static argument optimization
Janderson escribió:
> Don wrote:
>> Janderson wrote:
>>> Vladimir Panteleev wrote:
>>>> Hello,
>>>>
>>>> Often I encounter cases where I have a function taking some 
>>>> arguments, and I'd like for the compiler to generate separate code 
>>>> for the function when some of the arguments are known at compile 
>>>> time. For example, consider this function:
>>>>
>>>> int pow(int n, int power)
>>>> {
>>>>     return power==0 ? 1 : n*pow(n, power-1);
>>>> }
>>>>
>>>> I am looking for a way to make the function work at runtime, while 
>>>> pow(n, 3) to be inlined as n*n*n, and pow(2, 3) to be precalculated 
>>>> as 8. Is it possible to do this with some template trickery without 
>>>> having to write three versions of the function? I know macros should 
>>>> be able to do this in theory...
>>>>
>>>
>>> Walter has talked about adding the keyword static in the past to 
>>> generate templates ie:
>>>
>>> int pow(static int n, static int power)
>>> {
>>>
>>> }
>>>
>>> I'm not sure if all the params needed to be constant for it to 
>>> generate a template.  I can't see why your proposal wouldn't work 
>>> with this.
>>>
>>> -Joel
>>
>> No, they don't all need to be constant. The classic example is a 
>> regexp, where the regexp itself is a literal, but the other parameters 
>> are all variables.
> 
> That's good to know.  I was thinking that something like with regexpr 
> all parameters would be marked as static and it would pick-and-choose 
> which are actually static/constant based on the call.
> 
> Off-topic:
> 
> The game I'm working on was finally announced today 
> http://www.leagueoflegends.com/
> 
> I'm excited because I can now talk about it :)

I play DOTA every lunch hour since a couple of months with some friends 
at work! I love it! I'll sure try it. :-)
October 08, 2008
Re: Static argument optimization
Ary Borenszweig wrote:
> Janderson escribió:
>>
>> I'm excited because I can now talk about it :)
> 
> I play DOTA every lunch hour since a couple of months with some friends 
> at work! I love it! I'll sure try it. :-)

That's good to hear :)

I'm surprised every day by how popular DotA is.  I'd never heard of it 
before I'd started at Riot 7months ago but instantly fell in love with LOL.

Apparently there where several popular songs written about DotA.

Wait, heres one I found on utube: http://www.youtube.com/watch?v=qXKd7uuehlw

Now all we need is some D songs :)

Oh and by the way another plug: Riotgames is still looking for a couple 
of talented experienced engineers with a good knowledge of C++/stl or 
Java.  I'm hoping that one day we'll get enough D engineers to write our 
next game in D.

http://www.riotgames.com/careers/

You can contact me or riotgames if your interested.

hohums at gmail dot com

-Joel
October 08, 2008
Re: Static argument optimization
On Wed, 08 Oct 2008 12:12:50 +0400, Janderson <ask@me.com> wrote:

> Ary Borenszweig wrote:
>> Janderson escribió:
>>>
>>> I'm excited because I can now talk about it :)
>>  I play DOTA every lunch hour since a couple of months with some  
>> friends at work! I love it! I'll sure try it. :-)
>
> That's good to hear :)
>
> I'm surprised every day by how popular DotA is.  I'd never heard of it  
> before I'd started at Riot 7months ago but instantly fell in love with  
> LOL.
>
> Apparently there where several popular songs written about DotA.
>
> Wait, heres one I found on utube:  
> http://www.youtube.com/watch?v=qXKd7uuehlw
>
> Now all we need is some D songs :)
>
> Oh and by the way another plug: Riotgames is still looking for a couple  
> of talented experienced engineers with a good knowledge of C++/stl or  
> Java.  I'm hoping that one day we'll get enough D engineers to write our  
> next game in D.
>
> http://www.riotgames.com/careers/
>
> You can contact me or riotgames if your interested.
>
> hohums at gmail dot com
>
> -Joel


Dota is really nice because it has incredibly high replayability and very  
good competitive gameplay. Yeah, I'm addicted too :)
I'll try LOL for sure!
October 15, 2008
Re: Static argument optimization
Janderson wrote:
> Ary Borenszweig wrote:
>> Janderson escribió:
>>>
>>> I'm excited because I can now talk about it :)
>>
>> I play DOTA every lunch hour since a couple of months with some 
>> friends at work! I love it! I'll sure try it. :-)
> 
> That's good to hear :)
> 
> I'm surprised every day by how popular DotA is.  I'd never heard of it 
> before I'd started at Riot 7months ago but instantly fell in love with LOL.
> 
> Apparently there where several popular songs written about DotA.
> 
> Wait, heres one I found on utube: 
> http://www.youtube.com/watch?v=qXKd7uuehlw
> 

Lol, a new DotA song by Basshunter, nice! :D
The previous one was: http://www.youtube.com/watch?v=0OzWIFX8M-Y , still
my favorite, although this new is still nice, it shows even some of "teh
micro".

> Now all we need is some D songs :)
> 
> Oh and by the way another plug: Riotgames is still looking for a couple 
> of talented experienced engineers with a good knowledge of C++/stl or 
> Java.  I'm hoping that one day we'll get enough D engineers to write our 
> next game in D.
> 
> http://www.riotgames.com/careers/
> 
> You can contact me or riotgames if your interested.
> 
> hohums at gmail dot com
> 
> -Joel

Cool... wish you were London based. :P


-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home