1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _M68K_DIV64_H 3 #define _M68K_DIV64_H 4 5 #ifdef CONFIG_CPU_HAS_NO_MULDIV64 6 #include <asm-generic/div64.h> 7 #else 8 9 #include <linux/types.h> 10 11 /* n = n / base; return rem; */ 12 13 #define do_div(n, base) ({ \ 14 union { \ 15 unsigned long n32[2]; \ 16 unsigned long long n64; \ 17 } __n; \ 18 unsigned long __rem, __upper; \ 19 unsigned long __base = (base); \ 20 \ 21 __n.n64 = (n); \ 22 if ((__upper = __n.n32[0])) { \ 23 asm ("divul.l %2,%1:%0" \ 24 : "=d" (__n.n32[0]), "=d" (__upper) \ 25 : "d" (__base), "0" (__n.n32[0])); \ 26 } \ 27 asm ("divu.l %2,%1:%0" \ 28 : "=d" (__n.n32[1]), "=d" (__rem) \ 29 : "d" (__base), "1" (__upper), "0" (__n.n32[1])); \ 30 (n) = __n.n64; \ 31 __rem; \ 32 }) 33 34 /* defining this stops the unused helper function from being built */ 35 #define __div64_32 __div64_32 36 37 #endif /* CONFIG_CPU_HAS_NO_MULDIV64 */ 38 39 #endif /* _M68K_DIV64_H */ 40