From: David C. <wr...@mo...> - 2012-02-20 14:46:51
|
Hello, The file that I think may be causing problems does not contain inline assembler, it is a straight assembly file (redc.asm). I do not see any inline assembly in gmp-ecm. One strange thing I see at the top of that file is the following: # void ecm_redc3(mp_limb_t * z, const mp_limb_t * x, size_t n, mp_limb_t m) # %rdi %rsi %rdx %rcx # MinGW w64 %rcx %rdx %r8 %r9 # save them in %r8 %r9 %r10 %r11 Then there are a few push and pop statements in the file. Maybe the wrong registers are being push-ed and pop-ed for the way mingw64 works? Hmmm, but then why would some printf statements make it work? I'm not very good at tracking down some of these problems. I wish I could create a small test case to reproduce the problem, but I'm not sure that this file is the problem. Actually, I'll try to create a test case with this file later today to see what happens. But in the mean time, can someone else try the steps I have outlined below and let me know if you run into the same problem? Thanks for your time. -David C. On 2/19/2012 11:48 PM, Kai Tietz wrote: > Hi, > > such failures a commonly caused by inline-assembler not treating > memory-ref proper. I assume that inline assembler doesn't specify > explicit memory-clobber/modify. Newer gcc versions are here more > strict then older versions. > > Kai > > 2012/2/20 David Cleaver: >> Hello everyone, >> >> I have run into a very strange problem and I am not sure what might be causing >> it. I am compiling the latest svn of gmp-ecm (right now it is 1746) and >> depending on whether I insert a few extra print statements or not, one certain >> test in gmp-ecm will either run to completion or will seg_fault. Can someone >> here help me test whether this might be a problem with MingW64, Win XP x64, MPIR >> 2.5.0, or maybe something else? I have run into the problem with two different >> sezero builds (20101003 and 20111101) as my MingW64 compiler. I am compiling >> inside an MSYS shell (1.0.16). I am on a Windows XP x64 computer. >> >> Steps to reproduce the problem I am seeing: >> 0) Use MPIR as your GMP library and MingW64 as your compiler >> 1) Download latest gmp-ecm svn (currently 1746) >> 2) run 'autoreconf -i' >> 3) I configure with the following options: >> ./configure CC=gcc CFLAGS="-O2 -pedantic -m64 -std=gnu99 -mtune=core2 >> -march=core2" --enable-asm-redc --build=x86_64-w64-mingw32 --disable-assert >> 4) run 'make' >> >> At this point we can just run the test that fails for me, it is (sorry for any >> wrap around): >> echo >> 449590253344339769860648131841615148645295989319968106906219761704350259884936939123964073775456979170209297434164627098624602597663490109944575251386017 >> | ecm -sigma 63844855 -go 172969 61843 20658299 >> >> The test should produce a 27 digit factor of the 153 digit input. However, in >> my setup it seg_faults, actually just a silent crash with no screen output. >> >> Now, I have been using some printf's (actually outputf in gmp-ecm code) to try >> to track down where the crash was happening. I have found that if I put three >> outputf statements in one part of the code, the program runs successfully and >> produces the factorization. Can anyone else here reproduce this problem? I'm >> curious to see if this problem happens for anyone else on WinXP x64, or maybe on >> Win7 x64. >> >> If anyone can reproduce the crash, can you see if the following change fixes the >> problem in your environment? The diff just applies to one file, mpmod.c. >> $ diff -u ../svn/mpmod.c mpmod.c >> --- ../svn/mpmod.c 2012-02-12 19:59:32 -0600 >> +++ mpmod.c 2012-02-19 14:48:36 -0600 >> @@ -719,8 +719,11 @@ >> #endif /* otherwise go through to the next available mode */ >> case MPMOD_MUL_REDC3: /* mpn_mul_n + ecm_redc3 */ >> #if defined(HAVE_ASM_REDC3) >> +outputf(OUTPUT_VERBOSE, "tmp0=0x%I64x tmp1=0x%I64x tmp2=0x%I64x\n", tmp[0], >> tmp[1], tmp[2]); >> mpn_sqr (tmp, s1p, nn); >> +outputf(OUTPUT_VERBOSE, "tmp0=0x%I64x tmp1=0x%I64x tmp2=0x%I64x\n", tmp[0], >> tmp[1], tmp[2]); >> ecm_redc3 (tmp, np, nn, invm[0]); >> +outputf(OUTPUT_VERBOSE, "tmp0=0x%I64x tmp1=0x%I64x tmp2=0x%I64x\n", tmp[0], >> tmp[1], tmp[2]); >> cy = mpn_add_n (rp, tmp + nn, tmp, nn); >> if (cy != 0) >> mpn_sub_n (rp, rp, np, nn); /* a borrow should always occur here */ >> >> At this point, if you run 'make clean' and 'make' again, then run the test case >> from up above, it should produce a factor very quickly. >> >> For some strange reason, all three of the 'outputf' statements above are >> necessary to make gmp-ecm run to completion. If any of those 'outputf' >> statements are left out, then the program will silently crash. >> >> My guess is that there is some assembly code in gmp-ecm (the ecm_redc3 function, >> found in ecm_svn_1746/x86_64/redc.asm) that MingW64 might not be processing >> correctly. This is just a guess based on the fact that the crash happens with >> both MPIR and GMP (it only happens to GMP if it goes through the same code path >> as MPIR, ask me for the change if you would like to see it with GMP). >> >> Is anyone willing to help me track this problem down? Is there any more >> information that anyone needs to look into this problem? Thanks for your time >> and I'll talk with you later. >> >> -David C. |