mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Programming (https://www.mersenneforum.org/forumdisplay.php?f=29)
-   -   MinGW-w64 (https://www.mersenneforum.org/showthread.php?t=15192)

bsquared 2011-02-01 15:03

MinGW-w64
 
I develop primarily for a linux 64 bit target platform, but I also like to be able to produce windows executables of stuff because I have access to lots of resources in both environments. MinGW-w64 sounds great from that standpoint - a tool which can take my makefile and give me 64 bit windows binaries with all of the goodness that gcc has to offer.

Reality, however, is a large ugly feminine canine. I tried out MinGW-w64-1.0 last night thinking that the 1.0 release would be easier to work with, and while I was able to download, install, and point my path to the directory of binaries, I didn't get any further. Building YAFU failed on the first file when it tried to invoke the assembler (this was inside cygwin). In a native windows command prompt I didn't even get that far because make apparently didn't know how to parse the makefile correctly. I don't know where to look for what #defines are set so that I can properly set preprocessor directives in my code. And so on.

Has anyone here used mingw-w64 to build a factorization project like GMP, GMP-ECM, or GGNFS? If so I would be very grateful for hints on how to make it work. Any advice in general would be appreciated.

ATH 2011-02-01 16:29

WraithX taught me this last year, so he probably knows a lot more about it, but here goes.

I use MSYS 1.0.11 which is the last version with a windows install .exe, get "MSYS-1.0.11.exe" here:
[URL="http://sourceforge.net/projects/mingw/files/MSYS/BaseSystem/msys-core/msys-1.0.11/"]http://sourceforge.net/projects/mingw/files/MSYS/BaseSystem/msys-core/msys-1.0.11/[/URL]
I usually install it to the suggested c:\msys folder.

I use the personal build of Mingw64 from sezero, but this means its not the newest version. I tried the automatic builds but couldn't get them to work, so WraithX guided me to this one.
Get the file "mingw-w64-bin_x86_64-mingw_20101003_sezero.zip" here:
[URL="http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/sezero_20101003/"]http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/sezero_20101003/[/URL]
You can unpack the zip to c:\ because it contains the subfolder mingw64. Then go to C:\msys\1.0\etc and rename "fstab.sample" to "fstab" and edit it and add the line: c:/mingw64 /mingw
Now edit the "profile" file in the same folder. In the line starting with export PATH=".: there is probably a /mingw/bin, change this to /c/mingw64/bin .
If there is no /mingw/bin just add /c/mingw64/bin to the end of the line before :$PATH".
Now start Msys from the installed link and type "which gcc" and this should echo "/c/mingw64/bin/gcc.exe", and now you are ready to go.

bsquared 2011-02-01 16:35

Great, thanks!

I'll try that out tonight... hopefully that will do it. Have you used mingw64 to build gmp-ecm for windows?

ATH 2011-02-01 16:40

If you want the latest Msys 1.0.16, you can get it through the Mingw32 automatic installer. I haven't tested this but it should work.

Get "mingw-get-inst-20101030.exe" from here: [URL="http://sourceforge.net/projects/mingw/files/"]http://sourceforge.net/projects/mingw/files/[/URL]
Run it and choose "Download latest repository catalogues" and in the Select Components window choose "MSYS Basic System". This will install Mingw32 to c:\MinGW and the latest Msys to a subfolder: c:\MinGW\Msys.
Now get the Mingw64 zip as before or try the newer automatic builds:
[URL="http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Automated%20Builds/"]http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Automated%20Builds/[/URL]
and extract to c:\mingw64. Now go to c:\MinGW\Msys\1.0\etc and edit "fstab" and "profile" like before.

ATH 2011-02-01 16:44

Yes I built the GMP-ECM 64bit with mingw64: [URL="http://www.hoegge.dk/GMP-ECM.html"]GMP-ECM.html[/URL]

For 32bit versions I used the Msys 1.0.16 and Mingw32.

bsquared 2011-02-01 16:50

Perfect - I'll let you know how it goes.

Thanks again.

bsquared 2011-02-02 06:26

Following your guidance I was able to build YAFU with mingw-64! Thanks a ton for your help.

There are a couple remaining issues
1) I get spammed with all sorts of "integer constant too large for 'long' type" messages when things are clearly declared as long long unsigned int.
2) I also get spammed with lots of complaints about printing 64 bit quantities
3) aligned memory allocations don't seem to work.

