Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
September 23, 2017 Why isn't there more if(__ctfe) in std.math ? | ||||
---|---|---|---|---|
| ||||
Hi, browsing trough phobos bugzilla I found a couple of open issues regarding CTFE and basic math functions ( Issue 4177, 5227). It looks to me that at least floor/ceil could by fixed by a simple: if (__ctfe) return simple_floor_impl(x); But that looks too easy and would surely be implemented already. So I would like to ask what the real problems are. Thanks, Juraj |
September 23, 2017 Re: Why isn't there more if(__ctfe) in std.math ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Juraj Mojzis | On Saturday, 23 September 2017 at 18:23:12 UTC, Juraj Mojzis wrote:
> Hi,
> browsing trough phobos bugzilla I found a couple of open issues regarding CTFE and basic math functions ( Issue 4177, 5227).
> It looks to me that at least floor/ceil could by fixed by a simple:
> if (__ctfe) return simple_floor_impl(x);
>
> But that looks too easy and would surely be implemented already. So I would like to ask what the real problems are.
>
> Thanks,
> Juraj
"if (__ctfe) {}" is a test happening at runtime. Both the if and the else branches got compiled, this implies:
- more code to cache
- slower code
just to allow CTFE.
CTFE rounding can be more simply done using cast(int), although for negative numbers the behavior is not the same.
|
September 24, 2017 Re: Why isn't there more if( ctfe) in std.math ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | user1234 wrote:
> "if (__ctfe) {}" is a test happening at runtime. Both the if and the else branches got compiled
nope. compiler knows about this special pseudovariable, and will not generate code neither for condition, nor for ctfe branch.
|
September 24, 2017 Re: Why isn't there more if(__ctfe) in std.math ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to user1234 | On 09/23/2017 11:46 PM, user1234 wrote:
> "if (__ctfe) {}" is a test happening at runtime. Both the if and the else branches got compiled, this implies:
> - more code to cache
> - slower code
> just to allow CTFE.
__ctfe is a constant, though. Any half-decent optimizer will throw away the path that's not taken. dmd does it even without the optimization flag -O.
|
Copyright © 1999-2021 by the D Language Foundation