diff options
Diffstat (limited to 'crypto/openssh/mlkem768.sh')
-rw-r--r-- | crypto/openssh/mlkem768.sh | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/crypto/openssh/mlkem768.sh b/crypto/openssh/mlkem768.sh index 3d12b2ed88e2..cbc3d14da2ed 100644 --- a/crypto/openssh/mlkem768.sh +++ b/crypto/openssh/mlkem768.sh @@ -49,6 +49,11 @@ echo '#define KRML_HOST_EPRINTF(...)' echo '#define KRML_HOST_EXIT(x) fatal_f("internal error")' echo +__builtin_popcount_replacement=' + const uint8_t v[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; + return v[x0 & 0xf] + v[(x0 >> 4) & 0xf]; +' + for i in $FILES; do echo "/* from $i */" # Changes to all files: @@ -62,7 +67,10 @@ for i in $FILES; do # Replace endian functions with versions that work. perl -0777 -pe 's/(static inline void core_num__u64_9__to_le_bytes.*\n)([^}]*\n)/\1 v = htole64(v);\n\2/' | perl -0777 -pe 's/(static inline uint64_t core_num__u64_9__from_le_bytes.*?)return v;/\1return le64toh(v);/s' | - perl -0777 -pe 's/(static inline uint32_t core_num__u32_8__from_le_bytes.*?)return v;/\1return le32toh(v);/s' + perl -0777 -pe 's/(static inline uint32_t core_num__u32_8__from_le_bytes.*?)return v;/\1return le32toh(v);/s' | + # Compat for popcount. + perl -0777 -pe 's/\#ifdef (_MSC_VER)(.*?return __popcnt\(x0\);)/\#if defined(\1)\2/s' | + perl -0777 -pe "s/\\#else(\\n\\s+return __builtin_popcount\\(x0\\);)/\\#elif !defined(MISSING_BUILTIN_POPCOUNT)\\1\\n#else$__builtin_popcount_replacement/s" ;; # Default: pass through. *) |