1dnl PowerPC-32 mpn_add_n and mpn_sub_n. 2 3dnl Copyright 2002, 2005, 2007 Free Software Foundation, Inc. 4 5dnl This file is part of the GNU MP Library. 6 7dnl The GNU MP Library is free software; you can redistribute it and/or modify 8dnl it under the terms of the GNU Lesser General Public License as published 9dnl by the Free Software Foundation; either version 3 of the License, or (at 10dnl your option) any later version. 11 12dnl The GNU MP Library is distributed in the hope that it will be useful, but 13dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15dnl License for more details. 16 17dnl You should have received a copy of the GNU Lesser General Public License 18dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. 19 20include(`../config.m4') 21 22C cycles/limb 23C 603e: ? 24C 604e: ? old: 3.25 25C 75x (G3): ? old: 3.5 26C 7400,7410 (G4): 3.25 27C 744x,745x (G4+): 4 28C POWER3/PPC630 2 29C POWER4/PPC970 2.4 30C POWER5 2.75 31C POWER6 40-140 32C POWER7 3 33 34C INPUT PARAMETERS 35define(`rp', `r3') 36define(`up', `r4') 37define(`vp', `r5') 38define(`n', `r6') 39define(`cy', `r7') 40 41ifdef(`OPERATION_add_n', ` 42 define(ADCSBC, adde) 43 define(func, mpn_add_n) 44 define(func_nc, mpn_add_nc) 45 define(IFADD, `$1') 46 define(IFSUB, `')') 47ifdef(`OPERATION_sub_n', ` 48 define(ADCSBC, subfe) 49 define(func, mpn_sub_n) 50 define(func_nc, mpn_sub_nc) 51 define(IFADD, `') 52 define(IFSUB, `$1')') 53 54MULFUNC_PROLOGUE(mpn_add_n mpn_add_nc mpn_sub_n mpn_sub_nc) 55 56ASM_START() 57 58PROLOGUE(func_nc) 59IFADD(` addic r0, cy, -1') C set carry from argument 60IFSUB(` subfic r0, cy, 0') C set carry from argument 61 b L(ent) 62EPILOGUE() 63 64PROLOGUE(func) 65IFADD(` addic r0, n, 0') C clear carry 66IFSUB(` addic r0, n, -1') C set carry 67L(ent): andi. r0, n, 3 68 addi r3, r3, -12 69 addi n, n, 1 70 cmpwi cr7, r0, 2 71 srwi r0, n, 2 72 sub r4, r4, r3 73 sub r5, r5, r3 74 mtctr r0 75 bne cr0, L(n00) 76 77 lwzx r7, r4, r3 C n = 4, 8, 12, ... 78 lwzx r8, r5, r3 79 addi r3, r3, 4 80 lwzx r9, r4, r3 81 ADCSBC r7, r8, r7 82 lwzx r10, r5, r3 83 addi r3, r3, 4 84 b L(00) 85 86L(n00): bge cr7, L(n01) 87 cmpwi cr0, r0, 0 C n = 1, 5, 9, 13, ... 88 lwzx r0, r4, r3 89 lwzx r6, r5, r3 90 addi r3, r3, 4 91 ADCSBC r0, r6, r0 92 ble L(ret) 93L(gt1): lwzx r7, r4, r3 94 lwzx r8, r5, r3 95 addi r3, r3, 4 96 b L(01) 97 98L(n10): 99 lwzx r9, r4, r3 C n = 3, 7, 11, 15, ... 100 lwzx r10, r5, r3 101 addi r3, r3, 4 102 lwzx r11, r4, r3 103 ADCSBC r9, r10, r9 104 lwzx r12, r5, r3 105 addi r3, r3, 4 106 b L(11) 107 108L(n01): bne cr7, L(n10) 109 cmpwi cr0, r0, 0 C n = 2, 6, 10, 14, ... 110 lwzx r11, r4, r3 111 lwzx r12, r5, r3 112 addi r3, r3, 4 113 lwzx r0, r4, r3 114 ADCSBC r11, r12, r11 115 lwzx r6, r5, r3 116 addi r3, r3, 4 117 ble cr0, L(end) 118 119 120L(lp): lwzx r7, r4, r3 121 ADCSBC r0, r6, r0 122 lwzx r8, r5, r3 123 stwu r11, 4(r3) 124L(01): lwzx r9, r4, r3 125 ADCSBC r7, r8, r7 126 lwzx r10, r5, r3 127 stwu r0, 4(r3) 128L(00): lwzx r11, r4, r3 129 ADCSBC r9, r10, r9 130 lwzx r12, r5, r3 131 stwu r7, 4(r3) 132L(11): lwzx r0, r4, r3 133 ADCSBC r11, r12, r11 134 lwzx r6, r5, r3 135 stwu r9, 4(r3) 136 bdnz L(lp) 137 138L(end): ADCSBC r0, r6, r0 139 stw r11, 4(r3) 140L(ret): stw r0, 8(r3) 141IFADD(` li r3, 0 ') 142IFADD(` addze r3, r3 ') 143IFSUB(` subfe r3, r0, r0') 144IFSUB(` neg r3, r3') 145 blr 146EPILOGUE() 147