diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2022-01-08 01:25:23 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2022-01-08 01:25:23 +0100 |
commit | e7ff29402d23e1c265769dbe809cf2d329a75ec2 (patch) | |
tree | 2b8a1ca262efa3de73efb03eef8e75bd112238ed | |
parent | 805ececa615606c02a5ca8f37f84dbbc527221eb (diff) | |
download | busybox-w32-e7ff29402d23e1c265769dbe809cf2d329a75ec2.tar.gz busybox-w32-e7ff29402d23e1c265769dbe809cf2d329a75ec2.tar.bz2 busybox-w32-e7ff29402d23e1c265769dbe809cf2d329a75ec2.zip |
libbb/sha1: simplify cpuid code
function old new delta
sha1_begin 107 106 -1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/hash_md5_sha.c | 42 |
1 files changed, 10 insertions, 32 deletions
diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c index 0b3af723a..a23db5152 100644 --- a/libbb/hash_md5_sha.c +++ b/libbb/hash_md5_sha.c | |||
@@ -1143,43 +1143,21 @@ static void FAST_FUNC sha512_process_block128(sha512_ctx_t *ctx) | |||
1143 | #endif /* NEED_SHA512 */ | 1143 | #endif /* NEED_SHA512 */ |
1144 | 1144 | ||
1145 | #if ENABLE_SHA1_HWACCEL | 1145 | #if ENABLE_SHA1_HWACCEL |
1146 | # if defined(__GNUC__) && defined(__i386__) | 1146 | # if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) |
1147 | static void cpuid(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx) | 1147 | static void cpuid(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx) |
1148 | { | 1148 | { |
1149 | asm ( | 1149 | asm ("cpuid" |
1150 | " cpuid\n" | 1150 | : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) |
1151 | : "=a"(*eax), /* Output */ | 1151 | : "0"(*eax), "1"(*ebx), "2"(*ecx), "3"(*edx) |
1152 | "=b"(*ebx), | ||
1153 | "=c"(*ecx), | ||
1154 | "=d"(*edx) | ||
1155 | : "0"(*eax), /* Input */ | ||
1156 | "1"(*ebx), | ||
1157 | "2"(*ecx), | ||
1158 | "3"(*edx) | ||
1159 | /* No clobbered registers */ | ||
1160 | ); | 1152 | ); |
1161 | } | 1153 | } |
1162 | struct ASM_expects_76_shaNI { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 76)]; }; | ||
1163 | void FAST_FUNC sha1_process_block64_shaNI(sha1_ctx_t *ctx); | 1154 | void FAST_FUNC sha1_process_block64_shaNI(sha1_ctx_t *ctx); |
1164 | # endif | 1155 | # if defined(__i386__) |
1165 | # if defined(__GNUC__) && defined(__x86_64__) | 1156 | struct ASM_expects_76_shaNI { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 76)]; }; |
1166 | static void cpuid(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx) | 1157 | # endif |
1167 | { | 1158 | # if defined(__x86_64__) |
1168 | asm ( | ||
1169 | "cpuid\n" | ||
1170 | : "=a"(*eax), /* Output */ | ||
1171 | "=b"(*ebx), | ||
1172 | "=c"(*ecx), | ||
1173 | "=d"(*edx) | ||
1174 | : "0"(*eax), /* Input */ | ||
1175 | "1"(*ebx), | ||
1176 | "2"(*ecx), | ||
1177 | "3"(*edx) | ||
1178 | /* No clobbered registers */ | ||
1179 | ); | ||
1180 | } | ||
1181 | struct ASM_expects_80_shaNI { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 80)]; }; | 1159 | struct ASM_expects_80_shaNI { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 80)]; }; |
1182 | void FAST_FUNC sha1_process_block64_shaNI(sha1_ctx_t *ctx); | 1160 | # endif |
1183 | # endif | 1161 | # endif |
1184 | #endif | 1162 | #endif |
1185 | 1163 | ||
@@ -1199,7 +1177,7 @@ void FAST_FUNC sha1_begin(sha1_ctx_t *ctx) | |||
1199 | if (!shaNI) { | 1177 | if (!shaNI) { |
1200 | unsigned eax = 7, ebx = ebx, ecx = 0, edx = edx; | 1178 | unsigned eax = 7, ebx = ebx, ecx = 0, edx = edx; |
1201 | cpuid(&eax, &ebx, &ecx, &edx); | 1179 | cpuid(&eax, &ebx, &ecx, &edx); |
1202 | shaNI = ((ebx >> 28) & 2) - 1; | 1180 | shaNI = ((ebx >> 29) << 1) - 1; |
1203 | } | 1181 | } |
1204 | if (shaNI > 0) | 1182 | if (shaNI > 0) |
1205 | ctx->process_block = sha1_process_block64_shaNI; | 1183 | ctx->process_block = sha1_process_block64_shaNI; |