Text file src/crypto/aes/asm_amd64.s

     1  // Code generated by command: go run asm_amd64.go -out ../../asm_amd64.s -pkg aes. DO NOT EDIT.
     2  
     3  //go:build !purego
     4  
     5  #include "textflag.h"
     6  
     7  // func encryptBlockAsm(nr int, xk *uint32, dst *byte, src *byte)
     8  // Requires: AES, SSE, SSE2
     9  TEXT ·encryptBlockAsm(SB), NOSPLIT, $0-32
    10  	MOVQ   nr+0(FP), CX
    11  	MOVQ   xk+8(FP), AX
    12  	MOVQ   dst+16(FP), DX
    13  	MOVQ   src+24(FP), BX
    14  	MOVUPS (AX), X1
    15  	MOVUPS (BX), X0
    16  	ADDQ   $0x10, AX
    17  	PXOR   X1, X0
    18  	SUBQ   $0x0c, CX
    19  	JE     Lenc192
    20  	JB     Lenc128
    21  	MOVUPS (AX), X1
    22  	AESENC X1, X0
    23  	MOVUPS 16(AX), X1
    24  	AESENC X1, X0
    25  	ADDQ   $0x20, AX
    26  
    27  Lenc192:
    28  	MOVUPS (AX), X1
    29  	AESENC X1, X0
    30  	MOVUPS 16(AX), X1
    31  	AESENC X1, X0
    32  	ADDQ   $0x20, AX
    33  
    34  Lenc128:
    35  	MOVUPS     (AX), X1
    36  	AESENC     X1, X0
    37  	MOVUPS     16(AX), X1
    38  	AESENC     X1, X0
    39  	MOVUPS     32(AX), X1
    40  	AESENC     X1, X0
    41  	MOVUPS     48(AX), X1
    42  	AESENC     X1, X0
    43  	MOVUPS     64(AX), X1
    44  	AESENC     X1, X0
    45  	MOVUPS     80(AX), X1
    46  	AESENC     X1, X0
    47  	MOVUPS     96(AX), X1
    48  	AESENC     X1, X0
    49  	MOVUPS     112(AX), X1
    50  	AESENC     X1, X0
    51  	MOVUPS     128(AX), X1
    52  	AESENC     X1, X0
    53  	MOVUPS     144(AX), X1
    54  	AESENCLAST X1, X0
    55  	MOVUPS     X0, (DX)
    56  	RET
    57  
    58  // func decryptBlockAsm(nr int, xk *uint32, dst *byte, src *byte)
    59  // Requires: AES, SSE, SSE2
    60  TEXT ·decryptBlockAsm(SB), NOSPLIT, $0-32
    61  	MOVQ   nr+0(FP), CX
    62  	MOVQ   xk+8(FP), AX
    63  	MOVQ   dst+16(FP), DX
    64  	MOVQ   src+24(FP), BX
    65  	MOVUPS (AX), X1
    66  	MOVUPS (BX), X0
    67  	ADDQ   $0x10, AX
    68  	PXOR   X1, X0
    69  	SUBQ   $0x0c, CX
    70  	JE     Ldec192
    71  	JB     Ldec128
    72  	MOVUPS (AX), X1
    73  	AESDEC X1, X0
    74  	MOVUPS 16(AX), X1
    75  	AESDEC X1, X0
    76  	ADDQ   $0x20, AX
    77  
    78  Ldec192:
    79  	MOVUPS (AX), X1
    80  	AESDEC X1, X0
    81  	MOVUPS 16(AX), X1
    82  	AESDEC X1, X0
    83  	ADDQ   $0x20, AX
    84  
    85  Ldec128:
    86  	MOVUPS     (AX), X1
    87  	AESDEC     X1, X0
    88  	MOVUPS     16(AX), X1
    89  	AESDEC     X1, X0
    90  	MOVUPS     32(AX), X1
    91  	AESDEC     X1, X0
    92  	MOVUPS     48(AX), X1
    93  	AESDEC     X1, X0
    94  	MOVUPS     64(AX), X1
    95  	AESDEC     X1, X0
    96  	MOVUPS     80(AX), X1
    97  	AESDEC     X1, X0
    98  	MOVUPS     96(AX), X1
    99  	AESDEC     X1, X0
   100  	MOVUPS     112(AX), X1
   101  	AESDEC     X1, X0
   102  	MOVUPS     128(AX), X1
   103  	AESDEC     X1, X0
   104  	MOVUPS     144(AX), X1
   105  	AESDECLAST X1, X0
   106  	MOVUPS     X0, (DX)
   107  	RET
   108  
   109  // func expandKeyAsm(nr int, key *byte, enc *uint32, dec *uint32)
   110  // Requires: AES, SSE, SSE2
   111  TEXT ·expandKeyAsm(SB), NOSPLIT, $0-32
   112  	MOVQ   nr+0(FP), CX
   113  	MOVQ   key+8(FP), AX
   114  	MOVQ   enc+16(FP), BX
   115  	MOVQ   dec+24(FP), DX
   116  	MOVUPS (AX), X0
   117  
   118  	// enc
   119  	MOVUPS          X0, (BX)
   120  	ADDQ            $0x10, BX
   121  	PXOR            X4, X4
   122  	CMPL            CX, $0x0c
   123  	JE              Lexp_enc192
   124  	JB              Lexp_enc128
   125  	MOVUPS          16(AX), X2
   126  	MOVUPS          X2, (BX)
   127  	ADDQ            $0x10, BX
   128  	AESKEYGENASSIST $0x01, X2, X1
   129  	CALL            _expand_key_256a<>(SB)
   130  	AESKEYGENASSIST $0x01, X0, X1
   131  	CALL            _expand_key_256b<>(SB)
   132  	AESKEYGENASSIST $0x02, X2, X1
   133  	CALL            _expand_key_256a<>(SB)
   134  	AESKEYGENASSIST $0x02, X0, X1
   135  	CALL            _expand_key_256b<>(SB)
   136  	AESKEYGENASSIST $0x04, X2, X1
   137  	CALL            _expand_key_256a<>(SB)
   138  	AESKEYGENASSIST $0x04, X0, X1
   139  	CALL            _expand_key_256b<>(SB)
   140  	AESKEYGENASSIST $0x08, X2, X1
   141  	CALL            _expand_key_256a<>(SB)
   142  	AESKEYGENASSIST $0x08, X0, X1
   143  	CALL            _expand_key_256b<>(SB)
   144  	AESKEYGENASSIST $0x10, X2, X1
   145  	CALL            _expand_key_256a<>(SB)
   146  	AESKEYGENASSIST $0x10, X0, X1
   147  	CALL            _expand_key_256b<>(SB)
   148  	AESKEYGENASSIST $0x20, X2, X1
   149  	CALL            _expand_key_256a<>(SB)
   150  	AESKEYGENASSIST $0x20, X0, X1
   151  	CALL            _expand_key_256b<>(SB)
   152  	AESKEYGENASSIST $0x40, X2, X1
   153  	CALL            _expand_key_256a<>(SB)
   154  	JMP             Lexp_dec
   155  
   156  Lexp_enc192:
   157  	MOVQ            16(AX), X2
   158  	AESKEYGENASSIST $0x01, X2, X1
   159  	CALL            _expand_key_192a<>(SB)
   160  	AESKEYGENASSIST $0x02, X2, X1
   161  	CALL            _expand_key_192b<>(SB)
   162  	AESKEYGENASSIST $0x04, X2, X1
   163  	CALL            _expand_key_192a<>(SB)
   164  	AESKEYGENASSIST $0x08, X2, X1
   165  	CALL            _expand_key_192b<>(SB)
   166  	AESKEYGENASSIST $0x10, X2, X1
   167  	CALL            _expand_key_192a<>(SB)
   168  	AESKEYGENASSIST $0x20, X2, X1
   169  	CALL            _expand_key_192b<>(SB)
   170  	AESKEYGENASSIST $0x40, X2, X1
   171  	CALL            _expand_key_192a<>(SB)
   172  	AESKEYGENASSIST $0x80, X2, X1
   173  	CALL            _expand_key_192b<>(SB)
   174  	JMP             Lexp_dec
   175  
   176  Lexp_enc128:
   177  	AESKEYGENASSIST $0x01, X0, X1
   178  	CALL            _expand_key_128<>(SB)
   179  	AESKEYGENASSIST $0x02, X0, X1
   180  	CALL            _expand_key_128<>(SB)
   181  	AESKEYGENASSIST $0x04, X0, X1
   182  	CALL            _expand_key_128<>(SB)
   183  	AESKEYGENASSIST $0x08, X0, X1
   184  	CALL            _expand_key_128<>(SB)
   185  	AESKEYGENASSIST $0x10, X0, X1
   186  	CALL            _expand_key_128<>(SB)
   187  	AESKEYGENASSIST $0x20, X0, X1
   188  	CALL            _expand_key_128<>(SB)
   189  	AESKEYGENASSIST $0x40, X0, X1
   190  	CALL            _expand_key_128<>(SB)
   191  	AESKEYGENASSIST $0x80, X0, X1
   192  	CALL            _expand_key_128<>(SB)
   193  	AESKEYGENASSIST $0x1b, X0, X1
   194  	CALL            _expand_key_128<>(SB)
   195  	AESKEYGENASSIST $0x36, X0, X1
   196  	CALL            _expand_key_128<>(SB)
   197  
   198  Lexp_dec:
   199  	// dec
   200  	SUBQ   $0x10, BX
   201  	MOVUPS (BX), X1
   202  	MOVUPS X1, (DX)
   203  	DECQ   CX
   204  
   205  Lexp_dec_loop:
   206  	MOVUPS -16(BX), X1
   207  	AESIMC X1, X0
   208  	MOVUPS X0, 16(DX)
   209  	SUBQ   $0x10, BX
   210  	ADDQ   $0x10, DX
   211  	DECQ   CX
   212  	JNZ    Lexp_dec_loop
   213  	MOVUPS -16(BX), X0
   214  	MOVUPS X0, 16(DX)
   215  	RET
   216  
   217  // func _expand_key_128<>()
   218  // Requires: SSE, SSE2
   219  TEXT _expand_key_128<>(SB), NOSPLIT, $0
   220  	PSHUFD $0xff, X1, X1
   221  	SHUFPS $0x10, X0, X4
   222  	PXOR   X4, X0
   223  	SHUFPS $0x8c, X0, X4
   224  	PXOR   X4, X0
   225  	PXOR   X1, X0
   226  	MOVUPS X0, (BX)
   227  	ADDQ   $0x10, BX
   228  	RET
   229  
   230  // func _expand_key_192a<>()
   231  // Requires: SSE, SSE2
   232  TEXT _expand_key_192a<>(SB), NOSPLIT, $0
   233  	PSHUFD $0x55, X1, X1
   234  	SHUFPS $0x10, X0, X4
   235  	PXOR   X4, X0
   236  	SHUFPS $0x8c, X0, X4
   237  	PXOR   X4, X0
   238  	PXOR   X1, X0
   239  	MOVAPS X2, X5
   240  	MOVAPS X2, X6
   241  	PSLLDQ $0x04, X5
   242  	PSHUFD $0xff, X0, X3
   243  	PXOR   X3, X2
   244  	PXOR   X5, X2
   245  	MOVAPS X0, X1
   246  	SHUFPS $0x44, X0, X6
   247  	MOVUPS X6, (BX)
   248  	SHUFPS $0x4e, X2, X1
   249  	MOVUPS X1, 16(BX)
   250  	ADDQ   $0x20, BX
   251  	RET
   252  
   253  // func _expand_key_192b<>()
   254  // Requires: SSE, SSE2
   255  TEXT _expand_key_192b<>(SB), NOSPLIT, $0
   256  	PSHUFD $0x55, X1, X1
   257  	SHUFPS $0x10, X0, X4
   258  	PXOR   X4, X0
   259  	SHUFPS $0x8c, X0, X4
   260  	PXOR   X4, X0
   261  	PXOR   X1, X0
   262  	MOVAPS X2, X5
   263  	PSLLDQ $0x04, X5
   264  	PSHUFD $0xff, X0, X3
   265  	PXOR   X3, X2
   266  	PXOR   X5, X2
   267  	MOVUPS X0, (BX)
   268  	ADDQ   $0x10, BX
   269  	RET
   270  
   271  // func _expand_key_256a<>()
   272  TEXT _expand_key_256a<>(SB), NOSPLIT, $0
   273  	JMP _expand_key_128<>(SB)
   274  
   275  // func _expand_key_256b<>()
   276  // Requires: SSE, SSE2
   277  TEXT _expand_key_256b<>(SB), NOSPLIT, $0
   278  	PSHUFD $0xaa, X1, X1
   279  	SHUFPS $0x10, X2, X4
   280  	PXOR   X4, X2
   281  	SHUFPS $0x8c, X2, X4
   282  	PXOR   X4, X2
   283  	PXOR   X1, X2
   284  	MOVUPS X2, (BX)
   285  	ADDQ   $0x10, BX
   286  	RET
   287  

View as plain text