summaryrefslogtreecommitdiff
path: root/tests/test-progs/asmtest/src/riscv/isa/rv64uamt/amoxor_d.S
blob: 6650e452ad3cd70001cfe2e89119d481ff1f13ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * Copyright (c) 2018, Cornell University
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided
 * with the distribution.
 *
 * Neither the name of Cornell University nor the names of its
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * Authors: Tuan Ta
 */

//------------------------------------------------------------------------
// This code tests amoxor_d instruction in multi-threading system.
// All threads execute an amoxor_w instruction.
// Master thread (i.e., thread 0) waits for all threads to complete by
// spinning on the barrier variable until all threads update the variable.
// Then, the master thread checks the shared variable's value.
//------------------------------------------------------------------------

#include "riscv_test.h"
#include "test_macros.h"
#include "test_macros_mt.h"

  RVTEST_RV64U
  RVTEST_CODE_BEGIN

#define RESULT      0xCC998005AF423451

//------------------------------------------------------------------------
// Master thread creates new threads, waits for all threads to complete,
// deallocates threads and checks result
//------------------------------------------------------------------------
  call _create_threads
  call _join
  call _delete_threads
  call _check

  RVTEST_CODE_END

//------------------------------------------------------------------------
// mt_test function executed in child threads
// A child thread signals its completion by atomicaly adding 1 to barrier
//------------------------------------------------------------------------
_mt_test:
  la        a0, shared_var
  la        t0, array_index
  li        t1, 8
  amoadd.d  t1, t1, (t0)        // get my array_index

  la        t0, array
  add       t0, t0, t1
  ld        t0, (t0)            // get array[array_index]

  amoxor.d  zero, t0, (a0)

  li        t0, 1
  la        a0, barrier
  amoadd.d  zero, t0, (a0)

  RVTEST_CODE_END

//------------------------------------------------------------------------
// Master thread checks result
//------------------------------------------------------------------------
_check:
  la        a0, shared_var
  li        a1, RESULT
  ld        a0, (a0)
  bne       a0, a1, _fail
  li        a0, SUCCESS
  ret

_fail:
  li        a0, FAILURE
  ret

  .data

MT_DATA
array_index:    .dword    0;