using SSE2 in kernel C code (improving AES-NI module)

Konstantin Belousov kostikbel at gmail.com
Sat Oct 20 05:49:00 UTC 2012


On Fri, Oct 19, 2012 at 04:38:33PM -0700, John-Mark Gurney wrote:
> So, the AES-NI module already uses SSE2 instructions, but it does so
> only in assembly.  I have improved the perofrmance of the AES-NI
> modules implementation, but this involves me using additional SSE2
> instructions.
> 
> In order to keep my sanity, I did part of the new code in C using
> gcc native types and xmmintrin.h, but we do not support this header in
> the kernel..  This means we cannot simply add the new code to the
> kernel...
> 
> Any good ideas on how to integrate this code into the kernel build?
> 
> I have used the trick of producing assembly of the C file with gcc -S,
> and then compiling the assembly into the kernel, but I'm not sure if
> that's the best way, and even if it is the best, how I'd do the
> generation as part of the kernel build...  Or would it be ok to commit
> both, and require a regeneration each time the C file is updated?
> 
> In my testing in userland w/o the opencrypto framework overhead, the old
> code would only get about ~250MB/sec..  With the new code I get
> ~2200MB/sec...
> 
> Sample code:
> static inline __m128i
> xts_crank_lfsr(__m128i inp)
> {
> 	const __m128i alphamask = _mm_set_epi32(1, 1, 1, AES_XTS_ALPHA);
> 	__m128i xtweak, ret;
> 
> 	/* set up xor mask */
> 	xtweak = _mm_shuffle_epi32(inp, 0x93);
> 	xtweak = _mm_srai_epi32(xtweak, 31);
> 	xtweak &= alphamask;
> 
> 	/* next term */
> 	ret = _mm_slli_epi32(inp, 1);
> 	ret ^= xtweak;
> 
> 	return ret;
> }

The current structure of the aes-ni driver is partly enforced by the
issue you noted. We cannot use sse intristics in the kernel, and
huge inline assembler fragments are hard to write.

I prefer to have the separate .S files with the optimized code,
hand-written. If needed, I offer you a help with transition. I would
need a full patch to rewrite the code.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20121020/b69fc7fa/attachment.sig>


More information about the freebsd-arch mailing list