4 typedef signed int Int
;
5 typedef unsigned int UInt
;
7 __attribute__((noinline
)) UInt
do_udiv32 ( UInt x
, UInt y
)
11 "mov r9, %1 ; mov r10, %2 ; udiv r3,r9,r10 ; mov %0, r3"
12 : "=r"(res
) : "r"(x
), "r"(y
) : "r3", "r9", "r10"
17 __attribute__((noinline
)) Int
do_sdiv32 ( Int x
, Int y
)
21 "mov r9, %1 ; mov r10, %2 ; sdiv r3,r9,r10 ; mov %0, r3"
22 : "=r"(res
) : "r"(x
), "r"(y
) : "r3", "r9", "r10"
27 void test ( UInt x
, UInt y
)
29 UInt ru
= do_udiv32(x
,y
);
30 Int rs
= do_sdiv32(x
,y
);
31 printf( "%08x %08x -> u:%08x s:%08x\n", x
, y
, ru
, (UInt
)rs
);
36 // Check basic operation
41 // Check for rounding towards zero
42 test( 100, 7 ); // 14.285
46 // Division by zero produces zero
50 test( 0x80000000, 0 );
51 test( 0x7FFFFFFF, 0 );
52 // Test signed range ends
53 test( 0x80000000, -1 ); // unrepresentable as signed 32