amoor_d.S revision 12771
16285Snate@binkert.org/* 26285Snate@binkert.org * Copyright (c) 2018, Cornell University 36285Snate@binkert.org * All rights reserved. 46285Snate@binkert.org * 56285Snate@binkert.org * Redistribution and use in source and binary forms, with or 66285Snate@binkert.org * without modification, are permitted provided that the following 76467Sdrh5@cs.wisc.edu * conditions are met: 86467Sdrh5@cs.wisc.edu * 96285Snate@binkert.org * Redistributions of source code must retain the above copyright 106285Snate@binkert.org * notice, this list of conditions and the following disclaimer. 116285Snate@binkert.org * 126285Snate@binkert.org * Redistributions in binary form must reproduce the above 136285Snate@binkert.org * copyright notice, this list of conditions and the following 146285Snate@binkert.org * disclaimer in the documentation and/or other materials provided 156285Snate@binkert.org * with the distribution. 166285Snate@binkert.org * 176285Snate@binkert.org * Neither the name of Cornell University nor the names of its 186285Snate@binkert.org * contributors may be used to endorse or promote products derived 196285Snate@binkert.org * from this software without specific prior written permission. 206285Snate@binkert.org * 216285Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 226285Snate@binkert.org * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 236285Snate@binkert.org * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 246285Snate@binkert.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 256285Snate@binkert.org * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 266285Snate@binkert.org * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 276285Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 286285Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 296285Snate@binkert.org * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 306285Snate@binkert.org * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 316368Sdrh5@cs.wisc.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 326285Snate@binkert.org * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 336285Snate@binkert.org * POSSIBILITY OF SUCH DAMAGE. 346285Snate@binkert.org * 356285Snate@binkert.org * Authors: Tuan Ta 366285Snate@binkert.org */ 376285Snate@binkert.org 386285Snate@binkert.org//------------------------------------------------------------------------ 396285Snate@binkert.org// This code tests amoor_d instruction in multi-threading system. 406285Snate@binkert.org// All threads execute an amoor_w instruction. 416285Snate@binkert.org// Master thread (i.e., thread 0) waits for all threads to complete by 426285Snate@binkert.org// spinning on the barrier variable until all threads update the variable. 436285Snate@binkert.org// Then, the master thread checks the shared variable's value. 446285Snate@binkert.org//------------------------------------------------------------------------ 456285Snate@binkert.org 466285Snate@binkert.org#include "riscv_test.h" 476285Snate@binkert.org#include "test_macros.h" 486285Snate@binkert.org#include "test_macros_mt.h" 496350Spdudnik@gmail.com 506350Spdudnik@gmail.com RVTEST_RV64U 516355Spdudnik@gmail.com RVTEST_CODE_BEGIN 526355Spdudnik@gmail.com 536433Sdrh5@cs.wisc.edu#define RESULT 0xDEBDBEEFFFEFBEFF 546285Snate@binkert.org 556285Snate@binkert.org//------------------------------------------------------------------------ 566285Snate@binkert.org// Master thread creates new threads, waits for all threads to complete, 576368Sdrh5@cs.wisc.edu// deallocates threads and checks result 586285Snate@binkert.org//------------------------------------------------------------------------ 596285Snate@binkert.org call _create_threads 606285Snate@binkert.org call _join 616285Snate@binkert.org call _delete_threads 626285Snate@binkert.org call _check 636285Snate@binkert.org 646285Snate@binkert.org RVTEST_CODE_END 656285Snate@binkert.org 666285Snate@binkert.org//------------------------------------------------------------------------ 676285Snate@binkert.org// mt_test function executed in child threads 686467Sdrh5@cs.wisc.edu// A child thread signals its completion by atomicaly adding 1 to barrier 696285Snate@binkert.org//------------------------------------------------------------------------ 706368Sdrh5@cs.wisc.edu_mt_test: 716467Sdrh5@cs.wisc.edu la a0, shared_var 726467Sdrh5@cs.wisc.edu la t0, array_index 736467Sdrh5@cs.wisc.edu li t1, 8 746368Sdrh5@cs.wisc.edu amoadd.d t1, t1, (t0) // get my array_index 756467Sdrh5@cs.wisc.edu 766467Sdrh5@cs.wisc.edu la t0, array 776467Sdrh5@cs.wisc.edu add t0, t0, t1 786285Snate@binkert.org ld t0, (t0) // get array[array_index] 796285Snate@binkert.org 806285Snate@binkert.org amoor.d zero, t0, (a0) 816285Snate@binkert.org 826285Snate@binkert.org li t0, 1 836285Snate@binkert.org la a0, barrier 846285Snate@binkert.org amoadd.d zero, t0, (a0) 856285Snate@binkert.org 866285Snate@binkert.org RVTEST_CODE_END 876285Snate@binkert.org 886285Snate@binkert.org//------------------------------------------------------------------------ 896285Snate@binkert.org// Master thread checks result 906285Snate@binkert.org//------------------------------------------------------------------------ 916285Snate@binkert.org_check: 926285Snate@binkert.org la a0, shared_var 936285Snate@binkert.org li a1, RESULT 946467Sdrh5@cs.wisc.edu ld a0, (a0) 956368Sdrh5@cs.wisc.edu bne a0, a1, _fail 966368Sdrh5@cs.wisc.edu li a0, SUCCESS 976368Sdrh5@cs.wisc.edu ret 986368Sdrh5@cs.wisc.edu 996467Sdrh5@cs.wisc.edu_fail: 1006467Sdrh5@cs.wisc.edu li a0, FAILURE 1016368Sdrh5@cs.wisc.edu ret 1026368Sdrh5@cs.wisc.edu 1036368Sdrh5@cs.wisc.edu .data 1046368Sdrh5@cs.wisc.edu 1056285Snate@binkert.orgMT_DATA 1066368Sdrh5@cs.wisc.eduarray_index: .dword 0; 1076368Sdrh5@cs.wisc.edu