| 1 |
dnl Loongarch mpn_cnd_add_n and mpn_cnd_sub_n. |
| 2 |
|
| 3 |
dnl Contributed to the GNU project by Torbjorn Granlund. |
| 4 |
|
| 5 |
dnl Copyright 2016, 2023 Free Software Foundation, Inc. |
| 6 |
|
| 7 |
dnl This file is part of the GNU MP Library. |
| 8 |
dnl |
| 9 |
dnl The GNU MP Library is free software; you can redistribute it and/or modify |
| 10 |
dnl it under the terms of either: |
| 11 |
dnl |
| 12 |
dnl * the GNU Lesser General Public License as published by the Free |
| 13 |
dnl Software Foundation; either version 3 of the License, or (at your |
| 14 |
dnl option) any later version. |
| 15 |
dnl |
| 16 |
dnl or |
| 17 |
dnl |
| 18 |
dnl * the GNU General Public License as published by the Free Software |
| 19 |
dnl Foundation; either version 2 of the License, or (at your option) any |
| 20 |
dnl later version. |
| 21 |
dnl |
| 22 |
dnl or both in parallel, as here. |
| 23 |
dnl |
| 24 |
dnl The GNU MP Library is distributed in the hope that it will be useful, but |
| 25 |
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 26 |
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 27 |
dnl for more details. |
| 28 |
dnl |
| 29 |
dnl You should have received copies of the GNU General Public License and the |
| 30 |
dnl GNU Lesser General Public License along with the GNU MP Library. If not, |
| 31 |
dnl see https://www.gnu.org/licenses/. |
| 32 |
|
| 33 |
include(`../config.m4') |
| 34 |
|
| 35 |
C INPUT PARAMETERS |
| 36 |
define(`cnd', `$a0') |
| 37 |
define(`rp', `$a1') |
| 38 |
define(`up', `$a2') |
| 39 |
define(`vp', `$a3') |
| 40 |
define(`n', `$a4') |
| 41 |
|
| 42 |
define(`mask', `$t5') |
| 43 |
|
| 44 |
ifdef(`OPERATION_cnd_add_n',` |
| 45 |
define(`ADDSUB', `add.d') |
| 46 |
define(`CMPCY', `sltu $1, $2, $3') |
| 47 |
define(`func', `mpn_cnd_add_n') |
| 48 |
') |
| 49 |
ifdef(`OPERATION_cnd_sub_n',` |
| 50 |
define(`ADDSUB', `sub.d') |
| 51 |
define(`CMPCY', `sltu $1, $3, $4') |
| 52 |
define(`func', `mpn_cnd_sub_n') |
| 53 |
') |
| 54 |
|
| 55 |
MULFUNC_PROLOGUE(mpn_cnd_add_n mpn_cnd_sub_n) |
| 56 |
|
| 57 |
ASM_START() |
| 58 |
PROLOGUE(func) |
| 59 |
move $t6, $zero |
| 60 |
|
| 61 |
sltui mask, cnd, 1 |
| 62 |
addi.d mask, mask, -1 |
| 63 |
|
| 64 |
andi $t0, n, 1 |
| 65 |
beqz $t0, L(top) |
| 66 |
addi.d up, up, 8 |
| 67 |
addi.d vp, vp, -8 |
| 68 |
addi.d rp, rp, -8 |
| 69 |
addi.d n, n, -1 |
| 70 |
b L(mid) |
| 71 |
|
| 72 |
L(top): ld.d $a7, vp, 0 |
| 73 |
ld.d $a5, up, 0 |
| 74 |
addi.d n, n, -2 C bookkeeping |
| 75 |
addi.d up, up, 16 C bookkeeping |
| 76 |
and $a7, $a7, mask |
| 77 |
ADDSUB $t0, $a5, $a7 |
| 78 |
CMPCY( $t2, $t0, $a5, $a7) |
| 79 |
ADDSUB $t4, $t0, $t6 C cycle 3, 9, ... |
| 80 |
CMPCY( $t3, $t4, $t0, $t6) C cycle 4, 10, ... |
| 81 |
st.d $t4, rp, 0 |
| 82 |
add.d $t6, $t2, $t3 C cycle 5, 11, ... |
| 83 |
L(mid): ld.d $a7, vp, 8 |
| 84 |
ld.d $a5, up, -8 |
| 85 |
addi.d vp, vp, 16 C bookkeeping |
| 86 |
addi.d rp, rp, 16 C bookkeeping |
| 87 |
and $a7, $a7, mask |
| 88 |
ADDSUB $t1, $a5, $a7 |
| 89 |
CMPCY( $t2, $t1, $a5, $a7) |
| 90 |
ADDSUB $t4, $t1, $t6 C cycle 0, 6, ... |
| 91 |
CMPCY( $t3, $t4, $t1, $t6) C cycle 1, 7, ... |
| 92 |
st.d $t4, rp, -8 |
| 93 |
add.d $t6, $t2, $t3 C cycle 2, 8, ... |
| 94 |
bnez n, L(top) |
| 95 |
|
| 96 |
L(end): move $a0, $t6 |
| 97 |
jr $r1 |
| 98 |
EPILOGUE() |
| 99 |
ASM_END() |