54bc32125ba806c2a012017ff220bad60e58ffd7
[gem5.git] / tests / test-progs / asmtest / src / riscv / isa / rv64uamt / amomax_d.S
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 amomax_d instruction in multi-threading system.
40 // All threads execute an amomax_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 0x12343eeaaf423451
54
55 //------------------------------------------------------------------------
56 // Reinitialize shared_var to 0x8000000000000000
57 //------------------------------------------------------------------------
58 la a0, shared_var
59 li t0, 0x8000000000000000
60 sd t0, (a0)
61
62 //------------------------------------------------------------------------
63 // Master thread creates new threads, waits for all threads to complete,
64 // deallocates threads and checks result
65 //------------------------------------------------------------------------
66 call _create_threads
67 call _join
68 call _delete_threads
69 call _check
70
71 RVTEST_CODE_END
72
73 //------------------------------------------------------------------------
74 // mt_test function executed in child threads
75 // 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
112 MT_DATA
113 array_index: .dword 0;