Bug 17483 – std.numeric.gcd cannot inline function

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-06-09T02:50:22Z
Last change time
2024-12-13T18:52:30Z
Assigned to
No Owner
Creator
Stanislav Blinov
Moved to GitHub: dmd#19259 →

Comments

Comment #0 by stanislav.blinov — 2017-06-09T02:50:22Z
Not only can it not be inlined, due to this function's implementation it turns into two function calls when called with const/immutable arguments. --- import std.traits : isIntegral, Unqual; pragma(inline, true) // pasted from std.numeric T gcd(T)(T a, T b) if (isIntegral!T) { static if (is(T == const) || is(T == immutable)) { return gcd!(Unqual!T)(a, b); } else version(DigitalMars) { static if (T.min < 0) { assert(a >= 0 && b >= 0); } while (b) { immutable t = b; b = a % b; a = t; } return a; } else { if (a == 0) return b; if (b == 0) return a; import core.bitop : bsf; import std.algorithm.mutation : swap; immutable uint shift = bsf(a | b); a >>= a.bsf; do { b >>= b.bsf; if (a > b) swap(a, b); b -= a; } while (b); return a << shift; } } void foo() { size_t a, b; gcd(a, b); } ---
Comment #1 by robert.schadek — 2024-12-13T18:52:30Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19259 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB