Index: mpn/s390x/z196/gmp-mparam.h
===================================================================
--- /dev/null
+++ mpn/s390x/z196/gmp-mparam.h
@@ -0,0 +1,134 @@
+/*  IBM S/390 64 bit gmp-mparam.h -- Compiler/machine parameter header file.
+
+Copyright (C) 2011 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Library General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+The GNU MP 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 Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library General Public License
+along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#define BITS_PER_MP_LIMB 64
+
+/* Generated by tuneup.c, 2011-09-16, gcc 4.5 */
+
+#define DIVREM_1_NORM_THRESHOLD              0  /* always */
+#define DIVREM_1_UNNORM_THRESHOLD            0  /* always */
+#define MOD_1_1P_METHOD                      2
+#define MOD_1_NORM_THRESHOLD                 0  /* always */
+#define MOD_1_UNNORM_THRESHOLD               0  /* always */
+#define MOD_1N_TO_MOD_1_1_THRESHOLD          9
+#define MOD_1U_TO_MOD_1_1_THRESHOLD         22
+#define MOD_1_1_TO_MOD_1_2_THRESHOLD         0  /* never mpn_mod_1_1p */
+#define MOD_1_2_TO_MOD_1_4_THRESHOLD         0  /* never mpn_mod_1s_2p */
+#define PREINV_MOD_1_TO_MOD_1_THRESHOLD     27
+#define USE_PREINV_DIVREM_1                  1
+#define DIV_QR_2_PI2_THRESHOLD           MP_SIZE_T_MAX  /* never */
+#define DIVEXACT_1_THRESHOLD                 0  /* always */
+#define BMOD_1_TO_MOD_1_THRESHOLD        MP_SIZE_T_MAX  /* never */
+
+#define MUL_TOOM22_THRESHOLD                10
+#define MUL_TOOM33_THRESHOLD                50
+#define MUL_TOOM44_THRESHOLD               118
+#define MUL_TOOM6H_THRESHOLD               125
+#define MUL_TOOM8H_THRESHOLD               236
+
+#define MUL_TOOM32_TO_TOOM43_THRESHOLD      58
+#define MUL_TOOM32_TO_TOOM53_THRESHOLD      76
+#define MUL_TOOM42_TO_TOOM53_THRESHOLD      81
+#define MUL_TOOM42_TO_TOOM63_THRESHOLD      50
+
+#define SQR_BASECASE_THRESHOLD               0  /* always */
+#define SQR_TOOM2_THRESHOLD                 27
+#define SQR_TOOM3_THRESHOLD                 80
+#define SQR_TOOM4_THRESHOLD                123
+#define SQR_TOOM6_THRESHOLD                161
+#define SQR_TOOM8_THRESHOLD                230
+
+#define MULMOD_BNM1_THRESHOLD                7
+#define SQRMOD_BNM1_THRESHOLD                7
+
+#define MUL_FFT_MODF_THRESHOLD             180  /* k = 5 */
+#define MUL_FFT_TABLE3                                      \
+  { {    180, 5}, {      7, 6}, {      4, 5}, {      9, 6}, \
+    {      5, 5}, {     11, 6}, {      9, 7}, {      5, 6}, \
+    {     11, 7}, {      6, 6}, {     13, 7}, {      7, 6}, \
+    {     15, 7}, {      9, 8}, {      5, 7}, {     13, 8}, \
+    {      7, 7}, {     16, 8}, {      9, 7}, {     19, 8}, \
+    {     11, 7}, {     23, 8}, {     13, 9}, {      7, 8}, \
+    {     19, 9}, {     11, 8}, {     23,10}, {      7, 9}, \
+    {     15, 8}, {     31, 9}, {     23,10}, {     15, 9}, \
+    {     35,10}, {     23,11}, {     15,10}, {     31, 9}, \
+    {     63, 8}, {    127, 9}, {     67,10}, {     39, 8}, \
+    {    159, 7}, {    319,10}, {     47, 9}, {     95, 8}, \
+    {    191,11}, {   2048,12}, {   4096,13}, {   8192,14}, \
+    {  16384,15}, {  32768,16}, {  65536,17}, { 131072,18}, \
+    { 262144,19}, { 524288,20}, {1048576,21}, {2097152,22}, \
+    {4194304,23}, {8388608,24} }
+#define MUL_FFT_TABLE3_SIZE 58
+#define MUL_FFT_THRESHOLD                 1728
+
+#define SQR_FFT_MODF_THRESHOLD             152  /* k = 5 */
+#define SQR_FFT_TABLE3                                      \
+  { {    152, 5}, {      5, 4}, {     11, 5}, {      7, 6}, \
+    {      4, 5}, {      9, 6}, {      5, 5}, {     11, 6}, \
+    {     13, 7}, {      7, 6}, {     15, 7}, {      9, 8}, \
+    {      5, 7}, {     13, 8}, {      7, 7}, {     16, 8}, \
+    {      9, 7}, {     19, 8}, {     13, 9}, {      7, 8}, \
+    {     19, 9}, {     11, 8}, {     23,10}, {      7, 9}, \
+    {     15, 8}, {     31, 9}, {     23,10}, {     15, 9}, \
+    {     35,10}, {     23,11}, {     15,10}, {     31, 9}, \
+    {     63, 8}, {    127, 7}, {    255,10}, {     39, 9}, \
+    {     79, 8}, {    159,10}, {     47, 9}, {     95, 8}, \
+    {    191,11}, {   2048,12}, {   4096,13}, {   8192,14}, \
+    {  16384,15}, {  32768,16}, {  65536,17}, { 131072,18}, \
+    { 262144,19}, { 524288,20}, {1048576,21}, {2097152,22}, \
+    {4194304,23}, {8388608,24} }
+#define SQR_FFT_TABLE3_SIZE 54
+#define SQR_FFT_THRESHOLD                 1728
+
+#define MULLO_BASECASE_THRESHOLD             0  /* always */
+#define MULLO_DC_THRESHOLD                  46
+#define MULLO_MUL_N_THRESHOLD             3176
+
+#define DC_DIV_QR_THRESHOLD                 34
+#define DC_DIVAPPR_Q_THRESHOLD             153
+#define DC_BDIV_QR_THRESHOLD                50
+#define DC_BDIV_Q_THRESHOLD                119
+
+#define INV_MULMOD_BNM1_THRESHOLD           18
+#define INV_NEWTON_THRESHOLD               199
+#define INV_APPR_THRESHOLD                 170
+
+#define BINV_NEWTON_THRESHOLD              204
+#define REDC_1_TO_REDC_N_THRESHOLD          53
+
+#define MU_DIV_QR_THRESHOLD                734
+#define MU_DIVAPPR_Q_THRESHOLD             855
+#define MUPI_DIV_QR_THRESHOLD               99
+#define MU_BDIV_QR_THRESHOLD               562
+#define MU_BDIV_Q_THRESHOLD                823
+
+#define MATRIX22_STRASSEN_THRESHOLD         15
+#define HGCD_THRESHOLD                     109
+#define GCD_DC_THRESHOLD                   306
+#define GCDEXT_DC_THRESHOLD                242
+#define JACOBI_BASE_METHOD                   3
+
+#define GET_STR_DC_THRESHOLD                20
+#define GET_STR_PRECOMPUTE_THRESHOLD        32
+#define SET_STR_DC_THRESHOLD               562
+#define SET_STR_PRECOMPUTE_THRESHOLD      1164
+
+/* Tuneup completed successfully, took 71 seconds */
Index: configure.in
===================================================================
--- configure.in.orig
+++ configure.in
@@ -1113,12 +1113,59 @@ case $host in
     path="pyr"
     ;;
 
