root / tests / tcg / test-i386-ssse3.c @ c09015dd
History | View | Annotate | Download (1.8 kB)
1 | 59e0fbf8 | balrog | /* See if various MMX/SSE SSSE3 instructions give expected results */
|
---|---|---|---|
2 | 59e0fbf8 | balrog | #include <stdio.h> |
3 | 59e0fbf8 | balrog | #include <string.h> |
4 | 222a3336 | balrog | #include <stdint.h> |
5 | 59e0fbf8 | balrog | |
6 | 59e0fbf8 | balrog | int main(int argc, char *argv[]) { |
7 | 59e0fbf8 | balrog | char hello[16]; |
8 | 59e0fbf8 | balrog | const char ehlo[8] = "EHLO "; |
9 | 59e0fbf8 | balrog | uint64_t mask = 0x8080800302020001;
|
10 | 59e0fbf8 | balrog | |
11 | 59e0fbf8 | balrog | uint64_t a = 0x0000000000090007;
|
12 | 59e0fbf8 | balrog | uint64_t b = 0x0000000000000000;
|
13 | 222a3336 | balrog | uint32_t c; |
14 | 222a3336 | balrog | uint16_t d; |
15 | 59e0fbf8 | balrog | |
16 | 222a3336 | balrog | const char e[16] = "LLOaaaaaaaaaaaaa"; |
17 | 222a3336 | balrog | const char f[16] = "aaaaaaaaaaaaaaHE"; |
18 | 59e0fbf8 | balrog | |
19 | 59e0fbf8 | balrog | /* pshufb mm1/xmm1, mm2/xmm2 */
|
20 | 59e0fbf8 | balrog | asm volatile ("movq (%0), %%mm0" : : "r" (ehlo) : "mm0", "mm1"); |
21 | 59e0fbf8 | balrog | asm volatile ("movq %0, %%mm1" : : "m" (mask)); |
22 | 59e0fbf8 | balrog | asm volatile ("pshufb %mm1, %mm0"); |
23 | 59e0fbf8 | balrog | asm volatile ("movq %%mm0, %0" : "=m" (hello)); |
24 | 59e0fbf8 | balrog | printf("%s\n", hello);
|
25 | 59e0fbf8 | balrog | |
26 | 59e0fbf8 | balrog | /* pshufb mm1/xmm1, m64/m128 */
|
27 | 59e0fbf8 | balrog | asm volatile ("movq (%0), %%mm0" : : "r" (ehlo) : "mm0"); |
28 | 59e0fbf8 | balrog | asm volatile ("pshufb %0, %%mm0" : : "m" (mask)); |
29 | 59e0fbf8 | balrog | asm volatile ("movq %%mm0, %0" : "=m" (hello)); |
30 | 59e0fbf8 | balrog | printf("%s\n", hello);
|
31 | 59e0fbf8 | balrog | |
32 | 59e0fbf8 | balrog | /* psubsw mm1/xmm1, m64/m128 */
|
33 | 59e0fbf8 | balrog | asm volatile ("movq %0, %%mm0" : : "r" (a) : "mm0"); |
34 | 59e0fbf8 | balrog | asm volatile ("phsubsw %0, %%mm0" : : "m" (b)); |
35 | 59e0fbf8 | balrog | asm volatile ("movq %%mm0, %0" : "=m" (a)); |
36 | 59e0fbf8 | balrog | printf("%i - %i = %i\n", 9, 7, -(int16_t) a); |
37 | 59e0fbf8 | balrog | |
38 | 59e0fbf8 | balrog | /* palignr mm1/xmm1, m64/m128, imm8 */
|
39 | 222a3336 | balrog | asm volatile ("movdqa (%0), %%xmm0" : : "r" (e) : "xmm0"); |
40 | 222a3336 | balrog | asm volatile ("palignr $14, (%0), %%xmm0" : : "r" (f)); |
41 | 59e0fbf8 | balrog | asm volatile ("movdqa %%xmm0, (%0)" : : "r" (hello)); |
42 | 59e0fbf8 | balrog | printf("%5.5s\n", hello);
|
43 | 59e0fbf8 | balrog | |
44 | 222a3336 | balrog | #if 1 /* SSE4 */ |
45 | 222a3336 | balrog | /* popcnt r64, r/m64 */
|
46 | 222a3336 | balrog | asm volatile ("movq $0x8421000010009c63, %%rax" : : : "rax"); |
47 | 222a3336 | balrog | asm volatile ("popcnt %%ax, %%dx" : : : "dx"); |
48 | 222a3336 | balrog | asm volatile ("popcnt %%eax, %%ecx" : : : "ecx"); |
49 | 222a3336 | balrog | asm volatile ("popcnt %rax, %rax"); |
50 | 222a3336 | balrog | asm volatile ("movq %%rax, %0" : "=m" (a)); |
51 | 222a3336 | balrog | asm volatile ("movl %%ecx, %0" : "=m" (c)); |
52 | 222a3336 | balrog | asm volatile ("movw %%dx, %0" : "=m" (d)); |
53 | 222a3336 | balrog | printf("%i = %i\n%i = %i = %i\n", 13, (int) a, 9, c, d + 1); |
54 | 222a3336 | balrog | #endif
|
55 | 222a3336 | balrog | |
56 | 59e0fbf8 | balrog | return 0; |
57 | 59e0fbf8 | balrog | } |