Re: [RFC][PATCH 3/3] math128, x86_64: Implement {mult,add}_u128 in64bit asm

From: Peter Zijlstra
Date: Tue Apr 24 2012 - 18:00:54 EST


On Tue, 2012-04-24 at 10:20 -0700, H. Peter Anvin wrote:
> I have been told __int128 works for all versions of gcc which support
> x86-64, but I haven't verified it myself, no.

The gcc version I have seems to grok it:

u128 mult_u64_u128(u64 a, u64 b)
{
unsigned __int128 t = a;
t *= b;
return U128_INIT(t >> 64, t);
}
#define mult_u64_u128 mult_u64_u128

generates:

.p2align 4,,15
.globl mult_u64_u128
.type mult_u64_u128, @function
mult_u64_u128:
.LFB38:
.cfi_startproc
movq %rsi, %rax
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
mulq %rdi
popq %rbp
.cfi_def_cfa_offset 8
movq %rax, %rdi
movq %rdx, %rax
movq %rdi, %rdx
ret
.cfi_endproc
.LFE38:
.size mult_u64_u128, .-mult_u64_u128

I haven't been able to make add_u128 generate sane code using __int128,
the conversion between my struct and the __int128 layout makes a horrid
mess.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/