I redefined memalign to _mm_align and changed all of the appropriate "free" functions to _mm_free. But SIQS (which heavily relies on aligned memory allocation) crashes immediately when I run it. Everything else about the build seems to work, so I suspect the aligned memory allocation.

Any thoughts on the above points?

WraithX 2011-02-02 13:40

[QUOTE=bsquared;250906]Following your guidance I was able to build YAFU with mingw-64! Thanks a ton for your help.

There are a couple remaining issues
1) I get spammed with all sorts of "integer constant too large for 'long' type" messages when things are clearly declared as long long unsigned int.
2) I also get spammed with lots of complaints about printing 64 bit quantities
3) aligned memory allocations don't seem to work.

Any thoughts on the above points?[/QUOTE]

Congratulations on getting yafu to build in mingw64! I admit it, you are better than I am. ;)

For 1) you will probably have to put ll (long long) or ull (unsigned long long) after the number to clear those error messages. For example:
int64_t big_num = 12345678901ll;
uint64_t very_big_num = 18446744073709551615ull;

For 2) there are several ways to print out 64-bit variables, not all ways are supported by all compilers. Here are some different ways:
printf("%lld", big_num);
printf("%llu", very_big_num);
printf("%PRId64", big_num);
pritnf("%PRIu64", very_big_num);

For 3) I don't know about memory alignments, so I can't help here.

rogue 2011-02-02 13:41

[QUOTE=bsquared;250906]Following your guidance I was able to build YAFU with mingw-64! Thanks a ton for your help.

There are a couple remaining issues
1) I get spammed with all sorts of "integer constant too large for 'long' type" messages when things are clearly declared as long long unsigned int.
2) I also get spammed with lots of complaints about printing 64 bit quantities
3) aligned memory allocations don't seem to work.

I redefined memalign to _mm_align and changed all of the appropriate "free" functions to _mm_free. But SIQS (which heavily relies on aligned memory allocation) crashes immediately when I run it. Everything else about the build seems to work, so I suspect the aligned memory allocation.

Any thoughts on the above points?[/QUOTE]

You probably need to add the ULL or LL suffix to the integer definition.
Are you using %lld for printing 64-bit quantities (depending upon 32 vs 64 bit build)?

bsquared 2011-02-02 14:04

Thanks rogue and wraithX. I'm using %llu, %lld, %llx for printing 64bit quantities, and they do print just fine. gcc still complains something to the effect that: "%llu expects long long unsigned ints, but foo is of type uint64". But I've globally typedef'd uint64 to be long long unsigned int -- apparently gcc can't work its way through that layer of abstraction?

I didn't think about adding ll or ull as a suffix to 64 bit constants. Will that syntax still work for normal (non-mingw64) gcc builds too, do you know? It would be annoying to have to #ifdef all the constants in the code just to make mingw64 happy.

Unfortunately it's the last point which is the most important: the whole reason I'm trying mingw64 is to make use of 64 bit assembler optimizations in the SIQS routine. If I can't get past aligned memory allocation (or whatever the problem is), then I'm sunk.

I'll look into it more tonight. Thanks again for everyone's help.

WraithX 2011-02-02 15:03

[QUOTE=bsquared;250943]
I didn't think about adding ll or ull as a suffix to 64 bit constants. Will that syntax still work for normal (non-mingw64) gcc builds too, do you know? It would be annoying to have to #ifdef all the constants in the code just to make mingw64 happy.[/QUOTE]

This syntax should work on all systems. No need to #ifdef these.

[QUOTE=bsquared;250943]
Unfortunately it's the last point which is the most important: the whole reason I'm trying mingw64 is to make use of 64 bit assembler optimizations in the SIQS routine. If I can't get past aligned memory allocation (or whatever the problem is), then I'm sunk.

I'll look into it more tonight. Thanks again for everyone's help.[/QUOTE]

Looking around, maybe you can use:
_aligned_malloc
_aligned_free
A Microsoft page describing it is here:
[url]http://msdn.microsoft.com/en-us/library/8z34s9c6%28vs.71%29.aspx[/url]


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

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