]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Do float-to-bit-image conversion in a way which does not break ANSI C
authorJulian Seward <jseward@acm.org>
Wed, 23 Nov 2005 03:53:45 +0000 (03:53 +0000)
committerJulian Seward <jseward@acm.org>
Wed, 23 Nov 2005 03:53:45 +0000 (03:53 +0000)
aliasing rules.

git-svn-id: svn://svn.valgrind.org/vex/trunk@1467

VEX/priv/guest-ppc32/toIR.c

index 874424cae20933fb33a35ba0f39084cc8a3879e9..f601f7c54e27cb889a6da96d639345fa14d03ce0 100644 (file)
@@ -303,6 +303,18 @@ typedef enum {
 
 static void put_emwarn ( IRExpr* e /* :: Ity_I32 */ );
 
+/* Produce the 32-bit pattern corresponding to the supplied
+   float. */
+static UInt float_to_bits ( Float f )
+{
+   union { UInt i; Float f; } u;
+   vassert(4 == sizeof(UInt));
+   vassert(4 == sizeof(Float));
+   vassert(4 == sizeof(u));
+   u.f = f;
+   return u.i;
+}
+
 
 /*------------------------------------------------------------*/
 /*--- Misc Helpers                                         ---*/
@@ -6830,9 +6842,9 @@ static Bool dis_av_fp_convert ( UInt theInstr )
 
    /* scale = 2^UIMM, cast to float, reinterpreted as uint */
    scale = (float)( (unsigned int) 1<<UIMM_5 );
-   assign( vScale, unop(Iop_Dup32x4, mkU32( *((unsigned int*)(&scale)) )) );
+   assign( vScale, unop(Iop_Dup32x4, mkU32( float_to_bits(scale) )) );
    inv_scale = 1/scale;
-   assign( vInvScale, unop(Iop_Dup32x4, mkU32( *((unsigned int*)(&inv_scale)) )) );
+   assign( vInvScale, unop(Iop_Dup32x4, mkU32( float_to_bits(inv_scale) )) );
 
    if (opc1 != 0x4) {
       vex_printf("dis_av_fp_convert(PPC32)(instr)\n");