2 * Test R5900-specific DIV1.
9 struct quotient_remainder
{ int32_t quotient
, remainder
; };
11 static struct quotient_remainder
div1(int32_t rs
, int32_t rt
)
15 __asm__
__volatile__ (
19 : "=r" (lo
), "=r" (hi
)
20 : "r" (rs
), "r" (rt
));
22 assert(rs
/ rt
== lo
);
23 assert(rs
% rt
== hi
);
25 return (struct quotient_remainder
) { .quotient
= lo
, .remainder
= hi
};
28 static void verify_div1(int32_t rs
, int32_t rt
,
29 int32_t expected_quotient
,
30 int32_t expected_remainder
)
32 struct quotient_remainder qr
= div1(rs
, rt
);
34 assert(qr
.quotient
== expected_quotient
);
35 assert(qr
.remainder
== expected_remainder
);
38 static void verify_div1_negations(int32_t rs
, int32_t rt
,
39 int32_t expected_quotient
,
40 int32_t expected_remainder
)
42 verify_div1(rs
, rt
, expected_quotient
, expected_remainder
);
43 verify_div1(rs
, -rt
, -expected_quotient
, expected_remainder
);
44 verify_div1(-rs
, rt
, -expected_quotient
, -expected_remainder
);
45 verify_div1(-rs
, -rt
, expected_quotient
, -expected_remainder
);
50 verify_div1_negations(0, 1, 0, 0);
51 verify_div1_negations(1, 1, 1, 0);
52 verify_div1_negations(1, 2, 0, 1);
53 verify_div1_negations(17, 19, 0, 17);
54 verify_div1_negations(19, 17, 1, 2);
55 verify_div1_negations(77773, 101, 770, 3);
57 verify_div1(-0x80000000, 1, -0x80000000, 0);
60 * Supplementary explanation from the Toshiba TX System RISC TX79 Core
61 * Architecture manual, A-38 and B-7, https://wiki.qemu.org/File:C790.pdf
63 * Normally, when 0x80000000 (-2147483648) the signed minimum value is
64 * divided by 0xFFFFFFFF (-1), the operation will result in an overflow.
65 * However, in this instruction an overflow exception doesn't occur and
66 * the result will be as follows:
68 * Quotient is 0x80000000 (-2147483648), and remainder is 0x00000000 (0).
70 verify_div1(-0x80000000, -1, -0x80000000, 0);