__ctfe

Philippe Sigaud philippe.sigaud at gmail.com
Mon Oct 1 12:41:49 PDT 2012


On Mon, Oct 1, 2012 at 9:30 PM, Adam D. Ruppe <destructionator at gmail.com> wrote:
> On Monday, 1 October 2012 at 19:22:37 UTC, Philippe Sigaud wrote:
>>
>> Something I wanted to ask for a long time: is there any runtime speed
>> penalty in using __ctfe?
>
>
> No. What happens is when it goes to the compile the runtime code, __ctfe is
> a constant false, so then the optimizer can see it is obviously dead code
> and eliminate the branch entirely.

Cool.I feared it was a runtime-determined value, somehow.


> $ dmd test.d -c
> $ objdump --disassemble test.o
> Disassembly of section .text._D4test4testFZv:
>
> 00000000 <_D4test4testFZv>:
>    0:   55                      push   %ebp
>    1:   8b ec                   mov    %esp,%ebp
>    3:   f4                      hlt
>    4:   5d                      pop    %ebp
>    5:   c3                      ret
>
>
> Note that there's no trace of a compare, jmp, nor the nops from the dead
> ctfe branch.

OK, I'm sold.

Thanks!


More information about the Digitalmars-d mailing list