div64.c (b29a62d87cc0af3e9d134e9e0863b2cb053070b8) div64.c (1635e62e75a7bbb1c6274f6b43911cedfe0da60a)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2003 Bernardo Innocenti <bernie@develer.com>
4 *
5 * Based on former do_div() implementation from asm-parisc/div64.h:
6 * Copyright (C) 1999 Hewlett-Packard Co
7 * Copyright (C) 1999 David Mosberger-Tang <davidm@hpl.hp.com>
8 *

--- 198 unchanged lines hidden (view full) ---

207 y = (u64)a_hi * b_lo + (u32)y;
208 z += (u32)(y >> 32);
209 x = (y << 32) + (u32)x;
210
211 u64 n_lo = x, n_hi = z;
212
213#endif
214
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2003 Bernardo Innocenti <bernie@develer.com>
4 *
5 * Based on former do_div() implementation from asm-parisc/div64.h:
6 * Copyright (C) 1999 Hewlett-Packard Co
7 * Copyright (C) 1999 David Mosberger-Tang <davidm@hpl.hp.com>
8 *

--- 198 unchanged lines hidden (view full) ---

207 y = (u64)a_hi * b_lo + (u32)y;
208 z += (u32)(y >> 32);
209 x = (y << 32) + (u32)x;
210
211 u64 n_lo = x, n_hi = z;
212
213#endif
214
215 /* make sure c is not zero, trigger exception otherwise */
216#pragma GCC diagnostic push
217#pragma GCC diagnostic ignored "-Wdiv-by-zero"
218 if (unlikely(c == 0))
219 return 1/0;
220#pragma GCC diagnostic pop
221
215 int shift = __builtin_ctzll(c);
216
217 /* try reducing the fraction in case the dividend becomes <= 64 bits */
218 if ((n_hi >> shift) == 0) {
222 int shift = __builtin_ctzll(c);
223
224 /* try reducing the fraction in case the dividend becomes <= 64 bits */
225 if ((n_hi >> shift) == 0) {
219 u64 n = (n_lo >> shift) | (n_hi << (64 - shift));
226 u64 n = shift ? (n_lo >> shift) | (n_hi << (64 - shift)) : n_lo;
220
221 return div64_u64(n, c >> shift);
222 /*
223 * The remainder value if needed would be:
224 * res = div64_u64_rem(n, c >> shift, &rem);
225 * rem = (rem << shift) + (n_lo - (n << shift));
226 */
227 }

--- 35 unchanged lines hidden ---
227
228 return div64_u64(n, c >> shift);
229 /*
230 * The remainder value if needed would be:
231 * res = div64_u64_rem(n, c >> shift, &rem);
232 * rem = (rem << shift) + (n_lo - (n << shift));
233 */
234 }

--- 35 unchanged lines hidden ---