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