diff options
Diffstat (limited to 'usr/klibc/libgcc')
-rw-r--r-- | usr/klibc/libgcc/__ashldi3.c | 23 | ||||
-rw-r--r-- | usr/klibc/libgcc/__ashrdi3.c | 23 | ||||
-rw-r--r-- | usr/klibc/libgcc/__clzsi2.c | 36 | ||||
-rw-r--r-- | usr/klibc/libgcc/__divdi3.c | 29 | ||||
-rw-r--r-- | usr/klibc/libgcc/__divsi3.c | 29 | ||||
-rw-r--r-- | usr/klibc/libgcc/__lshrdi3.c | 23 | ||||
-rw-r--r-- | usr/klibc/libgcc/__moddi3.c | 29 | ||||
-rw-r--r-- | usr/klibc/libgcc/__modsi3.c | 29 | ||||
-rw-r--r-- | usr/klibc/libgcc/__udivdi3.c | 13 | ||||
-rw-r--r-- | usr/klibc/libgcc/__udivmoddi4.c | 32 | ||||
-rw-r--r-- | usr/klibc/libgcc/__udivmodsi4.c | 32 | ||||
-rw-r--r-- | usr/klibc/libgcc/__udivsi3.c | 13 | ||||
-rw-r--r-- | usr/klibc/libgcc/__umoddi3.c | 16 | ||||
-rw-r--r-- | usr/klibc/libgcc/__umodsi3.c | 16 |
14 files changed, 343 insertions, 0 deletions
diff --git a/usr/klibc/libgcc/__ashldi3.c b/usr/klibc/libgcc/__ashldi3.c new file mode 100644 index 0000000..95937f0 --- /dev/null +++ b/usr/klibc/libgcc/__ashldi3.c @@ -0,0 +1,23 @@ +/* + * libgcc/__ashldi3.c + */ + +#include <stdint.h> +#include <stddef.h> + +uint64_t __ashldi3(uint64_t v, int cnt) +{ + int c = cnt & 31; + uint32_t vl = (uint32_t) v; + uint32_t vh = (uint32_t) (v >> 32); + + if (cnt & 32) { + vh = (vl << c); + vl = 0; + } else { + vh = (vh << c) + (vl >> (32 - c)); + vl = (vl << c); + } + + return ((uint64_t) vh << 32) + vl; +} diff --git a/usr/klibc/libgcc/__ashrdi3.c b/usr/klibc/libgcc/__ashrdi3.c new file mode 100644 index 0000000..14e6d18 --- /dev/null +++ b/usr/klibc/libgcc/__ashrdi3.c @@ -0,0 +1,23 @@ +/* + * libgcc/__ashrdi3.c + */ + +#include <stdint.h> +#include <stddef.h> + +uint64_t __ashrdi3(uint64_t v, int cnt) +{ + int c = cnt & 31; + uint32_t vl = (uint32_t) v; + uint32_t vh = (uint32_t) (v >> 32); + + if (cnt & 32) { + vl = ((int32_t) vh >> c); + vh = (int32_t) vh >> 31; + } else { + vl = (vl >> c) + (vh << (32 - c)); + vh = ((int32_t) vh >> c); + } + + return ((uint64_t) vh << 32) + vl; +} diff --git a/usr/klibc/libgcc/__clzsi2.c b/usr/klibc/libgcc/__clzsi2.c new file mode 100644 index 0000000..ebb11f0 --- /dev/null +++ b/usr/klibc/libgcc/__clzsi2.c @@ -0,0 +1,36 @@ +/* + * libgcc/__clzsi2.c + * + * Returns the leading number of 0 bits in the argument + */ + +#include <stdint.h> +#include <stddef.h> + +uint32_t __clzsi2(uint32_t v) +{ + int p = 31; + + if (v & 0xffff0000) { + p -= 16; + v >>= 16; + } + if (v & 0xff00) { + p -= 8; + v >>= 8; + } + if (v & 0xf0) { + p -= 4; + v >>= 4; + } + if (v & 0xc) { + p -= 2; + v >>= 2; + } + if (v & 0x2) { + p -= 1; + v >>= 1; + } + + return p; +} diff --git a/usr/klibc/libgcc/__divdi3.c b/usr/klibc/libgcc/__divdi3.c new file mode 100644 index 0000000..973fe63 --- /dev/null +++ b/usr/klibc/libgcc/__divdi3.c @@ -0,0 +1,29 @@ +/* + * arch/i386/libgcc/__divdi3.c + */ + +#include <stdint.h> +#include <stddef.h> + +extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t * rem); + +int64_t __divdi3(int64_t num, int64_t den) +{ + int minus = 0; + int64_t v; + + if (num < 0) { + num = -num; + minus = 1; + } + if (den < 0) { + den = -den; + minus ^= 1; + } + + v = __udivmoddi4(num, den, NULL); + if (minus) + v = -v; + + return v; +} diff --git a/usr/klibc/libgcc/__divsi3.c b/usr/klibc/libgcc/__divsi3.c new file mode 100644 index 0000000..35420f5 --- /dev/null +++ b/usr/klibc/libgcc/__divsi3.c @@ -0,0 +1,29 @@ +/* + * libgcc/__divsi3.c + */ + +#include <stdint.h> +#include <stddef.h> + +extern uint32_t __udivmodsi4(uint32_t num, uint32_t den, uint32_t * rem); + +int32_t __divsi3(int32_t num, int32_t den) +{ + int minus = 0; + int32_t v; + + if (num < 0) { + num = -num; + minus = 1; + } + if (den < 0) { + den = -den; + minus ^= 1; + } + + v = __udivmodsi4(num, den, NULL); + if (minus) + v = -v; + + return v; +} diff --git a/usr/klibc/libgcc/__lshrdi3.c b/usr/klibc/libgcc/__lshrdi3.c new file mode 100644 index 0000000..765e1f2 --- /dev/null +++ b/usr/klibc/libgcc/__lshrdi3.c @@ -0,0 +1,23 @@ +/* + * libgcc/__lshrdi3.c + */ + +#include <stdint.h> +#include <stddef.h> + +uint64_t __lshrdi3(uint64_t v, int cnt) +{ + int c = cnt & 31; + uint32_t vl = (uint32_t) v; + uint32_t vh = (uint32_t) (v >> 32); + + if (cnt & 32) { + vl = (vh >> c); + vh = 0; + } else { + vl = (vl >> c) + (vh << (32 - c)); + vh = (vh >> c); + } + + return ((uint64_t) vh << 32) + vl; +} diff --git a/usr/klibc/libgcc/__moddi3.c b/usr/klibc/libgcc/__moddi3.c new file mode 100644 index 0000000..0e7ed98 --- /dev/null +++ b/usr/klibc/libgcc/__moddi3.c @@ -0,0 +1,29 @@ +/* + * arch/i386/libgcc/__moddi3.c + */ + +#include <stdint.h> +#include <stddef.h> + +extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t * rem); + +int64_t __moddi3(int64_t num, int64_t den) +{ + int minus = 0; + int64_t v; + + if (num < 0) { + num = -num; + minus = 1; + } + if (den < 0) { + den = -den; + minus ^= 1; + } + + (void)__udivmoddi4(num, den, (uint64_t *) & v); + if (minus) + v = -v; + + return v; +} diff --git a/usr/klibc/libgcc/__modsi3.c b/usr/klibc/libgcc/__modsi3.c new file mode 100644 index 0000000..33a21ba --- /dev/null +++ b/usr/klibc/libgcc/__modsi3.c @@ -0,0 +1,29 @@ +/* + * libgcc/__modsi3.c + */ + +#include <stdint.h> +#include <stddef.h> + +extern uint32_t __udivmodsi4(uint32_t num, uint32_t den, uint32_t * rem); + +int32_t __modsi3(int32_t num, int32_t den) +{ + int minus = 0; + int32_t v; + + if (num < 0) { + num = -num; + minus = 1; + } + if (den < 0) { + den = -den; + minus ^= 1; + } + + (void)__udivmodsi4(num, den, (uint32_t *) & v); + if (minus) + v = -v; + + return v; +} diff --git a/usr/klibc/libgcc/__udivdi3.c b/usr/klibc/libgcc/__udivdi3.c new file mode 100644 index 0000000..5eea461 --- /dev/null +++ b/usr/klibc/libgcc/__udivdi3.c @@ -0,0 +1,13 @@ +/* + * arch/i386/libgcc/__divdi3.c + */ + +#include <stdint.h> +#include <stddef.h> + +extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t * rem); + +uint64_t __udivdi3(uint64_t num, uint64_t den) +{ + return __udivmoddi4(num, den, NULL); +} diff --git a/usr/klibc/libgcc/__udivmoddi4.c b/usr/klibc/libgcc/__udivmoddi4.c new file mode 100644 index 0000000..aa86112 --- /dev/null +++ b/usr/klibc/libgcc/__udivmoddi4.c @@ -0,0 +1,32 @@ +#include <klibc/diverr.h> +#include <stdint.h> + +uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t * rem_p) +{ + uint64_t quot = 0, qbit = 1; + + if (den == 0) { + __divide_error(); + return 0; /* If trap returns... */ + } + + /* Left-justify denominator and count shift */ + while ((int64_t) den >= 0) { + den <<= 1; + qbit <<= 1; + } + + while (qbit) { + if (den <= num) { + num -= den; + quot += qbit; + } + den >>= 1; + qbit >>= 1; + } + + if (rem_p) + *rem_p = num; + + return quot; +} diff --git a/usr/klibc/libgcc/__udivmodsi4.c b/usr/klibc/libgcc/__udivmodsi4.c new file mode 100644 index 0000000..54980f0 --- /dev/null +++ b/usr/klibc/libgcc/__udivmodsi4.c @@ -0,0 +1,32 @@ +#include <klibc/diverr.h> +#include <stdint.h> + +uint32_t __udivmodsi4(uint32_t num, uint32_t den, uint32_t * rem_p) +{ + uint32_t quot = 0, qbit = 1; + + if (den == 0) { + __divide_error(); + return 0; /* If trap returns... */ + } + + /* Left-justify denominator and count shift */ + while ((int32_t) den >= 0) { + den <<= 1; + qbit <<= 1; + } + + while (qbit) { + if (den <= num) { + num -= den; + quot += qbit; + } + den >>= 1; + qbit >>= 1; + } + + if (rem_p) + *rem_p = num; + + return quot; +} diff --git a/usr/klibc/libgcc/__udivsi3.c b/usr/klibc/libgcc/__udivsi3.c new file mode 100644 index 0000000..5635f3f --- /dev/null +++ b/usr/klibc/libgcc/__udivsi3.c @@ -0,0 +1,13 @@ +/* + * libgcc/__divsi3.c + */ + +#include <stdint.h> +#include <stddef.h> + +extern uint32_t __udivmodsi4(uint32_t num, uint32_t den, uint32_t * rem); + +uint32_t __udivsi3(uint32_t num, uint32_t den) +{ + return __udivmodsi4(num, den, NULL); +} diff --git a/usr/klibc/libgcc/__umoddi3.c b/usr/klibc/libgcc/__umoddi3.c new file mode 100644 index 0000000..1fc754a --- /dev/null +++ b/usr/klibc/libgcc/__umoddi3.c @@ -0,0 +1,16 @@ +/* + * arch/i386/libgcc/__umoddi3.c + */ + +#include <stdint.h> +#include <stddef.h> + +extern uint64_t __udivmoddi4(uint64_t num, uint64_t den, uint64_t * rem); + +uint64_t __umoddi3(uint64_t num, uint64_t den) +{ + uint64_t v; + + (void)__udivmoddi4(num, den, &v); + return v; +} diff --git a/usr/klibc/libgcc/__umodsi3.c b/usr/klibc/libgcc/__umodsi3.c new file mode 100644 index 0000000..85e6e3c --- /dev/null +++ b/usr/klibc/libgcc/__umodsi3.c @@ -0,0 +1,16 @@ +/* + * libgcc/__umodsi3.c + */ + +#include <stdint.h> +#include <stddef.h> + +extern uint32_t __udivmodsi4(uint32_t num, uint32_t den, uint32_t * rem); + +uint32_t __umodsi3(uint32_t num, uint32_t den) +{ + uint32_t v; + + (void)__udivmodsi4(num, den, &v); + return v; +} |