Changes in kernel/genarch/src/softint/division.c [c7afcba7:9d58539] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/softint/division.c
rc7afcba7 r9d58539 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) 38 #define SGN(x) 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 73 74 74 75 static unsigned long long divandmod64(unsigned long long a, … … 76 77 { 77 78 unsigned long long result; 78 int steps = sizeof(unsigned long long) * 8; 79 int steps = sizeof(unsigned long long) * 8; 79 80 80 81 *remainder = 0; … … 90 91 return 0; 91 92 } 92 93 93 94 for (; steps > 0; steps--) { 94 95 /* shift one bit to remainder */ … … 102 103 a <<= 1; 103 104 } 104 105 105 106 return result; 106 107 } 107 108 108 109 /* 32bit integer division */ 109 int __divsi3(int a, int b) 110 { 111 unsigned int rem; 112 int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 113 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 114 117 if (SGN(a) == SGN(b)) 115 118 return result; 116 117 119 return -result; 118 120 } 119 121 120 122 /* 64bit integer division */ 121 long long __divdi3(long long a, long long b) 123 long long __divdi3(long long a, long long b) 122 124 { 123 125 unsigned long long rem; 124 long long result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 125 126 long long result; 127 128 result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 129 126 130 if (SGN(a) == SGN(b)) 127 131 return result; 128 129 132 return -result; 130 133 } … … 140 143 unsigned long long __udivdi3(unsigned long long a, unsigned long long b) 141 144 { 142 unsigned long long rem;145 unsigned long long rem; 143 146 return divandmod64(a, b, &rem); 144 147 } … … 151 154 152 155 /* if divident is negative, remainder must be too */ 153 if (!(SGN(a))) 156 if (!(SGN(a))) { 154 157 return -((int) rem); 158 } 155 159 156 160 return (int) rem; … … 158 162 159 163 /* 64bit remainder of the signed division */ 160 long long __moddi3(long long a, longlong b)164 long long __moddi3(long long a,long long b) 161 165 { 162 166 unsigned long long rem; … … 164 168 165 169 /* if divident is negative, remainder must be too */ 166 if (!(SGN(a))) 170 if (!(SGN(a))) { 167 171 return -((long long) rem); 172 } 168 173 169 174 return (long long) rem; … … 186 191 } 187 192 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 222 193 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, 223 194 unsigned long long *c)
Note:
See TracChangeset
for help on using the changeset viewer.