Bug 5943 – Power expression optimisation: 2^^unsigned ==> 1<<unsigned

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-05-07T05:27:00Z
Last change time
2013-06-20T03:20:28Z
Keywords
performance, pull
Assigned to
yebblies
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-05-07T05:27:50Z
Related to bug 5812 I think it's good to have an optimization of 2^^x ==> 1<<x when x is an unsigned integral or where the compiler can infer x to be a not negative integral: import std.math; // currently std.math is needed here int main(string[] args) { return 2 ^^ args.length; } Currently it generates: __Dmain comdat L0: push EAX push 2 mov EAX,0Ch[ESP] call near ptr _D3std4math12__T3powTiTkZ3powFNaNbNeikZk pop ECX ret
Comment #1 by yebblies — 2013-01-16T18:11:23Z
Comment #2 by github-bugzilla — 2013-06-20T02:35:23Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/50a484a60cc3794281a98c51346fc0dfacfc0f24 Fix Issue 5943 - Power expression optimisation: 2^^unsigned ==> 1<<unsigned https://github.com/D-Programming-Language/dmd/commit/1f7df6b2b0d0349570d58e92aa5cbceb4572f4c7 Merge pull request #1498 from yebblies/issue5943 Fix Issue 5943 - Power expression optimisation: 2^^unsigned ==> 1<<unsigned