diff options
Diffstat (limited to 'tests/test-progs/asmtest/src/riscv/isa/rv64uamt')
11 files changed, 1127 insertions, 0 deletions
diff --git a/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/Makefrag b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/Makefrag new file mode 100644 index 000000000..56a189f9f --- /dev/null +++ b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/Makefrag @@ -0,0 +1,10 @@ +#======================================================================= +# Makefrag for rv64ua_mt tests +#----------------------------------------------------------------------- + +rv64ua_mt_tests = amoadd_d amoswap_d amoxor_d amoand_d \ + amoor_d amomin_d amomax_d amominu_d amomaxu_d lrsc_d \ + +rv64uamt_ps_tests = $(addprefix rv64uamt-ps-, $(rv64ua_mt_tests)) + +spike_tests += $(rv64uamt_ps_tests) diff --git a/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoadd_d.S b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoadd_d.S new file mode 100644 index 000000000..cf744c46f --- /dev/null +++ b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoadd_d.S @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2018, Cornell University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Cornell University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Tuan Ta + */ + +//------------------------------------------------------------------------ +// This code tests amoadd_d instruction in multi-threading system. +// Each thread increments a globally shared variable LOOP_COUNT times. +// Once a thread completes, it signals its completition by atomically +// incrementing a barrier variable. +// Master thread (i.e., thread 0) waits for all threads to complete by +// spinning on the barrier variable until all threads update the variable. +// Then, the master thread checks the shared variable's value. +//------------------------------------------------------------------------ + +#include "riscv_test.h" +#include "test_macros.h" +#include "test_macros_mt.h" + + RVTEST_RV64U + RVTEST_CODE_BEGIN + +#define LOOP_COUNT 1000 +#define RESULT LOOP_COUNT * NUM_THREADS + +//------------------------------------------------------------------------ +// Master thread creates new threads, waits for all threads to complete, +// deallocates threads and checks result +//------------------------------------------------------------------------ + call _create_threads + call _join + call _delete_threads + call _check + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// mt_test function executed in child threads +// A child thread signals its completion by atomicaly adding 1 to barrier +//------------------------------------------------------------------------ +_mt_test: + li t0, 1 // one operand of amoadd_w + li t1, LOOP_COUNT // loop count + la a0, shared_var +1: + amoadd.d zero, t0, (a0) + addi t1, t1, -1 + bnez t1, 1b + + la a0, barrier + amoadd.d zero, t0, (a0) + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// Master thread checks result +//------------------------------------------------------------------------ +_check: + la a0, shared_var + li a1, RESULT + ld a0, (a0) + bne a0, a1, _fail + li a0, SUCCESS + ret + +_fail: + li a0, FAILURE + ret + + .data + +MT_DATA diff --git a/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoand_d.S b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoand_d.S new file mode 100644 index 000000000..668e4c375 --- /dev/null +++ b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoand_d.S @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018, Cornell University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Cornell University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Tuan Ta + */ + +//------------------------------------------------------------------------ +// This code tests amoand_w instruction in multi-threading system. +// All threads execute an amoxor_w instruction. +// Master thread (i.e., thread 0) waits for all threads to complete by +// spinning on the barrier variable until all threads update the variable. +// Then, the master thread checks the shared variable's value. +//------------------------------------------------------------------------ + +#include "riscv_test.h" +#include "test_macros.h" +#include "test_macros_mt.h" + + RVTEST_RV64U + RVTEST_CODE_BEGIN + +#define RESULT 0x000000008E003441 + +//------------------------------------------------------------------------ +// Reinitialize shared_var to 0xffffffffffffffff +//------------------------------------------------------------------------ + la a0, shared_var + li t0, 0xffffffffffffffff + sd t0, (a0) + +//------------------------------------------------------------------------ +// Master thread creates new threads, waits for all threads to complete, +// deallocates threads and checks result +//------------------------------------------------------------------------ + call _create_threads + call _join + call _delete_threads + call _check + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// mt_test function executed in child threads +// A child thread signals its completion by atomicaly adding 1 to barrier +//------------------------------------------------------------------------ +_mt_test: + la a0, shared_var + la t0, array_index + li t1, 8 + amoadd.d t1, t1, (t0) // get my array_index + + la t0, array + add t0, t0, t1 + ld t0, (t0) // get array[array_index] + + amoand.d zero, t0, (a0) + + li t0, 1 + la a0, barrier + amoadd.d zero, t0, (a0) + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// Master thread checks result +//------------------------------------------------------------------------ +_check: + la a0, shared_var + li a1, RESULT + ld a0, (a0) + bne a0, a1, _fail + li a0, SUCCESS + ret + +_fail: + li a0, FAILURE + ret + + .data + +MT_DATA +array_index: .dword 0; diff --git a/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amomax_d.S b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amomax_d.S new file mode 100644 index 000000000..54bc32125 --- /dev/null +++ b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amomax_d.S @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018, Cornell University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Cornell University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Tuan Ta + */ + +//------------------------------------------------------------------------ +// This code tests amomax_d instruction in multi-threading system. +// All threads execute an amomax_w instruction. +// Master thread (i.e., thread 0) waits for all threads to complete by +// spinning on the barrier variable until all threads update the variable. +// Then, the master thread checks the shared variable's value. +//------------------------------------------------------------------------ + +#include "riscv_test.h" +#include "test_macros.h" +#include "test_macros_mt.h" + + RVTEST_RV64U + RVTEST_CODE_BEGIN + +#define RESULT 0x12343eeaaf423451 + +//------------------------------------------------------------------------ +// Reinitialize shared_var to 0x8000000000000000 +//------------------------------------------------------------------------ + la a0, shared_var + li t0, 0x8000000000000000 + sd t0, (a0) + +//------------------------------------------------------------------------ +// Master thread creates new threads, waits for all threads to complete, +// deallocates threads and checks result +//------------------------------------------------------------------------ + call _create_threads + call _join + call _delete_threads + call _check + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// mt_test function executed in child threads +// A child thread signals its completion by atomicaly adding 1 to barrier +//------------------------------------------------------------------------ +_mt_test: + la a0, shared_var + la t0, array_index + li t1, 8 + amoadd.d t1, t1, (t0) // get my array_index + + la t0, array + add t0, t0, t1 + ld t0, (t0) // get array[array_index] + + amomax.d zero, t0, (a0) + + li t0, 1 + la a0, barrier + amoadd.d zero, t0, (a0) + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// Master thread checks result +//------------------------------------------------------------------------ +_check: + la a0, shared_var + li a1, RESULT + ld a0, (a0) + bne a0, a1, _fail + li a0, SUCCESS + ret + +_fail: + li a0, FAILURE + ret + + .data + +MT_DATA +array_index: .dword 0; diff --git a/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amomaxu_d.S b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amomaxu_d.S new file mode 100644 index 000000000..e5db058eb --- /dev/null +++ b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amomaxu_d.S @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018, Cornell University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Cornell University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Tuan Ta + */ + +//------------------------------------------------------------------------ +// This code tests amomax_d instruction in multi-threading system. +// All threads execute an amomax_w instruction. +// Master thread (i.e., thread 0) waits for all threads to complete by +// spinning on the barrier variable until all threads update the variable. +// Then, the master thread checks the shared variable's value. +//------------------------------------------------------------------------ + +#include "riscv_test.h" +#include "test_macros.h" +#include "test_macros_mt.h" + + RVTEST_RV64U + RVTEST_CODE_BEGIN + +#define RESULT 0xdeadbeefdeadbeef + +//------------------------------------------------------------------------ +// Reinitialize shared_var to 0x0000000000000000 +//------------------------------------------------------------------------ + la a0, shared_var + li t0, 0x0000000000000000 + sd t0, (a0) + +//------------------------------------------------------------------------ +// Master thread creates new threads, waits for all threads to complete, +// deallocates threads and checks result +//------------------------------------------------------------------------ + call _create_threads + call _join + call _delete_threads + call _check + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// mt_test function executed in child threads +// A child thread signals its completion by atomicaly adding 1 to barrier +//------------------------------------------------------------------------ +_mt_test: + la a0, shared_var + la t0, array_index + li t1, 8 + amoadd.d t1, t1, (t0) // get my array_index + + la t0, array + add t0, t0, t1 + ld t0, (t0) // get array[array_index] + + amomaxu.d zero, t0, (a0) + + li t0, 1 + la a0, barrier + amoadd.d zero, t0, (a0) + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// Master thread checks result +//------------------------------------------------------------------------ +_check: + la a0, shared_var + li a1, RESULT + ld a0, (a0) + bne a0, a1, _fail + li a0, SUCCESS + ret + +_fail: + li a0, FAILURE + ret + + .data + +MT_DATA +array_index: .dword 0; diff --git a/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amomin_d.S b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amomin_d.S new file mode 100644 index 000000000..684e9ed3e --- /dev/null +++ b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amomin_d.S @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018, Cornell University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Cornell University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Tuan Ta + */ + +//------------------------------------------------------------------------ +// This code tests amomin_d instruction in multi-threading system. +// All threads execute an amomin_d instruction. +// Master thread (i.e., thread 0) waits for all threads to complete by +// spinning on the barrier variable until all threads update the variable. +// Then, the master thread checks the shared variable's value. +//------------------------------------------------------------------------ + +#include "riscv_test.h" +#include "test_macros.h" +#include "test_macros_mt.h" + + RVTEST_RV64U + RVTEST_CODE_BEGIN + +#define RESULT 0xDEADBEEFDEADBEEF + +//------------------------------------------------------------------------ +// Reinitialize shared_var to 0x7fffffffffffffff +//------------------------------------------------------------------------ + la a0, shared_var + li t0, 0x7fffffffffffffff + sd t0, (a0) + +//------------------------------------------------------------------------ +// Master thread creates new threads, waits for all threads to complete, +// deallocates threads and checks result +//------------------------------------------------------------------------ + call _create_threads + call _join + call _delete_threads + call _check + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// mt_test function executed in child threads +// A child thread signals its completion by atomicaly adding 1 to barrier +//------------------------------------------------------------------------ +_mt_test: + la a0, shared_var + la t0, array_index + li t1, 8 + amoadd.d t1, t1, (t0) // get my array_index + + la t0, array + add t0, t0, t1 + ld t0, (t0) // get array[array_index] + + amomin.d zero, t0, (a0) + + li t0, 1 + la a0, barrier + amoadd.d zero, t0, (a0) + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// Master thread checks result +//------------------------------------------------------------------------ +_check: + la a0, shared_var + li a1, RESULT + ld a0, (a0) + bne a0, a1, _fail + li a0, SUCCESS + ret + +_fail: + li a0, FAILURE + ret + + .data + +MT_DATA +array_index: .dword 0; diff --git a/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amominu_d.S b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amominu_d.S new file mode 100644 index 000000000..a12443ed6 --- /dev/null +++ b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amominu_d.S @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018, Cornell University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Cornell University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Tuan Ta + */ + +//------------------------------------------------------------------------ +// This code tests amominu_d instruction in multi-threading system. +// All threads execute an amominu_d instruction. +// Master thread (i.e., thread 0) waits for all threads to complete by +// spinning on the barrier variable until all threads update the variable. +// Then, the master thread checks the shared variable's value. +//------------------------------------------------------------------------ + +#include "riscv_test.h" +#include "test_macros.h" +#include "test_macros_mt.h" + + RVTEST_RV64U + RVTEST_CODE_BEGIN + +#define RESULT 0x00000000deadbeef + +//------------------------------------------------------------------------ +// Reinitialize shared_var to 0xffffffffffffffff +//------------------------------------------------------------------------ + la a0, shared_var + li t0, 0xffffffffffffffff + sd t0, (a0) + +//------------------------------------------------------------------------ +// Master thread creates new threads, waits for all threads to complete, +// deallocates threads and checks result +//------------------------------------------------------------------------ + call _create_threads + call _join + call _delete_threads + call _check + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// mt_test function executed in child threads +// A child thread signals its completion by atomicaly adding 1 to barrier +//------------------------------------------------------------------------ +_mt_test: + la a0, shared_var + la t0, array_index + li t1, 8 + amoadd.d t1, t1, (t0) // get my array_index + + la t0, array + add t0, t0, t1 + ld t0, (t0) // get array[array_index] + + amominu.d zero, t0, (a0) + + li t0, 1 + la a0, barrier + amoadd.d zero, t0, (a0) + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// Master thread checks result +//------------------------------------------------------------------------ +_check: + la a0, shared_var + li a1, RESULT + ld a0, (a0) + bne a0, a1, _fail + li a0, SUCCESS + ret + +_fail: + li a0, FAILURE + ret + + .data + +MT_DATA +array_index: .dword 0; diff --git a/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoor_d.S b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoor_d.S new file mode 100644 index 000000000..1bcc37138 --- /dev/null +++ b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoor_d.S @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2018, Cornell University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Cornell University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Tuan Ta + */ + +//------------------------------------------------------------------------ +// This code tests amoor_d instruction in multi-threading system. +// All threads execute an amoor_w instruction. +// Master thread (i.e., thread 0) waits for all threads to complete by +// spinning on the barrier variable until all threads update the variable. +// Then, the master thread checks the shared variable's value. +//------------------------------------------------------------------------ + +#include "riscv_test.h" +#include "test_macros.h" +#include "test_macros_mt.h" + + RVTEST_RV64U + RVTEST_CODE_BEGIN + +#define RESULT 0xDEBDBEEFFFEFBEFF + +//------------------------------------------------------------------------ +// Master thread creates new threads, waits for all threads to complete, +// deallocates threads and checks result +//------------------------------------------------------------------------ + call _create_threads + call _join + call _delete_threads + call _check + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// mt_test function executed in child threads +// A child thread signals its completion by atomicaly adding 1 to barrier +//------------------------------------------------------------------------ +_mt_test: + la a0, shared_var + la t0, array_index + li t1, 8 + amoadd.d t1, t1, (t0) // get my array_index + + la t0, array + add t0, t0, t1 + ld t0, (t0) // get array[array_index] + + amoor.d zero, t0, (a0) + + li t0, 1 + la a0, barrier + amoadd.d zero, t0, (a0) + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// Master thread checks result +//------------------------------------------------------------------------ +_check: + la a0, shared_var + li a1, RESULT + ld a0, (a0) + bne a0, a1, _fail + li a0, SUCCESS + ret + +_fail: + li a0, FAILURE + ret + + .data + +MT_DATA +array_index: .dword 0; diff --git a/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoswap_d.S b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoswap_d.S new file mode 100644 index 000000000..5733de992 --- /dev/null +++ b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoswap_d.S @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2018, Cornell University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Cornell University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Tuan Ta + */ + +//------------------------------------------------------------------------ +// This code tests amoswap.d instruction in multi-threading system. +// All threads execute a critical section LOOP_COUNT times. A thread +// gets into a critical section by acquiring a lock variable (i.e., +// shared_var) and checking return value. +// 0 means the lock is not being locked. Each thread increments +// a variable (i.e., var) inside the critical section and releases the +// lock by swapping back 0 to the lock variable. +// The master thread (i.e., thread 0) waits for all threads to complete +// and compare the var's value to the expected result. +//------------------------------------------------------------------------ + +#include "riscv_test.h" +#include "test_macros.h" +#include "test_macros_mt.h" + + RVTEST_RV64U + RVTEST_CODE_BEGIN + +#define LOOP_COUNT 1000 +#define RESULT NUM_THREADS * LOOP_COUNT + +//------------------------------------------------------------------------ +// Master thread creates new threads, waits for all threads to complete, +// deallocates threads and checks result +//------------------------------------------------------------------------ + call _create_threads + call _join + call _delete_threads + call _check + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// mt_test function executed in child threads +// A child thread signals its completion by atomicaly adding 1 to barrier +//------------------------------------------------------------------------ +_mt_test: + li t0, 1 // initialize the swap value (1-locked) + li t1, LOOP_COUNT + la t2, var // load the var's address + la a0, shared_var + +1: + amoswap.d.aq s2, t0, (a0) // try to swap t0 with the lock + bnez s2, 1b // retry if the lock is being held + + lw t3, (t2) // load the var's value + addi t3, t3, 1 // add 1 to the value + sw t3, (t2) // store the new value to var + + amoswap.d.rl zero, zero, (a0)// release the lock by swapping back 0 + + addi t1, t1, -1 // decrement the loop_count + bnez t1, 1b // repeat if not done yet + + la a0, barrier + amoadd.d zero, t0, (a0) // signal this thread's completion + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// Master thread checks result +//------------------------------------------------------------------------ +_check: + la a0, var + li a1, RESULT + ld a0, (a0) + bne a0, a1, _fail + li a0, SUCCESS + ret + +_fail: + li a0, FAILURE + ret + + .data + +MT_DATA +var: .dword 0 diff --git a/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoxor_d.S b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoxor_d.S new file mode 100644 index 000000000..6650e452a --- /dev/null +++ b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoxor_d.S @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2018, Cornell University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Cornell University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Tuan Ta + */ + +//------------------------------------------------------------------------ +// This code tests amoxor_d instruction in multi-threading system. +// All threads execute an amoxor_w instruction. +// Master thread (i.e., thread 0) waits for all threads to complete by +// spinning on the barrier variable until all threads update the variable. +// Then, the master thread checks the shared variable's value. +//------------------------------------------------------------------------ + +#include "riscv_test.h" +#include "test_macros.h" +#include "test_macros_mt.h" + + RVTEST_RV64U + RVTEST_CODE_BEGIN + +#define RESULT 0xCC998005AF423451 + +//------------------------------------------------------------------------ +// Master thread creates new threads, waits for all threads to complete, +// deallocates threads and checks result +//------------------------------------------------------------------------ + call _create_threads + call _join + call _delete_threads + call _check + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// mt_test function executed in child threads +// A child thread signals its completion by atomicaly adding 1 to barrier +//------------------------------------------------------------------------ +_mt_test: + la a0, shared_var + la t0, array_index + li t1, 8 + amoadd.d t1, t1, (t0) // get my array_index + + la t0, array + add t0, t0, t1 + ld t0, (t0) // get array[array_index] + + amoxor.d zero, t0, (a0) + + li t0, 1 + la a0, barrier + amoadd.d zero, t0, (a0) + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// Master thread checks result +//------------------------------------------------------------------------ +_check: + la a0, shared_var + li a1, RESULT + ld a0, (a0) + bne a0, a1, _fail + li a0, SUCCESS + ret + +_fail: + li a0, FAILURE + ret + + .data + +MT_DATA +array_index: .dword 0; diff --git a/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/lrsc_d.S b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/lrsc_d.S new file mode 100644 index 000000000..fc07783b7 --- /dev/null +++ b/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/lrsc_d.S @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2018, Cornell University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * Neither the name of Cornell University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Tuan Ta + */ + +//------------------------------------------------------------------------ +// This code tests lr.d and sc.d instructions in multi-threading system. +// All threads execute a critical section LOOP_COUNT times. A thread +// gets into a critical section by acquiring a lock variable (i.e., +// shared_var) and checking return value. +// 0 means the lock is not being locked. Each thread increments +// a variable (i.e., var) inside the critical section and releases the +// lock by swapping back 0 to the lock variable. +// The master thread (i.e., thread 0) waits for all threads to complete +// and compare the var's value to the expected result. +//------------------------------------------------------------------------ + +#include "riscv_test.h" +#include "test_macros.h" +#include "test_macros_mt.h" + + RVTEST_RV64U + RVTEST_CODE_BEGIN + +#define LOOP_COUNT 1000 +#define RESULT NUM_THREADS * LOOP_COUNT + +//------------------------------------------------------------------------ +// Master thread creates new threads, waits for all threads to complete, +// deallocates threads and checks result +//------------------------------------------------------------------------ + call _create_threads + call _join + call _delete_threads + call _check + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// mt_test function executed in child threads +// A child thread signals its completion by atomicaly adding 1 to barrier +//------------------------------------------------------------------------ +_mt_test: + li t0, 1 // initialize the swap value (1-locked) + li t1, LOOP_COUNT + la t2, var // load the var's address + la a0, shared_var + +1: + lr.d.aq s2, (a0) // load and reserve a0 + bnez s2, 1b // retry lr if the lock is being held + sc.d.rl s2, t0, (a0) // try to lock a0 + bnez s2, 1b // retry if sc failed + + lw t3, (t2) // load the var's value + addi t3, t3, 1 // add 1 to the value + sw t3, (t2) // store the new value to var + + sd zero, (a0) // release the lock by storing 0 to a0 + + addi t1, t1, -1 // decrement the loop_count + bnez t1, 1b // repeat if not done yet + + la a0, barrier + amoadd.d zero, t0, (a0) // signal this thread's completion + + RVTEST_CODE_END + +//------------------------------------------------------------------------ +// Master thread checks result +//------------------------------------------------------------------------ +_check: + la a0, var + li a1, RESULT + ld a0, (a0) + bne a0, a1, _fail + li a0, SUCCESS + ret + +_fail: + li a0, FAILURE + ret + + .data + +MT_DATA +var: .dword 0 |