lkml.org 
[lkml]   [2013]   [Apr]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Using __int128 on 64-bit architectures
On Sun, 17 Mar 2013, H. Peter Anvin wrote:

> How desirable/portable is it to use __int128 on non-x86 64-bit
> architectures to get a 64*64 -> 128 bit multiply? On x86-64 this works
> extremely well, but I'm worried about that needlessly breaking on other
> architectures.

Hmm, nobody has replied, so just FYI such widening multiplication is
available in all 64-bit MIPS hardware and GCC has supported it since 4.4
or mid 2008 (older versions used a libgcc __multi3 helper, not quite so
efficient as you can imagine).

$ cat mulditi3.c
typedef int int128_t __attribute__((mode(TI)));

int128_t mulditi3(long x, long y)
{
int128_t _x = x, _y = y;
return _x * _y;
}
$ mips64-linux-gcc -O2 -c mulditi3.c
$ mips64-linux-objdump -d mulditi3.o

mulditi3.o: file format elf64-tradbigmips


Disassembly of section .text:

0000000000000000 <mulditi3>:
0: 0085001c dmult a0,a1
4: 00001812 mflo v1
8: 03e00008 jr ra
c: 00001010 mfhi v0
$

(MFLO and MFHI are register moves from the MD accumulator to GPRs).
There's an unsigned instruction variant as well.

HTH,

Maciej


\
 
 \ /
  Last update: 2013-04-21 07:21    [W:0.114 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site