Skip to content

Commit

Permalink
RISC-V: Table A.6 conformance tests
Browse files Browse the repository at this point in the history
These tests cover basic cases to ensure the atomic mappings follow the
strengthened Table A.6 mappings that are compatible with Table A.7.

2023-04-27 Patrick O'Neill <patrick@rivosinc.com>

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/amo-table-a-6-amo-add-1.c: New test.
	* gcc.target/riscv/amo-table-a-6-amo-add-2.c: New test.
	* gcc.target/riscv/amo-table-a-6-amo-add-3.c: New test.
	* gcc.target/riscv/amo-table-a-6-amo-add-4.c: New test.
	* gcc.target/riscv/amo-table-a-6-amo-add-5.c: New test.
	* gcc.target/riscv/amo-table-a-6-compare-exchange-1.c: New test.
	* gcc.target/riscv/amo-table-a-6-compare-exchange-2.c: New test.
	* gcc.target/riscv/amo-table-a-6-compare-exchange-3.c: New test.
	* gcc.target/riscv/amo-table-a-6-compare-exchange-4.c: New test.
	* gcc.target/riscv/amo-table-a-6-compare-exchange-5.c: New test.
	* gcc.target/riscv/amo-table-a-6-compare-exchange-6.c: New test.
	* gcc.target/riscv/amo-table-a-6-compare-exchange-7.c: New test.
	* gcc.target/riscv/amo-table-a-6-fence-1.c: New test.
	* gcc.target/riscv/amo-table-a-6-fence-2.c: New test.
	* gcc.target/riscv/amo-table-a-6-fence-3.c: New test.
	* gcc.target/riscv/amo-table-a-6-fence-4.c: New test.
	* gcc.target/riscv/amo-table-a-6-fence-5.c: New test.
	* gcc.target/riscv/amo-table-a-6-load-1.c: New test.
	* gcc.target/riscv/amo-table-a-6-load-2.c: New test.
	* gcc.target/riscv/amo-table-a-6-load-3.c: New test.
	* gcc.target/riscv/amo-table-a-6-store-1.c: New test.
	* gcc.target/riscv/amo-table-a-6-store-2.c: New test.
	* gcc.target/riscv/amo-table-a-6-store-compat-3.c: New test.
	* gcc.target/riscv/amo-table-a-6-subword-amo-add-1.c: New test.
	* gcc.target/riscv/amo-table-a-6-subword-amo-add-2.c: New test.
	* gcc.target/riscv/amo-table-a-6-subword-amo-add-3.c: New test.
	* gcc.target/riscv/amo-table-a-6-subword-amo-add-4.c: New test.
	* gcc.target/riscv/amo-table-a-6-subword-amo-add-5.c: New test.

Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
  • Loading branch information
