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