Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / tests / tcg / sh4 / test-macw.c
blob4eceec8634bbbba6e5b2d0a9f0d07d77591c47c1
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #include <stdint.h>
4 #include <stdlib.h>
5 #include <stdio.h>
7 int64_t mac_w(int64_t mac, const int16_t *a, const int16_t *b)
9 register uint32_t macl __asm__("macl") = mac;
10 register uint32_t mach __asm__("mach") = mac >> 32;
12 asm volatile("mac.w @%0+,@%1+"
13 : "+r"(a), "+r"(b), "+x"(macl), "+x"(mach));
15 return ((uint64_t)mach << 32) | macl;
18 typedef struct {
19 int64_t mac;
20 int16_t a, b;
21 int64_t res[2];
22 } Test;
24 __attribute__((noinline))
25 void test(const Test *t, int sat)
27 int64_t res;
29 if (sat) {
30 asm volatile("sets");
31 } else {
32 asm volatile("clrs");
34 res = mac_w(t->mac, &t->a, &t->b);
36 if (res != t->res[sat]) {
37 fprintf(stderr, "%#llx + (%#x * %#x) = %#llx -- got %#llx\n",
38 t->mac, t->a, t->b, t->res[sat], res);
39 abort();
43 int main()
45 static const Test tests[] = {
46 { 0, 2, 3, { 6, 6 } },
47 { 0x123456787ffffffell, 2, -3,
48 { 0x123456787ffffff8ll, 0x123456787ffffff8ll } },
49 { 0xabcdef127ffffffall, 2, 3,
50 { 0xabcdef1280000000ll, 0x000000017fffffffll } },
51 { 0xfffffffffll, INT16_MAX, INT16_MAX,
52 { 0x103fff0000ll, 0xf3fff0000ll } },
55 for (int i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i) {
56 for (int j = 0; j < 2; ++j) {
57 test(&tests[i], j);
60 return 0;