2007-10-21 19:16:36

by Denys Vlasenko

[permalink] [raw]
Subject: [PATCH] do not unroll big stuff in twofish key setup if OPTIMIZE_FOR_SIZE

Hello Herbert,

Currently twofish cipher key setup code
has unrolled loops - approximately 70-100
instructions are repeated 40 times.

As a result, twofish module is the biggest module
in crypto/*.

Attached patch conditionalize this unrolling on
CONFIG_CC_OPTIMIZE_FOR_SIZE. Presumably, people which
want to use -Os will also prefer to not have these loops
unrolled:

$ size */twofish_common.o
text data bss dec hex filename
37920 0 0 37920 9420 crypto.org/twofish_common.o
13209 0 0 13209 3399 crypto/twofish_common.o

Run tested (modprobe tcrypt reports ok). Please apply.

Signed-off-by: Denys Vlasenko <[email protected]>
--
vda


Attachments:
(No filename) (697.00 B)
twofish_common.diff (2.68 kB)
Download all attachments

2007-10-23 06:07:53

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] do not unroll big stuff in twofish key setup if OPTIMIZE_FOR_SIZE

On Sun, Oct 21, 2007 at 08:16:25PM +0100, Denys Vlasenko wrote:
> Hello Herbert,
>
> Currently twofish cipher key setup code
> has unrolled loops - approximately 70-100
> instructions are repeated 40 times.
>
> As a result, twofish module is the biggest module
> in crypto/*.
>
> Attached patch conditionalize this unrolling on
> CONFIG_CC_OPTIMIZE_FOR_SIZE. Presumably, people which
> want to use -Os will also prefer to not have these loops
> unrolled:

Thanks for the patch Denys.

Have you looked at the performance figures on x86 for the two
variants? If the difference is small we could just get rid of
the unrolled version altogether.

Cheers,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2007-10-24 17:45:03

by Denys Vlasenko

[permalink] [raw]
Subject: Re: [PATCH] do not unroll big stuff in twofish key setup if OPTIMIZE_FOR_SIZE

On Tuesday 23 October 2007 07:07, Herbert Xu wrote:
> On Sun, Oct 21, 2007 at 08:16:25PM +0100, Denys Vlasenko wrote:
> > Hello Herbert,
> >
> > Currently twofish cipher key setup code
> > has unrolled loops - approximately 70-100
> > instructions are repeated 40 times.
> >
> > As a result, twofish module is the biggest module
> > in crypto/*.
> >
> > Attached patch conditionalize this unrolling on
> > CONFIG_CC_OPTIMIZE_FOR_SIZE. Presumably, people which
> > want to use -Os will also prefer to not have these loops
> > unrolled:
>
> Thanks for the patch Denys.
>
> Have you looked at the performance figures on x86 for the two
> variants? If the difference is small we could just get rid of
> the unrolled version altogether.

7% slower key setup (see patch - there is a comment about it).
--
vda

2007-10-25 01:08:26

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] do not unroll big stuff in twofish key setup if OPTIMIZE_FOR_SIZE

On Wed, Oct 24, 2007 at 06:44:54PM +0100, Denys Vlasenko wrote:
>
> 7% slower key setup (see patch - there is a comment about it).

Is it just the keying? If so please simply delete the unrolled
version because keying is supposed to be a rare event.

Thanks,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

2007-10-25 18:34:05

by Denys Vlasenko

[permalink] [raw]
Subject: Re: [PATCH] do not unroll big stuff in twofish key setup if OPTIMIZE_FOR_SIZE

On Thursday 25 October 2007 02:08, Herbert Xu wrote:
> On Wed, Oct 24, 2007 at 06:44:54PM +0100, Denys Vlasenko wrote:
> >
> > 7% slower key setup (see patch - there is a comment about it).
>
> Is it just the keying? If so please simply delete the unrolled
> version because keying is supposed to be a rare event.

In some crypto applications key setup takes much longer
than encryption itself (e.g. password check).
Not sure whether this kind of behavior ever happens in kernel,
though.

And second, there will be people which want speed at all costs
and they surely will see 7% speedup as significant.

I personally am in the -Os camp and prefer smaller code,
so I personally have no objections.

See attached patch.

Signed-off-by: Denys Vlasenko <[email protected]>
--
vda


Attachments:
(No filename) (785.00 B)
twofish_common02.diff (4.66 kB)
Download all attachments

2007-10-26 08:24:51

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] do not unroll big stuff in twofish key setup if OPTIMIZE_FOR_SIZE

On Thu, Oct 25, 2007 at 07:33:55PM +0100, Denys Vlasenko wrote:
>
> See attached patch.
>
> Signed-off-by: Denys Vlasenko <[email protected]>

Patch applied. Thanks a lot Denys.
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt