linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* div64.h:do_div() bug
@ 2003-09-29 13:25 Artur Klauser
  2003-09-29 14:18 ` Matti Aarnio
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Artur Klauser @ 2003-09-29 13:25 UTC (permalink / raw)
  To: linux-kernel; +Cc: Artur Klauser

I've found that a bug in asm-arm/div64.h:do_div() is preventing correct
conversion of timestamps in smbfs (and probably ntfs as well) from NT to
Unix format. I'll post a patch that fixes the bug, but I think it is also
present in other architectures - at least SPARC, SH, and CRIS look
suspicious.

If people with access to these architectures could run the following small 
test and let me know the outcome, I can fix it there too - thanks.

//-----------------------------------------------------------------------------
#define __KERNEL__
#include <asm/types.h> // get kernel definition of u64, u32
#undef __KERNEL__
#include <asm/div64.h> // get definition of do_div()
#include <stdio.h>

main () {
  union {
    u64 n64;
    u32 n32[2];
  } in, out;

  in.n32[0] = 1;
  in.n32[1] = 1;
  out = in;

  do_div(out.n64, 1);

  if (in.n64 != out.n64) {
    printf("FAILURE: asm/div64.h:do_div() is broken for 64-bit dividends\n");
    exit(1);
  } else {
    printf("Congratulations: asm/div64.h:do_div() handles 64-bit dividends\n");
  }
  return 0;
}
//-----------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: div64.h:do_div() bug
  2003-09-29 13:25 div64.h:do_div() bug Artur Klauser
@ 2003-09-29 14:18 ` Matti Aarnio
  2003-09-30  9:52 ` Rogier Wolff
  2003-09-30 12:53 ` div64.h:do_div() bug - SPARC, SH anbody? Artur Klauser
  2 siblings, 0 replies; 8+ messages in thread
From: Matti Aarnio @ 2003-09-29 14:18 UTC (permalink / raw)
  To: Artur Klauser; +Cc: linux-kernel

On Mon, Sep 29, 2003 at 03:25:19PM +0200, Artur Klauser wrote:
> I've found that a bug in asm-arm/div64.h:do_div() is preventing correct
> conversion of timestamps in smbfs (and probably ntfs as well) from NT to
> Unix format. I'll post a patch that fixes the bug, but I think it is also
> present in other architectures - at least SPARC, SH, and CRIS look
> suspicious.
> 
> If people with access to these architectures could run the following small 
> test and let me know the outcome, I can fix it there too - thanks.

Call it "lack/lazyness of implementation"

Long ago it was used only in  printk()  debug printouts.
Now it is used all over the place.  At least its users are aware of
it being slow, and not just using GCC's magic bultin codes.


> //-----------------------------------------------------------------------------
> #define __KERNEL__
> #include <asm/types.h> // get kernel definition of u64, u32
> #undef __KERNEL__
> #include <asm/div64.h> // get definition of do_div()
> #include <stdio.h>
> 
> main () {
>   union {
>     u64 n64;
>     u32 n32[2];
>   } in, out;
> 
>   in.n32[0] = 1;
>   in.n32[1] = 1;
>   out = in;
> 
>   do_div(out.n64, 1);
> 
>   if (in.n64 != out.n64) {
>     printf("FAILURE: asm/div64.h:do_div() is broken for 64-bit dividends\n");
>     exit(1);
>   } else {
>     printf("Congratulations: asm/div64.h:do_div() handles 64-bit dividends\n");
>   }
>   return 0;
> }

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: div64.h:do_div() bug
  2003-09-29 13:25 div64.h:do_div() bug Artur Klauser
  2003-09-29 14:18 ` Matti Aarnio
@ 2003-09-30  9:52 ` Rogier Wolff
  2003-09-30 10:14   ` Matti Aarnio
  2003-09-30 12:53 ` div64.h:do_div() bug - SPARC, SH anbody? Artur Klauser
  2 siblings, 1 reply; 8+ messages in thread
From: Rogier Wolff @ 2003-09-30  9:52 UTC (permalink / raw)
  To: Artur Klauser; +Cc: linux-kernel

On Mon, Sep 29, 2003 at 03:25:19PM +0200, Artur Klauser wrote:
> I've found that a bug in asm-arm/div64.h:do_div() is preventing correct
> conversion of timestamps in smbfs (and probably ntfs as well) from NT to

Nope. 

