Quantcast

64-bit unsigned integer multiplication

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

64-bit unsigned integer multiplication

Matthew Kille
Hi All,

I'm seeing some problems with 64-bit integer multiplication when using
the optimiser. Can somebody confirm whether there are any known problems?

I have created a minimal test program to hopefully demonstrate the
issue, (see attached). The program does the same multiply twice; first
time to show the result we are expecting, and the second time using a
little extra code to force the optimiser into having to do some
non-trivial work.

The output is written to a file in the root. The results should clearly
be the same each case, but with optimisation enabled the results are as
follows:

a = 1000
b = 4294967295
a * b = 4294967295000

a = 1000
b = 4294967295
a * b = 18446744073709550616

(0x3e7fffffc18 compared to 0xfffffffffffffc18).

Looks like the most significant word is being miscalculated. With
optimisation switched off -O0 or a different value for 'b' the second
answer is correct, matching the first.

I'm using the 0.51 release. I haven't been able to test with 0.55 (no
Cygwin release) and the latest SVN sources have trouble building.

$ arm-wince-mingw32ce-gcc -v
Using built-in specs.
Target: arm-wince-mingw32ce
Configured with: /home/pedro/cegcc/0.51/src/gcc/configure --with-gcc
--with-gnu-ld --with-gnu-as --target=arm-wince-mingw32ce
--prefix=/opt/mingw32ce --enable-threads=win32 --disable-nls
--enable-languages=c,c++ --disable-win32-registry --disable-multilib
--disable-interwork --without-newlib --enable-checking --with-headers
Thread model: win32
gcc version 4.1.0

I would be pleased for any guidance on this matter and indeed whether
others experience the same thing.

--
Matt


#include <windows.h>
#include <inttypes.h>

int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
            LPWSTR lpCmdLine, int nCmdShow)
{
   FILE *f;

   if ((f = fopen("output.txt", "w")))
   {
      uint64_t a, b, result;

      b = 0xffffffffULL;

      a = 1000;
      {
         result = a * b;

         fprintf(f, "a = %"PRIu64"\n", a);
         fprintf(f, "b = %"PRIu64"\n", b);
         fprintf(f, "a * b = %"PRIu64"\n\n", result);
      }

      for (a = 1000; a < 1001; a += 1+(rand()%2))
      {
         result = a * b;

         fprintf(f, "a = %"PRIu64"\n", a);
         fprintf(f, "b = %"PRIu64"\n", b);
         fprintf(f, "a * b = %"PRIu64"\n\n", result);
      }

      fclose(f);
   }

   MessageBoxW(0, L"", L"Done", 0);
   return 0;
}

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cegcc-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/cegcc-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: 64-bit unsigned integer multiplication

Matthew Kille
Hi All,

Update: Now have a working copy SVN revision 1353 compiler to use. The
uint64 multiplication problem mentioned seems to have gone away now.
Will report if I have any further trouble.

Cheers,

--
Matt.


Matthew Kille wrote:

> Hi All,
>
> I'm seeing some problems with 64-bit integer multiplication when using
> the optimiser. Can somebody confirm whether there are any known problems?
>
> I have created a minimal test program to hopefully demonstrate the
> issue, (see attached). The program does the same multiply twice; first
> time to show the result we are expecting, and the second time using a
> little extra code to force the optimiser into having to do some
> non-trivial work.
>
> The output is written to a file in the root. The results should clearly
> be the same each case, but with optimisation enabled the results are as
> follows:
>
> a = 1000
> b = 4294967295
> a * b = 4294967295000
>
> a = 1000
> b = 4294967295
> a * b = 18446744073709550616
>
> (0x3e7fffffc18 compared to 0xfffffffffffffc18).
>
> Looks like the most significant word is being miscalculated. With
> optimisation switched off -O0 or a different value for 'b' the second
> answer is correct, matching the first.
>
> I'm using the 0.51 release. I haven't been able to test with 0.55 (no
> Cygwin release) and the latest SVN sources have trouble building.
>
> $ arm-wince-mingw32ce-gcc -v
> Using built-in specs.
> Target: arm-wince-mingw32ce
> Configured with: /home/pedro/cegcc/0.51/src/gcc/configure --with-gcc
> --with-gnu-ld --with-gnu-as --target=arm-wince-mingw32ce
> --prefix=/opt/mingw32ce --enable-threads=win32 --disable-nls
> --enable-languages=c,c++ --disable-win32-registry --disable-multilib
> --disable-interwork --without-newlib --enable-checking --with-headers
> Thread model: win32
> gcc version 4.1.0
>
> I would be pleased for any guidance on this matter and indeed whether
> others experience the same thing.
>
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Cegcc-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/cegcc-devel


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Cegcc-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/cegcc-devel
Loading...