Converted _a3 kernels, use SIMD for CPU and GPU
[hashcat.git] / OpenCL / m11700_a3.cl
index 5d9eaa1..1dbc959 100644 (file)
@@ -5,6 +5,8 @@
 
 #define _GOST2012_256_
 
+#define NEW_SIMD_CODE
+
 #include "include/constants.h"
 #include "include/kernel_vendor.h"
 
 #include "include/kernel_functions.c"
 #include "OpenCL/types_ocl.c"
 #include "OpenCL/common.c"
-
-#define COMPARE_S "OpenCL/check_single_comp4.c"
-#define COMPARE_M "OpenCL/check_multi_comp4.c"
+#include "OpenCL/simd.c"
 
 #define INITVAL 0x0101010101010101
 
-#define SBOG_LPSti64                         \
-  s_sbob_sl64[0][(t[0] >> (i * 8)) & 0xff] ^ \
-  s_sbob_sl64[1][(t[1] >> (i * 8)) & 0xff] ^ \
-  s_sbob_sl64[2][(t[2] >> (i * 8)) & 0xff] ^ \
-  s_sbob_sl64[3][(t[3] >> (i * 8)) & 0xff] ^ \
-  s_sbob_sl64[4][(t[4] >> (i * 8)) & 0xff] ^ \
-  s_sbob_sl64[5][(t[5] >> (i * 8)) & 0xff] ^ \
-  s_sbob_sl64[6][(t[6] >> (i * 8)) & 0xff] ^ \
-  s_sbob_sl64[7][(t[7] >> (i * 8)) & 0xff]
+#if   VECT_SIZE == 1
+#define BOX(S,n,i) (S)[(n)][(i)]
+#elif VECT_SIZE == 2
+#define BOX(S,n,i) (u64x) ((S)[(n)][(i).s0], (S)[(n)][(i).s1])
+#elif VECT_SIZE == 4
+#define BOX(S,n,i) (u64x) ((S)[(n)][(i).s0], (S)[(n)][(i).s1], (S)[(n)][(i).s2], (S)[(n)][(i).s3])
+#elif VECT_SIZE == 8
+#define BOX(S,n,i) (u64x) ((S)[(n)][(i).s0], (S)[(n)][(i).s1], (S)[(n)][(i).s2], (S)[(n)][(i).s3], (S)[(n)][(i).s4], (S)[(n)][(i).s5], (S)[(n)][(i).s6], (S)[(n)][(i).s7])
+#endif
+
+#define SBOG_LPSti64                                  \
+  BOX (s_sbob_sl64, 0, ((t[0] >> (i * 8)) & 0xff)) ^  \
+  BOX (s_sbob_sl64, 1, ((t[1] >> (i * 8)) & 0xff)) ^  \
+  BOX (s_sbob_sl64, 2, ((t[2] >> (i * 8)) & 0xff)) ^  \
+  BOX (s_sbob_sl64, 3, ((t[3] >> (i * 8)) & 0xff)) ^  \
+  BOX (s_sbob_sl64, 4, ((t[4] >> (i * 8)) & 0xff)) ^  \
+  BOX (s_sbob_sl64, 5, ((t[5] >> (i * 8)) & 0xff)) ^  \
+  BOX (s_sbob_sl64, 6, ((t[6] >> (i * 8)) & 0xff)) ^  \
+  BOX (s_sbob_sl64, 7, ((t[7] >> (i * 8)) & 0xff))
 
 // constants
 
@@ -2226,11 +2236,11 @@ __constant u64 sbob_rc64[12][8] =
   },
 };
 
