1ce83509251bd1412552915f5d642a2ec503a5810tom#include <stdint.h> 2ce83509251bd1412552915f5d642a2ec503a5810tom#include <string.h> 3ce83509251bd1412552915f5d642a2ec503a5810tom#include <stdio.h> 4ce83509251bd1412552915f5d642a2ec503a5810tom 5ce83509251bd1412552915f5d642a2ec503a5810tomchar buf1[64], buf2[64]; 6ce83509251bd1412552915f5d642a2ec503a5810tom 7ce83509251bd1412552915f5d642a2ec503a5810tomint 8ce83509251bd1412552915f5d642a2ec503a5810tommain (void) 9ce83509251bd1412552915f5d642a2ec503a5810tom{ 10ce83509251bd1412552915f5d642a2ec503a5810tom unsigned long rdi, rsi, rcx, rax; 11ce83509251bd1412552915f5d642a2ec503a5810tom uintptr_t b1 = (uintptr_t) buf1, b2 = (uintptr_t) buf2; 12ce83509251bd1412552915f5d642a2ec503a5810tom 13ce83509251bd1412552915f5d642a2ec503a5810tom if (b1 > 0xffffffffULL || b2 > 0xffffffffULL) 14ce83509251bd1412552915f5d642a2ec503a5810tom return 0; 15ce83509251bd1412552915f5d642a2ec503a5810tom 16ce83509251bd1412552915f5d642a2ec503a5810tom b1 += 0x100000000ULL; 17ce83509251bd1412552915f5d642a2ec503a5810tom b2 += 0xfff00000000ULL; 18ce83509251bd1412552915f5d642a2ec503a5810tom memcpy (buf1, "abcde", 4); 19ce83509251bd1412552915f5d642a2ec503a5810tom asm volatile ("addr32 rep movsb" 20ce83509251bd1412552915f5d642a2ec503a5810tom : "=D" (rdi), "=S" (rsi), "=c" (rcx) 21ce83509251bd1412552915f5d642a2ec503a5810tom : "D" (b2), "S" (b1), "c" (0x100000004ULL) 22ce83509251bd1412552915f5d642a2ec503a5810tom : "memory"); 23ce83509251bd1412552915f5d642a2ec503a5810tom if (memcmp (buf2, "abcd", 5) != 0 24ce83509251bd1412552915f5d642a2ec503a5810tom || rdi != (uintptr_t) buf2 + 4 25ce83509251bd1412552915f5d642a2ec503a5810tom || rsi != (uintptr_t) buf1 + 4 26ce83509251bd1412552915f5d642a2ec503a5810tom || rcx) 27ce83509251bd1412552915f5d642a2ec503a5810tom fprintf (stderr, "addr32 rep movsb wrong\n"); 28ce83509251bd1412552915f5d642a2ec503a5810tom 29ce83509251bd1412552915f5d642a2ec503a5810tom rax = 0x751234560000ULL + (' ' << 8) + '0'; 30ce83509251bd1412552915f5d642a2ec503a5810tom asm volatile ("addr32 rep stosw" 31ce83509251bd1412552915f5d642a2ec503a5810tom : "=D" (rdi), "=c" (rcx), "+a" (rax) 32ce83509251bd1412552915f5d642a2ec503a5810tom : "D" (b2), "c" (0x100000003ULL) 33ce83509251bd1412552915f5d642a2ec503a5810tom : "memory"); 34ce83509251bd1412552915f5d642a2ec503a5810tom if (memcmp (buf2, "0 0 0 ", 7) != 0 35ce83509251bd1412552915f5d642a2ec503a5810tom || rdi != (uintptr_t) buf2 + 6 36ce83509251bd1412552915f5d642a2ec503a5810tom || rcx 37ce83509251bd1412552915f5d642a2ec503a5810tom || rax != 0x751234560000ULL + (' ' << 8) + '0') 38ce83509251bd1412552915f5d642a2ec503a5810tom fprintf (stderr, "addr32 rep stosw wrong\n"); 39ce83509251bd1412552915f5d642a2ec503a5810tom 40ce83509251bd1412552915f5d642a2ec503a5810tom asm volatile ("addr32 lodsl" 41ce83509251bd1412552915f5d642a2ec503a5810tom : "=S" (rsi), "=a" (rax) 42ce83509251bd1412552915f5d642a2ec503a5810tom : "S" (b2), "a" (2ULL)); 43ce83509251bd1412552915f5d642a2ec503a5810tom if (rsi != (uintptr_t) buf2 + 4 44ce83509251bd1412552915f5d642a2ec503a5810tom || rax != 0x20302030ULL) 45ce83509251bd1412552915f5d642a2ec503a5810tom fprintf (stderr, "addr32 lodsl wrong\n"); 46ce83509251bd1412552915f5d642a2ec503a5810tom 47ce83509251bd1412552915f5d642a2ec503a5810tom memcpy (buf1, "abcdefghijklmno", 16); 48ce83509251bd1412552915f5d642a2ec503a5810tom memcpy (buf2, "abcdefghijklmnO", 16); 49ce83509251bd1412552915f5d642a2ec503a5810tom asm volatile ("addr32 repe cmpsb" 50ce83509251bd1412552915f5d642a2ec503a5810tom : "=D" (rdi), "=S" (rsi), "=c" (rcx) 51ce83509251bd1412552915f5d642a2ec503a5810tom : "D" (b2), "S" (b1), "c" (0x100000020ULL)); 52ce83509251bd1412552915f5d642a2ec503a5810tom if (rdi != (uintptr_t) buf2 + 15 53ce83509251bd1412552915f5d642a2ec503a5810tom || rsi != (uintptr_t) buf1 + 15 54ce83509251bd1412552915f5d642a2ec503a5810tom || rcx != 17ULL) 55ce83509251bd1412552915f5d642a2ec503a5810tom fprintf (stderr, "addr32 repe cmpsb wrong\n"); 56ce83509251bd1412552915f5d642a2ec503a5810tom 57ce83509251bd1412552915f5d642a2ec503a5810tom memcpy (buf2, "ababababababababcdab", 20); 58ce83509251bd1412552915f5d642a2ec503a5810tom rax = 0x123450000ULL + ('d' << 8) + 'c'; 59ce83509251bd1412552915f5d642a2ec503a5810tom asm volatile ("addr32 repne scasw" 60ce83509251bd1412552915f5d642a2ec503a5810tom : "=D" (rdi), "=c" (rcx), "+a" (rax) 61ce83509251bd1412552915f5d642a2ec503a5810tom : "D" (b2), "c" (0x100000020ULL)); 62ce83509251bd1412552915f5d642a2ec503a5810tom if (rdi != (uintptr_t) buf2 + 18 63ce83509251bd1412552915f5d642a2ec503a5810tom || rcx != 23ULL 64ce83509251bd1412552915f5d642a2ec503a5810tom || rax != 0x123450000ULL + ('d' << 8) + 'c') 65ce83509251bd1412552915f5d642a2ec503a5810tom fprintf (stderr, "addr32 repne scasw wrong\n"); 66ce83509251bd1412552915f5d642a2ec503a5810tom 67ce83509251bd1412552915f5d642a2ec503a5810tom rax = 0x543210000ULL + ('b' << 8) + 'a'; 68ce83509251bd1412552915f5d642a2ec503a5810tom asm volatile ("addr32 repe scasw" 69ce83509251bd1412552915f5d642a2ec503a5810tom : "=D" (rdi), "=c" (rcx), "+a" (rax) 70ce83509251bd1412552915f5d642a2ec503a5810tom : "D" (b2), "c" (0x100000020ULL)); 71ce83509251bd1412552915f5d642a2ec503a5810tom if (rdi != (uintptr_t) buf2 + 18 72ce83509251bd1412552915f5d642a2ec503a5810tom || rcx != 23ULL 73ce83509251bd1412552915f5d642a2ec503a5810tom || rax != 0x543210000ULL + ('b' << 8) + 'a') 74ce83509251bd1412552915f5d642a2ec503a5810tom fprintf (stderr, "addr32 repe scasw wrong\n"); 75ce83509251bd1412552915f5d642a2ec503a5810tom 76ce83509251bd1412552915f5d642a2ec503a5810tom return 0; 77ce83509251bd1412552915f5d642a2ec503a5810tom} 78