Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / tests / tcg / sh4 / test-macl.c
blobb66c854365acf8caf89b3ecf5fd7ae82840918c3
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #include <stdint.h>
4 #include <stdlib.h>
5 #include <stdio.h>
7 #define MACL_S_MIN (-(1ll << 47))
8 #define MACL_S_MAX ((1ll << 47) - 1)
10 int64_t mac_l(int64_t mac, const int32_t *a, const int32_t *b)
12 register uint32_t macl __asm__("macl") = mac;
13 register uint32_t mach __asm__("mach") = mac >> 32;
15 asm volatile("mac.l @%0+,@%1+"
16 : "+r"(a), "+r"(b), "+x"(macl), "+x"(mach));
18 return ((uint64_t)mach << 32) | macl;
21 typedef struct {
22 int64_t mac;
23 int32_t a, b;
24 int64_t res[2];
25 } Test;
27 __attribute__((noinline))
28 void test(const Test *t, int sat)
30 int64_t res;
32 if (sat) {
33 asm volatile("sets");
34 } else {
35 asm volatile("clrs");
37 res = mac_l(t->mac, &t->a, &t->b);
39 if (res != t->res[sat]) {
40 fprintf(stderr, "%#llx + (%#x * %#x) = %#llx -- got %#llx\n",
41 t->mac, t->a, t->b, t->res[sat], res);
42 abort();
46 int main()
48 static const Test tests[] = {
49 { 0x00007fff12345678ll, INT32_MAX, INT32_MAX,
50 { 0x40007ffe12345679ll, MACL_S_MAX } },
51 { MACL_S_MIN, -1, 1,
52 { 0xffff7fffffffffffll, MACL_S_MIN } },
53 { INT64_MIN, -1, 1,
54 { INT64_MAX, MACL_S_MIN } },
55 { 0x00007fff00000000ll, INT32_MAX, INT32_MAX,
56 { 0x40007ffe00000001ll, MACL_S_MAX } },
57 { 4, 1, 2, { 6, 6 } },
58 { -4, -1, -2, { -2, -2 } },
61 for (int i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i) {
62 for (int j = 0; j < 2; ++j) {
63 test(&tests[i], j);
66 return 0;