From owner-svn-src-head@freebsd.org Tue Jul 7 20:31:10 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9E540995246; Tue, 7 Jul 2015 20:31:10 +0000 (UTC) (envelope-from jmg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 632EE12EF; Tue, 7 Jul 2015 20:31:10 +0000 (UTC) (envelope-from jmg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t67KV9lA098453; Tue, 7 Jul 2015 20:31:09 GMT (envelope-from jmg@FreeBSD.org) Received: (from jmg@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t67KV9TN098452; Tue, 7 Jul 2015 20:31:09 GMT (envelope-from jmg@FreeBSD.org) Message-Id: <201507072031.t67KV9TN098452@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jmg set sender to jmg@FreeBSD.org using -f From: John-Mark Gurney Date: Tue, 7 Jul 2015 20:31:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285254 - head/sys/crypto/aesni X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jul 2015 20:31:10 -0000 Author: jmg Date: Tue Jul 7 20:31:09 2015 New Revision: 285254 URL: https://svnweb.freebsd.org/changeset/base/285254 Log: unroll the loop slightly... This improves performance enough to justify, especially for CBC performance where we can't pipeline.. I don't happen to have my measurements handy though... Sponsored by: Netflix, Inc. Modified: head/sys/crypto/aesni/aesencdec.h Modified: head/sys/crypto/aesni/aesencdec.h ============================================================================== --- head/sys/crypto/aesni/aesencdec.h Tue Jul 7 20:15:09 2015 (r285253) +++ head/sys/crypto/aesni/aesencdec.h Tue Jul 7 20:31:09 2015 (r285254) @@ -1,5 +1,6 @@ /*- * Copyright 2013 John-Mark Gurney + * Copyright 2015 Netflix, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,6 +28,9 @@ * */ +#ifndef _AESENCDEC_H_ +#define _AESENCDEC_H_ + #include #include @@ -105,6 +109,7 @@ aesni_dec8(int rounds, const __m128i *ke out[7] = _mm_aesdeclast_si128(h, keysched[i + 1]); } +/* rounds is passed in as rounds - 1 */ static inline __m128i aesni_enc(int rounds, const __m128i *keysched, const __m128i from) { @@ -112,11 +117,13 @@ aesni_enc(int rounds, const __m128i *key int i; tmp = from ^ keysched[0]; - - for (i = 0; i < rounds; i++) + for (i = 1; i < rounds; i += 2) { + tmp = _mm_aesenc_si128(tmp, keysched[i]); tmp = _mm_aesenc_si128(tmp, keysched[i + 1]); + } - return _mm_aesenclast_si128(tmp, keysched[i + 1]); + tmp = _mm_aesenc_si128(tmp, keysched[rounds]); + return _mm_aesenclast_si128(tmp, keysched[rounds + 1]); } static inline __m128i @@ -127,8 +134,13 @@ aesni_dec(int rounds, const __m128i *key tmp = from ^ keysched[0]; - for (i = 0; i < rounds; i++) + for (i = 1; i < rounds; i += 2) { + tmp = _mm_aesdec_si128(tmp, keysched[i]); tmp = _mm_aesdec_si128(tmp, keysched[i + 1]); + } - return _mm_aesdeclast_si128(tmp, keysched[i + 1]); + tmp = _mm_aesdec_si128(tmp, keysched[rounds]); + return _mm_aesdeclast_si128(tmp, keysched[rounds + 1]); } + +#endif /* _AESENCDEC_H_ */