Index: Makefile.in
===================================================================
--- Makefile.in	(revision c5cb613099f2fdd80518c1423be411f72bd629c4)
+++ Makefile.in	(revision e4745d7a69e805e1610459cace93880b062586f3)
@@ -35,10 +35,12 @@
 PRE_UNINSTALL = :
 POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
 subdir = .
 DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
 	$(srcdir)/Makefile.in $(srcdir)/config.h.in \
 	$(top_srcdir)/configure INSTALL automake/compile \
-	automake/depcomp automake/install-sh automake/missing \
-	automake/ylwrap
+	automake/config.guess automake/config.sub automake/depcomp \
+	automake/install-sh automake/missing automake/ylwrap
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/configure.ac
@@ -161,4 +163,5 @@
 LIBS = @LIBS@
 LTLIBOBJS = @LTLIBOBJS@
+MACHINE_TYPE = @MACHINE_TYPE@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
@@ -192,5 +195,9 @@
 am__untar = @am__untar@
 bindir = @bindir@
+build = @build@
 build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
 builddir = @builddir@
 datadir = @datadir@
@@ -199,5 +206,9 @@
 dvidir = @dvidir@
 exec_prefix = @exec_prefix@
+host = @host@
 host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
 htmldir = @htmldir@
 includedir = @includedir@
Index: automake/config.guess
===================================================================
--- automake/config.guess	(revision e4745d7a69e805e1610459cace93880b062586f3)
+++ automake/config.guess	(revision e4745d7a69e805e1610459cace93880b062586f3)
@@ -0,0 +1,1 @@
+/usr/share/automake-1.11/config.guess
Index: automake/config.sub
===================================================================
--- automake/config.sub	(revision e4745d7a69e805e1610459cace93880b062586f3)
+++ automake/config.sub	(revision e4745d7a69e805e1610459cace93880b062586f3)
@@ -0,0 +1,1 @@
+/usr/share/automake-1.11/config.sub
Index: configure
===================================================================
--- configure	(revision c5cb613099f2fdd80518c1423be411f72bd629c4)
+++ configure	(revision e4745d7a69e805e1610459cace93880b062586f3)
@@ -644,4 +644,13 @@
 CXXFLAGS
 CXX
+MACHINE_TYPE
+host_os
+host_vendor
+host_cpu
+host
+build_os
+build_vendor
+build_cpu
+build
 CFA_FLAGS
 CFA_LIBDIR
@@ -1346,4 +1355,8 @@
   --program-suffix=SUFFIX            append SUFFIX to installed program names
   --program-transform-name=PROGRAM   run sed PROGRAM on installed program names
+
+System types:
+  --build=BUILD     configure for building on BUILD [guessed]
+  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
 _ACEOF
 fi
@@ -3146,4 +3159,78 @@
 
 CFA_FLAGS=${CFAFLAGS}
+
+
+# Make sure we can run config.sub.
+$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 ||
+  as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5
+$as_echo_n "checking build system type... " >&6; }
+if ${ac_cv_build+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_build_alias=$build_alias
+test "x$ac_build_alias" = x &&
+  ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"`
+test "x$ac_build_alias" = x &&
+  as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5
+ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` ||
+  as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5
+$as_echo "$ac_cv_build" >&6; }
+case $ac_cv_build in
+*-*-*) ;;
+*) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;;
+esac
+build=$ac_cv_build
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_build
+shift
+build_cpu=$1
+build_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+build_os=$*
+IFS=$ac_save_IFS
+case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5
+$as_echo_n "checking host system type... " >&6; }
+if ${ac_cv_host+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test "x$host_alias" = x; then
+  ac_cv_host=$ac_cv_build
+else
+  ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` ||
+    as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5
+$as_echo "$ac_cv_host" >&6; }
+case $ac_cv_host in
+*-*-*) ;;
+*) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;;
+esac
+host=$ac_cv_host
+ac_save_IFS=$IFS; IFS='-'
+set x $ac_cv_host
+shift
+host_cpu=$1
+host_vendor=$2
+shift; shift
+# Remember, the first character of IFS is used to create $*,
+# except with old shells:
+host_os=$*
+IFS=$ac_save_IFS
+case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac
+
+
+MACHINE_TYPE=$host_cpu
 
 
Index: configure.ac
===================================================================
--- configure.ac	(revision c5cb613099f2fdd80518c1423be411f72bd629c4)
+++ configure.ac	(revision e4745d7a69e805e1610459cace93880b062586f3)
@@ -88,4 +88,7 @@
 AC_SUBST(CFA_FLAGS, ${CFAFLAGS})
 
