[PATCH 2/3] Add MIPS r6 support

YunQiang Su syq at debian.org
Thu May 23 04:03:11 UTC 2019


From: Luyou Peng <lpeng at wavecomp.com>

MIPS r6 changes the multiply instructions
The previous version use non-GPR for reuslt, while r6 use GPR.

The instructions are also replaced by new one:
  multu -> mulu/muhu
  dmultu -> dmulu/dmuhu

We rewrite the code for MIPS r6, to make it in a single loop.
Then the length of code is quite shorter now.
With some test, the performance is almost same with the privious.
---
 configure.ac                   | 15 +++++++
 mpn/mips32/r6/add_n.asm        | 65 +++++++++++++++++++++++++++
 mpn/mips32/r6/addmul_1.asm     | 70 +++++++++++++++++++++++++++++
 mpn/mips32/r6/gmp-mparam.h     | 72 ++++++++++++++++++++++++++++++
 mpn/mips32/r6/lshift.asm       | 99 ++++++++++++++++++++++++++++++++++++++++++
 mpn/mips32/r6/mul_1.asm        | 64 +++++++++++++++++++++++++++
 mpn/mips32/r6/rshift.asm       | 96 ++++++++++++++++++++++++++++++++++++++++
 mpn/mips32/r6/sqr_diagonal.asm | 59 +++++++++++++++++++++++++
 mpn/mips32/r6/sub_n.asm        | 64 +++++++++++++++++++++++++++
 mpn/mips32/r6/submul_1.asm     | 69 +++++++++++++++++++++++++++++
 mpn/mips32/r6/umul.asm         | 44 +++++++++++++++++++
 mpn/mips64/r6/add_n.asm        | 70 +++++++++++++++++++++++++++++
 mpn/mips64/r6/addmul_1.asm     | 70 +++++++++++++++++++++++++++++
 mpn/mips64/r6/gmp-mparam.h     | 72 ++++++++++++++++++++++++++++++
 mpn/mips64/r6/lshift.asm       | 99 ++++++++++++++++++++++++++++++++++++++++++
 mpn/mips64/r6/mul_1.asm        | 64 +++++++++++++++++++++++++++
 mpn/mips64/r6/rshift.asm       | 96 ++++++++++++++++++++++++++++++++++++++++
 mpn/mips64/r6/sqr_diagonal.asm | 59 +++++++++++++++++++++++++
 mpn/mips64/r6/sub_n.asm        | 68 +++++++++++++++++++++++++++++
 mpn/mips64/r6/submul_1.asm     | 69 +++++++++++++++++++++++++++++
 mpn/mips64/r6/umul.asm         | 44 +++++++++++++++++++
 21 files changed, 1428 insertions(+)
 create mode 100644 mpn/mips32/r6/add_n.asm
 create mode 100644 mpn/mips32/r6/addmul_1.asm
 create mode 100644 mpn/mips32/r6/gmp-mparam.h
 create mode 100644 mpn/mips32/r6/lshift.asm
 create mode 100644 mpn/mips32/r6/mul_1.asm
 create mode 100644 mpn/mips32/r6/rshift.asm
 create mode 100644 mpn/mips32/r6/sqr_diagonal.asm
 create mode 100644 mpn/mips32/r6/sub_n.asm
 create mode 100644 mpn/mips32/r6/submul_1.asm
 create mode 100644 mpn/mips32/r6/umul.asm
 create mode 100644 mpn/mips64/r6/add_n.asm
 create mode 100644 mpn/mips64/r6/addmul_1.asm
 create mode 100644 mpn/mips64/r6/gmp-mparam.h
 create mode 100644 mpn/mips64/r6/lshift.asm
 create mode 100644 mpn/mips64/r6/mul_1.asm
 create mode 100644 mpn/mips64/r6/rshift.asm
 create mode 100644 mpn/mips64/r6/sqr_diagonal.asm
 create mode 100644 mpn/mips64/r6/sub_n.asm
 create mode 100644 mpn/mips64/r6/submul_1.asm
 create mode 100644 mpn/mips64/r6/umul.asm

diff --git a/configure.ac b/configure.ac
index 6812547..25c984c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1006,6 +1006,16 @@ case $host in
     # this suits both mips32 and mips64
     GMP_INCLUDE_MPN(mips32/mips-defs.m4)
 
+    mips_isa_rev=$($CC -dM -E - < /dev/null | grep "__mips_isa_rev"| cut -d ' '  -f3)
+
+    if test -z "$mips_isa_rev"; then
+      mips_isa_rev=0
+    fi
+
+    if test $mips_isa_rev -ge 6; then
+      path="mips32/r6"
+    fi
+
     case $host in
       [mips64*-*-* | mipsisa64*-*-* | mips*-*-irix[6789]*])
         abilist="n32 64 o32"
@@ -1026,6 +1036,11 @@ case $host in
         cc_64_cflags="-O2 -64"		# no -g, it disables all optimizations
         cc_64_ldflags="-Wc,-64"
         path_64="mips64"
