2 * Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
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.
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.
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/>.
24 #define SIZE (1 << NBITS)
26 long long dbuf
[SIZE
] __attribute__((aligned(1 << 16))) = {0};
27 int wbuf
[SIZE
] __attribute__((aligned(1 << 16))) = {0};
28 short hbuf
[SIZE
] __attribute__((aligned(1 << 16))) = {0};
29 unsigned char bbuf
[SIZE
] __attribute__((aligned(1 << 16))) = {0};
32 * We use the C preporcessor to deal with the combinations of types
35 #define BREV_LOAD(SZ, RES, ADDR, INC) \
38 "%0 = mem" #SZ "(%1++m0:brev)\n\t" \
39 : "=r"(RES), "+r"(ADDR) \
43 #define BREV_LOAD_b(RES, ADDR, INC) \
44 BREV_LOAD(b, RES, ADDR, INC)
45 #define BREV_LOAD_ub(RES, ADDR, INC) \
46 BREV_LOAD(ub, RES, ADDR, INC)
47 #define BREV_LOAD_h(RES, ADDR, INC) \
48 BREV_LOAD(h, RES, ADDR, INC)
49 #define BREV_LOAD_uh(RES, ADDR, INC) \
50 BREV_LOAD(uh, RES, ADDR, INC)
51 #define BREV_LOAD_w(RES, ADDR, INC) \
52 BREV_LOAD(w, RES, ADDR, INC)
53 #define BREV_LOAD_d(RES, ADDR, INC) \
54 BREV_LOAD(d, RES, ADDR, INC)
56 #define BREV_STORE(SZ, PART, ADDR, VAL, INC) \
59 "mem" #SZ "(%0++m0:brev) = %1" PART "\n\t" \
61 : "r"(VAL), "r"(INC) \
64 #define BREV_STORE_b(ADDR, VAL, INC) \
65 BREV_STORE(b, "", ADDR, VAL, INC)
66 #define BREV_STORE_h(ADDR, VAL, INC) \
67 BREV_STORE(h, "", ADDR, VAL, INC)
68 #define BREV_STORE_f(ADDR, VAL, INC) \
69 BREV_STORE(h, ".H", ADDR, VAL, INC)
70 #define BREV_STORE_w(ADDR, VAL, INC) \
71 BREV_STORE(w, "", ADDR, VAL, INC)
72 #define BREV_STORE_d(ADDR, VAL, INC) \
73 BREV_STORE(d, "", ADDR, VAL, INC)
75 #define BREV_STORE_NEW(SZ, ADDR, VAL, INC) \
80 " mem" #SZ "(%0++m0:brev) = r5.new\n\t" \
83 : "r"(VAL), "r"(INC) \
84 : "r5", "m0", "memory")
86 #define BREV_STORE_bnew(ADDR, VAL, INC) \
87 BREV_STORE_NEW(b, ADDR, VAL, INC)
88 #define BREV_STORE_hnew(ADDR, VAL, INC) \
89 BREV_STORE_NEW(h, ADDR, VAL, INC)
90 #define BREV_STORE_wnew(ADDR, VAL, INC) \
91 BREV_STORE_NEW(w, ADDR, VAL, INC)
97 for (i
= 0; i
< NBITS
; i
++) {
107 return (x
<< 24) >> 24;
110 void check(int i
, long long result
, long long expect
)
112 if (result
!= expect
) {
113 printf("ERROR(%d): 0x%04llx != 0x%04llx\n", i
, result
, expect
);
118 #define TEST_BREV_LOAD(SZ, TYPE, BUF, SHIFT, EXP) \
121 for (i = 0; i < SIZE; i++) { \
123 BREV_LOAD_##SZ(result, p, 1 << (SHIFT - NBITS)); \
124 check(i, result, EXP); \
128 #define TEST_BREV_STORE(SZ, TYPE, BUF, VAL, SHIFT) \
131 memset(BUF, 0xff, sizeof(BUF)); \
132 for (i = 0; i < SIZE; i++) { \
133 BREV_STORE_##SZ(p, (TYPE)(VAL), 1 << (SHIFT - NBITS)); \
135 for (i = 0; i < SIZE; i++) { \
136 check(i, BUF[i], bitreverse(i)); \
140 #define TEST_BREV_STORE_NEW(SZ, BUF, SHIFT) \
143 memset(BUF, 0xff, sizeof(BUF)); \
144 for (i = 0; i < SIZE; i++) { \
145 BREV_STORE_##SZ(p, i, 1 << (SHIFT - NBITS)); \
147 for (i = 0; i < SIZE; i++) { \
148 check(i, BUF[i], bitreverse(i)); \
153 * We'll set high_half[i] = i << 16 for use in the .H form of store
154 * which stores from the high half of the word.
163 for (i
= 0; i
< SIZE
; i
++) {
164 bbuf
[i
] = bitreverse(i
);
165 hbuf
[i
] = bitreverse(i
);
166 wbuf
[i
] = bitreverse(i
);
167 dbuf
[i
] = bitreverse(i
);
168 high_half
[i
] = i
<< 16;
171 TEST_BREV_LOAD(b
, int, bbuf
, 16, sext8(i
));
172 TEST_BREV_LOAD(ub
, int, bbuf
, 16, i
);
173 TEST_BREV_LOAD(h
, int, hbuf
, 15, i
);
174 TEST_BREV_LOAD(uh
, int, hbuf
, 15, i
);
175 TEST_BREV_LOAD(w
, int, wbuf
, 14, i
);
176 TEST_BREV_LOAD(d
, long long, dbuf
, 13, i
);
178 TEST_BREV_STORE(b
, int, bbuf
, i
, 16);
179 TEST_BREV_STORE(h
, int, hbuf
, i
, 15);
180 TEST_BREV_STORE(f
, int, hbuf
, high_half
[i
], 15);
181 TEST_BREV_STORE(w
, int, wbuf
, i
, 14);
182 TEST_BREV_STORE(d
, long long, dbuf
, i
, 13);
184 TEST_BREV_STORE_NEW(bnew
, bbuf
, 16);
185 TEST_BREV_STORE_NEW(hnew
, hbuf
, 15);
186 TEST_BREV_STORE_NEW(wnew
, wbuf
, 14);
188 puts(err
? "FAIL" : "PASS");