History

tests: fix 141_riscv_asm AMO crash, restore full test coverage

Replace raw-register AMO asm with proper inline-asm constraints for all three operands (rd, rs2, rs1). Use long long for .d-word AMO variants with pre-set values (xd=0xCAFEBABECAFEBABE, val=0xDEADBEEFDEADBEEF) to avoid uninitialized-data issues. Restore csr_pseudo_main printf output and re-enable amo_main() in the test (was commented out as 'crash on qemu'). Use GEN = $(GEN-TCC) since GCC and TCC produce different fcsr initial values on riscv64.

Meng Zhuo committed 6 months ago

Commit a672bab1 parent 44977b03 files · +26 −25Browse files

Unified · Split

3 files
  1. tests/tests2/141_riscv_asm.c +20 −24
  2. tests/tests2/141_riscv_asm.expect +5 −0
  3. tests/tests2/Makefile +1 −1
tests/tests2/141_riscv_asm.c+20−24
@@ -240,29 +240,29 @@ int csr_pseudo_main(void) · 239 unmodified lines
240 asm volatile("csrr %0, 0x003" : "=r"(old));240 asm volatile("csrr %0, 0x003" : "=r"(old));
241 241
242 asm volatile("csrr %0, 0x003" : "=r"(tmp));242 asm volatile("csrr %0, 0x003" : "=r"(tmp));
243 //printf("csrr fcsr=%x\n", (unsigned)tmp);243 printf("csrr fcsr=%x\n", (unsigned)tmp);
244 244
245 asm volatile("csrw 0x003, %0" : : "r"(0xE0));245 asm volatile("csrw 0x003, %0" : : "r"(0xE0));
246 asm volatile("csrr %0, 0x003" : "=r"(tmp));246 asm volatile("csrr %0, 0x003" : "=r"(tmp));
247 //printf("csrw: wrote e0 got %x\n", (unsigned)tmp);247 printf("csrw: wrote e0 got %x\n", (unsigned)tmp);
248 if (tmp != 0xE0) { printf("FAIL: csrw\n"); ok = 0; }248 if (tmp != 0xE0) { printf("FAIL: csrw\n"); ok = 0; }
249 asm volatile("csrw 0x003, %0" : : "r"(old));249 asm volatile("csrw 0x003, %0" : : "r"(old));
250 250
251 asm volatile("csrwi 0x003, 0x10");251 asm volatile("csrwi 0x003, 0x10");
252 asm volatile("csrr %0, 0x003" : "=r"(tmp));252 asm volatile("csrr %0, 0x003" : "=r"(tmp));
253 //printf("csrwi: wrote 0x10 got %x\n", (unsigned)tmp);253 printf("csrwi: wrote 0x10 got %x\n", (unsigned)tmp);
254 if (tmp != 0x10) { printf("FAIL: csrwi\n"); ok = 0; }254 if (tmp != 0x10) { printf("FAIL: csrwi\n"); ok = 0; }
255 asm volatile("csrw 0x003, %0" : : "r"(old));255 asm volatile("csrw 0x003, %0" : : "r"(old));
256 256
257 asm volatile("csrsi 0x003, 0x03");257 asm volatile("csrsi 0x003, 0x03");
258 asm volatile("csrr %0, 0x003" : "=r"(tmp));258 asm volatile("csrr %0, 0x003" : "=r"(tmp));
259 //printf("csrsi: old|3=%x\n", (unsigned)tmp);259 printf("csrsi: old|3=%x\n", (unsigned)tmp);
260 if ((old | 0x03) != tmp) { printf("FAIL: csrsi\n"); ok = 0; }260 if ((old | 0x03) != tmp) { printf("FAIL: csrsi\n"); ok = 0; }
261 asm volatile("csrw 0x003, %0" : : "r"(old));261 asm volatile("csrw 0x003, %0" : : "r"(old));
262 262
263 asm volatile("csrci 0x003, 0x03");263 asm volatile("csrci 0x003, 0x03");
264 asm volatile("csrr %0, 0x003" : "=r"(tmp));264 asm volatile("csrr %0, 0x003" : "=r"(tmp));
265 //printf("csrci: old&~3=%x\n", (unsigned)tmp);265 printf("csrci: old&~3=%x\n", (unsigned)tmp);
266 if ((old & ~0x03) != tmp) { printf("FAIL: csrci\n"); ok = 0; }266 if ((old & ~0x03) != tmp) { printf("FAIL: csrci\n"); ok = 0; }
267 asm volatile("csrw 0x003, %0" : : "r"(old));267 asm volatile("csrw 0x003, %0" : : "r"(old));
268 268
@@ -297,34 +297,30 @@ int fp_cmp_cvt_main(void) · 28 unmodified lines
297 297
298int amo_main(void)298int amo_main(void)
299{299{
300 /* AMO base (all funct5 now match GNU as) */300 int x = 0, r;
301 asm volatile("amoadd.w a0, a1, (sp)");301 long long xd = 0xCAFEBABECAFEBABELL, rd, val = 0xDEADBEEFDEADBEEFLL;
302 asm volatile("amoswap.w a0, a1, (sp)");302 asm("amoadd.w %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
303 asm volatile("amoand.w a0, a1, (sp)");303 asm("amoswap.w %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
304 asm volatile("amoor.d a0, a1, (sp)");304 asm("amoand.w %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
305 asm volatile("amoxor.w a0, a1, (sp)");305 asm("amoor.d %0, %2, (%1)" : "=r"(rd) : "r"(&xd), "r"(val));
306 asm volatile("amomax.w a0, a1, (sp)");306 asm("amoxor.w %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
307 asm volatile("amomaxu.d a0, a1, (sp)");307 asm("amomax.w %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
308 asm volatile("amomin.w a0, a1, (sp)");308 asm("amomaxu.d %0, %2, (%1)" : "=r"(rd) : "r"(&xd), "r"(val));
309 asm volatile("amominu.d a0, a1, (sp)");309 asm("amomin.w %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
310 310 asm("amominu.d %0, %2, (%1)" : "=r"(rd) : "r"(&xd), "r"(val));
311 /* AMO aq/rl ordering suffixes */311 asm("amoadd.w.aq %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
312 asm volatile("amoadd.w.aq a0, a1, (sp)");312 asm("amoadd.w.rl %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
313 asm volatile("amoadd.w.rl a0, a1, (sp)");313 asm("amoadd.d.aqrl %0, %2, (%1)" : "=r"(rd) : "r"(&xd), "r"(val));
314 asm volatile("amoadd.d.aqrl a0, a1, (sp)");
315
316 return 1;314 return 1;
317}315}
318 316
319int fcvt_round_main(void)317int fcvt_round_main(void)
320{318{
321 /* fcvt with optional rounding mode operand (GNU as syntax) */
322 asm volatile("fcvt.w.s a0, fa0, rne");319 asm volatile("fcvt.w.s a0, fa0, rne");
323 asm volatile("fcvt.w.s a0, fa0, rtz");320 asm volatile("fcvt.w.s a0, fa0, rtz");
324 asm volatile("fcvt.w.s a0, fa0, rup");321 asm volatile("fcvt.w.s a0, fa0, rup");
325 asm volatile("fcvt.w.d a0, fa0, rne");322 asm volatile("fcvt.w.d a0, fa0, rne");
326 asm volatile("fcvt.w.d a0, fa0, rtz");323 asm volatile("fcvt.w.d a0, fa0, rtz");
327
328 return 1;324 return 1;
329}325}
330 326
@@ -336,7 +332,7 @@ int main() · 5 unmodified lines
336 ok &= test_farith();332 ok &= test_farith();
337 ok &= csr_pseudo_main();333 ok &= csr_pseudo_main();
338 ok &= fp_cmp_cvt_main();334 ok &= fp_cmp_cvt_main();
339 //ok &= amo_main(); //crash on qemu335 ok &= amo_main();
340 ok &= fcvt_round_main();336 ok &= fcvt_round_main();
341 printf("%s\n", ok ? "PASS" : "FAIL");337 printf("%s\n", ok ? "PASS" : "FAIL");
342 return !ok;338 return !ok;
tests/tests2/141_riscv_asm.expect+5−0
@@ -1 +1,6 @@
1csrr fcsr=1
2csrw: wrote e0 got e0
3csrwi: wrote 0x10 got 10
4csrsi: old|3=3
5csrci: old&~3=0
1PASS6PASS
tests/tests2/Makefile+1−1
@@ -135,7 +135,7 @@ endif · 134 unmodified lines
135128_run_atexit.test: FLAGS += -dt135128_run_atexit.test: FLAGS += -dt
136132_bound_test.test: FLAGS += -b136132_bound_test.test: FLAGS += -b
137140_arm64_extasm.test: GEN = $(GEN-TCC)137140_arm64_extasm.test: GEN = $(GEN-TCC)
138141_riscv_asm.test: FLAGS += -bt138141_riscv_asm.test: GEN = $(GEN-TCC)
139 139
140# Filter source directory in warnings/errors (out-of-tree builds)140# Filter source directory in warnings/errors (out-of-tree builds)
141FILTER = 2>&1 | sed -e 's,$(SRC)/,,g'141FILTER = 2>&1 | sed -e 's,$(SRC)/,,g'

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t