fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / machine / h8500 / divsi3.c
blobe19855d0a88d20277db4b2d09193335f34048daa
2 #define divnorm(num, den, sign) \
3 { \
4 if (num < 0) \
5 { \
6 num = -num; \
7 sign = 1; \
8 } \
9 else \
10 { \
11 sign = 0; \
12 } \
14 if (den < 0) \
15 { \
16 den = - den; \
17 sign = 1 - sign; \
18 } \
25 unsigned long
26 divmodsi4(int modwanted, unsigned long num, unsigned long den)
28 long int bit = 1;
29 long int res = 0;
30 long prevden;
31 while (den < num && bit && !(den & (1L<<31)))
33 den <<=1;
34 bit <<=1;
36 while (bit)
38 if (num >= den)
40 num -= den;
41 res |= bit;
43 bit >>=1;
44 den >>=1;
46 if (modwanted) return num;
47 return res;
51 #define exitdiv(sign, res) if (sign) { res = - res;} return res;
53 long
54 __modsi3 (long numerator, long denominator)
56 int sign = 0;
57 long dividend;
58 long modul;
61 if (numerator < 0)
63 numerator = -numerator;
64 sign = 1;
66 if (denominator < 0)
68 denominator = -denominator;
71 modul = divmodsi4 (1, numerator, denominator);
72 if (sign)
73 return - modul;
74 return modul;
78 long
79 __divsi3 (long numerator, long denominator)
81 int sign;
82 long dividend;
83 long modul;
84 divnorm (numerator, denominator, sign);
86 dividend = divmodsi4 (0, numerator, denominator);
87 exitdiv (sign, dividend);
90 long
91 __umodsi3 (unsigned long numerator, unsigned long denominator)
93 long dividend;
94 long modul;
96 modul= divmodsi4 (1, numerator, denominator);
97 return modul;
100 long
101 __udivsi3 (unsigned long numerator, unsigned long denominator)
103 int sign;
104 long dividend;
105 long modul;
106 dividend = divmodsi4 (0, numerator, denominator);
107 return dividend;
115 #ifdef TEST
119 main ()
121 long int i, j, k, m;
122 for (i = -10000; i < 10000; i += 8)
124 for (j = -10000; j < 10000; j += 11)
126 k = i / j;
127 m = __divsi3 (i, j);
128 if (k != m)
129 printf ("fail %d %d %d %d\n", i, j, k, m);
134 #endif