Bug 497723 - forgot to restore callgrind output cleanup
[valgrind.git] / none / tests / arm / ldrt_arm.c
blob2fa83b978e48afe26c2da4d62df24602ae5ac4a9
1 // This should be compiled as ARM code.
3 #include <stdio.h>
4 #include <malloc.h>
6 typedef unsigned int UInt;
8 __attribute__((noinline)) UInt do_ldrt_A1_imm_132 ( unsigned char* p )
10 UInt res;
11 __asm__ __volatile__(
12 // Twice do ldrt for testing post-indexed.
13 "mov r5, %1 ; ldrt r6, [r5], #+132 ; ldrt r6, [r5], #132 ; mov %0, r6"
14 : "=r"(res) : "r"(p) : "r5", "r6"
16 return res;
19 __attribute__((noinline)) UInt do_ldrt_A2_imm_132 ( unsigned char* p )
21 UInt res;
22 __asm__ __volatile__(
23 // Twice ldrt for testing post-indexed.
24 "mov r5, %1 ; mov r6, #33; ldrt r7, [r5], +r6, lsl #2 ; ldrt r7, [r5], +r6, lsl #2 ; mov %0, r7"
25 : "=r"(res) : "r"(p) : "r5", "r6", "r7"
27 return res;
30 __attribute__((noinline)) UInt do_ldrbt_A1_imm_2 (unsigned char* val)
32 UInt res;
33 __asm__ __volatile__(
34 // Twice ldrbt for testing post-indexed.
35 "mov r4, %1 ; ldrbt r5, [r4], #+2; ldrbt r5, [r4], #+2; mov %0, r5"
36 : "=r"(res) : "r"(val) : "r4", "r5"
38 return res;
41 __attribute__((noinline)) UInt do_ldrbt_A2_imm_2 (unsigned char* val)
43 UInt res;
44 __asm__ __volatile__(
45 // Twice ldrbt for testing post-indexed.
46 "mov r4, %1 ; mov r5, #4; ldrbt r6, [r4], +r5, lsr #2 ; ldrbt r6, [r4], +r5, lsr #2; mov %0, r6"
47 : "=r"(res) : "r"(val) : "r4", "r5", "r6"
49 return res;
52 __attribute__((noinline)) UInt do_ldrht_A1_imm_m2 (unsigned char* val)
54 UInt res;
55 __asm__ __volatile__(
56 // Twice ldrht for testing post-indexed.
57 "mov r4, %1 ; ldrht r5, [r4], #-2 ; ldrht r5, [r4], #-2 ; mov %0, r5"
58 : "=r"(res) : "r"(val) : "r4", "r5"
60 return res;
63 __attribute__((noinline)) UInt do_ldrht_A2_imm_m2 (unsigned char* val)
65 UInt res;
66 __asm__ __volatile__(
67 // Twice ldrht for testing post-indexed.
68 "mov r4, %1 ; mov r5, #2 ; ldrht r6, [r4], -r5 ; ldrht r6, [r4], -r5 ; mov %0, r6"
69 : "=r"(res) : "r"(val) : "r4", "r5", "r6"
71 return res;
74 __attribute__((noinline)) UInt do_ldrsht_A1_imm_m2 (unsigned char* val)
76 UInt res;
77 __asm__ __volatile__(
78 // Twice ldrsht for testing post-indexed.
79 "mov r4, %1 ; ldrsht r5, [r4], #-2 ; ldrsht r5, [r4], #-2 ; mov %0, r5"
80 : "=r"(res) : "r"(val) : "r4", "r5"
82 return res;
85 __attribute__((noinline)) UInt do_ldrsht_A2_imm_1 (unsigned char* val)
87 UInt res;
88 __asm__ __volatile__(
89 // Twice ldrsht for testing post-indexed.
90 "mov r4, %1 ; mov r5, #1 ; ldrsht r6, [r4], r5 ; ldrsht r6, [r4], r5 ; mov %0, r6"
91 : "=r"(res) : "r"(val) : "r4", "r5", "r6"
93 return res;
96 __attribute__((noinline)) UInt do_ldrsbt_A1_imm_1 (unsigned char* val)
98 UInt res;
99 __asm__ __volatile__(
100 // Twice ldrsbt for testing post-indexed.
101 "mov r4, %1 ; ldrsbt r5, [r4], #1 ; ldrsbt r5, [r4], #1 ; mov %0, r5"
102 : "=r"(res) : "r"(val) : "r4", "r5"
104 return res;
107 __attribute__((noinline)) UInt do_ldrsbt_A2_imm_1 (unsigned char* val)
109 UInt res;
110 __asm__ __volatile__(
111 // Twice ldrsbt for testing post-indexed.
112 "mov r4, %1 ; mov r5, #1 ; ldrsbt r6, [r4], r5 ; ldrsbt r6, [r4], r5 ; mov %0, r6"
113 : "=r"(res) : "r"(val) : "r4", "r5", "r6"
115 return res;
118 __attribute__((noinline)) void do_strbt_A1_imm_1 (unsigned char* val)
120 __asm__ __volatile__(
121 // Twice strbt for testing post-indexed.
122 "mov r4, %0 ; mov r5, #0xCD ; strbt r5, [r4], #1 ; strbt r5, [r4], #1"
123 : : "r"(val) : "r4", "r5"
127 __attribute__((noinline)) void do_strbt_A2_imm_1 (unsigned char* val)
129 __asm__ __volatile__(
130 // Twice strbt for testing post-indexed.
131 "mov r4, %0 ; mov r5, #1 ; mov r6, #0xCD ; strbt r6, [r4], r5, LSL #1 ; strbt r6, [r4], r5"
132 : : "r"(val) : "r4", "r5", "r6"
136 __attribute__((noinline)) void do_strht_A1_imm_1 (unsigned char* val)
138 __asm__ __volatile__(
139 // Twice strht for testing post-indexed.
140 "mov r4, %0 ; ldr r5, =0xABCD ; strht r5, [r4], #1 ; strht r5, [r4], #1"
141 : : "r"(val) : "r4", "r5"
145 __attribute__((noinline)) void do_strht_A2_imm_1 (unsigned char* val)
147 __asm__ __volatile__(
148 // Twice strht for testing post-indexed.
149 "mov r4, %0 ; mov r5, #1 ; ldr r6, =0xDCBA ; strht r6, [r4], r5 ; strht r6, [r4], r5"
150 : : "r"(val) : "r4", "r5", "r6"
154 __attribute__((noinline)) void do_strt_A1_imm_4 (unsigned char* val)
156 __asm__ __volatile__(
157 // Twice strt for testing post-indexed.
158 "mov r4, %0 ; ldr r5, =0xABCDEFFF ; strt r5, [r4], #4 ; ldr r5, =0x01234567 ; strt r5, [r4], #0"
159 : : "r"(val) : "r4", "r5"
163 __attribute__((noinline)) void do_strt_A2_imm_4 (unsigned char* val)
165 __asm__ __volatile__(
166 // Twice strt for testing post-indexed.
167 "mov r4, %0 ; mov r5, #2 ; ldr r6, =0xFFFEDCBA ; strt r6, [r4], -r5, LSL #1 ; mov r5, #0 ; ldr r6, =0x76543210 ; strt r6, [r4], +r5"
168 : : "r"(val) : "r4", "r5", "r6"
172 int main ( void )
174 UInt i;
175 unsigned char* b = malloc(256);
176 for (i = 0; i < 256; i++) b[i] = (unsigned char)i;
177 UInt r = do_ldrt_A1_imm_132(b);
178 free(b);
179 printf("result is 0x%08x (should be 0x%08x)\n", r, 0x87868584);
181 UInt j;
182 unsigned char* c = malloc(256);
183 for (j = 0; j < 256; j++) c[j] = (unsigned char)j;
184 UInt k = do_ldrt_A2_imm_132(c);
185 free(c);
186 printf("result is 0x%08x (should be 0x%08x)\n", k, 0x87868584);
188 UInt val_ldrbt = (200 << 0) | (150 << 8) | (137 << 16) | (10 << 24);
189 printf("result is %u (should be %u)\n", do_ldrbt_A1_imm_2((unsigned char*)&val_ldrbt), 137);
191 UInt val_ldrbt_A2 = (200 << 0) | (150 << 8) | (137 << 16) | (10 << 24);
192 printf("result is %u (should be %u)\n", do_ldrbt_A2_imm_2((unsigned char*)&val_ldrbt_A2), 150);
194 UInt val_ldrht_A1 = (0xC8 << 0) | (0xF6 << 8) | (0xBB << 16) | (0x0A << 24);
195 printf("result is %u (should be %u)\n", do_ldrht_A1_imm_m2((unsigned char*)&val_ldrht_A1 + 2), 0x0000F6C8);
197 UInt val_ldrht_A2 = (0xC8 << 0) | (0xF7 << 8) | (0xBB << 16) | (0x0A << 24);
198 printf("result is %u (should be %u)\n", do_ldrht_A2_imm_m2((unsigned char*)&val_ldrht_A2 + 2), 0x0000F7C8);
200 UInt val_ldrsht_A1 = (0x08 << 0) | (0xFC << 8) | (0x0B << 16) | (0x0A << 24);
201 printf("result is %u (should be %u)\n", do_ldrsht_A1_imm_m2((unsigned char*)&val_ldrsht_A1 + 2), 0xFFFFFC08);
203 UInt val_ldrsht_A2 = (0xC8 << 0) | (0x0B << 8) | (0xFB << 16) | (0x0A << 24);
204 printf("result is %u (should be %u)\n", do_ldrsht_A2_imm_1((unsigned char*)&val_ldrsht_A2), 0xFFFFFB0B);
206 UInt val_ldrsbt_A1 = (0xC8 << 0) | (0xF0 << 8) | (0xCD << 16) | (0x0A << 24);
207 printf("result is %u (should be %u)\n", do_ldrsbt_A1_imm_1((unsigned char*)&val_ldrsbt_A1), 0xFFFFFFF0);
209 UInt val_ldrsbt_A2 = (0xC8 << 0) | (0xF0 << 8) | (0xFD << 16) | (0x0A << 24);
210 printf("result is %u (should be %u)\n", do_ldrsbt_A2_imm_1((unsigned char*)&val_ldrsbt_A2 + 1), 0xFFFFFFFD);
212 UInt val_strbt_A1 = (0xC8 << 0) | (0xF0 << 8) | (0xFD << 16) | (0x0A << 24);
213 do_strbt_A1_imm_1((unsigned char*)&val_strbt_A1);
214 printf("result is %u (should be %u)\n", val_strbt_A1, 0x0AFDCDCD);
216 UInt val_strbt_A2 = (0xC8 << 0) | (0xF0 << 8) | (0xFD << 16) | (0x0A << 24);
217 do_strbt_A2_imm_1((unsigned char*)&val_strbt_A2);
218 printf("result is %u (should be %u)\n", val_strbt_A2, 0x0ACDF0CD);
220 UInt val_strht_A1 = 0xFFFFFFFF;
221 do_strht_A1_imm_1((unsigned char*)&val_strht_A1);
222 printf("result is %u (should be %u)\n", val_strht_A1, 0xFFABCDCD);
224 UInt val_strht_A2 = 0xFFFFFFFF;
225 do_strht_A2_imm_1((unsigned char*)&val_strht_A2);
226 printf("result is %u (should be %u)\n", val_strht_A2, 0xFFDCBABA);
228 UInt val_strt_A1[2] = {0xFFFFFFFF, 0xFFFFFFFF};
229 do_strt_A1_imm_4((unsigned char*)&val_strt_A1[0]);
230 printf("result is %u %u (should be %u %u)\n", val_strt_A1[0], val_strt_A1[1], 0xABCDEFFF, 0x01234567);
232 UInt val_strt_A2[2] = {0xFFFFFFFF, 0xFFFFFFFF};
233 do_strt_A2_imm_4((unsigned char*)&val_strt_A2[1]);
234 printf("result is %u %u (should be %u %u)\n", val_strt_A2[0], val_strt_A2[1], 0x76543210, 0xFFFEDCBA);
236 return 0;