-
-  # IBM s/370 and similar
-  [s3[6-9]0*-*-*])
+  # IBM S/390 32 bit
+  S390_PATTERN)
     gcc_cflags="$gcc_cflags $fomit_frame_pointer"
     path="s390"
     extra_functions="udiv_w_sdiv"
+
+    case $host_cpu in
+    z196)
+      gcc_cflags_optlist="arch tune"
+      # z10 specific tuning doesn't work well on z196
+      gcc_cflags_tune="-mtune=z196 -mtune=z9-109 -mtune=z990 -mtune=z900"
+      gcc_cflags_arch="-march=z196 -march=z10 -march=z9-109 -march=z990 -march=z900"
+      path="s390/z196 $path"
+      ;;
+    esac
+
+    ;;
+  # IBM S/390 64 bit
+  S390X_PATTERN)
+    abilist="64 32"
+    cclist_64="gcc cc"
+    cclist_32="gcc cc"
+    gcc_64_cflags="$gcc_cflags -O3 $fomit_frame_pointer"
+    gcc_32_cflags="$gcc_cflags -O3 $fomit_frame_pointer -m31"
+    path_64="s390x"
+    path_32="s390"
+    extra_functions_32="udiv_w_sdiv"
+
+    case $host_cpu in
+    z196)
+      gcc_64_cflags_optlist="arch tune"
+      # z10 specific tuning doesn't work well on z196
+      gcc_64_cflags_tune="-mtune=z196 -mtune=z9-109 -mtune=z990 -mtune=z900"
+      gcc_64_cflags_arch="-march=z196 -march=z10 -march=z9-109 -march=z990 -march=z900"
+      path_64="s390x/z196 $path_64"
+
+      gcc_32_cflags_optlist="arch tune"
+      gcc_32_cflags_tune="-mtune=z196 -mtune=z9-109 -mtune=z990 -mtune=z900"
+      gcc_32_cflags_arch="-march=z196 -march=z10 -march=z9-109 -march=z990 -march=z900"
+      path_32="s390/z196 $path_32"
+      ;;
+    z10)
+      gcc_64_cflags_optlist="arch tune"
+      gcc_64_cflags_tune="-mtune=z10 -mtune=z9-109 -mtune=z990 -mtune=z900"
+      gcc_64_cflags_arch="-march=z10 -march=z9-109 -march=z990 -march=z900"
+      path_64="s390x/z10 $path_64"
+
+      gcc_32_cflags_optlist="arch tune"
+      gcc_32_cflags_tune="-mtune=z10 -mtune=z9-109 -mtune=z990 -mtune=z900"
+      gcc_32_cflags_arch="-march=z10 -march=z9-109 -march=z990 -march=z900"
+      path_32="$path_32" # FIXME: Do z10 32 bit tuning.
+      ;;
+    esac
     ;;
 
 
Index: tune/time.c
===================================================================
--- tune/time.c.orig
+++ tune/time.c
@@ -248,10 +248,9 @@ static const int have_cycles = 0;
 
 /* "stck" returns ticks since 1 Jan 1900 00:00 GMT, where each tick is 2^-12
    microseconds.  Same #ifdefs here as in longlong.h.  */
-#if defined (__GNUC__) && ! defined (NO_ASM)                            \
-  && (defined (__i370__) || defined (__s390__) || defined (__mvs__))
+#if defined (__GNUC__) && ! defined (NO_ASM) && defined (__s390__)
 static const int  have_stck = 1;
