100e64fdaSTaylor Simpson /*
200e64fdaSTaylor Simpson * Copyright(c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
300e64fdaSTaylor Simpson *
400e64fdaSTaylor Simpson * This program is free software; you can redistribute it and/or modify
500e64fdaSTaylor Simpson * it under the terms of the GNU General Public License as published by
600e64fdaSTaylor Simpson * the Free Software Foundation; either version 2 of the License, or
700e64fdaSTaylor Simpson * (at your option) any later version.
800e64fdaSTaylor Simpson *
900e64fdaSTaylor Simpson * This program is distributed in the hope that it will be useful,
1000e64fdaSTaylor Simpson * but WITHOUT ANY WARRANTY; without even the implied warranty of
1100e64fdaSTaylor Simpson * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1200e64fdaSTaylor Simpson * GNU General Public License for more details.
1300e64fdaSTaylor Simpson *
1400e64fdaSTaylor Simpson * You should have received a copy of the GNU General Public License
1500e64fdaSTaylor Simpson * along with this program; if not, see <http://www.gnu.org/licenses/>.
1600e64fdaSTaylor Simpson */
1700e64fdaSTaylor Simpson
1800e64fdaSTaylor Simpson /*
1900e64fdaSTaylor Simpson * Test instructions where the semantics write to the destination
2000e64fdaSTaylor Simpson * before all the operand reads have been completed.
2100e64fdaSTaylor Simpson *
2200e64fdaSTaylor Simpson * These instructions are problematic when we short-circuit the
2300e64fdaSTaylor Simpson * register writes because the destination and source operands could
2400e64fdaSTaylor Simpson * be the same TCGv.
2500e64fdaSTaylor Simpson *
2600e64fdaSTaylor Simpson * We test by forcing the read and write to be register r7.
2700e64fdaSTaylor Simpson */
2800e64fdaSTaylor Simpson
2900e64fdaSTaylor Simpson #include <stdint.h>
3000e64fdaSTaylor Simpson #include <stdlib.h>
3100e64fdaSTaylor Simpson #include <stdio.h>
3200e64fdaSTaylor Simpson
3300e64fdaSTaylor Simpson int err;
3400e64fdaSTaylor Simpson
350d57cd61STaylor Simpson #include "hex_test.h"
3600e64fdaSTaylor Simpson
3700e64fdaSTaylor Simpson #define insert(RES, X, WIDTH, OFFSET) \
3800e64fdaSTaylor Simpson asm("r7 = %1\n\t" \
3900e64fdaSTaylor Simpson "r7 = insert(r7, #" #WIDTH ", #" #OFFSET ")\n\t" \
4000e64fdaSTaylor Simpson "%0 = r7\n\t" \
4100e64fdaSTaylor Simpson : "=r"(RES) : "r"(X) : "r7")
4200e64fdaSTaylor Simpson
test_insert(void)4300e64fdaSTaylor Simpson static void test_insert(void)
4400e64fdaSTaylor Simpson {
4500e64fdaSTaylor Simpson uint32_t res;
4600e64fdaSTaylor Simpson
4700e64fdaSTaylor Simpson insert(res, 0x12345678, 8, 1);
480d57cd61STaylor Simpson check32(res, 0x123456f0);
4900e64fdaSTaylor Simpson insert(res, 0x12345678, 0, 1);
500d57cd61STaylor Simpson check32(res, 0x12345678);
5100e64fdaSTaylor Simpson insert(res, 0x12345678, 20, 16);
520d57cd61STaylor Simpson check32(res, 0x56785678);
5300e64fdaSTaylor Simpson }
5400e64fdaSTaylor Simpson
insert_rp(uint32_t x,uint32_t width,uint32_t offset)5500e64fdaSTaylor Simpson static inline uint32_t insert_rp(uint32_t x, uint32_t width, uint32_t offset)
5600e64fdaSTaylor Simpson {
5700e64fdaSTaylor Simpson uint64_t width_offset = (uint64_t)width << 32 | offset;
5800e64fdaSTaylor Simpson uint32_t res;
5900e64fdaSTaylor Simpson asm("r7 = %1\n\t"
6000e64fdaSTaylor Simpson "r7 = insert(r7, %2)\n\t"
6100e64fdaSTaylor Simpson "%0 = r7\n\t"
6200e64fdaSTaylor Simpson : "=r"(res) : "r"(x), "r"(width_offset) : "r7");
6300e64fdaSTaylor Simpson return res;
6400e64fdaSTaylor Simpson
6500e64fdaSTaylor Simpson }
6600e64fdaSTaylor Simpson
test_insert_rp(void)6700e64fdaSTaylor Simpson static void test_insert_rp(void)
6800e64fdaSTaylor Simpson {
690d57cd61STaylor Simpson check32(insert_rp(0x12345678, 8, 1), 0x123456f0);
700d57cd61STaylor Simpson check32(insert_rp(0x12345678, 63, 8), 0x34567878);
710d57cd61STaylor Simpson check32(insert_rp(0x12345678, 127, 8), 0x34567878);
720d57cd61STaylor Simpson check32(insert_rp(0x12345678, 8, 24), 0x78345678);
730d57cd61STaylor Simpson check32(insert_rp(0x12345678, 8, 63), 0x12345678);
740d57cd61STaylor Simpson check32(insert_rp(0x12345678, 8, 64), 0x00000000);
7500e64fdaSTaylor Simpson }
7600e64fdaSTaylor Simpson
asr_r_svw_trun(uint64_t x,uint32_t y)7700e64fdaSTaylor Simpson static inline uint32_t asr_r_svw_trun(uint64_t x, uint32_t y)
7800e64fdaSTaylor Simpson {
7900e64fdaSTaylor Simpson uint32_t res;
8000e64fdaSTaylor Simpson asm("r7 = %2\n\t"
8100e64fdaSTaylor Simpson "r7 = vasrw(%1, r7)\n\t"
8200e64fdaSTaylor Simpson "%0 = r7\n\t"
8300e64fdaSTaylor Simpson : "=r"(res) : "r"(x), "r"(y) : "r7");
8400e64fdaSTaylor Simpson return res;
8500e64fdaSTaylor Simpson }
8600e64fdaSTaylor Simpson
test_asr_r_svw_trun(void)8700e64fdaSTaylor Simpson static void test_asr_r_svw_trun(void)
8800e64fdaSTaylor Simpson {
890d57cd61STaylor Simpson check32(asr_r_svw_trun(0x1111111122222222ULL, 5),
9000e64fdaSTaylor Simpson 0x88881111);
910d57cd61STaylor Simpson check32(asr_r_svw_trun(0x1111111122222222ULL, 63),
9200e64fdaSTaylor Simpson 0x00000000);
930d57cd61STaylor Simpson check32(asr_r_svw_trun(0x1111111122222222ULL, 64),
9400e64fdaSTaylor Simpson 0x00000000);
950d57cd61STaylor Simpson check32(asr_r_svw_trun(0x1111111122222222ULL, 127),
9600e64fdaSTaylor Simpson 0x22224444);
970d57cd61STaylor Simpson check32(asr_r_svw_trun(0x1111111122222222ULL, 128),
9800e64fdaSTaylor Simpson 0x11112222);
990d57cd61STaylor Simpson check32(asr_r_svw_trun(0xffffffff22222222ULL, 128),
10000e64fdaSTaylor Simpson 0xffff2222);
10100e64fdaSTaylor Simpson }
10200e64fdaSTaylor Simpson
swiz(uint32_t x)10300e64fdaSTaylor Simpson static inline uint32_t swiz(uint32_t x)
10400e64fdaSTaylor Simpson {
10500e64fdaSTaylor Simpson uint32_t res;
10600e64fdaSTaylor Simpson asm("r7 = %1\n\t"
10700e64fdaSTaylor Simpson "r7 = swiz(r7)\n\t"
10800e64fdaSTaylor Simpson "%0 = r7\n\t"
10900e64fdaSTaylor Simpson : "=r"(res) : "r"(x) : "r7");
11000e64fdaSTaylor Simpson return res;
11100e64fdaSTaylor Simpson }
11200e64fdaSTaylor Simpson
test_swiz(void)11300e64fdaSTaylor Simpson static void test_swiz(void)
11400e64fdaSTaylor Simpson {
1150d57cd61STaylor Simpson check32(swiz(0x11223344), 0x44332211);
11600e64fdaSTaylor Simpson }
11700e64fdaSTaylor Simpson
main()11800e64fdaSTaylor Simpson int main()
11900e64fdaSTaylor Simpson {
12000e64fdaSTaylor Simpson test_insert();
12100e64fdaSTaylor Simpson test_insert_rp();
12200e64fdaSTaylor Simpson test_asr_r_svw_trun();
12300e64fdaSTaylor Simpson test_swiz();
12400e64fdaSTaylor Simpson
12500e64fdaSTaylor Simpson puts(err ? "FAIL" : "PASS");
12600e64fdaSTaylor Simpson return err ? EXIT_FAILURE : EXIT_SUCCESS;
12700e64fdaSTaylor Simpson }
128