[FFmpeg-devel] [PATCH] strict-aliasing-safe aes.c

Reimar Döffinger Reimar.Doeffinger
Wed Jun 30 00:12:48 CEST 2010


On Tue, Jun 29, 2010 at 06:44:49PM +0100, M?ns Rullg?rd wrote:
> > -static inline void mix(uint8_t state[2][4][4], uint32_t multbl[][256], int s1, int s3){
> > -    ((uint32_t *)(state))[0] = mix_core(multbl, state[1][0][0], state[1][s1  ][1], state[1][2][2], state[1][s3  ][3]);
> > -    ((uint32_t *)(state))[1] = mix_core(multbl, state[1][1][0], state[1][s3-1][1], state[1][3][2], state[1][s1-1][3]);
> > -    ((uint32_t *)(state))[2] = mix_core(multbl, state[1][2][0], state[1][s3  ][1], state[1][0][2], state[1][s1  ][3]);
> > -    ((uint32_t *)(state))[3] = mix_core(multbl, state[1][3][0], state[1][s1-1][1], state[1][1][2], state[1][s3-1][3]);
> > +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]);
> >  }
> 
> These blocks are extremely dense both before and after.  Is there any
> way they could be made more readable?  This is not a criticism of your
> patch, just an observation.

Well, I'm not sure I like it myself and I suspect it makes Michael grab
a pitchfork and head towards Sweden, but you could do something like
#define MIX(s, a, b, c, d) mix_core(multbl, s[a][0], s[b][1], s[c][2], s[d][3])
state[0].u32[0] = MIX(state[1].u8x4, 0, s1,   2, s3);
state[0].u32[1] = MIX(state[1].u8x4, 1, s3-1, 3, s1-1);
state[0].u32[2] = MIX(state[1].u8x4, 2, s3,   0, s1);
state[0].u32[3] = MIX(state[1].u8x4, 3, s1-1, 1, s3-1);



More information about the ffmpeg-devel mailing list