Bug 497723 - forgot to restore callgrind output cleanup
[valgrind.git] / none / tests / arm / intdiv.c
blob264e2a8884cd11948c49d498bc5bdc5eb3128f79
2 #include <stdio.h>
4 typedef signed int Int;
5 typedef unsigned int UInt;
7 __attribute__((noinline)) UInt do_udiv32 ( UInt x, UInt y )
9 UInt res;
10 __asm__ __volatile__(
11 "mov r9, %1 ; mov r10, %2 ; udiv r3,r9,r10 ; mov %0, r3"
12 : "=r"(res) : "r"(x), "r"(y) : "r3", "r9", "r10"
14 return res;
17 __attribute__((noinline)) Int do_sdiv32 ( Int x, Int y )
19 UInt res;
20 __asm__ __volatile__(
21 "mov r9, %1 ; mov r10, %2 ; sdiv r3,r9,r10 ; mov %0, r3"
22 : "=r"(res) : "r"(x), "r"(y) : "r3", "r9", "r10"
24 return res;
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);
34 int main ( void )
36 // Check basic operation
37 test( 500, 50 );
38 test( 500, -50 );
39 test( -500, 50 );
40 test( -500, -50 );
41 // Check for rounding towards zero
42 test( 100, 7 ); // 14.285
43 test( -100, 7 );
44 test( 100, -7 );
45 test( -100, -7 );
46 // Division by zero produces zero
47 test( 1, 0 );
48 test( 0, 0 );
49 test( -1, 0 );
50 test( 0x80000000, 0 );
51 test( 0x7FFFFFFF, 0 );
52 // Test signed range ends
53 test( 0x80000000, -1 ); // unrepresentable as signed 32
54 return 0;