Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.40 KB | None | 0 0
  1. EBC encryption: 5.833 GB/s
  2. EBC encryption blocked: 802.582 MB/s
  3. EBC decryption: 5.74 GB/s
  4. EBC decryption blocked: 802.291 MB/s
  5.  
  6. public void EncryptEcb(Span<byte> data)
  7. {
  8.     Vector128<byte>[] keys = RoundKeys;
  9.     Span<Vector128<byte>> blocks = MemoryMarshal.Cast<byte, Vector128<byte>>(data);
  10.  
  11.     // Makes the JIT remove all the other range checks on keys
  12.     Vector128<byte> key10 = keys[10];
  13.  
  14.     for (int i = 0; i < blocks.Length; i++)
  15.     {
  16.         Vector128<byte> b = blocks[i];
  17.  
  18.         b = Sse2.Xor(b, keys[0]);
  19.         b = Aes.Encrypt(b, keys[1]);
  20.         b = Aes.Encrypt(b, keys[2]);
  21.         b = Aes.Encrypt(b, keys[3]);
  22.         b = Aes.Encrypt(b, keys[4]);
  23.         b = Aes.Encrypt(b, keys[5]);
  24.         b = Aes.Encrypt(b, keys[6]);
  25.         b = Aes.Encrypt(b, keys[7]);
  26.         b = Aes.Encrypt(b, keys[8]);
  27.         b = Aes.Encrypt(b, keys[9]);
  28.         b = Aes.EncryptLast(b, keys[10]);
  29.  
  30.         blocks[i] = b;
  31.     }
  32. }
  33.  
  34.  
  35. ; Assembly listing for method AesContext:EncryptEcb(struct):this
  36. ; Emitting BLENDED_CODE for X64 CPU with AVX - Windows
  37. ; optimized code
  38. ; rsp based frame
  39. ; fully interruptible
  40. ; Final local variable assignments
  41. ;
  42. ;  V00 this         [V00,T06] (  3,  3   )     ref  ->  rcx         this class-hnd
  43. ;  V01 arg1         [V01,T04] (  4,  8   )   byref  ->  rdx        
  44. ;  V02 loc0         [V02,T01] ( 13, 46   )     ref  ->  rax         class-hnd
  45. ;* V03 loc1         [V03    ] (  0,  0   )  struct (16) zero-ref    ld-addr-op
  46. ;  V04 loc2         [V04,T02] (  5, 17   )     int  ->   r8        
  47. ;  V05 loc3         [V05,T00] ( 24, 96   )  simd16  ->  mm0        
  48. ;  V06 OutArgs      [V06    ] (  1,  1   )  lclBlk (32) [rsp+0x00]   "OutgoingArgSpace"
  49. ;* V07 tmp1         [V07,T16] (  0,  0   )     int  ->  zero-ref    "Inline stloc first use temp"
  50. ;* V08 tmp2         [V08,T17] (  0,  0   )     int  ->  zero-ref    "Inline stloc first use temp"
  51. ;* V09 tmp3         [V09    ] (  0,  0   )  struct (16) zero-ref    ld-addr-op "Inlining Arg"
  52. ;  V10 tmp4         [V10,T11] (  2,  2   )     int  ->  rdx         "Inline stloc first use temp"
  53. ;* V11 tmp5         [V11    ] (  0,  0   )    long  ->  zero-ref    "Inline stloc first use temp"
  54. ;  V12 tmp6         [V12,T12] (  2,  2   )     int  ->  rdx         "Inline stloc first use temp"
  55. ;* V13 tmp7         [V13    ] (  0,  0   )  struct (16) zero-ref    "NewObj constructor temp"
  56. ;* V14 tmp8         [V14    ] (  0,  0   )   byref  ->  zero-ref    "Inlining Arg"
  57. ;* V15 tmp9         [V15    ] (  0,  0   )  struct ( 8) zero-ref    "NewObj constructor temp"
  58. ;* V16 tmp10        [V16    ] (  0,  0   )   byref  ->  zero-ref    V25._pointer(offs=0x00) P-INDEP "field V01._pointer (fldOffset=0x0)"
  59. ;* V17 tmp11        [V17    ] (  0,  0   )     int  ->  zero-ref    V25._length(offs=0x08) P-INDEP "field V01._length (fldOffset=0x8)"
  60. ;  V18 tmp12        [V18,T07] (  2,  5   )   byref  ->  rcx         V03._pointer(offs=0x00) P-INDEP "field V03._pointer (fldOffset=0x0)"
  61. ;  V19 tmp13        [V19,T05] (  3,  6   )     int  ->  rdx         V03._length(offs=0x08) P-INDEP "field V03._length (fldOffset=0x8)"
  62. ;  V20 tmp14        [V20,T08] (  2,  2   )   byref  ->  rcx         V09._pointer(offs=0x00) P-INDEP "field V09._pointer (fldOffset=0x0)"
  63. ;  V21 tmp15        [V21,T13] (  2,  2   )     int  ->  rdx         V09._length(offs=0x08) P-INDEP "field V09._length (fldOffset=0x8)"
  64. ;  V22 tmp16        [V22,T09] (  2,  2   )   byref  ->  rcx         V13._pointer(offs=0x00) P-INDEP "field V13._pointer (fldOffset=0x0)"
  65. ;  V23 tmp17        [V23,T14] (  2,  2   )     int  ->  rdx         V13._length(offs=0x08) P-INDEP "field V13._length (fldOffset=0x8)"
  66. ;  V24 tmp18        [V24,T10] (  2,  2   )   byref  ->  rcx         V15._value(offs=0x00) P-INDEP "field V15._value (fldOffset=0x0)"
  67. ;* V25 tmp19        [V25    ] (  0,  0   )  struct (16) zero-ref    "Promoted implicit byref"
  68. ;  V26 cse0         [V26,T03] (  3, 12   )   byref  ->   r9         "ValNumCSE"
  69. ;* V27 cse1         [V27    ] (  0,  0   )    long  ->  zero-ref    "ValNumCSE"
  70. ;  V28 cse2         [V28,T15] (  2,  2   )     int  ->   r8         "ValNumCSE"
  71. ;
  72. ; Lcl frame size = 40
  73.  
  74. G_M18342_IG02:
  75.        mov      rax, gword ptr [rcx+8]
  76.        mov      rcx, bword ptr [rdx]
  77.        mov      edx, dword ptr [rdx+8]
  78.        shr      edx, 4
  79.        mov      r8d, dword ptr [rax+8]
  80.        cmp      r8d, 10
  81.        jbe      G_M18342_IG06
  82.        xor      r8d, r8d
  83.        test     edx, edx
  84.        jle      SHORT G_M18342_IG04
  85.  
  86. G_M18342_IG03:
  87.        movsxd   r9, r8d
  88.        shl      r9, 4
  89.        add      r9, rcx
  90.        vmovupd  xmm0, xmmword ptr [r9]
  91.        vpxor    xmm0, xmm0, xmmword ptr [rax+16]
  92.        vaesenc  xmm0, xmm0, xmmword ptr [rax+32]
  93.        vaesenc  xmm0, xmm0, xmmword ptr [rax+48]
  94.        vaesenc  xmm0, xmm0, xmmword ptr [rax+64]
  95.        vaesenc  xmm0, xmm0, xmmword ptr [rax+80]
  96.        vaesenc  xmm0, xmm0, xmmword ptr [rax+96]
  97.        vaesenc  xmm0, xmm0, xmmword ptr [rax+112]
  98.        vaesenc  xmm0, xmm0, xmmword ptr [rax+128]
  99.        vaesenc  xmm0, xmm0, xmmword ptr [rax+144]
  100.        vaesenc  xmm0, xmm0, xmmword ptr [rax+160]
  101.        vaesenclast xmm0, xmm0, xmmword ptr [rax+176]
  102.        vmovupd  xmmword ptr [r9], xmm0
  103.        inc      r8d
  104.        cmp      r8d, edx
  105.        jl       SHORT G_M18342_IG03
  106.  
  107. G_M18342_IG04:
  108.        add      rsp, 40
  109.        ret      
  110.  
  111. G_M18342_IG05:
  112.        call     CORINFO_HELP_OVERFLOW
  113.        int3    
  114.  
  115. ; Total bytes of code 163, prolog size 7 for method AesContext:EncryptEcb(struct):this
  116. ; ============================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement