Does gcc support 128-bit int on amd64?
How to define it?
How to use scanf/printf to read/write it?
Does gcc support 128-bit int on amd64?
How to define it?
How to use scanf/printf to read/write it?
void f(__int128* res, __int128* op1, __int128* op2)
{
*res = *op1 + *op2;
}
Save to test.c and compile with:
$ gcc -c -O3 test.c
$ objdump -d -M intel test.o
You get:
mov rcx, rdx
mov rax, [rsi]
mov rdx, [rsi+0x8]
add rax, [rcx]
adc rdx, [rcx+0x8]
mov [rdi], rax
mov [rdi+0x8], rdx
As you can see the __int128 type is supported by keeping two 64-bits in sequence and then operating on them with the typical big int pattern of using two instructions, for example ADD and then ADC (add with carry)