-static const int  use_stck = 1;  /* always use when available */
+static const int  use_stck = 0;  /* clock_gettime is preferred when available */
 typedef uint64_t  stck_t; /* gcc for s390 is quite new, always has uint64_t */
 #define STCK(timestamp)                 \
   do {                                  \
@@ -708,11 +707,15 @@ getrusage_backwards_p (void)
    CLOCK_VIRTUAL is process time, available in BSD systems (though sometimes
    defined, but returning -1 for an error).  */
 
-#ifdef CLOCK_PROCESS_CPUTIME_ID
-# define CGT_ID        CLOCK_PROCESS_CPUTIME_ID
+#ifdef CLOCK_THREAD_CPUTIME_ID
+# define CGT_ID        CLOCK_THREAD_CPUTIME_ID
 #else
-# ifdef CLOCK_VIRTUAL
-#  define CGT_ID       CLOCK_VIRTUAL
+# ifdef CLOCK_PROCESS_CPUTIME_ID
+#  define CGT_ID        CLOCK_PROCESS_CPUTIME_ID
+# else
+#  ifdef CLOCK_VIRTUAL
+#   define CGT_ID       CLOCK_VIRTUAL
+#  endif
 # endif
 #endif
 #ifdef CGT_ID
@@ -1062,17 +1065,6 @@ speed_time_init (void)
 	    }
 	}
     }
-  else if (have_stck)
-    {
-      strcpy (speed_time_string, "STCK timestamp");
-      /* stck is in units of 2^-12 microseconds, which is very likely higher
-	 resolution than a cpu cycle */
-      if (speed_cycletime == 0.0)
-	speed_cycletime_fail
-	  ("Need to know CPU frequency for effective stck unit");
-      speed_unittime = MAX (speed_cycletime, STCK_PERIOD);
-      DEFAULT (speed_precision, 10000);
-    }
   else if (have_mftb && mftb_works_p ())
     {
       use_mftb = 1;
@@ -1127,6 +1119,17 @@ speed_time_init (void)
       DEFAULT (speed_precision, (cgt_unittime <= 0.1e-6 ? 10000 : 1000));
       strcpy (speed_time_string, "microsecond accurate clock_gettime()");
     }
