This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Obtaining the bit pattern of a floating point number
- From: Michael Meissner <meissner at linux dot vnet dot ibm dot com>
- To: Florian Weimer <fw at deneb dot enyo dot de>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sun, 24 May 2009 16:42:00 -0400
- Subject: Re: Obtaining the bit pattern of a floating point number
- References: <87skivyld5.fsf@mid.deneb.enyo.de>
On Sat, May 23, 2009 at 03:55:34PM +0200, Florian Weimer wrote:
> It seems to me that x86_64 supports direct moves from XMM to
> general-purpose registers, so that it's possible to access the
> representation of a floating point value without going through memory:
>
> long getbits(double src)
> {
> long result;
> __asm__ ("movq %1, %0" : "=q" (result) : "x" (src));
> return result;
> }
>
> Is this functionally available as some sort of built-in?
Well you typically can use a union to get the bits. Don't play pointer games,
or the compiler will trip you up.
Note, while the instruction exists, it is not always the optimial way to move
data from the GPRs to the XMMs. On some machines, it is better to store the
GPR into the stack and reload it into an XMM register, than to use the
instruction. On some machines, it is faster to use the instruction.
--
Michael Meissner, IBM
4 Technology Place Drive, MS 2203A, Westford, MA, 01886, USA
meissner@linux.vnet.ibm.com