+AC_CANONICAL_HOST
+AC_SUBST([MACHINE_TYPE],[$host_cpu])
+
 # Checks for programs.
 AC_PROG_CXX
Index: src/Makefile.in
===================================================================
--- src/Makefile.in	(revision c5cb613099f2fdd80518c1423be411f72bd629c4)
+++ src/Makefile.in	(revision e4745d7a69e805e1610459cace93880b062586f3)
@@ -69,4 +69,6 @@
 PRE_UNINSTALL = :
 POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
 DIST_COMMON = $(srcdir)/CodeGen/module.mk $(srcdir)/Common/module.mk \
 	$(srcdir)/ControlStruct/module.mk $(srcdir)/GenPoly/module.mk \
@@ -296,4 +298,5 @@
 LIBS = @LIBS@
 LTLIBOBJS = @LTLIBOBJS@
+MACHINE_TYPE = @MACHINE_TYPE@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
@@ -327,5 +330,9 @@
 am__untar = @am__untar@
 bindir = @bindir@
+build = @build@
 build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
 builddir = @builddir@
 datadir = @datadir@
@@ -334,5 +341,9 @@
 dvidir = @dvidir@
 exec_prefix = @exec_prefix@
+host = @host@
 host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
 htmldir = @htmldir@
 includedir = @includedir@
Index: src/driver/Makefile.in
===================================================================
--- src/driver/Makefile.in	(revision c5cb613099f2fdd80518c1423be411f72bd629c4)
+++ src/driver/Makefile.in	(revision e4745d7a69e805e1610459cace93880b062586f3)
@@ -36,4 +36,6 @@
 PRE_UNINSTALL = :
 POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
 bin_PROGRAMS = cfa$(EXEEXT)
 cc1lib_PROGRAMS = cc1$(EXEEXT)
@@ -129,4 +131,5 @@
 LIBS = @LIBS@
 LTLIBOBJS = @LTLIBOBJS@
+MACHINE_TYPE = @MACHINE_TYPE@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
@@ -160,5 +163,9 @@
 am__untar = @am__untar@
 bindir = @bindir@
+build = @build@
 build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
 builddir = @builddir@
 datadir = @datadir@
@@ -167,5 +174,9 @@
 dvidir = @dvidir@
 exec_prefix = @exec_prefix@
+host = @host@
 host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
 htmldir = @htmldir@
 includedir = @includedir@
Index: src/examples/Makefile.in
===================================================================
--- src/examples/Makefile.in	(revision c5cb613099f2fdd80518c1423be411f72bd629c4)
+++ src/examples/Makefile.in	(revision e4745d7a69e805e1610459cace93880b062586f3)
@@ -36,4 +36,6 @@
 PRE_UNINSTALL = :
 POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
 noinst_PROGRAMS = fstream_test$(EXEEXT) vector_test$(EXEEXT) \
 	avl_test$(EXEEXT)
@@ -140,4 +142,5 @@
 LIBS = @LIBS@
 LTLIBOBJS = @LTLIBOBJS@
+MACHINE_TYPE = @MACHINE_TYPE@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
@@ -171,5 +174,9 @@
 am__untar = @am__untar@
 bindir = @bindir@
+build = @build@
 build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
 builddir = @builddir@
 datadir = @datadir@
@@ -178,5 +185,9 @@
 dvidir = @dvidir@
 exec_prefix = @exec_prefix@
+host = @host@
 host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
 htmldir = @htmldir@
 includedir = @includedir@
Index: src/libcfa/Makefile.am
===================================================================
--- src/libcfa/Makefile.am	(revision c5cb613099f2fdd80518c1423be411f72bd629c4)
+++ src/libcfa/Makefile.am	(revision e4745d7a69e805e1610459cace93880b062586f3)
@@ -61,4 +61,5 @@
 	# TEMPORARY: does not build with -O2
 
+AM_CCASFLAGS = @CFA_FLAGS@
 CFLAGS = ${EXTRA_FLAGS}	-quiet -no-include-stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver
 CC = ${abs_top_srcdir}/src/driver/cfa
@@ -77,5 +78,5 @@
 ${libobjs} : ${abs_top_srcdir}/src/driver/cfa-cpp ${cfalib_DATA} # add dependency to cfa-cpp so all libraries are rebuilt with new translator
 
