x86: fix issue with casting in Cvtf2i
authorTony Gutierrez <anthony.gutierrez@amd.com>
Mon, 21 Nov 2016 20:35:56 +0000 (15:35 -0500)
committerTony Gutierrez <anthony.gutierrez@amd.com>
Mon, 21 Nov 2016 20:35:56 +0000 (15:35 -0500)
UBSAN flags this operation because it detects that arg is being cast directly
to an unsigned type, argBits. this patch fixes this by first casting the
value to a signed int type, then reintrepreting the raw bits of the signed
int into argBits.

src/arch/x86/isa/microops/mediaop.isa

index cdb3b4899541300dd9ec0fd890f9a5713982061a..63e22a23f51c4d3ffe21d48a6469cbc9d7eec253 100644 (file)
@@ -1220,9 +1220,11 @@ let {{
                 }
 
                 if (destSize == 4) {
-                    argBits = (uint32_t)arg;
+                    int32_t i_arg = (int32_t)arg;
+                    argBits = *((uint32_t*)&i_arg);
                 } else {
-                    argBits = (uint64_t)arg;
+                    int64_t i_arg = (int64_t)arg;
+                    argBits = *((uint64_t*)&i_arg);
                 }
                 int destHiIndex = destStart + (i + 1) * destSizeBits - 1;
                 int destLoIndex = destStart + (i + 0) * destSizeBits;