Skip to content
Permalink
Browse files

Reshuffel instructions for better preformance

  • Loading branch information...
vDorst committed Sep 13, 2016
1 parent 63e21ac commit 6f9187c325ee883b1f2b9f9da3deb0a61655b504
Showing with 26 additions and 38 deletions.
  1. +26 −38 src/crypto/chacha20-mips32r2.S
@@ -554,7 +554,6 @@ END(poly1305_generic_blocks)



#define PT0 $t0
#define PT1 $t1
#define PT2 $t2
#define PT3 $t3
@@ -565,8 +564,8 @@ END(poly1305_generic_blocks)
#define PR3 $t7
#define PR4 $t8

#define PS0 $t0
#define PS1 $t1
#define PS0 $t9
#define PS1 $t0
#define PS2 $t2
#define PS3 $t3

@@ -591,42 +590,45 @@ END(poly1305_generic_blocks)
.ent poly1305_init
//.type poly1305_init, @function
ENTRY(poly1305_init)
LOAD_key(PT(0), 0)
LOAD_key(PR(0), 0)
LOAD_key(PT(1), 1)
LOAD_key(PT(2), 2)
LOAD_key(PT(3), 3)
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
wsbh PT(0)
wsbh PR(0)
wsbh PT(1)
wsbh PT(2)
wsbh PT(3)
rotr PT(0), 16
rotr PR(0), 16
rotr PT(1), 16
rotr PT(2), 16
rotr PT(3), 16
#endif
# // ctx->r[0] = t0 & 0x3ffffff;
ext PR(0), PT(0), 0, 26

# // ctx->r[4] = (t3 >> 8) & 0x00fffff;
// ctx->r[x] = shift and ANDing
SRL_U64_LSB( PR(1), PR(0), 26 )
ext PR(0), PR(0), 0, 26
SRL_U64_LSB( PR(2), PT(1), 20 )
SRL_U64_LSB( PR(3), PT(2), 14 )
ext PR(4), PT(3), 8, 20

# // t0 >>= 26; t0 |= t1 << 6;
# // ctx->r[1] = t0 & 0x3ffff03;
SRL_U64_LSB( PR(1), PT(0), 26 )
SRL_U64_MSB_UPTO26BIT( PR(1), PT(1), 26 )
AND_6BIT( PR(1), 28-26 )

# // t1 >>= 20; t1 |= t2 << 12;
# // ctx->r[2] = t1 & 0x3ffc0ff;
SRL_U64_LSB( PR(2), PT(1), 20 )
sw $zero, 36($a0)
sw $zero, 40($a0)
sw $zero, 44($a0)
sw $zero, 48($a0)

SRL_U64_MSB_UPTO26BIT( PR(1), PT(1), 26 )
SRL_U64_MSB_UPTO26BIT( PR(2), PT(2), 20 )
AND_6BIT( PR(2), 28-20 )
SRL_U64_MSB_UPTO26BIT( PR(3), PT(3), 14 )

# // t2 >>= 14; t2 |= t3 << 18;
# // ctx->r[3] = t2 & 0x3f03fff;
SRL_U64_LSB( PR(3), PT(2), 14 )
SRL_U64_MSB_UPTO26BIT( PR(3), PT(3), 14 )
sw $zero, 52($a0)
sw $zero, 56($a0)
sw $zero, 60($a0)
sw $zero, 64($a0)
sw $zero, 68($a0)
sw $zero, 72($a0)

AND_6BIT( PR(1), 28-26 )
AND_6BIT( PR(2), 28-20 )
AND_6BIT( PR(3), 28-14 )

STORE_poly_r(0)
@@ -654,20 +656,6 @@ ENTRY(poly1305_init)
STORE_poly_s(2)
STORE_poly_s(3)

// Clear rest of the struct
// H[5]
sw $zero, 36($a0)
sw $zero, 40($a0)
sw $zero, 44($a0)
sw $zero, 48($a0)
sw $zero, 52($a0)
// buf[4] (8*16)/32 = 4
sw $zero, 56($a0)
sw $zero, 60($a0)
sw $zero, 64($a0)
sw $zero, 68($a0)
// buflen
sw $zero, 72($a0)
// Jump Back
jr $ra
nop

0 comments on commit 6f9187c

Please sign in to comment.
You can’t perform that action at this time.