2 * Copyright(c) 2023 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/>.
19 * Test instructions where the semantics write to the destination
20 * before all the operand reads have been completed.
22 * These instructions are problematic when we short-circuit the
23 * register writes because the destination and source operands could
26 * We test by forcing the read and write to be register r7.
37 #define insert(RES, X, WIDTH, OFFSET) \
39 "r7 = insert(r7, #" #WIDTH ", #" #OFFSET ")\n\t" \
41 : "=r"(RES) : "r"(X) : "r7")
43 static void test_insert(void)
47 insert(res
, 0x12345678, 8, 1);
48 check32(res
, 0x123456f0);
49 insert(res
, 0x12345678, 0, 1);
50 check32(res
, 0x12345678);
51 insert(res
, 0x12345678, 20, 16);
52 check32(res
, 0x56785678);
55 static inline uint32_t insert_rp(uint32_t x
, uint32_t width
, uint32_t offset
)
57 uint64_t width_offset
= (uint64_t)width
<< 32 | offset
;
60 "r7 = insert(r7, %2)\n\t"
62 : "=r"(res
) : "r"(x
), "r"(width_offset
) : "r7");
67 static void test_insert_rp(void)
69 check32(insert_rp(0x12345678, 8, 1), 0x123456f0);
70 check32(insert_rp(0x12345678, 63, 8), 0x34567878);
71 check32(insert_rp(0x12345678, 127, 8), 0x34567878);
72 check32(insert_rp(0x12345678, 8, 24), 0x78345678);
73 check32(insert_rp(0x12345678, 8, 63), 0x12345678);
74 check32(insert_rp(0x12345678, 8, 64), 0x00000000);
77 static inline uint32_t asr_r_svw_trun(uint64_t x
, uint32_t y
)
81 "r7 = vasrw(%1, r7)\n\t"
83 : "=r"(res
) : "r"(x
), "r"(y
) : "r7");
87 static void test_asr_r_svw_trun(void)
89 check32(asr_r_svw_trun(0x1111111122222222ULL
, 5),
91 check32(asr_r_svw_trun(0x1111111122222222ULL
, 63),
93 check32(asr_r_svw_trun(0x1111111122222222ULL
, 64),
95 check32(asr_r_svw_trun(0x1111111122222222ULL
, 127),
97 check32(asr_r_svw_trun(0x1111111122222222ULL
, 128),
99 check32(asr_r_svw_trun(0xffffffff22222222ULL
, 128),
103 static inline uint32_t swiz(uint32_t x
)
109 : "=r"(res
) : "r"(x
) : "r7");
113 static void test_swiz(void)
115 check32(swiz(0x11223344), 0x44332211);
122 test_asr_r_svw_trun();
125 puts(err
? "FAIL" : "PASS");
126 return err
? EXIT_FAILURE
: EXIT_SUCCESS
;