1typedef int HItype __attribute__ ((mode (HI))); 2typedef int SItype __attribute__ ((mode (SI))); 3typedef unsigned int USItype __attribute__ ((mode (SI))); 4 5typedef int word_type __attribute__ ((mode (__word__))); 6 7USItype 8udivmodsi4(USItype num, USItype den, word_type modwanted) 9{ 10 USItype bit = 1; 11 USItype res = 0; 12 13 while (den < num && bit && !(den & (1L<<31))) 14 { 15 den <<=1; 16 bit <<=1; 17 } 18 while (bit) 19 { 20 if (num >= den) 21 { 22 num -= den; 23 res |= bit; 24 } 25 bit >>=1; 26 den >>=1; 27 } 28 if (modwanted) return num; 29 return res; 30} 31 32 33 34SItype 35__divsi3 (SItype a, SItype b) 36{ 37 word_type neg = 0; 38 SItype res; 39 40 if (a < 0) 41 { 42 a = -a; 43 neg = !neg; 44 } 45 46 if (b < 0) 47 { 48 b = -b; 49 neg = !neg; 50 } 51 52 res = udivmodsi4 (a, b, 0); 53 54 if (neg) 55 res = -res; 56 57 return res; 58} 59 60 61 62SItype 63__modsi3 (SItype a, SItype b) 64{ 65 word_type neg = 0; 66 SItype res; 67 68 if (a < 0) 69 { 70 a = -a; 71 neg = 1; 72 } 73 74 if (b < 0) 75 b = -b; 76 77 res = udivmodsi4 (a, b, 1); 78 79 if (neg) 80 res = -res; 81 82 return res; 83} 84 85 86 87 88SItype 89__udivsi3 (SItype a, SItype b) 90{ 91 return udivmodsi4 (a, b, 0); 92} 93 94 95 96SItype 97__umodsi3 (SItype a, SItype b) 98{ 99 return udivmodsi4 (a, b, 1); 100} 101 102SItype 103__ashlsi3 (SItype a, SItype b) 104{ 105 word_type i; 106 107 if (b & 16) 108 a <<= 16; 109 if (b & 8) 110 a <<= 8; 111 for (i = (b & 0x7); i > 0; --i) 112 a <<= 1; 113 return a; 114} 115 116SItype 117__ashrsi3 (SItype a, SItype b) 118{ 119 word_type i; 120 121 if (b & 16) 122 a >>= 16; 123 if (b & 8) 124 a >>= 8; 125 for (i = (b & 0x7); i > 0; --i) 126 a >>= 1; 127 return a; 128} 129 130USItype 131__lshrsi3 (USItype a, USItype b) 132{ 133 word_type i; 134 135 if (b & 16) 136 a >>= 16; 137 if (b & 8) 138 a >>= 8; 139 for (i = (b & 0x7); i > 0; --i) 140 a >>= 1; 141 return a; 142} 143