Revert "Remove gmp from AOS"

This reverts commit f37c97684f0910a3f241394549392f00145ab0f7.

We need gmp for SymEngine for symbolicmanipultion in C++

Change-Id: Ia13216d1715cf96944f7b4f422b7a799f921d4a4
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/third_party/gmp/mpn/vax/add_n.asm b/third_party/gmp/mpn/vax/add_n.asm
new file mode 100644
index 0000000..0a0bf78
--- /dev/null
+++ b/third_party/gmp/mpn/vax/add_n.asm
@@ -0,0 +1,64 @@
+dnl  VAX mpn_add_n -- Add two limb vectors of the same length > 0 and store sum
+dnl  in a third limb vector.
+
+dnl  Copyright 1999, 2000, 2012 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')
+
+ASM_START()
+PROLOGUE(mpn_add_n)
+	.word	0x0
+	movl	16(ap), r0
+	movl	12(ap), r1
+	movl	8(ap), r2
+	movl	4(ap), r3
+	mnegl	r0, r5
+	addl2	$3, r0
+	ashl	$-2, r0, r0	C unroll loop count
+	bicl2	$-4, r5		C mask out low 2 bits
+	movaq	(r5)[r5], r5	C 9x
+	jmp	L(top)[r5]
+
+L(top):	movl	(r2)+, r4
+	adwc	(r1)+, r4
+	movl	r4, (r3)+
+	movl	(r2)+, r4
+	adwc	(r1)+, r4
+	movl	r4, (r3)+
+	movl	(r2)+, r4
+	adwc	(r1)+, r4
+	movl	r4, (r3)+
+	movl	(r2)+, r4
+	adwc	(r1)+, r4
+	movl	r4, (r3)+
+	sobgtr	r0, L(top)
+
+	adwc	r0, r0
+	ret
+EPILOGUE()
diff --git a/third_party/gmp/mpn/vax/addmul_1.asm b/third_party/gmp/mpn/vax/addmul_1.asm
new file mode 100644
index 0000000..8a6f636
--- /dev/null
+++ b/third_party/gmp/mpn/vax/addmul_1.asm
@@ -0,0 +1,124 @@
+dnl  VAX mpn_addmul_1 -- Multiply a limb vector with a limb and add the result
+dnl  to a second limb vector.
+
+dnl  Copyright 1992, 1994, 1996, 2000, 2012 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')
+
+ASM_START()
+PROLOGUE(mpn_addmul_1)
+	.word	0xfc0
+	movl	12(ap), r4
+	movl	8(ap), r8
+	movl	4(ap), r9
+	clrl	r3
+	incl	r4
+	ashl	$-1, r4, r7
+	clrl	r11
+	movl	16(ap), r6
+	jlss	L(v0_big)
+	jlbc	r4, L(1)
+
+C Loop for v0 < 0x80000000
+L(tp1):	movl	(r8)+, r1
+	jlss	L(1n0)
+	emul	r1, r6, $0, r2
+	addl2	r11, r2
+	adwc	$0, r3
+	addl2	r2, (r9)+
+	adwc	$0, r3
+L(1):	movl	(r8)+, r1
+	jlss	L(1n1)
+L(1p1):	emul	r1, r6, $0, r10
+	addl2	r3, r10
+	adwc	$0, r11
+	addl2	r10, (r9)+
+	adwc	$0, r11
+
+	sobgtr	r7, L(tp1)
+	movl	r11, r0
+	ret
+
+L(1n0):	emul	r1, r6, $0, r2
+	addl2	r11, r2
+	adwc	r6, r3
+	addl2	r2, (r9)+
+	adwc	$0, r3
+	movl	(r8)+, r1
+	jgeq	L(1p1)
+L(1n1):	emul	r1, r6, $0, r10
+	addl2	r3, r10
+	adwc	r6, r11
+	addl2	r10, (r9)+
+	adwc	$0, r11
+
+	sobgtr	r7, L(tp1)
+	movl	r11, r0
+	ret
+
+L(v0_big):
+	jlbc	r4, L(2)
+
+C Loop for v0 >= 0x80000000
+L(tp2):	movl	(r8)+, r1
+	jlss	L(2n0)
+	emul	r1, r6, $0, r2
+	addl2	r11, r2
+	adwc	r1, r3
+	addl2	r2, (r9)+
+	adwc	$0, r3
+L(2):	movl	(r8)+, r1
+	jlss	L(2n1)
+L(2p1):	emul	r1, r6, $0, r10
+	addl2	r3, r10
+	adwc	r1, r11
+	addl2	r10, (r9)+
+	adwc	$0, r11
+
+	sobgtr	r7, L(tp2)
+	movl	r11, r0
+	ret
+
+L(2n0):	emul	r1, r6, $0, r2
+	addl2	r11, r2
+	adwc	r6, r3
+	addl2	r2, (r9)+
+	adwc	r1, r3
+	movl	(r8)+, r1
+	jgeq	L(2p1)
+L(2n1):	emul	r1, r6, $0, r10
+	addl2	r3, r10
+	adwc	r6, r11
+	addl2	r10, (r9)+
+	adwc	r1, r11
+
+	sobgtr	r7, L(tp2)
+	movl	r11, r0
+	ret
+EPILOGUE()
diff --git a/third_party/gmp/mpn/vax/elf.m4 b/third_party/gmp/mpn/vax/elf.m4
new file mode 100644
index 0000000..e04f0ba
--- /dev/null
+++ b/third_party/gmp/mpn/vax/elf.m4
@@ -0,0 +1,54 @@
+divert(-1)
+
+dnl  m4 macros for VAX assembler.
+
+dnl  Copyright 2001, 2012 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/.
+
+
+defreg(r0,`%r``''0')
+defreg(r1,`%r``''1')
+defreg(r2,`%r``''2')
+defreg(r3,`%r``''3')
+defreg(r4,`%r``''4')
+defreg(r5,`%r``''5')
+defreg(r6,`%r``''6')
+defreg(r7,`%r``''7')
+defreg(r8,`%r``''8')
+defreg(r9,`%r``''9')
+defreg(r10,`%r``''10')
+defreg(r11,`%r``''11')
+defreg(r12,`%r``''12')
+defreg(r13,`%r``''13')
+defreg(r14,`%r``''14')
+defreg(r15,`%r``''15')
+defreg(ap,`%a``''p')
+
+define(`foo', blablabla)
+
+divert
diff --git a/third_party/gmp/mpn/vax/gmp-mparam.h b/third_party/gmp/mpn/vax/gmp-mparam.h
new file mode 100644
index 0000000..9f20b9b
--- /dev/null
+++ b/third_party/gmp/mpn/vax/gmp-mparam.h
@@ -0,0 +1,60 @@
+/* VAX gmp-mparam.h -- Compiler/machine parameter header file.
+
+Copyright 2000-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/.  */
+
+/* These numbers were measured manually using the tune/speed program.
+   The standard tune/tuneup takes too long.  (VAX 8800) */
+
+#define MUL_TOOM22_THRESHOLD             14
+#define MUL_TOOM33_THRESHOLD            110
+
+#define SQR_BASECASE_THRESHOLD            6
+#define SQR_TOOM2_THRESHOLD              42
+#define SQR_TOOM3_THRESHOLD             250
+
+/* #define DIV_SB_PREINV_THRESHOLD         */
+/* #define DIV_DC_THRESHOLD                */
+/* #define POWM_THRESHOLD                  */
+
+/* #define GCD_ACCEL_THRESHOLD             */
+/* #define JACOBI_BASE_METHOD              */
+
+/* #define DIVREM_1_NORM_THRESHOLD         */
+/* #define DIVREM_1_UNNORM_THRESHOLD       */
+/* #define MOD_1_NORM_THRESHOLD            */
+/* #define MOD_1_UNNORM_THRESHOLD          */
+/* #define USE_PREINV_DIVREM_1             */
+/* #define USE_PREINV_MOD_1                */
+/* #define DIVREM_2_THRESHOLD              */
+/* #define DIVEXACT_1_THRESHOLD            */
+/* #define MODEXACT_1_ODD_THRESHOLD        */
+
+/* #define GET_STR_DC_THRESHOLD            */
+/* #define GET_STR_PRECOMPUTE_THRESHOLD    */
+#define SET_STR_THRESHOLD              3400
diff --git a/third_party/gmp/mpn/vax/lshift.asm b/third_party/gmp/mpn/vax/lshift.asm
new file mode 100644
index 0000000..941e999
--- /dev/null
+++ b/third_party/gmp/mpn/vax/lshift.asm
@@ -0,0 +1,59 @@
+dnl  VAX mpn_lshift -- left shift.
+
+dnl  Copyright 1999-2001, 2012 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')
+
+ASM_START()
+PROLOGUE(mpn_lshift)
+	.word	0x1c0
+	movl	4(ap), r7
+	movl	8(ap), r6
+	movl	12(ap), r1
+	movl	16(ap), r8
+
+	moval	(r6)[r1], r6
+	moval	(r7)[r1], r7
+	clrl	r3
+	movl	-(r6), r2
+	ashq	r8, r2, r4
+	movl	r5, r0
+	movl	r2, r3
+	decl	r1
+	jeql	L(end)
+
+L(top):	movl	-(r6), r2
+	ashq	r8, r2, r4
+	movl	r5, -(r7)
+	movl	r2, r3
+	sobgtr	r1, L(top)
+
+L(end):	movl	r4, -4(r7)
+	ret
+EPILOGUE()
diff --git a/third_party/gmp/mpn/vax/mul_1.asm b/third_party/gmp/mpn/vax/mul_1.asm
new file mode 100644
index 0000000..8e4dcd2
--- /dev/null
+++ b/third_party/gmp/mpn/vax/mul_1.asm
@@ -0,0 +1,118 @@
+dnl  VAX mpn_mul_1 -- Multiply a limb vector with a limb and store the result
+dnl  in a second limb vector.
+
+dnl  Copyright 1992, 1994, 1996, 2000, 2012 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')
+
+ASM_START()
+PROLOGUE(mpn_mul_1)
+	.word	0xfc0
+	movl	12(ap), r4
+	movl	8(ap), r8
+	movl	4(ap), r9
+	clrl	r3
+	incl	r4
+	ashl	$-1, r4, r7
+	clrl	r11
+	movl	16(ap), r6
+	jlss	L(v0_big)
+	jlbc	r4, L(1)
+
+C Loop for v0 < 0x80000000
+L(tp1):	movl	(r8)+, r1
+	jlss	L(1n0)
+	emul	r1, r6, $0, r2
+	addl2	r11, r2
+	adwc	$0, r3
+	movl	r2, (r9)+
+L(1):	movl	(r8)+, r1
+	jlss	L(1n1)
+L(1p1):	emul	r1, r6, $0, r10
+	addl2	r3, r10
+	adwc	$0, r11
+	movl	r10, (r9)+
+
+	sobgtr	r7, L(tp1)
+	movl	r11, r0
+	ret
+
+L(1n0):	emul	r1, r6, $0, r2
+	addl2	r11, r2
+	adwc	r6, r3
+	movl	r2, (r9)+
+	movl	(r8)+, r1
+	jgeq	L(1p1)
+L(1n1):	emul	r1, r6, $0, r10
+	addl2	r3, r10
+	adwc	r6, r11
+	movl	r10, (r9)+
+
+	sobgtr	r7, L(tp1)
+	movl	r11, r0
+	ret
+
+L(v0_big):
+	jlbc	r4, L(2)
+
+C Loop for v0 >= 0x80000000
+L(tp2):	movl	(r8)+, r1
+	jlss	L(2n0)
+	emul	r1, r6, $0, r2
+	addl2	r11, r2
+	adwc	r1, r3
+	movl	r2, (r9)+
+L(2):	movl	(r8)+, r1
+	jlss	L(2n1)
+L(2p1):	emul	r1, r6, $0, r10
+	addl2	r3, r10
+	adwc	r1, r11
+	movl	r10, (r9)+
+
+	sobgtr	r7, L(tp2)
+	movl	r11, r0
+	ret
+
+L(2n0):	emul	r1, r6, $0, r2
+	addl2	r1, r3
+	addl2	r11, r2
+	adwc	r6, r3
+	movl	r2, (r9)+
+	movl	(r8)+, r1
+	jgeq	L(2p1)
+L(2n1):	emul	r1, r6, $0, r10
+	addl2	r1, r11
+	addl2	r3, r10
+	adwc	r6, r11
+	movl	r10, (r9)+
+
+	sobgtr	r7, L(tp2)
+	movl	r11, r0
+	ret
+EPILOGUE()
diff --git a/third_party/gmp/mpn/vax/rshift.asm b/third_party/gmp/mpn/vax/rshift.asm
new file mode 100644
index 0000000..00b2daa
--- /dev/null
+++ b/third_party/gmp/mpn/vax/rshift.asm
@@ -0,0 +1,57 @@
+dnl  VAX mpn_rshift -- right shift.
+
+dnl  Copyright 1999-2001, 2012 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')
+
+ASM_START()
+PROLOGUE(mpn_rshift)
+	.word	0x1c0
+	movl	4(ap), r7
+	movl	8(ap), r6
+	movl	12(ap), r1
+	movl	16(ap), r8
+
+	movl	(r6)+, r2
+	subl3	r8, $32, r8
+	ashl	r8, r2, r0
+	decl	r1
+	jeql	L(end)
+
+L(top):	movl	(r6)+, r3
+	ashq	r8, r2, r4
+	movl	r5, (r7)+
+	movl	r3, r2
+	sobgtr	r1, L(top)
+
+L(end):	clrl	r3
+	ashq	r8, r2, r4
+	movl	r5, (r7)
+	ret
+EPILOGUE()
diff --git a/third_party/gmp/mpn/vax/sub_n.asm b/third_party/gmp/mpn/vax/sub_n.asm
new file mode 100644
index 0000000..2844ef2
--- /dev/null
+++ b/third_party/gmp/mpn/vax/sub_n.asm
@@ -0,0 +1,64 @@
+dnl  VAX mpn_sub_n -- Subtract two limb vectors of the same length > 0 and
+dnl  store difference in a third limb vector.
+
+dnl  Copyright 1999, 2000, 2012 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')
+
+ASM_START()
+PROLOGUE(mpn_sub_n)
+	.word	0x0
+	movl	16(ap), r0
+	movl	12(ap), r1
+	movl	8(ap), r2
+	movl	4(ap), r3
+	mnegl	r0, r5
+	addl2	$3, r0
+	ashl	$-2, r0, r0	C unroll loop count
+	bicl2	$-4, r5		C mask out low 2 bits
+	movaq	(r5)[r5], r5	C 9x
+	jmp	L(top)[r5]
+
+L(top):	movl	(r2)+, r4
+	sbwc	(r1)+, r4
+	movl	r4, (r3)+
+	movl	(r2)+, r4
+	sbwc	(r1)+, r4
+	movl	r4, (r3)+
+	movl	(r2)+, r4
+	sbwc	(r1)+, r4
+	movl	r4, (r3)+
+	movl	(r2)+, r4
+	sbwc	(r1)+, r4
+	movl	r4, (r3)+
+	sobgtr	r0, L(top)
+
+	adwc	r0, r0
+	ret
+EPILOGUE()
diff --git a/third_party/gmp/mpn/vax/submul_1.asm b/third_party/gmp/mpn/vax/submul_1.asm
new file mode 100644
index 0000000..60d47fc
--- /dev/null
+++ b/third_party/gmp/mpn/vax/submul_1.asm
@@ -0,0 +1,124 @@
+dnl  VAX mpn_submul_1 -- Multiply a limb vector with a limb and subtract the
+dnl  result from a second limb vector.
+
+dnl  Copyright 1992, 1994, 1996, 2000, 2012 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')
+
+ASM_START()
+PROLOGUE(mpn_submul_1)
+	.word	0xfc0
+	movl	12(ap), r4
+	movl	8(ap), r8
+	movl	4(ap), r9
+	clrl	r3
+	incl	r4
+	ashl	$-1, r4, r7
+	clrl	r11
+	movl	16(ap), r6
+	jlss	L(v0_big)
+	jlbc	r4, L(1)
+
+C Loop for v0 < 0x80000000
+L(tp1):	movl	(r8)+, r1
+	jlss	L(1n0)
+	emul	r1, r6, $0, r2
+	addl2	r11, r2
+	adwc	$0, r3
+	subl2	r2, (r9)+
+	adwc	$0, r3
+L(1):	movl	(r8)+, r1
+	jlss	L(1n1)
+L(1p1):	emul	r1, r6, $0, r10
+	addl2	r3, r10
+	adwc	$0, r11
+	subl2	r10, (r9)+
+	adwc	$0, r11
+
+	sobgtr	r7, L(tp1)
+	movl	r11, r0
+	ret
+
+L(1n0):	emul	r1, r6, $0, r2
+	addl2	r11, r2
+	adwc	r6, r3
+	subl2	r2, (r9)+
+	adwc	$0, r3
+	movl	(r8)+, r1
+	jgeq	L(1p1)
+L(1n1):	emul	r1, r6, $0, r10
+	addl2	r3, r10
+	adwc	r6, r11
+	subl2	r10, (r9)+
+	adwc	$0, r11
+
+	sobgtr	r7, L(tp1)
+	movl	r11, r0
+	ret
+
+L(v0_big):
+	jlbc	r4, L(2)
+
+C Loop for v0 >= 0x80000000
+L(tp2):	movl	(r8)+, r1
+	jlss	L(2n0)
+	emul	r1, r6, $0, r2
+	addl2	r11, r2
+	adwc	r1, r3
+	subl2	r2, (r9)+
+	adwc	$0, r3
+L(2):	movl	(r8)+, r1
+	jlss	L(2n1)
+L(2p1):	emul	r1, r6, $0, r10
+	addl2	r3, r10
+	adwc	r1, r11
+	subl2	r10, (r9)+
+	adwc	$0, r11
+
+	sobgtr	r7, L(tp2)
+	movl	r11, r0
+	ret
+
+L(2n0):	emul	r1, r6, $0, r2
+	addl2	r11, r2
+	adwc	r6, r3
+	subl2	r2, (r9)+
+	adwc	r1, r3
+	movl	(r8)+, r1
+	jgeq	L(2p1)
+L(2n1):	emul	r1, r6, $0, r10
+	addl2	r3, r10
+	adwc	r6, r11
+	subl2	r10, (r9)+
+	adwc	r1, r11
+
+	sobgtr	r7, L(tp2)
+	movl	r11, r0
+	ret
+EPILOGUE()