понедельник, 28 мая 2012 г.

Building ecl 12.5.1 for win64

It seems that current support of win64 is broken - you can only set GMP_TYPE to gc (although gmp has right project in msvc\gmp\build.vc8\lib_gmp_amd64) and anyway building ends with following error:

        cl -c /EHsc /DGC_DLL /DGC_BUILD /nologo /D_CRT_SECURE_NO_DEPRECATE /DNDEBUG /MD /O2 /arch:SSE2 -DG
ECL_API="__declspec(dllexport)" -I./ -I../ -I..\..\src\c -I..\..\src/gc/include  -I..\..\src/gc/include/pr
umber.obj number.c
cl : Command line warning D9002 : ignoring unknown option '/arch:SSE2'
number.c
../../src/c/number.d(479) : error C4235: nonstandard extension used : '__asm' keyword not supported on this architecture
../../src/c/number.d(479) : error C2065: 'fwait' : undeclared identifier
../../src/c/number.d(497) : error C4235: nonstandard extension used : '__asm' keyword not supported on this architecture
../../src/c/number.d(497) : error C2065: 'fwait' : undeclared identifier
NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\cl.EXE"' : re
'0x2'
Stop.

So I made set of patches to build ecl on win64

msvc\gmp\Makefile patch
*** C:\src\ecl\msvc\gmp\Makefile    Fri May 25 18:29:16 2012
--- Makefile    Fri May 25 18:22:23 2012
*************** srcdir = ..\..\src\gmp
*** 3,12 ****
--- 3,81 ----
  #
  # Change for other configurations
  #
+ !if "$(BITS)" == "64"
+ BITS=64
+ YASM_TARGET=win64
+ YASM_FLAGS=-D PIC
+ D_WIN64=/D "WIN64"
+ MPN_TYPE = amd64
+ !else
  BITS=32
+ YASM_TARGET=win32
+ YASM_FLAGS=
+ D_WIN64=
+ MPN_TYPE = p3
+ !endif
 
  AUTO_SUBDIRS = mpf mpq printf scanf
 
+ # for amd
+ MPN_AMD64_C_SOURCES = \
+     mpn\generic\popham_amd64.c \
+     mpn\generic\add.c \
+     mpn\generic\add_1.c \
+     mpn\generic\add_n.c \
+     mpn\generic\addmul_1.c \
+     mpn\generic\addsub_n.c \
+     mpn\generic\bdivmod.c \
+     mpn\generic\cmp.c \
+     mpn\generic\dc_divrem_n.c \
+     mpn\generic\dive_1.c \
+     mpn\generic\diveby3.c \
+     mpn\generic\divis.c \
+     mpn\generic\divrem.c \
+     mpn\generic\divrem_1.c \
+     mpn\generic\divrem_2.c \
+     mpn\generic\dump.c \
+     mpn\generic\fib2_ui.c \
+     mpn\generic\gcd.c \
+     mpn\generic\gcd_1.c \
+     mpn\generic\gcdext.c \
+     mpn\generic\get_d.c \
+     mpn\generic\get_str.c \
+     mpn\generic\jacbase.c \
+     mpn\generic\lshift.c \
+     mpn\generic\mod_1.c \
+     mpn\generic\mod_34lsub1.c \
+     mpn\generic\mode1o.c \
+     mpn\generic\mul.c \
+     mpn\generic\mul_1.c \
+     mpn\generic\mul_basecase.c \
+     mpn\generic\mul_fft.c \
+     mpn\generic\mul_n.c \
+     mpn\generic\mullow_basecase.c \
+     mpn\generic\mullow_n.c \
+     mpn\generic\perfsqr.c \
+     mpn\generic\pow_1.c \
+     mpn\generic\pre_divrem_1.c \
+     mpn\generic\pre_mod_1.c \
+     mpn\generic\random.c \
+     mpn\generic\random2.c \
+     mpn\generic\rootrem.c \
+     mpn\generic\rshift.c \
+     mpn\generic\sb_divrem_mn.c \
+     mpn\generic\scan0.c \
+     mpn\generic\scan1.c \
+     mpn\generic\set_str.c \
+     mpn\generic\sizeinbase.c \
+     mpn\generic\sqr_basecase.c \
+     mpn\generic\sqrtrem.c \
+     mpn\generic\sub.c \
+     mpn\generic\sub_1.c \
+     mpn\generic\sub_n.c \
+     mpn\generic\submul_1.c \
+     mpn\generic\tdiv_qr.c
+
  # for p4
  MPN_P4_C_SOURCES = \
      mpn\generic\add.c \
