2 /* Test for a number of SSE instructions which were seen in the wild
3 with a bogus (irrelevant) REX.W bit in their prefixes. Some just
4 have REX = 0x48 where REX.W is irrelevant, hence the whole REX
5 prefix is pointless. Probably related to #133962. */
10 #include "tests/malloc.h"
12 typedef unsigned char UChar
;
15 struct { __attribute__((aligned(16))) UChar b
[16]; }
19 struct { UWord128 reg
[16]; }
23 struct { UWord128 dqw
[5]; }
26 void pp_UWord128 ( UWord128
* w
) {
29 for (i
= 15; i
>= 0; i
--) {
31 sprintf(buf
, "%02x", (unsigned int)w
->b
[i
]);
33 if (buf
[0] == '0') buf
[0] = '.';
34 if (buf
[1] == '0') buf
[1] = '.';
39 void pp_XMMRegs ( char* who
, XMMRegs
* regs
) {
41 printf ("%s (xmms in order [15..0]) {\n", who
);
42 for (i
= 0; i
< 16; i
++) {
43 printf(" %%xmm%2d ", i
);
44 pp_UWord128( ®s
->reg
[i
] );
50 void pp_Mem ( char* who
, Mem
* mem
) {
52 printf ("%s (dqws in order [15 .. 0]) {\n", who
);
53 for (i
= 0; i
< 5; i
++) {
55 pp_UWord128( &mem
->dqw
[i
] );
61 void xor_UWord128( UWord128
* src
, UWord128
* dst
) {
63 for (i
= 0; i
< 16; i
++)
64 dst
->b
[i
] ^= src
->b
[i
];
66 void xor_XMMRegs ( XMMRegs
* src
, XMMRegs
* dst
) {
68 for (i
= 0; i
< 16; i
++)
69 xor_UWord128( &src
->reg
[i
], &dst
->reg
[i
] );
72 void xor_Mem ( Mem
* src
, Mem
* dst
) {
74 for (i
= 0; i
< 5; i
++)
75 xor_UWord128( &src
->dqw
[i
], &dst
->dqw
[i
] );
78 void setup_regs_mem ( XMMRegs
* regs
, Mem
* mem
) {
81 for (i
= 0; i
< 16; i
++) {
82 for (j
= 0; j
< 16; j
++)
83 regs
->reg
[i
].b
[j
] = 0x51 + (ctr
++ % 7);
85 for (i
= 0; i
< 5; i
++) {
86 for (j
= 0; j
< 16; j
++)
87 mem
->dqw
[i
].b
[j
] = 0x52 + (ctr
++ % 13);
91 void before_test ( XMMRegs
* regs
, Mem
* mem
) {
92 setup_regs_mem( regs
, mem
);
95 void after_test ( char* who
, XMMRegs
* regs
, Mem
* mem
) {
99 setup_regs_mem( &rdiff
, &mdiff
);
100 xor_XMMRegs( regs
, &rdiff
);
101 xor_Mem( mem
, &mdiff
);
102 sprintf(s
, "after \"%s\"", who
);
104 pp_XMMRegs( s
, &rdiff
);
108 #define LOAD_XMMREGS_from_r14 \
109 "\tmovupd 0(%%r14), %%xmm0\n" \
110 "\tmovupd 16(%%r14), %%xmm1\n" \
111 "\tmovupd 32(%%r14), %%xmm2\n" \
112 "\tmovupd 48(%%r14), %%xmm3\n" \
113 "\tmovupd 64(%%r14), %%xmm4\n" \
114 "\tmovupd 80(%%r14), %%xmm5\n" \
115 "\tmovupd 96(%%r14), %%xmm6\n" \
116 "\tmovupd 112(%%r14), %%xmm7\n" \
117 "\tmovupd 128(%%r14), %%xmm8\n" \
118 "\tmovupd 144(%%r14), %%xmm9\n" \
119 "\tmovupd 160(%%r14), %%xmm10\n" \
120 "\tmovupd 176(%%r14), %%xmm11\n" \
121 "\tmovupd 192(%%r14), %%xmm12\n" \
122 "\tmovupd 208(%%r14), %%xmm13\n" \
123 "\tmovupd 224(%%r14), %%xmm14\n" \
124 "\tmovupd 240(%%r14), %%xmm15\n"
126 #define SAVE_XMMREGS_to_r14 \
127 "\tmovupd %%xmm0, 0(%%r14)\n" \
128 "\tmovupd %%xmm1, 16(%%r14)\n" \
129 "\tmovupd %%xmm2, 32(%%r14)\n" \
130 "\tmovupd %%xmm3, 48(%%r14)\n" \
131 "\tmovupd %%xmm4, 64(%%r14)\n" \
132 "\tmovupd %%xmm5, 80(%%r14)\n" \
133 "\tmovupd %%xmm6, 96(%%r14)\n" \
134 "\tmovupd %%xmm7, 112(%%r14)\n" \
135 "\tmovupd %%xmm8, 128(%%r14)\n" \
136 "\tmovupd %%xmm9, 144(%%r14)\n" \
137 "\tmovupd %%xmm10, 160(%%r14)\n" \
138 "\tmovupd %%xmm11, 176(%%r14)\n" \
139 "\tmovupd %%xmm12, 192(%%r14)\n" \
140 "\tmovupd %%xmm13, 208(%%r14)\n" \
141 "\tmovupd %%xmm14, 224(%%r14)\n" \
142 "\tmovupd %%xmm15, 240(%%r14)"
145 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7", \
146 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15"
149 /* Boilerplate for test */
151 before_test( regs
, mem
);
152 __asm__
__volatile__(
155 LOAD_XMMREGS_from_r14
156 "\tmovq %%r15, %%rx\n"
159 : /*out*/ : /*in*/ "r"(regs
), "r"( -x
+ (char*)&mem
->dqw
[2] )
160 : /*trash*/ "r14","r15","memory", XMMREGS
,
163 after_test( "", regs
, mem
);
171 regs
= memalign16(sizeof(XMMRegs
) + 16);
172 mem
= memalign16(sizeof(Mem
) + 16);
174 /* addpd mem, reg 66 49 0f 58 48 00 rex.WB addpd 0x0(%r8),%xmm1 */
176 before_test( regs
, mem
);
177 __asm__
__volatile__(
180 LOAD_XMMREGS_from_r14
181 "\tmovq %%r15, %%r8\n"
182 "\t.byte 0x66,0x49,0x0f,0x58,0x48,0x00\n"
184 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
185 : /*trash*/ "r14","r15","memory", XMMREGS
,
188 after_test( "rex.WB addpd 0x0(%r8),%xmm1", regs
, mem
);
191 /* addsd mem, reg f2 48 0f 58 27 rex.W addsd (%rdi),%xmm4 */
193 before_test( regs
, mem
);
194 __asm__
__volatile__(
197 LOAD_XMMREGS_from_r14
198 "\tmovq %%r15, %%rdi\n"
199 "\t.byte 0xf2,0x48,0x0f,0x58,0x27\n"
201 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
202 : /*trash*/ "r14","r15","memory", XMMREGS
,
205 after_test( "rex.W addsd (%rdi),%xmm4", regs
, mem
);
208 /* movapd mem, reg 66 48 0f 28 0a rex.W movapd (%rdx),%xmm1 */
210 before_test( regs
, mem
);
211 __asm__
__volatile__(
214 LOAD_XMMREGS_from_r14
215 "\tmovq %%r15, %%rdx\n"
216 "\t.byte 0x66,0x48,0x0f,0x28,0x0a\n"
218 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
219 : /*trash*/ "r14","r15","memory", XMMREGS
,
222 after_test( "rex.W movapd (%rdx),%xmm1", regs
, mem
);
225 /* movapd reg, mem 66 48 0f 29 0a rex.W movapd %xmm1,(%rdx) */
227 before_test( regs
, mem
);
228 __asm__
__volatile__(
231 LOAD_XMMREGS_from_r14
232 "\tmovq %%r15, %%rdx\n"
233 "\t.byte 0x66,0x48,0x0f,0x29,0x0a\n"
235 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
236 : /*trash*/ "r14","r15","memory", XMMREGS
,
239 after_test( "rex.W movapd %xmm1,(%rdx)", regs
, mem
);
242 /* movaps mem, reg 48 0f 28 42 30 rex.W movaps 0x30(%rdx),%xmm0 */
244 before_test( regs
, mem
);
245 __asm__
__volatile__(
248 LOAD_XMMREGS_from_r14
249 "\tmovq %%r15, %%rdx\n"
250 "\t.byte 0x48,0x0f,0x28,0x42,0x30\n"
252 : /*out*/ : /*in*/ "r"(regs
), "r"( -0x30 + (char*)&mem
->dqw
[2] )
253 : /*trash*/ "r14","r15","memory", XMMREGS
,
256 after_test( "movaps 0x30(%rdx),%xmm0", regs
, mem
);
259 /* movaps reg, mem 49 0f 29 48 00 rex.WB movaps %xmm1,0x0(%r8) */
261 before_test( regs
, mem
);
262 __asm__
__volatile__(
265 LOAD_XMMREGS_from_r14
266 "\tmovq %%r15, %%r8\n"
267 "\t.byte 0x49,0x0f,0x29,0x48,0x00\n"
269 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
270 : /*trash*/ "r14","r15","memory", XMMREGS
,
273 after_test( "rex.WB movaps %xmm1,0x0(%r8)", regs
, mem
);
276 /* movddup mem, reg f2 48 0f 12 2a rex.W movddup (%rdx),%xmm5 */
278 before_test( regs
, mem
);
279 __asm__
__volatile__(
282 LOAD_XMMREGS_from_r14
283 "\tmovq %%r15, %%rdx\n"
284 "\t.byte 0xf2,0x48,0x0f,0x12,0x2a\n"
286 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
287 : /*trash*/ "r14","r15","memory", XMMREGS
,
290 after_test( "movddup (%rdx),%xmm5", regs
, mem
);
293 /* movhpd mem, reg 66 48 0f 16 06 rex.W movhpd (%rsi),%xmm0 */
295 before_test( regs
, mem
);
296 __asm__
__volatile__(
299 LOAD_XMMREGS_from_r14
300 "\tmovq %%r15, %%rsi\n"
301 "\t.byte 0x66,0x48,0x0f,0x16,0x06\n"
303 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
304 : /*trash*/ "r14","r15","memory", XMMREGS
,
307 after_test( "rex.W movhpd (%rsi),%xmm0", regs
, mem
);
310 /* movhpd reg, mem 66 48 0f 17 07 rex.W movhpd %xmm0,(%rdi) */
312 before_test( regs
, mem
);
313 __asm__
__volatile__(
316 LOAD_XMMREGS_from_r14
317 "\tmovq %%r15, %%rdi\n"
318 "\t.byte 0x66,0x48,0x0f,0x17,0x07\n"
320 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
321 : /*trash*/ "r14","r15","memory", XMMREGS
,
324 after_test( "rex.W movhpd %xmm0,(%rdi)", regs
, mem
);
327 /* movhps mem, reg 48 0f 16 36 rex.W movhps (%rsi),%xmm6 */
329 before_test( regs
, mem
);
330 __asm__
__volatile__(
333 LOAD_XMMREGS_from_r14
334 "\tmovq %%r15, %%rsi\n"
335 "\t.byte 0x48,0x0f,0x16,0x36\n"
337 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
338 : /*trash*/ "r14","r15","memory", XMMREGS
,
341 after_test( "rex.W movhps (%rsi),%xmm6", regs
, mem
);
343 /* movhps reg, mem 49 0f 17 03 rex.WB movhps %xmm0,(%r11) */
345 before_test( regs
, mem
);
346 __asm__
__volatile__(
349 LOAD_XMMREGS_from_r14
350 "\tmovq %%r15, %%r11\n"
351 "\t.byte 0x49,0x0F,0x17,0x03\n" /* rex.WB movhps %xmm0,(%r11) */
353 : /*out*/ : /*in*/ "r"(regs
), "r"( 0 + (char*)&mem
->dqw
[2] )
354 : /*trash*/ "r14","r15","memory", XMMREGS
,
357 after_test( "rex.WB movhps %xmm0,(%r11)", regs
, mem
);
360 /* movlpd mem, reg 66 48 0f 12 4a 00 rex.W movlpd 0x0(%rdx),%xmm1 */
362 before_test( regs
, mem
);
363 __asm__
__volatile__(
366 LOAD_XMMREGS_from_r14
367 "\tmovq %%r15, %%rdx\n"
368 "\t.byte 0x66,0x48,0x0f,0x12,0x4a,0x00\n"
370 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
371 : /*trash*/ "r14","r15","memory", XMMREGS
,
374 after_test( "rex.W movlpd 0x0(%rdx),%xmm1", regs
, mem
);
377 /* movlpd reg, mem 66 48 0f 13 30 rex.W movlpd %xmm6,(%rax) */
379 before_test( regs
, mem
);
380 __asm__
__volatile__(
383 LOAD_XMMREGS_from_r14
384 "\tmovq %%r15, %%rax\n"
385 "\t.byte 0x66,0x48,0x0f,0x13,0x30\n"
387 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
388 : /*trash*/ "r14","r15","memory", XMMREGS
,
391 after_test( "rex.W movlpd %xmm6,(%rax)", regs
, mem
);
394 /* movlps mem, reg 48 0f 12 07 rex.W movlps (%rdi),%xmm0 */
396 before_test( regs
, mem
);
397 __asm__
__volatile__(
400 LOAD_XMMREGS_from_r14
401 "\tmovq %%r15, %%rdi\n"
402 "\t.byte 0x48,0x0f,0x12,0x07\n"
404 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
405 : /*trash*/ "r14","r15","memory", XMMREGS
,
408 after_test( "rex.W movlps (%rdi),%xmm0", regs
, mem
);
411 /* movlps reg, mem 49 0f 13 02 rex.WB movlps %xmm0,(%r10) */
413 before_test( regs
, mem
);
414 __asm__
__volatile__(
417 LOAD_XMMREGS_from_r14
418 "\tmovq %%r15, %%r10\n"
419 "\t.byte 0x49,0x0f,0x13,0x02\n"
421 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
422 : /*trash*/ "r14","r15","memory", XMMREGS
,
425 after_test( "rex.WB movlps %xmm0,(%r10)", regs
, mem
);
428 /* movq mem, reg f3 48 0f 7e 00 rex.W movq (%rax),%xmm0 */
430 before_test( regs
, mem
);
431 __asm__
__volatile__(
434 LOAD_XMMREGS_from_r14
435 "\tmovq %%r15, %%rax\n"
436 "\t.byte 0xf3,0x48,0x0f,0x7e,0x00\n"
438 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
439 : /*trash*/ "r14","r15","memory", XMMREGS
,
442 after_test( "rex.W movq (%rax),%xmm0", regs
, mem
);
445 /* movq reg, mem 66 48 0f d6 00 rex.W movq %xmm0,(%rax) */
447 before_test( regs
, mem
);
448 __asm__
__volatile__(
451 LOAD_XMMREGS_from_r14
452 "\tmovq %%r15, %%rax\n"
453 "\t.byte 0x66,0x48,0x0f,0xd6,0x00\n"
455 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
456 : /*trash*/ "r14","r15","memory", XMMREGS
,
459 after_test( "rex.W movq %xmm0,(%rax)", regs
, mem
);
462 /* movsd mem, reg f2 48 0f 10 11 rex.W movsd (%rcx),%xmm2 */
464 before_test( regs
, mem
);
465 __asm__
__volatile__(
468 LOAD_XMMREGS_from_r14
469 "\tmovq %%r15, %%rcx\n"
470 "\t.byte 0xf2,0x48,0x0f,0x10,0x11\n"
472 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
473 : /*trash*/ "r14","r15","memory", XMMREGS
,
476 after_test( "rex.W movsd (%rcx),%xmm2", regs
, mem
);
479 /* movsd reg, mem f2 48 0f 11 3f rex.W movsd %xmm7,(%rdi) */
481 before_test( regs
, mem
);
482 __asm__
__volatile__(
485 LOAD_XMMREGS_from_r14
486 "\tmovq %%r15, %%rdi\n"
487 "\t.byte 0xf2,0x48,0x0f,0x11,0x3f\n"
489 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
490 : /*trash*/ "r14","r15","memory", XMMREGS
,
493 after_test( "rex.W movsd %xmm7,(%rdi)", regs
, mem
);
496 /* movss mem, reg f3 48 0f 10 5e 04 rex.W movss 0x4(%rsi),%xmm3 */
498 before_test( regs
, mem
);
499 __asm__
__volatile__(
502 LOAD_XMMREGS_from_r14
503 "\tmovq %%r15, %%rsi\n"
504 "\t.byte 0xf3,0x48,0x0f,0x10,0x5e,0x04\n"
506 : /*out*/ : /*in*/ "r"(regs
), "r"( -0x4 + (char*)&mem
->dqw
[2] )
507 : /*trash*/ "r14","r15","memory", XMMREGS
,
510 after_test( "rex.W movss 0x4(%rsi),%xmm3", regs
, mem
);
513 /* movupd reg, mem 66 48 0f 11 07 rex.W movupd %xmm0,(%rdi) */
515 before_test( regs
, mem
);
516 __asm__
__volatile__(
519 LOAD_XMMREGS_from_r14
520 "\tmovq %%r15, %%rdi\n"
521 "\t.byte 0x66,0x48,0x0f,0x11,0x07\n"
523 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
524 : /*trash*/ "r14","r15","memory", XMMREGS
,
527 after_test( "rex.W movupd %xmm0,(%rdi)", regs
, mem
);
530 /* mulpd mem, reg 66 48 0f 59 61 00 rex.W mulpd 0x0(%rcx),%xmm4 */
532 before_test( regs
, mem
);
533 __asm__
__volatile__(
536 LOAD_XMMREGS_from_r14
537 "\tmovq %%r15, %%rcx\n"
538 "\t.byte 0x66,0x48,0x0f,0x59,0x61,0x00\n"
540 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
541 : /*trash*/ "r14","r15","memory", XMMREGS
,
544 after_test( "rex.W mulpd 0x0(%rcx),%xmm4", regs
, mem
);
547 /* mulsd mem, reg f2 48 0f 59 1f rex.W mulsd (%rdi),%xmm3 */
549 before_test( regs
, mem
);
550 __asm__
__volatile__(
553 LOAD_XMMREGS_from_r14
554 "\tmovq %%r15, %%rdi\n"
555 "\t.byte 0xf2,0x48,0x0f,0x59,0x1f\n"
557 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
558 : /*trash*/ "r14","r15","memory", XMMREGS
,
561 after_test( "rex.W mulsd (%rdi),%xmm3", regs
, mem
);
564 /* prefetchnt0 49 0f 18 4c f2 a0 rex.WB prefetcht0 -0x60(%r10,%rsi,8) */
566 before_test( regs
, mem
);
567 __asm__
__volatile__(
570 LOAD_XMMREGS_from_r14
571 "\tmovq %%r15, %%r10\n"
572 "\txorq %%rsi, %%rsi\n"
573 "\t.byte 0x49,0x0f,0x18,0x4c,0xf2,0xa0\n"
575 : /*out*/ : /*in*/ "r"(regs
), "r"( - -0x60 + (char*)&mem
->dqw
[2] )
576 : /*trash*/ "r14","r15","memory", XMMREGS
,
579 after_test( "rex.WB prefetcht0 -0x60(%r10,%rsi,8)", regs
, mem
);
582 /* subsd mem, reg f2 49 0f 5c 4d f8 rex.WB subsd -0x8(%r13),%xmm1 */
584 before_test( regs
, mem
);
585 __asm__
__volatile__(
588 LOAD_XMMREGS_from_r14
589 "\tmovq %%r15, %%r13\n"
590 "\t.byte 0xf2,0x49,0x0f,0x5c,0x4d,0xf8\n"
592 : /*out*/ : /*in*/ "r"(regs
), "r"( - -0x8 + (char*)&mem
->dqw
[2] )
593 : /*trash*/ "r14","r15","memory", XMMREGS
,
596 after_test( "rex.WB subsd -0x8(%r13),%xmm1", regs
, mem
);
599 /* cvtps2pd mem, reg 48 0f 5a 07 rex.W cvtps2pd (%rdi),%xmm0 */
601 before_test( regs
, mem
);
602 __asm__
__volatile__(
605 LOAD_XMMREGS_from_r14
606 "\tmovq %%r15, %%rdi\n"
607 "\t.byte 0x48,0x0f,0x5a,0x07\n"
609 : /*out*/ : /*in*/ "r"(regs
), "r"( -0 + (char*)&mem
->dqw
[2] )
610 : /*trash*/ "r14","r15","memory", XMMREGS
,
613 after_test( "rex.W cvtps2pd (%rdi),%xmm0", regs
, mem
);