[FFmpeg-devel] [RFC] more readable aes.c mix function

Måns Rullgård mans
Wed Jun 30 11:13:08 CEST 2010


Reimar D?ffinger <Reimar.Doeffinger at gmx.de> writes:

> Hello,
> I think below patch makes the mix function more readable by avoiding
> repeating the state[1].u8x4 part all over.
> Generated code stays identical with gcc 4.4.
>
> Index: libavutil/aes.c
> ===================================================================
> --- libavutil/aes.c	(revision 23896)
> +++ libavutil/aes.c	(working copy)
> @@ -78,10 +78,11 @@
>  }
>  
>  static inline void mix(av_aes_block state[2], uint32_t multbl[][256], int s1, int s3){
> -    state[0].u32[0] = mix_core(multbl, state[1].u8x4[0][0], state[1].u8x4[s1  ][1], state[1].u8x4[2][2], state[1].u8x4[s3  ][3]);
> -    state[0].u32[1] = mix_core(multbl, state[1].u8x4[1][0], state[1].u8x4[s3-1][1], state[1].u8x4[3][2], state[1].u8x4[s1-1][3]);
> -    state[0].u32[2] = mix_core(multbl, state[1].u8x4[2][0], state[1].u8x4[s3  ][1], state[1].u8x4[0][2], state[1].u8x4[s1  ][3]);
> -    state[0].u32[3] = mix_core(multbl, state[1].u8x4[3][0], state[1].u8x4[s1-1][1], state[1].u8x4[1][2], state[1].u8x4[s3-1][3]);
> +    uint8_t (*src)[4] = state[1].u8x4;
> +    state[0].u32[0] = mix_core(multbl, src[0][0], src[s1  ][1], src[2][2], src[s3  ][3]);
> +    state[0].u32[1] = mix_core(multbl, src[1][0], src[s3-1][1], src[3][2], src[s1-1][3]);
> +    state[0].u32[2] = mix_core(multbl, src[2][0], src[s3  ][1], src[0][2], src[s1  ][3]);
> +    state[0].u32[3] = mix_core(multbl, src[3][0], src[s1-1][1], src[1][2], src[s3-1][3]);
>  }
>  
>  static inline void crypt(AVAES *a, int s, const uint8_t *sbox, uint32_t multbl[][256]){

Much better.

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-devel mailing list