[llvm-commits] [llvm] r57932 - /llvm/trunk/lib/Target/X86/X86ISelLowering.cpp

Evan Cheng evan.cheng at apple.com
Tue Oct 21 16:51:15 PDT 2008


Nice. Thanks. However, can you fix the comments so there is a space  
between "//" and the first letter? It's driving me nuts. :-)

Evan

On Oct 21, 2008, at 4:07 PM, Dale Johannesen wrote:

> Author: johannes
> Date: Tue Oct 21 18:07:49 2008
> New Revision: 57932
>
> URL: http://llvm.org/viewvc/llvm-project?rev=57932&view=rev
> Log:
> Add comments to explain uint64->f64 algorithm,
> well, sort of.  (Algorithm by Ian Ollmann.)
>
>
> Modified:
>    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
>
> Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=57932&r1=57931&r2=57932&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
> +++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Tue Oct 21  
> 18:07:49 2008
> @@ -4696,6 +4696,41 @@
>   if (Op.getValueType() != MVT::f64 || !X86ScalarSSEf64)
>     return SDValue();
>
> +  // This algorithm is not obvious.  Here it is in C code, more or  
> less:
> +/*
> + double uint64_to_double( uint32_t hi, uint32_t lo )
> +  {
> +    static const __m128i exp = { 0x4330000045300000ULL, 0 };
> +    static const __m128d bias = { 0x1.0p84, 0x1.0p52 };
> +
> +    //copy ints to xmm registers
> +    __m128i xh = _mm_cvtsi32_si128( hi );
> +    __m128i xl = _mm_cvtsi32_si128( lo );
> +
> +    //combine into low half of a single xmm register
> +    __m128i x = _mm_unpacklo_epi32( xh, xl );
> +    __m128d d;
> +    double sd;
> +
> +    //merge in appropriate exponents to give the integer bits the
> +    // right magnitude
> +    x = _mm_unpacklo_epi32( x, exp );
> +
> +    //subtract away the biases to deal with the IEEE-754 double  
> precision
> +    //implicit 1
> +    d = _mm_sub_pd( (__m128d) x, bias );
> +
> +    //All conversions up to here are exact. The correctly rounded  
> result is
> +    // calculated using the
> +    //current rounding mode using the following horizontal add.
> +    d = _mm_add_sd( d, _mm_unpackhi_pd( d, d ) );
> +    _mm_store_sd( &sd, d );   //since we are returning doubles in  
> XMM, this
> +    //store doesn't really need to be here (except maybe to zero  
> the other
> +    //double)
> +    return sd;
> +  }
> +*/
> +
>   // Get a XMM-vector-sized stack slot.
>   unsigned Size = 128/8;
>   MachineFunction &MF = DAG.getMachineFunction();
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list