1 /* SPDX-License-Identifier: GPL-2.0-or-later */
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
;
27 __attribute__((noinline
))
28 void test(const Test
*t
, int sat
)
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
);
48 static const Test tests
[] = {
49 { 0x00007fff12345678ll
, INT32_MAX
, INT32_MAX
,
50 { 0x40007ffe12345679ll
, MACL_S_MAX
} },
52 { 0xffff7fffffffffffll
, MACL_S_MIN
} },
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
) {