From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 1/8] include: Add support for "do_div" macro
Date: Sat, 26 Dec 2015 14:09:16 +0100 [thread overview]
Message-ID: <567E917C.4030304@gmail.com> (raw)
In-Reply-To: <BLU436-SMTP1053A064566AF9F805FF7D8FFF80@phx.gbl>
Am 25.12.2015 um 19:56 schrieb Wills Wang:
> Use the div64 header files from the kernel.
>
> Signed-off-by: Wills Wang <wills.wang@live.com>
> ---
>
> Changes in v4: None
> Changes in v3: None
> Changes in v2: None
>
> arch/mips/include/asm/div64.h | 68 +++++++++++++++++++++++++++++++++++++++++++
> include/asm-generic/div64.h | 59 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 127 insertions(+)
> create mode 100644 arch/mips/include/asm/div64.h
> create mode 100644 include/asm-generic/div64.h
please drop this patch, we already have a generic do_div()
implementation. Also we do not really need an assembly optimized
implementation for MIPS.
>
> diff --git a/arch/mips/include/asm/div64.h b/arch/mips/include/asm/div64.h
> new file mode 100644
> index 0000000..e5e6782
> --- /dev/null
> +++ b/arch/mips/include/asm/div64.h
> @@ -0,0 +1,68 @@
> +/*
> + * Copyright (C) 2000, 2004 Maciej W. Rozycki
> + * Copyright (C) 2003, 07 Ralf Baechle (ralf at linux-mips.org)
> + *
> + * This file is subject to the terms and conditions of the GNU General Public
> + * License. See the file "COPYING" in the main directory of this archive
> + * for more details.
> + */
> +#ifndef __ASM_DIV64_H
> +#define __ASM_DIV64_H
> +
> +#include <asm-generic/div64.h>
> +
> +#if BITS_PER_LONG == 64
> +
> +#include <linux/types.h>
> +
> +/*
> + * No traps on overflows for any of these...
> + */
> +
> +#define __div64_32(n, base) \
> +({ \
> + unsigned long __cf, __tmp, __tmp2, __i; \
> + unsigned long __quot32, __mod32; \
> + unsigned long __high, __low; \
> + unsigned long long __n; \
> + \
> + __high = *__n >> 32; \
> + __low = __n; \
> + __asm__( \
> + " .set push\n" \
> + " .set noat\n" \
> + " .set noreorder\n" \
> + " move %2, $0\n" \
> + " move %3, $0\n" \
> + " b 1f\n" \
> + " li %4, 0x21\n" \
> + "0:\n" \
> + " sll $1, %0, 0x1\n" \
> + " srl %3, %0, 0x1f\n" \
> + " or %0, $1, %5\n" \
> + " sll %1, %1, 0x1\n" \
> + " sll %2, %2, 0x1\n" \
> + "1:\n" \
> + " bnez %3, 2f\n" \
> + " sltu %5, %0, %z6\n" \
> + " bnez %5, 3f\n" \
> + "2:\n" \
> + " addiu %4, %4, -1\n" \
> + " subu %0, %0, %z6\n" \
> + " addiu %2, %2, 1\n" \
> + "3:\n" \
> + " bnez %4, 0b\n\t" \
> + " srl %5, %1, 0x1f\n\t" \
> + " .set pop" \
> + : "=&r" (__mod32), "=&r" (__tmp), \
> + "=&r" (__quot32), "=&r" (__cf), \
> + "=&r" (__i), "=&r" (__tmp2) \
> + : "Jr" (base), "0" (__high), "1" (__low)); \
> + \
> + (__n) = __quot32; \
> + __mod32; \
> +})
> +
> +#endif /* BITS_PER_LONG == 64 */
> +
> +#endif /* __ASM_DIV64_H */
> diff --git a/include/asm-generic/div64.h b/include/asm-generic/div64.h
> new file mode 100644
> index 0000000..d689fc4
> --- /dev/null
> +++ b/include/asm-generic/div64.h
> @@ -0,0 +1,59 @@
> +/*
> + * Copyright (C) 2003 Bernardo Innocenti <bernie@develer.com>
> + * Based on former asm-ppc/div64.h and asm-m68knommu/div64.h
> + *
> + * The semantics of do_div() are:
> + *
> + * uint32_t do_div(uint64_t *n, uint32_t base)
> + * {
> + * uint32_t remainder = *n % base;
> + * *n = *n / base;
> + * return remainder;
> + * }
> + *
> + * NOTE: macro parameter n is evaluated multiple times,
> + * beware of side effects!
> + */
> +
> +#ifndef _ASM_GENERIC_DIV64_H
> +#define _ASM_GENERIC_DIV64_H
> +
> +#include <linux/types.h>
> +#include <linux/compiler.h>
> +
> +#if BITS_PER_LONG == 64
> +
> +# define do_div(n, base) ({ \
> + uint32_t __base = (base); \
> + uint32_t __rem; \
> + __rem = ((uint64_t)(n)) % __base; \
> + (n) = ((uint64_t)(n)) / __base; \
> + __rem; \
> +})
> +
> +#elif BITS_PER_LONG == 32
> +
> +extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor);
> +
> +/* The unnecessary pointer compare is there
> + * to check for type safety (n must be 64bit)
> + */
> +# define do_div(n, base) ({ \
> + uint32_t __base = (base); \
> + uint32_t __rem; \
> + (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \
> + if (likely(((n) >> 32) == 0)) { \
> + __rem = (uint32_t)(n) % __base; \
> + (n) = (uint32_t)(n) / __base; \
> + } else \
> + __rem = __div64_32(&(n), __base); \
> + __rem; \
> +})
> +
> +#else /* BITS_PER_LONG == ?? */
> +
> +# error do_div() does not yet support the C64
> +
> +#endif /* BITS_PER_LONG */
> +
> +#endif /* _ASM_GENERIC_DIV64_H */
>
--
- Daniel
next prev parent reply other threads:[~2015-12-26 13:09 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1451069788-6786-1-git-send-email-wills.wang@live.com>
2015-12-25 18:56 ` [U-Boot] [PATCH v4 1/8] include: Add support for "do_div" macro Wills Wang
2015-12-26 7:24 ` Marek Vasut
2015-12-26 15:48 ` Wills Wang
2015-12-26 13:09 ` Daniel Schwierzeck [this message]
2015-12-26 16:54 ` Wills Wang
2015-12-25 18:56 ` [U-Boot] [PATCH v4 2/8] mips: implement to access the KSEG0/1 memory range in map_physmem Wills Wang
2015-12-26 7:25 ` Marek Vasut
2015-12-25 18:56 ` [U-Boot] [PATCH v4 3/8] mips: add base support for atheros ath79 based SOCs Wills Wang
2015-12-26 7:28 ` Marek Vasut
2015-12-26 16:17 ` Wills Wang
2015-12-26 17:01 ` Daniel Schwierzeck
2015-12-26 17:06 ` Marek Vasut
2015-12-27 9:37 ` Wills Wang
2015-12-25 18:56 ` [U-Boot] [PATCH v4 4/8] mips: ath79: add serial driver for ar933x SOC Wills Wang
2015-12-26 13:20 ` Daniel Schwierzeck
2015-12-26 16:54 ` Wills Wang
2015-12-26 17:19 ` Daniel Schwierzeck
2015-12-27 6:28 ` Wills Wang
2015-12-27 8:21 ` Thomas Chou
2015-12-27 13:07 ` Thomas Chou
2015-12-27 8:31 ` Thomas Chou
2015-12-25 18:56 ` [U-Boot] [PATCH v4 5/8] mips: ath79: add spi driver Wills Wang
2015-12-26 13:23 ` Daniel Schwierzeck
2015-12-26 16:56 ` Wills Wang
2015-12-25 18:56 ` [U-Boot] [PATCH v4 6/8] mips: ath79: add AP121 reference board Wills Wang
2015-12-26 13:52 ` Daniel Schwierzeck
2015-12-26 16:59 ` Wills Wang
2015-12-26 17:07 ` Daniel Schwierzeck
2015-12-27 6:36 ` Wills Wang
2015-12-27 6:41 ` Marek Vasut
2015-12-27 7:03 ` Wills Wang
2015-12-27 7:10 ` Marek Vasut
2015-12-25 18:56 ` [U-Boot] [PATCH v4 7/8] mips: support optimize tuning for same common processor cores Wills Wang
2015-12-26 7:30 ` Marek Vasut
2015-12-26 18:58 ` Daniel Schwierzeck
2015-12-27 3:03 ` Wills Wang
2015-12-25 18:56 ` [U-Boot] [PATCH v4 8/8] mips: move optimize tuning option from deprecated config.mk to Kconfig Wills Wang
2015-12-26 7:30 ` Marek Vasut
2015-12-26 17:33 ` Wills Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=567E917C.4030304@gmail.com \
--to=daniel.schwierzeck@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.