>   if (in.n64 != out.n64) {
>     printf("FAILURE: asm/div64.h:do_div() is broken for 64-bit dividends\n");

do_div should be/is documented as not doing 64 bit dividents. It does
64/32 -> 32 divides, IIRC... 

		Roger. 

(This EMail has a Unique reply address, so that I can count the number
of times that SWEN bites... :-)

-- 
** R.E.Wolff@BitWizard.nl ** http://www.BitWizard.nl/ ** +31-15-2600998 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
**** "Linux is like a wigwam -  no windows, no gates, apache inside!" ****

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: div64.h:do_div() bug
  2003-09-30  9:52 ` Rogier Wolff
@ 2003-09-30 10:14   ` Matti Aarnio
  2003-09-30 11:28     ` Matti Aarnio
  0 siblings, 1 reply; 8+ messages in thread
From: Matti Aarnio @ 2003-09-30 10:14 UTC (permalink / raw)
  To: Rogier Wolff; +Cc: Artur Klauser, linux-kernel

On Tue, Sep 30, 2003 at 11:52:29AM +0200, Rogier Wolff wrote:
> On Mon, Sep 29, 2003 at 03:25:19PM +0200, Artur Klauser wrote:
> > I've found that a bug in asm-arm/div64.h:do_div() is preventing correct
> > conversion of timestamps in smbfs (and probably ntfs as well) from NT to
> 
> Nope. 

  Nope yourself.

> >   if (in.n64 != out.n64) {
> >     printf("FAILURE: asm/div64.h:do_div() is broken for 64-bit dividends\n");
> 
> do_div should be/is documented as not doing 64 bit dividents. It does
> 64/32 -> 32 divides, IIRC... 

  64/32 -> 64,32

The REMAINDER is 32 bit value.

> 		Roger. 

/Matti Aarnio

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: div64.h:do_div() bug
  2003-09-30 10:14   ` Matti Aarnio
@ 2003-09-30 11:28     ` Matti Aarnio
  2003-09-30 12:30       ` Andreas Schwab
  0 siblings, 1 reply; 8+ messages in thread
From: Matti Aarnio @ 2003-09-30 11:28 UTC (permalink / raw)
  To: Rogier Wolff, Artur Klauser, linux-kernel

On Tue, Sep 30, 2003 at 01:14:38PM +0300, Matti Aarnio wrote:
> On Tue, Sep 30, 2003 at 11:52:29AM +0200, Rogier Wolff wrote:
> > On Mon, Sep 29, 2003 at 03:25:19PM +0200, Artur Klauser wrote:
> > > I've found that a bug in asm-arm/div64.h:do_div() is preventing correct
> > > conversion of timestamps in smbfs (and probably ntfs as well) from NT to
> > 
> > Nope. 
> 
>   Nope yourself.
> 
> > >   if (in.n64 != out.n64) {
> > >     printf("FAILURE: asm/div64.h:do_div() is broken for 64-bit dividends\n");
> > 
> > do_div should be/is documented as not doing 64 bit dividents. It does
> > 64/32 -> 32 divides, IIRC... 
> 
>   64/32 -> 64,32
> 
> The REMAINDER is 32 bit value.

Non-native english speaker makes the mistake..  MODULUS is 32 bits as is
DIVISOR, REMAINDER is 64 bit, as is DIVIDEND.

That is:
	DIVIDEND / DIVISOR -> REMAINDER , MODULUS

and
	REMAINDER * DIVISOR + MODULUS = DIVIDEND

> > 		Roger. 
 
/Matti Aarnio

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: div64.h:do_div() bug
  2003-09-30 11:28     ` Matti Aarnio
@ 2003-09-30 12:30       ` Andreas Schwab
  2003-09-30 12:41         ` Artur Klauser
  0 siblings, 1 reply; 8+ messages in thread
From: Andreas Schwab @ 2003-09-30 12:30 UTC (permalink / raw)
  To: Matti Aarnio; +Cc: Rogier Wolff, Artur Klauser, linux-kernel

Matti Aarnio <matti.aarnio@zmailer.org> writes:

> On Tue, Sep 30, 2003 at 01:14:38PM +0300, Matti Aarnio wrote:
>> On Tue, Sep 30, 2003 at 11:52:29AM +0200, Rogier Wolff wrote:
>> > On Mon, Sep 29, 2003 at 03:25:19PM +0200, Artur Klauser wrote:
>> > > I've found that a bug in asm-arm/div64.h:do_div() is preventing correct
>> > > conversion of timestamps in smbfs (and probably ntfs as well) from NT to
>> > 
>> > Nope. 
>> 
>>   Nope yourself.
>> 
>> > >   if (in.n64 != out.n64) {
>> > >     printf("FAILURE: asm/div64.h:do_div() is broken for 64-bit dividends\n");
>> > 
>> > do_div should be/is documented as not doing 64 bit dividents. It does
>> > 64/32 -> 32 divides, IIRC... 
>> 
>>   64/32 -> 64,32
>> 
>> The REMAINDER is 32 bit value.
>
> Non-native english speaker makes the mistake..  MODULUS is 32 bits as is
> DIVISOR, REMAINDER is 64 bit, as is DIVIDEND.
>
> That is:
> 	DIVIDEND / DIVISOR -> REMAINDER , MODULUS
                              ^^^^^^^^^^^^^^^^^^^
???
                              QUOTIENT, REMAINDER

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: div64.h:do_div() bug
  2003-09-30 12:30       ` Andreas Schwab
@ 2003-09-30 12:41         ` Artur Klauser
  0 siblings, 0 replies; 8+ messages in thread
From: Artur Klauser @ 2003-09-30 12:41 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Matti Aarnio, Rogier Wolff, linux-kernel

On Tue, 30 Sep 2003, Andreas Schwab wrote:
> Matti Aarnio <matti.aarnio@zmailer.org> writes:
> > On Tue, Sep 30, 2003 at 01:14:38PM +0300, Matti Aarnio wrote:
> >> On Tue, Sep 30, 2003 at 11:52:29AM +0200, Rogier Wolff wrote:
> >> > On Mon, Sep 29, 2003 at 03:25:19PM +0200, Artur Klauser wrote:
> >> > > I've found that a bug in asm-arm/div64.h:do_div() is preventing correct
> >> > > conversion of timestamps in smbfs (and probably ntfs as well) from NT to
> >> >
> >> > Nope.
> >>
> >>   Nope yourself.
> >>
> >> > >   if (in.n64 != out.n64) {
> >> > >     printf("FAILURE: asm/div64.h:do_div() is broken for 64-bit dividends\n");
> >> >
> >> > do_div should be/is documented as not doing 64 bit dividents. It does
> >> > 64/32 -> 32 divides, IIRC...
> >>
> >>   64/32 -> 64,32
> >>
> >> The REMAINDER is 32 bit value.
> >
> > Non-native english speaker makes the mistake..  MODULUS is 32 bits as is
> > DIVISOR, REMAINDER is 64 bit, as is DIVIDEND.
> >
> > That is:
> > 	DIVIDEND / DIVISOR -> REMAINDER , MODULUS
>                               ^^^^^^^^^^^^^^^^^^^
> ???
>                               QUOTIENT, REMAINDER

Actually, I have to agree with Andreas here - and with Matti's 1st naming
attempt :)

But whatever the naming is, the operation AFAICT should be, and is
implemented that way in other asm-<arch>/div64.h:do_div() macros:

do_div(u64, u32)
  u64 / u32  ->  u64  (modifies 1st argument)
  u64 % u32  ->  u32  (return value)

 -r2r-

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: div64.h:do_div() bug - SPARC, SH anbody?
  2003-09-29 13:25 div64.h:do_div() bug Artur Klauser
  2003-09-29 14:18 ` Matti Aarnio
  2003-09-30  9:52 ` Rogier Wolff
@ 2003-09-30 12:53 ` Artur Klauser
  2 siblings, 0 replies; 8+ messages in thread
From: Artur Klauser @ 2003-09-30 12:53 UTC (permalink / raw)
  To: linux-kernel

Got confirmation that ARM and CRIS experience the problem, pending info
from folks with access to SPARC or SH architectures... anybody?

 -r2r-

On Mon, 29 Sep 2003, Artur Klauser wrote:
> I've found that a bug in asm-arm/div64.h:do_div() is preventing correct
> conversion of timestamps in smbfs (and probably ntfs as well) from NT to
> Unix format. I'll post a patch that fixes the bug, but I think it is also
> present in other architectures - at least SPARC, SH, and CRIS look
> suspicious.
>
> If people with access to these architectures could run the following small
> test and let me know the outcome, I can fix it there too - thanks.
>
> //-----------------------------------------------------------------------------
> #define __KERNEL__
> #include <asm/types.h> // get kernel definition of u64, u32
> #undef __KERNEL__
> #include <asm/div64.h> // get definition of do_div()
> #include <stdio.h>
>
> main () {
>   union {
>     u64 n64;
>     u32 n32[2];
>   } in, out;
>
>   in.n32[0] = 1;
>   in.n32[1] = 1;
>   out = in;
>
>   do_div(out.n64, 1);
>
>   if (in.n64 != out.n64) {
>     printf("FAILURE: asm/div64.h:do_div() is broken for 64-bit dividends\n");
>     exit(1);
>   } else {
>     printf("Congratulations: asm/div64.h:do_div() handles 64-bit dividends\n");
>   }
>   return 0;
> }
> //-----------------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-09-30 13:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-29 13:25 div64.h:do_div() bug Artur Klauser
2003-09-29 14:18 ` Matti Aarnio
2003-09-30  9:52 ` Rogier Wolff
2003-09-30 10:14   ` Matti Aarnio
2003-09-30 11:28     ` Matti Aarnio
2003-09-30 12:30       ` Andreas Schwab
2003-09-30 12:41         ` Artur Klauser
2003-09-30 12:53 ` div64.h:do_div() bug - SPARC, SH anbody? Artur Klauser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).