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
240240 asm volatile("csrr %0, 0x003" : "=r"(old));
241241
242242 asm volatile("csrr %0, 0x003" : "=r"(tmp));
243− //printf("csrr fcsr=%x\n", (unsigned)tmp);
243+ printf("csrr fcsr=%x\n", (unsigned)tmp);
244244
245245 asm volatile("csrw 0x003, %0" : : "r"(0xE0));
246246 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);
248248 if (tmp != 0xE0) { printf("FAIL: csrw\n"); ok = 0; }
249249 asm volatile("csrw 0x003, %0" : : "r"(old));
250250
251251 asm volatile("csrwi 0x003, 0x10");
252252 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);
254254 if (tmp != 0x10) { printf("FAIL: csrwi\n"); ok = 0; }
255255 asm volatile("csrw 0x003, %0" : : "r"(old));
256256
257257 asm volatile("csrsi 0x003, 0x03");
258258 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);
260260 if ((old | 0x03) != tmp) { printf("FAIL: csrsi\n"); ok = 0; }
261261 asm volatile("csrw 0x003, %0" : : "r"(old));
262262
263263 asm volatile("csrci 0x003, 0x03");
264264 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);
266266 if ((old & ~0x03) != tmp) { printf("FAIL: csrci\n"); ok = 0; }
267267 asm volatile("csrw 0x003, %0" : : "r"(old));
268268
@@ -297,34 +297,30 @@ int fp_cmp_cvt_main(void) · 28 unmodified lines
297297
298298 int amo_main(void)
299299 {
300− /* AMO base (all funct5 now match GNU as) */
301− asm volatile("amoadd.w a0, a1, (sp)");
302− asm volatile("amoswap.w a0, a1, (sp)");
303− asm volatile("amoand.w a0, a1, (sp)");
304− asm volatile("amoor.d a0, a1, (sp)");
305− asm volatile("amoxor.w a0, a1, (sp)");
306− asm volatile("amomax.w a0, a1, (sp)");
307− asm volatile("amomaxu.d a0, a1, (sp)");
308− asm volatile("amomin.w a0, a1, (sp)");
309− asm volatile("amominu.d a0, a1, (sp)");
310−
311− /* AMO aq/rl ordering suffixes */
312− asm volatile("amoadd.w.aq a0, a1, (sp)");
313− asm volatile("amoadd.w.rl a0, a1, (sp)");
314− asm volatile("amoadd.d.aqrl a0, a1, (sp)");
315−
300+ int x = 0, r;
301+ long long xd = 0xCAFEBABECAFEBABELL, rd, val = 0xDEADBEEFDEADBEEFLL;
302+ asm("amoadd.w %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
303+ asm("amoswap.w %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
304+ asm("amoand.w %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
305+ asm("amoor.d %0, %2, (%1)" : "=r"(rd) : "r"(&xd), "r"(val));
306+ asm("amoxor.w %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
307+ asm("amomax.w %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
308+ asm("amomaxu.d %0, %2, (%1)" : "=r"(rd) : "r"(&xd), "r"(val));
309+ asm("amomin.w %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
310+ asm("amominu.d %0, %2, (%1)" : "=r"(rd) : "r"(&xd), "r"(val));
311+ asm("amoadd.w.aq %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
312+ asm("amoadd.w.rl %0, %2, (%1)" : "=r"(r) : "r"(&x), "r"(val));
313+ asm("amoadd.d.aqrl %0, %2, (%1)" : "=r"(rd) : "r"(&xd), "r"(val));
316314 return 1;
317315 }
318316
319317 int fcvt_round_main(void)
320318 {
321− /* fcvt with optional rounding mode operand (GNU as syntax) */
322319 asm volatile("fcvt.w.s a0, fa0, rne");
323320 asm volatile("fcvt.w.s a0, fa0, rtz");
324321 asm volatile("fcvt.w.s a0, fa0, rup");
325322 asm volatile("fcvt.w.d a0, fa0, rne");
326323 asm volatile("fcvt.w.d a0, fa0, rtz");
327−
328324 return 1;
329325 }
330326
@@ -336,7 +332,7 @@ int main() · 5 unmodified lines
336332 ok &= test_farith();
337333 ok &= csr_pseudo_main();
338334 ok &= fp_cmp_cvt_main();
339− //ok &= amo_main(); //crash on qemu
335+ ok &= amo_main();
340336 ok &= fcvt_round_main();
341337 printf("%s\n", ok ? "PASS" : "FAIL");
342338 return !ok;
tests/tests2/141_riscv_asm.expect+5−0
@@ -1 +1,6 @@
1+csrr fcsr=1
2+csrw: wrote e0 got e0
3+csrwi: wrote 0x10 got 10
4+csrsi: old|3=3
5+csrci: old&~3=0
16 PASS
tests/tests2/Makefile+1−1
@@ -135,7 +135,7 @@ endif · 134 unmodified lines
135135 128_run_atexit.test: FLAGS += -dt
136136 132_bound_test.test: FLAGS += -b
137137 140_arm64_extasm.test: GEN = $(GEN-TCC)
138−141_riscv_asm.test: FLAGS += -bt
138+141_riscv_asm.test: GEN = $(GEN-TCC)
139139
140140 # Filter source directory in warnings/errors (out-of-tree builds)
141141 FILTER = 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