Changeset 7fe9c5b in mainline
- Timestamp:
- 2007-08-03T09:35:00Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0368fb59
- Parents:
- b76a2217
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/softint/division.c
rb76a2217 r7fe9c5b 35 35 #include <genarch/softint/division.h> 36 36 37 #define ABSVAL(x) ( 38 #define SGN(x) ( (x) >= 0 ? 1 : 0)37 #define ABSVAL(x) ((x) > 0 ? (x) : -(x)) 38 #define SGN(x) ((x) >= 0 ? 1 : 0) 39 39 40 static unsigned int divandmod32(unsigned int a, unsigned int b, unsigned int *remainder) 40 static unsigned int divandmod32(unsigned int a, unsigned int b, 41 unsigned int *remainder) 41 42 { 42 43 unsigned int result; … … 51 52 } 52 53 53 if ( 54 if (a < b) { 54 55 *remainder = a; 55 56 return 0; 56 57 } 57 58 58 for ( 59 for (; steps > 0; steps--) { 59 60 /* shift one bit to remainder */ 60 *remainder = ( 61 *remainder = ((*remainder) << 1) | (( a >> 31) & 0x1); 61 62 result <<= 1; 62 63 63 64 if (*remainder >= b) { 64 65 65 *remainder -= b; 66 result |= 0x1; 66 67 } 67 68 a <<= 1; … … 72 73 73 74 74 static unsigned long long divandmod64(unsigned long long a, unsigned long long b, unsigned long long *remainder) 75 static unsigned long long divandmod64(unsigned long long a, 76 unsigned long long b, unsigned long long *remainder) 75 77 { 76 78 unsigned long long result; … … 85 87 } 86 88 87 if ( 89 if (a < b) { 88 90 *remainder = a; 89 91 return 0; 90 92 } 91 93 92 for ( 94 for (; steps > 0; steps--) { 93 95 /* shift one bit to remainder */ 94 *remainder = ( 96 *remainder = ((*remainder) << 1) | ((a >> 63) & 0x1); 95 97 result <<= 1; 96 98 97 99 if (*remainder >= b) { 98 99 100 *remainder -= b; 101 result |= 0x1; 100 102 } 101 103 a <<= 1; … … 111 113 int result; 112 114 113 result = (int)divandmod32(ABSVAL(a), ABSVAL(b), &rem); 114 115 if ( SGN(a) == SGN(b)) return result; 115 result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 116 117 if (SGN(a) == SGN(b)) 118 return result; 116 119 return -result; 117 120 } … … 123 126 long long result; 124 127 125 result = (long long)divandmod64(ABSVAL(a), ABSVAL(b), &rem); 126 127 if ( SGN(a) == SGN(b)) return result; 128 result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 129 130 if (SGN(a) == SGN(b)) 131 return result; 128 132 return -result; 129 133 } … … 151 155 /* if divident is negative, remainder must be too */ 152 156 if (!(SGN(a))) { 153 return -((int) rem);154 } 155 156 return (int) rem;157 return -((int) rem); 158 } 159 160 return (int) rem; 157 161 } 158 162 … … 165 169 /* if divident is negative, remainder must be too */ 166 170 if (!(SGN(a))) { 167 return -((long long) rem);168 } 169 170 return (long long) rem;171 return -((long long) rem); 172 } 173 174 return (long long) rem; 171 175 } 172 176 … … 187 191 } 188 192 189 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, unsigned long long *c) 193 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, 194 unsigned long long *c) 190 195 { 191 196 return divandmod64(a, b, c);
Note:
See TracChangeset
for help on using the changeset viewer.