| 1 |
dnl RISC-V/64 mpn_add_n and mpn_sub_n. |
| 2 |
|
| 3 |
dnl Copyright 2016 Free Software Foundation, Inc. |
| 4 |
|
| 5 |
dnl This file is part of the GNU MP Library. |
| 6 |
dnl |
| 7 |
dnl The GNU MP Library is free software; you can redistribute it and/or modify |
| 8 |
dnl it under the terms of either: |
| 9 |
dnl |
| 10 |
dnl * the GNU Lesser General Public License as published by the Free |
| 11 |
dnl Software Foundation; either version 3 of the License, or (at your |
| 12 |
dnl option) any later version. |
| 13 |
dnl |
| 14 |
dnl or |
| 15 |
dnl |
| 16 |
dnl * the GNU General Public License as published by the Free Software |
| 17 |
dnl Foundation; either version 2 of the License, or (at your option) any |
| 18 |
dnl later version. |
| 19 |
dnl |
| 20 |
dnl or both in parallel, as here. |
| 21 |
dnl |
| 22 |
dnl The GNU MP Library is distributed in the hope that it will be useful, but |
| 23 |
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 24 |
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 25 |
dnl for more details. |
| 26 |
dnl |
| 27 |
dnl You should have received copies of the GNU General Public License and the |
| 28 |
dnl GNU Lesser General Public License along with the GNU MP Library. If not, |
| 29 |
dnl see https://www.gnu.org/licenses/. |
| 30 |
|
| 31 |
include(`../config.m4') |
| 32 |
|
| 33 |
C INPUT PARAMETERS |
| 34 |
define(`rp', `a0') |
| 35 |
define(`ap', `a1') |
| 36 |
define(`bp', `a2') |
| 37 |
define(`n', `a3') |
| 38 |
|
| 39 |
define(`i', `a6') |
| 40 |
|
| 41 |
ifdef(`OPERATION_add_n',` |
| 42 |
define(`ADDSUB', `add') |
| 43 |
define(`CMPCY', `sltu $1, $2, $3') |
| 44 |
define(`func', `mpn_add_n') |
| 45 |
') |
| 46 |
ifdef(`OPERATION_sub_n',` |
| 47 |
define(`ADDSUB', `sub') |
| 48 |
define(`CMPCY', `sltu $1, $3, $4') |
| 49 |
define(`func', `mpn_sub_n') |
| 50 |
') |
| 51 |
|
| 52 |
MULFUNC_PROLOGUE(mpn_add_n mpn_sub_n) |
| 53 |
|
| 54 |
ASM_START() |
| 55 |
PROLOGUE(func) |
| 56 |
li t6, 0 |
| 57 |
srli i, n, 2 |
| 58 |
|
| 59 |
ld a4, 0(ap) |
| 60 |
ld a5, 0(bp) |
| 61 |
|
| 62 |
andi t0, n, 1 |
| 63 |
andi t1, n, 2 |
| 64 |
bnez t0, L(bx1) |
| 65 |
L(bx0): bnez t1, L(b10) |
| 66 |
L(b00): addi rp, rp, -8 |
| 67 |
addi i, i, -1 |
| 68 |
j L(b0) |
| 69 |
L(b10): addi bp, bp, -16 |
| 70 |
addi ap, ap, -16 |
| 71 |
addi rp, rp, -24 |
| 72 |
j L(b2) |
| 73 |
L(bx1): bnez t1, L(b11) |
| 74 |
L(b01): beqz i, L(1) |
| 75 |
addi bp, bp, 8 |
| 76 |
addi ap, ap, 8 |
| 77 |
addi i, i, -1 |
| 78 |
j L(b1) |
| 79 |
L(1): ADDSUB t0, a4, a5 |
| 80 |
sd t0, 0(rp) |
| 81 |
CMPCY( a0, t0, a4, a5) |
| 82 |
ret |
| 83 |
L(b11): addi bp, bp, -8 |
| 84 |
addi ap, ap, -8 |
| 85 |
addi rp, rp, -16 |
| 86 |
j L(b3) |
| 87 |
|
| 88 |
ALIGN( 16) |
| 89 |
L(top): addi bp, bp, 32 |
| 90 |
addi ap, ap, 32 |
| 91 |
addi rp, rp, 32 |
| 92 |
addi i, i, -1 |
| 93 |
L(b1): ADDSUB t0, a4, a5 |
| 94 |
CMPCY( t2, t0, a4, a5) |
| 95 |
ld a4, 0(ap) |
| 96 |
ld a5, 0(bp) |
| 97 |
ADDSUB t4, t0, t6 |
| 98 |
CMPCY( t3, t4, t0, t6) |
| 99 |
sd t4, 0(rp) |
| 100 |
or t6, t2, t3 |
| 101 |
|
| 102 |
L(b0): ADDSUB t1, a4, a5 |
| 103 |
CMPCY( t2, t1, a4, a5) |
| 104 |
ld a4, 8(ap) |
| 105 |
ld a5, 8(bp) |
| 106 |
ADDSUB t4, t1, t6 |
| 107 |
CMPCY( t3, t4, t1, t6) |
| 108 |
sd t4, 8(rp) |
| 109 |
or t6, t2, t3 |
| 110 |
L(b3): ADDSUB t0, a4, a5 |
| 111 |
CMPCY( t2, t0, a4, a5) |
| 112 |
ld a4, 16(ap) |
| 113 |
ld a5, 16(bp) |
| 114 |
ADDSUB t4, t0, t6 |
| 115 |
CMPCY( t3, t4, t0, t6) |
| 116 |
sd t4, 16(rp) |
| 117 |
or t6, t2, t3 |
| 118 |
L(b2): ADDSUB t1, a4, a5 |
| 119 |
CMPCY( t2, t1, a4, a5) |
| 120 |
ld a4, 24(ap) |
| 121 |
ld a5, 24(bp) |
| 122 |
ADDSUB t4, t1, t6 |
| 123 |
CMPCY( t3, t4, t1, t6) |
| 124 |
sd t4, 24(rp) |
| 125 |
or t6, t2, t3 |
| 126 |
bne i, x0, L(top) |
| 127 |
|
| 128 |
L(end): ADDSUB t0, a4, a5 |
| 129 |
CMPCY( t2, t0, a4, a5) |
| 130 |
ADDSUB t4, t0, t6 |
| 131 |
CMPCY( t3, t4, t0, t6) |
| 132 |
sd t4, 32(rp) |
| 133 |
or a0, t2, t3 |
| 134 |
ret |
| 135 |
EPILOGUE() |