linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@linux-mips.org>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: Linux Arch Mailing List <linux-arch@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Using __int128 on 64-bit architectures
Date: Sun, 21 Apr 2013 05:29:28 +0100 (BST)	[thread overview]
Message-ID: <alpine.LFD.2.03.1304210450490.17443@linux-mips.org> (raw)
In-Reply-To: <51464C00.5090107@zytor.com>

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

  reply	other threads:[~2013-04-21  4:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-17 23:04 Using __int128 on 64-bit architectures H. Peter Anvin
2013-04-21  4:29 ` Maciej W. Rozycki [this message]
2013-04-21  9:35   ` Stephen Rothwell
2013-04-21  9:51     ` Michael Cree
2013-04-21  9:51       ` Michael Cree

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.2.03.1304210450490.17443@linux-mips.org \
    --to=macro@linux-mips.org \
    --cc=hpa@zytor.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).