*************** MPN_GC_SOURCES = \
*** 94,100 ****
      mpn\generic\add_1.c \
      mpn\generic\add_n.c \
      mpn\generic\addmul_1.c \
!     .\mpn\generic\addsub_n.c \
      mpn\generic\bdivmod.c \
      mpn\generic\cmp.c \
      mpn\generic\dc_divrem_n.c \
--- 163,169 ----
      mpn\generic\add_1.c \
      mpn\generic\add_n.c \
      mpn\generic\addmul_1.c \
!     mpn\generic\addsub_n.c \
      mpn\generic\bdivmod.c \
      mpn\generic\cmp.c \
      mpn\generic\dc_divrem_n.c \
*************** MPN_GC_SOURCES = \
*** 102,109 ****
      mpn\generic\diveby3.c \
      mpn\generic\divis.c \
      mpn\generic\divrem.c \
!     .\mpn\generic\divrem_1.c \
!     .\mpn\generic\divrem_2.c \
      mpn\generic\dump.c \
      mpn\generic\fib2_ui.c \
      mpn\generic\gcd.c \
--- 171,178 ----
      mpn\generic\diveby3.c \
      mpn\generic\divis.c \
      mpn\generic\divrem.c \
!     mpn\generic\divrem_1.c \
!     mpn\generic\divrem_2.c \
      mpn\generic\dump.c \
      mpn\generic\fib2_ui.c \
      mpn\generic\gcd.c \
*************** MPN_GC_SOURCES = \
*** 124,130 ****
      mpn\generic\mullow_basecase.c \
      mpn\generic\mullow_n.c \
      mpn\generic\perfsqr.c \
!     .\mpn\generic\popham2.c \
      mpn\generic\pow_1.c \
      mpn\generic\pre_divrem_1.c \
      mpn\generic\pre_mod_1.c \
--- 193,199 ----
      mpn\generic\mullow_basecase.c \
      mpn\generic\mullow_n.c \
      mpn\generic\perfsqr.c \
!     mpn\generic\popham2.c \
      mpn\generic\pow_1.c \
      mpn\generic\pre_divrem_1.c \
      mpn\generic\pre_mod_1.c \
*************** MPZ_SOURCES = \
*** 360,366 ****
      mpz\scan0.c \
      mpz\scan1.c \
      mpz\set.c \
!     .\mpz\set_d.c \
      mpz\set_f.c \
      mpz\set_q.c \
      mpz\set_si.c \
--- 429,435 ----
      mpz\scan0.c \
      mpz\scan1.c \
      mpz\set.c \
!     mpz\set_d.c \
      mpz\set_f.c \
      mpz\set_q.c \
      mpz\set_si.c \
*************** GMP_SOURCES = \
*** 455,460 ****
--- 524,543 ----
      mp_bases.c \
      fib_table.c
 
+ MPN_AMD64_ASM_SOURCES = \
+     mpn\amd64i\fwait.asm \
+     mpn\amd64i\aors_n.asm \
+     mpn\amd64i\aorsmul_1.asm \
+     mpn\amd64i\copyd.asm \
+     mpn\amd64i\copyi.asm \
+     mpn\amd64i\dive_1.asm \
+     mpn\amd64i\lshift.asm \
+     mpn\amd64i\mode1o.asm \
+     mpn\amd64i\mul_1.asm \
+     mpn\amd64i\mul_basecase.asm \
+     mpn\amd64i\rshift.asm \
+     mpn\amd64i\sqr_basecase.asm
+
  MPN_P4_ASM_SOURCES = \
      mpn\x86i\aors_n.asm \
      mpn\x86i\aorsmul_1.asm \
*************** MPN_GC_OBJS = $(MPN_GC_SOURCES:.c=.obj)
*** 514,519 ****
--- 597,603 ----
  #MPN_P0_OBJS = $(MPN_P0_ASM_SOURCES:.asm=.obj) $(MPN_P0_C_SOURCES:.c=.obj)
  MPN_P3_OBJS = $(MPN_P3_ASM_SOURCES:.asm=.obj) $(MPN_P3_C_SOURCES:.c=.obj)
  MPN_P4_OBJS = $(MPN_P4_ASM_SOURCES:.asm=.obj) $(MPN_P4_C_SOURCES:.c=.obj)
