[PATCH] Add MIPS r6 support
YunQiang Su
syq at debian.org
Mon Jun 3 04:59:48 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.
---
configure.ac | 17 ++++++++++
mpn/mips32/r6/addmul_1.asm | 70 ++++++++++++++++++++++++++++++++++++++++++
mpn/mips32/r6/mul_1.asm | 64 ++++++++++++++++++++++++++++++++++++++
mpn/mips32/r6/submul_1.asm | 69 +++++++++++++++++++++++++++++++++++++++++
mpn/mips32/r6/umul.asm | 44 ++++++++++++++++++++++++++
mpn/mips64/r6/addmul_1.asm | 70 ++++++++++++++++++++++++++++++++++++++++++
mpn/mips64/r6/mul_1.asm | 64 ++++++++++++++++++++++++++++++++++++++
mpn/mips64/r6/sqr_diagonal.asm | 59 +++++++++++++++++++++++++++++++++++
mpn/mips64/r6/submul_1.asm | 69 +++++++++++++++++++++++++++++++++++++++++
mpn/mips64/r6/umul.asm | 44 ++++++++++++++++++++++++++
10 files changed, 570 insertions(+)
create mode 100644 mpn/mips32/r6/addmul_1.asm
create mode 100644 mpn/mips32/r6/mul_1.asm
create mode 100644 mpn/mips32/r6/submul_1.asm
create mode 100644 mpn/mips32/r6/umul.asm
create mode 100644 mpn/mips64/r6/addmul_1.asm
create mode 100644 mpn/mips64/r6/mul_1.asm
create mode 100644 mpn/mips64/r6/sqr_diagonal.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 681254782..dfa55f065 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1006,10 +1006,22 @@ case $host in
# this suits both mips32 and mips64
GMP_INCLUDE_MPN(mips32/mips-defs.m4)
+ mips_isa_rev=0
+ case $host_cpu in
+ mipsisa64r6*)
+ mips_isa_rev=6
+ ;;
+ esac
+
case $host in
[mips64*-*-* | mipsisa64*-*-* | mips*-*-irix[6789]*])
abilist="n32 64 o32"
+ case $host in
+ *abi64)
+ abilist="64 n32 o32"
+ esac
+
cclist_n32="gcc cc"
gcc_n32_cflags_optlist="abi"
gcc_n32_cflags="$gcc_cflags"
@@ -1026,6 +1038,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 mips64"
+ path_64="mips64/r6 mips64"
+ fi
;;
esac
;;
diff --git a/mpn/mips32/r6/addmul_1.asm b/mpn/mips32/r6/addmul_1.asm
new file mode 100644
index 000000000..f4e258610
--- /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/mul_1.asm b/mpn/mips32/r6/mul_1.asm
new file mode 100644
index 000000000..efce09c2f
--- /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/submul_1.asm b/mpn/mips32/r6/submul_1.asm
new file mode 100644
index 000000000..7d8eda4de
--- /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)
+ 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
+ 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 000000000..c5345e73e
--- /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
+ sw $3,0($4)
+EPILOGUE(mpn_umul_ppmm)
diff --git a/mpn/mips64/r6/addmul_1.asm b/mpn/mips64/r6/addmul_1.asm
new file mode 100644
index 000000000..766996f60
--- /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/mul_1.asm b/mpn/mips64/r6/mul_1.asm
new file mode 100644
index 000000000..fc1e83d35
--- /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/sqr_diagonal.asm b/mpn/mips64/r6/sqr_diagonal.asm
new file mode 100644
index 000000000..66d4faf5d
--- /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/submul_1.asm b/mpn/mips64/r6/submul_1.asm
new file mode 100644
index 000000000..6e8e6ed62
--- /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 000000000..22c8e8c5d
--- /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