|
From: <sv...@va...> - 2010-08-17 22:39:55
|
Author: sewardj
Date: 2010-08-17 23:39:46 +0100 (Tue, 17 Aug 2010)
New Revision: 11265
Log:
Fix strict-aliasing violations; + minor futzing.
Modified:
trunk/none/tests/amd64/pcmpstr64.c
Modified: trunk/none/tests/amd64/pcmpstr64.c
===================================================================
--- trunk/none/tests/amd64/pcmpstr64.c 2010-08-17 15:19:55 UTC (rev 11264)
+++ trunk/none/tests/amd64/pcmpstr64.c 2010-08-17 22:39:46 UTC (rev 11265)
@@ -1,9 +1,12 @@
+/* Tests in detail the core arithmetic for pcmp{e,i}str{i,m} using
+ pcmpistri to drive it. Does not check the e-vs-i or i-vs-m
+ aspect. */
+
#include <string.h>
#include <stdio.h>
#include <assert.h>
-typedef unsigned char V128[16];
typedef unsigned int UInt;
typedef signed int Int;
typedef unsigned char UChar;
@@ -12,6 +15,14 @@
#define False ((Bool)0)
#define True ((Bool)1)
+//typedef unsigned char V128[16];
+typedef
+ union {
+ UChar uChar[16];
+ UInt uInt[4];
+ }
+ V128;
+
#define SHIFT_O 11
#define SHIFT_S 7
#define SHIFT_Z 6
@@ -71,7 +82,7 @@
assert(xx < 16);
xx = (xx << 4) | xx;
assert(xx < 256);
- (*dst)[i] = xx;
+ dst->uChar[i] = xx;
}
}
@@ -94,7 +105,7 @@
{
UInt i, res = 0;
for (i = 0; i < 16; i++) {
- res |= (((*arg)[i] == 0) ? 1 : 0) << i;
+ res |= ((arg->uChar[i] == 0) ? 1 : 0) << i;
}
return res;
}
@@ -187,6 +198,17 @@
assert((zmaskL >> 16) == 0);
assert((zmaskR >> 16) == 0);
+ /* Explicitly reject any imm8 values that haven't been validated,
+ even if they would probably work. Life is too short to have
+ unvalidated cases in the code base. */
+ switch (imm8) {
+ case 0x02: case 0x08: case 0x0C: case 0x12: case 0x1A:
+ case 0x3A: case 0x44: case 0x4A:
+ break;
+ default:
+ return False;
+ }
+
UInt fmt = (imm8 >> 0) & 3; // imm8[1:0] data format
UInt agg = (imm8 >> 2) & 3; // imm8[3:2] aggregation fn
UInt pol = (imm8 >> 4) & 3; // imm8[5:4] polarity
@@ -391,7 +413,7 @@
0x4A, False/*!isSTRM*/
);
assert(ok);
- resECX = *(UInt*)(&resV[0]);
+ resECX = resV.uInt[0];
return (resOSZACP << 16) | resECX;
}
@@ -482,7 +504,7 @@
0x3A, False/*!isSTRM*/
);
assert(ok);
- resECX = *(UInt*)(&resV[0]);
+ resECX = resV.uInt[0];
return (resOSZACP << 16) | resECX;
}
@@ -559,7 +581,7 @@
"popq %%rdx" "\n\t"
"movq %%rcx, %0" "\n\t"
"movq %%rdx, %1" "\n\t"
- : /*out*/ "=r"(res), "=r"(flags) : "r"/*in*/(&block[0][0])
+ : /*out*/ "=r"(res), "=r"(flags) : "r"/*in*/(&block[0])
: "rcx","rdx","xmm0","xmm2","xmm11","cc","memory"
);
return ((flags & 0x8D5) << 16) | (res & 0xFFFF);
@@ -576,7 +598,7 @@
0x0C, False/*!isSTRM*/
);
assert(ok);
- resECX = *(UInt*)(&resV[0]);
+ resECX = resV.uInt[0];
return (resOSZACP << 16) | resECX;
}
@@ -658,7 +680,7 @@
0x08, False/*!isSTRM*/
);
assert(ok);
- resECX = *(UInt*)(&resV[0]);
+ resECX = resV.uInt[0];
return (resOSZACP << 16) | resECX;
}
@@ -751,7 +773,7 @@
0x1A, False/*!isSTRM*/
);
assert(ok);
- resECX = *(UInt*)(&resV[0]);
+ resECX = resV.uInt[0];
return (resOSZACP << 16) | resECX;
}
@@ -846,7 +868,7 @@
0x02, False/*!isSTRM*/
);
assert(ok);
- resECX = *(UInt*)(&resV[0]);
+ resECX = resV.uInt[0];
return (resOSZACP << 16) | resECX;
}
@@ -928,7 +950,7 @@
0x12, False/*!isSTRM*/
);
assert(ok);
- resECX = *(UInt*)(&resV[0]);
+ resECX = resV.uInt[0];
return (resOSZACP << 16) | resECX;
}
@@ -1011,7 +1033,7 @@
0x44, False/*!isSTRM*/
);
assert(ok);
- resECX = *(UInt*)(&resV[0]);
+ resECX = resV.uInt[0];
return (resOSZACP << 16) | resECX;
}
|