1/* PowerPC-32 addmul_1 -- Multiply a limb vector with a limb and add 2 * the result to a second limb vector. 3 * 4 * Copyright (C) 1995, 1998, 2002 Free Software Foundation, Inc. 5 * 6 * This file is part of Libgcrypt. 7 * 8 * Libgcrypt is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as 10 * published by the Free Software Foundation; either version 2.1 of 11 * the License, or (at your option) any later version. 12 * 13 * Libgcrypt is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 21 */ 22 23#include "sysdep.h" 24#include "asm-syntax.h" 25 26 27#ifndef USE_PPC_PATCHES 28 29/******************* 30 * mpi_limb_t 31 * _gcry_mpih_addmul_1( mpi_ptr_t res_ptr, (r3) 32 * mpi_ptr_t s1_ptr, (r4) 33 * mpi_size_t s1_size, (r5) 34 * mpi_limb_t s2_limb) (r6) 35 * 36 * This is a fairly straightforward implementation. The timing of the PC601 37 * is hard to understand, so I will wait to optimize this until I have some 38 * hardware to play with. 39 * 40 * The code trivially generalizes to 64 bit limbs for the PC620. 41 */ 42 43 44 .toc 45 .csect ._gcry_mpih_addmul_1[PR] 46 .align 2 47 .globl _gcry_mpih_addmul_1 48 .globl ._gcry_mpih_addmul_1 49 .csect _gcry_mpih_addmul_1[DS] 50_gcry_mpih_addmul_1: 51 .long ._gcry_mpih_addmul_1[PR], TOC[tc0], 0 52 .csect ._gcry_mpih_addmul_1[PR] 53._gcry_mpih_addmul_1: 54 mtctr 5 55 56 lwz 0,0(4) 57 mullw 7,0,6 58 mulhwu 10,0,6 59 lwz 9,0(3) 60 addc 8,7,9 61 addi 3,3,-4 62 bdz Lend 63 64Loop: lwzu 0,4(4) 65 stwu 8,4(3) 66 mullw 8,0,6 67 adde 7,8,10 68 mulhwu 10,0,6 69 lwz 9,4(3) 70 addze 10,10 71 addc 8,7,9 72 bdnz Loop 73 74Lend: stw 8,4(3) 75 addze 3,10 76 blr 77 78#else 79/* Multiply a limb vector by a single limb, for PowerPC. 80 Copyright (C) 1993, 1994, 1995, 1997 Free Software Foundation, Inc. 81 This file is part of the GNU C Library. 82 83 The GNU C Library is free software; you can redistribute it and/or 84 modify it under the terms of the GNU Library General Public License as 85 published by the Free Software Foundation; either version 2 of the 86 License, or (at your option) any later version. 87 88 The GNU C Library is distributed in the hope that it will be useful, 89 but WITHOUT ANY WARRANTY; without even the implied warranty of 90 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 91 Library General Public License for more details. 92 93 You should have received a copy of the GNU Library General Public 94 License along with the GNU C Library; see the file COPYING.LIB. If not, 95 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 96 Boston, MA 02111-1307, USA. */ 97 98 99/* mp_limb_t mpn_addmul_1 (mp_ptr res_ptr, mp_srcptr s1_ptr, 100 mp_size_t s1_size, mp_limb_t s2_limb) 101 Calculate res+s1*s2 and put result back in res; return carry. */ 102ENTRY(_gcry_mpih_addmul_1) 103 mtctr %r5 104 105 lwz %r0,0(%r4) 106 mullw %r7,%r0,%r6 107 mulhwu %r10,%r0,%r6 108 lwz %r9,0(%r3) 109 addc %r8,%r7,%r9 110 addi %r3,%r3,-4 /* adjust res_ptr */ 111 bdz 1f 112 1130: lwzu %r0,4(%r4) 114 stwu %r8,4(%r3) 115 mullw %r8,%r0,%r6 116 adde %r7,%r8,%r10 117 mulhwu %r10,%r0,%r6 118 lwz %r9,4(%r3) 119 addze %r10,%r10 120 addc %r8,%r7,%r9 121 bdnz 0b 122 1231: stw %r8,4(%r3) 124 addze %r3,%r10 125 blr 126END(_gcry_mpih_addmul_1) 127#endif 128