]> git.karo-electronics.de Git - karo-tx-linux.git/commit
crypto: algapi - annotate expected branch behavior in crypto_inc()
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 14 Feb 2017 21:51:02 +0000 (21:51 +0000)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 9 Mar 2017 10:34:17 +0000 (18:34 +0800)
commit27c539aeffe2851bf9aeeeba8a58038187a05019
tree7b886932aea0c06725a51b0cee0ff02b6cf63a4d
parentb56f5cbc7e08ec7d31c42fc41e5247677f20b143
crypto: algapi - annotate expected branch behavior in crypto_inc()

To prevent unnecessary branching, mark the exit condition of the
primary loop as likely(), given that a carry in a 32-bit counter
occurs very rarely.

On arm64, the resulting code is emitted by GCC as

     9a8:   cmp     w1, #0x3
     9ac:   add     x3, x0, w1, uxtw
     9b0:   b.ls    9e0 <crypto_inc+0x38>
     9b4:   ldr     w2, [x3,#-4]!
     9b8:   rev     w2, w2
     9bc:   add     w2, w2, #0x1
     9c0:   rev     w4, w2
     9c4:   str     w4, [x3]
     9c8:   cbz     w2, 9d0 <crypto_inc+0x28>
     9cc:   ret

where the two remaining branch conditions (one for size < 4 and one for
the carry) are statically predicted as non-taken, resulting in optimal
execution in the vast majority of cases.

Also, replace the open coded alignment test with IS_ALIGNED().

Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/algapi.c