Converted to new SIMD: -m 1760 -a 0
authorJens Steube <jens.steube@gmail.com>
Fri, 5 Feb 2016 17:01:37 +0000 (18:01 +0100)
committerJens Steube <jens.steube@gmail.com>
Fri, 5 Feb 2016 17:01:37 +0000 (18:01 +0100)
OpenCL/m01760_a0.cl

index cf23b3e..4c44129 100644 (file)
@@ -5,6 +5,8 @@
 
 #define _SHA512_
 
+#define NEW_SIMD_CODE
+
 #include "include/constants.h"
 #include "include/kernel_vendor.h"
 
@@ -18,9 +20,7 @@
 #include "OpenCL/common.c"
 #include "include/rp_kernel.h"
 #include "OpenCL/rp.c"
-
-#define COMPARE_S "OpenCL/check_single_comp4.c"
-#define COMPARE_M "OpenCL/check_multi_comp4.c"
+#include "OpenCL/simd.c"
 
 __constant u64 k_sha512[80] =
 {
@@ -46,33 +46,33 @@ __constant u64 k_sha512[80] =
   SHA512C4c, SHA512C4d, SHA512C4e, SHA512C4f,
 };
 
-static void sha512_transform (const u64 w0[4], const u64 w1[4], const u64 w2[4], const u64 w3[4], u64 digest[8])
+static void sha512_transform (const u64x w0[4], const u64x w1[4], const u64x w2[4], const u64x w3[4], u64x digest[8])
 {
-  u64 w0_t = w0[0];
-  u64 w1_t = w0[1];
-  u64 w2_t = w0[2];
-  u64 w3_t = w0[3];
-  u64 w4_t = w1[0];
-  u64 w5_t = w1[1];
-  u64 w6_t = w1[2];
-  u64 w7_t = w1[3];
-  u64 w8_t = w2[0];
-  u64 w9_t = w2[1];
-  u64 wa_t = w2[2];
-  u64 wb_t = w2[3];
-  u64 wc_t = w3[0];
-  u64 wd_t = w3[1];
-  u64 we_t = w3[2];
-  u64 wf_t = w3[3];
-
-  u64 a = digest[0];
-  u64 b = digest[1];
-  u64 c = digest[2];
-  u64 d = digest[3];
-  u64 e = digest[4];
-  u64 f = digest[5];
-  u64 g = digest[6];
-  u64 h = digest[7];
+  u64x w0_t = w0[0];
+  u64x w1_t = w0[1];
+  u64x w2_t = w0[2];
+  u64x w3_t = w0[3];
+  u64x w4_t = w1[0];
+  u64x w5_t = w1[1];
+  u64x w6_t = w1[2];
+  u64x w7_t = w1[3];
+  u64x w8_t = w2[0];
+  u64x w9_t = w2[1];
+  u64x wa_t = w2[2];
+  u64x wb_t = w2[3];
+  u64x wc_t = w3[0];
+  u64x wd_t = w3[1];
+  u64x we_t = w3[2];
+  u64x wf_t = w3[3];
+
+  u64x a = digest[0];
+  u64x b = digest[1];
+  u64x c = digest[2];
+  u64x d = digest[3];
+  u64x e = digest[4];
+  u64x f = digest[5];
+  u64x g = digest[6];
+  u64x h = digest[7];
 
   #define ROUND_EXPAND()                            \
   {                                                 \
@@ -132,29 +132,29 @@ static void sha512_transform (const u64 w0[4], const u64 w1[4], const u64 w2[4],
   digest[7] += h;
 }
 
-static void hmac_sha512_pad (u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], u64 ipad[8], u64 opad[8])
+static void hmac_sha512_pad (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u64x ipad[8], u64x opad[8])
 {
-  u64 w0_t[4];
-  u64 w1_t[4];
-  u64 w2_t[4];
-  u64 w3_t[4];
-
-  w0_t[0] = hl32_to_64 (w0[0], w0[1]) ^ 0x3636363636363636;
-  w0_t[1] = hl32_to_64 (w0[2], w0[3]) ^ 0x3636363636363636;
-  w0_t[2] = hl32_to_64 (w1[0], w1[1]) ^ 0x3636363636363636;
-  w0_t[3] = hl32_to_64 (w1[2], w1[3]) ^ 0x3636363636363636;
-  w1_t[0] = hl32_to_64 (w2[0], w2[1]) ^ 0x3636363636363636;
-  w1_t[1] = hl32_to_64 (w2[2], w2[3]) ^ 0x3636363636363636;
-  w1_t[2] = hl32_to_64 (w3[0], w3[1]) ^ 0x3636363636363636;
-  w1_t[3] = hl32_to_64 (w3[2], w3[3]) ^ 0x3636363636363636;
-  w2_t[0] =                                 0 ^ 0x3636363636363636;
-  w2_t[1] =                                 0 ^ 0x3636363636363636;
-  w2_t[2] =                                 0 ^ 0x3636363636363636;
-  w2_t[3] =                                 0 ^ 0x3636363636363636;
-  w3_t[0] =                                 0 ^ 0x3636363636363636;
-  w3_t[1] =                                 0 ^ 0x3636363636363636;
-  w3_t[2] =                                 0 ^ 0x3636363636363636;
-  w3_t[3] =                                 0 ^ 0x3636363636363636;
+  u64x w0_t[4];
+  u64x w1_t[4];
+  u64x w2_t[4];
+  u64x w3_t[4];
+
+  w0_t[0] = hl32_to_64 (w0[0], w0[1]) ^ (u64x) 0x3636363636363636;
+  w0_t[1] = hl32_to_64 (w0[2], w0[3]) ^ (u64x) 0x3636363636363636;
+  w0_t[2] = hl32_to_64 (w1[0], w1[1]) ^ (u64x) 0x3636363636363636;
+  w0_t[3] = hl32_to_64 (w1[2], w1[3]) ^ (u64x) 0x3636363636363636;
+  w1_t[0] = hl32_to_64 (w2[0], w2[1]) ^ (u64x) 0x3636363636363636;
+  w1_t[1] = hl32_to_64 (w2[2], w2[3]) ^ (u64x) 0x3636363636363636;
+  w1_t[2] = hl32_to_64 (w3[0], w3[1]) ^ (u64x) 0x3636363636363636;
+  w1_t[3] = hl32_to_64 (w3[2], w3[3]) ^ (u64x) 0x3636363636363636;
+  w2_t[0] =                             (u64x) 0x3636363636363636;
+  w2_t[1] =                             (u64x) 0x3636363636363636;
+  w2_t[2] =                             (u64x) 0x3636363636363636;
+  w2_t[3] =                             (u64x) 0x3636363636363636;
+  w3_t[0] =                             (u64x) 0x3636363636363636;
+  w3_t[1] =                             (u64x) 0x3636363636363636;
+  w3_t[2] =                             (u64x) 0x3636363636363636;
+  w3_t[3] =                             (u64x) 0x3636363636363636;
 
   ipad[0] = SHA512M_A;
   ipad[1] = SHA512M_B;
@@ -167,22 +167,22 @@ static void hmac_sha512_pad (u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], u64 ipa
 
   sha512_transform (w0_t, w1_t, w2_t, w3_t, ipad);
 
-  w0_t[0] = hl32_to_64 (w0[0], w0[1]) ^ 0x5c5c5c5c5c5c5c5c;
-  w0_t[1] = hl32_to_64 (w0[2], w0[3]) ^ 0x5c5c5c5c5c5c5c5c;
-  w0_t[2] = hl32_to_64 (w1[0], w1[1]) ^ 0x5c5c5c5c5c5c5c5c;
-  w0_t[3] = hl32_to_64 (w1[2], w1[3]) ^ 0x5c5c5c5c5c5c5c5c;
-  w1_t[0] = hl32_to_64 (w2[0], w2[1]) ^ 0x5c5c5c5c5c5c5c5c;
-  w1_t[1] = hl32_to_64 (w2[2], w2[3]) ^ 0x5c5c5c5c5c5c5c5c;
-  w1_t[2] = hl32_to_64 (w3[0], w3[1]) ^ 0x5c5c5c5c5c5c5c5c;
-  w1_t[3] = hl32_to_64 (w3[2], w3[3]) ^ 0x5c5c5c5c5c5c5c5c;
-  w2_t[0] =                                 0 ^ 0x5c5c5c5c5c5c5c5c;
-  w2_t[1] =                                 0 ^ 0x5c5c5c5c5c5c5c5c;
-  w2_t[2] =                                 0 ^ 0x5c5c5c5c5c5c5c5c;
-  w2_t[3] =                                 0 ^ 0x5c5c5c5c5c5c5c5c;
-  w3_t[0] =                                 0 ^ 0x5c5c5c5c5c5c5c5c;
-  w3_t[1] =                                 0 ^ 0x5c5c5c5c5c5c5c5c;
-  w3_t[2] =                                 0 ^ 0x5c5c5c5c5c5c5c5c;
-  w3_t[3] =                                 0 ^ 0x5c5c5c5c5c5c5c5c;
+  w0_t[0] = hl32_to_64 (w0[0], w0[1]) ^ (u64x) 0x5c5c5c5c5c5c5c5c;
+  w0_t[1] = hl32_to_64 (w0[2], w0[3]) ^ (u64x) 0x5c5c5c5c5c5c5c5c;
+  w0_t[2] = hl32_to_64 (w1[0], w1[1]) ^ (u64x) 0x5c5c5c5c5c5c5c5c;
+  w0_t[3] = hl32_to_64 (w1[2], w1[3]) ^ (u64x) 0x5c5c5c5c5c5c5c5c;
+  w1_t[0] = hl32_to_64 (w2[0], w2[1]) ^ (u64x) 0x5c5c5c5c5c5c5c5c;
+  w1_t[1] = hl32_to_64 (w2[2], w2[3]) ^ (u64x) 0x5c5c5c5c5c5c5c5c;
+  w1_t[2] = hl32_to_64 (w3[0], w3[1]) ^ (u64x) 0x5c5c5c5c5c5c5c5c;
+  w1_t[3] = hl32_to_64 (w3[2], w3[3]) ^ (u64x) 0x5c5c5c5c5c5c5c5c;
+  w2_t[0] =                             (u64x) 0x5c5c5c5c5c5c5c5c;
+  w2_t[1] =                             (u64x) 0x5c5c5c5c5c5c5c5c;
+  w2_t[2] =                             (u64x) 0x5c5c5c5c5c5c5c5c;
+  w2_t[3] =                             (u64x) 0x5c5c5c5c5c5c5c5c;
+  w3_t[0] =                             (u64x) 0x5c5c5c5c5c5c5c5c;
+  w3_t[1] =                             (u64x) 0x5c5c5c5c5c5c5c5c;
+  w3_t[2] =                             (u64x) 0x5c5c5c5c5c5c5c5c;
+  w3_t[3] =                             (u64x) 0x5c5c5c5c5c5c5c5c;
 
   opad[0] = SHA512M_A;
   opad[1] = SHA512M_B;
@@ -196,12 +196,12 @@ static void hmac_sha512_pad (u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], u64 ipa
   sha512_transform (w0_t, w1_t, w2_t, w3_t, opad);
 }
 
-static void hmac_sha512_run (u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], u64 ipad[8], u64 opad[8], u64 digest[8])
+static void hmac_sha512_run (u32x w0[4], u32x w1[4], u32x w2[4], u32x w3[4], u64x ipad[8], u64x opad[8], u64x digest[8])
 {
-  u64 w0_t[4];
-  u64 w1_t[4];
-  u64 w2_t[4];
-  u64 w3_t[4];
+  u64x w0_t[4];
+  u64x w1_t[4];
+  u64x w2_t[4];
+  u64x w3_t[4];
 
   w0_t[0] = hl32_to_64 (w0[0], w0[1]);
   w0_t[1] = hl32_to_64 (w0[2], w0[3]);
@@ -314,36 +314,36 @@ __kernel void m01760_m04 (__global pw_t *pws, __global kernel_rule_t *  rules_bu
    * pads
    */
 
-  u32 w0_t[4];
+  u32x w0_t[4];
 
   w0_t[0] = swap32 (salt_buf0[0]);
   w0_t[1] = swap32 (salt_buf0[1]);
   w0_t[2] = swap32 (salt_buf0[2]);
   w0_t[3] = swap32 (salt_buf0[3]);
 
-  u32 w1_t[4];
+  u32x w1_t[4];
 
   w1_t[0] = swap32 (salt_buf1[0]);
   w1_t[1] = swap32 (salt_buf1[1]);
   w1_t[2] = swap32 (salt_buf1[2]);
   w1_t[3] = swap32 (salt_buf1[3]);
 
-  u32 w2_t[4];
+  u32x w2_t[4];
 
   w2_t[0] = 0;
   w2_t[1] = 0;
   w2_t[2] = 0;
   w2_t[3] = 0;
 
-  u32 w3_t[4];
+  u32x w3_t[4];
 
   w3_t[0] = 0;
   w3_t[1] = 0;
   w3_t[2] = 0;
   w3_t[3] = 0;
 
-  u64 ipad[8];
-  u64 opad[8];
+  u64x ipad[8];
+  u64x opad[8];
 
   hmac_sha512_pad (w0_t, w1_t, w2_t, w3_t, ipad, opad);
 
@@ -351,37 +351,14 @@ __kernel void m01760_m04 (__global pw_t *pws, __global kernel_rule_t *  rules_bu
    * loop
    */
 
-  for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
+  for (u32 il_pos = 0; il_pos < rules_cnt; il_pos += VECT_SIZE)
   {
-    u32 w0[4];
-
-    w0[0] = pw_buf0[0];
-    w0[1] = pw_buf0[1];
-    w0[2] = pw_buf0[2];
-    w0[3] = pw_buf0[3];
-
-    u32 w1[4];
-
-    w1[0] = pw_buf1[0];
-    w1[1] = pw_buf1[1];
-    w1[2] = pw_buf1[2];
-    w1[3] = pw_buf1[3];
-
-    u32 w2[4];
-
-    w2[0] = 0;
-    w2[1] = 0;
-    w2[2] = 0;
-    w2[3] = 0;
-
-    u32 w3[4];
-
-    w3[0] = 0;
-    w3[1] = 0;
-    w3[2] = 0;
-    w3[3] = 0;
+    u32x w0[4] = { 0 };
+    u32x w1[4] = { 0 };
+    u32x w2[4] = { 0 };
+    u32x w3[4] = { 0 };
 
-    const u32 out_len = apply_rules (rules_buf[il_pos].cmds, w0, w1, pw_len);
+    const u32 out_len = apply_rules_vect (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1);
 
     append_0x80_2x4 (w0, w1, out_len);
 
@@ -402,17 +379,16 @@ __kernel void m01760_m04 (__global pw_t *pws, __global kernel_rule_t *  rules_bu
     w3_t[2] = 0;
     w3_t[3] = (128 + out_len) * 8;
 
-    u64 digest[8];
+    u64x digest[8];
 
     hmac_sha512_run (w0_t, w1_t, w2_t, w3_t, ipad, opad, digest);
 
+    const u32x r0 = l32_from_64 (digest[7]);
+    const u32x r1 = h32_from_64 (digest[7]);
+    const u32x r2 = l32_from_64 (digest[3]);
+    const u32x r3 = h32_from_64 (digest[3]);
 
-    const u32 r0 = l32_from_64 (digest[7]);
-    const u32 r1 = h32_from_64 (digest[7]);
-    const u32 r2 = l32_from_64 (digest[3]);
-    const u32 r3 = h32_from_64 (digest[3]);
-
-    #include COMPARE_M
+    COMPARE_M_SIMD (r0, r1, r2, r3);
   }
 }
 
@@ -478,36 +454,36 @@ __kernel void m01760_s04 (__global pw_t *pws, __global kernel_rule_t *  rules_bu
    * pads
    */
 
-  u32 w0_t[4];
+  u32x w0_t[4];
 
   w0_t[0] = swap32 (salt_buf0[0]);
   w0_t[1] = swap32 (salt_buf0[1]);
   w0_t[2] = swap32 (salt_buf0[2]);
   w0_t[3] = swap32 (salt_buf0[3]);
 
-  u32 w1_t[4];
+  u32x w1_t[4];
 
   w1_t[0] = swap32 (salt_buf1[0]);
   w1_t[1] = swap32 (salt_buf1[1]);
   w1_t[2] = swap32 (salt_buf1[2]);
   w1_t[3] = swap32 (salt_buf1[3]);
 
-  u32 w2_t[4];
+  u32x w2_t[4];
 
   w2_t[0] = 0;
   w2_t[1] = 0;
   w2_t[2] = 0;
   w2_t[3] = 0;
 
-  u32 w3_t[4];
+  u32x w3_t[4];
 
   w3_t[0] = 0;
   w3_t[1] = 0;
   w3_t[2] = 0;
   w3_t[3] = 0;
 
-  u64 ipad[8];
-  u64 opad[8];
+  u64x ipad[8];
+  u64x opad[8];
 
   hmac_sha512_pad (w0_t, w1_t, w2_t, w3_t, ipad, opad);
 
@@ -527,37 +503,14 @@ __kernel void m01760_s04 (__global pw_t *pws, __global kernel_rule_t *  rules_bu
    * loop
    */
 
-  for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
+  for (u32 il_pos = 0; il_pos < rules_cnt; il_pos += VECT_SIZE)
   {
-    u32 w0[4];
-
-    w0[0] = pw_buf0[0];
-    w0[1] = pw_buf0[1];
-    w0[2] = pw_buf0[2];
-    w0[3] = pw_buf0[3];
-
-    u32 w1[4];
-
-    w1[0] = pw_buf1[0];
-    w1[1] = pw_buf1[1];
-    w1[2] = pw_buf1[2];
-    w1[3] = pw_buf1[3];
-
-    u32 w2[4];
+    u32x w0[4] = { 0 };
+    u32x w1[4] = { 0 };
+    u32x w2[4] = { 0 };
+    u32x w3[4] = { 0 };
 
-    w2[0] = 0;
-    w2[1] = 0;
-    w2[2] = 0;
-    w2[3] = 0;
-
-    u32 w3[4];
-
-    w3[0] = 0;
-    w3[1] = 0;
-    w3[2] = 0;
-    w3[3] = 0;
-
-    const u32 out_len = apply_rules (rules_buf[il_pos].cmds, w0, w1, pw_len);
+    const u32 out_len = apply_rules_vect (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1);
 
     append_0x80_2x4 (w0, w1, out_len);
 
@@ -578,17 +531,16 @@ __kernel void m01760_s04 (__global pw_t *pws, __global kernel_rule_t *  rules_bu
     w3_t[2] = 0;
     w3_t[3] = (128 + out_len) * 8;
 
-    u64 digest[8];
+    u64x digest[8];
 
     hmac_sha512_run (w0_t, w1_t, w2_t, w3_t, ipad, opad, digest);
 
+    const u32x r0 = l32_from_64 (digest[7]);
+    const u32x r1 = h32_from_64 (digest[7]);
+    const u32x r2 = l32_from_64 (digest[3]);
+    const u32x r3 = h32_from_64 (digest[3]);
 
-    const u32 r0 = l32_from_64 (digest[7]);
-    const u32 r1 = h32_from_64 (digest[7]);
-    const u32 r2 = l32_from_64 (digest[3]);
-    const u32 r3 = h32_from_64 (digest[3]);
-
-    #include COMPARE_S
+    COMPARE_S_SIMD (r0, r1, r2, r3);
   }
 }