1 #ifdef IN_SANDY2X 2 3 /* 4 This file is the result of merging 5 amd64-51/fe25519_pack.c and amd64-51/fe25519_freeze.s. 6 */ 7 #include "fe51_namespace.h" 8 #include "consts_namespace.h" 9 .p2align 5 10 11 #ifdef ASM_HIDE_SYMBOL 12 ASM_HIDE_SYMBOL fe51_pack 13 ASM_HIDE_SYMBOL _fe51_pack 14 #endif 15 .globl fe51_pack 16 .globl _fe51_pack 17 #ifdef __ELF__ 18 .type fe51_pack, @function 19 .type _fe51_pack, @function 20 #endif 21 fe51_pack: 22 _fe51_pack: 23 24 mov %rsp,%r11 25 and $31,%r11 26 add $32,%r11 27 sub %r11,%rsp 28 movq %r11,0(%rsp) 29 movq %r12,8(%rsp) 30 movq 0(%rsi),%rdx 31 movq 8(%rsi),%rcx 32 movq 16(%rsi),%r8 33 movq 24(%rsi),%r9 34 movq 32(%rsi),%rsi 35 movq REDMASK51(%rip),%rax 36 lea -18(%rax),%r10 37 mov $3,%r11 38 39 .p2align 4 40 ._reduceloop: 41 mov %rdx,%r12 42 shr $51,%r12 43 and %rax,%rdx 44 add %r12,%rcx 45 mov %rcx,%r12 46 shr $51,%r12 47 and %rax,%rcx 48 add %r12,%r8 49 mov %r8,%r12 50 shr $51,%r12 51 and %rax,%r8 52 add %r12,%r9 53 mov %r9,%r12 54 shr $51,%r12 55 and %rax,%r9 56 add %r12,%rsi 57 mov %rsi,%r12 58 shr $51,%r12 59 and %rax,%rsi 60 imulq $19, %r12,%r12 61 add %r12,%rdx 62 sub $1,%r11 63 ja ._reduceloop 64 65 mov $1,%r12 66 cmp %r10,%rdx 67 cmovl %r11,%r12 68 cmp %rax,%rcx 69 cmovne %r11,%r12 70 cmp %rax,%r8 71 cmovne %r11,%r12 72 cmp %rax,%r9 73 cmovne %r11,%r12 74 cmp %rax,%rsi 75 cmovne %r11,%r12 76 neg %r12 77 and %r12,%rax 78 and %r12,%r10 79 sub %r10,%rdx 80 sub %rax,%rcx 81 sub %rax,%r8 82 sub %rax,%r9 83 sub %rax,%rsi 84 mov %rdx,%rax 85 and $0xFF,%eax 86 movb %al,0(%rdi) 87 mov %rdx,%rax 88 shr $8,%rax 89 and $0xFF,%eax 90 movb %al,1(%rdi) 91 mov %rdx,%rax 92 shr $16,%rax 93 and $0xFF,%eax 94 movb %al,2(%rdi) 95 mov %rdx,%rax 96 shr $24,%rax 97 and $0xFF,%eax 98 movb %al,3(%rdi) 99 mov %rdx,%rax 100 shr $32,%rax 101 and $0xFF,%eax 102 movb %al,4(%rdi) 103 mov %rdx,%rax 104 shr $40,%rax 105 and $0xFF,%eax 106 movb %al,5(%rdi) 107 mov %rdx,%rdx 108 shr $48,%rdx 109 mov %rcx,%rax 110 shl $3,%rax 111 and $0xF8,%eax 112 xor %rdx,%rax 113 movb %al,6(%rdi) 114 mov %rcx,%rdx 115 shr $5,%rdx 116 and $0xFF,%edx 117 movb %dl,7(%rdi) 118 mov %rcx,%rdx 119 shr $13,%rdx 120 and $0xFF,%edx 121 movb %dl,8(%rdi) 122 mov %rcx,%rdx 123 shr $21,%rdx 124 and $0xFF,%edx 125 movb %dl,9(%rdi) 126 mov %rcx,%rdx 127 shr $29,%rdx 128 and $0xFF,%edx 129 movb %dl,10(%rdi) 130 mov %rcx,%rdx 131 shr $37,%rdx 132 and $0xFF,%edx 133 movb %dl,11(%rdi) 134 mov %rcx,%rdx 135 shr $45,%rdx 136 mov %r8,%rcx 137 shl $6,%rcx 138 and $0xC0,%ecx 139 xor %rdx,%rcx 140 movb %cl,12(%rdi) 141 mov %r8,%rdx 142 shr $2,%rdx 143 and $0xFF,%edx 144 movb %dl,13(%rdi) 145 mov %r8,%rdx 146 shr $10,%rdx 147 and $0xFF,%edx 148 movb %dl,14(%rdi) 149 mov %r8,%rdx 150 shr $18,%rdx 151 and $0xFF,%edx 152 movb %dl,15(%rdi) 153 mov %r8,%rdx 154 shr $26,%rdx 155 and $0xFF,%edx 156 movb %dl,16(%rdi) 157 mov %r8,%rdx 158 shr $34,%rdx 159 and $0xFF,%edx 160 movb %dl,17(%rdi) 161 mov %r8,%rdx 162 shr $42,%rdx 163 movb %dl,18(%rdi) 164 mov %r8,%rdx 165 shr $50,%rdx 166 mov %r9,%rcx 167 shl $1,%rcx 168 and $0xFE,%ecx 169 xor %rdx,%rcx 170 movb %cl,19(%rdi) 171 mov %r9,%rdx 172 shr $7,%rdx 173 and $0xFF,%edx 174 movb %dl,20(%rdi) 175 mov %r9,%rdx 176 shr $15,%rdx 177 and $0xFF,%edx 178 movb %dl,21(%rdi) 179 mov %r9,%rdx 180 shr $23,%rdx 181 and $0xFF,%edx 182 movb %dl,22(%rdi) 183 mov %r9,%rdx 184 shr $31,%rdx 185 and $0xFF,%edx 186 movb %dl,23(%rdi) 187 mov %r9,%rdx 188 shr $39,%rdx 189 and $0xFF,%edx 190 movb %dl,24(%rdi) 191 mov %r9,%rdx 192 shr $47,%rdx 193 mov %rsi,%rcx 194 shl $4,%rcx 195 and $0xF0,%ecx 196 xor %rdx,%rcx 197 movb %cl,25(%rdi) 198 mov %rsi,%rdx 199 shr $4,%rdx 200 and $0xFF,%edx 201 movb %dl,26(%rdi) 202 mov %rsi,%rdx 203 shr $12,%rdx 204 and $0xFF,%edx 205 movb %dl,27(%rdi) 206 mov %rsi,%rdx 207 shr $20,%rdx 208 and $0xFF,%edx 209 movb %dl,28(%rdi) 210 mov %rsi,%rdx 211 shr $28,%rdx 212 and $0xFF,%edx 213 movb %dl,29(%rdi) 214 mov %rsi,%rdx 215 shr $36,%rdx 216 and $0xFF,%edx 217 movb %dl,30(%rdi) 218 mov %rsi,%rsi 219 shr $44,%rsi 220 movb %sil,31(%rdi) 221 movq 0(%rsp),%r11 222 movq 8(%rsp),%r12 223 add %r11,%rsp 224 ret 225 226 #endif 227