diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-10-06 19:59:39 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-10-06 19:59:39 +0200 |
| commit | 87e3f2e9f8a1c99b223b316fbefb5ae49c2a8fe2 (patch) | |
| tree | 0751b9c52ace20c6cff5297fbf1f955b44f30faf | |
| parent | 911344a99889319a7dba8a725a64dc324597f9eb (diff) | |
| download | busybox-w32-87e3f2e9f8a1c99b223b316fbefb5ae49c2a8fe2.tar.gz busybox-w32-87e3f2e9f8a1c99b223b316fbefb5ae49c2a8fe2.tar.bz2 busybox-w32-87e3f2e9f8a1c99b223b316fbefb5ae49c2a8fe2.zip | |
tls: P256: x86-64 optimized sp_256_sub_8_p256_mod
function old new delta
sp_256_sub_8_p256_mod - 53 +53
sp_256_mont_reduce_8 223 217 -6
sp_256_mont_dbl_8 38 32 -6
sp_256_ecc_mulmod_8 1535 1529 -6
sp_256_proj_point_dbl_8 469 454 -15
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/4 up/down: 53/-33) Total: 20 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | networking/tls_sp_c32.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/networking/tls_sp_c32.c b/networking/tls_sp_c32.c index 14a7c7066..1391cb405 100644 --- a/networking/tls_sp_c32.c +++ b/networking/tls_sp_c32.c | |||
| @@ -346,8 +346,8 @@ static int sp_256_sub_8(sp_digit* r, const sp_digit* a, const sp_digit* b) | |||
| 346 | #endif | 346 | #endif |
| 347 | } | 347 | } |
| 348 | 348 | ||
| 349 | #if ALLOW_ASM && defined(__GNUC__) && defined(__i386__) | ||
| 350 | /* Sub p256_mod from a into r. (r = a - p256_mod). */ | 349 | /* Sub p256_mod from a into r. (r = a - p256_mod). */ |
| 350 | #if ALLOW_ASM && defined(__GNUC__) && defined(__i386__) | ||
| 351 | static void sp_256_sub_8_p256_mod(sp_digit* r, const sp_digit* a) | 351 | static void sp_256_sub_8_p256_mod(sp_digit* r, const sp_digit* a) |
| 352 | { | 352 | { |
| 353 | sp_digit reg; | 353 | sp_digit reg; |
| @@ -390,6 +390,36 @@ static void sp_256_sub_8_p256_mod(sp_digit* r, const sp_digit* a) | |||
| 390 | : "memory" | 390 | : "memory" |
| 391 | ); | 391 | ); |
| 392 | } | 392 | } |
| 393 | #elif ALLOW_ASM && defined(__GNUC__) && defined(__x86_64__) | ||
| 394 | static void sp_256_sub_8_p256_mod(sp_digit* r, const sp_digit* a) | ||
| 395 | { | ||
| 396 | uint64_t reg; | ||
| 397 | uint64_t ooff; | ||
| 398 | //p256_mod[3..0] = ffffffff00000001 0000000000000000 00000000ffffffff ffffffffffffffff | ||
| 399 | asm volatile ( | ||
| 400 | "\n movq (%0), %3" | ||
| 401 | "\n addq $1, %3" // adding 1 is the same as subtracting ffffffffffffffff | ||
| 402 | "\n movq %3, (%1)" // | ||
| 403 | "\n cmc" // only carry bit needs inverting | ||
| 404 | "\n" | ||
| 405 | "\n movq 1*8(%0), %3" | ||
| 406 | "\n sbbq %2, %3" // %2 holds 00000000ffffffff | ||
| 407 | "\n movq %3, 1*8(%1)" | ||
| 408 | "\n" | ||
| 409 | "\n movq 2*8(%0), %3" | ||
| 410 | "\n sbbq $0, %3" | ||
| 411 | "\n movq %3, 2*8(%1)" | ||
| 412 | "\n" | ||
| 413 | "\n movq 3*8(%0), %3" | ||
| 414 | "\n sbbq $0, %3" // adding 00000000ffffffff (in %2) | ||
| 415 | "\n addq %2, %3" // is the same as subtracting ffffffff00000001 | ||
| 416 | "\n movq %3, 3*8(%1)" | ||
| 417 | "\n" | ||
| 418 | : "=r" (a), "=r" (r), "=r" (ooff), "=r" (reg) | ||
| 419 | : "0" (a), "1" (r), "2" (0x00000000ffffffff) | ||
| 420 | : "memory" | ||
| 421 | ); | ||
| 422 | } | ||
| 393 | #else | 423 | #else |
| 394 | # define sp_256_sub_8_p256_mod(r, a) sp_256_sub_8((r), (a), p256_mod) | 424 | # define sp_256_sub_8_p256_mod(r, a) sp_256_sub_8((r), (a), p256_mod) |
| 395 | #endif | 425 | #endif |
