mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Matti Aarnio <matti.aarnio@zmailer.org>
To: Momchil Velikov <velco@fadata.bg>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] 64-bit divide tweaks
Date: Sun, 27 Jan 2002 20:51:41 +0200	[thread overview]
Message-ID: <20020127205141.L5808@mea-ext.zmailer.org> (raw)
In-Reply-To: <87r8oez0ks.fsf@fadata.bg>
In-Reply-To: <87r8oez0ks.fsf@fadata.bg>; from velco@fadata.bg on Fri, Jan 25, 2002 at 09:34:43PM +0200

On Fri, Jan 25, 2002 at 09:34:43PM +0200, Momchil Velikov wrote:
> Hi there,
>   printk, etc. are broken wrt printing 64-bit numbers (%ll, %L).
>   This patch fixes do_div, which did (on some archs) 32-bit divide.

  Wrong.

  Correct one is to supply each arch with their native way to handle
  the division.  Remember, the base (divisor) is SMALLISH (2 to 16).

  Where you are unable to do it, the C code that is still present in
  include/asm-parisc/div64.h   alternate code branch will do it.

  This code is needed because the Linux kernel DOES NOT WANT TO
  use gcc builtin functions normally available via  libgcc.
  This is primarily to detect when 32-bit machine does arbitrary
  (and expensive) divisions on 64-bit values.  E.g. stupid code
  slipped into fast-paths.

> Regards,
> -velco

/Matti Aarnio  (who originally created this %Ld printing code,
                and which others have mutated since then..)

 
> ===== drivers/net/sk98lin/skproc.c 1.1 vs edited =====
> --- 1.1/drivers/net/sk98lin/skproc.c	Sat Dec  8 02:14:15 2001
> +++ edited/drivers/net/sk98lin/skproc.c	Fri Jan 25 21:20:06 2002
> @@ -339,17 +339,6 @@
>   return (Rest);
>  }
>  
> -
> -#if 0
> -#define do_div(n,base) ({ \
> -long long __res; \
> -__res = ((unsigned long long) n) % (unsigned) base; \
> -n = ((unsigned long long) n) / (unsigned) base; \
> -__res; })
> -
> -#endif
> -
> -
>  /*****************************************************************************
>   *
>   * SkNumber - Print results
> ===== include/asm-arm/div64.h 1.1 vs edited =====
> --- 1.1/include/asm-arm/div64.h	Sat Dec  8 02:13:45 2001
> +++ edited/include/asm-arm/div64.h	Fri Jan 25 21:21:56 2002
> @@ -1,12 +1,11 @@
>  #ifndef __ASM_ARM_DIV64
>  #define __ASM_ARM_DIV64
>  
> -/* We're not 64-bit, but... */
>  #define do_div(n,base)						\
>  ({								\
>  	int __res;						\
> -	__res = ((unsigned long)n) % (unsigned int)base;	\
> -	n = ((unsigned long)n) / (unsigned int)base;		\
> +	__res = ((unsigned long long)n) % (unsigned int)base;	\
> +	n = ((unsigned long long)n) / (unsigned int)base;		\
>  	__res;							\
>  })
>  
> ===== include/asm-cris/div64.h 1.1 vs edited =====
> --- 1.1/include/asm-cris/div64.h	Sat Dec  8 02:13:57 2001
> +++ edited/include/asm-cris/div64.h	Fri Jan 25 21:22:19 2002
> @@ -3,12 +3,11 @@
>  
>  /* copy from asm-arm */
>  
> -/* We're not 64-bit, but... */
>  #define do_div(n,base)						\
>  ({								\
>  	int __res;						\
> -	__res = ((unsigned long)n) % (unsigned int)base;	\
> -	n = ((unsigned long)n) / (unsigned int)base;		\
> +	__res = ((unsigned long long)n) % (unsigned int)base;	\
> +	n = ((unsigned long long)n) / (unsigned int)base;	\
>  	__res;							\
>  })
>  
> ===== include/asm-m68k/div64.h 1.1 vs edited =====
> --- 1.1/include/asm-m68k/div64.h	Sat Dec  8 02:13:35 2001
> +++ edited/include/asm-m68k/div64.h	Fri Jan 25 21:23:59 2002
> @@ -26,8 +26,8 @@
>  #else
>  #define do_div(n,base) ({					\
>  	int __res;						\
> -	__res = ((unsigned long) n) % (unsigned) base;		\
> -	n = ((unsigned long) n) / (unsigned) base;		\
> +	__res = ((unsigned long long) n) % (unsigned) base;	\
> +	n = ((unsigned long long) n) / (unsigned) base;		\
>  	__res;							\
>  })
>  #endif
> ===== include/asm-ppc/div64.h 1.1 vs edited =====
> --- 1.1/include/asm-ppc/div64.h	Sat Dec  8 02:13:37 2001
> +++ edited/include/asm-ppc/div64.h	Fri Jan 25 21:28:49 2002
> @@ -4,10 +4,9 @@
>  #ifndef __PPC_DIV64
>  #define __PPC_DIV64
>  
> -#define do_div(n,base) ({ \
> -int __res; \
> -__res = ((unsigned long) n) % (unsigned) base; \
> -n = ((unsigned long) n) / (unsigned) base; \
> -__res; })
> -
> +#define do_div(n,base) ({					\
> +	int __res;						\
> +	__res = ((unsigned long long) n) % (unsigned) base;	\
> +	n = ((unsigned long long) n) / (unsigned) base;		\
> +	__res; })
>  #endif
> ===== include/asm-sh/div64.h 1.1 vs edited =====
> --- 1.1/include/asm-sh/div64.h	Sat Dec  8 02:13:46 2001
> +++ edited/include/asm-sh/div64.h	Fri Jan 25 21:29:31 2002
> @@ -1,10 +1,9 @@
>  #ifndef __ASM_SH_DIV64
>  #define __ASM_SH_DIV64
>  
> -#define do_div(n,base) ({ \
> -int __res; \
> -__res = ((unsigned long) n) % (unsigned) base; \
> -n = ((unsigned long) n) / (unsigned) base; \
> -__res; })
> -
> +#define do_div(n,base) ({					\
> +	int __res;						\
> +	__res = ((unsigned long long) n) % (unsigned) base;	\
> +	n = ((unsigned long long) n) / (unsigned) base;		\
> +	__res; })
>  #endif /* __ASM_SH_DIV64 */
> ===== include/asm-sparc/div64.h 1.1 vs edited =====
> --- 1.1/include/asm-sparc/div64.h	Sat Dec  8 02:13:36 2001
> +++ edited/include/asm-sparc/div64.h	Fri Jan 25 21:25:39 2002
> @@ -1,11 +1,10 @@
>  #ifndef __SPARC_DIV64
>  #define __SPARC_DIV64
>  
> -/* We're not 64-bit, but... */
>  #define do_div(n,base) ({ \
>  	int __res; \
> -	__res = ((unsigned long) n) % (unsigned) base; \
> -	n = ((unsigned long) n) / (unsigned) base; \
> +	__res = ((unsigned long long) n) % (unsigned) base; \
> +	n = ((unsigned long long) n) / (unsigned) base; \
>  	__res; })
>  
>  #endif /* __SPARC_DIV64 */
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

  parent reply	other threads:[~2002-01-27 18:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-25 19:34 Momchil Velikov
2002-01-25 19:40 ` Jeff Garzik
2002-01-25 21:50   ` Tim Schmielau
2002-01-27 18:04 ` Troy Benjegerdes
2002-01-27 18:51 ` Matti Aarnio [this message]
2002-01-29  0:00   ` 64-bit divide cleanup (tested on ppc) Troy Benjegerdes
2002-02-07 16:11     ` Gabriel Paubert

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=20020127205141.L5808@mea-ext.zmailer.org \
    --to=matti.aarnio@zmailer.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=velco@fadata.bg \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome