diff options
author | James Almer <jamrial@gmail.com> | 2025-04-07 12:51:54 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2025-04-10 12:02:34 -0300 |
commit | a039726c2a092c340e26b28fcc2bb3582be85d4f (patch) | |
tree | 4dd02d944598c49e0f357b3f6cb8dd2296a30d76 /libavutil/aes.c | |
parent | 4d4b301e4a269adfabceaeca1a20c653bde47554 (diff) | |
download | ffmpeg-a039726c2a092c340e26b28fcc2bb3582be85d4f.tar.gz |
avutil/x86/aes: remove a few branches
The rounds value is constant and can be one of three hardcoded values, so
instead of checking it on every loop, just split the function into three
different implementations for each value.
Before:
aes_decrypt_128_aesni: 93.8 (47.58x)
aes_decrypt_192_aesni: 106.9 (49.30x)
aes_decrypt_256_aesni: 109.8 (56.50x)
aes_encrypt_128_aesni: 93.2 (47.70x)
aes_encrypt_192_aesni: 111.1 (48.36x)
aes_encrypt_256_aesni: 113.6 (56.27x)
After:
aes_decrypt_128_aesni: 71.5 (63.31x)
aes_decrypt_192_aesni: 96.8 (55.64x)
aes_decrypt_256_aesni: 106.1 (58.51x)
aes_encrypt_128_aesni: 81.3 (55.92x)
aes_encrypt_192_aesni: 91.2 (59.78x)
aes_encrypt_256_aesni: 109.0 (58.26x)
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavutil/aes.c')
-rw-r--r-- | libavutil/aes.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/libavutil/aes.c b/libavutil/aes.c index 5f31412149..52a250bc00 100644 --- a/libavutil/aes.c +++ b/libavutil/aes.c @@ -234,6 +234,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) int KC = key_bits >> 5; int rounds = KC + 6; + a->rounds = rounds; a->crypt = decrypt ? aes_decrypt : aes_encrypt; if (ARCH_X86) ff_init_aes_x86(a, decrypt); @@ -243,8 +244,6 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) if (key_bits != 128 && key_bits != 192 && key_bits != 256) return AVERROR(EINVAL); - a->rounds = rounds; - memcpy(tk, key, KC * 4); memcpy(a->round_key[0].u8, key, KC * 4); |