summaryrefslogtreecommitdiff
path: root/utests/compiler_ctz.cpp
blob: d84fdadad665ae4a28b8c31096c09a4c5765769a (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
#include "utest_helper.hpp"

namespace {

template<typename T>
T get_max();

template<typename U>
void test(const char *kernel_name)
{
  const size_t n = 65;

  // Setup kernel and buffers
  OCL_CREATE_KERNEL_FROM_FILE("compiler_ctz", kernel_name);
  OCL_CREATE_BUFFER(buf[0], 0, n * sizeof(U), NULL);
  OCL_CREATE_BUFFER(buf[1], 0, n * sizeof(U), NULL);
  OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
  OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);

  OCL_MAP_BUFFER(0);
  for (uint32_t i = 0; i < n; ++i) {
      ((U*)buf_data[0])[i] = 1ll << i;
      if(i == sizeof(U)*8)
        ((U*)buf_data[0])[i] = 0;
  }

  OCL_UNMAP_BUFFER(0);

  globals[0] = n;
  locals[0] = 1;
  OCL_NDRANGE(1);
  OCL_MAP_BUFFER(1);
  for (uint32_t i = 0; i < n; ++i) {
      if(sizeof(U) == 1 && i <= 8 )
        OCL_ASSERT(((U*)buf_data[1])[i] == (U)i );
      else if(sizeof(U) == 2 && i <= 16 )
        OCL_ASSERT(((U*)buf_data[1])[i] == (U)i );
      else if(sizeof(U) == 4 && i <= 32 )
        OCL_ASSERT(((U*)buf_data[1])[i] == (U)i );
      else if(sizeof(U) == 8 && i <= 64 )
        OCL_ASSERT(((U*)buf_data[1])[i] == (U)i );
    }
  OCL_UNMAP_BUFFER(1);

}
}

#define compiler_ctz(type, kernel)\
static void compiler_ctz_ ##type(void)\
{\
  test<type>(# kernel);\
}\
MAKE_UTEST_FROM_FUNCTION(compiler_ctz_ ## type);

compiler_ctz(uint64_t, compiler_ctz_ulong)
compiler_ctz(uint32_t, compiler_ctz_uint)
compiler_ctz(uint16_t, compiler_ctz_ushort)
compiler_ctz(uint8_t, compiler_ctz_uchar)
compiler_ctz(int64_t, compiler_ctz_long)
compiler_ctz(int32_t, compiler_ctz_int)
compiler_ctz(int16_t, compiler_ctz_short)
compiler_ctz(int8_t, compiler_ctz_char)