+
+        if test $mips_isa_rev -ge 6; then
+          path_n32="mips64/r6"
+          path_64="mips64/r6"
+        fi
         ;;
     esac
     ;;
diff --git a/mpn/mips32/r6/add_n.asm b/mpn/mips32/r6/add_n.asm
new file mode 100644
index 0000000..20909c4
--- /dev/null
+++ b/mpn/mips32/r6/add_n.asm
@@ -0,0 +1,65 @@
+dnl  MIPS64 mpn_add_n -- Add two limb vectors of the same length > 0 and store
+dnl  sum in a third limb vector.
+
+dnl  Copyright 1995, 2000-2002, 2011 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C res_ptr	$4
+C s1_ptr	$5
+C s2_ptr	$6
+C size		$7
+
+ASM_START()
+PROLOGUE(mpn_add_n)
+
+	move	$2,$0
+Loop:
+	lw	$9,0($5)
+	lw	$10,0($6)
+	addiu	$7,$7,-1	C decrement loop counter
+
+	addu	$9,$2,$9
+	sltu	$2,$9,$2
+	addu	$10,$9,$10
+	sltu	$9,$10,$9
+
+	sw	$10,0($4)
+
+	addiu	$5,$5,4
+	addiu	$6,$6,4
+	addiu	$4,$4,4
+
+	bgtz	$7,Loop
+	addu	$2,$2,$9
+Lend:
+	j	$31
+	nop
+EPILOGUE()
diff --git a/mpn/mips32/r6/addmul_1.asm b/mpn/mips32/r6/addmul_1.asm
new file mode 100644
index 0000000..66b20e8
--- /dev/null
+++ b/mpn/mips32/r6/addmul_1.asm
@@ -0,0 +1,70 @@
+dnl  MIPS64 mpn_addmul_1 -- Multiply a limb vector with a single limb and add
+dnl  the product to a second limb vector.
+
+dnl  Copyright 1992, 1994, 1995, 2000-2002 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C res_ptr	$4
+C s1_ptr	$5
+C size		$6
+C s2_limb	$7
+
+ASM_START()
+PROLOGUE(mpn_addmul_1)
+
+	move	$2,$0		C zero cy2
+
+Loop:
+	lw      $8,0($5)
+	lw	$10,0($4)
+	addiu	$6,$6,-1	C decrement loop counter
+
+
+	mulu	$3,$7,$8
+
+	addu	$3,$3,$2	C add old carry limb to low product limb
+	sltu	$2,$3,$2	C carry from previous addition -> $2
+	addu	$3,$10,$3
+	sltu	$10,$3,$10
+	addu	$2,$2,$10
+	sw	$3,0($4)
+
+	muhu	$9,$7,$8
+
+	addiu	$5,$5,4
+	addiu	$4,$4,4
+
+	bgtz	$6,Loop
+	addu	$2,$9,$2	C add high product limb and carry from addition
+Lend:
+	j	$31
+	nop
+EPILOGUE(mpn_addmul_1)
diff --git a/mpn/mips32/r6/gmp-mparam.h b/mpn/mips32/r6/gmp-mparam.h
new file mode 100644
index 0000000..986135d
--- /dev/null
+++ b/mpn/mips32/r6/gmp-mparam.h
@@ -0,0 +1,72 @@
+/* gmp-mparam.h -- Compiler/machine parameter header file.
+
+Copyright 1991, 1993, 1994, 1999-2002 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 either:
+
+  * 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.
+
+or
+
+  * the GNU General Public License as published by the Free Software
+    Foundation; either version 2 of the License, or (at your option) any
+    later version.
+
+or both in parallel, as here.
+
+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 General Public License
+for more details.
+
+You should have received copies of the GNU General Public License and the
+GNU Lesser General Public License along with the GNU MP Library.  If not,
+see https://www.gnu.org/licenses/.  */
+
+
+#define GMP_LIMB_BITS 32
+#define GMP_LIMB_BYTES 4
+
+
+/* Generated by tuneup.c, 2002-02-20, gcc 2.95 (R3000) */
+
+#define MUL_TOOM22_THRESHOLD             20
+#define MUL_TOOM33_THRESHOLD             50
+
+#define SQR_BASECASE_THRESHOLD            7
+#define SQR_TOOM2_THRESHOLD              57
+#define SQR_TOOM3_THRESHOLD              78
+
+#define DIV_SB_PREINV_THRESHOLD           0  /* always */
+#define DIV_DC_THRESHOLD                 57
+#define POWM_THRESHOLD                   78
+
+#define GCD_ACCEL_THRESHOLD               3
+#define JACOBI_BASE_METHOD                2
+
+#define DIVREM_1_NORM_THRESHOLD           0  /* always */
+#define DIVREM_1_UNNORM_THRESHOLD         0  /* always */
+#define MOD_1_NORM_THRESHOLD              0  /* always */
+#define MOD_1_UNNORM_THRESHOLD            0  /* always */
+#define USE_PREINV_DIVREM_1               1
+#define USE_PREINV_MOD_1                  1
+#define DIVREM_2_THRESHOLD                0  /* always */
+#define DIVEXACT_1_THRESHOLD              0  /* always */
+#define MODEXACT_1_ODD_THRESHOLD          0  /* always */
+
+#define GET_STR_DC_THRESHOLD             19
+#define GET_STR_PRECOMPUTE_THRESHOLD     25
+#define SET_STR_THRESHOLD               309
+
+#define MUL_FFT_TABLE  { 496, 1056, 2176, 5632, 14336, 40960, 0 }
+#define MUL_FFT_MODF_THRESHOLD          624
+#define MUL_FFT_THRESHOLD              5888
+
+#define SQR_FFT_TABLE  { 496, 1184, 2176, 5632, 14336, 40960, 0 }
+#define SQR_FFT_MODF_THRESHOLD          560
+#define SQR_FFT_THRESHOLD              5376
diff --git a/mpn/mips32/r6/lshift.asm b/mpn/mips32/r6/lshift.asm
new file mode 100644
index 0000000..2428409
--- /dev/null
+++ b/mpn/mips32/r6/lshift.asm
@@ -0,0 +1,99 @@
+dnl  MIPS32 mpn_lshift -- Left shift.
+
+dnl  Copyright 1995, 2000, 2002 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C res_ptr	$4
+C src_ptr	$5
+C size		$6
+C cnt		$7
+
+ASM_START()
+PROLOGUE(mpn_lshift)
+	sll	$2,$6,2
+	addu	$5,$5,$2	C make r5 point at end of src
+	lw	$10,-4($5)	C load first limb
+	subu	$13,$0,$7
+	addu	$4,$4,$2	C make r4 point at end of res
+	addiu	$6,$6,-1
+	and	$9,$6,4-1	C number of limbs in first loop
+	beq	$9,$0,.L0	C if multiple of 4 limbs, skip first loop
+	srl	$2,$10,$13	C compute function result
+
+	subu	$6,$6,$9
+
+.Loop0:	lw	$3,-8($5)
+	addiu	$4,$4,-4
+	addiu	$5,$5,-4
+	addiu	$9,$9,-1
+	sll	$11,$10,$7
+	srl	$12,$3,$13
+	move	$10,$3
+	or	$8,$11,$12
+	bne	$9,$0,.Loop0
+	sw	$8,0($4)
+
+.L0:	beq	$6,$0,.Lend
+	 nop
+
+.Loop:	lw	$3,-8($5)
+	addiu	$4,$4,-16
+	addiu	$6,$6,-4
+	sll	$11,$10,$7
+	srl	$12,$3,$13
+
+	lw	$10,-12($5)
+	sll	$14,$3,$7
+	or	$8,$11,$12
+	sw	$8,12($4)
+	srl	$9,$10,$13
+
+	lw	$3,-16($5)
+	sll	$11,$10,$7
+	or	$8,$14,$9
+	sw	$8,8($4)
+	srl	$12,$3,$13
+
+	lw	$10,-20($5)
+	sll	$14,$3,$7
+	or	$8,$11,$12
+	sw	$8,4($4)
+	srl	$9,$10,$13
+
+	addiu	$5,$5,-16
+	or	$8,$14,$9
+	bgtz	$6,.Loop
+	sw	$8,0($4)
+
+.Lend:	sll	$8,$10,$7
+	j	$31
+	sw	$8,-4($4)
+EPILOGUE(mpn_lshift)
diff --git a/mpn/mips32/r6/mul_1.asm b/mpn/mips32/r6/mul_1.asm
new file mode 100644
index 0000000..ab8db7b
--- /dev/null
+++ b/mpn/mips32/r6/mul_1.asm
@@ -0,0 +1,64 @@
+dnl  MIPS64 mpn_mul_1 -- Multiply a limb vector with a single limb and store
+dnl  the product in a second limb vector.
+
+dnl  Copyright 1992, 1994, 1995, 2000-2002 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C res_ptr	$4
+C s1_ptr	$5
+C size		$6
+C s2_limb	$7
+
+ASM_START()
+PROLOGUE(mpn_mul_1)
+
+	move	$2,$0		C zero cy2
+Loop:
+	lw      $8,0($5)
+	addiu	$6,$6,-1	C decrement loop counter
+
+	mulu	$3,$7,$8
+
+	addu	$3,$3,$2	C add old carry limb to low product limb
+	sltu	$2,$3,$2	C carry from previous addition -> $2
+	sw	$3,0($4)
+
+	muhu	$9,$7,$8
+
+	addiu	$5,$5,4
+	addiu	$4,$4,4
+
+	bgtz	$6,Loop
+	addu	$2,$9,$2	C add high product limb and carry from addition
+Lend:
+	j	$31
+	nop
+EPILOGUE(mpn_mul_1)
diff --git a/mpn/mips32/r6/rshift.asm b/mpn/mips32/r6/rshift.asm
new file mode 100644
index 0000000..5b3fa03
--- /dev/null
+++ b/mpn/mips32/r6/rshift.asm
@@ -0,0 +1,96 @@
+dnl  MIPS32 mpn_rshift -- Right shift.
+
+dnl  Copyright 1995, 2000, 2002 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C res_ptr	$4
+C src_ptr	$5
+C size		$6
+C cnt		$7
+
+ASM_START()
+PROLOGUE(mpn_rshift)
+	lw	$10,0($5)	C load first limb
+	subu	$13,$0,$7
+	addiu	$6,$6,-1
+	and	$9,$6,4-1	C number of limbs in first loop
+	beq	$9,$0,.L0	C if multiple of 4 limbs, skip first loop
+	sll	$2,$10,$13	C compute function result
+
+	subu	$6,$6,$9
+
+.Loop0:	lw	$3,4($5)
+	addiu	$4,$4,4
+	addiu	$5,$5,4
+	addiu	$9,$9,-1
+	srl	$11,$10,$7
+	sll	$12,$3,$13
+	move	$10,$3
+	or	$8,$11,$12
+	bne	$9,$0,.Loop0
+	sw	$8,-4($4)
+
+.L0:	beq	$6,$0,.Lend
+	 nop
+
+.Loop:	lw	$3,4($5)
+	addiu	$4,$4,16
+	addiu	$6,$6,-4
+	srl	$11,$10,$7
+	sll	$12,$3,$13
+
+	lw	$10,8($5)
+	srl	$14,$3,$7
+	or	$8,$11,$12
+	sw	$8,-16($4)
+	sll	$9,$10,$13
+
+	lw	$3,12($5)
+	srl	$11,$10,$7
+	or	$8,$14,$9
+	sw	$8,-12($4)
+	sll	$12,$3,$13
+
+	lw	$10,16($5)
+	srl	$14,$3,$7
+	or	$8,$11,$12
+	sw	$8,-8($4)
+	sll	$9,$10,$13
+
+	addiu	$5,$5,16
+	or	$8,$14,$9
+	bgtz	$6,.Loop
+	sw	$8,-4($4)
+
+.Lend:	srl	$8,$10,$7
+	j	$31
+	sw	$8,0($4)
+EPILOGUE(mpn_rshift)
diff --git a/mpn/mips32/r6/sqr_diagonal.asm b/mpn/mips32/r6/sqr_diagonal.asm
new file mode 100644
index 0000000..633ad23
--- /dev/null
+++ b/mpn/mips32/r6/sqr_diagonal.asm
@@ -0,0 +1,59 @@
+dnl  MIPS64 mpn_sqr_diagonal.
+
+dnl  Copyright 2001, 2002 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+
+dnl  INPUT PARAMETERS
+dnl  rp		$4
+dnl  up		$5
+dnl  n		$6
+
+include(`../config.m4')
+
+ASM_START()
+PROLOGUE(mpn_sqr_diagonal)
+
+Loop:
+	lw	$8,0($5)
+	addiu	$6,$6,-1
+
+	mulu	$10,$8,$8
+	muhu	$9,$8,$8
+
+	sw	$10,0($4)
+	sw	$9,4($4)
+
+	addiu	$5,$5,4
+
+	bgtz	$6,Loop
+	daddiu	$4,$4,8
+Lend:
+	j	$31
+	nop
+EPILOGUE(mpn_sqr_diagonal)
diff --git a/mpn/mips32/r6/sub_n.asm b/mpn/mips32/r6/sub_n.asm
new file mode 100644
index 0000000..65c5dda
--- /dev/null
+++ b/mpn/mips32/r6/sub_n.asm
@@ -0,0 +1,64 @@
+dnl  MIPS64 mpn_sub_n -- Subtract two limb vectors of the same length > 0 and
+dnl  store difference in a third limb vector.
+
+dnl  Copyright 1995, 2000-2002, 2011 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C res_ptr	$4
+C s1_ptr	$5
+C s2_ptr	$6
+C size		$7
+
+ASM_START()
+PROLOGUE(mpn_sub_n)
+	move	$2,$0
+Loop:
+	lw	$9,0($5)
+	lw	$10,0($6)
+	addiu	$7,$7,-1	C decrement loop counter
+
+	addu	$10,$2,$10
+	sltu	$2,$10,$2
+	subu	$10,$9,$10
+	sltu	$9,$9,$10
+
+	sw	$10,0($4)
+
+	addiu	$5,$5,4
+	addiu	$6,$6,4
+	addiu	$4,$4,4
+
+	bgtz	$7,Loop
+	addu	$2,$2,$9
+Lend:
+	j	$31
+	nop
+EPILOGUE()
diff --git a/mpn/mips32/r6/submul_1.asm b/mpn/mips32/r6/submul_1.asm
new file mode 100644
index 0000000..8031941
--- /dev/null
+++ b/mpn/mips32/r6/submul_1.asm
@@ -0,0 +1,69 @@
+dnl  MIPS64 mpn_submul_1 -- Multiply a limb vector with a single limb and
+dnl  subtract the product from a second limb vector.
+
+dnl  Copyright 1992, 1994, 1995, 2000-2002 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C res_ptr	$4
+C s1_ptr	$5
+C size		$6
+C s2_limb	$7
+
+ASM_START()
+PROLOGUE(mpn_submul_1)
+
+	move	$2,$0		C zero cy2
+Loop:
+	lw      $8,0($5)
+	lw	    $10,0($4)
+	daddiu	$6,$6,-1	C decrement loop counter
+
+	mulu	$3,$7,$8
+
+	addu	$3,$3,$2	C add old carry limb to low product limb
+	sltu	$2,$3,$2	C carry from previous addition -> $2
+	subu	$3,$10,$3
+	sltu	$10,$10,$3
+	addu	$2,$2,$10
+	sw	$3,0($4)
+
+	muhu	$9,$7,$8
+
+	addiu	$5,$5,4
+	addiu	$4,$4,4
+
+	bgtz	$6,Loop
+	addu	$2,$9,$2	C add high product limb and carry from addition
+Lend:
+	j	$31
+	nop
+
+EPILOGUE(mpn_submul_1)
diff --git a/mpn/mips32/r6/umul.asm b/mpn/mips32/r6/umul.asm
new file mode 100644
index 0000000..51531ff
--- /dev/null
+++ b/mpn/mips32/r6/umul.asm
@@ -0,0 +1,44 @@
+dnl  MIPS64 umul_ppmm -- longlong.h support.
+
+dnl  Copyright 2002 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C plp   $4
+C u     $5
+C v     $6
+
+ASM_START()
+PROLOGUE(mpn_umul_ppmm)
+	mulu	$3,$5,$6
+	muhu	$2,$5,$6
+	j	$31
+	sd	$3,0($4)
+EPILOGUE(mpn_umul_ppmm)
diff --git a/mpn/mips64/r6/add_n.asm b/mpn/mips64/r6/add_n.asm
new file mode 100644
index 0000000..c9b593b
--- /dev/null
+++ b/mpn/mips64/r6/add_n.asm
@@ -0,0 +1,70 @@
+dnl  MIPS64 mpn_add_n -- Add two limb vectors of the same length > 0 and store
+dnl  sum in a third limb vector.
+
+dnl  Copyright 1995, 2000-2002, 2011 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C res_ptr	$4
+C s1_ptr	$5
+C s2_ptr	$6
+C size		$7
+
+ASM_START()
+PROLOGUE(mpn_add_nc)
+
+	move	$2,$8
+	b	Loop
+EPILOGUE()
+PROLOGUE(mpn_add_n)
+
+	move	$2,$0
+Loop:
+	ld	$9,0($5)
+	ld	$10,0($6)
+	daddiu	$7,$7,-1	C decrement loop counter
+
+	daddu	$9,$2,$9
+	sltu	$2,$9,$2
+	daddu	$10,$9,$10
+	sltu	$9,$10,$9
+
+	sd	$10,0($4)
+
+	daddiu	$5,$5,8
+	daddiu	$6,$6,8
+	daddiu	$4,$4,8
+
+	bgtz	$7,Loop
+	daddu	$2,$2,$9
+Lend:
+	j	$31
+	nop
+EPILOGUE()
diff --git a/mpn/mips64/r6/addmul_1.asm b/mpn/mips64/r6/addmul_1.asm
new file mode 100644
index 0000000..17267d9
--- /dev/null
+++ b/mpn/mips64/r6/addmul_1.asm
@@ -0,0 +1,70 @@
+dnl  MIPS64 mpn_addmul_1 -- Multiply a limb vector with a single limb and add
+dnl  the product to a second limb vector.
+
+dnl  Copyright 1992, 1994, 1995, 2000-2002 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C res_ptr	$4
+C s1_ptr	$5
+C size		$6
+C s2_limb	$7
+
+ASM_START()
+PROLOGUE(mpn_addmul_1)
+
+	move	$2,$0		C zero cy2
+
+Loop:
+	ld      $8,0($5)
+	ld	$10,0($4)
+	daddiu	$6,$6,-1	C decrement loop counter
+
+
+	dmulu	$3,$7,$8
+
+	daddu	$3,$3,$2	C add old carry limb to low product limb
+	sltu	$2,$3,$2	C carry from previous addition -> $2
+	daddu	$3,$10,$3
+	sltu	$10,$3,$10
+	daddu	$2,$2,$10
+	sd	$3,0($4)
+
+	dmuhu	$9,$7,$8
+
+	daddiu  $5,$5,8
+	daddiu	$4,$4,8
+
+	bgtz	$6,Loop
+	daddu	$2,$9,$2	C add high product limb and carry from addition
+Lend:
+	j	$31
+	nop
+EPILOGUE(mpn_addmul_1)
diff --git a/mpn/mips64/r6/gmp-mparam.h b/mpn/mips64/r6/gmp-mparam.h
new file mode 100644
index 0000000..b7fcf24
--- /dev/null
+++ b/mpn/mips64/r6/gmp-mparam.h
@@ -0,0 +1,72 @@
+/* gmp-mparam.h -- Compiler/machine parameter header file.
+
+Copyright 1991, 1993, 1994, 1999-2004 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 either:
+
+  * 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.
+
+or
+
+  * the GNU General Public License as published by the Free Software
+    Foundation; either version 2 of the License, or (at your option) any
+    later version.
+
+or both in parallel, as here.
+
+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 General Public License
+for more details.
+
+You should have received copies of the GNU General Public License and the
+GNU Lesser General Public License along with the GNU MP Library.  If not,
+see https://www.gnu.org/licenses/.  */
+
+
+#define GMP_LIMB_BITS 64
+#define GMP_LIMB_BYTES 8
+
+
+/* Generated by tuneup.c, 2004-02-10, gcc 3.2 & MIPSpro C 7.2.1 (R1x000) */
+
+#define MUL_TOOM22_THRESHOLD             16
+#define MUL_TOOM33_THRESHOLD             89
+
+#define SQR_BASECASE_THRESHOLD            6
+#define SQR_TOOM2_THRESHOLD              32
+#define SQR_TOOM3_THRESHOLD              98
+
+#define DIV_SB_PREINV_THRESHOLD           0  /* always */
+#define DIV_DC_THRESHOLD                 53
+#define POWM_THRESHOLD                   61
+
+#define HGCD_THRESHOLD                  116
+#define GCD_ACCEL_THRESHOLD               3
+#define GCD_DC_THRESHOLD                492
+#define JACOBI_BASE_METHOD                2
+
+#define MOD_1_NORM_THRESHOLD              0  /* always */
+#define MOD_1_UNNORM_THRESHOLD            0  /* always */
+#define USE_PREINV_DIVREM_1               1
+#define USE_PREINV_MOD_1                  1
+#define DIVREM_2_THRESHOLD                0  /* always */
+#define DIVEXACT_1_THRESHOLD              0  /* always */
+#define MODEXACT_1_ODD_THRESHOLD          0  /* always */
+
+#define GET_STR_DC_THRESHOLD             21
+#define GET_STR_PRECOMPUTE_THRESHOLD     26
+#define SET_STR_THRESHOLD              3962
+
+#define MUL_FFT_TABLE  { 368, 736, 1600, 3328, 7168, 20480, 49152, 0 }
+#define MUL_FFT_MODF_THRESHOLD          264
+#define MUL_FFT_THRESHOLD              1920
+
+#define SQR_FFT_TABLE  { 368, 736, 1856, 3328, 7168, 20480, 49152, 0 }
+#define SQR_FFT_MODF_THRESHOLD          280
+#define SQR_FFT_THRESHOLD              1920
diff --git a/mpn/mips64/r6/lshift.asm b/mpn/mips64/r6/lshift.asm
new file mode 100644
index 0000000..a232fcf
--- /dev/null
+++ b/mpn/mips64/r6/lshift.asm
@@ -0,0 +1,99 @@
+dnl  MIPS64 mpn_lshift -- Left shift.
+
+dnl  Copyright 1995, 2000-2002 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C res_ptr	$4
+C src_ptr	$5
+C size		$6
+C cnt		$7
+
+ASM_START()
+PROLOGUE(mpn_lshift)
+	dsll	$2,$6,3
+	daddu	$5,$5,$2	C make r5 point at end of src
+	ld	$10,-8($5)	C load first limb
+	dsubu	$13,$0,$7
+	daddu	$4,$4,$2	C make r4 point at end of res
+	daddiu	$6,$6,-1
+	and	$9,$6,4-1	C number of limbs in first loop
+	beq	$9,$0,.L0	C if multiple of 4 limbs, skip first loop
+	dsrl	$2,$10,$13	C compute function result
+
+	dsubu	$6,$6,$9
+
+.Loop0:	ld	$3,-16($5)
+	daddiu	$4,$4,-8
+	daddiu	$5,$5,-8
+	daddiu	$9,$9,-1
+	dsll	$11,$10,$7
+	dsrl	$12,$3,$13
+	move	$10,$3
+	or	$8,$11,$12
+	bne	$9,$0,.Loop0
+	sd	$8,0($4)
+
+.L0:	beq	$6,$0,.Lend
+	nop
+
+.Loop:	ld	$3,-16($5)
+	daddiu	$4,$4,-32
+	daddiu	$6,$6,-4
+	dsll	$11,$10,$7
+	dsrl	$12,$3,$13
+
+	ld	$10,-24($5)
+	dsll	$14,$3,$7
+	or	$8,$11,$12
+	sd	$8,24($4)
+	dsrl	$9,$10,$13
+
+	ld	$3,-32($5)
+	dsll	$11,$10,$7
+	or	$8,$14,$9
+	sd	$8,16($4)
+	dsrl	$12,$3,$13
+
+	ld	$10,-40($5)
+	dsll	$14,$3,$7
+	or	$8,$11,$12
+	sd	$8,8($4)
+	dsrl	$9,$10,$13
+
+	daddiu	$5,$5,-32
+	or	$8,$14,$9
+	bgtz	$6,.Loop
+	sd	$8,0($4)
+
+.Lend:	dsll	$8,$10,$7
+	j	$31
+	sd	$8,-8($4)
+EPILOGUE(mpn_lshift)
diff --git a/mpn/mips64/r6/mul_1.asm b/mpn/mips64/r6/mul_1.asm
new file mode 100644
index 0000000..bd7ba30
--- /dev/null
+++ b/mpn/mips64/r6/mul_1.asm
@@ -0,0 +1,64 @@
+dnl  MIPS64 mpn_mul_1 -- Multiply a limb vector with a single limb and store
+dnl  the product in a second limb vector.
+
+dnl  Copyright 1992, 1994, 1995, 2000-2002 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C res_ptr	$4
+C s1_ptr	$5
+C size		$6
+C s2_limb	$7
+
+ASM_START()
+PROLOGUE(mpn_mul_1)
+
+	move	$2,$0		C zero cy2
+Loop:
+	ld      $8,0($5)
+	daddiu	$6,$6,-1	C decrement loop counter
+
+	dmulu	$3,$7,$8
+
+	daddu	$3,$3,$2	C add old carry limb to low product limb
+	sltu	$2,$3,$2	C carry from previous addition -> $2
+	sd	$3,0($4)
+
+	dmuhu	$9,$7,$8
+
+	daddiu  $5,$5,8
+	daddiu	$4,$4,8
+
+	bgtz	$6,Loop
+	daddu	$2,$9,$2	C add high product limb and carry from addition
+Lend:
+	j	$31
+	nop
+EPILOGUE(mpn_mul_1)
diff --git a/mpn/mips64/r6/rshift.asm b/mpn/mips64/r6/rshift.asm
new file mode 100644
index 0000000..a43aa90
--- /dev/null
+++ b/mpn/mips64/r6/rshift.asm
@@ -0,0 +1,96 @@
+dnl  MIPS64 mpn_rshift -- Right shift.
+
+dnl  Copyright 1995, 2000-2002 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C res_ptr	$4
+C src_ptr	$5
+C size		$6
+C cnt		$7
+
+ASM_START()
+PROLOGUE(mpn_rshift)
+	ld	$10,0($5)	C load first limb
+	dsubu	$13,$0,$7
+	daddiu	$6,$6,-1
+	and	$9,$6,4-1	C number of limbs in first loop
+	beq	$9,$0,.L0	C if multiple of 4 limbs, skip first loop
+	dsll	$2,$10,$13	C compute function result
+
+	dsubu	$6,$6,$9
+
+.Loop0:	ld	$3,8($5)
+	daddiu	$4,$4,8
+	daddiu	$5,$5,8
+	daddiu	$9,$9,-1
+	dsrl	$11,$10,$7
+	dsll	$12,$3,$13
+	move	$10,$3
+	or	$8,$11,$12
+	bne	$9,$0,.Loop0
+	sd	$8,-8($4)
+
+.L0:	beq	$6,$0,.Lend
+	nop
+
+.Loop:	ld	$3,8($5)
+	daddiu	$4,$4,32
+	daddiu	$6,$6,-4
+	dsrl	$11,$10,$7
+	dsll	$12,$3,$13
+
+	ld	$10,16($5)
+	dsrl	$14,$3,$7
+	or	$8,$11,$12
+	sd	$8,-32($4)
+	dsll	$9,$10,$13
+
+	ld	$3,24($5)
+	dsrl	$11,$10,$7
+	or	$8,$14,$9
+	sd	$8,-24($4)
+	dsll	$12,$3,$13
+
+	ld	$10,32($5)
+	dsrl	$14,$3,$7
+	or	$8,$11,$12
+	sd	$8,-16($4)
+	dsll	$9,$10,$13
+
+	daddiu	$5,$5,32
+	or	$8,$14,$9
+	bgtz	$6,.Loop
+	sd	$8,-8($4)
+
+.Lend:	dsrl	$8,$10,$7
+	j	$31
+	sd	$8,0($4)
+EPILOGUE(mpn_rshift)
diff --git a/mpn/mips64/r6/sqr_diagonal.asm b/mpn/mips64/r6/sqr_diagonal.asm
new file mode 100644
index 0000000..1f22774
--- /dev/null
+++ b/mpn/mips64/r6/sqr_diagonal.asm
@@ -0,0 +1,59 @@
+dnl  MIPS64 mpn_sqr_diagonal.
+
+dnl  Copyright 2001, 2002 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+
+dnl  INPUT PARAMETERS
+dnl  rp		$4
+dnl  up		$5
+dnl  n		$6
+
+include(`../config.m4')
+
+ASM_START()
+PROLOGUE(mpn_sqr_diagonal)
+
+Loop:
+	ld	$8,0($5)
+	daddiu	$6,$6,-1
+
+	dmulu	$10,$8,$8
+	dmuhu	$9,$8,$8
+
+	sd	$10,0($4)
+	sd	$9,8($4)
+
+	daddiu  $5,$5,8
+
+	bgtz	$6,Loop
+	daddiu	$4,$4,16
+Lend:
+	j	$31
+	nop
+EPILOGUE(mpn_sqr_diagonal)
diff --git a/mpn/mips64/r6/sub_n.asm b/mpn/mips64/r6/sub_n.asm
new file mode 100644
index 0000000..b8b4e78
--- /dev/null
+++ b/mpn/mips64/r6/sub_n.asm
@@ -0,0 +1,68 @@
+dnl  MIPS64 mpn_sub_n -- Subtract two limb vectors of the same length > 0 and
+dnl  store difference in a third limb vector.
+
+dnl  Copyright 1995, 2000-2002, 2011 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C res_ptr	$4
+C s1_ptr	$5
+C s2_ptr	$6
+C size		$7
+
+ASM_START()
+PROLOGUE(mpn_sub_nc)
+	move	$2,$8
+	b	Loop
+EPILOGUE()
+PROLOGUE(mpn_sub_n)
+	move	$2,$0
+Loop:
+	ld	$9,0($5)
+	ld	$10,0($6)
+	daddiu	$7,$7,-1	C decrement loop counter
+
+	daddu	$10,$2,$10
+	sltu	$2,$10,$2
+	dsubu	$10,$9,$10
+	sltu	$9,$9,$10
+
+	sd	$10,0($4)
+
+	daddiu	$5,$5,8
+	daddiu	$6,$6,8
+	daddiu  $4,$4,8
+
+	bgtz	$7,Loop
+	daddu	$2,$2,$9
+Lend:
+	j	$31
+	nop
+EPILOGUE()
diff --git a/mpn/mips64/r6/submul_1.asm b/mpn/mips64/r6/submul_1.asm
new file mode 100644
index 0000000..4f74e63
--- /dev/null
+++ b/mpn/mips64/r6/submul_1.asm
@@ -0,0 +1,69 @@
+dnl  MIPS64 mpn_submul_1 -- Multiply a limb vector with a single limb and
+dnl  subtract the product from a second limb vector.
+
+dnl  Copyright 1992, 1994, 1995, 2000-2002 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C res_ptr	$4
+C s1_ptr	$5
+C size		$6
+C s2_limb	$7
+
+ASM_START()
+PROLOGUE(mpn_submul_1)
+
+	move	$2,$0		C zero cy2
+Loop:
+	ld      $8,0($5)
+	ld	    $10,0($4)
+	daddiu	$6,$6,-1	C decrement loop counter
+
+	dmulu	$3,$7,$8
+
+	daddu	$3,$3,$2	C add old carry limb to low product limb
+	sltu	$2,$3,$2	C carry from previous addition -> $2
+	dsubu	$3,$10,$3
+	sltu	$10,$10,$3
+	daddu	$2,$2,$10
+	sd	$3,0($4)
+
+	dmuhu	$9,$7,$8
+
+	daddiu  $5,$5,8
+	daddiu	$4,$4,8
+
+	bgtz	$6,Loop
+	daddu	$2,$9,$2	C add high product limb and carry from addition
+Lend:
+	j	$31
+	nop
+
+EPILOGUE(mpn_submul_1)
diff --git a/mpn/mips64/r6/umul.asm b/mpn/mips64/r6/umul.asm
new file mode 100644
index 0000000..22c8e8c
--- /dev/null
+++ b/mpn/mips64/r6/umul.asm
@@ -0,0 +1,44 @@
+dnl  MIPS64 umul_ppmm -- longlong.h support.
+
+dnl  Copyright 2002 Free Software Foundation, Inc.
+
+dnl  This file is part of the GNU MP Library.
+dnl
+dnl  The GNU MP Library is free software; you can redistribute it and/or modify
+dnl  it under the terms of either:
+dnl
+dnl    * the GNU Lesser General Public License as published by the Free
+dnl      Software Foundation; either version 3 of the License, or (at your
+dnl      option) any later version.
+dnl
+dnl  or
+dnl
+dnl    * the GNU General Public License as published by the Free Software
+dnl      Foundation; either version 2 of the License, or (at your option) any
+dnl      later version.
+dnl
+dnl  or both in parallel, as here.
+dnl
+dnl  The GNU MP Library is distributed in the hope that it will be useful, but
+dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+dnl  for more details.
+dnl
+dnl  You should have received copies of the GNU General Public License and the
+dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
+dnl  see https://www.gnu.org/licenses/.
+
+include(`../config.m4')
+
+C INPUT PARAMETERS
+C plp   $4
+C u     $5
+C v     $6
+
+ASM_START()
+PROLOGUE(mpn_umul_ppmm)
+	dmulu	$3,$5,$6
+	dmuhu	$2,$5,$6
+	j	$31
+	sd	$3,0($4)
+EPILOGUE(mpn_umul_ppmm)
-- 
2.11.0



More information about the gmp-devel mailing list