[OT] The Usual Arithmetic Confusions

Max Samukha maxsamukha at gmail.com
Sat Feb 5 09:25:39 UTC 2022


On Friday, 4 February 2022 at 22:15:37 UTC, Elronnd wrote:
> On Friday, 4 February 2022 at 21:13:10 UTC, Walter Bright wrote:
>> It's slower, too.
>
> Not anymore.  And div can be faster on smaller integers.
>
>
>> You're paying a 3 size byte penalty for using short arithmetic 
>> rather than int arithmetic.
>
> 1. You are very careful to demonstrate short arithmetic, not 
> byte arithmetic, which is the same size as int arithmetic on 
> x86.

Interestingly, for bytes, the code is even smaller (ldc):

0000000000000000 <_D4main5testbFPhQcQeZv>:
    0:   8a 02                   mov    (%rdx),%al
    2:   41 f6 20                mulb   (%r8)
    5:   88 01                   mov    %al,(%rcx)
    7:   c3                      ret

0000000000000000 <_D4main5testiFPiQcQeZv>:
    0:   8b 02                   mov    (%rdx),%eax
    2:   41 0f af 00             imul   (%r8),%eax
    6:   89 01                   mov    %eax,(%rcx)
    8:   c3                      ret


Also, there is no difference in size for ARM64:

testb:
         ldrb    w0, [x0]
         ldrb    w1, [x1]
         mul     w0, w0, w1
         strb    w0, [x2]
         ret
tests:
         ldrh    w0, [x0]
         ldrh    w1, [x1]
         mul     w0, w0, w1
         strh    w0, [x2]
         ret
testi:
         ldr     w0, [x0]
         ldr     w1, [x1]
         mul     w0, w0, w1
         str     w0, [x2]
         ret





More information about the Digitalmars-d mailing list