aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2023-11-28 13:29:58 +0100
committerJakub Jelinek <jakub@redhat.com>2023-11-28 13:29:58 +0100
commit4a50820ee8f153265ec8ffd068618607d4be3a26 (patch)
tree680392257eafcb9160a66e62070f802374d2eda6 /include
parente5f1ee1832ff9e970833fa5773f46c3e0b93bc04 (diff)
downloadbinutils-4a50820ee8f153265ec8ffd068618607d4be3a26.zip
binutils-4a50820ee8f153265ec8ffd068618607d4be3a26.tar.gz
binutils-4a50820ee8f153265ec8ffd068618607d4be3a26.tar.bz2
libiberty, ld: Use x86 HW optimized sha1
The following patch attempts to use x86 SHA ISA if available to speed up in my testing about 2.5x sha1 build-id processing (in my case on AMD Ryzen 5 3600) while producing the same result. I believe AArch64 has similar HW acceleration for SHA1, perhaps it could be added similarly. Note, seems lld uses BLAKE3 rather than md5/sha1. I think it would be a bad idea to lie to users, if they choose --buildid=sha1, we should be using SHA1, not some other checksum, but perhaps we could add some other --buildid= styles and perhaps make one of the new the default. Tested on x86_64-linux, both on Intel i9-7960X (which doesn't have sha_ni ISA support) without/with the patch and on AMD Ryzen 5 3600 (which does have it) without/with the patch. 2023-11-28 Jakub Jelinek <jakub@redhat.com> include/ * sha1.h (sha1_process_bytes_fn): New typedef. (sha1_choose_process_bytes): Declare. libiberty/ * configure.ac (HAVE_X86_SHA1_HW_SUPPORT): New check. * sha1.c: If HAVE_X86_SHA1_HW_SUPPORT is defined, include x86intrin.h and cpuid.h. (sha1_hw_process_bytes, sha1_hw_process_block, sha1_choose_process_bytes): New functions. * config.in: Regenerated. * configure: Regenerated. ld/ * ldbuildid.c (generate_build_id): Use sha1_choose_process_bytes () instead of &sha1_process_bytes.
Diffstat (limited to 'include')
-rw-r--r--include/ChangeLog5
-rw-r--r--include/sha1.h7
2 files changed, 12 insertions, 0 deletions
diff --git a/include/ChangeLog b/include/ChangeLog
index dbef999..d9e4dc4 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,3 +1,8 @@
+2023-11-28 Jakub Jelinek <jakub@redhat.com>
+
+ * sha1.h (sha1_process_bytes_fn): New typedef.
+ (sha1_choose_process_bytes): Declare.
+
2023-11-10 Simon Marchi <simon.marchi@efficios.com>
* elf/amdgpu.h (EF_AMDGPU_MACH_AMDGCN_GFX1100,
diff --git a/include/sha1.h b/include/sha1.h
index eb86fbb..6c94a47 100644
--- a/include/sha1.h
+++ b/include/sha1.h
@@ -108,6 +108,13 @@ extern void sha1_process_block (const void *buffer, size_t len,
extern void sha1_process_bytes (const void *buffer, size_t len,
struct sha1_ctx *ctx);
+typedef void (*sha1_process_bytes_fn) (const void *, size_t,
+ struct sha1_ctx *);
+
+/* Return sha1_process_bytes or some hardware optimized version thereof
+ depending on current CPU. */
+extern sha1_process_bytes_fn sha1_choose_process_bytes (void);
+
/* Process the remaining bytes in the buffer and put result from CTX
in first 20 bytes following RESBUF. The result is always in little
endian byte order, so that a byte-wise output yields to the wanted