From a4f7ba2c60a10a82912f836fa6760d8c46048481 Mon Sep 17 00:00:00 2001 From: jsteube Date: Tue, 1 Nov 2016 14:44:35 +0100 Subject: [PATCH] Optimize rule_op_mangle_rotate_right() --- OpenCL/inc_rp.cl | 21 ++++++++++----------- src/rp_kernel_on_cpu.c | 23 +++++++++++------------ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/OpenCL/inc_rp.cl b/OpenCL/inc_rp.cl index 23e1e0694..ec2dece96 100644 --- a/OpenCL/inc_rp.cl +++ b/OpenCL/inc_rp.cl @@ -1204,17 +1204,16 @@ inline u32 rule_op_mangle_rotate_right (const u32 p0, const u32 p1, u32 buf0[4], u32 tmp = 0; - switch (in_len1 / 4) - { - case 0: tmp = (buf0[0] >> sh) & 0xff; break; - case 1: tmp = (buf0[1] >> sh) & 0xff; break; - case 2: tmp = (buf0[2] >> sh) & 0xff; break; - case 3: tmp = (buf0[3] >> sh) & 0xff; break; - case 4: tmp = (buf1[0] >> sh) & 0xff; break; - case 5: tmp = (buf1[1] >> sh) & 0xff; break; - case 6: tmp = (buf1[2] >> sh) & 0xff; break; - case 7: tmp = (buf1[3] >> sh) & 0xff; break; - } + tmp |= (in_len1 < 4) ? buf0[0] : 0; + tmp |= ((in_len1 >= 4) && (in_len1 < 8)) ? buf0[1] : 0; + tmp |= ((in_len1 >= 8) && (in_len1 < 12)) ? buf0[2] : 0; + tmp |= ((in_len1 >= 12) && (in_len1 < 16)) ? buf0[3] : 0; + tmp |= ((in_len1 >= 16) && (in_len1 < 20)) ? buf1[0] : 0; + tmp |= ((in_len1 >= 20) && (in_len1 < 24)) ? buf1[1] : 0; + tmp |= ((in_len1 >= 24) && (in_len1 < 28)) ? buf1[2] : 0; + tmp |= (in_len1 >= 28) ? buf1[3] : 0; + + tmp = (tmp >> sh) & 0xff; rshift_block (buf0, buf1, buf0, buf1); diff --git a/src/rp_kernel_on_cpu.c b/src/rp_kernel_on_cpu.c index 34d4725af..1cf672312 100644 --- a/src/rp_kernel_on_cpu.c +++ b/src/rp_kernel_on_cpu.c @@ -1249,7 +1249,7 @@ static u32 rule_op_mangle_rotate_left (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED c return in_len; } -static u32 rule_op_mangle_rotate_right (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_rotate_right (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) { if (in_len == 0) return (in_len); @@ -1259,17 +1259,16 @@ static u32 rule_op_mangle_rotate_right (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED u32 tmp = 0; - switch (in_len1 / 4) - { - case 0: tmp = (buf0[0] >> sh) & 0xff; break; - case 1: tmp = (buf0[1] >> sh) & 0xff; break; - case 2: tmp = (buf0[2] >> sh) & 0xff; break; - case 3: tmp = (buf0[3] >> sh) & 0xff; break; - case 4: tmp = (buf1[0] >> sh) & 0xff; break; - case 5: tmp = (buf1[1] >> sh) & 0xff; break; - case 6: tmp = (buf1[2] >> sh) & 0xff; break; - case 7: tmp = (buf1[3] >> sh) & 0xff; break; - } + tmp |= (in_len1 < 4) ? buf0[0] : 0; + tmp |= ((in_len1 >= 4) && (in_len1 < 8)) ? buf0[1] : 0; + tmp |= ((in_len1 >= 8) && (in_len1 < 12)) ? buf0[2] : 0; + tmp |= ((in_len1 >= 12) && (in_len1 < 16)) ? buf0[3] : 0; + tmp |= ((in_len1 >= 16) && (in_len1 < 20)) ? buf1[0] : 0; + tmp |= ((in_len1 >= 20) && (in_len1 < 24)) ? buf1[1] : 0; + tmp |= ((in_len1 >= 24) && (in_len1 < 28)) ? buf1[2] : 0; + tmp |= (in_len1 >= 28) ? buf1[3] : 0; + + tmp = (tmp >> sh) & 0xff; rshift_block (buf0, buf1, buf0, buf1);