+  else if (have_stck)
+    {
+      strcpy (speed_time_string, "STCK timestamp");
+      /* stck is in units of 2^-12 microseconds, which is very likely higher
+	 resolution than a cpu cycle */
+      if (speed_cycletime == 0.0)
+	speed_cycletime_fail
+	  ("Need to know CPU frequency for effective stck unit");
+      speed_unittime = MAX (speed_cycletime, STCK_PERIOD);
+      DEFAULT (speed_precision, 10000);
+    }
   else if (have_times && clk_tck() > 1000000)
     {
       /* Cray vector systems have times() which is clock cycle resolution
Index: longlong.h
===================================================================
--- longlong.h.orig
+++ longlong.h
@@ -654,29 +654,67 @@ extern UWtype __MPN(udiv_qrnnd) _PROTO (
 #endif /* hppa */
 
 #if (defined (__i370__) || defined (__s390__) || defined (__mvs__)) && W_TYPE_SIZE == 32
+#if !defined (__zarch__)
 #define smul_ppmm(xh, xl, m0, m1) \
-  do {									\
-    union {DItype __ll;							\
-	   struct {USItype __h, __l;} __i;				\
-	  } __x;							\
-    __asm__ ("lr %N0,%1\n\tmr %0,%2"					\
-	     : "=&r" (__x.__ll)						\
-	     : "r" (m0), "r" (m1));					\
-    (xh) = __x.__i.__h; (xl) = __x.__i.__l;				\
+  do {                                                                  \
+    union {DItype __ll;                                                 \
+           struct {USItype __h, __l;} __i;                              \
+          } __x;                                                        \
+    __asm__ ("lr %N0,%1\n\tmr %0,%2"                                    \
+             : "=&r" (__x.__ll)                                         \
+             : "r" (m0), "r" (m1));                                     \
+    (xh) = __x.__i.__h; (xl) = __x.__i.__l;                             \
+  } while (0)
+#define sdiv_qrnnd(q, r, n1, n0, d) \
+  do {                                                                  \
+    union {DItype __ll;                                                 \
+           struct {USItype __h, __l;} __i;                              \
+          } __x;                                                        \
+    __x.__i.__h = n1; __x.__i.__l = n0;                                 \
+    __asm__ ("dr %0,%2"                                                 \
+             : "=r" (__x.__ll)                                          \
+             : "0" (__x.__ll), "r" (d));                                \
+    (q) = __x.__i.__l; (r) = __x.__i.__h;                               \
+  } while (0)
+#else
+#define smul_ppmm(xh, xl, m0, m1) \
+  do {                                                                  \
+    register SItype r0 __asm__ ("0");                                   \
+    register SItype r1 __asm__ ("1") = m0;                              \
+                                                                        \
+    __asm__ ("mr\t%%r0,%3"                                              \
+             : "=r" (r0), "=r" (r1)                                     \
+             : "r"  (r1),  "r" (m1));                                   \
+    (xh) = r0; (xl) = r1;                                               \
   } while (0)
 #define sdiv_qrnnd(q, r, n1, n0, d) \
+  do {                                                                  \
+    register SItype r0 __asm__ ("0") = n0;                              \
+    register SItype r1 __asm__ ("1") = n1;                              \
+                                                                        \
+    __asm__ ("dr\t%%r0,%3"                                              \
+             : "=r" (r0), "=r" (r1)                                     \
+             : "r" (r0), "r" (r1), "r" (d));                            \
+    (q) = r0; (r) = r1;                                                 \
+  } while (0)
+#endif /* __zarch__ */
+#endif
+
+#if defined (__s390x__) && W_TYPE_SIZE == 64
+#define umul_ppmm(xh, xl, m0, m1) \
   do {									\
-    union {DItype __ll;							\
-	   struct {USItype __h, __l;} __i;				\
+    union {unsigned int __attribute__ ((mode (TI))) __lti;		\
+	   struct {UDItype __h, __l;} __i;				\
 	  } __x;							\
-    __x.__i.__h = n1; __x.__i.__l = n0;					\
-    __asm__ ("dr %0,%2"							\
-	     : "=r" (__x.__ll)						\
-	     : "0" (__x.__ll), "r" (d));				\
-    (q) = __x.__i.__l; (r) = __x.__i.__h;				\
+    __asm__ ("lgr %N[result],%[mul0]\n\t"				\
+             "mlgr %[result],%[mul1]"					\
+	     : [result] "=&r" (__x.__lti)				\
+	     : [mul0] "r" (m0), [mul1] "r" (m1));			\
+    (xh) = __x.__i.__h; (xl) = __x.__i.__l;				\
   } while (0)
 #endif
 
+
 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("addl %5,%k1\n\tadcl %3,%k0"					\
Index: mpn/s390/z196/gmp-mparam.h
===================================================================
--- /dev/null
+++ mpn/s390/z196/gmp-mparam.h
@@ -0,0 +1,130 @@
+/* IBM S/390 32 bit gmp-mparam.h -- Compiler/machine parameter header file.
+
+Copyright 2001-2011 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP 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 3 of the License, or (at your
+option) any later version.
+
+The GNU MP 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 the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
+
+
+/* GMP_LIMB_BITS etc generated by configure */
+
+/* Generated by tuneup.c, 2011-09-16, gcc 4.4 */
+
+#define DIVREM_1_NORM_THRESHOLD              0  /* always */
+#define DIVREM_1_UNNORM_THRESHOLD            3
+#define MOD_1_1P_METHOD                      2
+#define MOD_1_NORM_THRESHOLD                 0  /* always */
+#define MOD_1_UNNORM_THRESHOLD               4
+#define MOD_1N_TO_MOD_1_1_THRESHOLD         11
+#define MOD_1U_TO_MOD_1_1_THRESHOLD          3
+#define MOD_1_1_TO_MOD_1_2_THRESHOLD        14
+#define MOD_1_2_TO_MOD_1_4_THRESHOLD        38
+#define PREINV_MOD_1_TO_MOD_1_THRESHOLD     24
+#define USE_PREINV_DIVREM_1                  1
+#define DIV_QR_2_PI2_THRESHOLD           MP_SIZE_T_MAX  /* never */
+#define DIVEXACT_1_THRESHOLD                 0  /* always */
+#define BMOD_1_TO_MOD_1_THRESHOLD        MP_SIZE_T_MAX  /* never */
+
+#define MUL_TOOM22_THRESHOLD                10
+#define MUL_TOOM33_THRESHOLD                49
+#define MUL_TOOM44_THRESHOLD                82
+#define MUL_TOOM6H_THRESHOLD               125
+#define MUL_TOOM8H_THRESHOLD               195
+
+#define MUL_TOOM32_TO_TOOM43_THRESHOLD      58
+#define MUL_TOOM32_TO_TOOM53_THRESHOLD      61
+#define MUL_TOOM42_TO_TOOM53_THRESHOLD      57
+#define MUL_TOOM42_TO_TOOM63_THRESHOLD      50
+
+#define SQR_BASECASE_THRESHOLD               5
+#define SQR_TOOM2_THRESHOLD                 27
+#define SQR_TOOM3_THRESHOLD                 77
+#define SQR_TOOM4_THRESHOLD                105
+#define SQR_TOOM6_THRESHOLD                152
+#define SQR_TOOM8_THRESHOLD                212
+
+#define MULMOD_BNM1_THRESHOLD               10
+#define SQRMOD_BNM1_THRESHOLD               13
+
+#define MUL_FFT_MODF_THRESHOLD             188  /* k = 5 */
+#define MUL_FFT_TABLE3                                      \
+  { {    188, 5}, {      9, 6}, {      5, 5}, {     11, 6}, \
+    {      6, 5}, {     13, 6}, {      9, 7}, {      5, 6}, \
+    {     13, 7}, {      7, 6}, {     15, 7}, {      9, 6}, \
+    {     19, 7}, {     13, 8}, {      7, 7}, {     19, 8}, \
+    {     11, 7}, {     23, 9}, {      7, 8}, {     15, 7}, \
+    {     31, 8}, {     23, 9}, {     15, 8}, {     43, 9}, \
+    {     23,10}, {     15, 9}, {     31, 8}, {     67, 9}, \
+    {     39, 8}, {     79, 7}, {    159, 9}, {     47, 8}, \
+    {     95,10}, {     31, 9}, {     63, 8}, {    127, 7}, \
+    {    255, 9}, {     71, 8}, {    143, 7}, {    287, 9}, \
+    {     79, 8}, {    159,10}, {     47, 9}, {     95,11}, \
+    {   2048,12}, {   4096,13}, {   8192,14}, {  16384,15}, \
+    {  32768,16} }
+#define MUL_FFT_TABLE3_SIZE 49
+#define MUL_FFT_THRESHOLD                 2496
+
+#define SQR_FFT_MODF_THRESHOLD             152  /* k = 5 */
+#define SQR_FFT_TABLE3                                      \
+  { {    152, 5}, {      5, 4}, {     11, 5}, {     11, 6}, \
+    {      6, 5}, {     13, 6}, {      7, 5}, {     15, 6}, \
+    {      9, 7}, {      5, 6}, {     13, 7}, {      7, 6}, \
+    {     16, 7}, {      9, 6}, {     19, 7}, {     13, 8}, \
+    {      7, 7}, {     19, 8}, {     11, 7}, {     23, 9}, \
+    {      7, 8}, {     15, 7}, {     31, 8}, {     19, 7}, \
+    {     39, 8}, {     23, 9}, {     15, 8}, {     39, 9}, \
+    {     23,10}, {     15, 9}, {     31, 8}, {     63, 7}, \
+    {    127, 9}, {     39, 8}, {     79, 9}, {     47, 8}, \
+    {     95,10}, {     31, 9}, {     63, 8}, {    127, 7}, \
+    {    255, 9}, {     71, 8}, {    143, 9}, {     79, 8}, \
+    {    159,10}, {     47, 9}, {     95,11}, {   2048,12}, \
+    {   4096,13}, {   8192,14}, {  16384,15}, {  32768,16} }
+#define SQR_FFT_TABLE3_SIZE 52
+#define SQR_FFT_THRESHOLD                 1728
+
+#define MULLO_BASECASE_THRESHOLD             0  /* always */
+#define MULLO_DC_THRESHOLD                  33
+#define MULLO_MUL_N_THRESHOLD             4392
+
+#define DC_DIV_QR_THRESHOLD                 17
+#define DC_DIVAPPR_Q_THRESHOLD             155
+#define DC_BDIV_QR_THRESHOLD                26
+#define DC_BDIV_Q_THRESHOLD                 90
+
+#define INV_MULMOD_BNM1_THRESHOLD           23
+#define INV_NEWTON_THRESHOLD               162
+#define INV_APPR_THRESHOLD                 155
+
+#define BINV_NEWTON_THRESHOLD              170
+#define REDC_1_TO_REDC_N_THRESHOLD          45
+
+#define MU_DIV_QR_THRESHOLD                680
+#define MU_DIVAPPR_Q_THRESHOLD             748
+#define MUPI_DIV_QR_THRESHOLD               82
+#define MU_BDIV_QR_THRESHOLD               562
+#define MU_BDIV_Q_THRESHOLD                748
+
+#define MATRIX22_STRASSEN_THRESHOLD         11
+#define HGCD_THRESHOLD                     198
+#define GCD_DC_THRESHOLD                   551
+#define GCDEXT_DC_THRESHOLD                492
+#define JACOBI_BASE_METHOD                   4
+
+#define GET_STR_DC_THRESHOLD                13
+#define GET_STR_PRECOMPUTE_THRESHOLD        27
+#define SET_STR_DC_THRESHOLD              1352
+#define SET_STR_PRECOMPUTE_THRESHOLD      2291
+
+/* Tuneup completed successfully, took 96 seconds */
Index: config.guess
===================================================================
--- config.guess.orig
+++ config.guess
@@ -890,10 +890,24 @@ EOF
   rm -f ${dummy}0.s ${dummy}0.o ${dummy}1.s ${dummy}1.o ${dummy}2.c ${dummy}2.o $dummy
   ;;
 
+s390*-*-*)
+  model=`grep "processor 0: version =" /proc/cpuinfo | sed -e 's/^.*machine = //'`
+  case $model in
+	  2064 | 2066) zcpu="z900" ;;
+	  2084 | 2086) zcpu="z990" ;;
+	  2094 | 2096) zcpu="z9-109" ;;
+	  2097 | 2098) zcpu="z10" ;;
+	  2817 | 2818) zcpu="z196" ;;
+	  *) zcpu="z196" ;; # Default to latest known CPU for everything unknown.
+  esac
+  case "$guess_full" in
+	  s390x-*-*) exact_cpu=$zcpu ;;
+	  s390-*-*)  exact_cpu=${zcpu}esa ;;
+  esac
+  ;;
 esac
 
 
