mersenneforum.org  

Go Back   mersenneforum.org > Factoring Projects > Cunningham Tables

Reply
 
Thread Tools
Old 2010-10-01, 00:36   #1
R.D. Silverman
 
R.D. Silverman's Avatar
 
Nov 2003

723210 Posts
Default Help! Compiler bug

Here is a code snippet:

Code:
void prepare_bounds(v1, v2, sign)
int v1[2], v2[2], sign;

{   /* start of prepare_bounds */

double m_over_a1, n_over_b1, b0_over_b1, a0_over_a1;
double a0, a1, b0, b1, one_over_a1, one_over_b1;
double l1and4, l2and3, l1and3, determ, inv_determ;
double stime;
double temp;


temp = get_time();
if (TIME_STATS) stime = get_time();
printf("1");
a0 = (double)v1[0];
a1 = (double)v2[0];
b0 = (double)v1[1];
b1 = (double)v2[1];
printf("2");
I am trying to produce a release (i.e. non-debug) executable for my siever
using Visual Studio 2010.

As written exactly above the code runs just fine.

If I delete the "printf("1");" statement, the code core dumps before
hitting printf("2");

If I delete the calls to get_time(), the code runs fine.

This seems to be the same compiler bug that I saw with VS 2008.
Apparently, the code is doing a register mis-allocation involving the call
to get_time. Adding the printf("1") statement seems to make the problem
go bye-bye.....

This is a total mystery.

Comments would be GREATLY appreciated.
R.D. Silverman is offline   Reply With Quote
Old 2010-10-01, 00:39   #2
R.D. Silverman
 
R.D. Silverman's Avatar
 
Nov 2003

161008 Posts
Default

Quote:
Originally Posted by R.D. Silverman View Post
Here is a code snippet:

Code:
void prepare_bounds(v1, v2, sign)
int v1[2], v2[2], sign;

{   /* start of prepare_bounds */

double m_over_a1, n_over_b1, b0_over_b1, a0_over_a1;
double a0, a1, b0, b1, one_over_a1, one_over_b1;
double l1and4, l2and3, l1and3, determ, inv_determ;
double stime;
double temp;


temp = get_time();
if (TIME_STATS) stime = get_time();
printf("1");
a0 = (double)v1[0];
a1 = (double)v2[0];
b0 = (double)v1[1];
b1 = (double)v2[1];
printf("2");
I am trying to produce a release (i.e. non-debug) executable for my siever
using Visual Studio 2010.

As written exactly above the code runs just fine.

If I delete the "printf("1");" statement, the code core dumps before
hitting printf("2");

If I delete the calls to get_time(), the code runs fine.

This seems to be the same compiler bug that I saw with VS 2008.
Apparently, the code is doing a register mis-allocation involving the call
to get_time. Adding the printf("1") statement seems to make the problem
go bye-bye.....

This is a total mystery.

Comments would be GREATLY appreciated.
I forgot to mention. If I produce a debug version, even without the
printf statements, the code runs fine. It also runs fine without the
printf's when compiled with Visual C++ 5.0 and Visual C++ 6.0

WTF is going on here????

It is only when I produce a RELEASE version under Vs2010 that the code
barfs.
R.D. Silverman is offline   Reply With Quote
Old 2010-10-01, 00:54   #3
R.D. Silverman
 
R.D. Silverman's Avatar
 
Nov 2003

26·113 Posts
Default

Quote:
Originally Posted by R.D. Silverman View Post
I forgot to mention. If I produce a debug version, even without the
printf statements, the code runs fine. It also runs fine without the
printf's when compiled with Visual C++ 5.0 and Visual C++ 6.0

WTF is going on here????

It is only when I produce a RELEASE version under Vs2010 that the code
barfs.
One final piece of information. get_time() is called in MANY places throughout
the code. It only barfs within this little piece of code.
R.D. Silverman is offline   Reply With Quote
Old 2010-10-01, 01:32   #4
alpertron
 
alpertron's Avatar
 
Aug 2002
Buenos Aires, Argentina

101001110002 Posts
Default

Are you compiling in 32-bit mode? Notice that there are some differences in 64 bits so if you for example cast pointers which are 64 bits long to integer (32 bits) and then you try to use them again as pointers, it will fail.

It is possible that before entering that function the heap and/or the stack were corrupted, so the function get_time() just triggers the error that was already present.
alpertron is offline   Reply With Quote
Old 2010-10-01, 01:34   #5
Robert Holmes
 
Robert Holmes's Avatar
 
Oct 2007

23·13 Posts
Default

That's a weird problem.

I assume this is being compiled in 32-bit mode. Instead of printf("1"), try putting an inline asm block that does nothing, like

Code:
__asm { nop }
The compiler should be forced to separate the function before and after the assembly block, and that might work around the bug.

Last fiddled with by Robert Holmes on 2010-10-01 at 01:35
Robert Holmes is offline   Reply With Quote
Old 2010-10-01, 01:44   #6
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

24·3·73 Posts
Default

Code:
void prepare_bounds(v1, v2, sign)
int v1[2], v2[2], sign;
Quote:
Originally Posted by R.D. Silverman

WTF is going on here????
http://msdn.microsoft.com/en-us/library/efx873ys.aspx

Looks like you function variable declarations/definitions are old school

Last fiddled with by paulunderwood on 2010-10-01 at 01:49
paulunderwood is offline   Reply With Quote
Old 2010-10-01, 02:44   #7
R.D. Silverman
 
R.D. Silverman's Avatar
 
Nov 2003

26·113 Posts
Default

Quote:
Originally Posted by alpertron View Post
Are you compiling in 32-bit mode? Notice that there are some differences in 64 bits so if you for example cast pointers which are 64 bits long to integer (32 bits) and then you try to use them again as pointers, it will fail.
There are no 64 bit pointers in the code.

Quote:

It is possible that before entering that function the heap and/or the stack were corrupted, so the function get_time() just triggers the error that was already present.
This does not explain why adding a printf fixes the problem.

This is a register misallocation. Adding the printf causes the compiler to use
its registers differently.
R.D. Silverman is offline   Reply With Quote
Old 2010-10-01, 02:45   #8
R.D. Silverman
 
R.D. Silverman's Avatar
 
Nov 2003

26·113 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
Code:
void prepare_bounds(v1, v2, sign)
int v1[2], v2[2], sign;

http://msdn.microsoft.com/en-us/library/efx873ys.aspx

Looks like you function variable declarations/definitions are old school
Irrelevant.
R.D. Silverman is offline   Reply With Quote
Old 2010-10-01, 11:35   #9
alpertron
 
alpertron's Avatar
 
Aug 2002
Buenos Aires, Argentina

23·167 Posts
Default

Quote:
Originally Posted by R.D. Silverman View Post
There are no 64 bit pointers in the code.

This does not explain why adding a printf fixes the problem.

This is a register misallocation. Adding the printf causes the compiler to use
its registers differently.
Maybe it is a problem on the optimization stage. I suggest you to change the project in order to add debugging information in the RELEASE version, and then run your program until the function is reached. Then run it step by step in the disassembler window. You can see in this way whether the function was compiled correctly or not.
alpertron is offline   Reply With Quote
Old 2010-10-01, 11:45   #10
R.D. Silverman
 
R.D. Silverman's Avatar
 
Nov 2003

1C4016 Posts
Default

Quote:
Originally Posted by alpertron View Post
Maybe it is a problem on the optimization stage. I suggest you to change the project in order to add debugging information in the RELEASE version, and then run your program until the function is reached. Then run it step by step in the disassembler window. You can see in this way whether the function was compiled correctly or not.
Instead, I am just going to kick out the assembler code and look at it.
R.D. Silverman is offline   Reply With Quote
Old 2010-10-01, 23:22   #11
R.D. Silverman
 
R.D. Silverman's Avatar
 
Nov 2003

26·113 Posts
Default

Quote:
Originally Posted by R.D. Silverman View Post
Here is a code snippet:

Code:
void prepare_bounds(v1, v2, sign)
int v1[2], v2[2], sign;

{   /* start of prepare_bounds */

double m_over_a1, n_over_b1, b0_over_b1, a0_over_a1;
double a0, a1, b0, b1, one_over_a1, one_over_b1;
double l1and4, l2and3, l1and3, determ, inv_determ;
double stime;
double temp;


temp = get_time();
if (TIME_STATS) stime = get_time();
printf("1");
a0 = (double)v1[0];
a1 = (double)v2[0];
b0 = (double)v1[1];
b1 = (double)v2[1];
printf("2");
I am trying to produce a release (i.e. non-debug) executable for my siever
using Visual Studio 2010.

As written exactly above the code runs just fine.

If I delete the "printf("1");" statement, the code core dumps before
hitting printf("2");

If I delete the calls to get_time(), the code runs fine.

This seems to be the same compiler bug that I saw with VS 2008.
Apparently, the code is doing a register mis-allocation involving the call
to get_time. Adding the printf("1") statement seems to make the problem
go bye-bye.....

This is a total mystery.

Comments would be GREATLY appreciated.
More weirdness. If I replace printf("1") with do_nothing("1") where
do_nothing is just a dummy routine the code STILL fails.

How can the addition of a printf of a static string cure a core dump
caused by a read access failure?
R.D. Silverman is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
mprime 28.10 compiler warning Explorer09 Software 1 2017-01-23 02:50
GCC/compiler warnings Dubslow Programming 2 2016-02-27 06:55
compiler/assembler optimizations possible? ixfd64 Software 7 2011-02-25 20:05
Linux32 -> Windows64 C compiler? geoff Programming 3 2007-09-26 03:09
/. Video processor compiler tha Hardware 17 2005-10-12 08:10

All times are UTC. The time now is 08:00.

Mon Nov 30 08:00:30 UTC 2020 up 81 days, 5:11, 3 users, load averages: 1.55, 1.45, 1.39

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.