Changeset 5a6a42f in mainline
- Timestamp:
- 2012-04-07T12:34:19Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 956a22c
- Parents:
- df955955
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/genarch/include/division.h
rdf955955 r5a6a42f 33 33 #define BOOT_DIVISION_H_ 34 34 35 /* 32bit integer division */36 35 extern int __divsi3(int, int); 37 38 /* 64bit integer division */39 36 extern long long __divdi3(long long, long long); 40 37 41 /* 32bit unsigned integer division */42 38 extern unsigned int __udivsi3(unsigned int, unsigned int); 43 44 /* 64bit unsigned integer division */45 39 extern unsigned long long __udivdi3(unsigned long long, unsigned long long); 46 40 47 /* 32bit remainder of the signed division */48 41 extern int __modsi3(int, int); 49 50 /* 64bit remainder of the signed division */51 42 extern long long __moddi3(long long, long long); 52 43 53 /* 32bit remainder of the unsigned division */54 44 extern unsigned int __umodsi3(unsigned int, unsigned int); 55 56 /* 64bit remainder of the unsigned division */57 45 extern unsigned long long __umoddi3(unsigned long long, unsigned long long); 58 46 47 extern unsigned int __udivmodsi3(unsigned int, unsigned int, unsigned int *); 59 48 extern unsigned long long __udivmoddi3(unsigned long long, unsigned long long, 60 49 unsigned long long *); -
boot/genarch/src/division.c
rdf955955 r5a6a42f 73 73 { 74 74 unsigned long long result; 75 int steps = sizeof(unsigned long long) * 8; 75 int steps = sizeof(unsigned long long) * 8; 76 76 77 77 *remainder = 0; … … 104 104 105 105 /* 32bit integer division */ 106 int __divsi3(int a, int b) 106 int __divsi3(int a, int b) 107 107 { 108 108 unsigned int rem; … … 116 116 117 117 /* 64bit integer division */ 118 long long __divdi3(long long a, long long b) 118 long long __divdi3(long long a, long long b) 119 119 { 120 120 unsigned long long rem; … … 155 155 156 156 /* 64bit remainder of the signed division */ 157 long long __moddi3(long long a, longlong b)157 long long __moddi3(long long a, long long b) 158 158 { 159 159 unsigned long long rem; … … 183 183 } 184 184 185 unsigned int __udivmodsi3(unsigned int a, unsigned int b, 186 unsigned int *c) 187 { 188 return divandmod32(a, b, c); 189 } 190 185 191 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, 186 192 unsigned long long *c) -
kernel/genarch/include/softint/division.h
rdf955955 r5a6a42f 36 36 #define KERN_DIVISION_H_ 37 37 38 /* 32bit integer division */ 39 int __divsi3(int a, int b);38 extern int __divsi3(int, int); 39 extern long long __divdi3(long long, long long); 40 40 41 /* 64bit integer division */ 42 long long __divdi3(long long a, long long b);41 extern unsigned int __udivsi3(unsigned int, unsigned int); 42 extern unsigned long long __udivdi3(unsigned long long, unsigned long long); 43 43 44 /* 32bit unsigned integer division */ 45 unsigned int __udivsi3(unsigned int a, unsigned int b);44 extern int __modsi3(int, int); 45 extern long long __moddi3(long long, long long); 46 46 47 /* 64bit unsigned integer division */ 48 unsigned long long __udivdi3(unsigned long long a, unsigned long long b);47 extern unsigned int __umodsi3(unsigned int, unsigned int); 48 extern unsigned long long __umoddi3(unsigned long long, unsigned long long); 49 49 50 /* 32bit remainder of the signed division */ 51 int __modsi3(int a, int b); 52 53 /* 64bit remainder of the signed division */ 54 long long __moddi3(long long a, long long b); 55 56 /* 32bit remainder of the unsigned division */ 57 unsigned int __umodsi3(unsigned int a, unsigned int b); 58 59 /* 64bit remainder of the unsigned division */ 60 unsigned long long __umoddi3(unsigned long long a, unsigned long long b); 61 62 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, unsigned long long *c); 50 extern unsigned int __udivmodsi3(unsigned int, unsigned int, unsigned int *); 51 extern unsigned long long __udivmoddi3(unsigned long long, unsigned long long, 52 unsigned long long *); 63 53 64 54 #endif -
kernel/genarch/src/softint/division.c
rdf955955 r5a6a42f 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 unsigned int __udivmodsi3(unsigned int a, unsigned int b, 189 unsigned int *c) 190 { 191 return divandmod32(a, b, c); 192 } 193 193 194 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, 194 195 unsigned long long *c) -
uspace/lib/softint/generic/division.c
rdf955955 r5a6a42f 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 unsigned int __udivmodsi3(unsigned int a, unsigned int b, 191 unsigned int *c) 192 { 193 return divandmod32(a, b, c); 194 } 195 196 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, 197 unsigned long long *c) 192 198 { 193 199 return divandmod64(a, b, c); -
uspace/lib/softint/include/division.h
rdf955955 r5a6a42f 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 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); 51 extern unsigned int __udivmodsi3(unsigned int, unsigned int, unsigned int *); 52 extern unsigned long long __udivmoddi3(unsigned long long, unsigned long long, 53 unsigned long long *); 65 54 66 55 #endif … … 68 57 /** @} 69 58 */ 70
Note:
See TracChangeset
for help on using the changeset viewer.