diff options
author | Cyril SIX <cyril.six@kalray.eu> | 2018-05-21 16:34:36 +0200 |
---|---|---|
committer | Cyril SIX <cyril.six@kalray.eu> | 2018-05-21 16:39:48 +0200 |
commit | 479aacd0254605942a3f48c3b8053af4d07f0f6c (patch) | |
tree | 7ddbddf078b86a30e693ae35721e08f54a0af11e /runtime/mppa_k1c/i32_udivmod.c | |
parent | b81dbb863781a5f450cad0b01f90f729fb1a2244 (diff) | |
download | compcert-kvx-479aacd0254605942a3f48c3b8053af4d07f0f6c.tar.gz compcert-kvx-479aacd0254605942a3f48c3b8053af4d07f0f6c.zip |
MPPA - Added modulo and division 64 bits. Non certified
32 bits version are not yet there.
Right now the code is directly from libgcc, compiled with k1-gcc because
of builtins.
Diffstat (limited to 'runtime/mppa_k1c/i32_udivmod.c')
-rw-r--r-- | runtime/mppa_k1c/i32_udivmod.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/runtime/mppa_k1c/i32_udivmod.c b/runtime/mppa_k1c/i32_udivmod.c new file mode 100644 index 00000000..e66496af --- /dev/null +++ b/runtime/mppa_k1c/i32_udivmod.c @@ -0,0 +1,89 @@ + +static unsigned int +udivmodsi4(unsigned int num, unsigned int den, int modwanted) +{ + unsigned r = num, q = 0; + + if(den <= r) { + unsigned k = __builtin_k1_clz (den) - __builtin_k1_clz (r); + den = den << k; + if(r >= den) { + r = r - den; + q = 1 << k; + } + if(k != 0) { + unsigned i = k; + den = den >> 1; + do { + r = __builtin_k1_stsu (den, r); + i--; + } while (i!= 0); + q = q + r; + r = r >> k; + q = q - (r << k); + } + } + + return modwanted ? r : q; +} + +unsigned int +__udivsi3 (unsigned int a, unsigned int b) +{ + return udivmodsi4 (a, b, 0); +} + +unsigned int +__umodsi3 (unsigned int a, unsigned int b) +{ + return udivmodsi4 (a, b, 1); +} + +int +__divsi3 (int a, int b) +{ + int neg = 0; + int res; + + if (a < 0) + { + a = -a; + neg = !neg; + } + + if (b < 0) + { + b = -b; + neg = !neg; + } + + res = udivmodsi4 (a, b, 0); + + if (neg) + res = -res; + + return res; +} + +int +__modsi3 (int a, int b) +{ + int neg = 0; + int res; + + if (a < 0) + { + a = -a; + neg = 1; + } + + if (b < 0) + b = -b; + + res = udivmodsi4 (a, b, 1); + + if (neg) + res = -res; + + return res; +} |