00001 typedef int HItype __attribute__ ((mode (HI)));
00002 typedef int SItype __attribute__ ((mode (SI)));
00003 typedef unsigned int USItype __attribute__ ((mode (SI)));
00004
00005 typedef int word_type __attribute__ ((mode (__word__)));
00006
00007 USItype
00008 udivmodsi4(USItype num, USItype den, word_type modwanted)
00009 {
00010 USItype bit = 1;
00011 USItype res = 0;
00012
00013 while (den < num && bit && !(den & (1L<<31)))
00014 {
00015 den <<=1;
00016 bit <<=1;
00017 }
00018 while (bit)
00019 {
00020 if (num >= den)
00021 {
00022 num -= den;
00023 res |= bit;
00024 }
00025 bit >>=1;
00026 den >>=1;
00027 }
00028 if (modwanted) return num;
00029 return res;
00030 }
00031
00032
00033
00034 SItype
00035 __divsi3 (SItype a, SItype b)
00036 {
00037 word_type neg = 0;
00038 SItype res;
00039
00040 if (a < 0)
00041 {
00042 a = -a;
00043 neg = !neg;
00044 }
00045
00046 if (b < 0)
00047 {
00048 b = -b;
00049 neg = !neg;
00050 }
00051
00052 res = udivmodsi4 (a, b, 0);
00053
00054 if (neg)
00055 res = -res;
00056
00057 return res;
00058 }
00059
00060
00061
00062 SItype
00063 __modsi3 (SItype a, SItype b)
00064 {
00065 word_type neg = 0;
00066 SItype res;
00067
00068 if (a < 0)
00069 {
00070 a = -a;
00071 neg = 1;
00072 }
00073
00074 if (b < 0)
00075 b = -b;
00076
00077 res = udivmodsi4 (a, b, 1);
00078
00079 if (neg)
00080 res = -res;
00081
00082 return res;
00083 }
00084
00085
00086
00087
00088 SItype
00089 __udivsi3 (SItype a, SItype b)
00090 {
00091 return udivmodsi4 (a, b, 0);
00092 }
00093
00094
00095
00096 SItype
00097 __umodsi3 (SItype a, SItype b)
00098 {
00099 return udivmodsi4 (a, b, 1);
00100 }
00101
00102 SItype
00103 __ashlsi3 (SItype a, SItype b)
00104 {
00105 word_type i;
00106
00107 if (b & 16)
00108 a <<= 16;
00109 if (b & 8)
00110 a <<= 8;
00111 for (i = (b & 0x7); i > 0; --i)
00112 a <<= 1;
00113 return a;
00114 }
00115
00116 SItype
00117 __ashrsi3 (SItype a, SItype b)
00118 {
00119 word_type i;
00120
00121 if (b & 16)
00122 a >>= 16;
00123 if (b & 8)
00124 a >>= 8;
00125 for (i = (b & 0x7); i > 0; --i)
00126 a >>= 1;
00127 return a;
00128 }
00129
00130 USItype
00131 __lshrsi3 (USItype a, USItype b)
00132 {
00133 word_type i;
00134
00135 if (b & 16)
00136 a >>= 16;
00137 if (b & 8)
00138 a >>= 8;
00139 for (i = (b & 0x7); i > 0; --i)
00140 a >>= 1;
00141 return a;
00142 }