deadalnix
Posted in reply to Guillaume Piolat
| On Monday, 28 March 2022 at 18:37:27 UTC, Guillaume Piolat wrote:
> On Saturday, 26 March 2022 at 19:30:13 UTC, Walter Bright wrote:
>> https://dlang.org/phobos/core_int128.html
>
> I tried to find faults in its divide and modulo so that I could rant about wideint.d being rewritten, but actually core.int128 seems to be better and correct (possibly more correct with negative modulo even). :)
>
> So now it's all about adding the operator overloads, and done with that particular complaint!
With LDC 1.27.1 :
```d
Cent foobar(Cent a, Cent b) {
return mul(a, b);
}
```
Codegen:
```asm
nothrow @nogc @safe example.Cent example.foobar(example.Cent, example.Cent):
push r15
push r14
push rbx
mov r9d, edi
mov r8, rdi
shr r8, 32
mov r11d, esi
mov r10, rsi
shr r10, 32
mov ebx, edx
mov rax, rbx
imul r11, rbx
imul rbx, r9
imul rax, r8
mov r14d, ebx
shr rbx, 32
add rbx, rax
mov eax, ebx
shr rbx, 32
add rbx, r11
imul r10d, edx
shr rdx, 32
mov r11, rdx
imul r11, r9
add rax, r11
mov r11, rdx
imul r11, r8
mov r15d, ebx
add r15, r11
mov r11, rax
shr r11, 32
add r11, r15
imul edx, esi
add edx, r10d
mov r10d, ecx
imul r10, r9
mov esi, r11d
add rsi, r10
imul r8d, ecx
add r8d, edx
shr rcx, 32
imul ecx, edi
add ecx, r8d
shl rax, 32
or rax, r14
shl rcx, 32
add rcx, rbx
movabs rdx, -4294967296
and rcx, rdx
add rcx, r11
and rcx, rdx
add rsi, rcx
mov rdx, rsi
pop rbx
pop r14
pop r15
ret
```
Now let's see what we can get with clang and __int128_t, same backend so the comparison is fair:
```cpp
__uint128_t foobar(__uint128_t a, __uint128_t b) {
return a * b;
}
```
codegen:
```asm
foobar(unsigned __int128, unsigned __int128): # @foobar(unsigned __int128, unsigned __int128)
mov r8, rdx
mov rax, rdx
mul rdi
imul rsi, r8
add rdx, rsi
imul rcx, rdi
add rdx, rcx
ret
```
Why do I even have to argue that case?
|