Changes in kernel/genarch/src/softint/division.c [7fe9c5b:c7afcba7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/softint/division.c
r7fe9c5b rc7afcba7 27 27 */ 28 28 29 /** @addtogroup genarch 29 /** @addtogroup genarch 30 30 * @{ 31 31 */ … … 35 35 #include <genarch/softint/division.h> 36 36 37 #define ABSVAL(x) ((x) > 0 ? (x) : -(x))38 #define SGN(x) ((x) >= 0 ? 1 : 0)39 37 #define ABSVAL(x) ((x) > 0 ? (x) : -(x)) 38 #define SGN(x) ((x) >= 0 ? 1 : 0) 39 40 40 static unsigned int divandmod32(unsigned int a, unsigned int b, 41 41 unsigned int *remainder) … … 56 56 return 0; 57 57 } 58 58 59 59 for (; steps > 0; steps--) { 60 60 /* shift one bit to remainder */ … … 68 68 a <<= 1; 69 69 } 70 70 71 71 return result; 72 72 } 73 74 73 75 74 static unsigned long long divandmod64(unsigned long long a, … … 77 76 { 78 77 unsigned long long result; 79 int steps = sizeof(unsigned long long) * 8; 78 int steps = sizeof(unsigned long long) * 8; 80 79 81 80 *remainder = 0; … … 91 90 return 0; 92 91 } 93 92 94 93 for (; steps > 0; steps--) { 95 94 /* shift one bit to remainder */ … … 103 102 a <<= 1; 104 103 } 105 104 106 105 return result; 107 106 } 108 107 109 108 /* 32bit integer division */ 110 int __divsi3(int a, int b) 111 { 112 unsigned int rem; 113 int result; 114 115 result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 116 109 int __divsi3(int a, int b) 110 { 111 unsigned int rem; 112 int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 113 117 114 if (SGN(a) == SGN(b)) 118 115 return result; 116 119 117 return -result; 120 118 } 121 119 122 120 /* 64bit integer division */ 123 long long __divdi3(long long a, long long b) 124 { 125 unsigned long long rem; 126 long long result; 127 128 result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 129 121 long long __divdi3(long long a, long long b) 122 { 123 unsigned long long rem; 124 long long result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 125 130 126 if (SGN(a) == SGN(b)) 131 127 return result; 128 132 129 return -result; 133 130 } … … 143 140 unsigned long long __udivdi3(unsigned long long a, unsigned long long b) 144 141 { 145 unsigned long long 142 unsigned long long rem; 146 143 return divandmod64(a, b, &rem); 147 144 } … … 154 151 155 152 /* if divident is negative, remainder must be too */ 156 if (!(SGN(a))) {153 if (!(SGN(a))) 157 154 return -((int) rem); 158 }159 155 160 156 return (int) rem; … … 162 158 163 159 /* 64bit remainder of the signed division */ 164 long long __moddi3(long long a, longlong b)160 long long __moddi3(long long a, long long b) 165 161 { 166 162 unsigned long long rem; … … 168 164 169 165 /* if divident is negative, remainder must be too */ 170 if (!(SGN(a))) {166 if (!(SGN(a))) 171 167 return -((long long) rem); 172 }173 168 174 169 return (long long) rem; … … 191 186 } 192 187 188 int __divmodsi3(int a, int b, int *c) 189 { 190 unsigned int rem; 191 int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 192 193 if (SGN(a) == SGN(b)) { 194 *c = rem; 195 return result; 196 } 197 198 *c = -rem; 199 return -result; 200 } 201 202 unsigned int __udivmodsi3(unsigned int a, unsigned int b, 203 unsigned int *c) 204 { 205 return divandmod32(a, b, c); 206 } 207 208 long long __divmoddi3(long long a, long long b, long long *c) 209 { 210 unsigned long long rem; 211 long long result = (int) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 212 213 if (SGN(a) == SGN(b)) { 214 *c = rem; 215 return result; 216 } 217 218 *c = -rem; 219 return -result; 220 } 221 193 222 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, 194 223 unsigned long long *c)
Note:
See TracChangeset
for help on using the changeset viewer.