xref: /openbmc/qemu/tests/tcg/hexagon/dual_stores.c (revision 7d87775f)
1 /*
2  *  Copyright(c) 2019-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <stdio.h>
19 #include <stdint.h>
20 
21 int err;
22 
23 #include "hex_test.h"
24 
25 /*
26  *  Make sure that two stores in the same packet honor proper
27  *  semantics: slot 1 executes first, then slot 0.
28  *  This is important when the addresses overlap.
29  */
30 static inline void dual_stores(int32_t *p, int8_t *q, int32_t x, int8_t y)
31 {
32   asm volatile("{\n\t"
33                "    memw(%0) = %2\n\t"
34                "    memb(%1) = %3\n\t"
35                "}\n"
36                :: "r"(p), "r"(q), "r"(x), "r"(y)
37                : "memory");
38 }
39 
40 typedef union {
41     int32_t word;
42     int8_t byte;
43 } Dual;
44 
45 int main()
46 {
47     Dual d;
48 
49     d.word = ~0;
50     dual_stores(&d.word, &d.byte, 0x12345678, 0xff);
51     check32(d.word, 0x123456ff);
52 
53     puts(err ? "FAIL" : "PASS");
54     return err;
55 }
56