History

lavu/aes: add x86 AESNI optimizations

crypto_bench comparison for AES-128-ECB: lavu_aesni AES-128-ECB size: 1048576 runs: 1024 time: 0.596 +- 0.081 lavu_c AES-128-ECB size: 1048576 runs: 1024 time: 17.007 +- 2.131 crypto AES-128-ECB size: 1048576 runs: 1024 time: 0.612 +- 1.857 gcrypt AES-128-ECB size: 1048576 runs: 1024 time: 1.123 +- 0.224 tomcrypt AES-128-ECB size: 1048576 runs: 1024 time: 9.038 +- 0.790

Rodger Combs committed 11 years ago

Commit 2ea3c511 parent 2daaafa5 files · +139 −2Browse files

Unified · Split

5 files
  1. libavutil/aes.c +2 −0
  2. libavutil/aes_internal.h +2 −0
  3. libavutil/x86/Makefile +4 −2
  4. libavutil/x86/aes.asm +95 −0
  5. libavutil/x86/aes_init.c +36 −0
libavutil/aes.c+2−0
@@ -208,6 +208,8 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) · 207 unmodified lines
208 uint8_t alog8[512];208 uint8_t alog8[512];
209 209
210 a->crypt = decrypt ? aes_decrypt : aes_encrypt;210 a->crypt = decrypt ? aes_decrypt : aes_encrypt;
211 if (ARCH_X86)
212 ff_init_aes_x86(a, decrypt);
211 213
212 if (!enc_multbl[FF_ARRAY_ELEMS(enc_multbl) - 1][FF_ARRAY_ELEMS(enc_multbl[0]) - 1]) {214 if (!enc_multbl[FF_ARRAY_ELEMS(enc_multbl) - 1][FF_ARRAY_ELEMS(enc_multbl[0]) - 1]) {
213 j = 1;215 j = 1;
libavutil/aes_internal.h+2−0
@@ -40,4 +40,6 @@ typedef struct AVAES { · 39 unmodified lines
40 void (*crypt)(struct AVAES *a, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int rounds);40 void (*crypt)(struct AVAES *a, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int rounds);
41} AVAES;41} AVAES;
42 42
43void ff_init_aes_x86(AVAES *a, int decrypt);
44
43#endif /* AVUTIL_AES_INTERNAL_H */45#endif /* AVUTIL_AES_INTERNAL_H */
libavutil/x86/Makefile+4−2
@@ -1,4 +1,5 @@
1OBJS += x86/cpu.o \1OBJS += x86/aes_init.o \
2 x86/cpu.o \
2 x86/fixed_dsp_init.o \3 x86/fixed_dsp_init.o \
3 x86/float_dsp_init.o \4 x86/float_dsp_init.o \
4 x86/imgutils_init.o \5 x86/imgutils_init.o \
@@ -10,7 +11,8 @@ OBJS-$(CONFIG_PIXELUTILS) += x86/pixelutils_init.o \ · 5 unmodified lines
10 11
11EMMS_OBJS_$(HAVE_MMX_INLINE)_$(HAVE_MMX_EXTERNAL)_$(HAVE_MM_EMPTY) = x86/emms.o12EMMS_OBJS_$(HAVE_MMX_INLINE)_$(HAVE_MMX_EXTERNAL)_$(HAVE_MM_EMPTY) = x86/emms.o
12 13
13X86ASM-OBJS += x86/cpuid.o \14X86ASM-OBJS += x86/aes.o \
15 x86/cpuid.o \
14 $(EMMS_OBJS__yes_) \16 $(EMMS_OBJS__yes_) \
15 x86/fixed_dsp.o \17 x86/fixed_dsp.o \
16 x86/float_dsp.o \18 x86/float_dsp.o \
libavutil/x86/aes.asm+95−0
@@ -0,0 +1,95 @@
1;*****************************************************************************
2;* Copyright (c) 2015 Rodger Combs <rodger.combs@gmail.com>
3;*
4;* This file is part of FFmpeg.
5;*
6;* FFmpeg is free software; you can redistribute it and/or
7;* modify it under the terms of the GNU Lesser General Public
8;* License as published by the Free Software Foundation; either
9;* version 2.1 of the License, or (at your option) any later version.
10;*
11;* FFmpeg is distributed in the hope that it will be useful,
12;* but WITHOUT ANY WARRANTY; without even the implied warranty of
13;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14;* Lesser General Public License for more details.
15;*
16;* You should have received a copy of the GNU Lesser General Public
17;* License along with FFmpeg; if not, write to the Free Software
18;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19;******************************************************************************
20
21%include "x86util.asm"
22
23SECTION .text
24
25;-----------------------------------------------------------------------------
26; void ff_aes_decrypt(AVAES *a, uint8_t *dst, const uint8_t *src,
27; int count, uint8_t *iv, int rounds)
28;-----------------------------------------------------------------------------
29%macro AES_CRYPT 1
30cglobal aes_%1rypt, 6,6,2
31 test r3, r3
32 je .ret
33 shl r3d, 4
34 add r5d, r5d
35 add r0, 0x60
36 add r2, r3
37 add r1, r3
38 neg r3
39 pxor m1, m1
40 test r4, r4
41 je .block
42 movu m1, [r4] ; iv
43.block:
44 movu m0, [r2+r3] ; state
45%ifidn %1, enc
46 pxor m0, m1
47%endif
48 pxor m0, [r0+8*r5-0x60]
49 cmp r5d, 24
50 je .rounds12
51 jl .rounds10
52 aes%1 m0, [r0+0x70]
53 aes%1 m0, [r0+0x60]
54.rounds12:
55 aes%1 m0, [r0+0x50]
56 aes%1 m0, [r0+0x40]
57.rounds10:
58 aes%1 m0, [r0+0x30]
59 aes%1 m0, [r0+0x20]
60 aes%1 m0, [r0+0x10]
61 aes%1 m0, [r0+0x00]
62 aes%1 m0, [r0-0x10]
63 aes%1 m0, [r0-0x20]
64 aes%1 m0, [r0-0x30]
65 aes%1 m0, [r0-0x40]
66 aes%1 m0, [r0-0x50]
67 aes%1last m0, [r0-0x60]
68 test r4, r4
69 je .noiv
70%ifidn %1, enc
71 mova m1, m0
72%else
73 pxor m0, m1
74 movu m1, [r2+r3]
75%endif
76.noiv:
77 movu [r1+r3], m0
78 add r3, 16
79 jl .block
80 test r4, r4
81 je .ret
82%ifidn %1, dec
83 movu [r4], m1
84%else
85 movu [r4], m0
86%endif
87.ret:
88 REP_RET
89%endmacro
90
91%if HAVE_AESNI_EXTERNAL
92INIT_XMM aesni
93AES_CRYPT enc
94AES_CRYPT dec
95%endif
libavutil/x86/aes_init.c+36−0
@@ -0,0 +1,36 @@
1/*
2 * Copyright (c) 2015 Rodger Combs <rodger.combs@gmail.com>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <stddef.h>
22#include "libavutil/aes_internal.h"
23#include "libavutil/x86/cpu.h"
24
25void ff_aes_decrypt_aesni(AVAES *a, uint8_t *dst, const uint8_t *src,
26 int count, uint8_t *iv, int rounds);
27void ff_aes_encrypt_aesni(AVAES *a, uint8_t *dst, const uint8_t *src,
28 int count, uint8_t *iv, int rounds);
29
30void ff_init_aes_x86(AVAES *a, int decrypt)
31{
32 int cpu_flags = av_get_cpu_flags();
33
34 if (EXTERNAL_AESNI(cpu_flags))
35 a->crypt = decrypt ? ff_aes_decrypt_aesni : ff_aes_encrypt_aesni;
36}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t