[MLton] Opteron build patch

Ray Racine rracine@adelphia.net
Sun, 09 Jan 2005 00:41:42 -0500


--=-ubfv5l7VyO5oBBd9RPHx
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Small patch for building MLton, still as a 32 bit app, on a 64 bit
Opteron.  Works for me on my FC3-64 OS system.

Basically small adjustment to the build stuff to put -m32 -mtune=opteron
in all the right places.

Small change to main.fun to create an asOpts to pass options to the
assembler phase.

Fedora Core 3 does not have a 32 bit libgmp.a but does have
a /usr/lib/libgmp.so.3 which gcc refuses to find.  You need to soft link
a /usr/lib/libgmp.so and everthing links fine. Same in /usr/lib/sse2 .



--=-ubfv5l7VyO5oBBd9RPHx
Content-Disposition: attachment; filename=opteron.patch
Content-Type: text/x-patch; name=opteron.patch; charset=UTF-8
Content-Transfer-Encoding: 7bit

? opteron.patch
Index: Makefile
===================================================================
RCS file: /cvsroot/mlton/mlton/Makefile,v
retrieving revision 1.139
diff -u -r1.139 Makefile
--- Makefile	22 Dec 2004 05:08:10 -0000	1.139
+++ Makefile	9 Jan 2005 05:14:08 -0000
@@ -289,8 +289,8 @@
 # The TBIN and TLIB are where the files are going to be after installing.
 # The DESTDIR and is added onto them to indicate where the Makefile actually
 # puts them.
-DESTDIR = $(CURDIR)/install
-PREFIX = /usr
+DESTDIR = 
+PREFIX = /usr/local
 ifeq ($(TARGET_OS), solaris)
 PREFIX = /usr/local
 endif
Index: bin/mlton-script
===================================================================
RCS file: /cvsroot/mlton/mlton/bin/mlton-script,v
retrieving revision 1.5
diff -u -r1.5 mlton-script
--- bin/mlton-script	23 Dec 2004 22:08:48 -0000	1.5
+++ bin/mlton-script	9 Jan 2005 05:14:09 -0000
@@ -69,16 +69,23 @@
 		-malign-functions=5
 		-malign-jumps=2
 		-malign-loops=2
-		-mcpu=pentiumpro'				\
+		-mcpu=pentiumpro'  				\
+	-target-cc-opt amd64					\
+		'-m32
+		-mtune=opteron'  				\
+	-target-as-opt amd64					\
+		'-m32
+		-mtune=opteron'  				\
 	-target-link-opt cygwin '-lgmp'				\
  	-target-link-opt darwin '-lgmp'				\
 	-target-link-opt freebsd '-L/usr/local/lib/ -lgmp'	\
-	-target-link-opt linux '-lgmp'				\
+	-target-link-opt linux '-lgmp'          		\
 	-target-link-opt mingw 					\
 		'-lgmp -lws2_32 -lkernel32 -lpsapi -lnetapi32'	\
 	-target-link-opt netbsd					\
 		'-Wl,-R/usr/pkg/lib -L/usr/local/lib/ -lgmp'	\
 	-target-link-opt openbsd '-L/usr/local/lib/ -lgmp'	\
 	-target-link-opt solaris '-lgmp -lnsl -lsocket'		\
-	-link-opt '-lgdtoa -lm'					\
+	-target-link-opt amd64 '-m32'           	        \
+	-link-opt '-lgdtoa -lm'  				\
 	"$@"
Index: bin/platform
===================================================================
RCS file: /cvsroot/mlton/mlton/bin/platform,v
retrieving revision 1.6
diff -u -r1.6 platform
--- bin/platform	22 Dec 2004 05:11:24 -0000	1.6
+++ bin/platform	9 Jan 2005 05:14:09 -0000
@@ -99,6 +99,9 @@
 i?86)
 	HOST_ARCH=x86
 ;;
+i?86_64)
+	HOST_ARCH=amd64
+;;
 *)
 	die "Unknown arch $arch."
 ;;