-libcfa_a_SOURCES = libcfa-prelude.c ${headers:=.c} concurrency/CtxSwitch-x86_64.S concurrency/invoke.c
+libcfa_a_SOURCES = libcfa-prelude.c ${headers:=.c} concurrency/CtxSwitch-@MACHINE_TYPE@.S concurrency/invoke.c
 
 stdhdr = ${shell echo stdhdr/*}
Index: src/libcfa/Makefile.in
===================================================================
--- src/libcfa/Makefile.in	(revision c5cb613099f2fdd80518c1423be411f72bd629c4)
+++ src/libcfa/Makefile.in	(revision e4745d7a69e805e1610459cace93880b062586f3)
@@ -38,4 +38,6 @@
 PRE_UNINSTALL = :
 POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
 subdir = src/libcfa
 DIST_COMMON = $(nobase_include_HEADERS) $(srcdir)/Makefile.am \
@@ -95,5 +97,5 @@
 	containers/vector.$(OBJEXT) concurrency/threads.$(OBJEXT)
 am_libcfa_a_OBJECTS = libcfa-prelude.$(OBJEXT) $(am__objects_1) \
-	concurrency/CtxSwitch-x86_64.$(OBJEXT) \
+	concurrency/CtxSwitch-@MACHINE_TYPE@.$(OBJEXT) \
 	concurrency/invoke.$(OBJEXT)
 libcfa_a_OBJECTS = $(am_libcfa_a_OBJECTS)
@@ -174,4 +176,5 @@
 LIBS = @LIBS@
 LTLIBOBJS = @LTLIBOBJS@
+MACHINE_TYPE = @MACHINE_TYPE@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
@@ -205,5 +208,9 @@
 am__untar = @am__untar@
 bindir = @bindir@
+build = @build@
 build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
 builddir = @builddir@
 datadir = @datadir@
@@ -212,5 +219,9 @@
 dvidir = @dvidir@
 exec_prefix = @exec_prefix@
+host = @host@
 host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
 htmldir = @htmldir@
 includedir = @includedir@
@@ -253,8 +264,9 @@
 	# TEMPORARY: does not build with -O2
 
+AM_CCASFLAGS = @CFA_FLAGS@
 headers = limits stdlib math iostream fstream iterator rational assert containers/vector concurrency/threads
 runtimehdrs = concurrency
 libobjs = ${headers:=.o}
-libcfa_a_SOURCES = libcfa-prelude.c ${headers:=.c} concurrency/CtxSwitch-x86_64.S concurrency/invoke.c
+libcfa_a_SOURCES = libcfa-prelude.c ${headers:=.c} concurrency/CtxSwitch-@MACHINE_TYPE@.S concurrency/invoke.c
 stdhdr = ${shell echo stdhdr/*}
 nobase_include_HEADERS = ${headers} ${stdhdr}
@@ -340,5 +352,6 @@
 concurrency/threads.$(OBJEXT): concurrency/$(am__dirstamp) \
 	concurrency/$(DEPDIR)/$(am__dirstamp)
-concurrency/CtxSwitch-x86_64.$(OBJEXT): concurrency/$(am__dirstamp) \
+concurrency/CtxSwitch-@MACHINE_TYPE@.$(OBJEXT):  \
+	concurrency/$(am__dirstamp) \
 	concurrency/$(DEPDIR)/$(am__dirstamp)
 concurrency/invoke.$(OBJEXT): concurrency/$(am__dirstamp) \
@@ -351,5 +364,5 @@
 mostlyclean-compile:
 	-rm -f *.$(OBJEXT)
-	-rm -f concurrency/CtxSwitch-x86_64.$(OBJEXT)
+	-rm -f concurrency/CtxSwitch-@MACHINE_TYPE@.$(OBJEXT)
 	-rm -f concurrency/invoke.$(OBJEXT)
 	-rm -f concurrency/threads.$(OBJEXT)
@@ -368,5 +381,5 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rational.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stdlib.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/CtxSwitch-x86_64.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/CtxSwitch-@MACHINE_TYPE@.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/invoke.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@concurrency/$(DEPDIR)/threads.Po@am__quote@
Index: src/libcfa/concurrency/CtxSwitch-i386.S
===================================================================
--- src/libcfa/concurrency/CtxSwitch-i386.S	(revision e4745d7a69e805e1610459cace93880b062586f3)
+++ src/libcfa/concurrency/CtxSwitch-i386.S	(revision e4745d7a69e805e1610459cace93880b062586f3)
@@ -0,0 +1,90 @@
+//                               -*- Mode: Asm -*-
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// CtxSwitch-i386.S --
+//
+// Author           : Thierry Delisle
+// Created On       : Tue Dec 6 12:27:26 2016
+// Last Modified By : Thierry Delisle
+// Last Modified On : Tue Dec 6 12:27:26 2016
+// Update Count     : 0
+//
+// This  library is free  software; you  can redistribute  it and/or  modify it
+// under the terms of the GNU Lesser General Public License as published by the
+// Free Software  Foundation; either  version 2.1 of  the License, or  (at your
+// option) any later version.
+//
+// This library is distributed in the  hope that it will be useful, but WITHOUT
+// ANY  WARRANTY;  without even  the  implied  warranty  of MERCHANTABILITY  or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+// for more details.
+//
+// You should  have received a  copy of the  GNU Lesser General  Public License
+// along  with this library.
+//
+
+// This context switch routine depends on the fact that the stack of a new
+// thread has been set up to look like the thread has saved its context in
+// the normal manner.
+//
+// void CtxSwitch( machine_context *from, machine_context *to );
+
+// Offsets in the context structure. This needs to be synchronized with the
+// high level code a little better.
+
+#define PTR_BYTE	4
+#define SP_OFFSET	( 0 * PTR_BYTE )
+#define FP_OFFSET	( 1 * PTR_BYTE )
+#define PC_OFFSET	( 2 * PTR_BYTE )
+
+.text
+	.align 2
+.globl	CtxSwitch
+CtxSwitch:
+
+	// Copy the "from" context argument from the stack to register eax
+	// Return address is at 0(%esp), with parameters following
+
+	movl 4(%esp),%eax
+
+	// Save volatile registers on the stack.
+
+	pushl %ebx
+	pushl %edi
+	pushl %esi
+
+	// Save old context in the "from" area.
+
+	movl %esp,SP_OFFSET(%eax)
+	movl %ebp,FP_OFFSET(%eax)
+//	movl 4(%ebp),%ebx	// save previous eip for debugger
+//	movl %ebx,PC_OFFSET(%eax)
+
+	// Copy the "to" context argument from the stack to register eax
+	// Having pushed three words (= 12 bytes) on the stack, the
+	// argument is now at 8 + 12 = 20(%esp)
+
+	movl 20(%esp),%eax
+
+	// Load new context from the "to" area.
+
+	movl SP_OFFSET(%eax),%esp
+	movl FP_OFFSET(%eax),%ebp
+
+	// Load volatile registers from the stack.
+
+	popl %esi
+	popl %edi
+	popl %ebx
+
+	// Return to thread.
+
+	ret
+
+// Local Variables: //
+// compile-command: "make install" //
+// End: //
Index: src/libcfa/concurrency/invoke.c
===================================================================
--- src/libcfa/concurrency/invoke.c	(revision c5cb613099f2fdd80518c1423be411f72bd629c4)
+++ src/libcfa/concurrency/invoke.c	(revision e4745d7a69e805e1610459cace93880b062586f3)
@@ -28,13 +28,13 @@
 
 void __startCoroutine__A0_1_0___this_coroutine__PFP10scoroutine_Pd0___co_main__PF_Pd0___vtable__PFP9scoVtable_Pd0__F_Pd0PF_P9scoVtablePv___1(
-      struct coroutine *(*this_coroutine)(void * ), 
-      void (*co_main)(void *), 
-      struct coVtable *(*get_vtable)(void *), 
-      void *vthis, 
+      struct coroutine *(*this_coroutine)(void * ),
+      void (*co_main)(void *),
+      struct coVtable *(*get_vtable)(void *),
+      void *vthis,
       void (*invoke)(struct coVtable *, void *)
 ) {
 
-      #if ! defined( __x86_64__ )
-            #error Only __x86_64__ is supported for threads in cfa
+      #if ! defined( __x86_64__ ) && ! defined( __i386__ )
+            #error Only __x86_64__ and __i386__ is supported for threads in cfa
       #endif
 
Index: src/tests/Makefile.in
===================================================================
--- src/tests/Makefile.in	(revision c5cb613099f2fdd80518c1423be411f72bd629c4)
+++ src/tests/Makefile.in	(revision e4745d7a69e805e1610459cace93880b062586f3)
@@ -35,4 +35,6 @@
 PRE_UNINSTALL = :
 POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
 EXTRA_PROGRAMS = fstream_test$(EXEEXT) vector_test$(EXEEXT) \
 	avl_test$(EXEEXT) constant0-1DP$(EXEEXT) \
@@ -150,4 +152,5 @@
 LIBS = @LIBS@
 LTLIBOBJS = @LTLIBOBJS@
+MACHINE_TYPE = @MACHINE_TYPE@
 MAINT = @MAINT@
 MAKEINFO = @MAKEINFO@
@@ -181,5 +184,9 @@
 am__untar = @am__untar@
 bindir = @bindir@
+build = @build@
 build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
 builddir = @builddir@
 datadir = @datadir@
@@ -188,5 +195,9 @@
 dvidir = @dvidir@
 exec_prefix = @exec_prefix@
+host = @host@
 host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
 htmldir = @htmldir@
 includedir = @includedir@
