aboutsummaryrefslogtreecommitdiff
path: root/gmp-6.3.0/mpn/loongarch/64
diff options
context:
space:
mode:
Diffstat (limited to 'gmp-6.3.0/mpn/loongarch/64')
-rw-r--r--gmp-6.3.0/mpn/loongarch/64/add_n.asm64
-rw-r--r--gmp-6.3.0/mpn/loongarch/64/aorslsh1_n.asm50
-rw-r--r--gmp-6.3.0/mpn/loongarch/64/aorslsh2_n.asm50
-rw-r--r--gmp-6.3.0/mpn/loongarch/64/aorslshC_n.asm116
-rw-r--r--gmp-6.3.0/mpn/loongarch/64/aorsmul_1.asm120
-rw-r--r--gmp-6.3.0/mpn/loongarch/64/cnd_aors_n.asm99
-rw-r--r--gmp-6.3.0/mpn/loongarch/64/copyd.asm75
-rw-r--r--gmp-6.3.0/mpn/loongarch/64/copyi.asm73
-rw-r--r--gmp-6.3.0/mpn/loongarch/64/lshift.asm120
-rw-r--r--gmp-6.3.0/mpn/loongarch/64/mul_1.asm97
-rw-r--r--gmp-6.3.0/mpn/loongarch/64/rshift.asm119
-rw-r--r--gmp-6.3.0/mpn/loongarch/64/sub_n.asm106
12 files changed, 1089 insertions, 0 deletions
diff --git a/gmp-6.3.0/mpn/loongarch/64/add_n.asm b/gmp-6.3.0/mpn/loongarch/64/add_n.asm
new file mode 100644
index 0000000..e0832a0
--- /dev/null
+++ b/gmp-6.3.0/mpn/loongarch/64/add_n.asm
@@ -0,0 +1,64 @@
+dnl Loongarch mpn_add_n
+
+dnl Contributed to the GNU project by Torbjorn Granlund.
+
+dnl Copyright 2023 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
+define(`rp_arg',`$r4')
+define(`ap', `$r5')
+define(`bp', `$r6')
+define(`n', `$r7')
+
+define(`rp', `$r8')
+
+ASM_START()
+PROLOGUE(mpn_add_n)
+ alsl.d rp, n, rp_arg, 3
+ alsl.d ap, n, ap, 3
+ alsl.d bp, n, bp, 3
+ sub.d n, $r0, n
+ slli.d n, n, 3
+ or $r4, $r0, $r0
+
+L(top): ldx.d $r14, ap, n
+ ldx.d $r13, bp, n
+ add.d $r12, $r14, $r13
+ sltu $r15, $r12, $r13 C cy0
+ add.d $r14, $r12, $r4
+ sltu $r16, $r14, $r4 C cy1 set iff r4=1 & r12=111...1
+ stx.d $r14, rp, n
+ addi.d n, n, 8
+ or $r4, $r15, $r16
+ bnez n, L(top)
+
+ jr $r1
+EPILOGUE()
diff --git a/gmp-6.3.0/mpn/loongarch/64/aorslsh1_n.asm b/gmp-6.3.0/mpn/loongarch/64/aorslsh1_n.asm
new file mode 100644
index 0000000..ea70b13
--- /dev/null
+++ b/gmp-6.3.0/mpn/loongarch/64/aorslsh1_n.asm
@@ -0,0 +1,50 @@
+dnl Loongarch mpn_addlsh1_n, mpn_sublsh1_n.
+
+dnl Contributed to the GNU project by Torbjorn Granlund.
+
+dnl Copyright 2023 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')
+
+define(LSH, 1)
+define(RSH, 63)
+
+ifdef(`OPERATION_addlsh1_n',`
+ define(`ADDSUB', `add.d')
+ define(`CARRY', `sltu $1,$2,$3')
+ define(`func', `mpn_addlsh1_n')
+')
+ifdef(`OPERATION_sublsh1_n',`
+ define(`ADDSUB', `sub.d')
+ define(`CARRY', `sltu $1,$3,$2')
+ define(`func', `mpn_sublsh1_n')
+')
+
+MULFUNC_PROLOGUE(mpn_addlsh1_n mpn_sublsh1_n)
+include_mpn(`loongarch/64/aorslshC_n.asm')
diff --git a/gmp-6.3.0/mpn/loongarch/64/aorslsh2_n.asm b/gmp-6.3.0/mpn/loongarch/64/aorslsh2_n.asm
new file mode 100644
index 0000000..6f03d06
--- /dev/null
+++ b/gmp-6.3.0/mpn/loongarch/64/aorslsh2_n.asm
@@ -0,0 +1,50 @@
+dnl Loongarch mpn_addlsh1_n, mpn_sublsh1_n.
+
+dnl Contributed to the GNU project by Torbjorn Granlund.
+
+dnl Copyright 2023 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')
+
+define(LSH, 2)
+define(RSH, 62)
+
+ifdef(`OPERATION_addlsh2_n',`
+ define(`ADDSUB', `add.d')
+ define(`CARRY', `sltu $1,$2,$3')
+ define(`func', `mpn_addlsh2_n')
+')
+ifdef(`OPERATION_sublsh2_n',`
+ define(`ADDSUB', `sub.d')
+ define(`CARRY', `sltu $1,$3,$2')
+ define(`func', `mpn_sublsh2_n')
+')
+
+MULFUNC_PROLOGUE(mpn_addlsh2_n mpn_sublsh2_n)
+include_mpn(`loongarch/64/aorslshC_n.asm')
diff --git a/gmp-6.3.0/mpn/loongarch/64/aorslshC_n.asm b/gmp-6.3.0/mpn/loongarch/64/aorslshC_n.asm
new file mode 100644
index 0000000..dd34188
--- /dev/null
+++ b/gmp-6.3.0/mpn/loongarch/64/aorslshC_n.asm
@@ -0,0 +1,116 @@
+dnl Loongarch mpn_addlshC_n/mpn_sublshC_n
+
+dnl Contributed to the GNU project by Torbjorn Granlund.
+
+dnl Copyright 2023 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')
+
+
+define(`rp',`$a0')
+define(`ap',`$a1')
+define(`bp',`$a2')
+define(`n', `$a3')
+
+define(`i', `$a4')
+
+
+ASM_START()
+PROLOGUE(func)
+ srli.d i, n, 2
+ move $a5, $zero
+ move $t7, $zero
+
+ andi $t0, n, 1
+ andi $t1, n, 2
+ bnez $t0, L(bx1)
+L(bx0): beqz $t1, L(b0)
+L(b10): addi.d bp, bp, -16
+ addi.d ap, ap, -16
+ addi.d rp, rp, -16
+ b L(b2)
+L(bx1): bnez $t1, L(b11)
+L(b01): addi.d bp, bp, -24
+ addi.d ap, ap, -24
+ addi.d rp, rp, -24
+ b L(b1)
+L(b11): addi.d bp, bp, -8
+ addi.d ap, ap, -8
+ addi.d rp, rp, -8
+ b L(b3)
+
+L(top): addi.d bp, bp, 32
+ addi.d ap, ap, 32
+ addi.d rp, rp, 32
+L(b0): addi.d i, i, -1
+ ld.d $t0, bp, 0
+ alsl.d $t6, $t0, $t7, LSH
+ ld.d $t2, ap, 0
+ ADDSUB $t4, $t2, $t6
+ CARRY( $a6, $t4, $t2, $t6)
+ srli.d $t7, $t0, RSH
+ ADDSUB $t5, $t4, $a5
+ CARRY( $a5, $t5, $t4, $a5)
+ st.d $t5, rp, 0
+ or $a5, $a5, $a6
+L(b3): ld.d $t0, bp, 8
+ alsl.d $t6, $t0, $t7, LSH
+ ld.d $t2, ap, 8
+ ADDSUB $t4, $t2, $t6
+ CARRY( $a6, $t4, $t2, $t6)
+ srli.d $t7, $t0, RSH
+ ADDSUB $t5, $t4, $a5
+ CARRY( $a5, $t5, $t4, $a5)
+ st.d $t5, rp, 8
+ or $a5, $a5, $a6
+L(b2): ld.d $t0, bp, 16
+ alsl.d $t6, $t0, $t7, LSH
+ ld.d $t2, ap, 16
+ ADDSUB $t4, $t2, $t6
+ CARRY( $a6, $t4, $t2, $t6)
+ srli.d $t7, $t0, RSH
+ ADDSUB $t5, $t4, $a5
+ CARRY( $a5, $t5, $t4, $a5)
+ st.d $t5, rp, 16
+ or $a5, $a5, $a6
+L(b1): ld.d $t0, bp, 24
+ alsl.d $t6, $t0, $t7, LSH
+ ld.d $t2, ap, 24
+ ADDSUB $t4, $t2, $t6
+ CARRY( $a6, $t4, $t2, $t6)
+ srli.d $t7, $t0, RSH
+ ADDSUB $t5, $t4, $a5
+ CARRY( $a5, $t5, $t4, $a5)
+ st.d $t5, rp, 24
+ or $a5, $a5, $a6
+ bnez i, L(top)
+
+L(end): add.d $a0, $a5, $t7
+ jr $r1
+EPILOGUE()
diff --git a/gmp-6.3.0/mpn/loongarch/64/aorsmul_1.asm b/gmp-6.3.0/mpn/loongarch/64/aorsmul_1.asm
new file mode 100644
index 0000000..49de51d
--- /dev/null
+++ b/gmp-6.3.0/mpn/loongarch/64/aorsmul_1.asm
@@ -0,0 +1,120 @@
+dnl Loongarch mpn_addmul_1 and mpn_submul_1
+
+dnl Contributed to the GNU project by Torbjorn Granlund.
+
+dnl Copyright 2023 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
+define(`rp', `$a0')
+define(`ap', `$a1')
+define(`n', `$a2')
+define(`b0', `$a3')
+
+define(`cy', `$a4')
+define(`i', `$a5')
+
+ifdef(`OPERATION_addmul_1',`
+ define(`ADDSUB', `add.d')
+ define(`CMPCY', `sltu $1, $2, $3')
+ define(`func', `mpn_addmul_1')
+')
+ifdef(`OPERATION_submul_1',`
+ define(`ADDSUB', `sub.d')
+ define(`CMPCY', `sltu $1, $3, $2')
+ define(`func', `mpn_submul_1')
+')
+
+MULFUNC_PROLOGUE(mpn_addmul_1 mpn_addmul_1c mpn_submul_1)
+
+define(`BLOCK', `
+ mul.d $t1, $t2, b0
+ mulh.du $t0, $t2, b0
+ ld.d $t2, ap, $1
+ ADDSUB $t5, $t3, $t1
+ CMPCY( $t4, $t5, $t3)
+ ld.d $t3, rp, $1
+ ADDSUB $t6, $t5, cy
+ add.d $t4, $t4, $t0
+ CMPCY( $t5, $t6, $t5)
+ st.d $t6, rp, eval($1-8)
+ add.d cy, $t4, $t5')
+
+ASM_START()
+
+ifdef(`OPERATION_addmul_1', `
+PROLOGUE(mpn_addmul_1c)
+ srli.d i, n, 2
+ b L(ent)
+EPILOGUE()
+')
+
+PROLOGUE(func)
+ srli.d i, n, 2
+ or cy, $r0, $r0
+L(ent): ld.d $t2, ap, 0
+ ld.d $t3, rp, 0
+
+ andi $t0, n, 1
+ andi $t1, n, 2
+ bnez $t0, L(bx1)
+L(bx0): beqz $t1, L(b0)
+L(b10): addi.d ap, ap, -16
+ addi.d rp, rp, -16
+ b L(b2)
+L(bx1): beqz $t1, L(b01)
+L(b11): addi.d ap, ap, -8
+ addi.d rp, rp, -8
+ b L(b3)
+L(b01): addi.d ap, ap, 8
+ addi.d rp, rp, 8
+ beqz i, L(end)
+
+L(top):
+L(b1): BLOCK(0)
+L(b0): BLOCK(8)
+ addi.d i, i, -1
+L(b3): BLOCK(16)
+L(b2): BLOCK(24)
+ addi.d ap, ap, 32
+ addi.d rp, rp, 32
+ bnez i, L(top)
+
+L(end): mul.d $t1, $t2, b0
+ mulh.du $t0, $t2, b0
+ ADDSUB $t5, $t3, $t1
+ CMPCY( $t4, $t5, $t3)
+ ADDSUB $t6, $t5, cy
+ add.d $t4, $t4, $t0
+ CMPCY( $t5, $t6, $t5)
+ st.d $t6, rp, -8
+ add.d $a0, $t4, $t5
+ jr $r1
+EPILOGUE()
diff --git a/gmp-6.3.0/mpn/loongarch/64/cnd_aors_n.asm b/gmp-6.3.0/mpn/loongarch/64/cnd_aors_n.asm
new file mode 100644
index 0000000..deff3d3
--- /dev/null
+++ b/gmp-6.3.0/mpn/loongarch/64/cnd_aors_n.asm
@@ -0,0 +1,99 @@
+dnl Loongarch mpn_cnd_add_n and mpn_cnd_sub_n.
+
+dnl Contributed to the GNU project by Torbjorn Granlund.
+
+dnl Copyright 2016, 2023 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
+define(`cnd', `$a0')
+define(`rp', `$a1')
+define(`up', `$a2')
+define(`vp', `$a3')
+define(`n', `$a4')
+
+define(`mask', `$t5')
+
+ifdef(`OPERATION_cnd_add_n',`
+ define(`ADDSUB', `add.d')
+ define(`CMPCY', `sltu $1, $2, $3')
+ define(`func', `mpn_cnd_add_n')
+')
+ifdef(`OPERATION_cnd_sub_n',`
+ define(`ADDSUB', `sub.d')
+ define(`CMPCY', `sltu $1, $3, $4')
+ define(`func', `mpn_cnd_sub_n')
+')
+
+MULFUNC_PROLOGUE(mpn_cnd_add_n mpn_cnd_sub_n)
+
+ASM_START()
+PROLOGUE(func)
+ move $t6, $zero
+
+ sltui mask, cnd, 1
+ addi.d mask, mask, -1
+
+ andi $t0, n, 1
+ beqz $t0, L(top)
+ addi.d up, up, 8
+ addi.d vp, vp, -8
+ addi.d rp, rp, -8
+ addi.d n, n, -1
+ b L(mid)
+
+L(top): ld.d $a7, vp, 0
+ ld.d $a5, up, 0
+ addi.d n, n, -2 C bookkeeping
+ addi.d up, up, 16 C bookkeeping
+ and $a7, $a7, mask
+ ADDSUB $t0, $a5, $a7
+ CMPCY( $t2, $t0, $a5, $a7)
+ ADDSUB $t4, $t0, $t6 C cycle 3, 9, ...
+ CMPCY( $t3, $t4, $t0, $t6) C cycle 4, 10, ...
+ st.d $t4, rp, 0
+ add.d $t6, $t2, $t3 C cycle 5, 11, ...
+L(mid): ld.d $a7, vp, 8
+ ld.d $a5, up, -8
+ addi.d vp, vp, 16 C bookkeeping
+ addi.d rp, rp, 16 C bookkeeping
+ and $a7, $a7, mask
+ ADDSUB $t1, $a5, $a7
+ CMPCY( $t2, $t1, $a5, $a7)
+ ADDSUB $t4, $t1, $t6 C cycle 0, 6, ...
+ CMPCY( $t3, $t4, $t1, $t6) C cycle 1, 7, ...
+ st.d $t4, rp, -8
+ add.d $t6, $t2, $t3 C cycle 2, 8, ...
+ bnez n, L(top)
+
+L(end): move $a0, $t6
+ jr $r1
+EPILOGUE()
+ASM_END()
diff --git a/gmp-6.3.0/mpn/loongarch/64/copyd.asm b/gmp-6.3.0/mpn/loongarch/64/copyd.asm
new file mode 100644
index 0000000..1d10b28
--- /dev/null
+++ b/gmp-6.3.0/mpn/loongarch/64/copyd.asm
@@ -0,0 +1,75 @@
+dnl Loongarch mpn_copyd
+
+dnl Contributed to the GNU project by Torbjorn Granlund.
+
+dnl Copyright 2023 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
+define(`rp', `$a0')
+define(`ap', `$a1')
+define(`n', `$a2')
+
+define(`i', `$a3')
+
+ASM_START()
+PROLOGUE(mpn_copyd)
+ alsl.d ap, n, ap, 3
+ alsl.d rp, n, rp, 3
+ srli.d i, n, 2
+ beqz i, L(end)
+
+L(top): addi.d i, i, -1
+ ld.d $t0, ap, -8
+ st.d $t0, rp, -8
+ ld.d $t1, ap, -16
+ st.d $t1, rp, -16
+ ld.d $t2, ap, -24
+ st.d $t2, rp, -24
+ ld.d $t3, ap, -32
+ st.d $t3, rp, -32
+ addi.d ap, ap, -32
+ addi.d rp, rp, -32
+ bnez i, L(top)
+
+L(end): andi $t1, n, 2
+ beqz $t1, L(b0x)
+ ld.d $t0, ap, -8
+ st.d $t0, rp, -8
+ ld.d $t1, ap, -16
+ st.d $t1, rp, -16
+ addi.d ap, ap, -16
+ addi.d rp, rp, -16
+L(b0x): andi $t0, n, 1
+ beqz $t0, L(bx0)
+ ld.d $t0, ap, -8
+ st.d $t0, rp, -8
+L(bx0): jr $r1
+EPILOGUE()
diff --git a/gmp-6.3.0/mpn/loongarch/64/copyi.asm b/gmp-6.3.0/mpn/loongarch/64/copyi.asm
new file mode 100644
index 0000000..a52401c
--- /dev/null
+++ b/gmp-6.3.0/mpn/loongarch/64/copyi.asm
@@ -0,0 +1,73 @@
+dnl Loongarch mpn_copyi
+
+dnl Contributed to the GNU project by Torbjorn Granlund.
+
+dnl Copyright 2023 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
+define(`rp', `$a0')
+define(`ap', `$a1')
+define(`n', `$a2')
+
+define(`i', `$a3')
+
+ASM_START()
+PROLOGUE(mpn_copyi)
+ srli.d i, n, 2
+ beqz i, L(end)
+
+L(top): addi.d i, i, -1
+ ld.d $t0, ap, 0
+ st.d $t0, rp, 0
+ ld.d $t1, ap, 8
+ st.d $t1, rp, 8
+ ld.d $t2, ap, 16
+ st.d $t2, rp, 16
+ ld.d $t3, ap, 24
+ st.d $t3, rp, 24
+ addi.d ap, ap, 32
+ addi.d rp, rp, 32
+ bnez i, L(top)
+
+L(end): andi $t1, n, 2
+ beqz $t1, L(b0x)
+ ld.d $t0, ap, 0
+ st.d $t0, rp, 0
+ ld.d $t1, ap, 8
+ st.d $t1, rp, 8
+ addi.d ap, ap, 16
+ addi.d rp, rp, 16
+L(b0x): andi $t0, n, 1
+ beqz $t0, L(bx0)
+ ld.d $t0, ap, 0
+ st.d $t0, rp, 0
+L(bx0): jr $r1
+EPILOGUE()
diff --git a/gmp-6.3.0/mpn/loongarch/64/lshift.asm b/gmp-6.3.0/mpn/loongarch/64/lshift.asm
new file mode 100644
index 0000000..71eef3b
--- /dev/null
+++ b/gmp-6.3.0/mpn/loongarch/64/lshift.asm
@@ -0,0 +1,120 @@
+dnl Loongarch mpn_lshift
+
+dnl Contributed to the GNU project by Torbjorn Granlund.
+
+dnl Copyright 2023 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
+define(`rp_arg',`$a0')
+define(`ap', `$a1')
+define(`n', `$a2')
+define(`cnt', `$a3')
+
+define(`rp', `$a4')
+define(`tnc', `$t8')
+define(`i', `$a7')
+
+ASM_START()
+PROLOGUE(mpn_lshift)
+ alsl.d ap, n, ap, 3
+ alsl.d rp, n, rp_arg, 3
+ sub.d tnc, $zero, cnt
+ srli.d i, n, 2
+
+ ld.d $t0, ap, -8
+ srl.d $a0, $t0, tnc
+
+ andi $t6, n, 1
+ andi $t7, n, 2
+ bnez $t6, L(bx1)
+
+ sll.d $t3, $t0, cnt
+ ld.d $t0, ap, -16
+ addi.d i, i, -1
+ bnez $t7, L(b10)
+ addi.d rp, rp, 16
+ b L(b0)
+L(b10): addi.d ap, ap, -16
+ bge i, $zero, L(b2)
+L(eq2): srl.d $t4, $t0, tnc
+ sll.d $t2, $t0, cnt
+ or $t4, $t3, $t4
+ st.d $t4, rp, -8
+ st.d $t2, rp, -16
+ jr $r1
+
+L(bx1): sll.d $t2, $t0, cnt
+ bnez $t7, L(b11)
+ bnez i, L(gt1)
+ st.d $t2, rp, -8
+ jr $r1
+L(gt1): ld.d $t0, ap, -16
+ addi.d ap, ap, -8
+ addi.d rp, rp, 8
+ addi.d i, i, -1
+ b L(b1)
+L(b11): ld.d $t0, ap, -16
+ addi.d ap, ap, 8
+ addi.d rp, rp, 24
+ b L(b3)
+
+L(top): addi.d ap, ap, -32
+ addi.d rp, rp, -32
+ addi.d i, i, -1
+L(b2): srl.d $t4, $t0, tnc
+ sll.d $t2, $t0, cnt
+ ld.d $t0, ap, -8
+ or $t4, $t3, $t4
+ st.d $t4, rp, -8
+L(b1): srl.d $t4, $t0, tnc
+ sll.d $t3, $t0, cnt
+ ld.d $t0, ap, -16
+ or $t4, $t2, $t4
+ st.d $t4, rp, -16
+L(b0): srl.d $t4, $t0, tnc
+ sll.d $t2, $t0, cnt
+ ld.d $t0, ap, -24
+ or $t4, $t3, $t4
+ st.d $t4, rp, -24
+L(b3): srl.d $t4, $t0, tnc
+ sll.d $t3, $t0, cnt
+ ld.d $t0, ap, -32
+ or $t4, $t2, $t4
+ st.d $t4, rp, -32
+ bnez i, L(top)
+
+L(end): srl.d $t4, $t0, tnc
+ sll.d $t2, $t0, cnt
+ or $t4, $t3, $t4
+ st.d $t4, rp, -40
+ st.d $t2, rp, -48
+ jr $r1
+EPILOGUE()
diff --git a/gmp-6.3.0/mpn/loongarch/64/mul_1.asm b/gmp-6.3.0/mpn/loongarch/64/mul_1.asm
new file mode 100644
index 0000000..8f84709
--- /dev/null
+++ b/gmp-6.3.0/mpn/loongarch/64/mul_1.asm
@@ -0,0 +1,97 @@
+dnl Loongarch mpn_mul_1
+
+dnl Contributed to the GNU project by Torbjorn Granlund.
+
+dnl Copyright 2023 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
+define(`rp', `$a0')
+define(`ap', `$a1')
+define(`n', `$a2')
+define(`b0', `$a3')
+
+define(`cy', `$a4')
+define(`i', `$a5')
+
+define(`BLOCK', `
+ mul.d $t1, $t2, b0
+ mulh.du $t0, $t2, b0
+ ld.d $t2, ap, $1
+ add.d $t6, $t1, cy
+ sltu $t5, $t6, $t1
+ st.d $t6, rp, eval($1-8)
+ add.d cy, $t0, $t5')
+
+ASM_START()
+
+PROLOGUE(mpn_mul_1c)
+ srli.d i, n, 2
+ b L(ent)
+EPILOGUE()
+
+PROLOGUE(mpn_mul_1)
+ srli.d i, n, 2
+ or cy, $r0, $r0
+L(ent): ld.d $t2, ap, 0
+
+ andi $t0, n, 1
+ andi $t1, n, 2
+ bnez $t0, L(bx1)
+L(bx0): beqz $t1, L(b0)
+L(b10): addi.d ap, ap, -16
+ addi.d rp, rp, -16
+ b L(b2)
+L(bx1): beqz $t1, L(b01)
+L(b11): addi.d ap, ap, -8
+ addi.d rp, rp, -8
+ b L(b3)
+L(b01): addi.d ap, ap, 8
+ addi.d rp, rp, 8
+ beqz i, L(end)
+
+L(top):
+L(b1): BLOCK(0)
+L(b0): BLOCK(8)
+ addi.d i, i, -1
+L(b3): BLOCK(16)
+L(b2): BLOCK(24)
+ addi.d ap, ap, 32
+ addi.d rp, rp, 32
+ bnez i, L(top)
+
+L(end): mul.d $t1, $t2, b0
+ mulh.du $t0, $t2, b0
+ add.d $t6, $t1, cy
+ sltu $t5, $t6, $t1
+ st.d $t6, rp, -8
+ add.d $a0, $t0, $t5
+ jr $r1
+EPILOGUE()
diff --git a/gmp-6.3.0/mpn/loongarch/64/rshift.asm b/gmp-6.3.0/mpn/loongarch/64/rshift.asm
new file mode 100644
index 0000000..a183576
--- /dev/null
+++ b/gmp-6.3.0/mpn/loongarch/64/rshift.asm
@@ -0,0 +1,119 @@
+dnl Loongarch mpn_rshift
+
+dnl Contributed to the GNU project by Torbjorn Granlund.
+
+dnl Copyright 2023 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
+define(`rp_arg',`$a0')
+define(`ap', `$a1')
+define(`n', `$a2')
+define(`cnt', `$a3')
+
+define(`rp', `$a4')
+define(`tnc', `$t8')
+define(`i', `$a7')
+
+ASM_START()
+PROLOGUE(mpn_rshift)
+ move rp, rp_arg
+ sub.d tnc, $zero, cnt
+ srli.d i, n, 2
+
+ ld.d $t0, ap, 0
+ sll.d $a0, $t0, tnc
+
+ andi $t6, n, 1
+ andi $t7, n, 2
+ bnez $t6, L(bx1)
+
+ srl.d $t3, $t0, cnt
+ ld.d $t0, ap, 8
+ addi.d i, i, -1
+ bnez $t7, L(b10)
+ addi.d rp, rp, -16
+ b L(b0)
+L(b10): addi.d ap, ap, 16
+ bge i, $zero, L(b2)
+L(eq2): sll.d $t4, $t0, tnc
+ srl.d $t2, $t0, cnt
+ or $t4, $t3, $t4
+ st.d $t4, rp, 0
+ st.d $t2, rp, 8
+ jr $r1
+
+L(bx1): srl.d $t2, $t0, cnt
+ bnez $t7, L(b11)
+ bnez i, L(gt1)
+ st.d $t2, rp, 0
+ jr $r1
+L(gt1): ld.d $t0, ap, 8
+ addi.d ap, ap, 8
+ addi.d rp, rp, -8
+ addi.d i, i, -1
+ b L(b1)
+L(b11): ld.d $t0, ap, 8
+ addi.d ap, ap, -8
+ addi.d rp, rp, -24
+ b L(b3)
+
+L(top): addi.d ap, ap, 32
+ addi.d rp, rp, 32
+ addi.d i, i, -1
+L(b2): sll.d $t4, $t0, tnc
+ srl.d $t2, $t0, cnt
+ ld.d $t0, ap, 0
+ or $t4, $t3, $t4
+ st.d $t4, rp, 0
+L(b1): sll.d $t4, $t0, tnc
+ srl.d $t3, $t0, cnt
+ ld.d $t0, ap, 8
+ or $t4, $t2, $t4
+ st.d $t4, rp, 8
+L(b0): sll.d $t4, $t0, tnc
+ srl.d $t2, $t0, cnt
+ ld.d $t0, ap, 16
+ or $t4, $t3, $t4
+ st.d $t4, rp, 16
+L(b3): sll.d $t4, $t0, tnc
+ srl.d $t3, $t0, cnt
+ ld.d $t0, ap, 24
+ or $t4, $t2, $t4
+ st.d $t4, rp, 24
+ bnez i, L(top)
+
+L(end): sll.d $t4, $t0, tnc
+ srl.d $t2, $t0, cnt
+ or $t4, $t3, $t4
+ st.d $t4, rp, 32
+ st.d $t2, rp, 40
+ jr $r1
+EPILOGUE()
diff --git a/gmp-6.3.0/mpn/loongarch/64/sub_n.asm b/gmp-6.3.0/mpn/loongarch/64/sub_n.asm
new file mode 100644
index 0000000..50821d9
--- /dev/null
+++ b/gmp-6.3.0/mpn/loongarch/64/sub_n.asm
@@ -0,0 +1,106 @@
+dnl Loongarch mpn_sub_n
+
+dnl Contributed to the GNU project by Torbjorn Granlund.
+
+dnl Copyright 2023 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
+define(`rp', `$a0')
+define(`ap', `$a1')
+define(`bp', `$a2')
+define(`n', `$a3')
+
+define(`i', `$a7')
+
+ASM_START()
+PROLOGUE(mpn_sub_n)
+ srli.d i, n, 2
+ move $t8, $zero
+
+ andi $t0, n, 1
+ andi $t1, n, 2
+ bnez $t0, L(bx1)
+L(bx0): beqz $t1, L(b0)
+L(b10): addi.d bp, bp, -16
+ addi.d ap, ap, -16
+ addi.d rp, rp, -16
+ b L(b2)
+L(bx1): bnez $t1, L(b11)
+L(b01): addi.d bp, bp, -24
+ addi.d ap, ap, -24
+ addi.d rp, rp, -24
+ b L(b1)
+L(b11): addi.d bp, bp, -8
+ addi.d ap, ap, -8
+ addi.d rp, rp, -8
+ b L(b3)
+
+L(top): addi.d bp, bp, 32
+ addi.d ap, ap, 32
+ addi.d rp, rp, 32
+L(b0): addi.d i, i, -1
+ ld.d $t4, bp, 0
+ ld.d $t0, ap, 0
+ sltu $a4, $t0, $t4
+ sub.d $t0, $t0, $t4
+ sltu $a5, $t0, $t8 C 0
+ sub.d $t0, $t0, $t8 C 0
+ or $t8, $a4, $a5 C 1
+ st.d $t0, rp, 0
+L(b3): ld.d $t5, bp, 8
+ ld.d $t1, ap, 8
+ sltu $a4, $t1, $t5
+ sub.d $t1, $t1, $t5
+ sltu $a5, $t1, $t8 C 2
+ sub.d $t1, $t1, $t8 C 2
+ or $t8, $a4, $a5 C 3
+ st.d $t1, rp, 8
+L(b2): ld.d $t4, bp, 16
+ ld.d $t0, ap, 16
+ sltu $a4, $t0, $t4
+ sub.d $t0, $t0, $t4
+ sltu $a5, $t0, $t8 C 4
+ sub.d $t0, $t0, $t8 C 4
+ or $t8, $a4, $a5 C 5
+ st.d $t0, rp, 16
+L(b1): ld.d $t5, bp, 24
+ ld.d $t1, ap, 24
+ sltu $a4, $t1, $t5
+ sub.d $t1, $t1, $t5
+ sltu $a5, $t1, $t8 C 6
+ sub.d $t1, $t1, $t8 C 6
+ or $t8, $a4, $a5 C 7
+ st.d $t1, rp, 24
+ bnez i, L(top)
+
+ move $a0, $t8
+ jr $r1
+EPILOGUE()