sewardj | 3a63e8c | 2005-09-09 11:33:25 +0000 | [diff] [blame^] | 1 | |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <string.h> |
| 5 | |
| 6 | static void announce ( char* str ) |
| 7 | { |
| 8 | printf("------ %s ------\n", str); |
| 9 | } |
| 10 | |
| 11 | int main ( void ) |
| 12 | { |
| 13 | int i; |
| 14 | char* a1 = malloc(100); |
| 15 | char* a2 = malloc(100); |
| 16 | strcpy(a1,"here is a stringHERE IS A STRING"); |
| 17 | |
| 18 | announce("lswi n == 8 (fe special cased)"); |
| 19 | asm volatile("li 5,0\n\t" |
| 20 | "lswi 3,%0, 8\n\t" |
| 21 | "stw 3,0(%1)\n\t" |
| 22 | "stw 4,4(%1)\n\t" |
| 23 | "stw 5,8(%1)\n\t" |
| 24 | : : "r"(a1), "r"(a2) : "r3", "r4", "r5", |
| 25 | "cc", "memory" ); |
| 26 | printf("%s\n", a2); |
| 27 | for (i = 0; i < 12; i++) |
| 28 | printf("%d = 0x%2x\n", i, a2[i]); |
| 29 | printf("\n"); |
| 30 | |
| 31 | |
| 32 | announce("lswi n /= 8"); |
| 33 | asm volatile("lswi 3,%0, 9\n\t" |
| 34 | "stw 3,0(%1)\n\t" |
| 35 | "stw 4,4(%1)\n\t" |
| 36 | "stw 5,8(%1)\n\t" |
| 37 | : : "r"(a1), "r"(a2) : "r3", "r4", "r5", |
| 38 | "cc", "memory" ); |
| 39 | printf("%s\n", a2); |
| 40 | for (i = 0; i < 12; i++) |
| 41 | printf("%d = 0x%2x\n", i, a2[i]); |
| 42 | printf("\n"); |
| 43 | |
| 44 | |
| 45 | announce("lswx"); |
| 46 | free(a2); |
| 47 | a2 = malloc(100); |
| 48 | asm volatile("li 8, 11\n\t" |
| 49 | "mtxer 8\n\t" |
| 50 | "lswx 3,%0,%2\n\t" |
| 51 | "stw 3,0(%1)\n\t" |
| 52 | "stw 4,4(%1)\n\t" |
| 53 | "stw 5,8(%1)\n\t" |
| 54 | : : "r"(a1), "r"(a2), "r"(16) : "r3", "r4", "r5", "r8", |
| 55 | "cc", "memory" ); |
| 56 | printf("%s\n", a2); |
| 57 | for (i = 0; i < 12; i++) |
| 58 | printf("%d = 0x%2x\n", i, a2[i]); |
| 59 | printf("\n"); |
| 60 | |
| 61 | |
| 62 | announce("stswi n == 8 (fe special cased)"); |
| 63 | free(a2); |
| 64 | a2 = calloc(100,1); |
| 65 | asm volatile("lswi 3,%0, 19\n\t" |
| 66 | "stswi 3,%1, 8\n" |
| 67 | : : "r"(a1), "r"(a2) : "r3","r4","r5","r6","r7", |
| 68 | "cc", "memory" ); |
| 69 | printf("%s\n", a2); |
| 70 | printf("\n"); |
| 71 | |
| 72 | |
| 73 | announce("stswi n /= 8"); |
| 74 | free(a2); |
| 75 | a2 = calloc(100,1); |
| 76 | asm volatile("lswi 3,%0, 19\n\t" |
| 77 | "stswi 3,%1, 17\n" |
| 78 | : : "r"(a1), "r"(a2) : "r3","r4","r5","r6","r7", |
| 79 | "cc", "memory" ); |
| 80 | printf("%s\n", a2); |
| 81 | printf("\n"); |
| 82 | |
| 83 | |
| 84 | announce("stswx"); |
| 85 | free(a2); |
| 86 | a2 = calloc(100,1); |
| 87 | asm volatile("li 8, 11\n\t" |
| 88 | "mtxer 8\n\t" |
| 89 | "lswx 3,%0,%2\n\t" |
| 90 | "stswx 3,%1,%2\n\t" |
| 91 | : : "r"(a1), "r"(a2), "r"(16) : "r3", "r4", "r5", "r8", |
| 92 | "cc", "memory" ); |
| 93 | printf("%s\n", a2+16); |
| 94 | printf("\n"); |
| 95 | |
| 96 | return 0; |
| 97 | } |