Bug 16474 – CTFE pow

Status
RESOLVED
Resolution
DUPLICATE
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-09-06T14:06:35Z
Last change time
2018-03-23T08:40:49Z
Assigned to
No Owner
Creator
Manu

Comments

Comment #0 by turkeyman — 2016-09-06T14:06:35Z
enum x = 2^^(1.0/10); Please, please, can we please have '^^' work at CTFE. It's been forever. I have so many stalled branches of various projects depending on this eventually being fixed. It's constantly blocking my work.
Comment #1 by uplink.coder — 2016-09-09T06:57:30Z
are 64bit floating point operations good enough for you ? (And anyone else) If so the fix is rather straight-forward.
Comment #2 by turkeyman — 2016-09-09T11:26:04Z
Sure, or reals, whatever precision the compiler does floating point constant folding would be fine.
Comment #3 by turkeyman — 2017-08-02T08:54:09Z
Come on... surely it's reasonable to expect all builtin operators should work at ctfe!! ;)
Comment #4 by uplink.coder — 2017-08-02T20:22:31Z
newCTFE is eventually going to fix that. and other compile-time floating-point issues as well.
Comment #5 by turkeyman — 2017-08-02T22:10:10Z
True, but that could still be a long way off, and this should have already been working like, 10 years ago... it'd be good to have a default fix in existing ctfe code.
Comment #6 by petar.p.kirov — 2017-08-05T21:13:53Z
Manu, you may be interested in trying LDC as it will soon support much more intrinsics at CTFE than dmd. For reference: https://github.com/ldc-developers/ldc/pull/2259 I'm not sure if specifically the pow operator is supported (though pow is supported as a function call).
Comment #7 by uplink.coder — 2017-08-05T21:50:22Z
(In reply to ZombineDev from comment #6) > Manu, you may be interested in trying LDC as it will soon support much more > intrinsics at CTFE than dmd. For reference: > https://github.com/ldc-developers/ldc/pull/2259 I'm not sure if specifically > the pow operator is supported (though pow is supported as a function call). Do they interface with the CTFE engine ? That'd be crazy :)
Comment #8 by petar.p.kirov — 2017-08-05T22:58:07Z
I don't think so, but see the PR for yourself ;)
Comment #9 by kinke — 2017-08-05T23:00:36Z
(In reply to uplink.coder from comment #7) > (In reply to ZombineDev from comment #6) > > Manu, you may be interested in trying LDC as it will soon support much more > > intrinsics at CTFE than dmd. For reference: > > https://github.com/ldc-developers/ldc/pull/2259 I'm not sure if specifically > > the pow operator is supported (though pow is supported as a function call). I started that work due to a recent ping of this issue and me accidentally noticing it. ;) So the pow operator is working with that PR for LDC; there a static assert in the last line of the test. > Do they interface with the CTFE engine ? > That'd be crazy :) I detect a few more key primitive functions (ldexp, isNaN, isInfinity, isFinite...) as builtins and forward to proper implementations in CTFloat. I also had to make std.math.exp2() CTFE-able for 80-bit reals by not using the inline assembly code for CTFE. DMD may need a few more builtins or CTFE-friendly Phobos implementations to get all of this working as well; I'll open a DMD PR for the ones required by LDC. So how does newCTFE interact with CTFloat at the moment? This is an important piece for cross-compilers. And is there an estimate for when newCTFE will land?
Comment #10 by uplink.coder — 2017-08-05T23:31:50Z
(In reply to kinke from comment #9) > > So how does newCTFE interact with CTFloat at the moment? This is an > important piece for cross-compilers. And is there an estimate for when > newCTFE will land? It does currently not use CTFloat at all. It only implements add, sub, mul and div and mod for floats/doubles. As well as float <=> double <=> long/int casts.
Comment #11 by kinke — 2017-08-06T00:56:17Z
(In reply to uplink.coder from comment #10) > (In reply to kinke from comment #9) > > > > So how does newCTFE interact with CTFloat at the moment? This is an > > important piece for cross-compilers. And is there an estimate for when > > newCTFE will land? > > It does currently not use CTFloat at all. > It only implements add, sub, mul and div and mod for floats/doubles. > As well as float <=> double <=> long/int casts. [Sorry about hijacking this issue.] Okay, but as guys clearly expect most of the math functionality to be available at CTFE too, newCTFE will eventually have to feature a similar system of CTFE builtins (ddmd.builtin). Currently, it plugs into function calls and tries to match the callee name in a map of mangled name => CTFE implementation. The builtins are required for functions whose source code isn't available for CTFE, such as compiler intrinsics, inline assembly and C library functions. So newCTFE discriminates between 32-bit float and 64-bit double but lacks support for real_t, as opposed to the current interpreter, which uses real_t exclusively (in RealExp). So the current floating-point builtin implementations expect host/compiler-specific real_t values, but extending those to allow for all 3 (float, double, real_t) should be straightforward. newCTFE should at some point support real_t and use it to represent target reals at compile-time. It's most likely the host real type, but it may also be a software implementation as custom type with overloaded binops (GDC afaik, possibly LDC at some point), with a specific size and alignment, and more advanced functionality provided by helper struct CTFloat.
Comment #12 by ibuclaw — 2017-12-12T22:56:57Z
This should probably be considered duplicate of issue 5227.
Comment #13 by bugzilla — 2018-03-23T08:40:49Z
*** This issue has been marked as a duplicate of issue 5227 ***