amomax_d.S revision 12771
110263Satgutier@umich.edu/*
210941Sdavid.guillen@arm.com * Copyright (c) 2018, Cornell University
310263Satgutier@umich.edu * All rights reserved.
410263Satgutier@umich.edu *
510263Satgutier@umich.edu * Redistribution and use in source and binary forms, with or
610263Satgutier@umich.edu * without modification, are permitted provided that the following
710263Satgutier@umich.edu * conditions are met:
810263Satgutier@umich.edu *
910263Satgutier@umich.edu * Redistributions of source code must retain the above copyright
1010263Satgutier@umich.edu * notice, this list of conditions and the following disclaimer.
1110263Satgutier@umich.edu *
1210263Satgutier@umich.edu * Redistributions in binary form must reproduce the above
1310263Satgutier@umich.edu * copyright notice, this list of conditions and the following
1410263Satgutier@umich.edu * disclaimer in the documentation and/or other materials provided
1510263Satgutier@umich.edu * with the distribution.
1610263Satgutier@umich.edu *
1710263Satgutier@umich.edu * Neither the name of Cornell University nor the names of its
1810263Satgutier@umich.edu * contributors may be used to endorse or promote products derived
1910263Satgutier@umich.edu * from this software without specific prior written permission.
2010263Satgutier@umich.edu *
2110263Satgutier@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
2210263Satgutier@umich.edu * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
2310263Satgutier@umich.edu * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
2410263Satgutier@umich.edu * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2510263Satgutier@umich.edu * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
2610263Satgutier@umich.edu * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2710263Satgutier@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2810263Satgutier@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2910263Satgutier@umich.edu * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
3010263Satgutier@umich.edu * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3110263Satgutier@umich.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
3210263Satgutier@umich.edu * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3310263Satgutier@umich.edu * POSSIBILITY OF SUCH DAMAGE.
3410263Satgutier@umich.edu *
3510263Satgutier@umich.edu * Authors: Tuan Ta
3610263Satgutier@umich.edu */
3710263Satgutier@umich.edu
3810263Satgutier@umich.edu//------------------------------------------------------------------------
3910263Satgutier@umich.edu// This code tests amomax_d instruction in multi-threading system.
4010263Satgutier@umich.edu// All threads execute an amomax_w instruction.
4110263Satgutier@umich.edu// Master thread (i.e., thread 0) waits for all threads to complete by
4210263Satgutier@umich.edu// spinning on the barrier variable until all threads update the variable.
4310263Satgutier@umich.edu// Then, the master thread checks the shared variable's value.
4410263Satgutier@umich.edu//------------------------------------------------------------------------
4510263Satgutier@umich.edu
4610263Satgutier@umich.edu#include "riscv_test.h"
4710263Satgutier@umich.edu#include "test_macros.h"
4810263Satgutier@umich.edu#include "test_macros_mt.h"
4910263Satgutier@umich.edu
5010263Satgutier@umich.edu  RVTEST_RV64U
5110263Satgutier@umich.edu  RVTEST_CODE_BEGIN
5210263Satgutier@umich.edu
5310263Satgutier@umich.edu#define RESULT      0x12343eeaaf423451
5410263Satgutier@umich.edu
5510263Satgutier@umich.edu//------------------------------------------------------------------------
5610263Satgutier@umich.edu// Reinitialize shared_var to 0x8000000000000000
5710263Satgutier@umich.edu//------------------------------------------------------------------------
5810263Satgutier@umich.edu  la  a0, shared_var
5910263Satgutier@umich.edu  li  t0, 0x8000000000000000
6010263Satgutier@umich.edu  sd  t0, (a0)
6110263Satgutier@umich.edu
6210263Satgutier@umich.edu//------------------------------------------------------------------------
6310263Satgutier@umich.edu// Master thread creates new threads, waits for all threads to complete,
6410263Satgutier@umich.edu// deallocates threads and checks result
6510263Satgutier@umich.edu//------------------------------------------------------------------------
6610263Satgutier@umich.edu  call _create_threads
6710263Satgutier@umich.edu  call _join
6810263Satgutier@umich.edu  call _delete_threads
6910263Satgutier@umich.edu  call _check
7010263Satgutier@umich.edu
7110263Satgutier@umich.edu  RVTEST_CODE_END
7210263Satgutier@umich.edu
7310263Satgutier@umich.edu//------------------------------------------------------------------------
7410263Satgutier@umich.edu// mt_test function executed in child threads
7510263Satgutier@umich.edu// A child thread signals its completion by atomicaly adding 1 to barrier
7610263Satgutier@umich.edu//------------------------------------------------------------------------
7710263Satgutier@umich.edu_mt_test:
7810263Satgutier@umich.edu  la        a0, shared_var
7910263Satgutier@umich.edu  la        t0, array_index
8010263Satgutier@umich.edu  li        t1, 8
8110263Satgutier@umich.edu  amoadd.d  t1, t1, (t0)        // get my array_index
8210263Satgutier@umich.edu
8310263Satgutier@umich.edu  la        t0, array
8410263Satgutier@umich.edu  add       t0, t0, t1
8510263Satgutier@umich.edu  ld        t0, (t0)            // get array[array_index]
8610263Satgutier@umich.edu
8710263Satgutier@umich.edu  amomax.d  zero, t0, (a0)
8810263Satgutier@umich.edu
8910263Satgutier@umich.edu  li        t0, 1
9010941Sdavid.guillen@arm.com  la        a0, barrier
9110941Sdavid.guillen@arm.com  amoadd.d  zero, t0, (a0)
9210263Satgutier@umich.edu
9310263Satgutier@umich.edu  RVTEST_CODE_END
9410263Satgutier@umich.edu
9510263Satgutier@umich.edu//------------------------------------------------------------------------
9610263Satgutier@umich.edu// Master thread checks result
9710263Satgutier@umich.edu//------------------------------------------------------------------------
9810263Satgutier@umich.edu_check:
9910263Satgutier@umich.edu  la        a0, shared_var
10010263Satgutier@umich.edu  li        a1, RESULT
10110263Satgutier@umich.edu  ld        a0, (a0)
10210263Satgutier@umich.edu  bne       a0, a1, _fail
10310263Satgutier@umich.edu  li        a0, SUCCESS
10410263Satgutier@umich.edu  ret
10510263Satgutier@umich.edu
10610263Satgutier@umich.edu_fail:
10710263Satgutier@umich.edu  li        a0, FAILURE
10810263Satgutier@umich.edu  ret
10910263Satgutier@umich.edu
11010263Satgutier@umich.edu  .data
11110263Satgutier@umich.edu
11210263Satgutier@umich.eduMT_DATA
11310263Satgutier@umich.eduarray_index:    .dword    0;
11410263Satgutier@umich.edu