add sdcard to raspi BE kernel
[AROS.git] / arch / arm-all / arm-aeabi / ldiv.c
blobd689822c9006b29f7892019a2fda5205290f1237
1 /*
2 Copyright © 2009-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <inttypes.h>
8 void __attribute__((noreturn)) __aeabi_ldiv0(uint64_t);
10 int64_t __ldiv(int64_t a, int64_t b)
12 int32_t sign = ((int32_t)(a >> 32))^((int32_t)(b >> 32));
13 int64_t ret = 0;
15 if (a < 0)
16 a = -a;
17 if (b < 0)
18 b = -b;
20 if (b == 0)
22 __aeabi_ldiv0(a);
24 else if (b > a)
26 return 0;
28 else
30 int first_bit_a = __builtin_clz(a >> 32);
31 int first_bit_b = __builtin_clz(b >> 32);
33 if (first_bit_a == 32)
34 first_bit_a += __builtin_clz(a & 0xffffffff);
35 if (first_bit_b == 32)
36 first_bit_b += __builtin_clz(b & 0xffffffff);
38 uint64_t mask = 0x00000001ULL << (first_bit_b-first_bit_a);
39 b <<= (first_bit_b - first_bit_a);
43 if (a >= b)
45 ret |= mask;
46 a -= b;
49 mask >>=1;
50 b >>=1;
51 } while(mask);
54 if (sign < 0)
55 ret = -ret;
57 return ret;
60 int64_t __ldivmod_helper(int64_t a, int64_t b, int64_t *remainder)
62 int64_t quotient;
64 quotient = __ldiv(a, b);
66 *remainder = a - b * quotient;
68 return quotient;