Bug 14936 – Dividing by a power of 2 slow on 32bit

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2015-08-19T16:51:31Z
Last change time
2020-07-22T23:59:06Z
Keywords
performance, pull
Assigned to
No Owner
Creator
Iain Buclaw

Comments

Comment #0 by ibuclaw — 2015-08-19T16:51:31Z
Noticed from results in: http://bugzilla.gdcproject.org/show_bug.cgi?id=180 """ for: dmd -O -inline -release tByte: 0.004,872 secs tShort: 0.006,896 secs tInt: 0.008,672 secs tLong: 0.036,864 secs """ Reduced test: long test(long l) { return l / 2; } Compiles down to: http://goo.gl/10dWmf long example.test(long): push %ebp mov %esp,%ebp push %eax xor %ecx,%ecx mov 0xc(%ebp),%edx push %ebx mov $0x2,%ebx mov 0x8(%ebp),%eax push %ecx push %ebx push %edx push %eax call __divdi3 ; <--- !!! add $0x10,%esp pop %ebx mov %ebp,%esp pop %ebp ret $0x8 add %al,(%eax) In comparison to GDC: http://goo.gl/XaBqdA push %ebx mov 12(%esp), %ebx xor %edx, %edx mov 8(%esp), %ecx mov %ebx, %eax shr $31, %eax add %ecx, %eax adc %ebx, %edx shrd $1, %edx, %eax pop %ebx sar %edx ret You can exchange '2' for '4', '8', '16'... '128' to observe the difference (optimization changes for 256 and higher).
Comment #1 by dlang-bot — 2020-07-22T10:53:52Z
@WalterBright created dlang/dmd pull request #11445 "fix Issue 14936 - Dividing by a power of 2 slow on 32bit" fixing this issue: - fix Issue 14936 - Dividing by a power of 2 slow on 32bit https://github.com/dlang/dmd/pull/11445
Comment #2 by dlang-bot — 2020-07-22T23:59:06Z
dlang/dmd pull request #11445 "fix Issue 14936 - Dividing by a power of 2 slow on 32bit" was merged into master: - 5badb70971549986a9a68ebb42614e446f3af1dd by Walter Bright: fix Issue 14936 - Dividing by a power of 2 slow on 32bit https://github.com/dlang/dmd/pull/11445