Changeset 41455a22 in mainline for uspace/lib/softint
- Timestamp:
- 2012-04-07T17:56:35Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 44c1a48, f3378ba
- Parents:
- 6bb169b5 (diff), 88d5c1e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/lib/softint
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/softint/generic/division.c
r6bb169b5 r41455a22 37 37 #include <division.h> 38 38 39 #define ABSVAL(x) ( (x) > 0 ? (x) : -(x)) 40 #define SGN(x) ( (x) >= 0 ? 1 : 0 ) 41 42 static unsigned int divandmod32(unsigned int a, unsigned int b, unsigned int *remainder) 39 #define ABSVAL(x) ((x) > 0 ? (x) : -(x)) 40 #define SGN(x) ((x) >= 0 ? 1 : 0) 41 42 static unsigned int divandmod32(unsigned int a, unsigned int b, 43 unsigned int *remainder) 43 44 { 44 45 unsigned int result; … … 53 54 } 54 55 55 if ( 56 if (a < b) { 56 57 *remainder = a; 57 58 return 0; 58 59 } 59 60 for ( 60 61 for (; steps > 0; steps--) { 61 62 /* shift one bit to remainder */ 62 *remainder = ( 63 *remainder = ((*remainder) << 1) | (( a >> 31) & 0x1); 63 64 result <<= 1; 64 65 65 66 if (*remainder >= b) { 66 67 67 *remainder -= b; 68 result |= 0x1; 68 69 } 69 70 a <<= 1; 70 71 } 71 72 72 73 return result; 73 74 } 74 75 75 76 static unsigned long long divandmod64(unsigned long long a,unsigned long long b, unsigned long long *remainder)76 static unsigned long long divandmod64(unsigned long long a, 77 unsigned long long b, unsigned long long *remainder) 77 78 { 78 79 unsigned long long result; 79 int steps = sizeof(unsigned long long) * 8; 80 int steps = sizeof(unsigned long long) * 8; 80 81 81 82 *remainder = 0; … … 87 88 } 88 89 89 if ( 90 if (a < b) { 90 91 *remainder = a; 91 92 return 0; 92 93 } 93 94 for ( 94 95 for (; steps > 0; steps--) { 95 96 /* shift one bit to remainder */ 96 *remainder = ( 97 *remainder = ((*remainder) << 1) | ((a >> 63) & 0x1); 97 98 result <<= 1; 98 99 99 100 if (*remainder >= b) { 100 101 101 *remainder -= b; 102 result |= 0x1; 102 103 } 103 104 a <<= 1; 104 105 } 105 106 106 107 return result; 107 108 } 108 109 109 110 /* 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 117 if ( SGN(a) == SGN(b)) return result;111 int __divsi3(int a, int b) 112 { 113 unsigned int rem; 114 int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 115 116 if (SGN(a) == SGN(b)) 117 return result; 118 118 119 return -result; 119 120 } 120 121 121 122 /* 64bit integer division */ 122 long long __divdi3(long long a, long long b) 123 { 124 unsigned long long rem; 125 long long result ;126 127 result = (long long)divandmod64(ABSVAL(a), ABSVAL(b), &rem);128 129 if ( SGN(a) == SGN(b)) return result;123 long long __divdi3(long long a, long long b) 124 { 125 unsigned long long rem; 126 long long result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 127 128 if (SGN(a) == SGN(b)) 129 return result; 130 130 131 return -result; 131 132 } … … 141 142 unsigned long long __udivdi3(unsigned long long a, unsigned long long b) 142 143 { 143 unsigned long long 144 unsigned long long rem; 144 145 return divandmod64(a, b, &rem); 145 146 } … … 152 153 153 154 /* if divident is negative, remainder must be too */ 154 if (!(SGN(a))) { 155 return -((int)rem); 156 } 157 158 return (int)rem; 155 if (!(SGN(a))) 156 return -((int) rem); 157 158 return (int) rem; 159 159 } 160 160 161 161 /* 64bit remainder of the signed division */ 162 long long __moddi3(long long a, longlong b)162 long long __moddi3(long long a, long long b) 163 163 { 164 164 unsigned long long rem; … … 166 166 167 167 /* if divident is negative, remainder must be too */ 168 if (!(SGN(a))) { 169 return -((long long)rem); 170 } 171 172 return (long long)rem; 168 if (!(SGN(a))) 169 return -((long long) rem); 170 171 return (long long) rem; 173 172 } 174 173 … … 189 188 } 190 189 191 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, unsigned long long *c) 190 int __divmodsi3(int a, int b, int *c) 191 { 192 unsigned int rem; 193 int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 194 195 if (SGN(a) == SGN(b)) { 196 *c = rem; 197 return result; 198 } 199 200 *c = -rem; 201 return -result; 202 } 203 204 unsigned int __udivmodsi3(unsigned int a, unsigned int b, 205 unsigned int *c) 206 { 207 return divandmod32(a, b, c); 208 } 209 210 long long __divmoddi3(long long a, long long b, long long *c) 211 { 212 unsigned long long rem; 213 long long result = (int) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 214 215 if (SGN(a) == SGN(b)) { 216 *c = rem; 217 return result; 218 } 219 220 *c = -rem; 221 return -result; 222 } 223 224 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, 225 unsigned long long *c) 192 226 { 193 227 return divandmod64(a, b, c); -
uspace/lib/softint/include/comparison.h
r6bb169b5 r41455a22 38 38 39 39 /* Signed comparison (a < b => 0, a == b => 1, a > b => 2). */ 40 int __cmpdi2 (long long a, long long b);40 extern int __cmpdi2(long long, long long); 41 41 42 42 /* Unsigned comparison (a < b => 0, a == b => 1, a > b => 2). */ 43 int __ucmpdi2 (unsigned long long a, unsigned long long b);43 extern int __ucmpdi2(unsigned long long, unsigned long long); 44 44 45 45 #endif -
uspace/lib/softint/include/division.h
r6bb169b5 r41455a22 29 29 /** @addtogroup softint 30 30 * @{ 31 */ 31 */ 32 32 /** 33 33 * @file … … 37 37 #define __SOFTINT_DIVISION_H__ 38 38 39 extern int __divsi3(int, int); 40 extern long long __divdi3(long long, long long); 39 41 40 /* 32bit integer division */ 41 int __divsi3(int a, int b);42 extern unsigned int __udivsi3(unsigned int, unsigned int); 43 extern unsigned long long __udivdi3(unsigned long long, unsigned long long); 42 44 43 /* 64bit integer division */ 44 long long __divdi3(long long a, long long b);45 extern int __modsi3(int, int); 46 extern long long __moddi3(long long, long long); 45 47 46 /* 32bit unsigned integer division */ 47 unsigned int __udivsi3(unsigned int a, unsigned int b);48 extern unsigned int __umodsi3(unsigned int, unsigned int); 49 extern unsigned long long __umoddi3(unsigned long long, unsigned long long); 48 50 49 /* 64bit unsigned integer division */ 50 unsigned long long __udivdi3(unsigned long long a, unsigned long long b);51 extern int __divmodsi3(int, int, int *); 52 extern unsigned int __udivmodsi3(unsigned int, unsigned int, unsigned int *); 51 53 52 /* 32bit remainder of the signed division */ 53 int __modsi3(int a, int b); 54 55 /* 64bit remainder of the signed division */ 56 long long __moddi3(long long a, long long b); 57 58 /* 32bit remainder of the unsigned division */ 59 unsigned int __umodsi3(unsigned int a, unsigned int b); 60 61 /* 64bit remainder of the unsigned division */ 62 unsigned long long __umoddi3(unsigned long long a, unsigned long long b); 63 64 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, unsigned long long *c); 54 extern long long __divmoddi3(long long, long long, long long *); 55 extern unsigned long long __udivmoddi3(unsigned long long, unsigned long long, 56 unsigned long long *); 65 57 66 58 #endif … … 68 60 /** @} 69 61 */ 70 -
uspace/lib/softint/include/lltype.h
r6bb169b5 r41455a22 39 39 #include <stdint.h> 40 40 41 #define HALF_BIT_CNT (sizeof(int32_t) * sizeof(char))42 #define WHOLE_BIT_CNT (sizeof(int64_t) * sizeof(char))41 #define HALF_BIT_CNT (sizeof(int32_t) * sizeof(char)) 42 #define WHOLE_BIT_CNT (sizeof(int64_t) * sizeof(char)) 43 43 44 44 #ifdef __BE__ -
uspace/lib/softint/include/multiplication.h
r6bb169b5 r41455a22 29 29 /** @addtogroup softint 30 30 * @{ 31 */ 31 */ 32 32 /** 33 33 * @file … … 38 38 39 39 /* 64 bit multiplication */ 40 long long __muldi3(long long a, long long b);40 extern long long __muldi3(long long, long long); 41 41 42 42 #endif -
uspace/lib/softint/include/shift.h
r6bb169b5 r41455a22 38 38 39 39 /* Arithmetic/logical shift left. */ 40 long long __ashldi3 (long long val, int shift);40 extern long long __ashldi3(long long, int); 41 41 42 42 /* Arithmetic shift right. */ 43 long long __ashrdi3 (long long val, int shift);43 extern long long __ashrdi3(long long, int); 44 44 45 45 /* Logical shift right. */ 46 long long __lshrdi3 (long long val, int shift);46 extern long long __lshrdi3(long long, int); 47 47 48 48 #endif
Note:
See TracChangeset
for help on using the changeset viewer.