While I'm at it, squeeze out a little more performance

by changing some integer regular arithmetic to bitwise operations.

I'm not sure that would make any difference if I used optimized
compilation, but it might still make a difference on some old
compilers.

It seems to make a difference on gcc without optimization on my Linux
machine (and, of course, it does not break the tests).

Before:
real	1m6,707s
user	1m6,035s
sys	0m0,672s

After:
real	1m6,352s
user	1m5,672s
sys	0m0,680s
This commit is contained in:
Alain Mosnier 2019-08-04 14:20:53 +02:00
parent db722a7329
commit 61555d4567
No known key found for this signature in database
GPG Key ID: 331DCAAEDE209451
1 changed files with 1 additions and 1 deletions

View File

@ -187,7 +187,7 @@ void calc_sha_256(uint8_t hash[32], const void * input, size_t len)
}
const uint32_t s1 = right_rot(ah[4], 6) ^ right_rot(ah[4], 11) ^ right_rot(ah[4], 25);
const uint32_t ch = (ah[4] & ah[5]) ^ (~ah[4] & ah[6]);
const uint32_t temp1 = ah[7] + s1 + ch + k[i * 16 + j] + w[j];
const uint32_t temp1 = ah[7] + s1 + ch + k[i << 4 | j] + w[j];
const uint32_t s0 = right_rot(ah[0], 2) ^ right_rot(ah[0], 13) ^ right_rot(ah[0], 22);
const uint32_t maj = (ah[0] & ah[1]) ^ (ah[0] & ah[2]) ^ (ah[1] & ah[2]);
const uint32_t temp2 = s0 + maj;