1/* alpha rshift 2 * Copyright (C) 1994, 1995, 1998, 1999, 3 * 2000, 2001, 2002 Free Software Foundation, Inc. 4 * 5 * This file is part of Libgcrypt. 6 * 7 * Libgcrypt is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation; either version 2.1 of 10 * the License, or (at your option) any later version. 11 * 12 * Libgcrypt is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 20 * 21 * Note: This code is heavily based on the GNU MP Library. 22 * Actually it's the same code with only minor changes in the 23 * way the data is stored; this is to support the abstraction 24 * of an optional secure memory allocation which may be used 25 * to avoid revealing of sensitive data due to paging etc. 26 */ 27 28 29 30 31/******************* 32 * mpi_limb_t 33 * _gcry_mpih_rshift( mpi_ptr_t wp, (r16) 34 * mpi_ptr_t up, (r17) 35 * mpi_size_t usize, (r18) 36 * unsigned cnt) (r19) 37 * 38 * This code runs at 4.8 cycles/limb on the 21064. With infinite unrolling, 39 * it would take 4 cycles/limb. It should be possible to get down to 3 40 * cycles/limb since both ldq and stq can be paired with the other used 41 * instructions. But there are many restrictions in the 21064 pipeline that 42 * makes it hard, if not impossible, to get down to 3 cycles/limb: 43 * 44 * 1. ldq has a 3 cycle delay, srl and sll have a 2 cycle delay. 45 * 2. Only aligned instruction pairs can be paired. 46 * 3. The store buffer or silo might not be able to deal with the bandwidth. 47 */ 48 49 .set noreorder 50 .set noat 51.text 52 .align 3 53 .globl _gcry_mpih_rshift 54 .ent _gcry_mpih_rshift 55_gcry_mpih_rshift: 56 .frame $30,0,$26,0 57 58 ldq $4,0($17) # load first limb 59 addq $17,8,$17 60 subq $31,$19,$7 61 subq $18,1,$18 62 and $18,4-1,$20 # number of limbs in first loop 63 sll $4,$7,$0 # compute function result 64 65 beq $20,.R0 66 subq $18,$20,$18 67 68 .align 3 69.Roop0: 70 ldq $3,0($17) 71 addq $16,8,$16 72 addq $17,8,$17 73 subq $20,1,$20 74 srl $4,$19,$5 75 sll $3,$7,$6 76 bis $3,$3,$4 77 bis $5,$6,$8 78 stq $8,-8($16) 79 bne $20,.Roop0 80 81.R0: beq $18,.Rend 82 83 .align 3 84.Roop: ldq $3,0($17) 85 addq $16,32,$16 86 subq $18,4,$18 87 srl $4,$19,$5 88 sll $3,$7,$6 89 90 ldq $4,8($17) 91 srl $3,$19,$1 92 bis $5,$6,$8 93 stq $8,-32($16) 94 sll $4,$7,$2 95 96 ldq $3,16($17) 97 srl $4,$19,$5 98 bis $1,$2,$8 99 stq $8,-24($16) 100 sll $3,$7,$6 101 102 ldq $4,24($17) 103 srl $3,$19,$1 104 bis $5,$6,$8 105 stq $8,-16($16) 106 sll $4,$7,$2 107 108 addq $17,32,$17 109 bis $1,$2,$8 110 stq $8,-8($16) 111 112 bgt $18,.Roop 113 114.Rend: srl $4,$19,$8 115 stq $8,0($16) 116 ret $31,($26),1 117 .end _gcry_mpih_rshift 118 119