patrick-rivos authored and Liaoshihua committed Mar 12, 2024
1 parent ea287b5 commit a9cd998
Show file tree
Hide file tree
Showing 28 changed files with 360 additions and 0 deletions.
15 changes: 15 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-amo-add-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* { dg-do compile } */
/* Verify that atomic op mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** amoadd\.w\tzero,a1,0\(a0\)
** ret
*/
void foo (int* bar, int* baz)
{
__atomic_add_fetch(bar, baz, __ATOMIC_RELAXED);
}
15 changes: 15 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-amo-add-2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* { dg-do compile } */
/* Verify that atomic op mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** amoadd\.w\.aq\tzero,a1,0\(a0\)
** ret
*/
void foo (int* bar, int* baz)
{
__atomic_add_fetch(bar, baz, __ATOMIC_ACQUIRE);
}
15 changes: 15 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-amo-add-3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* { dg-do compile } */
/* Verify that atomic op mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** amoadd\.w\.rl\tzero,a1,0\(a0\)
** ret
*/
void foo (int* bar, int* baz)
{
__atomic_add_fetch(bar, baz, __ATOMIC_RELEASE);
}
15 changes: 15 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-amo-add-4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* { dg-do compile } */
/* Verify that atomic op mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** amoadd\.w\.aqrl\tzero,a1,0\(a0\)
** ret
*/
void foo (int* bar, int* baz)
{
__atomic_add_fetch(bar, baz, __ATOMIC_ACQ_REL);
}
15 changes: 15 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-amo-add-5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* { dg-do compile } */
/* Verify that atomic op mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** amoadd\.w\.aqrl\tzero,a1,0\(a0\)
** ret
*/
void foo (int* bar, int* baz)
{
__atomic_add_fetch(bar, baz, __ATOMIC_SEQ_CST);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* { dg-do compile } */
/* Verify that compare exchange mappings match Table A.6's recommended mapping. */
/* { dg-final { scan-assembler-times "lr.w\t" 1 } } */
/* { dg-final { scan-assembler-times "sc.w\t" 1 } } */

void foo (int bar, int baz, int qux)
{
__atomic_compare_exchange_n(&bar, &baz, qux, 1, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* { dg-do compile } */
/* Verify that compare exchange mappings match Table A.6's recommended mapping. */
/* { dg-final { scan-assembler-times "lr.w.aq\t" 1 } } */
/* { dg-final { scan-assembler-times "sc.w\t" 1 } } */

void foo (int bar, int baz, int qux)
{
__atomic_compare_exchange_n(&bar, &baz, qux, 1, __ATOMIC_CONSUME, __ATOMIC_CONSUME);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* { dg-do compile } */
/* Verify that compare exchange mappings match Table A.6's recommended mapping. */
/* { dg-final { scan-assembler-times "lr.w.aq\t" 1 } } */
/* { dg-final { scan-assembler-times "sc.w\t" 1 } } */

void foo (int bar, int baz, int qux)
{
__atomic_compare_exchange_n(&bar, &baz, qux, 1, __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* { dg-do compile } */
/* Verify that compare exchange mappings match Table A.6's recommended mapping. */
/* { dg-final { scan-assembler-times "lr.w\t" 1 } } */
/* { dg-final { scan-assembler-times "sc.w.rl\t" 1 } } */

void foo (int bar, int baz, int qux)
{
__atomic_compare_exchange_n(&bar, &baz, qux, 1, __ATOMIC_RELEASE, __ATOMIC_RELAXED);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* { dg-do compile } */
/* Verify that compare exchange mappings match Table A.6's recommended mapping. */
/* { dg-final { scan-assembler-times "lr.w.aqrl\t" 1 } } */
/* { dg-final { scan-assembler-times "sc.w.rl\t" 1 } } */

void foo (int bar, int baz, int qux)
{
__atomic_compare_exchange_n(&bar, &baz, qux, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
}
10 changes: 10 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-compare-exchange-6.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* { dg-do compile } */
/* Verify that compare exchange mappings match Table A.6's recommended mapping. */
/* Mixed mappings need to be unioned. */
/* { dg-final { scan-assembler-times "lr.w.aq\t" 1 } } */
/* { dg-final { scan-assembler-times "sc.w.rl\t" 1 } } */

void foo (int bar, int baz, int qux)
{
__atomic_compare_exchange_n(&bar, &baz, qux, 1, __ATOMIC_RELEASE, __ATOMIC_ACQUIRE);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* { dg-do compile } */
/* Verify that compare exchange mappings match Table A.6's recommended mapping. */
/* { dg-final { scan-assembler-times "lr.w.aqrl\t" 1 } } */
/* { dg-final { scan-assembler-times "sc.w.rl\t" 1 } } */

void foo (int bar, int baz, int qux)
{
__atomic_compare_exchange_n(&bar, &baz, qux, 1, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
}
14 changes: 14 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-fence-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* { dg-do compile } */
/* Verify that fence mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** ret
*/
void foo()
{
__atomic_thread_fence(__ATOMIC_RELAXED);
}
15 changes: 15 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-fence-2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* { dg-do compile } */
/* Verify that fence mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** fence\tr,rw
** ret
*/
void foo()
{
__atomic_thread_fence(__ATOMIC_ACQUIRE);
}
15 changes: 15 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-fence-3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* { dg-do compile } */
/* Verify that fence mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** fence\trw,w
** ret
*/
void foo()
{
__atomic_thread_fence(__ATOMIC_RELEASE);
}
15 changes: 15 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-fence-4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* { dg-do compile } */
/* Verify that fence mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** fence\.tso
** ret
*/
void foo()
{
__atomic_thread_fence(__ATOMIC_ACQ_REL);
}
15 changes: 15 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-fence-5.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* { dg-do compile } */
/* Verify that fence mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** fence\trw,rw
** ret
*/
void foo()
{
__atomic_thread_fence(__ATOMIC_SEQ_CST);
}
16 changes: 16 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-load-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* { dg-do compile } */
/* Verify that load mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** lw\ta[0-9]+,0\(a0\)
** sw\ta[0-9]+,0\(a1\)
** ret
*/
void foo (int* bar, int* baz)
{
__atomic_load(bar, baz, __ATOMIC_RELAXED);
}
17 changes: 17 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-load-2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* { dg-do compile } */
/* Verify that load mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** lw\ta[0-9]+,0\(a0\)
** fence\tr,rw
** sw\ta[0-9]+,0\(a1\)
** ret
*/
void foo (int* bar, int* baz)
{
__atomic_load(bar, baz, __ATOMIC_ACQUIRE);
}
18 changes: 18 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-load-3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* { dg-do compile } */
/* Verify that load mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** fence\trw,rw
** lw\ta[0-9]+,0\(a0\)
** fence\tr,rw
** sw\ta[0-9]+,0\(a1\)
** ret
*/
void foo (int* bar, int* baz)
{
__atomic_load(bar, baz, __ATOMIC_SEQ_CST);
}
16 changes: 16 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-store-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* { dg-do compile } */
/* Verify that store mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** lw\ta[0-9]+,0\(a1\)
** sw\ta[0-9]+,0\(a0\)
** ret
*/
void foo (int* bar, int* baz)
{
__atomic_store(bar, baz, __ATOMIC_RELAXED);
}
17 changes: 17 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-store-2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* { dg-do compile } */
/* Verify that store mappings match Table A.6's recommended mapping. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** lw\ta[0-9]+,0\(a1\)
** fence\trw,w
** sw\ta[0-9]+,0\(a0\)
** ret
*/
void foo (int* bar, int* baz)
{
__atomic_store(bar, baz, __ATOMIC_RELEASE);
}
18 changes: 18 additions & 0 deletions gcc/testsuite/gcc.target/riscv/amo-table-a-6-store-compat-3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* { dg-do compile } */
/* Verify that store mapping are compatible with Table A.6 & A.7. */
/* { dg-options "-O3" } */
/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
/* { dg-final { check-function-bodies "**" "" } } */

/*
** foo:
** lw\ta[0-9]+,0\(a1\)
** fence\trw,w
** sw\ta[0-9]+,0\(a0\)
** fence\trw,rw
** ret
*/
void foo (int* bar, int* baz)
{
__atomic_store(bar, baz, __ATOMIC_SEQ_CST);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* { dg-do compile } */
/* Verify that subword atomic op mappings match Table A.6's recommended mapping. */
/* { dg-final { scan-assembler-times "lr.w\t" 1 } } */
/* { dg-final { scan-assembler-times "sc.w\t" 1 } } */

void foo (short* bar, short* baz)
{
__atomic_add_fetch(bar, baz, __ATOMIC_RELAXED);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* { dg-do compile } */
/* Verify that subword atomic op mappings match Table A.6's recommended mapping. */
/* { dg-final { scan-assembler-times "lr.w.aq\t" 1 } } */
/* { dg-final { scan-assembler-times "sc.w\t" 1 } } */

void foo (short* bar, short* baz)
{
__atomic_add_fetch(bar, baz, __ATOMIC_ACQUIRE);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* { dg-do compile } */
/* Verify that subword atomic op mappings match Table A.6's recommended mapping. */
/* { dg-final { scan-assembler-times "lr.w\t" 1 } } */
/* { dg-final { scan-assembler-times "sc.w.rl\t" 1 } } */

void foo (short* bar, short* baz)
{
__atomic_add_fetch(bar, baz, __ATOMIC_RELEASE);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* { dg-do compile } */
/* Verify that subword atomic op mappings match Table A.6's recommended mapping. */
/* { dg-final { scan-assembler-times "lr.w.aq\t" 1 } } */
/* { dg-final { scan-assembler-times "sc.w.rl\t" 1 } } */

void foo (short* bar, short* baz)
{
__atomic_add_fetch(bar, baz, __ATOMIC_ACQ_REL);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* { dg-do compile } */
/* Verify that subword atomic op mappings match Table A.6's recommended mapping. */
/* { dg-final { scan-assembler-times "lr.w.aqrl\t" 1 } } */
/* { dg-final { scan-assembler-times "sc.w.rl\t" 1 } } */

void foo (short* bar, short* baz)
{
__atomic_add_fetch(bar, baz, __ATOMIC_SEQ_CST);
}

0 comments on commit a9cd998

Please sign in to comment.