Index: bytecode/Makefile
===================================================================
RCS file: /cvsroot/mlton/mlton/bytecode/Makefile,v
retrieving revision 1.12
diff -u -r1.12 Makefile
--- bytecode/Makefile	22 Dec 2004 05:11:24 -0000	1.12
+++ bytecode/Makefile	9 Jan 2005 05:14:09 -0000
@@ -1,7 +1,13 @@
+TARGET_ARCH = $(shell ../bin/host-arch)
+
 all: interpret.o interpret-gdb.o print-opcodes
 
 CC = gcc -std=c99
 CFLAGS = -fomit-frame-pointer -I../runtime -I../include -Wall
+
+ifeq ($(TARGET_ARCH), amd64)
+CFLAGS += -mtune=opteron -m32 
+endif 
 
 interpret.o: interpret.c interpret.h opcode.h
 	$(CC) $(CFLAGS) -c -O2 interpret.c
Index: mlton/main/main.fun
===================================================================
RCS file: /cvsroot/mlton/mlton/mlton/main/main.fun,v
retrieving revision 1.85
diff -u -r1.85 main.fun
--- mlton/main/main.fun	23 Dec 2004 22:08:48 -0000	1.85
+++ mlton/main/main.fun	9 Jan 2005 05:14:13 -0000
@@ -49,6 +49,7 @@
 
 val buildConstants: bool ref = ref false
 val ccOpts: {opt: string, pred: OptPred.t} list ref = ref []
+val asOpts: {opt: string, pred: OptPred.t} list ref = ref []
 val coalesce: int option ref = ref NONE
 val expert: bool ref = ref false
 val gcc: string ref = ref "<unset>"
@@ -97,6 +98,7 @@
 	    ; (case arch of
 		  Sparc => (align := Align8; codegen := CCodegen)
 		| X86 => codegen := Native
+ 		| AMD64 => codegen := Native 
 		| _ => codegen := CCodegen)
 	 end
 
@@ -115,6 +117,7 @@
    in
       case !Control.targetArch of
          X86 => true
+	| AMD64 => true	
        | _ => false
    end
 
@@ -470,6 +473,10 @@
 	(SpaceString2
 	 (fn (target, opt) =>
 	  List.push (ccOpts, {opt = opt, pred = OptPred.Target target})))),
+       (Expert, "target-as-opt", " <target> <opt>", "target-dependent assembler option",
+	(SpaceString2
+	 (fn (target, opt) =>
+	  List.push (asOpts, {opt = opt, pred = OptPred.Target target})))),
        (Normal, "target-link-opt", " <os> <opt>",
 	"target-dependent link option",
 	(SpaceString2
@@ -590,6 +597,7 @@
 	      then opt :: ac
 	   else ac))
       val ccOpts = addTargetOpts ccOpts
+      val asOpts = addTargetOpts asOpts
       val linkOpts =
 	 List.concat [[concat ["-L", !libTargetDir],
 		       if !debug then "-lmlton-gdb" else "-lmlton"],
@@ -818,7 +826,7 @@
 					    then
 					       (gccDebug @ ["-DASSERT=1"],
 						ccOpts)
-					 else ([asDebug], [])
+					 else ([asDebug], asOpts)
 				      val switches =
 					 if !debug
 					    then debugSwitches @ switches
Index: runtime/Makefile
===================================================================
RCS file: /cvsroot/mlton/mlton/runtime/Makefile,v
retrieving revision 1.95
diff -u -r1.95 Makefile
--- runtime/Makefile	22 Dec 2004 05:11:26 -0000	1.95
+++ runtime/Makefile	9 Jan 2005 05:14:13 -0000
@@ -28,6 +28,14 @@
 ifeq ($(TARGET_OS), solaris)
 FLAGS += -Wa,-xarch=v8plusa -fcall-used-g5 -fcall-used-g7 -funroll-all-loops -mcpu=ultrasparc
 endif
+ifeq ($(TARGET_ARCH), amd64)
+FLAGS += -mtune=opteron -m32
+ifeq ($(GCC_VERSION), 3)
+FLAGS += -falign-loops=2 -falign-jumps=2 -falign-functions=5
+else
+FLAGS += -malign-loops=2 -malign-jumps=2 -malign-functions=5
+endif
+endif
 
 ifeq ($(TARGET), self)
 AR = ar rc

--=-ubfv5l7VyO5oBBd9RPHx--