-
 # -------------------------------------------------------------------------
 # Use an exact cpu, if possible
 
Index: config.sub
===================================================================
--- config.sub.orig
+++ config.sub
@@ -110,7 +110,10 @@ ultrasparc | ultrasparc2 | ultrasparc2i 
   test_cpu=sparc ;;
 sh2)
   test_cpu=sh ;;
-
+z900esa | z990esa | z9-109esa | z10esa | z196esa)
+  test_cpu=s390 ;;
+z900 | z990 | z9-109 | z10 | z196)
+  test_cpu=s390x ;;
 *)
   # Don't need or want to change the given name, just run configfsf.sub
   $SHELL $configfsf_sub "$given_full"
Index: acinclude.m4
===================================================================
--- acinclude.m4.orig
+++ acinclude.m4
@@ -43,6 +43,12 @@ define(M68K_PATTERN,
 define(POWERPC64_PATTERN,
 [[powerpc64-*-* | powerpc64le-*-* | powerpc620-*-* | powerpc630-*-* | powerpc970-*-* | power[3-9]-*-*]])
 
+define(S390_PATTERN,
+[[z900esa-*-* | z990esa-*-* | z9-109esa-*-* | z10esa-*-* | z196esa-*-*]])
+
+define(S390X_PATTERN,
+[[z900-*-* | z990-*-* | z9-109-*-* | z10-*-* | z196-*-*]])
+
 define(X86_PATTERN,
 [[i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-* | viac3*-*-* | geode*-*-* | atom-*-*]])
 
Index: mpn/s390/gmp-mparam.h
===================================================================
--- mpn/s390/gmp-mparam.h.orig
+++ mpn/s390/gmp-mparam.h
@@ -1,6 +1,6 @@
-/* IBM s370 gmp-mparam.h -- Compiler/machine parameter header file.
+/* IBM S/390 32 bit gmp-mparam.h -- Compiler/machine parameter header file.
 
-Copyright 2001, 2002 Free Software Foundation, Inc.
+Copyright 2001-2011 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -20,35 +20,111 @@ along with the GNU MP Library.  If not, 
 
 /* GMP_LIMB_BITS etc generated by configure */
 
+/* Generated by tuneup.c, 2011-09-16, gcc 4.4 */
 
-/* Generated by tuneup.c, 2001-12-03, gcc 2.95 */
+#define DIVREM_1_NORM_THRESHOLD              0  /* always */
+#define DIVREM_1_UNNORM_THRESHOLD            3
+#define MOD_1_1P_METHOD                      2
+#define MOD_1_NORM_THRESHOLD                 0  /* always */
+#define MOD_1_UNNORM_THRESHOLD               4
+#define MOD_1N_TO_MOD_1_1_THRESHOLD         11
+#define MOD_1U_TO_MOD_1_1_THRESHOLD          3
+#define MOD_1_1_TO_MOD_1_2_THRESHOLD        14
+#define MOD_1_2_TO_MOD_1_4_THRESHOLD        38
+#define PREINV_MOD_1_TO_MOD_1_THRESHOLD     24
+#define USE_PREINV_DIVREM_1                  1
+#define DIV_QR_2_PI2_THRESHOLD           MP_SIZE_T_MAX  /* never */
+#define DIVEXACT_1_THRESHOLD                 0  /* always */
+#define BMOD_1_TO_MOD_1_THRESHOLD        MP_SIZE_T_MAX  /* never */
+
+#define MUL_TOOM22_THRESHOLD                10
+#define MUL_TOOM33_THRESHOLD                49
+#define MUL_TOOM44_THRESHOLD                82
+#define MUL_TOOM6H_THRESHOLD               125
+#define MUL_TOOM8H_THRESHOLD               195
+
+#define MUL_TOOM32_TO_TOOM43_THRESHOLD      58
+#define MUL_TOOM32_TO_TOOM53_THRESHOLD      61
+#define MUL_TOOM42_TO_TOOM53_THRESHOLD      57
+#define MUL_TOOM42_TO_TOOM63_THRESHOLD      50
+
+#define SQR_BASECASE_THRESHOLD               5
+#define SQR_TOOM2_THRESHOLD                 27
+#define SQR_TOOM3_THRESHOLD                 77
+#define SQR_TOOM4_THRESHOLD                105
+#define SQR_TOOM6_THRESHOLD                152
+#define SQR_TOOM8_THRESHOLD                212
+
+#define MULMOD_BNM1_THRESHOLD               10
+#define SQRMOD_BNM1_THRESHOLD               13
+
+#define MUL_FFT_MODF_THRESHOLD             188  /* k = 5 */
+#define MUL_FFT_TABLE3                                      \
+  { {    188, 5}, {      9, 6}, {      5, 5}, {     11, 6}, \
+    {      6, 5}, {     13, 6}, {      9, 7}, {      5, 6}, \
+    {     13, 7}, {      7, 6}, {     15, 7}, {      9, 6}, \
+    {     19, 7}, {     13, 8}, {      7, 7}, {     19, 8}, \
+    {     11, 7}, {     23, 9}, {      7, 8}, {     15, 7}, \
+    {     31, 8}, {     23, 9}, {     15, 8}, {     43, 9}, \
+    {     23,10}, {     15, 9}, {     31, 8}, {     67, 9}, \
+    {     39, 8}, {     79, 7}, {    159, 9}, {     47, 8}, \
+    {     95,10}, {     31, 9}, {     63, 8}, {    127, 7}, \
+    {    255, 9}, {     71, 8}, {    143, 7}, {    287, 9}, \
+    {     79, 8}, {    159,10}, {     47, 9}, {     95,11}, \
+    {   2048,12}, {   4096,13}, {   8192,14}, {  16384,15}, \
+    {  32768,16} }
+#define MUL_FFT_TABLE3_SIZE 49
+#define MUL_FFT_THRESHOLD                 2496
+
+#define SQR_FFT_MODF_THRESHOLD             152  /* k = 5 */
+#define SQR_FFT_TABLE3                                      \
+  { {    152, 5}, {      5, 4}, {     11, 5}, {     11, 6}, \
+    {      6, 5}, {     13, 6}, {      7, 5}, {     15, 6}, \
+    {      9, 7}, {      5, 6}, {     13, 7}, {      7, 6}, \
+    {     16, 7}, {      9, 6}, {     19, 7}, {     13, 8}, \
+    {      7, 7}, {     19, 8}, {     11, 7}, {     23, 9}, \
+    {      7, 8}, {     15, 7}, {     31, 8}, {     19, 7}, \
+    {     39, 8}, {     23, 9}, {     15, 8}, {     39, 9}, \
+    {     23,10}, {     15, 9}, {     31, 8}, {     63, 7}, \
+    {    127, 9}, {     39, 8}, {     79, 9}, {     47, 8}, \
+    {     95,10}, {     31, 9}, {     63, 8}, {    127, 7}, \
+    {    255, 9}, {     71, 8}, {    143, 9}, {     79, 8}, \
+    {    159,10}, {     47, 9}, {     95,11}, {   2048,12}, \
+    {   4096,13}, {   8192,14}, {  16384,15}, {  32768,16} }
+#define SQR_FFT_TABLE3_SIZE 52
+#define SQR_FFT_THRESHOLD                 1728
+
+#define MULLO_BASECASE_THRESHOLD             0  /* always */
+#define MULLO_DC_THRESHOLD                  33
+#define MULLO_MUL_N_THRESHOLD             4392
+
+#define DC_DIV_QR_THRESHOLD                 17
+#define DC_DIVAPPR_Q_THRESHOLD             155
+#define DC_BDIV_QR_THRESHOLD                26
+#define DC_BDIV_Q_THRESHOLD                 90
+
+#define INV_MULMOD_BNM1_THRESHOLD           23
+#define INV_NEWTON_THRESHOLD               162
+#define INV_APPR_THRESHOLD                 155
+
+#define BINV_NEWTON_THRESHOLD              170
+#define REDC_1_TO_REDC_N_THRESHOLD          45
+
+#define MU_DIV_QR_THRESHOLD                680
+#define MU_DIVAPPR_Q_THRESHOLD             748
+#define MUPI_DIV_QR_THRESHOLD               82
+#define MU_BDIV_QR_THRESHOLD               562
+#define MU_BDIV_Q_THRESHOLD                748
+
+#define MATRIX22_STRASSEN_THRESHOLD         11
+#define HGCD_THRESHOLD                     198
+#define GCD_DC_THRESHOLD                   551
+#define GCDEXT_DC_THRESHOLD                492
+#define JACOBI_BASE_METHOD                   4
+
+#define GET_STR_DC_THRESHOLD                13
+#define GET_STR_PRECOMPUTE_THRESHOLD        27
+#define SET_STR_DC_THRESHOLD              1352
+#define SET_STR_PRECOMPUTE_THRESHOLD      2291
 
-#define MUL_TOOM22_THRESHOLD          18
-#define MUL_TOOM33_THRESHOLD         210
-
-#define SQR_BASECASE_THRESHOLD         8
-#define SQR_TOOM2_THRESHOLD           40
-#define SQR_TOOM3_THRESHOLD          250
-
-#define DIV_SB_PREINV_THRESHOLD            0
-#define DIV_DC_THRESHOLD                  63
-#define POWM_THRESHOLD                63
-
-#define GCD_ACCEL_THRESHOLD            3
-
-#define DIVREM_1_NORM_THRESHOLD        0
-#define DIVREM_1_UNNORM_THRESHOLD      5
-#define MOD_1_NORM_THRESHOLD           0
-#define MOD_1_UNNORM_THRESHOLD         4
-#define USE_PREINV_MOD_1               0
-#define DIVREM_2_THRESHOLD             0
-#define DIVEXACT_1_THRESHOLD           0
-#define MODEXACT_1_ODD_THRESHOLD       0
-
-#define MUL_FFT_TABLE  { 432, 992, 1664, 4608, 14336, 40960, 0 }
-#define MUL_FFT_MODF_THRESHOLD       448
-#define MUL_FFT_THRESHOLD           3840
-
-#define SQR_FFT_TABLE  { 400, 992, 1664, 4608, 10240, 40960, 0 }
-#define SQR_FFT_MODF_THRESHOLD       416
-#define SQR_FFT_THRESHOLD           3328
+/* Tuneup completed successfully, took 96 seconds */
Index: mpn/s390x/gmp-mparam.h
===================================================================
--- /dev/null
+++ mpn/s390x/gmp-mparam.h
@@ -0,0 +1,134 @@
+/*  IBM S/390 64 bit gmp-mparam.h -- Compiler/machine parameter header file.
+
+Copyright (C) 2011 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Library General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at your
+option) any later version.
+
+The GNU MP 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 Library General Public
+License for more details.
+
+You should have received a copy of the GNU Library General Public License
+along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#define BITS_PER_MP_LIMB 64
+
+/* Generated by tuneup.c, 2011-09-16, gcc 4.5 */
+
+#define DIVREM_1_NORM_THRESHOLD              0  /* always */
+#define DIVREM_1_UNNORM_THRESHOLD            0  /* always */
+#define MOD_1_1P_METHOD                      2
+#define MOD_1_NORM_THRESHOLD                 0  /* always */
+#define MOD_1_UNNORM_THRESHOLD               0  /* always */
+#define MOD_1N_TO_MOD_1_1_THRESHOLD          9
+#define MOD_1U_TO_MOD_1_1_THRESHOLD         22
+#define MOD_1_1_TO_MOD_1_2_THRESHOLD         0  /* never mpn_mod_1_1p */
+#define MOD_1_2_TO_MOD_1_4_THRESHOLD         0  /* never mpn_mod_1s_2p */
+#define PREINV_MOD_1_TO_MOD_1_THRESHOLD     27
+#define USE_PREINV_DIVREM_1                  1
+#define DIV_QR_2_PI2_THRESHOLD           MP_SIZE_T_MAX  /* never */
+#define DIVEXACT_1_THRESHOLD                 0  /* always */
+#define BMOD_1_TO_MOD_1_THRESHOLD        MP_SIZE_T_MAX  /* never */
+
+#define MUL_TOOM22_THRESHOLD                10
+#define MUL_TOOM33_THRESHOLD                50
+#define MUL_TOOM44_THRESHOLD               118
+#define MUL_TOOM6H_THRESHOLD               125
+#define MUL_TOOM8H_THRESHOLD               236
+
+#define MUL_TOOM32_TO_TOOM43_THRESHOLD      58
+#define MUL_TOOM32_TO_TOOM53_THRESHOLD      76
+#define MUL_TOOM42_TO_TOOM53_THRESHOLD      81
+#define MUL_TOOM42_TO_TOOM63_THRESHOLD      50
+
+#define SQR_BASECASE_THRESHOLD               0  /* always */
+#define SQR_TOOM2_THRESHOLD                 27
+#define SQR_TOOM3_THRESHOLD                 80
+#define SQR_TOOM4_THRESHOLD                123
+#define SQR_TOOM6_THRESHOLD                161
+#define SQR_TOOM8_THRESHOLD                230
+
+#define MULMOD_BNM1_THRESHOLD                7
+#define SQRMOD_BNM1_THRESHOLD                7
+
+#define MUL_FFT_MODF_THRESHOLD             180  /* k = 5 */
+#define MUL_FFT_TABLE3                                      \
+  { {    180, 5}, {      7, 6}, {      4, 5}, {      9, 6}, \
+    {      5, 5}, {     11, 6}, {      9, 7}, {      5, 6}, \
+    {     11, 7}, {      6, 6}, {     13, 7}, {      7, 6}, \
+    {     15, 7}, {      9, 8}, {      5, 7}, {     13, 8}, \
+    {      7, 7}, {     16, 8}, {      9, 7}, {     19, 8}, \
+    {     11, 7}, {     23, 8}, {     13, 9}, {      7, 8}, \
+    {     19, 9}, {     11, 8}, {     23,10}, {      7, 9}, \
+    {     15, 8}, {     31, 9}, {     23,10}, {     15, 9}, \
+    {     35,10}, {     23,11}, {     15,10}, {     31, 9}, \
+    {     63, 8}, {    127, 9}, {     67,10}, {     39, 8}, \
+    {    159, 7}, {    319,10}, {     47, 9}, {     95, 8}, \
+    {    191,11}, {   2048,12}, {   4096,13}, {   8192,14}, \
+    {  16384,15}, {  32768,16}, {  65536,17}, { 131072,18}, \
+    { 262144,19}, { 524288,20}, {1048576,21}, {2097152,22}, \
+    {4194304,23}, {8388608,24} }
+#define MUL_FFT_TABLE3_SIZE 58
+#define MUL_FFT_THRESHOLD                 1728
+
+#define SQR_FFT_MODF_THRESHOLD             152  /* k = 5 */
+#define SQR_FFT_TABLE3                                      \
+  { {    152, 5}, {      5, 4}, {     11, 5}, {      7, 6}, \
+    {      4, 5}, {      9, 6}, {      5, 5}, {     11, 6}, \
+    {     13, 7}, {      7, 6}, {     15, 7}, {      9, 8}, \
+    {      5, 7}, {     13, 8}, {      7, 7}, {     16, 8}, \
+    {      9, 7}, {     19, 8}, {     13, 9}, {      7, 8}, \
+    {     19, 9}, {     11, 8}, {     23,10}, {      7, 9}, \
+    {     15, 8}, {     31, 9}, {     23,10}, {     15, 9}, \
+    {     35,10}, {     23,11}, {     15,10}, {     31, 9}, \
+    {     63, 8}, {    127, 7}, {    255,10}, {     39, 9}, \
+    {     79, 8}, {    159,10}, {     47, 9}, {     95, 8}, \
+    {    191,11}, {   2048,12}, {   4096,13}, {   8192,14}, \
+    {  16384,15}, {  32768,16}, {  65536,17}, { 131072,18}, \
+    { 262144,19}, { 524288,20}, {1048576,21}, {2097152,22}, \
+    {4194304,23}, {8388608,24} }
+#define SQR_FFT_TABLE3_SIZE 54
+#define SQR_FFT_THRESHOLD                 1728
+
+#define MULLO_BASECASE_THRESHOLD             0  /* always */
+#define MULLO_DC_THRESHOLD                  46
+#define MULLO_MUL_N_THRESHOLD             3176
+
+#define DC_DIV_QR_THRESHOLD                 34
+#define DC_DIVAPPR_Q_THRESHOLD             153
+#define DC_BDIV_QR_THRESHOLD                50
+#define DC_BDIV_Q_THRESHOLD                119
+
+#define INV_MULMOD_BNM1_THRESHOLD           18
+#define INV_NEWTON_THRESHOLD               199
+#define INV_APPR_THRESHOLD                 170
+
+#define BINV_NEWTON_THRESHOLD              204
+#define REDC_1_TO_REDC_N_THRESHOLD          53
+
+#define MU_DIV_QR_THRESHOLD                734
+#define MU_DIVAPPR_Q_THRESHOLD             855
+#define MUPI_DIV_QR_THRESHOLD               99
+#define MU_BDIV_QR_THRESHOLD               562
+#define MU_BDIV_Q_THRESHOLD                823
+
+#define MATRIX22_STRASSEN_THRESHOLD         15
+#define HGCD_THRESHOLD                     109
+#define GCD_DC_THRESHOLD                   306
+#define GCDEXT_DC_THRESHOLD                242
+#define JACOBI_BASE_METHOD                   3
+
+#define GET_STR_DC_THRESHOLD                20
+#define GET_STR_PRECOMPUTE_THRESHOLD        32
+#define SET_STR_DC_THRESHOLD               562
+#define SET_STR_PRECOMPUTE_THRESHOLD      1164
+
+/* Tuneup completed successfully, took 71 seconds */
