summaryrefslogtreecommitdiff
path: root/generic/lib/shared/vload.cl
blob: f6ebd375c122396da6688849bab8cd4c787c8022 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#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[offset] , x[offset+1]); \
  } \
\
  _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##3 vload3(size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \
    return (PRIM_TYPE##3)(x[offset] , x[offset+1], x[offset+2]); \
  } \
\
  _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##4 vload4(size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \
    return (PRIM_TYPE##4)(x[offset], x[offset+1], x[offset+2], x[offset+3]); \
  } \
\
  _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##8 vload8(size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \
    return (PRIM_TYPE##8)(vload4(offset, x), vload4(offset+4, x)); \
  } \
\
  _CLC_OVERLOAD _CLC_DEF PRIM_TYPE##16 vload16(size_t offset, const ADDR_SPACE PRIM_TYPE *x) { \
    return (PRIM_TYPE##16)(vload8(offset, x), vload8(offset+8, x)); \
  } \

#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

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 int2 vload2(size_t offset, const global int *x) {
  return (int2)(x[offset] , x[offset+1]);
}
_CLC_OVERLOAD _CLC_DEF int3 vload3(size_t offset, const global int *x) {
  return (int3)(vload2(offset, x), x[offset+2]);
}
_CLC_OVERLOAD _CLC_DEF uint2 vload2(size_t offset, const global uint *x) {
  return (uint2)(x[offset] , x[offset+1]);
}
_CLC_OVERLOAD _CLC_DEF uint3 vload3(size_t offset, const global uint *x) {
  return (uint3)(vload2(offset, x), x[offset+2]);
}
        
/*Note: It is known that R600 doesn't support load <2 x ?> and <3 x ?>... so
 * they aren't actually overridden here
 */
_CLC_DECL int4 __clc_vload4_int__global(size_t offset, const __global int *);
_CLC_DECL int8 __clc_vload8_int__global(size_t offset, const __global int *);
_CLC_DECL int16 __clc_vload16_int__global(size_t offset, const __global int *);

_CLC_OVERLOAD _CLC_DEF int4 vload4(size_t offset, const global int *x) {
  return __clc_vload4_int__global(offset, x);
}
_CLC_OVERLOAD _CLC_DEF int8 vload8(size_t offset, const global int *x) {
  return __clc_vload8_int__global(offset, x);
}
_CLC_OVERLOAD _CLC_DEF int16 vload16(size_t offset, const global int *x) {
  return __clc_vload16_int__global(offset, x);
}

_CLC_DECL uint4 __clc_vload4_uint__global(size_t offset, const __global uint *);
_CLC_DECL uint8 __clc_vload8_uint__global(size_t offset, const __global uint *);
_CLC_DECL uint16 __clc_vload16_uint__global(size_t offset, const __global uint *);

_CLC_OVERLOAD _CLC_DEF uint4 vload4(size_t offset, const global uint *x) {
  return __clc_vload4_uint__global(offset, x);
}
_CLC_OVERLOAD _CLC_DEF uint8 vload8(size_t offset, const global uint *x) {
  return __clc_vload8_uint__global(offset, x);
}
_CLC_OVERLOAD _CLC_DEF uint16 vload16(size_t offset, const global uint *x) {
  return __clc_vload16_uint__global(offset, x);
}