+ MPN_AMD64_OBJS = $(MPN_AMD64_ASM_SOURCES:.asm=.obj) $(MPN_AMD64_C_SOURCES:.c=.obj)
  MPF_OBJS = $(MPF_SOURCES:.c=.obj)
  MPQ_OBJS = $(MPQ_SOURCES:.c=.obj)
  MPZ_OBJS = $(MPZ_SOURCES:.c=.obj)
*************** GMP_ALL_OBJS = $(MPF_OBJS) $(MPQ_OBJS) $
*** 526,533 ****
 
  AUTO_FILES = mp_bases.h mp_bases.c fac_ui.h fib_table.h fib_table.c perfsqr.h
 
- MPN_TYPE = p3
-
  all: $(AUTO_FILES) gmp.lib
 
  mpn_gc.lib: msvc-build $(MPN_GC_OBJS)
--- 610,615 ----
*************** mpn_p3.lib: msvc-build $(MPN_P3_OBJS)
*** 542,552 ****
  mpn_p4.lib: msvc-build $(MPN_P4_OBJS)
          link -lib /NOLOGO /OUT:$@ $(MPN_P4_OBJS)
 
  gmp.lib: mpn_$(MPN_TYPE).lib $(GMP_ALL_OBJS)
          link -lib /NOLOGO /OUT:$@ *.obj mpf\*.obj mpz\*.obj mpq\*.obj $(PRINTF_OBJS) $(SCANF_OBJS) mpn_$(MPN_TYPE).lib
 
  #CFLAGS = $(CFLAGS_CONFIG) /nologo /W3 /EHsc /I "." /I $(srcdir) /I "$(srcdir)\mpn\generic" /D "WIN32" /D "_LIB" /D "_WIN32" /D "_MBCS"
! CFLAGS = $(CFLAGS_CONFIG) /nologo /W3 /EHsc /I "." /I $(srcdir) /I "$(srcdir)\mpn\generic" /D "_LIB" /D "_MBCS"
 
  {.\mpn\generic}.c{.\mpn\generic}.obj:
          cl -c $(CFLAGS) /Fo$@ $?
--- 624,637 ----
  mpn_p4.lib: msvc-build $(MPN_P4_OBJS)
          link -lib /NOLOGO /OUT:$@ $(MPN_P4_OBJS)
 
+ mpn_amd64.lib: msvc-build $(MPN_AMD64_OBJS)
+         link -lib /NOLOGO /OUT:$@ $(MPN_AMD64_OBJS)
+
  gmp.lib: mpn_$(MPN_TYPE).lib $(GMP_ALL_OBJS)
          link -lib /NOLOGO /OUT:$@ *.obj mpf\*.obj mpz\*.obj mpq\*.obj $(PRINTF_OBJS) $(SCANF_OBJS) mpn_$(MPN_TYPE).lib
 
  #CFLAGS = $(CFLAGS_CONFIG) /nologo /W3 /EHsc /I "." /I $(srcdir) /I "$(srcdir)\mpn\generic" /D "WIN32" /D "_LIB" /D "_WIN32" /D "_MBCS"
! CFLAGS = $(CFLAGS_CONFIG) /nologo /W3 /EHsc /I "." /I $(srcdir) /I "$(srcdir)\mpn\generic" /D "_LIB" /D "_MBCS" $(D_WIN64)
 
  {.\mpn\generic}.c{.\mpn\generic}.obj:
          cl -c $(CFLAGS) /Fo$@ $?
*************** CFLAGS = $(CFLAGS_CONFIG) /nologo /W3 /E
*** 570,577 ****
          cl -c $(CFLAGS) /Fo$@ $?
 
  .asm.obj:
!         C:\yamo\distroz\yasm-1.2.0-win32.exe -O9 -Xvc -f win32 -i $(@D)\ -o $@ $?
! #       yasm-1.2.0-win32.exe -O9 -Xvc -f win32 -i $(@D)\ -o $@ $?
 
  gen-bases.exe: build.vc8\gen-bases\gen-bases.c
          cl $(CFLAGS) /Fe$@ $?
--- 655,662 ----
          cl -c $(CFLAGS) /Fo$@ $?
 
  .asm.obj:
! #       nasm -O9 -Xvc -f win32 -i $(@D)\ -o $@ $?
!         C:\yamo\distroz\yasm-1.2.0-win32.exe -O9 $(YASM_FLAGS) -Xvc -f $(YASM_TARGET) -i $(@D)\ -o $@ $?
 
  gen-bases.exe: build.vc8\gen-bases\gen-bases.c
          cl $(CFLAGS) /Fe$@ $?
 


I add new MPN_TYPE amd64 and used yasm for building .asm files. Also I add to mpn\amd64i\ new file fwait.asm:
    bits 64
ecl_detect_fpe:
    fwait
    retn


You also must copy file msvc\gmp\build.vc8\popham.c to src\gmp\mpn\generic\popham_amd64.c and fix its headers:
*** C:\src\ecl\msvc\gmp\build.vc8\popham.c      Fri May 25 18:28:05 2012
--- popham_amd64.c      Fri May 25 17:26:48 2012
*************** MA 02110-1301, USA. */
*** 25,31 ****
  #define OPERATION_popcount 1
  #define OPERATION_hamdist  0

! #include "..\mpn\generic\popham.c"

  #undef OPERATION_popcount
  #undef OPERATION_hamdist
--- 25,31 ----
  #define OPERATION_popcount 1
  #define OPERATION_hamdist  0

! #include "popham.c"

  #undef OPERATION_popcount
  #undef OPERATION_hamdist
*************** MA 02110-1301, USA. */
*** 34,37 ****
  #define OPERATION_popcount 0
  #define OPERATION_hamdist  1

! #include "..\mpn\generic\popham.c"
--- 34,37 ----
  #define OPERATION_popcount 0
  #define OPERATION_hamdist  1

! #include "popham.c"


msvc\Makefile patch
*** C:\src\ecl\msvc\Makefile    Mon May 28 18:24:32 2012
--- Makefile    Mon May 28 18:24:55 2012
*************** ECL_WIN64 = 1
*** 26,32 ****
--- 26,36 ----
  #       p0 -> Pentium processor
  #       p3 -> Pentium III processor
  #       p4 -> Pentium IV processor
+ !if "$(ECL_WIN64)" != ""
+ GMP_TYPE      = amd64
+ !else
  GMP_TYPE      = p4
+ !endif
 
  # Set it to non-empty to include Win32 thread support
  # Currently it is NOT SUPPORTED to build ECL without threads. The reason
*************** MKNSI   = makensis.exe
*** 81,90 ****
 
  # ==================== Flags ====================
 
- !if "$(ECL_SSE)" != ""
- CFLAGS_SSE=/arch:SSE2
- !endif
-
  !if "$(ECL_WIN64)" != ""
  GMP_BITS=64
  GC_CPU=AMD64
--- 85,90 ----
*************** GC_CPU=AMD64
*** 91,96 ****
--- 91,99 ----
  ARCHITECTURE=AMD64
  VCREDIST=vcredist_x64.exe
  !else
+ !if "$(ECL_SSE)" != ""
+ CFLAGS_SSE=/arch:SSE2
+ !endif
  GMP_BITS=32
  GC_CPU=i386
  ARCHITECTURE=PENTIUM4
*************** eclmin.lib: eclgmp.lib eclgc.lib lsp/con
*** 334,340 ****
          cd c
          $(MAKE) ECL_VERSION_NUMBER=$(ECL_VERSION_NUMBER) \
                  ECL_THREADS=$(ECL_THREADS) ECL_UNICODE=$(ECL_UNICODE) \
!                 ECL_SSE=$(ECL_SSE) "ECL_CFLAGS=$(CFLAGS) -DGC_BUILD"
          cd ..
  eclgc.lib:
          cd gc
--- 337,343 ----
          cd c
          $(MAKE) ECL_VERSION_NUMBER=$(ECL_VERSION_NUMBER) \
                  ECL_THREADS=$(ECL_THREADS) ECL_UNICODE=$(ECL_UNICODE) \
!                 ECL_SSE=$(ECL_SSE) ECL_WIN64=$(ECL_WIN64) "ECL_CFLAGS=$(CFLAGS) -DGC_BUILD"
          cd ..
  eclgc.lib:
          cd gc

Changes was made to
  • autoselect right GMP_TYPE for x64
  • supress warnings D9002 : ignoring unknown option '/arch:SSE2' on amd64
  • pass ECL_WIN64 to c/Makefile
FFI for win64 don`t work yet :-(

Комментариев нет:

Отправить комментарий