1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_ARM_DIV64
3 #define __ASM_ARM_DIV64
5 #include <linux/types.h>
6 #include <asm/compiler.h>
9 * The semantics of __div64_32() are:
11 * uint32_t __div64_32(uint64_t *n, uint32_t base)
13 * uint32_t remainder = *n % base;
18 * In other words, a 64-bit dividend with a 32-bit divisor producing
19 * a 64-bit result and a 32-bit remainder. To accomplish this optimally
20 * we override the generic version in lib/div64.c to call our __do_div64
21 * assembly implementation with completely non standard calling convention
22 * for arguments and results (beware).
33 static inline uint32_t __div64_32(uint64_t *n
, uint32_t base
)
35 register unsigned int __base
asm("r4") = base
;
36 register unsigned long long __n
asm("r0") = *n
;
37 register unsigned long long __res
asm("r2");
38 register unsigned int __rem
asm(__xh
);
39 asm( __asmeq("%0", __xh
)
44 : "=r" (__rem
), "=r" (__res
)
45 : "r" (__n
), "r" (__base
)
50 #define __div64_32 __div64_32
52 #if !defined(CONFIG_AEABI)
55 * In OABI configurations, some uses of the do_div function
56 * cause gcc to run out of registers. To work around that,
57 * we can force the use of the out-of-line version for
58 * configurations that build a OABI kernel.
60 #define do_div(n, base) __div64_32(&(n), base)
65 * gcc versions earlier than 4.0 are simply too problematic for the
66 * __div64_const32() code in asm-generic/div64.h. First there is
67 * gcc PR 15089 that tend to trig on more complex constructs, spurious
68 * .global __udivsi3 are inserted even if none of those symbols are
69 * referenced in the generated code, and those gcc versions are not able
70 * to do constant propagation on long long values anyway.
73 #define __div64_const32_is_OK (__GNUC__ >= 4)
75 static inline uint64_t __arch_xprod_64(uint64_t m
, uint64_t n
, bool bias
)
77 unsigned long long res
;
78 register unsigned int tmp
asm("ip") = 0;
81 asm ( "umull %Q0, %R0, %Q1, %Q2\n\t"
86 } else if (!(m
& ((1ULL << 63) | (1ULL << 31)))) {
88 asm ( "umlal %Q0, %R0, %Q1, %Q2\n\t"
94 asm ( "umull %Q0, %R0, %Q2, %Q3\n\t"
96 "adcs %R0, %R0, %R2\n\t"
98 : "=&r" (res
), "+&r" (tmp
)
103 if (!(m
& ((1ULL << 63) | (1ULL << 31)))) {
104 asm ( "umlal %R0, %Q0, %R1, %Q2\n\t"
105 "umlal %R0, %Q0, %Q1, %R2\n\t"
107 "umlal %Q0, %R0, %R1, %R2"
112 asm ( "umlal %R0, %Q0, %R2, %Q3\n\t"
113 "umlal %R0, %1, %Q2, %R3\n\t"
115 "adds %Q0, %1, %Q0\n\t"
116 "adc %R0, %R0, #0\n\t"
117 "umlal %Q0, %R0, %R2, %R3"
118 : "+&r" (res
), "+&r" (tmp
)
125 #define __arch_xprod_64 __arch_xprod_64
127 #include <asm-generic/div64.h>