1/* 2 * Copyright (c) 2018, Cornell University 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or 6 * without modification, are permitted provided that the following 7 * conditions are met: 8 * 9 * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * Redistributions in binary form must reproduce the above 13 * copyright notice, this list of conditions and the following 14 * disclaimer in the documentation and/or other materials provided 15 * with the distribution. 16 * 17 * Neither the name of Cornell University nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 22 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 23 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 29 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 * POSSIBILITY OF SUCH DAMAGE. 34 * 35 * Authors: Tuan Ta 36 */ 37 38//------------------------------------------------------------------------ 39// This code tests amoxor_d instruction in multi-threading system. 40// All threads execute an amoxor_w instruction. 41// Master thread (i.e., thread 0) waits for all threads to complete by 42// spinning on the barrier variable until all threads update the variable. 43// Then, the master thread checks the shared variable's value. 44//------------------------------------------------------------------------ 45 46#include "riscv_test.h" 47#include "test_macros.h" 48#include "test_macros_mt.h" 49 50 RVTEST_RV64U 51 RVTEST_CODE_BEGIN 52 53#define RESULT 0xCC998005AF423451 54 55//------------------------------------------------------------------------ 56// Master thread creates new threads, waits for all threads to complete, 57// deallocates threads and checks result 58//------------------------------------------------------------------------ 59 call _create_threads 60 call _join 61 call _delete_threads 62 call _check 63 64 RVTEST_CODE_END 65 66//------------------------------------------------------------------------ 67// mt_test function executed in child threads 68// A child thread signals its completion by atomicaly adding 1 to barrier 69//------------------------------------------------------------------------ 70_mt_test: 71 la a0, shared_var 72 la t0, array_index 73 li t1, 8 74 amoadd.d t1, t1, (t0) // get my array_index 75 76 la t0, array 77 add t0, t0, t1 78 ld t0, (t0) // get array[array_index] 79 80 amoxor.d zero, t0, (a0) 81 82 li t0, 1 83 la a0, barrier 84 amoadd.d zero, t0, (a0) 85 86 RVTEST_CODE_END 87 88//------------------------------------------------------------------------ 89// Master thread checks result 90//------------------------------------------------------------------------ 91_check: 92 la a0, shared_var 93 li a1, RESULT 94 ld a0, (a0) 95 bne a0, a1, _fail 96 li a0, SUCCESS 97 ret 98 99_fail: 100 li a0, FAILURE 101 ret 102 103 .data 104 105MT_DATA 106array_index: .dword 0; 107