diff options
author | jsing <> | 2023-02-16 10:51:58 +0000 |
---|---|---|
committer | jsing <> | 2023-02-16 10:51:58 +0000 |
commit | 20d77e168d6700000dda87019218f2b9f8c395ca (patch) | |
tree | 0bc2b51519057f8eaf4d97f8d03156c7e2cba9b4 | |
parent | d3699a732b869a27d4edac40e74816362ea9be8a (diff) | |
download | openbsd-20d77e168d6700000dda87019218f2b9f8c395ca.tar.gz openbsd-20d77e168d6700000dda87019218f2b9f8c395ca.tar.bz2 openbsd-20d77e168d6700000dda87019218f2b9f8c395ca.zip |
Bring in word_clz.S from s2n-bignum for amd64.
-rw-r--r-- | src/lib/libcrypto/bn/arch/amd64/word_clz.S | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/lib/libcrypto/bn/arch/amd64/word_clz.S b/src/lib/libcrypto/bn/arch/amd64/word_clz.S new file mode 100644 index 0000000000..6388b75d53 --- /dev/null +++ b/src/lib/libcrypto/bn/arch/amd64/word_clz.S | |||
@@ -0,0 +1,48 @@ | |||
1 | // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
2 | // SPDX-License-Identifier: Apache-2.0 OR ISC | ||
3 | |||
4 | // ---------------------------------------------------------------------------- | ||
5 | // Count leading zero bits in a single word | ||
6 | // Input a; output function return | ||
7 | // | ||
8 | // extern uint64_t word_clz (uint64_t a); | ||
9 | // | ||
10 | // Standard x86-64 ABI: RDI = a, returns RAX | ||
11 | // Microsoft x64 ABI: RCX = a, returns RAX | ||
12 | // ---------------------------------------------------------------------------- | ||
13 | |||
14 | #include "_internal_s2n_bignum.h" | ||
15 | |||
16 | .intel_syntax noprefix | ||
17 | S2N_BN_SYM_VISIBILITY_DIRECTIVE(word_clz) | ||
18 | S2N_BN_SYM_PRIVACY_DIRECTIVE(word_clz) | ||
19 | .text | ||
20 | |||
21 | S2N_BN_SYMBOL(word_clz): | ||
22 | |||
23 | #if WINDOWS_ABI | ||
24 | push rdi | ||
25 | push rsi | ||
26 | mov rdi, rcx | ||
27 | #endif | ||
28 | |||
29 | // First do rax = 63 - bsr(a), which is right except (maybe) for zero inputs | ||
30 | |||
31 | bsr rax, rdi | ||
32 | xor rax, 63 | ||
33 | |||
34 | // Force return of 64 in the zero-input case | ||
35 | |||
36 | mov edx, 64 | ||
37 | test rdi, rdi | ||
38 | cmove rax, rdx | ||
39 | |||
40 | #if WINDOWS_ABI | ||
41 | pop rsi | ||
42 | pop rdi | ||
43 | #endif | ||
44 | ret | ||
45 | |||
46 | #if defined(__linux__) && defined(__ELF__) | ||
47 | .section .note.GNU-stack,"",%progbits | ||
48 | #endif | ||