From 9562d072647e7282e99342ebe693f848cfe1062c Mon Sep 17 00:00:00 2001 From: jsteube Date: Sun, 23 Jul 2017 17:01:15 +0200 Subject: [PATCH] Replace bitwise swaps with rotate() versions for AMD --- OpenCL/inc_types.cl | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/OpenCL/inc_types.cl b/OpenCL/inc_types.cl index 7737c7235..c31bc0046 100644 --- a/OpenCL/inc_types.cl +++ b/OpenCL/inc_types.cl @@ -176,12 +176,16 @@ u64x hl32_to_64 (const u32x a, const u32x b) #ifdef IS_AMD u32 swap32_S (const u32 v) { - return (as_uint (as_uchar4 (v).s3210)); + return bitselect (rotate (v, 24u), rotate (v, 8u), 0x00ff00ffu); } u64 swap64_S (const u64 v) { - return (as_ulong (as_uchar8 (v).s76543210)); + return bitselect (bitselect (rotate (v, 24ul), + rotate (v, 8ul), 0x000000ff000000fful), + bitselect (rotate (v, 56ul), + rotate (v, 40ul), 0x00ff000000ff0000ul), + 0xffff0000ffff0000ul); } u32 rotr32_S (const u32 a, const u32 n) @@ -206,22 +210,16 @@ u64 rotl64_S (const u64 a, const u32 n) u32x swap32 (const u32x v) { - return ((v >> 24) & 0x000000ff) - | ((v >> 8) & 0x0000ff00) - | ((v << 8) & 0x00ff0000) - | ((v << 24) & 0xff000000); + return bitselect (rotate (v, 24u), rotate (v, 8u), 0x00ff00ffu); } u64x swap64 (const u64x v) { - return ((v >> 56) & 0x00000000000000ff) - | ((v >> 40) & 0x000000000000ff00) - | ((v >> 24) & 0x0000000000ff0000) - | ((v >> 8) & 0x00000000ff000000) - | ((v << 8) & 0x000000ff00000000) - | ((v << 24) & 0x0000ff0000000000) - | ((v << 40) & 0x00ff000000000000) - | ((v << 56) & 0xff00000000000000); + return bitselect (bitselect (rotate (v, 24ul), + rotate (v, 8ul), 0x000000ff000000fful), + bitselect (rotate (v, 56ul), + rotate (v, 40ul), 0x00ff000000ff0000ul), + 0xffff0000ffff0000ul); } u32x rotr32 (const u32x a, const u32 n)