diff options
author | Aaron Watry <awatry@gmail.com> | 2013-07-16 14:29:01 +0000 |
---|---|---|
committer | Aaron Watry <awatry@gmail.com> | 2013-07-16 14:29:01 +0000 |
commit | 2b80a46a5b9b0836e7a8cf4e6fbd85c332302398 (patch) | |
tree | fd149beaf7da04c2ad5772310781588a53a94733 /r600/lib | |
parent | cfdac80e2cb66d091cf0b70cd0a0c1f258d14005 (diff) |
Fix and re-enable R600 vload/vstore assembly
The assembly optimizations were making unsafe assumptions about which address
spaces had which identifiers.
Also, fix vload/vstore with 64-bit pointers. This was broken previously on
Radeon SI.
This version still only has assembly versions of int/uint 2/4/8/16 for global
loads and stores on R600, but it does it in a way that would be very easily
extended to private/local/constant and could also be handled easily on other
architectures.
v2: 1) Leave v[load|store]_impl.ll in generic/lib
2) Remove vload_if.ll and vstore_if.ll interfaces
3) Fix address+offset calculations
3) Remove offset from assembly arg list
git-svn-id: https://llvm.org/svn/llvm-project/libclc/trunk@186416 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'r600/lib')
-rw-r--r-- | r600/lib/SOURCES | 2 | ||||
-rw-r--r-- | r600/lib/shared/vload.cl | 92 | ||||
-rw-r--r-- | r600/lib/shared/vstore.cl | 104 |
3 files changed, 198 insertions, 0 deletions
diff --git a/r600/lib/SOURCES b/r600/lib/SOURCES index 16ef3ac..87df0b7 100644 --- a/r600/lib/SOURCES +++ b/r600/lib/SOURCES @@ -4,3 +4,5 @@ workitem/get_local_id.ll workitem/get_global_size.ll synchronization/barrier.cl synchronization/barrier_impl.ll +shared/vload.cl +shared/vstore.cl
\ No newline at end of file diff --git a/r600/lib/shared/vload.cl b/r600/lib/shared/vload.cl new file mode 100644 index 0000000..6144dde --- /dev/null +++ b/r600/lib/shared/vload.cl @@ -0,0 +1,92 @@ +#include <clc/clc.h> + +#define VLOAD_VECTORIZE(PRIM_TYPE, ADDR_SPACE) \ + _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##2 vload2(size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \ + return (PRIM_TYPE##2)(x[2*offset] , x[2*offset+1]); \ + } \ +\ + _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##3 vload3(size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \ + return (PRIM_TYPE##3)(x[3*offset] , x[3*offset+1], x[3*offset+2]); \ + } \ +\ + _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##4 vload4(size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \ + return (PRIM_TYPE##4)(x[4*offset], x[4*offset+1], x[4*offset+2], x[4*offset+3]); \ + } \ +\ + _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##8 vload8(size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \ + return (PRIM_TYPE##8)(vload4(0, &x[8*offset]), vload4(1, &x[8*offset])); \ + } \ +\ + _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##16 vload16(size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \ + return (PRIM_TYPE##16)(vload8(0, &x[16*offset]), vload8(1, &x[16*offset])); \ + } \ + +#define VLOAD_ADDR_SPACES(SCALAR_GENTYPE) \ + VLOAD_VECTORIZE(SCALAR_GENTYPE, __private) \ + VLOAD_VECTORIZE(SCALAR_GENTYPE, __local) \ + VLOAD_VECTORIZE(SCALAR_GENTYPE, __constant) \ + VLOAD_VECTORIZE(SCALAR_GENTYPE, __global) \ + +//int/uint are special... see below +#define VLOAD_TYPES() \ + VLOAD_ADDR_SPACES(char) \ + VLOAD_ADDR_SPACES(uchar) \ + VLOAD_ADDR_SPACES(short) \ + VLOAD_ADDR_SPACES(ushort) \ + VLOAD_ADDR_SPACES(long) \ + VLOAD_ADDR_SPACES(ulong) \ + VLOAD_ADDR_SPACES(float) \ + +VLOAD_TYPES() + +#ifdef cl_khr_fp64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable + VLOAD_ADDR_SPACES(double) +#endif + +//Assembly overrides start here + +VLOAD_VECTORIZE(int, __private) +VLOAD_VECTORIZE(int, __local) +VLOAD_VECTORIZE(int, __constant) +VLOAD_VECTORIZE(uint, __private) +VLOAD_VECTORIZE(uint, __local) +VLOAD_VECTORIZE(uint, __constant) + +_CLC_OVERLOAD _CLC_DEF int3 vload3(size_t offset, const global int *x) { + return (int3)(vload2(0, &x[3*offset]), x[3*offset+2]); +} +_CLC_OVERLOAD _CLC_DEF uint3 vload3(size_t offset, const global uint *x) { + return (uint3)(vload2(0, &x[3*offset]), x[3*offset+2]); +} + +//We only define functions for typeN vloadN(), and then just bitcast the result for unsigned types +#define _CLC_VLOAD_ASM_DECL(PRIM_TYPE,LLVM_SCALAR_TYPE,ADDR_SPACE,ADDR_SPACE_ID) \ +_CLC_DECL PRIM_TYPE##2 __clc_vload2_##LLVM_SCALAR_TYPE##__addr##ADDR_SPACE_ID (const ADDR_SPACE PRIM_TYPE *); \ +_CLC_DECL PRIM_TYPE##4 __clc_vload4_##LLVM_SCALAR_TYPE##__addr##ADDR_SPACE_ID (const ADDR_SPACE PRIM_TYPE *); \ +_CLC_DECL PRIM_TYPE##8 __clc_vload8_##LLVM_SCALAR_TYPE##__addr##ADDR_SPACE_ID (const ADDR_SPACE PRIM_TYPE *); \ +_CLC_DECL PRIM_TYPE##16 __clc_vload16_##LLVM_SCALAR_TYPE##__addr##ADDR_SPACE_ID (const ADDR_SPACE PRIM_TYPE *); \ + +#define _CLC_VLOAD_ASM_DEFINE(PRIM_TYPE,S_PRIM_TYPE, LLVM_SCALAR_TYPE,VEC_WIDTH,ADDR_SPACE,ADDR_SPACE_ID) \ + _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##VEC_WIDTH vload##VEC_WIDTH (size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \ + return __builtin_astype(__clc_vload##VEC_WIDTH##_##LLVM_SCALAR_TYPE##__addr##ADDR_SPACE_ID ((const ADDR_SPACE S_PRIM_TYPE *)&x[VEC_WIDTH * offset]), PRIM_TYPE##VEC_WIDTH); \ + } \ + +/*Note: R600 back-end doesn't support load <3 x ?>... so + * those functions aren't actually overridden here + */ +#define _CLC_VLOAD_ASM_OVERLOAD_SIZES(PRIM_TYPE,S_PRIM_TYPE,LLVM_TYPE,ADDR_SPACE,ADDR_SPACE_ID) \ + _CLC_VLOAD_ASM_DEFINE(PRIM_TYPE, S_PRIM_TYPE, LLVM_TYPE, 2, ADDR_SPACE, ADDR_SPACE_ID) \ + _CLC_VLOAD_ASM_DEFINE(PRIM_TYPE, S_PRIM_TYPE, LLVM_TYPE, 4, ADDR_SPACE, ADDR_SPACE_ID) \ + _CLC_VLOAD_ASM_DEFINE(PRIM_TYPE, S_PRIM_TYPE, LLVM_TYPE, 8, ADDR_SPACE, ADDR_SPACE_ID) \ + _CLC_VLOAD_ASM_DEFINE(PRIM_TYPE, S_PRIM_TYPE, LLVM_TYPE, 16, ADDR_SPACE, ADDR_SPACE_ID) \ + +#define _CLC_VLOAD_ASM_OVERLOAD_ADDR_SPACES(PRIM_TYPE,S_PRIM_TYPE,LLVM_TYPE) \ + _CLC_VLOAD_ASM_OVERLOAD_SIZES(PRIM_TYPE, S_PRIM_TYPE, LLVM_TYPE, global, 1) \ + +#define _CLC_VLOAD_ASM_OVERLOADS() \ + _CLC_VLOAD_ASM_DECL(int,i32,__global,1) \ + _CLC_VLOAD_ASM_OVERLOAD_ADDR_SPACES(int,int,i32) \ + _CLC_VLOAD_ASM_OVERLOAD_ADDR_SPACES(uint,int,i32) \ + +_CLC_VLOAD_ASM_OVERLOADS()
\ No newline at end of file diff --git a/r600/lib/shared/vstore.cl b/r600/lib/shared/vstore.cl new file mode 100644 index 0000000..a150849 --- /dev/null +++ b/r600/lib/shared/vstore.cl @@ -0,0 +1,104 @@ +#include <clc/clc.h> + +#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable + +#define VSTORE_VECTORIZE(PRIM_TYPE, ADDR_SPACE) \ + _CLC_OVERLOAD _CLC_DEF void vstore2(PRIM_TYPE##2 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \ + mem[2*offset] = vec.s0; \ + mem[2*offset+1] = vec.s1; \ + } \ +\ + _CLC_OVERLOAD _CLC_DEF void vstore3(PRIM_TYPE##3 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \ + mem[3*offset] = vec.s0; \ + mem[3*offset+1] = vec.s1; \ + mem[3*offset+2] = vec.s2; \ + } \ +\ + _CLC_OVERLOAD _CLC_DEF void vstore4(PRIM_TYPE##4 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \ + vstore2(vec.lo, 0, &mem[offset*4]); \ + vstore2(vec.hi, 1, &mem[offset*4]); \ + } \ +\ + _CLC_OVERLOAD _CLC_DEF void vstore8(PRIM_TYPE##8 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \ + vstore4(vec.lo, 0, &mem[offset*8]); \ + vstore4(vec.hi, 1, &mem[offset*8]); \ + } \ +\ + _CLC_OVERLOAD _CLC_DEF void vstore16(PRIM_TYPE##16 vec, size_t offset, ADDR_SPACE PRIM_TYPE *mem) { \ + vstore8(vec.lo, 0, &mem[offset*16]); \ + vstore8(vec.hi, 1, &mem[offset*16]); \ + } \ + +#define VSTORE_ADDR_SPACES(SCALAR_GENTYPE) \ + VSTORE_VECTORIZE(SCALAR_GENTYPE, __private) \ + VSTORE_VECTORIZE(SCALAR_GENTYPE, __local) \ + VSTORE_VECTORIZE(SCALAR_GENTYPE, __global) \ + +//int/uint are special... see below +#define VSTORE_TYPES() \ + VSTORE_ADDR_SPACES(char) \ + VSTORE_ADDR_SPACES(uchar) \ + VSTORE_ADDR_SPACES(short) \ + VSTORE_ADDR_SPACES(ushort) \ + VSTORE_ADDR_SPACES(long) \ + VSTORE_ADDR_SPACES(ulong) \ + VSTORE_ADDR_SPACES(float) \ + +VSTORE_TYPES() + +#ifdef cl_khr_fp64 +#pragma OPENCL EXTENSION cl_khr_fp64 : enable + VSTORE_ADDR_SPACES(double) +#endif + +VSTORE_VECTORIZE(int, __private) +VSTORE_VECTORIZE(int, __local) +VSTORE_VECTORIZE(uint, __private) +VSTORE_VECTORIZE(uint, __local) + +_CLC_OVERLOAD _CLC_DEF void vstore3(int3 vec, size_t offset, global int *mem) { + mem[3*offset] = vec.s0; + mem[3*offset+1] = vec.s1; + mem[3*offset+2] = vec.s2; +} +_CLC_OVERLOAD _CLC_DEF void vstore3(uint3 vec, size_t offset, global uint *mem) { + mem[3*offset] = vec.s0; + mem[3*offset+1] = vec.s1; + mem[3*offset+2] = vec.s2; +} + +/*Note: R600 doesn't support store <3 x ?>... so + * those functions aren't actually overridden here... lowest-common-denominator + */ + +//We only define functions for signed_type vstoreN(), and then just cast the pointers/vectors for unsigned types +#define _CLC_VSTORE_ASM_DECL(PRIM_TYPE,LLVM_SCALAR_TYPE,ADDR_SPACE,ADDR_SPACE_ID) \ +_CLC_DECL void __clc_vstore2_##LLVM_SCALAR_TYPE##__addr##ADDR_SPACE_ID (PRIM_TYPE##2, ADDR_SPACE PRIM_TYPE *); \ +_CLC_DECL void __clc_vstore4_##LLVM_SCALAR_TYPE##__addr##ADDR_SPACE_ID (PRIM_TYPE##4, ADDR_SPACE PRIM_TYPE *); \ +_CLC_DECL void __clc_vstore8_##LLVM_SCALAR_TYPE##__addr##ADDR_SPACE_ID (PRIM_TYPE##8, ADDR_SPACE PRIM_TYPE *); \ +_CLC_DECL void __clc_vstore16_##LLVM_SCALAR_TYPE##__addr##ADDR_SPACE_ID (PRIM_TYPE##16, ADDR_SPACE PRIM_TYPE *); \ + +#define _CLC_VSTORE_ASM_DEFINE(PRIM_TYPE, S_PRIM_TYPE, LLVM_SCALAR_TYPE, VEC_WIDTH, ADDR_SPACE, ADDR_SPACE_ID) \ + _CLC_OVERLOAD _CLC_DEF void vstore##VEC_WIDTH(PRIM_TYPE##VEC_WIDTH vec, size_t offset, ADDR_SPACE PRIM_TYPE *x) { \ + __clc_vstore##VEC_WIDTH##_##LLVM_SCALAR_TYPE##__addr##ADDR_SPACE_ID (__builtin_astype(vec, S_PRIM_TYPE##VEC_WIDTH), (ADDR_SPACE S_PRIM_TYPE *)&x[ VEC_WIDTH * offset]); \ + } \ + +/*Note: R600 back-end doesn't support load <3 x ?>... so + * those functions aren't actually overridden here... When the back-end supports + * that, then clean add here, and remove the vstore3 definitions from above. + */ +#define _CLC_VSTORE_ASM_OVERLOAD_SIZES(PRIM_TYPE,S_PRIM_TYPE,LLVM_TYPE,ADDR_SPACE,ADDR_SPACE_ID) \ + _CLC_VSTORE_ASM_DEFINE(PRIM_TYPE, S_PRIM_TYPE, LLVM_TYPE, 2, ADDR_SPACE, ADDR_SPACE_ID) \ + _CLC_VSTORE_ASM_DEFINE(PRIM_TYPE, S_PRIM_TYPE, LLVM_TYPE, 4, ADDR_SPACE, ADDR_SPACE_ID) \ + _CLC_VSTORE_ASM_DEFINE(PRIM_TYPE, S_PRIM_TYPE, LLVM_TYPE, 8, ADDR_SPACE, ADDR_SPACE_ID) \ + _CLC_VSTORE_ASM_DEFINE(PRIM_TYPE, S_PRIM_TYPE, LLVM_TYPE, 16, ADDR_SPACE, ADDR_SPACE_ID) \ + +#define _CLC_VSTORE_ASM_OVERLOAD_ADDR_SPACES(PRIM_TYPE,S_PRIM_TYPE,LLVM_TYPE) \ + _CLC_VSTORE_ASM_OVERLOAD_SIZES(PRIM_TYPE, S_PRIM_TYPE, LLVM_TYPE, global, 1) \ + +#define _CLC_VSTORE_ASM_OVERLOADS() \ + _CLC_VSTORE_ASM_DECL(int,i32,__global,1) \ + _CLC_VSTORE_ASM_OVERLOAD_ADDR_SPACES(int,int,i32) \ + _CLC_VSTORE_ASM_OVERLOAD_ADDR_SPACES(uint,int,i32) \ + +_CLC_VSTORE_ASM_OVERLOADS()
\ No newline at end of file |