#define _WHIRLPOOL_
+#define NEW_SIMD_CODE
+
#include "include/constants.h"
#include "include/kernel_vendor.h"
#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"
#define R 10
// this is a highly optimized that assumes dgst[16] = { 0 }; only reuse of no 2nd transform is needed
-static void whirlpool_transform (const u32 w[16], u32 dgst[16], __local u32 (*s_Ch)[256], __local u32 (*s_Cl)[256])
+static void whirlpool_transform (const u32x w[16], u32x dgst[16], __local u32 (*s_Ch)[256], __local u32 (*s_Cl)[256])
{
- u32 Kh[8];
- u32 Kl[8];
+ u32x Kh[8];
+ u32x Kl[8];
Kh[0] = 0x300beec0;
Kl[0] = 0xaf902967;
Kh[7] = 0x28282828;
Kl[7] = 0x28282828;
- u32 stateh[8];
- u32 statel[8];
+ u32x stateh[8];
+ u32x statel[8];
stateh[0] = w[ 0];
statel[0] = w[ 1];
stateh[7] = w[14];
statel[7] = w[15];
- u32 Lh[8];
- u32 Ll[8];
+ u32x Lh[8];
+ u32x Ll[8];
#pragma unroll
for (int i = 0; i < 8; i++)
{
- const u32 Lp0 = stateh[(i + 8) & 7] >> 24;
- const u32 Lp1 = stateh[(i + 7) & 7] >> 16;
- const u32 Lp2 = stateh[(i + 6) & 7] >> 8;
- const u32 Lp3 = stateh[(i + 5) & 7] >> 0;
- const u32 Lp4 = statel[(i + 4) & 7] >> 24;
- const u32 Lp5 = statel[(i + 3) & 7] >> 16;
- const u32 Lp6 = statel[(i + 2) & 7] >> 8;
- const u32 Lp7 = statel[(i + 1) & 7] >> 0;
+ const u32x Lp0 = stateh[(i + 8) & 7] >> 24;
+ const u32x Lp1 = stateh[(i + 7) & 7] >> 16;
+ const u32x Lp2 = stateh[(i + 6) & 7] >> 8;
+ const u32x Lp3 = stateh[(i + 5) & 7] >> 0;
+ const u32x Lp4 = statel[(i + 4) & 7] >> 24;
+ const u32x Lp5 = statel[(i + 3) & 7] >> 16;
+ const u32x Lp6 = statel[(i + 2) & 7] >> 8;
+ const u32x Lp7 = statel[(i + 1) & 7] >> 0;
Lh[i] = BOX (s_Ch, 0, Lp0 & 0xff)
^ BOX (s_Ch, 1, Lp1 & 0xff)
for (int r = 2; r <= R; r++)
{
- u32 Lh[8];
- u32 Ll[8];
+ u32x Lh[8];
+ u32x Ll[8];
#pragma unroll
for (int i = 0; i < 8; i++)
{
- const u32 Lp0 = Kh[(i + 8) & 7] >> 24;
- const u32 Lp1 = Kh[(i + 7) & 7] >> 16;
- const u32 Lp2 = Kh[(i + 6) & 7] >> 8;
- const u32 Lp3 = Kh[(i + 5) & 7] >> 0;
- const u32 Lp4 = Kl[(i + 4) & 7] >> 24;
- const u32 Lp5 = Kl[(i + 3) & 7] >> 16;
- const u32 Lp6 = Kl[(i + 2) & 7] >> 8;
- const u32 Lp7 = Kl[(i + 1) & 7] >> 0;
+ const u32x Lp0 = Kh[(i + 8) & 7] >> 24;
+ const u32x Lp1 = Kh[(i + 7) & 7] >> 16;
+ const u32x Lp2 = Kh[(i + 6) & 7] >> 8;
+ const u32x Lp3 = Kh[(i + 5) & 7] >> 0;
+ const u32x Lp4 = Kl[(i + 4) & 7] >> 24;
+ const u32x Lp5 = Kl[(i + 3) & 7] >> 16;
+ const u32x Lp6 = Kl[(i + 2) & 7] >> 8;
+ const u32x Lp7 = Kl[(i + 1) & 7] >> 0;
Lh[i] = BOX (s_Ch, 0, Lp0 & 0xff)
^ BOX (s_Ch, 1, Lp1 & 0xff)
#pragma unroll 8
for (int i = 0; i < 8; i++)
{
- const u32 Lp0 = stateh[(i + 8) & 7] >> 24;
- const u32 Lp1 = stateh[(i + 7) & 7] >> 16;
- const u32 Lp2 = stateh[(i + 6) & 7] >> 8;
- const u32 Lp3 = stateh[(i + 5) & 7] >> 0;
- const u32 Lp4 = statel[(i + 4) & 7] >> 24;
- const u32 Lp5 = statel[(i + 3) & 7] >> 16;
- const u32 Lp6 = statel[(i + 2) & 7] >> 8;
- const u32 Lp7 = statel[(i + 1) & 7] >> 0;
+ const u32x Lp0 = stateh[(i + 8) & 7] >> 24;
+ const u32x Lp1 = stateh[(i + 7) & 7] >> 16;
+ const u32x Lp2 = stateh[(i + 6) & 7] >> 8;
+ const u32x Lp3 = stateh[(i + 5) & 7] >> 0;
+ const u32x Lp4 = statel[(i + 4) & 7] >> 24;
+ const u32x Lp5 = statel[(i + 3) & 7] >> 16;
+ const u32x Lp6 = statel[(i + 2) & 7] >> 8;
+ const u32x Lp7 = statel[(i + 1) & 7] >> 0;
Lh[i] = BOX (s_Ch, 0, Lp0 & 0xff)
^ BOX (s_Ch, 1, Lp1 & 0xff)
* 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);
- u32 wl[16];
+ u32x wl[16];
wl[ 0] = swap32 (w0[0]);
wl[ 1] = swap32 (w0[1]);
wl[14] = 0;
wl[15] = out_len * 8;
- u32 dgst[16];
+ u32x dgst[16];
dgst[ 0] = 0;
dgst[ 1] = 0;
whirlpool_transform (wl, dgst, s_Ch, s_Cl);
- const u32 r0 = dgst[0];
- const u32 r1 = dgst[1];
- const u32 r2 = dgst[2];
- const u32 r3 = dgst[3];
-
- #include COMPARE_M
+ COMPARE_M_SIMD (dgst[0], dgst[1], dgst[2], dgst[3]);
}
}
* 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);
- u32 wl[16];
+ u32x wl[16];
wl[ 0] = swap32 (w0[0]);
wl[ 1] = swap32 (w0[1]);
wl[14] = 0;
wl[15] = out_len * 8;
- u32 dgst[16];
+ u32x dgst[16];
dgst[ 0] = 0;
dgst[ 1] = 0;
whirlpool_transform (wl, dgst, s_Ch, s_Cl);
- const u32 r0 = dgst[0];
- const u32 r1 = dgst[1];
- const u32 r2 = dgst[2];
- const u32 r3 = dgst[3];
-
- #include COMPARE_S
+ COMPARE_S_SIMD (dgst[0], dgst[1], dgst[2], dgst[3]);
}
}