amomax_d.S revision 12771:75508af5d8dc
112855Sgabeblack@google.com/* 212855Sgabeblack@google.com * Copyright (c) 2018, Cornell University 312855Sgabeblack@google.com * All rights reserved. 412855Sgabeblack@google.com * 512855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or 612855Sgabeblack@google.com * without modification, are permitted provided that the following 712855Sgabeblack@google.com * conditions are met: 812855Sgabeblack@google.com * 912855Sgabeblack@google.com * Redistributions of source code must retain the above copyright 1012855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer. 1112855Sgabeblack@google.com * 1212855Sgabeblack@google.com * Redistributions in binary form must reproduce the above 1312855Sgabeblack@google.com * copyright notice, this list of conditions and the following 1412855Sgabeblack@google.com * disclaimer in the documentation and/or other materials provided 1512855Sgabeblack@google.com * with the distribution. 1612855Sgabeblack@google.com * 1712855Sgabeblack@google.com * Neither the name of Cornell University nor the names of its 1812855Sgabeblack@google.com * contributors may be used to endorse or promote products derived 1912855Sgabeblack@google.com * from this software without specific prior written permission. 2012855Sgabeblack@google.com * 2112855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 2212855Sgabeblack@google.com * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 2312855Sgabeblack@google.com * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 2412855Sgabeblack@google.com * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 2512855Sgabeblack@google.com * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 2612855Sgabeblack@google.com * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2712855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2812855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 2912855Sgabeblack@google.com * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 3012855Sgabeblack@google.com * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3112855Sgabeblack@google.com * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 3212855Sgabeblack@google.com * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3312855Sgabeblack@google.com * POSSIBILITY OF SUCH DAMAGE. 3412855Sgabeblack@google.com * 3512855Sgabeblack@google.com * Authors: Tuan Ta 3612855Sgabeblack@google.com */ 3712855Sgabeblack@google.com 3812855Sgabeblack@google.com//------------------------------------------------------------------------ 3912855Sgabeblack@google.com// This code tests amomax_d instruction in multi-threading system. 4012855Sgabeblack@google.com// All threads execute an amomax_w instruction. 4112855Sgabeblack@google.com// Master thread (i.e., thread 0) waits for all threads to complete by 4212855Sgabeblack@google.com// spinning on the barrier variable until all threads update the variable. 4312855Sgabeblack@google.com// Then, the master thread checks the shared variable's value. 4412855Sgabeblack@google.com//------------------------------------------------------------------------ 4512855Sgabeblack@google.com 4612855Sgabeblack@google.com#include "riscv_test.h" 4712855Sgabeblack@google.com#include "test_macros.h" 4812855Sgabeblack@google.com#include "test_macros_mt.h" 4912855Sgabeblack@google.com 5012855Sgabeblack@google.com RVTEST_RV64U 5112855Sgabeblack@google.com RVTEST_CODE_BEGIN 5212855Sgabeblack@google.com 5312855Sgabeblack@google.com#define RESULT 0x12343eeaaf423451 5412855Sgabeblack@google.com 5512855Sgabeblack@google.com//------------------------------------------------------------------------ 5612855Sgabeblack@google.com// Reinitialize shared_var to 0x8000000000000000 5712855Sgabeblack@google.com//------------------------------------------------------------------------ 5812855Sgabeblack@google.com la a0, shared_var 5912855Sgabeblack@google.com li t0, 0x8000000000000000 6012855Sgabeblack@google.com sd t0, (a0) 6112855Sgabeblack@google.com 6212855Sgabeblack@google.com//------------------------------------------------------------------------ 6312855Sgabeblack@google.com// Master thread creates new threads, waits for all threads to complete, 6412855Sgabeblack@google.com// deallocates threads and checks result 6512855Sgabeblack@google.com//------------------------------------------------------------------------ 6612855Sgabeblack@google.com call _create_threads 6712855Sgabeblack@google.com call _join 6812855Sgabeblack@google.com call _delete_threads 6912855Sgabeblack@google.com call _check 7012855Sgabeblack@google.com 7112855Sgabeblack@google.com RVTEST_CODE_END 7212855Sgabeblack@google.com 7312855Sgabeblack@google.com//------------------------------------------------------------------------ 7412855Sgabeblack@google.com// mt_test function executed in child threads 7512855Sgabeblack@google.com// A child thread signals its completion by atomicaly adding 1 to barrier 76//------------------------------------------------------------------------ 77_mt_test: 78 la a0, shared_var 79 la t0, array_index 80 li t1, 8 81 amoadd.d t1, t1, (t0) // get my array_index 82 83 la t0, array 84 add t0, t0, t1 85 ld t0, (t0) // get array[array_index] 86 87 amomax.d zero, t0, (a0) 88 89 li t0, 1 90 la a0, barrier 91 amoadd.d zero, t0, (a0) 92 93 RVTEST_CODE_END 94 95//------------------------------------------------------------------------ 96// Master thread checks result 97//------------------------------------------------------------------------ 98_check: 99 la a0, shared_var 100 li a1, RESULT 101 ld a0, (a0) 102 bne a0, a1, _fail 103 li a0, SUCCESS 104 ret 105 106_fail: 107 li a0, FAILURE 108 ret 109 110 .data 111 112MT_DATA 113array_index: .dword 0; 114