-static void streebog_g (u64 h[8], const u64 m[8], __local u64 s_sbob_sl64[8][256])
+static void streebog_g (u64x h[8], const u64x m[8], __local u64 s_sbob_sl64[8][256])
 {
-  u64 k[8];
-  u64 s[8];
-  u64 t[8];
+  u64x k[8];
+  u64x s[8];
+  u64x t[8];
 
   #pragma unroll
   for (int i = 0; i < 8; i++)
@@ -2297,17 +2307,17 @@ static void m11700m (__local u64 s_sbob_sl64[8][256], u32 w[16], const u32 pw_le
 
   u32 w0l = w[0];
 
-  for (u32 il_pos = 0; il_pos < bfs_cnt; il_pos++)
+  for (u32 il_pos = 0; il_pos < bfs_cnt; il_pos += VECT_SIZE)
   {
-    const u32 w0r = bfs_buf[il_pos].i;
+    const u32x w0r = w0r_create_bft (bfs_buf, il_pos);
 
-    w[0] = w0l | w0r;
+    const u32x w0lr = w0l | w0r;
 
     /**
      * reverse message block
      */
 
-    u64 m[8];
+    u64x m[8];
 
     m[0] = hl32_to_64 (w[15], w[14]);
     m[1] = hl32_to_64 (w[13], w[12]);
@@ -2316,7 +2326,7 @@ static void m11700m (__local u64 s_sbob_sl64[8][256], u32 w[16], const u32 pw_le
     m[4] = hl32_to_64 (w[ 7], w[ 6]);
     m[5] = hl32_to_64 (w[ 5], w[ 4]);
     m[6] = hl32_to_64 (w[ 3], w[ 2]);
-    m[7] = hl32_to_64 (w[ 1], w[ 0]);
+    m[7] = hl32_to_64 (w[ 1], w0lr );
 
     m[0] = swap64 (m[0]);
     m[1] = swap64 (m[1]);
@@ -2329,7 +2339,7 @@ static void m11700m (__local u64 s_sbob_sl64[8][256], u32 w[16], const u32 pw_le
 
     // state buffer (hash)
 
-    u64 h[8];
+    u64x h[8];
 
     h[0] = INITVAL;
     h[1] = INITVAL;
@@ -2342,7 +2352,7 @@ static void m11700m (__local u64 s_sbob_sl64[8][256], u32 w[16], const u32 pw_le
 
     streebog_g (h, m, s_sbob_sl64);
 
-    u64 z[8];
+    u64x z[8];
 
     z[0] = 0;
     z[1] = 0;
@@ -2356,12 +2366,12 @@ static void m11700m (__local u64 s_sbob_sl64[8][256], u32 w[16], const u32 pw_le
     streebog_g (h, z, s_sbob_sl64);
     streebog_g (h, m, s_sbob_sl64);
 
-    const u32 r0 = l32_from_64 (h[0]);
-    const u32 r1 = h32_from_64 (h[0]);
-    const u32 r2 = l32_from_64 (h[1]);
-    const u32 r3 = h32_from_64 (h[1]);
+    const u32x r0 = l32_from_64 (h[0]);
+    const u32x r1 = h32_from_64 (h[0]);
+    const u32x r2 = l32_from_64 (h[1]);
+    const u32x r3 = h32_from_64 (h[1]);
 
-    #include COMPARE_M
+    COMPARE_M_SIMD (r0, r1, r2, r3);
   }
 }
 
@@ -2392,17 +2402,17 @@ static void m11700s (__local u64 s_sbob_sl64[8][256], u32 w[16], const u32 pw_le
 
   u32 w0l = w[0];
 
-  for (u32 il_pos = 0; il_pos < bfs_cnt; il_pos++)
+  for (u32 il_pos = 0; il_pos < bfs_cnt; il_pos += VECT_SIZE)
   {
-    const u32 w0r = bfs_buf[il_pos].i;
+    const u32x w0r = w0r_create_bft (bfs_buf, il_pos);
 
-    w[0] = w0l | w0r;
+    const u32x w0lr = w0l | w0r;
 
     /**
      * reverse message block
      */
 
-    u64 m[8];
+    u64x m[8];
 
     m[0] = hl32_to_64 (w[15], w[14]);
     m[1] = hl32_to_64 (w[13], w[12]);
@@ -2411,7 +2421,7 @@ static void m11700s (__local u64 s_sbob_sl64[8][256], u32 w[16], const u32 pw_le
     m[4] = hl32_to_64 (w[ 7], w[ 6]);
     m[5] = hl32_to_64 (w[ 5], w[ 4]);
     m[6] = hl32_to_64 (w[ 3], w[ 2]);
-    m[7] = hl32_to_64 (w[ 1], w[ 0]);
+    m[7] = hl32_to_64 (w[ 1], w0lr );
 
     m[0] = swap64 (m[0]);
     m[1] = swap64 (m[1]);
@@ -2424,7 +2434,7 @@ static void m11700s (__local u64 s_sbob_sl64[8][256], u32 w[16], const u32 pw_le
 
     // state buffer (hash)
 
-    u64 h[8];
+    u64x h[8];
 
     h[0] = INITVAL;
     h[1] = INITVAL;
@@ -2437,7 +2447,7 @@ static void m11700s (__local u64 s_sbob_sl64[8][256], u32 w[16], const u32 pw_le
 
     streebog_g (h, m, s_sbob_sl64);
 
-    u64 z[8];
+    u64x z[8];
 
     z[0] = 0;
     z[1] = 0;
@@ -2451,12 +2461,12 @@ static void m11700s (__local u64 s_sbob_sl64[8][256], u32 w[16], const u32 pw_le
     streebog_g (h, z, s_sbob_sl64);
     streebog_g (h, m, s_sbob_sl64);
 
-    const u32 r0 = l32_from_64 (h[0]);
-    const u32 r1 = h32_from_64 (h[0]);
-    const u32 r2 = l32_from_64 (h[1]);
-    const u32 r3 = h32_from_64 (h[1]);
+    const u32x r0 = l32_from_64 (h[0]);
+    const u32x r1 = h32_from_64 (h[0]);
+    const u32x r2 = l32_from_64 (h[1]);
+    const u32x r3 = h32_from_64 (h[1]);
 
-    #include COMPARE_S
+    COMPARE_S_SIMD (r0, r1, r2, r3);
   }
 }