| 1 | /* |
| 2 | * Test R5900-specific DIVU1. |
| 3 | */ |
| 4 | |
| 5 | #include <stdio.h> |
| 6 | #include <inttypes.h> |
| 7 | #include <assert.h> |
| 8 | |
| 9 | struct quotient_remainder { uint32_t quotient, remainder; }; |
| 10 | |
| 11 | static struct quotient_remainder divu1(uint32_t rs, uint32_t rt) |
| 12 | { |
| 13 | uint32_t lo, hi; |
| 14 | |
| 15 | __asm__ __volatile__ ( |
| 16 | " divu1 $0, %2, %3\n" |
| 17 | " mflo1 %0\n" |
| 18 | " mfhi1 %1\n" |
| 19 | : "=r" (lo), "=r" (hi) |
| 20 | : "r" (rs), "r" (rt)); |
| 21 | |
| 22 | assert(rs / rt == lo); |
| 23 | assert(rs % rt == hi); |
| 24 | |
| 25 | return (struct quotient_remainder) { .quotient = lo, .remainder = hi }; |
| 26 | } |
| 27 | |
| 28 | static void verify_divu1(uint32_t rs, uint32_t rt, |
| 29 | uint32_t expected_quotient, |
| 30 | uint32_t expected_remainder) |
| 31 | { |
| 32 | struct quotient_remainder qr = divu1(rs, rt); |
| 33 | |
| 34 | assert(qr.quotient == expected_quotient); |
| 35 | assert(qr.remainder == expected_remainder); |
| 36 | } |
| 37 | |
| 38 | int main() |
| 39 | { |
| 40 | verify_divu1(0, 1, 0, 0); |
| 41 | verify_divu1(1, 1, 1, 0); |
| 42 | verify_divu1(1, 2, 0, 1); |
| 43 | verify_divu1(17, 19, 0, 17); |
| 44 | verify_divu1(19, 17, 1, 2); |
| 45 | verify_divu1(77773, 101, 770, 3); |
| 46 | |
| 47 | return 0; |
| 48 | } |