/* !!!! AUTOGENERATED FILE generated by test_convert_type.py !!!!!

   DO NOT CHANGE THIS FILE. MAKE YOUR CHANGES TO test_convert_type.py
   AND RUN:

   LINUX: $ python3 test_convert_type_.py <num> > test_convert_type_<num>.cl

   WINDOWS: python3.exe .	est_convert_type.py <num> | set-content -Encoding UTF8 .	est_convert_type_<num>.cl

   With <num> replaced with a vector length.
*/

#include "common.cl"


constant char char_values[6] = { 0, 1, CHAR_MIN, CHAR_MAX, CHAR_MIN / 2, CHAR_MAX / 2 };
constant uchar uchar_values[6] = { 0, 1, 0, UCHAR_MAX, 0 / 2, UCHAR_MAX / 2 };
constant short short_values[6] = { 0, 1, SHRT_MIN, SHRT_MAX, SHRT_MIN / 2, SHRT_MAX / 2 };
constant ushort ushort_values[6] = { 0, 1, 0, USHRT_MAX, 0 / 2, USHRT_MAX / 2 };
constant int int_values[6] = { 0, 1, INT_MIN, INT_MAX, INT_MIN / 2, INT_MAX / 2 };
constant uint uint_values[6] = { 0, 1, 0, UINT_MAX, 0 / 2, UINT_MAX / 2 };

constant size_t char_values_length = sizeof(char_values) / sizeof(char_values[0]);
constant size_t uchar_values_length = sizeof(uchar_values) / sizeof(uchar_values[0]);
constant size_t short_values_length = sizeof(short_values) / sizeof(short_values[0]);
constant size_t ushort_values_length = sizeof(ushort_values) / sizeof(ushort_values[0]);
constant size_t int_values_length = sizeof(int_values) / sizeof(int_values[0]);
constant size_t uint_values_length = sizeof(uint_values) / sizeof(uint_values[0]);

#ifdef cl_khr_int64
constant long long_values[6] = { 0, 1, LONG_MIN, LONG_MAX, LONG_MIN / 2, LONG_MAX / 2 };
constant ulong ulong_values[6] = { 0, 1, 0, ULONG_MAX, 0 / 2, ULONG_MAX / 2 };

constant size_t long_values_length = sizeof(long_values) / sizeof(long_values[0]);
constant size_t ulong_values_length = sizeof(ulong_values) / sizeof(ulong_values[0]);

#endif

#ifdef cl_khr_fp64
constant float float_sat_offsets[16] =
{
   0.0f, (float)CHAR_MAX, (float)CHAR_MIN, (float)UCHAR_MAX, (float)SHRT_MIN, (float)SHRT_MAX, (float)USHRT_MAX, (float)INT_MAX,
   (float)INT_MIN, (float)UINT_MAX, (float)LONG_MAX, (float)LONG_MIN, (float)ULONG_MAX, 0.0f, 1.0e15f, -1.0e15f
};
#else
constant float float_sat_offsets[13] =
{
   0.0f, (float)CHAR_MAX, (float)CHAR_MIN, (float)UCHAR_MAX, (float)SHRT_MIN, (float)SHRT_MAX, (float)USHRT_MAX, (float)INT_MAX,
   (float)INT_MIN, (float)UINT_MAX, 0.0f, 1.0e15f, -1.0e15f
};
#endif

constant float float_values            [17] = { -2.0f, -1.75f, -1.5f, -1.25f, -1.0f, -0.75f, -0.5f, -0.25f, 0.0f, 0.25f, 0.5f, 0.75f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f };
constant int float_rounded_values    [17] = { -2     , -1      , -1     , -1      , -1     ,  0      ,  0     ,  0      , 0     , 0      , 0     , 0      , 1     , 1      , 1     , 1      , 2      };
constant int float_rounded_values_rtz[17] = { -2     , -1      , -1     , -1      , -1     ,  0      ,  0     ,  0      , 0     , 0      , 0     , 0      , 1     , 1      , 1     , 1      , 2      };
constant int float_rounded_values_rte[17] = { -2     , -2      , -2     , -1      , -1     , -1      ,  0     ,  0      , 0     , 0      , 0     , 1      , 1     , 1      , 2     , 2      , 2      };
constant int float_rounded_values_rtp[17] = { -2     , -1      , -1     , -1      , -1     ,  0      ,  0     ,  0      , 0     , 1      , 1     , 1      , 1     , 2      , 2     , 2      , 2      };
constant int float_rounded_values_rtn[17] = { -2     , -2      , -2     , -2      , -1     , -1      , -1     , -1      , 0     , 0      , 0     , 0      , 1     , 1      , 1     , 1      , 2      };

constant size_t float_values_length = sizeof(float_values) / sizeof(float_values[0]);


#ifdef cl_khr_fp64

#ifdef cl_khr_fp64
constant double double_sat_offsets[16] =
{
   0.0, (double)CHAR_MAX, (double)CHAR_MIN, (double)UCHAR_MAX, (double)SHRT_MIN, (double)SHRT_MAX, (double)USHRT_MAX, (double)INT_MAX,
   (double)INT_MIN, (double)UINT_MAX, (double)LONG_MAX, (double)LONG_MIN, (double)ULONG_MAX, 0.0, 1.0e15, -1.0e15
};
#else
constant double double_sat_offsets[13] =
{
   0.0, (double)CHAR_MAX, (double)CHAR_MIN, (double)UCHAR_MAX, (double)SHRT_MIN, (double)SHRT_MAX, (double)USHRT_MAX, (double)INT_MAX,
   (double)INT_MIN, (double)UINT_MAX, 0.0, 1.0e15, -1.0e15
};
#endif

constant double double_values            [17] = { -2.0, -1.75, -1.5, -1.25, -1.0, -0.75, -0.5, -0.25, 0.0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0 };
constant long double_rounded_values    [17] = { -2     , -1      , -1     , -1      , -1     ,  0      ,  0     ,  0      , 0     , 0      , 0     , 0      , 1     , 1      , 1     , 1      , 2      };
constant long double_rounded_values_rtz[17] = { -2     , -1      , -1     , -1      , -1     ,  0      ,  0     ,  0      , 0     , 0      , 0     , 0      , 1     , 1      , 1     , 1      , 2      };
constant long double_rounded_values_rte[17] = { -2     , -2      , -2     , -1      , -1     , -1      ,  0     ,  0      , 0     , 0      , 0     , 1      , 1     , 1      , 2     , 2      , 2      };
constant long double_rounded_values_rtp[17] = { -2     , -1      , -1     , -1      , -1     ,  0      ,  0     ,  0      , 0     , 1      , 1     , 1      , 1     , 2      , 2     , 2      , 2      };
constant long double_rounded_values_rtn[17] = { -2     , -2      , -2     , -2      , -1     , -1      , -1     , -1      , 0     , 0      , 0     , 0      , 1     , 1      , 1     , 1      , 2      };

constant size_t double_values_length = sizeof(double_values) / sizeof(double_values[0]);


#endif

_CL_NOINLINE
void compare_char_elements_char(string name, size_t sample, constant char* original_scalar, const char* original_array, const char* expected, const char* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (char)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_char_elements_uchar(string name, size_t sample, constant uchar* original_scalar, const uchar* original_array, const char* expected, const char* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (uchar)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_char_elements_short(string name, size_t sample, constant short* original_scalar, const short* original_array, const char* expected, const char* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (short)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_char_elements_ushort(string name, size_t sample, constant ushort* original_scalar, const ushort* original_array, const char* expected, const char* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (ushort)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_char_elements_int(string name, size_t sample, constant int* original_scalar, const int* original_array, const char* expected, const char* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (int)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_char_elements_uint(string name, size_t sample, constant uint* original_scalar, const uint* original_array, const char* expected, const char* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (uint)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_char_elements_long(string name, size_t sample, constant long* original_scalar, const long* original_array, const char* expected, const char* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (long)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_char_elements_ulong(string name, size_t sample, constant ulong* original_scalar, const ulong* original_array, const char* expected, const char* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (ulong)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

_CL_NOINLINE
void compare_char_elements_float(string name, size_t sample, constant float* original_scalar, const float* original_array, const char* expected, const char* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.8g expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (float)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_char_elements_double(string name, size_t sample, constant double* original_scalar, const double* original_array, const char* expected, const char* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.17g expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (double)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

_CL_NOINLINE
void compare_uchar_elements_char(string name, size_t sample, constant char* original_scalar, const char* original_array, const uchar* expected, const uchar* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (char)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_uchar_elements_uchar(string name, size_t sample, constant uchar* original_scalar, const uchar* original_array, const uchar* expected, const uchar* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (uchar)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_uchar_elements_short(string name, size_t sample, constant short* original_scalar, const short* original_array, const uchar* expected, const uchar* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (short)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_uchar_elements_ushort(string name, size_t sample, constant ushort* original_scalar, const ushort* original_array, const uchar* expected, const uchar* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (ushort)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_uchar_elements_int(string name, size_t sample, constant int* original_scalar, const int* original_array, const uchar* expected, const uchar* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (int)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_uchar_elements_uint(string name, size_t sample, constant uint* original_scalar, const uint* original_array, const uchar* expected, const uchar* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (uint)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_uchar_elements_long(string name, size_t sample, constant long* original_scalar, const long* original_array, const uchar* expected, const uchar* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (long)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_uchar_elements_ulong(string name, size_t sample, constant ulong* original_scalar, const ulong* original_array, const uchar* expected, const uchar* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (ulong)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

_CL_NOINLINE
void compare_uchar_elements_float(string name, size_t sample, constant float* original_scalar, const float* original_array, const uchar* expected, const uchar* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.8g expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (float)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_uchar_elements_double(string name, size_t sample, constant double* original_scalar, const double* original_array, const uchar* expected, const uchar* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.17g expected: %#.2hhx actual: %#.2hhx\n",
        name, (uint)sample, (uint)i, (double)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

_CL_NOINLINE
void compare_short_elements_char(string name, size_t sample, constant char* original_scalar, const char* original_array, const short* expected, const short* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (char)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_short_elements_uchar(string name, size_t sample, constant uchar* original_scalar, const uchar* original_array, const short* expected, const short* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (uchar)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_short_elements_short(string name, size_t sample, constant short* original_scalar, const short* original_array, const short* expected, const short* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (short)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_short_elements_ushort(string name, size_t sample, constant ushort* original_scalar, const ushort* original_array, const short* expected, const short* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (ushort)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_short_elements_int(string name, size_t sample, constant int* original_scalar, const int* original_array, const short* expected, const short* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (int)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_short_elements_uint(string name, size_t sample, constant uint* original_scalar, const uint* original_array, const short* expected, const short* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (uint)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_short_elements_long(string name, size_t sample, constant long* original_scalar, const long* original_array, const short* expected, const short* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (long)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_short_elements_ulong(string name, size_t sample, constant ulong* original_scalar, const ulong* original_array, const short* expected, const short* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (ulong)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

_CL_NOINLINE
void compare_short_elements_float(string name, size_t sample, constant float* original_scalar, const float* original_array, const short* expected, const short* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.8g expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (float)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_short_elements_double(string name, size_t sample, constant double* original_scalar, const double* original_array, const short* expected, const short* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.17g expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (double)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

_CL_NOINLINE
void compare_ushort_elements_char(string name, size_t sample, constant char* original_scalar, const char* original_array, const ushort* expected, const ushort* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (char)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_ushort_elements_uchar(string name, size_t sample, constant uchar* original_scalar, const uchar* original_array, const ushort* expected, const ushort* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (uchar)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_ushort_elements_short(string name, size_t sample, constant short* original_scalar, const short* original_array, const ushort* expected, const ushort* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (short)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_ushort_elements_ushort(string name, size_t sample, constant ushort* original_scalar, const ushort* original_array, const ushort* expected, const ushort* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (ushort)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_ushort_elements_int(string name, size_t sample, constant int* original_scalar, const int* original_array, const ushort* expected, const ushort* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (int)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_ushort_elements_uint(string name, size_t sample, constant uint* original_scalar, const uint* original_array, const ushort* expected, const ushort* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (uint)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_ushort_elements_long(string name, size_t sample, constant long* original_scalar, const long* original_array, const ushort* expected, const ushort* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (long)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_ushort_elements_ulong(string name, size_t sample, constant ulong* original_scalar, const ulong* original_array, const ushort* expected, const ushort* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (ulong)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

_CL_NOINLINE
void compare_ushort_elements_float(string name, size_t sample, constant float* original_scalar, const float* original_array, const ushort* expected, const ushort* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.8g expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (float)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_ushort_elements_double(string name, size_t sample, constant double* original_scalar, const double* original_array, const ushort* expected, const ushort* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.17g expected: %#.4hx actual: %#.4hx\n",
        name, (uint)sample, (uint)i, (double)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

_CL_NOINLINE
void compare_int_elements_char(string name, size_t sample, constant char* original_scalar, const char* original_array, const int* expected, const int* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (char)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_int_elements_uchar(string name, size_t sample, constant uchar* original_scalar, const uchar* original_array, const int* expected, const int* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (uchar)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_int_elements_short(string name, size_t sample, constant short* original_scalar, const short* original_array, const int* expected, const int* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (short)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_int_elements_ushort(string name, size_t sample, constant ushort* original_scalar, const ushort* original_array, const int* expected, const int* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (ushort)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_int_elements_int(string name, size_t sample, constant int* original_scalar, const int* original_array, const int* expected, const int* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (int)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_int_elements_uint(string name, size_t sample, constant uint* original_scalar, const uint* original_array, const int* expected, const int* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (uint)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_int_elements_long(string name, size_t sample, constant long* original_scalar, const long* original_array, const int* expected, const int* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (long)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_int_elements_ulong(string name, size_t sample, constant ulong* original_scalar, const ulong* original_array, const int* expected, const int* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (ulong)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

_CL_NOINLINE
void compare_int_elements_float(string name, size_t sample, constant float* original_scalar, const float* original_array, const int* expected, const int* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.8g expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (float)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_int_elements_double(string name, size_t sample, constant double* original_scalar, const double* original_array, const int* expected, const int* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.17g expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (double)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

_CL_NOINLINE
void compare_uint_elements_char(string name, size_t sample, constant char* original_scalar, const char* original_array, const uint* expected, const uint* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (char)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_uint_elements_uchar(string name, size_t sample, constant uchar* original_scalar, const uchar* original_array, const uint* expected, const uint* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (uchar)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_uint_elements_short(string name, size_t sample, constant short* original_scalar, const short* original_array, const uint* expected, const uint* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (short)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_uint_elements_ushort(string name, size_t sample, constant ushort* original_scalar, const ushort* original_array, const uint* expected, const uint* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (ushort)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_uint_elements_int(string name, size_t sample, constant int* original_scalar, const int* original_array, const uint* expected, const uint* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (int)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_uint_elements_uint(string name, size_t sample, constant uint* original_scalar, const uint* original_array, const uint* expected, const uint* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (uint)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_uint_elements_long(string name, size_t sample, constant long* original_scalar, const long* original_array, const uint* expected, const uint* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (long)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_uint_elements_ulong(string name, size_t sample, constant ulong* original_scalar, const ulong* original_array, const uint* expected, const uint* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (ulong)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

_CL_NOINLINE
void compare_uint_elements_float(string name, size_t sample, constant float* original_scalar, const float* original_array, const uint* expected, const uint* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.8g expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (float)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_uint_elements_double(string name, size_t sample, constant double* original_scalar, const double* original_array, const uint* expected, const uint* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.17g expected: %#.8x actual: %#.8x\n",
        name, (uint)sample, (uint)i, (double)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_long_elements_char(string name, size_t sample, constant char* original_scalar, const char* original_array, const long* expected, const long* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (char)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_long_elements_uchar(string name, size_t sample, constant uchar* original_scalar, const uchar* original_array, const long* expected, const long* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (uchar)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_long_elements_short(string name, size_t sample, constant short* original_scalar, const short* original_array, const long* expected, const long* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (short)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_long_elements_ushort(string name, size_t sample, constant ushort* original_scalar, const ushort* original_array, const long* expected, const long* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (ushort)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_long_elements_int(string name, size_t sample, constant int* original_scalar, const int* original_array, const long* expected, const long* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (int)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_long_elements_uint(string name, size_t sample, constant uint* original_scalar, const uint* original_array, const long* expected, const long* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (uint)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_long_elements_long(string name, size_t sample, constant long* original_scalar, const long* original_array, const long* expected, const long* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (long)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_long_elements_ulong(string name, size_t sample, constant ulong* original_scalar, const ulong* original_array, const long* expected, const long* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (ulong)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_long_elements_float(string name, size_t sample, constant float* original_scalar, const float* original_array, const long* expected, const long* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.8g expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (float)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_fp64

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_long_elements_double(string name, size_t sample, constant double* original_scalar, const double* original_array, const long* expected, const long* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.17g expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (double)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_ulong_elements_char(string name, size_t sample, constant char* original_scalar, const char* original_array, const ulong* expected, const ulong* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (char)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_ulong_elements_uchar(string name, size_t sample, constant uchar* original_scalar, const uchar* original_array, const ulong* expected, const ulong* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (uchar)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_ulong_elements_short(string name, size_t sample, constant short* original_scalar, const short* original_array, const ulong* expected, const ulong* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (short)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_ulong_elements_ushort(string name, size_t sample, constant ushort* original_scalar, const ushort* original_array, const ulong* expected, const ulong* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (ushort)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_ulong_elements_int(string name, size_t sample, constant int* original_scalar, const int* original_array, const ulong* expected, const ulong* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (int)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_ulong_elements_uint(string name, size_t sample, constant uint* original_scalar, const uint* original_array, const ulong* expected, const ulong* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (uint)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_ulong_elements_long(string name, size_t sample, constant long* original_scalar, const long* original_array, const ulong* expected, const ulong* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (long)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_ulong_elements_ulong(string name, size_t sample, constant ulong* original_scalar, const ulong* original_array, const ulong* expected, const ulong* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (ulong)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_ulong_elements_float(string name, size_t sample, constant float* original_scalar, const float* original_array, const ulong* expected, const ulong* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.8g expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (float)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_fp64

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_ulong_elements_double(string name, size_t sample, constant double* original_scalar, const double* original_array, const ulong* expected, const ulong* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.17g expected: %#.16llx actual: %#.16llx\n",
        name, (uint)sample, (uint)i, (double)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#endif

_CL_NOINLINE
void compare_float_elements_char(string name, size_t sample, constant char* original_scalar, const char* original_array, const float* expected, const float* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %.8g actual: %.8g\n",
        name, (uint)sample, (uint)i, (char)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_float_elements_uchar(string name, size_t sample, constant uchar* original_scalar, const uchar* original_array, const float* expected, const float* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %.8g actual: %.8g\n",
        name, (uint)sample, (uint)i, (uchar)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_float_elements_short(string name, size_t sample, constant short* original_scalar, const short* original_array, const float* expected, const float* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %.8g actual: %.8g\n",
        name, (uint)sample, (uint)i, (short)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_float_elements_ushort(string name, size_t sample, constant ushort* original_scalar, const ushort* original_array, const float* expected, const float* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %.8g actual: %.8g\n",
        name, (uint)sample, (uint)i, (ushort)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_float_elements_int(string name, size_t sample, constant int* original_scalar, const int* original_array, const float* expected, const float* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %.8g actual: %.8g\n",
        name, (uint)sample, (uint)i, (int)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

_CL_NOINLINE
void compare_float_elements_uint(string name, size_t sample, constant uint* original_scalar, const uint* original_array, const float* expected, const float* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %.8g actual: %.8g\n",
        name, (uint)sample, (uint)i, (uint)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_float_elements_long(string name, size_t sample, constant long* original_scalar, const long* original_array, const float* expected, const float* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %.8g actual: %.8g\n",
        name, (uint)sample, (uint)i, (long)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_float_elements_ulong(string name, size_t sample, constant ulong* original_scalar, const ulong* original_array, const float* expected, const float* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %.8g actual: %.8g\n",
        name, (uint)sample, (uint)i, (ulong)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

_CL_NOINLINE
void compare_float_elements_float(string name, size_t sample, constant float* original_scalar, const float* original_array, const float* expected, const float* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.8g expected: %.8g actual: %.8g\n",
        name, (uint)sample, (uint)i, (float)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_float_elements_double(string name, size_t sample, constant double* original_scalar, const double* original_array, const float* expected, const float* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.17g expected: %.8g actual: %.8g\n",
        name, (uint)sample, (uint)i, (double)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_double_elements_char(string name, size_t sample, constant char* original_scalar, const char* original_array, const double* expected, const double* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %.17g actual: %.17g\n",
        name, (uint)sample, (uint)i, (char)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_double_elements_uchar(string name, size_t sample, constant uchar* original_scalar, const uchar* original_array, const double* expected, const double* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.2hhx expected: %.17g actual: %.17g\n",
        name, (uint)sample, (uint)i, (uchar)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_double_elements_short(string name, size_t sample, constant short* original_scalar, const short* original_array, const double* expected, const double* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %.17g actual: %.17g\n",
        name, (uint)sample, (uint)i, (short)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_double_elements_ushort(string name, size_t sample, constant ushort* original_scalar, const ushort* original_array, const double* expected, const double* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.4hx expected: %.17g actual: %.17g\n",
        name, (uint)sample, (uint)i, (ushort)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_double_elements_int(string name, size_t sample, constant int* original_scalar, const int* original_array, const double* expected, const double* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %.17g actual: %.17g\n",
        name, (uint)sample, (uint)i, (int)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_double_elements_uint(string name, size_t sample, constant uint* original_scalar, const uint* original_array, const double* expected, const double* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.8x expected: %.17g actual: %.17g\n",
        name, (uint)sample, (uint)i, (uint)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_fp64

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_double_elements_long(string name, size_t sample, constant long* original_scalar, const long* original_array, const double* expected, const double* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %.17g actual: %.17g\n",
        name, (uint)sample, (uint)i, (long)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#endif

#ifdef cl_khr_fp64

#ifdef cl_khr_int64

_CL_NOINLINE
void compare_double_elements_ulong(string name, size_t sample, constant ulong* original_scalar, const ulong* original_array, const double* expected, const double* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %#.16llx expected: %.17g actual: %.17g\n",
        name, (uint)sample, (uint)i, (ulong)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#endif

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_double_elements_float(string name, size_t sample, constant float* original_scalar, const float* original_array, const double* expected, const double* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.8g expected: %.17g actual: %.17g\n",
        name, (uint)sample, (uint)i, (float)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

#ifdef cl_khr_fp64

_CL_NOINLINE
void compare_double_elements_double(string name, size_t sample, constant double* original_scalar, const double* original_array, const double* expected, const double* actual, size_t n)
{
  for (size_t i = 0; i < n; ++i) {
    if (expected[i] != actual[i]) {
      printf("FAIL: %s - sample#: %u element#: %u original: %.17g expected: %.17g actual: %.17g\n",
        name, (uint)sample, (uint)i, (double)(original_scalar ? *original_scalar : original_array[i]), expected[i], actual[i]);
    }
  }
}

#endif

kernel void test_convert_type_char_char() {
  for (size_t i = 0; i < char_values_length; ++i) {
    const char min_expected = (char)(CHAR_MIN > CHAR_MIN) ? (char)CHAR_MIN : CHAR_MIN;
    const char max_expected = (char)(CHAR_MAX < CHAR_MAX) ? (char)CHAR_MAX : CHAR_MAX;
    union { char value; char raw[1]; } expected, actual;
    expected.value = ((char)((char)char_values[i]));
    actual.value = convert_char((char)char_values[i]);
    compare_char_elements_char("convert_char(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
    if (char_values[i] < min_expected) {
       expected.value = (char)min_expected;
    }
    else if (char_values[i] > max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat((char)char_values[i]);
    compare_char_elements_char("convert_char_sat(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_uchar_char() {
  for (size_t i = 0; i < char_values_length; ++i) {
    const char min_expected = (char)(0 > CHAR_MIN) ? (char)0 : CHAR_MIN;
    const char max_expected = (char)(UCHAR_MAX < CHAR_MAX) ? (char)UCHAR_MAX : CHAR_MAX;
    union { uchar value; uchar raw[1]; } expected, actual;
    expected.value = ((uchar)((uchar)char_values[i]));
    actual.value = convert_uchar((char)char_values[i]);
    compare_uchar_elements_char("convert_uchar(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
    if (char_values[i] < min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (char_values[i] > max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat((char)char_values[i]);
    compare_uchar_elements_char("convert_uchar_sat(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_short_char() {
  for (size_t i = 0; i < char_values_length; ++i) {
    const char min_expected = (char)(SHRT_MIN > CHAR_MIN) ? (char)SHRT_MIN : CHAR_MIN;
    const char max_expected = (char)(SHRT_MAX < CHAR_MAX) ? (char)SHRT_MAX : CHAR_MAX;
    union { short value; short raw[1]; } expected, actual;
    expected.value = ((short)((short)char_values[i]));
    actual.value = convert_short((char)char_values[i]);
    compare_short_elements_char("convert_short(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
    if (char_values[i] < min_expected) {
       expected.value = (short)min_expected;
    }
    else if (char_values[i] > max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat((char)char_values[i]);
    compare_short_elements_char("convert_short_sat(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_ushort_char() {
  for (size_t i = 0; i < char_values_length; ++i) {
    const char min_expected = (char)(0 > CHAR_MIN) ? (char)0 : CHAR_MIN;
    const char max_expected = (char)(USHRT_MAX < CHAR_MAX) ? (char)USHRT_MAX : CHAR_MAX;
    union { ushort value; ushort raw[1]; } expected, actual;
    expected.value = ((ushort)((ushort)char_values[i]));
    actual.value = convert_ushort((char)char_values[i]);
    compare_ushort_elements_char("convert_ushort(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
    if (char_values[i] < min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (char_values[i] > max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat((char)char_values[i]);
    compare_ushort_elements_char("convert_ushort_sat(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_int_char() {
  for (size_t i = 0; i < char_values_length; ++i) {
    const char min_expected = (char)(INT_MIN > CHAR_MIN) ? (char)INT_MIN : CHAR_MIN;
    const char max_expected = (char)(INT_MAX < CHAR_MAX) ? (char)INT_MAX : CHAR_MAX;
    union { int value; int raw[1]; } expected, actual;
    expected.value = ((int)((int)char_values[i]));
    actual.value = convert_int((char)char_values[i]);
    compare_int_elements_char("convert_int(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
    if (char_values[i] < min_expected) {
       expected.value = (int)min_expected;
    }
    else if (char_values[i] > max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat((char)char_values[i]);
    compare_int_elements_char("convert_int_sat(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_uint_char() {
  for (size_t i = 0; i < char_values_length; ++i) {
    const char min_expected = (char)(0 > CHAR_MIN) ? (char)0 : CHAR_MIN;
    const char max_expected = (char)(UINT_MAX < CHAR_MAX) ? (char)UINT_MAX : CHAR_MAX;
    union { uint value; uint raw[1]; } expected, actual;
    expected.value = ((uint)((uint)char_values[i]));
    actual.value = convert_uint((char)char_values[i]);
    compare_uint_elements_char("convert_uint(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
    if (char_values[i] < min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (char_values[i] > max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat((char)char_values[i]);
    compare_uint_elements_char("convert_uint_sat(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#ifdef cl_khr_int64

kernel void test_convert_type_long_char() {
  for (size_t i = 0; i < char_values_length; ++i) {
    const char min_expected = (char)(LONG_MIN > CHAR_MIN) ? (char)LONG_MIN : CHAR_MIN;
    const char max_expected = (char)(LONG_MAX < CHAR_MAX) ? (char)LONG_MAX : CHAR_MAX;
    union { long value; long raw[1]; } expected, actual;
    expected.value = ((long)((long)char_values[i]));
    actual.value = convert_long((char)char_values[i]);
    compare_long_elements_char("convert_long(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
    if (char_values[i] < min_expected) {
       expected.value = (long)min_expected;
    }
    else if (char_values[i] > max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat((char)char_values[i]);
    compare_long_elements_char("convert_long_sat(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_ulong_char() {
  for (size_t i = 0; i < char_values_length; ++i) {
    const char min_expected = (char)(0 > CHAR_MIN) ? (char)0 : CHAR_MIN;
    const char max_expected = (char)(ULONG_MAX < CHAR_MAX) ? (char)ULONG_MAX : CHAR_MAX;
    union { ulong value; ulong raw[1]; } expected, actual;
    expected.value = ((ulong)((ulong)char_values[i]));
    actual.value = convert_ulong((char)char_values[i]);
    compare_ulong_elements_char("convert_ulong(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
    if (char_values[i] < min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (char_values[i] > max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat((char)char_values[i]);
    compare_ulong_elements_char("convert_ulong_sat(char)", i, &char_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

kernel void test_convert_type_char_uchar() {
  for (size_t i = 0; i < uchar_values_length; ++i) {
    const uchar min_expected = (uchar)(CHAR_MIN > 0) ? (uchar)CHAR_MIN : 0;
    const uchar max_expected = (uchar)(CHAR_MAX < UCHAR_MAX) ? (uchar)CHAR_MAX : UCHAR_MAX;
    union { char value; char raw[1]; } expected, actual;
    expected.value = ((char)((char)uchar_values[i]));
    actual.value = convert_char((uchar)uchar_values[i]);
    compare_char_elements_uchar("convert_char(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
    if (uchar_values[i] < min_expected) {
       expected.value = (char)min_expected;
    }
    else if (uchar_values[i] > max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat((uchar)uchar_values[i]);
    compare_char_elements_uchar("convert_char_sat(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_uchar_uchar() {
  for (size_t i = 0; i < uchar_values_length; ++i) {
    const uchar min_expected = (uchar)(0 > 0) ? (uchar)0 : 0;
    const uchar max_expected = (uchar)(UCHAR_MAX < UCHAR_MAX) ? (uchar)UCHAR_MAX : UCHAR_MAX;
    union { uchar value; uchar raw[1]; } expected, actual;
    expected.value = ((uchar)((uchar)uchar_values[i]));
    actual.value = convert_uchar((uchar)uchar_values[i]);
    compare_uchar_elements_uchar("convert_uchar(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
    if (uchar_values[i] < min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (uchar_values[i] > max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat((uchar)uchar_values[i]);
    compare_uchar_elements_uchar("convert_uchar_sat(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_short_uchar() {
  for (size_t i = 0; i < uchar_values_length; ++i) {
    const uchar min_expected = (uchar)(SHRT_MIN > 0) ? (uchar)SHRT_MIN : 0;
    const uchar max_expected = (uchar)(SHRT_MAX < UCHAR_MAX) ? (uchar)SHRT_MAX : UCHAR_MAX;
    union { short value; short raw[1]; } expected, actual;
    expected.value = ((short)((short)uchar_values[i]));
    actual.value = convert_short((uchar)uchar_values[i]);
    compare_short_elements_uchar("convert_short(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
    if (uchar_values[i] < min_expected) {
       expected.value = (short)min_expected;
    }
    else if (uchar_values[i] > max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat((uchar)uchar_values[i]);
    compare_short_elements_uchar("convert_short_sat(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_ushort_uchar() {
  for (size_t i = 0; i < uchar_values_length; ++i) {
    const uchar min_expected = (uchar)(0 > 0) ? (uchar)0 : 0;
    const uchar max_expected = (uchar)(USHRT_MAX < UCHAR_MAX) ? (uchar)USHRT_MAX : UCHAR_MAX;
    union { ushort value; ushort raw[1]; } expected, actual;
    expected.value = ((ushort)((ushort)uchar_values[i]));
    actual.value = convert_ushort((uchar)uchar_values[i]);
    compare_ushort_elements_uchar("convert_ushort(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
    if (uchar_values[i] < min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (uchar_values[i] > max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat((uchar)uchar_values[i]);
    compare_ushort_elements_uchar("convert_ushort_sat(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_int_uchar() {
  for (size_t i = 0; i < uchar_values_length; ++i) {
    const uchar min_expected = (uchar)(INT_MIN > 0) ? (uchar)INT_MIN : 0;
    const uchar max_expected = (uchar)(INT_MAX < UCHAR_MAX) ? (uchar)INT_MAX : UCHAR_MAX;
    union { int value; int raw[1]; } expected, actual;
    expected.value = ((int)((int)uchar_values[i]));
    actual.value = convert_int((uchar)uchar_values[i]);
    compare_int_elements_uchar("convert_int(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
    if (uchar_values[i] < min_expected) {
       expected.value = (int)min_expected;
    }
    else if (uchar_values[i] > max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat((uchar)uchar_values[i]);
    compare_int_elements_uchar("convert_int_sat(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_uint_uchar() {
  for (size_t i = 0; i < uchar_values_length; ++i) {
    const uchar min_expected = (uchar)(0 > 0) ? (uchar)0 : 0;
    const uchar max_expected = (uchar)(UINT_MAX < UCHAR_MAX) ? (uchar)UINT_MAX : UCHAR_MAX;
    union { uint value; uint raw[1]; } expected, actual;
    expected.value = ((uint)((uint)uchar_values[i]));
    actual.value = convert_uint((uchar)uchar_values[i]);
    compare_uint_elements_uchar("convert_uint(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
    if (uchar_values[i] < min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (uchar_values[i] > max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat((uchar)uchar_values[i]);
    compare_uint_elements_uchar("convert_uint_sat(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#ifdef cl_khr_int64

kernel void test_convert_type_long_uchar() {
  for (size_t i = 0; i < uchar_values_length; ++i) {
    const uchar min_expected = (uchar)(LONG_MIN > 0) ? (uchar)LONG_MIN : 0;
    const uchar max_expected = (uchar)(LONG_MAX < UCHAR_MAX) ? (uchar)LONG_MAX : UCHAR_MAX;
    union { long value; long raw[1]; } expected, actual;
    expected.value = ((long)((long)uchar_values[i]));
    actual.value = convert_long((uchar)uchar_values[i]);
    compare_long_elements_uchar("convert_long(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
    if (uchar_values[i] < min_expected) {
       expected.value = (long)min_expected;
    }
    else if (uchar_values[i] > max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat((uchar)uchar_values[i]);
    compare_long_elements_uchar("convert_long_sat(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_ulong_uchar() {
  for (size_t i = 0; i < uchar_values_length; ++i) {
    const uchar min_expected = (uchar)(0 > 0) ? (uchar)0 : 0;
    const uchar max_expected = (uchar)(ULONG_MAX < UCHAR_MAX) ? (uchar)ULONG_MAX : UCHAR_MAX;
    union { ulong value; ulong raw[1]; } expected, actual;
    expected.value = ((ulong)((ulong)uchar_values[i]));
    actual.value = convert_ulong((uchar)uchar_values[i]);
    compare_ulong_elements_uchar("convert_ulong(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
    if (uchar_values[i] < min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (uchar_values[i] > max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat((uchar)uchar_values[i]);
    compare_ulong_elements_uchar("convert_ulong_sat(uchar)", i, &uchar_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

kernel void test_convert_type_char_short() {
  for (size_t i = 0; i < short_values_length; ++i) {
    const short min_expected = (short)(CHAR_MIN > SHRT_MIN) ? (short)CHAR_MIN : SHRT_MIN;
    const short max_expected = (short)(CHAR_MAX < SHRT_MAX) ? (short)CHAR_MAX : SHRT_MAX;
    union { char value; char raw[1]; } expected, actual;
    expected.value = ((char)((char)short_values[i]));
    actual.value = convert_char((short)short_values[i]);
    compare_char_elements_short("convert_char(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
    if (short_values[i] < min_expected) {
       expected.value = (char)min_expected;
    }
    else if (short_values[i] > max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat((short)short_values[i]);
    compare_char_elements_short("convert_char_sat(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_uchar_short() {
  for (size_t i = 0; i < short_values_length; ++i) {
    const short min_expected = (short)(0 > SHRT_MIN) ? (short)0 : SHRT_MIN;
    const short max_expected = (short)(UCHAR_MAX < SHRT_MAX) ? (short)UCHAR_MAX : SHRT_MAX;
    union { uchar value; uchar raw[1]; } expected, actual;
    expected.value = ((uchar)((uchar)short_values[i]));
    actual.value = convert_uchar((short)short_values[i]);
    compare_uchar_elements_short("convert_uchar(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
    if (short_values[i] < min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (short_values[i] > max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat((short)short_values[i]);
    compare_uchar_elements_short("convert_uchar_sat(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_short_short() {
  for (size_t i = 0; i < short_values_length; ++i) {
    const short min_expected = (short)(SHRT_MIN > SHRT_MIN) ? (short)SHRT_MIN : SHRT_MIN;
    const short max_expected = (short)(SHRT_MAX < SHRT_MAX) ? (short)SHRT_MAX : SHRT_MAX;
    union { short value; short raw[1]; } expected, actual;
    expected.value = ((short)((short)short_values[i]));
    actual.value = convert_short((short)short_values[i]);
    compare_short_elements_short("convert_short(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
    if (short_values[i] < min_expected) {
       expected.value = (short)min_expected;
    }
    else if (short_values[i] > max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat((short)short_values[i]);
    compare_short_elements_short("convert_short_sat(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_ushort_short() {
  for (size_t i = 0; i < short_values_length; ++i) {
    const short min_expected = (short)(0 > SHRT_MIN) ? (short)0 : SHRT_MIN;
    const short max_expected = (short)(USHRT_MAX < SHRT_MAX) ? (short)USHRT_MAX : SHRT_MAX;
    union { ushort value; ushort raw[1]; } expected, actual;
    expected.value = ((ushort)((ushort)short_values[i]));
    actual.value = convert_ushort((short)short_values[i]);
    compare_ushort_elements_short("convert_ushort(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
    if (short_values[i] < min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (short_values[i] > max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat((short)short_values[i]);
    compare_ushort_elements_short("convert_ushort_sat(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_int_short() {
  for (size_t i = 0; i < short_values_length; ++i) {
    const short min_expected = (short)(INT_MIN > SHRT_MIN) ? (short)INT_MIN : SHRT_MIN;
    const short max_expected = (short)(INT_MAX < SHRT_MAX) ? (short)INT_MAX : SHRT_MAX;
    union { int value; int raw[1]; } expected, actual;
    expected.value = ((int)((int)short_values[i]));
    actual.value = convert_int((short)short_values[i]);
    compare_int_elements_short("convert_int(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
    if (short_values[i] < min_expected) {
       expected.value = (int)min_expected;
    }
    else if (short_values[i] > max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat((short)short_values[i]);
    compare_int_elements_short("convert_int_sat(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_uint_short() {
  for (size_t i = 0; i < short_values_length; ++i) {
    const short min_expected = (short)(0 > SHRT_MIN) ? (short)0 : SHRT_MIN;
    const short max_expected = (short)(UINT_MAX < SHRT_MAX) ? (short)UINT_MAX : SHRT_MAX;
    union { uint value; uint raw[1]; } expected, actual;
    expected.value = ((uint)((uint)short_values[i]));
    actual.value = convert_uint((short)short_values[i]);
    compare_uint_elements_short("convert_uint(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
    if (short_values[i] < min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (short_values[i] > max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat((short)short_values[i]);
    compare_uint_elements_short("convert_uint_sat(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#ifdef cl_khr_int64

kernel void test_convert_type_long_short() {
  for (size_t i = 0; i < short_values_length; ++i) {
    const short min_expected = (short)(LONG_MIN > SHRT_MIN) ? (short)LONG_MIN : SHRT_MIN;
    const short max_expected = (short)(LONG_MAX < SHRT_MAX) ? (short)LONG_MAX : SHRT_MAX;
    union { long value; long raw[1]; } expected, actual;
    expected.value = ((long)((long)short_values[i]));
    actual.value = convert_long((short)short_values[i]);
    compare_long_elements_short("convert_long(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
    if (short_values[i] < min_expected) {
       expected.value = (long)min_expected;
    }
    else if (short_values[i] > max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat((short)short_values[i]);
    compare_long_elements_short("convert_long_sat(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_ulong_short() {
  for (size_t i = 0; i < short_values_length; ++i) {
    const short min_expected = (short)(0 > SHRT_MIN) ? (short)0 : SHRT_MIN;
    const short max_expected = (short)(ULONG_MAX < SHRT_MAX) ? (short)ULONG_MAX : SHRT_MAX;
    union { ulong value; ulong raw[1]; } expected, actual;
    expected.value = ((ulong)((ulong)short_values[i]));
    actual.value = convert_ulong((short)short_values[i]);
    compare_ulong_elements_short("convert_ulong(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
    if (short_values[i] < min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (short_values[i] > max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat((short)short_values[i]);
    compare_ulong_elements_short("convert_ulong_sat(short)", i, &short_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

kernel void test_convert_type_char_ushort() {
  for (size_t i = 0; i < ushort_values_length; ++i) {
    const ushort min_expected = (ushort)(CHAR_MIN > 0) ? (ushort)CHAR_MIN : 0;
    const ushort max_expected = (ushort)(CHAR_MAX < USHRT_MAX) ? (ushort)CHAR_MAX : USHRT_MAX;
    union { char value; char raw[1]; } expected, actual;
    expected.value = ((char)((char)ushort_values[i]));
    actual.value = convert_char((ushort)ushort_values[i]);
    compare_char_elements_ushort("convert_char(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
    if (ushort_values[i] < min_expected) {
       expected.value = (char)min_expected;
    }
    else if (ushort_values[i] > max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat((ushort)ushort_values[i]);
    compare_char_elements_ushort("convert_char_sat(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_uchar_ushort() {
  for (size_t i = 0; i < ushort_values_length; ++i) {
    const ushort min_expected = (ushort)(0 > 0) ? (ushort)0 : 0;
    const ushort max_expected = (ushort)(UCHAR_MAX < USHRT_MAX) ? (ushort)UCHAR_MAX : USHRT_MAX;
    union { uchar value; uchar raw[1]; } expected, actual;
    expected.value = ((uchar)((uchar)ushort_values[i]));
    actual.value = convert_uchar((ushort)ushort_values[i]);
    compare_uchar_elements_ushort("convert_uchar(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
    if (ushort_values[i] < min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (ushort_values[i] > max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat((ushort)ushort_values[i]);
    compare_uchar_elements_ushort("convert_uchar_sat(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_short_ushort() {
  for (size_t i = 0; i < ushort_values_length; ++i) {
    const ushort min_expected = (ushort)(SHRT_MIN > 0) ? (ushort)SHRT_MIN : 0;
    const ushort max_expected = (ushort)(SHRT_MAX < USHRT_MAX) ? (ushort)SHRT_MAX : USHRT_MAX;
    union { short value; short raw[1]; } expected, actual;
    expected.value = ((short)((short)ushort_values[i]));
    actual.value = convert_short((ushort)ushort_values[i]);
    compare_short_elements_ushort("convert_short(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
    if (ushort_values[i] < min_expected) {
       expected.value = (short)min_expected;
    }
    else if (ushort_values[i] > max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat((ushort)ushort_values[i]);
    compare_short_elements_ushort("convert_short_sat(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_ushort_ushort() {
  for (size_t i = 0; i < ushort_values_length; ++i) {
    const ushort min_expected = (ushort)(0 > 0) ? (ushort)0 : 0;
    const ushort max_expected = (ushort)(USHRT_MAX < USHRT_MAX) ? (ushort)USHRT_MAX : USHRT_MAX;
    union { ushort value; ushort raw[1]; } expected, actual;
    expected.value = ((ushort)((ushort)ushort_values[i]));
    actual.value = convert_ushort((ushort)ushort_values[i]);
    compare_ushort_elements_ushort("convert_ushort(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
    if (ushort_values[i] < min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (ushort_values[i] > max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat((ushort)ushort_values[i]);
    compare_ushort_elements_ushort("convert_ushort_sat(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_int_ushort() {
  for (size_t i = 0; i < ushort_values_length; ++i) {
    const ushort min_expected = (ushort)(INT_MIN > 0) ? (ushort)INT_MIN : 0;
    const ushort max_expected = (ushort)(INT_MAX < USHRT_MAX) ? (ushort)INT_MAX : USHRT_MAX;
    union { int value; int raw[1]; } expected, actual;
    expected.value = ((int)((int)ushort_values[i]));
    actual.value = convert_int((ushort)ushort_values[i]);
    compare_int_elements_ushort("convert_int(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
    if (ushort_values[i] < min_expected) {
       expected.value = (int)min_expected;
    }
    else if (ushort_values[i] > max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat((ushort)ushort_values[i]);
    compare_int_elements_ushort("convert_int_sat(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_uint_ushort() {
  for (size_t i = 0; i < ushort_values_length; ++i) {
    const ushort min_expected = (ushort)(0 > 0) ? (ushort)0 : 0;
    const ushort max_expected = (ushort)(UINT_MAX < USHRT_MAX) ? (ushort)UINT_MAX : USHRT_MAX;
    union { uint value; uint raw[1]; } expected, actual;
    expected.value = ((uint)((uint)ushort_values[i]));
    actual.value = convert_uint((ushort)ushort_values[i]);
    compare_uint_elements_ushort("convert_uint(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
    if (ushort_values[i] < min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (ushort_values[i] > max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat((ushort)ushort_values[i]);
    compare_uint_elements_ushort("convert_uint_sat(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#ifdef cl_khr_int64

kernel void test_convert_type_long_ushort() {
  for (size_t i = 0; i < ushort_values_length; ++i) {
    const ushort min_expected = (ushort)(LONG_MIN > 0) ? (ushort)LONG_MIN : 0;
    const ushort max_expected = (ushort)(LONG_MAX < USHRT_MAX) ? (ushort)LONG_MAX : USHRT_MAX;
    union { long value; long raw[1]; } expected, actual;
    expected.value = ((long)((long)ushort_values[i]));
    actual.value = convert_long((ushort)ushort_values[i]);
    compare_long_elements_ushort("convert_long(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
    if (ushort_values[i] < min_expected) {
       expected.value = (long)min_expected;
    }
    else if (ushort_values[i] > max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat((ushort)ushort_values[i]);
    compare_long_elements_ushort("convert_long_sat(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_ulong_ushort() {
  for (size_t i = 0; i < ushort_values_length; ++i) {
    const ushort min_expected = (ushort)(0 > 0) ? (ushort)0 : 0;
    const ushort max_expected = (ushort)(ULONG_MAX < USHRT_MAX) ? (ushort)ULONG_MAX : USHRT_MAX;
    union { ulong value; ulong raw[1]; } expected, actual;
    expected.value = ((ulong)((ulong)ushort_values[i]));
    actual.value = convert_ulong((ushort)ushort_values[i]);
    compare_ulong_elements_ushort("convert_ulong(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
    if (ushort_values[i] < min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (ushort_values[i] > max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat((ushort)ushort_values[i]);
    compare_ulong_elements_ushort("convert_ulong_sat(ushort)", i, &ushort_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

kernel void test_convert_type_char_int() {
  for (size_t i = 0; i < int_values_length; ++i) {
    const int min_expected = (int)(CHAR_MIN > INT_MIN) ? (int)CHAR_MIN : INT_MIN;
    const int max_expected = (int)(CHAR_MAX < INT_MAX) ? (int)CHAR_MAX : INT_MAX;
    union { char value; char raw[1]; } expected, actual;
    expected.value = ((char)((char)int_values[i]));
    actual.value = convert_char((int)int_values[i]);
    compare_char_elements_int("convert_char(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
    if (int_values[i] < min_expected) {
       expected.value = (char)min_expected;
    }
    else if (int_values[i] > max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat((int)int_values[i]);
    compare_char_elements_int("convert_char_sat(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_uchar_int() {
  for (size_t i = 0; i < int_values_length; ++i) {
    const int min_expected = (int)(0 > INT_MIN) ? (int)0 : INT_MIN;
    const int max_expected = (int)(UCHAR_MAX < INT_MAX) ? (int)UCHAR_MAX : INT_MAX;
    union { uchar value; uchar raw[1]; } expected, actual;
    expected.value = ((uchar)((uchar)int_values[i]));
    actual.value = convert_uchar((int)int_values[i]);
    compare_uchar_elements_int("convert_uchar(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
    if (int_values[i] < min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (int_values[i] > max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat((int)int_values[i]);
    compare_uchar_elements_int("convert_uchar_sat(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_short_int() {
  for (size_t i = 0; i < int_values_length; ++i) {
    const int min_expected = (int)(SHRT_MIN > INT_MIN) ? (int)SHRT_MIN : INT_MIN;
    const int max_expected = (int)(SHRT_MAX < INT_MAX) ? (int)SHRT_MAX : INT_MAX;
    union { short value; short raw[1]; } expected, actual;
    expected.value = ((short)((short)int_values[i]));
    actual.value = convert_short((int)int_values[i]);
    compare_short_elements_int("convert_short(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
    if (int_values[i] < min_expected) {
       expected.value = (short)min_expected;
    }
    else if (int_values[i] > max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat((int)int_values[i]);
    compare_short_elements_int("convert_short_sat(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_ushort_int() {
  for (size_t i = 0; i < int_values_length; ++i) {
    const int min_expected = (int)(0 > INT_MIN) ? (int)0 : INT_MIN;
    const int max_expected = (int)(USHRT_MAX < INT_MAX) ? (int)USHRT_MAX : INT_MAX;
    union { ushort value; ushort raw[1]; } expected, actual;
    expected.value = ((ushort)((ushort)int_values[i]));
    actual.value = convert_ushort((int)int_values[i]);
    compare_ushort_elements_int("convert_ushort(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
    if (int_values[i] < min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (int_values[i] > max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat((int)int_values[i]);
    compare_ushort_elements_int("convert_ushort_sat(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_int_int() {
  for (size_t i = 0; i < int_values_length; ++i) {
    const int min_expected = (int)(INT_MIN > INT_MIN) ? (int)INT_MIN : INT_MIN;
    const int max_expected = (int)(INT_MAX < INT_MAX) ? (int)INT_MAX : INT_MAX;
    union { int value; int raw[1]; } expected, actual;
    expected.value = ((int)((int)int_values[i]));
    actual.value = convert_int((int)int_values[i]);
    compare_int_elements_int("convert_int(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
    if (int_values[i] < min_expected) {
       expected.value = (int)min_expected;
    }
    else if (int_values[i] > max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat((int)int_values[i]);
    compare_int_elements_int("convert_int_sat(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_uint_int() {
  for (size_t i = 0; i < int_values_length; ++i) {
    const int min_expected = (int)(0 > INT_MIN) ? (int)0 : INT_MIN;
    const int max_expected = (int)(UINT_MAX < INT_MAX) ? (int)UINT_MAX : INT_MAX;
    union { uint value; uint raw[1]; } expected, actual;
    expected.value = ((uint)((uint)int_values[i]));
    actual.value = convert_uint((int)int_values[i]);
    compare_uint_elements_int("convert_uint(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
    if (int_values[i] < min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (int_values[i] > max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat((int)int_values[i]);
    compare_uint_elements_int("convert_uint_sat(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#ifdef cl_khr_int64

kernel void test_convert_type_long_int() {
  for (size_t i = 0; i < int_values_length; ++i) {
    const int min_expected = (int)(LONG_MIN > INT_MIN) ? (int)LONG_MIN : INT_MIN;
    const int max_expected = (int)(LONG_MAX < INT_MAX) ? (int)LONG_MAX : INT_MAX;
    union { long value; long raw[1]; } expected, actual;
    expected.value = ((long)((long)int_values[i]));
    actual.value = convert_long((int)int_values[i]);
    compare_long_elements_int("convert_long(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
    if (int_values[i] < min_expected) {
       expected.value = (long)min_expected;
    }
    else if (int_values[i] > max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat((int)int_values[i]);
    compare_long_elements_int("convert_long_sat(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_ulong_int() {
  for (size_t i = 0; i < int_values_length; ++i) {
    const int min_expected = (int)(0 > INT_MIN) ? (int)0 : INT_MIN;
    const int max_expected = (int)(ULONG_MAX < INT_MAX) ? (int)ULONG_MAX : INT_MAX;
    union { ulong value; ulong raw[1]; } expected, actual;
    expected.value = ((ulong)((ulong)int_values[i]));
    actual.value = convert_ulong((int)int_values[i]);
    compare_ulong_elements_int("convert_ulong(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
    if (int_values[i] < min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (int_values[i] > max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat((int)int_values[i]);
    compare_ulong_elements_int("convert_ulong_sat(int)", i, &int_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

kernel void test_convert_type_char_uint() {
  for (size_t i = 0; i < uint_values_length; ++i) {
    const uint min_expected = (uint)(CHAR_MIN > 0) ? (uint)CHAR_MIN : 0;
    const uint max_expected = (uint)(CHAR_MAX < UINT_MAX) ? (uint)CHAR_MAX : UINT_MAX;
    union { char value; char raw[1]; } expected, actual;
    expected.value = ((char)((char)uint_values[i]));
    actual.value = convert_char((uint)uint_values[i]);
    compare_char_elements_uint("convert_char(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
    if (uint_values[i] < min_expected) {
       expected.value = (char)min_expected;
    }
    else if (uint_values[i] > max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat((uint)uint_values[i]);
    compare_char_elements_uint("convert_char_sat(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_uchar_uint() {
  for (size_t i = 0; i < uint_values_length; ++i) {
    const uint min_expected = (uint)(0 > 0) ? (uint)0 : 0;
    const uint max_expected = (uint)(UCHAR_MAX < UINT_MAX) ? (uint)UCHAR_MAX : UINT_MAX;
    union { uchar value; uchar raw[1]; } expected, actual;
    expected.value = ((uchar)((uchar)uint_values[i]));
    actual.value = convert_uchar((uint)uint_values[i]);
    compare_uchar_elements_uint("convert_uchar(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
    if (uint_values[i] < min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (uint_values[i] > max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat((uint)uint_values[i]);
    compare_uchar_elements_uint("convert_uchar_sat(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_short_uint() {
  for (size_t i = 0; i < uint_values_length; ++i) {
    const uint min_expected = (uint)(SHRT_MIN > 0) ? (uint)SHRT_MIN : 0;
    const uint max_expected = (uint)(SHRT_MAX < UINT_MAX) ? (uint)SHRT_MAX : UINT_MAX;
    union { short value; short raw[1]; } expected, actual;
    expected.value = ((short)((short)uint_values[i]));
    actual.value = convert_short((uint)uint_values[i]);
    compare_short_elements_uint("convert_short(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
    if (uint_values[i] < min_expected) {
       expected.value = (short)min_expected;
    }
    else if (uint_values[i] > max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat((uint)uint_values[i]);
    compare_short_elements_uint("convert_short_sat(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_ushort_uint() {
  for (size_t i = 0; i < uint_values_length; ++i) {
    const uint min_expected = (uint)(0 > 0) ? (uint)0 : 0;
    const uint max_expected = (uint)(USHRT_MAX < UINT_MAX) ? (uint)USHRT_MAX : UINT_MAX;
    union { ushort value; ushort raw[1]; } expected, actual;
    expected.value = ((ushort)((ushort)uint_values[i]));
    actual.value = convert_ushort((uint)uint_values[i]);
    compare_ushort_elements_uint("convert_ushort(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
    if (uint_values[i] < min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (uint_values[i] > max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat((uint)uint_values[i]);
    compare_ushort_elements_uint("convert_ushort_sat(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_int_uint() {
  for (size_t i = 0; i < uint_values_length; ++i) {
    const uint min_expected = (uint)(INT_MIN > 0) ? (uint)INT_MIN : 0;
    const uint max_expected = (uint)(INT_MAX < UINT_MAX) ? (uint)INT_MAX : UINT_MAX;
    union { int value; int raw[1]; } expected, actual;
    expected.value = ((int)((int)uint_values[i]));
    actual.value = convert_int((uint)uint_values[i]);
    compare_int_elements_uint("convert_int(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
    if (uint_values[i] < min_expected) {
       expected.value = (int)min_expected;
    }
    else if (uint_values[i] > max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat((uint)uint_values[i]);
    compare_int_elements_uint("convert_int_sat(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
  }
}

kernel void test_convert_type_uint_uint() {
  for (size_t i = 0; i < uint_values_length; ++i) {
    const uint min_expected = (uint)(0 > 0) ? (uint)0 : 0;
    const uint max_expected = (uint)(UINT_MAX < UINT_MAX) ? (uint)UINT_MAX : UINT_MAX;
    union { uint value; uint raw[1]; } expected, actual;
    expected.value = ((uint)((uint)uint_values[i]));
    actual.value = convert_uint((uint)uint_values[i]);
    compare_uint_elements_uint("convert_uint(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
    if (uint_values[i] < min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (uint_values[i] > max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat((uint)uint_values[i]);
    compare_uint_elements_uint("convert_uint_sat(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#ifdef cl_khr_int64

kernel void test_convert_type_long_uint() {
  for (size_t i = 0; i < uint_values_length; ++i) {
    const uint min_expected = (uint)(LONG_MIN > 0) ? (uint)LONG_MIN : 0;
    const uint max_expected = (uint)(LONG_MAX < UINT_MAX) ? (uint)LONG_MAX : UINT_MAX;
    union { long value; long raw[1]; } expected, actual;
    expected.value = ((long)((long)uint_values[i]));
    actual.value = convert_long((uint)uint_values[i]);
    compare_long_elements_uint("convert_long(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
    if (uint_values[i] < min_expected) {
       expected.value = (long)min_expected;
    }
    else if (uint_values[i] > max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat((uint)uint_values[i]);
    compare_long_elements_uint("convert_long_sat(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_ulong_uint() {
  for (size_t i = 0; i < uint_values_length; ++i) {
    const uint min_expected = (uint)(0 > 0) ? (uint)0 : 0;
    const uint max_expected = (uint)(ULONG_MAX < UINT_MAX) ? (uint)ULONG_MAX : UINT_MAX;
    union { ulong value; ulong raw[1]; } expected, actual;
    expected.value = ((ulong)((ulong)uint_values[i]));
    actual.value = convert_ulong((uint)uint_values[i]);
    compare_ulong_elements_uint("convert_ulong(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
    if (uint_values[i] < min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (uint_values[i] > max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat((uint)uint_values[i]);
    compare_ulong_elements_uint("convert_ulong_sat(uint)", i, &uint_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_char_long() {
  for (size_t i = 0; i < long_values_length; ++i) {
    const long min_expected = (long)(CHAR_MIN > LONG_MIN) ? (long)CHAR_MIN : LONG_MIN;
    const long max_expected = (long)(CHAR_MAX < LONG_MAX) ? (long)CHAR_MAX : LONG_MAX;
    union { char value; char raw[1]; } expected, actual;
    expected.value = ((char)((char)long_values[i]));
    actual.value = convert_char((long)long_values[i]);
    compare_char_elements_long("convert_char(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
    if (long_values[i] < min_expected) {
       expected.value = (char)min_expected;
    }
    else if (long_values[i] > max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat((long)long_values[i]);
    compare_char_elements_long("convert_char_sat(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_uchar_long() {
  for (size_t i = 0; i < long_values_length; ++i) {
    const long min_expected = (long)(0 > LONG_MIN) ? (long)0 : LONG_MIN;
    const long max_expected = (long)(UCHAR_MAX < LONG_MAX) ? (long)UCHAR_MAX : LONG_MAX;
    union { uchar value; uchar raw[1]; } expected, actual;
    expected.value = ((uchar)((uchar)long_values[i]));
    actual.value = convert_uchar((long)long_values[i]);
    compare_uchar_elements_long("convert_uchar(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
    if (long_values[i] < min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (long_values[i] > max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat((long)long_values[i]);
    compare_uchar_elements_long("convert_uchar_sat(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_short_long() {
  for (size_t i = 0; i < long_values_length; ++i) {
    const long min_expected = (long)(SHRT_MIN > LONG_MIN) ? (long)SHRT_MIN : LONG_MIN;
    const long max_expected = (long)(SHRT_MAX < LONG_MAX) ? (long)SHRT_MAX : LONG_MAX;
    union { short value; short raw[1]; } expected, actual;
    expected.value = ((short)((short)long_values[i]));
    actual.value = convert_short((long)long_values[i]);
    compare_short_elements_long("convert_short(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
    if (long_values[i] < min_expected) {
       expected.value = (short)min_expected;
    }
    else if (long_values[i] > max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat((long)long_values[i]);
    compare_short_elements_long("convert_short_sat(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_ushort_long() {
  for (size_t i = 0; i < long_values_length; ++i) {
    const long min_expected = (long)(0 > LONG_MIN) ? (long)0 : LONG_MIN;
    const long max_expected = (long)(USHRT_MAX < LONG_MAX) ? (long)USHRT_MAX : LONG_MAX;
    union { ushort value; ushort raw[1]; } expected, actual;
    expected.value = ((ushort)((ushort)long_values[i]));
    actual.value = convert_ushort((long)long_values[i]);
    compare_ushort_elements_long("convert_ushort(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
    if (long_values[i] < min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (long_values[i] > max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat((long)long_values[i]);
    compare_ushort_elements_long("convert_ushort_sat(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_int_long() {
  for (size_t i = 0; i < long_values_length; ++i) {
    const long min_expected = (long)(INT_MIN > LONG_MIN) ? (long)INT_MIN : LONG_MIN;
    const long max_expected = (long)(INT_MAX < LONG_MAX) ? (long)INT_MAX : LONG_MAX;
    union { int value; int raw[1]; } expected, actual;
    expected.value = ((int)((int)long_values[i]));
    actual.value = convert_int((long)long_values[i]);
    compare_int_elements_long("convert_int(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
    if (long_values[i] < min_expected) {
       expected.value = (int)min_expected;
    }
    else if (long_values[i] > max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat((long)long_values[i]);
    compare_int_elements_long("convert_int_sat(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_uint_long() {
  for (size_t i = 0; i < long_values_length; ++i) {
    const long min_expected = (long)(0 > LONG_MIN) ? (long)0 : LONG_MIN;
    const long max_expected = (long)(UINT_MAX < LONG_MAX) ? (long)UINT_MAX : LONG_MAX;
    union { uint value; uint raw[1]; } expected, actual;
    expected.value = ((uint)((uint)long_values[i]));
    actual.value = convert_uint((long)long_values[i]);
    compare_uint_elements_long("convert_uint(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
    if (long_values[i] < min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (long_values[i] > max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat((long)long_values[i]);
    compare_uint_elements_long("convert_uint_sat(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_long_long() {
  for (size_t i = 0; i < long_values_length; ++i) {
    const long min_expected = (long)(LONG_MIN > LONG_MIN) ? (long)LONG_MIN : LONG_MIN;
    const long max_expected = (long)(LONG_MAX < LONG_MAX) ? (long)LONG_MAX : LONG_MAX;
    union { long value; long raw[1]; } expected, actual;
    expected.value = ((long)((long)long_values[i]));
    actual.value = convert_long((long)long_values[i]);
    compare_long_elements_long("convert_long(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
    if (long_values[i] < min_expected) {
       expected.value = (long)min_expected;
    }
    else if (long_values[i] > max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat((long)long_values[i]);
    compare_long_elements_long("convert_long_sat(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_ulong_long() {
  for (size_t i = 0; i < long_values_length; ++i) {
    const long min_expected = (long)(0 > LONG_MIN) ? (long)0 : LONG_MIN;
    const long max_expected = (long)(ULONG_MAX < LONG_MAX) ? (long)ULONG_MAX : LONG_MAX;
    union { ulong value; ulong raw[1]; } expected, actual;
    expected.value = ((ulong)((ulong)long_values[i]));
    actual.value = convert_ulong((long)long_values[i]);
    compare_ulong_elements_long("convert_ulong(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
    if (long_values[i] < min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (long_values[i] > max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat((long)long_values[i]);
    compare_ulong_elements_long("convert_ulong_sat(long)", i, &long_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_char_ulong() {
  for (size_t i = 0; i < ulong_values_length; ++i) {
    const ulong min_expected = (ulong)(CHAR_MIN > 0) ? (ulong)CHAR_MIN : 0;
    const ulong max_expected = (ulong)(CHAR_MAX < ULONG_MAX) ? (ulong)CHAR_MAX : ULONG_MAX;
    union { char value; char raw[1]; } expected, actual;
    expected.value = ((char)((char)ulong_values[i]));
    actual.value = convert_char((ulong)ulong_values[i]);
    compare_char_elements_ulong("convert_char(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
    if (ulong_values[i] < min_expected) {
       expected.value = (char)min_expected;
    }
    else if (ulong_values[i] > max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat((ulong)ulong_values[i]);
    compare_char_elements_ulong("convert_char_sat(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_uchar_ulong() {
  for (size_t i = 0; i < ulong_values_length; ++i) {
    const ulong min_expected = (ulong)(0 > 0) ? (ulong)0 : 0;
    const ulong max_expected = (ulong)(UCHAR_MAX < ULONG_MAX) ? (ulong)UCHAR_MAX : ULONG_MAX;
    union { uchar value; uchar raw[1]; } expected, actual;
    expected.value = ((uchar)((uchar)ulong_values[i]));
    actual.value = convert_uchar((ulong)ulong_values[i]);
    compare_uchar_elements_ulong("convert_uchar(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
    if (ulong_values[i] < min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (ulong_values[i] > max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat((ulong)ulong_values[i]);
    compare_uchar_elements_ulong("convert_uchar_sat(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_short_ulong() {
  for (size_t i = 0; i < ulong_values_length; ++i) {
    const ulong min_expected = (ulong)(SHRT_MIN > 0) ? (ulong)SHRT_MIN : 0;
    const ulong max_expected = (ulong)(SHRT_MAX < ULONG_MAX) ? (ulong)SHRT_MAX : ULONG_MAX;
    union { short value; short raw[1]; } expected, actual;
    expected.value = ((short)((short)ulong_values[i]));
    actual.value = convert_short((ulong)ulong_values[i]);
    compare_short_elements_ulong("convert_short(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
    if (ulong_values[i] < min_expected) {
       expected.value = (short)min_expected;
    }
    else if (ulong_values[i] > max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat((ulong)ulong_values[i]);
    compare_short_elements_ulong("convert_short_sat(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_ushort_ulong() {
  for (size_t i = 0; i < ulong_values_length; ++i) {
    const ulong min_expected = (ulong)(0 > 0) ? (ulong)0 : 0;
    const ulong max_expected = (ulong)(USHRT_MAX < ULONG_MAX) ? (ulong)USHRT_MAX : ULONG_MAX;
    union { ushort value; ushort raw[1]; } expected, actual;
    expected.value = ((ushort)((ushort)ulong_values[i]));
    actual.value = convert_ushort((ulong)ulong_values[i]);
    compare_ushort_elements_ulong("convert_ushort(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
    if (ulong_values[i] < min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (ulong_values[i] > max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat((ulong)ulong_values[i]);
    compare_ushort_elements_ulong("convert_ushort_sat(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_int_ulong() {
  for (size_t i = 0; i < ulong_values_length; ++i) {
    const ulong min_expected = (ulong)(INT_MIN > 0) ? (ulong)INT_MIN : 0;
    const ulong max_expected = (ulong)(INT_MAX < ULONG_MAX) ? (ulong)INT_MAX : ULONG_MAX;
    union { int value; int raw[1]; } expected, actual;
    expected.value = ((int)((int)ulong_values[i]));
    actual.value = convert_int((ulong)ulong_values[i]);
    compare_int_elements_ulong("convert_int(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
    if (ulong_values[i] < min_expected) {
       expected.value = (int)min_expected;
    }
    else if (ulong_values[i] > max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat((ulong)ulong_values[i]);
    compare_int_elements_ulong("convert_int_sat(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_uint_ulong() {
  for (size_t i = 0; i < ulong_values_length; ++i) {
    const ulong min_expected = (ulong)(0 > 0) ? (ulong)0 : 0;
    const ulong max_expected = (ulong)(UINT_MAX < ULONG_MAX) ? (ulong)UINT_MAX : ULONG_MAX;
    union { uint value; uint raw[1]; } expected, actual;
    expected.value = ((uint)((uint)ulong_values[i]));
    actual.value = convert_uint((ulong)ulong_values[i]);
    compare_uint_elements_ulong("convert_uint(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
    if (ulong_values[i] < min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (ulong_values[i] > max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat((ulong)ulong_values[i]);
    compare_uint_elements_ulong("convert_uint_sat(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_long_ulong() {
  for (size_t i = 0; i < ulong_values_length; ++i) {
    const ulong min_expected = (ulong)(LONG_MIN > 0) ? (ulong)LONG_MIN : 0;
    const ulong max_expected = (ulong)(LONG_MAX < ULONG_MAX) ? (ulong)LONG_MAX : ULONG_MAX;
    union { long value; long raw[1]; } expected, actual;
    expected.value = ((long)((long)ulong_values[i]));
    actual.value = convert_long((ulong)ulong_values[i]);
    compare_long_elements_ulong("convert_long(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
    if (ulong_values[i] < min_expected) {
       expected.value = (long)min_expected;
    }
    else if (ulong_values[i] > max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat((ulong)ulong_values[i]);
    compare_long_elements_ulong("convert_long_sat(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_ulong_ulong() {
  for (size_t i = 0; i < ulong_values_length; ++i) {
    const ulong min_expected = (ulong)(0 > 0) ? (ulong)0 : 0;
    const ulong max_expected = (ulong)(ULONG_MAX < ULONG_MAX) ? (ulong)ULONG_MAX : ULONG_MAX;
    union { ulong value; ulong raw[1]; } expected, actual;
    expected.value = ((ulong)((ulong)ulong_values[i]));
    actual.value = convert_ulong((ulong)ulong_values[i]);
    compare_ulong_elements_ulong("convert_ulong(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
    if (ulong_values[i] < min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (ulong_values[i] > max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat((ulong)ulong_values[i]);
    compare_ulong_elements_ulong("convert_ulong_sat(ulong)", i, &ulong_values[i], 0, expected.raw, actual.raw, 1);
  }
}

#endif

kernel void test_convert_type_char_float() {
  for (size_t i = 0; i < float_values_length; ++i) {
    const float sat_input = (float_values[i] + float_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const char min_expected = (char)(CHAR_MIN > -FLT_MAX) ? CHAR_MIN : (char)-FLT_MAX;
    const char max_expected = (char)(CHAR_MAX < FLT_MAX) ? CHAR_MAX : (char)FLT_MAX;
    union { char value; char raw[1]; } expected, actual;
    expected.value = ((char)((char)float_rounded_values[i]));
    actual.value = convert_char((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (char)((char)0 - (char)1) >= (char)0;
      bool result_is_negative = float_rounded_values[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (char)0;
        actual.raw[n] = (char)0;
      }
    }
    compare_char_elements_float("convert_char(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (char)convert_char(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (char)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat((float)sat_input);
    compare_char_elements_float("convert_char_sat(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((char)((char)float_rounded_values_rte[i]));
    actual.value = convert_char_rte((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (char)((char)0 - (char)1) >= (char)0;
      bool result_is_negative = float_rounded_values_rte[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (char)0;
        actual.raw[n] = (char)0;
      }
    }
    compare_char_elements_float("convert_char_rte(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (char)convert_char_rte(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (char)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat_rte((float)sat_input);
    compare_char_elements_float("convert_char_sat_rte(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((char)((char)float_rounded_values_rtz[i]));
    actual.value = convert_char_rtz((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (char)((char)0 - (char)1) >= (char)0;
      bool result_is_negative = float_rounded_values_rtz[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (char)0;
        actual.raw[n] = (char)0;
      }
    }
    compare_char_elements_float("convert_char_rtz(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (char)convert_char_rtz(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (char)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat_rtz((float)sat_input);
    compare_char_elements_float("convert_char_sat_rtz(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((char)((char)float_rounded_values_rtp[i]));
    actual.value = convert_char_rtp((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (char)((char)0 - (char)1) >= (char)0;
      bool result_is_negative = float_rounded_values_rtp[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (char)0;
        actual.raw[n] = (char)0;
      }
    }
    compare_char_elements_float("convert_char_rtp(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (char)convert_char_rtp(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (char)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat_rtp((float)sat_input);
    compare_char_elements_float("convert_char_sat_rtp(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((char)((char)float_rounded_values_rtn[i]));
    actual.value = convert_char_rtn((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (char)((char)0 - (char)1) >= (char)0;
      bool result_is_negative = float_rounded_values_rtn[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (char)0;
        actual.raw[n] = (char)0;
      }
    }
    compare_char_elements_float("convert_char_rtn(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (char)convert_char_rtn(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (char)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat_rtn((float)sat_input);
    compare_char_elements_float("convert_char_sat_rtn(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

kernel void test_convert_type_uchar_float() {
  for (size_t i = 0; i < float_values_length; ++i) {
    const float sat_input = (float_values[i] + float_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const uchar min_expected = (uchar)(0 > -FLT_MAX) ? 0 : (uchar)-FLT_MAX;
    const uchar max_expected = (uchar)(UCHAR_MAX < FLT_MAX) ? UCHAR_MAX : (uchar)FLT_MAX;
    union { uchar value; uchar raw[1]; } expected, actual;
    expected.value = ((uchar)((uchar)float_rounded_values[i]));
    actual.value = convert_uchar((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uchar)((uchar)0 - (uchar)1) >= (uchar)0;
      bool result_is_negative = float_rounded_values[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uchar)0;
        actual.raw[n] = (uchar)0;
      }
    }
    compare_uchar_elements_float("convert_uchar(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uchar)convert_uchar(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat((float)sat_input);
    compare_uchar_elements_float("convert_uchar_sat(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uchar)((uchar)float_rounded_values_rte[i]));
    actual.value = convert_uchar_rte((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uchar)((uchar)0 - (uchar)1) >= (uchar)0;
      bool result_is_negative = float_rounded_values_rte[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uchar)0;
        actual.raw[n] = (uchar)0;
      }
    }
    compare_uchar_elements_float("convert_uchar_rte(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uchar)convert_uchar_rte(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat_rte((float)sat_input);
    compare_uchar_elements_float("convert_uchar_sat_rte(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uchar)((uchar)float_rounded_values_rtz[i]));
    actual.value = convert_uchar_rtz((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uchar)((uchar)0 - (uchar)1) >= (uchar)0;
      bool result_is_negative = float_rounded_values_rtz[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uchar)0;
        actual.raw[n] = (uchar)0;
      }
    }
    compare_uchar_elements_float("convert_uchar_rtz(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uchar)convert_uchar_rtz(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat_rtz((float)sat_input);
    compare_uchar_elements_float("convert_uchar_sat_rtz(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uchar)((uchar)float_rounded_values_rtp[i]));
    actual.value = convert_uchar_rtp((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uchar)((uchar)0 - (uchar)1) >= (uchar)0;
      bool result_is_negative = float_rounded_values_rtp[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uchar)0;
        actual.raw[n] = (uchar)0;
      }
    }
    compare_uchar_elements_float("convert_uchar_rtp(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uchar)convert_uchar_rtp(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat_rtp((float)sat_input);
    compare_uchar_elements_float("convert_uchar_sat_rtp(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uchar)((uchar)float_rounded_values_rtn[i]));
    actual.value = convert_uchar_rtn((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uchar)((uchar)0 - (uchar)1) >= (uchar)0;
      bool result_is_negative = float_rounded_values_rtn[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uchar)0;
        actual.raw[n] = (uchar)0;
      }
    }
    compare_uchar_elements_float("convert_uchar_rtn(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uchar)convert_uchar_rtn(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat_rtn((float)sat_input);
    compare_uchar_elements_float("convert_uchar_sat_rtn(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

kernel void test_convert_type_short_float() {
  for (size_t i = 0; i < float_values_length; ++i) {
    const float sat_input = (float_values[i] + float_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const short min_expected = (short)(SHRT_MIN > -FLT_MAX) ? SHRT_MIN : (short)-FLT_MAX;
    const short max_expected = (short)(SHRT_MAX < FLT_MAX) ? SHRT_MAX : (short)FLT_MAX;
    union { short value; short raw[1]; } expected, actual;
    expected.value = ((short)((short)float_rounded_values[i]));
    actual.value = convert_short((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (short)((short)0 - (short)1) >= (short)0;
      bool result_is_negative = float_rounded_values[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (short)0;
        actual.raw[n] = (short)0;
      }
    }
    compare_short_elements_float("convert_short(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (short)convert_short(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (short)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat((float)sat_input);
    compare_short_elements_float("convert_short_sat(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((short)((short)float_rounded_values_rte[i]));
    actual.value = convert_short_rte((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (short)((short)0 - (short)1) >= (short)0;
      bool result_is_negative = float_rounded_values_rte[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (short)0;
        actual.raw[n] = (short)0;
      }
    }
    compare_short_elements_float("convert_short_rte(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (short)convert_short_rte(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (short)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat_rte((float)sat_input);
    compare_short_elements_float("convert_short_sat_rte(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((short)((short)float_rounded_values_rtz[i]));
    actual.value = convert_short_rtz((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (short)((short)0 - (short)1) >= (short)0;
      bool result_is_negative = float_rounded_values_rtz[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (short)0;
        actual.raw[n] = (short)0;
      }
    }
    compare_short_elements_float("convert_short_rtz(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (short)convert_short_rtz(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (short)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat_rtz((float)sat_input);
    compare_short_elements_float("convert_short_sat_rtz(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((short)((short)float_rounded_values_rtp[i]));
    actual.value = convert_short_rtp((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (short)((short)0 - (short)1) >= (short)0;
      bool result_is_negative = float_rounded_values_rtp[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (short)0;
        actual.raw[n] = (short)0;
      }
    }
    compare_short_elements_float("convert_short_rtp(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (short)convert_short_rtp(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (short)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat_rtp((float)sat_input);
    compare_short_elements_float("convert_short_sat_rtp(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((short)((short)float_rounded_values_rtn[i]));
    actual.value = convert_short_rtn((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (short)((short)0 - (short)1) >= (short)0;
      bool result_is_negative = float_rounded_values_rtn[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (short)0;
        actual.raw[n] = (short)0;
      }
    }
    compare_short_elements_float("convert_short_rtn(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (short)convert_short_rtn(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (short)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat_rtn((float)sat_input);
    compare_short_elements_float("convert_short_sat_rtn(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

kernel void test_convert_type_ushort_float() {
  for (size_t i = 0; i < float_values_length; ++i) {
    const float sat_input = (float_values[i] + float_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const ushort min_expected = (ushort)(0 > -FLT_MAX) ? 0 : (ushort)-FLT_MAX;
    const ushort max_expected = (ushort)(USHRT_MAX < FLT_MAX) ? USHRT_MAX : (ushort)FLT_MAX;
    union { ushort value; ushort raw[1]; } expected, actual;
    expected.value = ((ushort)((ushort)float_rounded_values[i]));
    actual.value = convert_ushort((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ushort)((ushort)0 - (ushort)1) >= (ushort)0;
      bool result_is_negative = float_rounded_values[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ushort)0;
        actual.raw[n] = (ushort)0;
      }
    }
    compare_ushort_elements_float("convert_ushort(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ushort)convert_ushort(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat((float)sat_input);
    compare_ushort_elements_float("convert_ushort_sat(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ushort)((ushort)float_rounded_values_rte[i]));
    actual.value = convert_ushort_rte((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ushort)((ushort)0 - (ushort)1) >= (ushort)0;
      bool result_is_negative = float_rounded_values_rte[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ushort)0;
        actual.raw[n] = (ushort)0;
      }
    }
    compare_ushort_elements_float("convert_ushort_rte(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ushort)convert_ushort_rte(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat_rte((float)sat_input);
    compare_ushort_elements_float("convert_ushort_sat_rte(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ushort)((ushort)float_rounded_values_rtz[i]));
    actual.value = convert_ushort_rtz((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ushort)((ushort)0 - (ushort)1) >= (ushort)0;
      bool result_is_negative = float_rounded_values_rtz[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ushort)0;
        actual.raw[n] = (ushort)0;
      }
    }
    compare_ushort_elements_float("convert_ushort_rtz(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ushort)convert_ushort_rtz(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat_rtz((float)sat_input);
    compare_ushort_elements_float("convert_ushort_sat_rtz(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ushort)((ushort)float_rounded_values_rtp[i]));
    actual.value = convert_ushort_rtp((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ushort)((ushort)0 - (ushort)1) >= (ushort)0;
      bool result_is_negative = float_rounded_values_rtp[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ushort)0;
        actual.raw[n] = (ushort)0;
      }
    }
    compare_ushort_elements_float("convert_ushort_rtp(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ushort)convert_ushort_rtp(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat_rtp((float)sat_input);
    compare_ushort_elements_float("convert_ushort_sat_rtp(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ushort)((ushort)float_rounded_values_rtn[i]));
    actual.value = convert_ushort_rtn((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ushort)((ushort)0 - (ushort)1) >= (ushort)0;
      bool result_is_negative = float_rounded_values_rtn[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ushort)0;
        actual.raw[n] = (ushort)0;
      }
    }
    compare_ushort_elements_float("convert_ushort_rtn(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ushort)convert_ushort_rtn(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat_rtn((float)sat_input);
    compare_ushort_elements_float("convert_ushort_sat_rtn(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

kernel void test_convert_type_int_float() {
  for (size_t i = 0; i < float_values_length; ++i) {
    const float sat_input = (float_values[i] + float_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const int min_expected = (int)(INT_MIN > -FLT_MAX) ? INT_MIN : (int)-FLT_MAX;
    const int max_expected = (int)(INT_MAX < FLT_MAX) ? INT_MAX : (int)FLT_MAX;
    union { int value; int raw[1]; } expected, actual;
    expected.value = ((int)((int)float_rounded_values[i]));
    actual.value = convert_int((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (int)((int)0 - (int)1) >= (int)0;
      bool result_is_negative = float_rounded_values[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (int)0;
        actual.raw[n] = (int)0;
      }
    }
    compare_int_elements_float("convert_int(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (int)convert_int(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (int)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat((float)sat_input);
    compare_int_elements_float("convert_int_sat(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((int)((int)float_rounded_values_rte[i]));
    actual.value = convert_int_rte((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (int)((int)0 - (int)1) >= (int)0;
      bool result_is_negative = float_rounded_values_rte[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (int)0;
        actual.raw[n] = (int)0;
      }
    }
    compare_int_elements_float("convert_int_rte(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (int)convert_int_rte(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (int)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat_rte((float)sat_input);
    compare_int_elements_float("convert_int_sat_rte(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((int)((int)float_rounded_values_rtz[i]));
    actual.value = convert_int_rtz((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (int)((int)0 - (int)1) >= (int)0;
      bool result_is_negative = float_rounded_values_rtz[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (int)0;
        actual.raw[n] = (int)0;
      }
    }
    compare_int_elements_float("convert_int_rtz(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (int)convert_int_rtz(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (int)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat_rtz((float)sat_input);
    compare_int_elements_float("convert_int_sat_rtz(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((int)((int)float_rounded_values_rtp[i]));
    actual.value = convert_int_rtp((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (int)((int)0 - (int)1) >= (int)0;
      bool result_is_negative = float_rounded_values_rtp[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (int)0;
        actual.raw[n] = (int)0;
      }
    }
    compare_int_elements_float("convert_int_rtp(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (int)convert_int_rtp(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (int)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat_rtp((float)sat_input);
    compare_int_elements_float("convert_int_sat_rtp(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((int)((int)float_rounded_values_rtn[i]));
    actual.value = convert_int_rtn((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (int)((int)0 - (int)1) >= (int)0;
      bool result_is_negative = float_rounded_values_rtn[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (int)0;
        actual.raw[n] = (int)0;
      }
    }
    compare_int_elements_float("convert_int_rtn(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (int)convert_int_rtn(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (int)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat_rtn((float)sat_input);
    compare_int_elements_float("convert_int_sat_rtn(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

kernel void test_convert_type_uint_float() {
  for (size_t i = 0; i < float_values_length; ++i) {
    const float sat_input = (float_values[i] + float_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const uint min_expected = (uint)(0 > -FLT_MAX) ? 0 : (uint)-FLT_MAX;
    const uint max_expected = (uint)(UINT_MAX < FLT_MAX) ? UINT_MAX : (uint)FLT_MAX;
    union { uint value; uint raw[1]; } expected, actual;
    expected.value = ((uint)((uint)float_rounded_values[i]));
    actual.value = convert_uint((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uint)((uint)0 - (uint)1) >= (uint)0;
      bool result_is_negative = float_rounded_values[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uint)0;
        actual.raw[n] = (uint)0;
      }
    }
    compare_uint_elements_float("convert_uint(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uint)convert_uint(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat((float)sat_input);
    compare_uint_elements_float("convert_uint_sat(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uint)((uint)float_rounded_values_rte[i]));
    actual.value = convert_uint_rte((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uint)((uint)0 - (uint)1) >= (uint)0;
      bool result_is_negative = float_rounded_values_rte[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uint)0;
        actual.raw[n] = (uint)0;
      }
    }
    compare_uint_elements_float("convert_uint_rte(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uint)convert_uint_rte(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat_rte((float)sat_input);
    compare_uint_elements_float("convert_uint_sat_rte(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uint)((uint)float_rounded_values_rtz[i]));
    actual.value = convert_uint_rtz((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uint)((uint)0 - (uint)1) >= (uint)0;
      bool result_is_negative = float_rounded_values_rtz[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uint)0;
        actual.raw[n] = (uint)0;
      }
    }
    compare_uint_elements_float("convert_uint_rtz(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uint)convert_uint_rtz(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat_rtz((float)sat_input);
    compare_uint_elements_float("convert_uint_sat_rtz(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uint)((uint)float_rounded_values_rtp[i]));
    actual.value = convert_uint_rtp((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uint)((uint)0 - (uint)1) >= (uint)0;
      bool result_is_negative = float_rounded_values_rtp[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uint)0;
        actual.raw[n] = (uint)0;
      }
    }
    compare_uint_elements_float("convert_uint_rtp(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uint)convert_uint_rtp(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat_rtp((float)sat_input);
    compare_uint_elements_float("convert_uint_sat_rtp(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uint)((uint)float_rounded_values_rtn[i]));
    actual.value = convert_uint_rtn((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uint)((uint)0 - (uint)1) >= (uint)0;
      bool result_is_negative = float_rounded_values_rtn[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uint)0;
        actual.raw[n] = (uint)0;
      }
    }
    compare_uint_elements_float("convert_uint_rtn(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uint)convert_uint_rtn(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat_rtn((float)sat_input);
    compare_uint_elements_float("convert_uint_sat_rtn(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

#ifdef cl_khr_int64

kernel void test_convert_type_long_float() {
  for (size_t i = 0; i < float_values_length; ++i) {
    const float sat_input = (float_values[i] + float_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const long min_expected = (long)(LONG_MIN > -FLT_MAX) ? LONG_MIN : (long)-FLT_MAX;
    const long max_expected = (long)(LONG_MAX < FLT_MAX) ? LONG_MAX : (long)FLT_MAX;
    union { long value; long raw[1]; } expected, actual;
    expected.value = ((long)((long)float_rounded_values[i]));
    actual.value = convert_long((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (long)((long)0 - (long)1) >= (long)0;
      bool result_is_negative = float_rounded_values[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (long)0;
        actual.raw[n] = (long)0;
      }
    }
    compare_long_elements_float("convert_long(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (long)convert_long(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (long)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat((float)sat_input);
    compare_long_elements_float("convert_long_sat(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((long)((long)float_rounded_values_rte[i]));
    actual.value = convert_long_rte((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (long)((long)0 - (long)1) >= (long)0;
      bool result_is_negative = float_rounded_values_rte[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (long)0;
        actual.raw[n] = (long)0;
      }
    }
    compare_long_elements_float("convert_long_rte(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (long)convert_long_rte(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (long)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat_rte((float)sat_input);
    compare_long_elements_float("convert_long_sat_rte(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((long)((long)float_rounded_values_rtz[i]));
    actual.value = convert_long_rtz((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (long)((long)0 - (long)1) >= (long)0;
      bool result_is_negative = float_rounded_values_rtz[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (long)0;
        actual.raw[n] = (long)0;
      }
    }
    compare_long_elements_float("convert_long_rtz(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (long)convert_long_rtz(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (long)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat_rtz((float)sat_input);
    compare_long_elements_float("convert_long_sat_rtz(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((long)((long)float_rounded_values_rtp[i]));
    actual.value = convert_long_rtp((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (long)((long)0 - (long)1) >= (long)0;
      bool result_is_negative = float_rounded_values_rtp[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (long)0;
        actual.raw[n] = (long)0;
      }
    }
    compare_long_elements_float("convert_long_rtp(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (long)convert_long_rtp(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (long)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat_rtp((float)sat_input);
    compare_long_elements_float("convert_long_sat_rtp(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((long)((long)float_rounded_values_rtn[i]));
    actual.value = convert_long_rtn((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (long)((long)0 - (long)1) >= (long)0;
      bool result_is_negative = float_rounded_values_rtn[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (long)0;
        actual.raw[n] = (long)0;
      }
    }
    compare_long_elements_float("convert_long_rtn(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (long)convert_long_rtn(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (long)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat_rtn((float)sat_input);
    compare_long_elements_float("convert_long_sat_rtn(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

#endif

#ifdef cl_khr_int64

kernel void test_convert_type_ulong_float() {
  for (size_t i = 0; i < float_values_length; ++i) {
    const float sat_input = (float_values[i] + float_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const ulong min_expected = (ulong)(0 > -FLT_MAX) ? 0 : (ulong)-FLT_MAX;
    const ulong max_expected = (ulong)(ULONG_MAX < FLT_MAX) ? ULONG_MAX : (ulong)FLT_MAX;
    union { ulong value; ulong raw[1]; } expected, actual;
    expected.value = ((ulong)((ulong)float_rounded_values[i]));
    actual.value = convert_ulong((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ulong)((ulong)0 - (ulong)1) >= (ulong)0;
      bool result_is_negative = float_rounded_values[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ulong)0;
        actual.raw[n] = (ulong)0;
      }
    }
    compare_ulong_elements_float("convert_ulong(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ulong)convert_ulong(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat((float)sat_input);
    compare_ulong_elements_float("convert_ulong_sat(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ulong)((ulong)float_rounded_values_rte[i]));
    actual.value = convert_ulong_rte((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ulong)((ulong)0 - (ulong)1) >= (ulong)0;
      bool result_is_negative = float_rounded_values_rte[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ulong)0;
        actual.raw[n] = (ulong)0;
      }
    }
    compare_ulong_elements_float("convert_ulong_rte(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ulong)convert_ulong_rte(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat_rte((float)sat_input);
    compare_ulong_elements_float("convert_ulong_sat_rte(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ulong)((ulong)float_rounded_values_rtz[i]));
    actual.value = convert_ulong_rtz((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ulong)((ulong)0 - (ulong)1) >= (ulong)0;
      bool result_is_negative = float_rounded_values_rtz[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ulong)0;
        actual.raw[n] = (ulong)0;
      }
    }
    compare_ulong_elements_float("convert_ulong_rtz(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ulong)convert_ulong_rtz(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat_rtz((float)sat_input);
    compare_ulong_elements_float("convert_ulong_sat_rtz(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ulong)((ulong)float_rounded_values_rtp[i]));
    actual.value = convert_ulong_rtp((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ulong)((ulong)0 - (ulong)1) >= (ulong)0;
      bool result_is_negative = float_rounded_values_rtp[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ulong)0;
        actual.raw[n] = (ulong)0;
      }
    }
    compare_ulong_elements_float("convert_ulong_rtp(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ulong)convert_ulong_rtp(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat_rtp((float)sat_input);
    compare_ulong_elements_float("convert_ulong_sat_rtp(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ulong)((ulong)float_rounded_values_rtn[i]));
    actual.value = convert_ulong_rtn((float)float_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ulong)((ulong)0 - (ulong)1) >= (ulong)0;
      bool result_is_negative = float_rounded_values_rtn[i] < (float)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ulong)0;
        actual.raw[n] = (ulong)0;
      }
    }
    compare_ulong_elements_float("convert_ulong_rtn(float)", i, &float_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ulong)convert_ulong_rtn(sat_input);
    if (sat_input <= (float)min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (sat_input >= (float)max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat_rtn((float)sat_input);
    compare_ulong_elements_float("convert_ulong_sat_rtn(float)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

#endif

#ifdef cl_khr_fp64

kernel void test_convert_type_char_double() {
  for (size_t i = 0; i < double_values_length; ++i) {
    const double sat_input = (double_values[i] + double_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const char min_expected = (char)(CHAR_MIN > -DBL_MAX) ? CHAR_MIN : (char)-DBL_MAX;
    const char max_expected = (char)(CHAR_MAX < DBL_MAX) ? CHAR_MAX : (char)DBL_MAX;
    union { char value; char raw[1]; } expected, actual;
    expected.value = ((char)((char)double_rounded_values[i]));
    actual.value = convert_char((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (char)((char)0 - (char)1) >= (char)0;
      bool result_is_negative = double_rounded_values[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (char)0;
        actual.raw[n] = (char)0;
      }
    }
    compare_char_elements_double("convert_char(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (char)convert_char(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (char)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat((double)sat_input);
    compare_char_elements_double("convert_char_sat(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((char)((char)double_rounded_values_rte[i]));
    actual.value = convert_char_rte((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (char)((char)0 - (char)1) >= (char)0;
      bool result_is_negative = double_rounded_values_rte[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (char)0;
        actual.raw[n] = (char)0;
      }
    }
    compare_char_elements_double("convert_char_rte(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (char)convert_char_rte(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (char)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat_rte((double)sat_input);
    compare_char_elements_double("convert_char_sat_rte(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((char)((char)double_rounded_values_rtz[i]));
    actual.value = convert_char_rtz((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (char)((char)0 - (char)1) >= (char)0;
      bool result_is_negative = double_rounded_values_rtz[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (char)0;
        actual.raw[n] = (char)0;
      }
    }
    compare_char_elements_double("convert_char_rtz(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (char)convert_char_rtz(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (char)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat_rtz((double)sat_input);
    compare_char_elements_double("convert_char_sat_rtz(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((char)((char)double_rounded_values_rtp[i]));
    actual.value = convert_char_rtp((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (char)((char)0 - (char)1) >= (char)0;
      bool result_is_negative = double_rounded_values_rtp[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (char)0;
        actual.raw[n] = (char)0;
      }
    }
    compare_char_elements_double("convert_char_rtp(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (char)convert_char_rtp(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (char)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat_rtp((double)sat_input);
    compare_char_elements_double("convert_char_sat_rtp(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((char)((char)double_rounded_values_rtn[i]));
    actual.value = convert_char_rtn((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (char)((char)0 - (char)1) >= (char)0;
      bool result_is_negative = double_rounded_values_rtn[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (char)0;
        actual.raw[n] = (char)0;
      }
    }
    compare_char_elements_double("convert_char_rtn(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (char)convert_char_rtn(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (char)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (char)max_expected;
    }
    actual.value = convert_char_sat_rtn((double)sat_input);
    compare_char_elements_double("convert_char_sat_rtn(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

#endif

#ifdef cl_khr_fp64

kernel void test_convert_type_uchar_double() {
  for (size_t i = 0; i < double_values_length; ++i) {
    const double sat_input = (double_values[i] + double_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const uchar min_expected = (uchar)(0 > -DBL_MAX) ? 0 : (uchar)-DBL_MAX;
    const uchar max_expected = (uchar)(UCHAR_MAX < DBL_MAX) ? UCHAR_MAX : (uchar)DBL_MAX;
    union { uchar value; uchar raw[1]; } expected, actual;
    expected.value = ((uchar)((uchar)double_rounded_values[i]));
    actual.value = convert_uchar((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uchar)((uchar)0 - (uchar)1) >= (uchar)0;
      bool result_is_negative = double_rounded_values[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uchar)0;
        actual.raw[n] = (uchar)0;
      }
    }
    compare_uchar_elements_double("convert_uchar(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uchar)convert_uchar(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat((double)sat_input);
    compare_uchar_elements_double("convert_uchar_sat(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uchar)((uchar)double_rounded_values_rte[i]));
    actual.value = convert_uchar_rte((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uchar)((uchar)0 - (uchar)1) >= (uchar)0;
      bool result_is_negative = double_rounded_values_rte[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uchar)0;
        actual.raw[n] = (uchar)0;
      }
    }
    compare_uchar_elements_double("convert_uchar_rte(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uchar)convert_uchar_rte(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat_rte((double)sat_input);
    compare_uchar_elements_double("convert_uchar_sat_rte(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uchar)((uchar)double_rounded_values_rtz[i]));
    actual.value = convert_uchar_rtz((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uchar)((uchar)0 - (uchar)1) >= (uchar)0;
      bool result_is_negative = double_rounded_values_rtz[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uchar)0;
        actual.raw[n] = (uchar)0;
      }
    }
    compare_uchar_elements_double("convert_uchar_rtz(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uchar)convert_uchar_rtz(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat_rtz((double)sat_input);
    compare_uchar_elements_double("convert_uchar_sat_rtz(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uchar)((uchar)double_rounded_values_rtp[i]));
    actual.value = convert_uchar_rtp((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uchar)((uchar)0 - (uchar)1) >= (uchar)0;
      bool result_is_negative = double_rounded_values_rtp[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uchar)0;
        actual.raw[n] = (uchar)0;
      }
    }
    compare_uchar_elements_double("convert_uchar_rtp(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uchar)convert_uchar_rtp(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat_rtp((double)sat_input);
    compare_uchar_elements_double("convert_uchar_sat_rtp(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uchar)((uchar)double_rounded_values_rtn[i]));
    actual.value = convert_uchar_rtn((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uchar)((uchar)0 - (uchar)1) >= (uchar)0;
      bool result_is_negative = double_rounded_values_rtn[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uchar)0;
        actual.raw[n] = (uchar)0;
      }
    }
    compare_uchar_elements_double("convert_uchar_rtn(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uchar)convert_uchar_rtn(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (uchar)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (uchar)max_expected;
    }
    actual.value = convert_uchar_sat_rtn((double)sat_input);
    compare_uchar_elements_double("convert_uchar_sat_rtn(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

#endif

#ifdef cl_khr_fp64

kernel void test_convert_type_short_double() {
  for (size_t i = 0; i < double_values_length; ++i) {
    const double sat_input = (double_values[i] + double_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const short min_expected = (short)(SHRT_MIN > -DBL_MAX) ? SHRT_MIN : (short)-DBL_MAX;
    const short max_expected = (short)(SHRT_MAX < DBL_MAX) ? SHRT_MAX : (short)DBL_MAX;
    union { short value; short raw[1]; } expected, actual;
    expected.value = ((short)((short)double_rounded_values[i]));
    actual.value = convert_short((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (short)((short)0 - (short)1) >= (short)0;
      bool result_is_negative = double_rounded_values[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (short)0;
        actual.raw[n] = (short)0;
      }
    }
    compare_short_elements_double("convert_short(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (short)convert_short(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (short)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat((double)sat_input);
    compare_short_elements_double("convert_short_sat(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((short)((short)double_rounded_values_rte[i]));
    actual.value = convert_short_rte((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (short)((short)0 - (short)1) >= (short)0;
      bool result_is_negative = double_rounded_values_rte[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (short)0;
        actual.raw[n] = (short)0;
      }
    }
    compare_short_elements_double("convert_short_rte(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (short)convert_short_rte(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (short)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat_rte((double)sat_input);
    compare_short_elements_double("convert_short_sat_rte(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((short)((short)double_rounded_values_rtz[i]));
    actual.value = convert_short_rtz((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (short)((short)0 - (short)1) >= (short)0;
      bool result_is_negative = double_rounded_values_rtz[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (short)0;
        actual.raw[n] = (short)0;
      }
    }
    compare_short_elements_double("convert_short_rtz(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (short)convert_short_rtz(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (short)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat_rtz((double)sat_input);
    compare_short_elements_double("convert_short_sat_rtz(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((short)((short)double_rounded_values_rtp[i]));
    actual.value = convert_short_rtp((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (short)((short)0 - (short)1) >= (short)0;
      bool result_is_negative = double_rounded_values_rtp[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (short)0;
        actual.raw[n] = (short)0;
      }
    }
    compare_short_elements_double("convert_short_rtp(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (short)convert_short_rtp(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (short)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat_rtp((double)sat_input);
    compare_short_elements_double("convert_short_sat_rtp(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((short)((short)double_rounded_values_rtn[i]));
    actual.value = convert_short_rtn((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (short)((short)0 - (short)1) >= (short)0;
      bool result_is_negative = double_rounded_values_rtn[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (short)0;
        actual.raw[n] = (short)0;
      }
    }
    compare_short_elements_double("convert_short_rtn(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (short)convert_short_rtn(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (short)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (short)max_expected;
    }
    actual.value = convert_short_sat_rtn((double)sat_input);
    compare_short_elements_double("convert_short_sat_rtn(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

#endif

#ifdef cl_khr_fp64

kernel void test_convert_type_ushort_double() {
  for (size_t i = 0; i < double_values_length; ++i) {
    const double sat_input = (double_values[i] + double_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const ushort min_expected = (ushort)(0 > -DBL_MAX) ? 0 : (ushort)-DBL_MAX;
    const ushort max_expected = (ushort)(USHRT_MAX < DBL_MAX) ? USHRT_MAX : (ushort)DBL_MAX;
    union { ushort value; ushort raw[1]; } expected, actual;
    expected.value = ((ushort)((ushort)double_rounded_values[i]));
    actual.value = convert_ushort((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ushort)((ushort)0 - (ushort)1) >= (ushort)0;
      bool result_is_negative = double_rounded_values[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ushort)0;
        actual.raw[n] = (ushort)0;
      }
    }
    compare_ushort_elements_double("convert_ushort(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ushort)convert_ushort(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat((double)sat_input);
    compare_ushort_elements_double("convert_ushort_sat(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ushort)((ushort)double_rounded_values_rte[i]));
    actual.value = convert_ushort_rte((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ushort)((ushort)0 - (ushort)1) >= (ushort)0;
      bool result_is_negative = double_rounded_values_rte[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ushort)0;
        actual.raw[n] = (ushort)0;
      }
    }
    compare_ushort_elements_double("convert_ushort_rte(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ushort)convert_ushort_rte(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat_rte((double)sat_input);
    compare_ushort_elements_double("convert_ushort_sat_rte(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ushort)((ushort)double_rounded_values_rtz[i]));
    actual.value = convert_ushort_rtz((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ushort)((ushort)0 - (ushort)1) >= (ushort)0;
      bool result_is_negative = double_rounded_values_rtz[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ushort)0;
        actual.raw[n] = (ushort)0;
      }
    }
    compare_ushort_elements_double("convert_ushort_rtz(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ushort)convert_ushort_rtz(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat_rtz((double)sat_input);
    compare_ushort_elements_double("convert_ushort_sat_rtz(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ushort)((ushort)double_rounded_values_rtp[i]));
    actual.value = convert_ushort_rtp((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ushort)((ushort)0 - (ushort)1) >= (ushort)0;
      bool result_is_negative = double_rounded_values_rtp[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ushort)0;
        actual.raw[n] = (ushort)0;
      }
    }
    compare_ushort_elements_double("convert_ushort_rtp(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ushort)convert_ushort_rtp(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat_rtp((double)sat_input);
    compare_ushort_elements_double("convert_ushort_sat_rtp(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ushort)((ushort)double_rounded_values_rtn[i]));
    actual.value = convert_ushort_rtn((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ushort)((ushort)0 - (ushort)1) >= (ushort)0;
      bool result_is_negative = double_rounded_values_rtn[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ushort)0;
        actual.raw[n] = (ushort)0;
      }
    }
    compare_ushort_elements_double("convert_ushort_rtn(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ushort)convert_ushort_rtn(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (ushort)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (ushort)max_expected;
    }
    actual.value = convert_ushort_sat_rtn((double)sat_input);
    compare_ushort_elements_double("convert_ushort_sat_rtn(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

#endif

#ifdef cl_khr_fp64

kernel void test_convert_type_int_double() {
  for (size_t i = 0; i < double_values_length; ++i) {
    const double sat_input = (double_values[i] + double_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const int min_expected = (int)(INT_MIN > -DBL_MAX) ? INT_MIN : (int)-DBL_MAX;
    const int max_expected = (int)(INT_MAX < DBL_MAX) ? INT_MAX : (int)DBL_MAX;
    union { int value; int raw[1]; } expected, actual;
    expected.value = ((int)((int)double_rounded_values[i]));
    actual.value = convert_int((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (int)((int)0 - (int)1) >= (int)0;
      bool result_is_negative = double_rounded_values[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (int)0;
        actual.raw[n] = (int)0;
      }
    }
    compare_int_elements_double("convert_int(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (int)convert_int(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (int)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat((double)sat_input);
    compare_int_elements_double("convert_int_sat(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((int)((int)double_rounded_values_rte[i]));
    actual.value = convert_int_rte((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (int)((int)0 - (int)1) >= (int)0;
      bool result_is_negative = double_rounded_values_rte[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (int)0;
        actual.raw[n] = (int)0;
      }
    }
    compare_int_elements_double("convert_int_rte(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (int)convert_int_rte(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (int)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat_rte((double)sat_input);
    compare_int_elements_double("convert_int_sat_rte(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((int)((int)double_rounded_values_rtz[i]));
    actual.value = convert_int_rtz((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (int)((int)0 - (int)1) >= (int)0;
      bool result_is_negative = double_rounded_values_rtz[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (int)0;
        actual.raw[n] = (int)0;
      }
    }
    compare_int_elements_double("convert_int_rtz(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (int)convert_int_rtz(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (int)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat_rtz((double)sat_input);
    compare_int_elements_double("convert_int_sat_rtz(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((int)((int)double_rounded_values_rtp[i]));
    actual.value = convert_int_rtp((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (int)((int)0 - (int)1) >= (int)0;
      bool result_is_negative = double_rounded_values_rtp[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (int)0;
        actual.raw[n] = (int)0;
      }
    }
    compare_int_elements_double("convert_int_rtp(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (int)convert_int_rtp(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (int)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat_rtp((double)sat_input);
    compare_int_elements_double("convert_int_sat_rtp(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((int)((int)double_rounded_values_rtn[i]));
    actual.value = convert_int_rtn((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (int)((int)0 - (int)1) >= (int)0;
      bool result_is_negative = double_rounded_values_rtn[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (int)0;
        actual.raw[n] = (int)0;
      }
    }
    compare_int_elements_double("convert_int_rtn(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (int)convert_int_rtn(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (int)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (int)max_expected;
    }
    actual.value = convert_int_sat_rtn((double)sat_input);
    compare_int_elements_double("convert_int_sat_rtn(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

#endif

#ifdef cl_khr_fp64

kernel void test_convert_type_uint_double() {
  for (size_t i = 0; i < double_values_length; ++i) {
    const double sat_input = (double_values[i] + double_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const uint min_expected = (uint)(0 > -DBL_MAX) ? 0 : (uint)-DBL_MAX;
    const uint max_expected = (uint)(UINT_MAX < DBL_MAX) ? UINT_MAX : (uint)DBL_MAX;
    union { uint value; uint raw[1]; } expected, actual;
    expected.value = ((uint)((uint)double_rounded_values[i]));
    actual.value = convert_uint((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uint)((uint)0 - (uint)1) >= (uint)0;
      bool result_is_negative = double_rounded_values[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uint)0;
        actual.raw[n] = (uint)0;
      }
    }
    compare_uint_elements_double("convert_uint(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uint)convert_uint(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat((double)sat_input);
    compare_uint_elements_double("convert_uint_sat(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uint)((uint)double_rounded_values_rte[i]));
    actual.value = convert_uint_rte((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uint)((uint)0 - (uint)1) >= (uint)0;
      bool result_is_negative = double_rounded_values_rte[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uint)0;
        actual.raw[n] = (uint)0;
      }
    }
    compare_uint_elements_double("convert_uint_rte(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uint)convert_uint_rte(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat_rte((double)sat_input);
    compare_uint_elements_double("convert_uint_sat_rte(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uint)((uint)double_rounded_values_rtz[i]));
    actual.value = convert_uint_rtz((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uint)((uint)0 - (uint)1) >= (uint)0;
      bool result_is_negative = double_rounded_values_rtz[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uint)0;
        actual.raw[n] = (uint)0;
      }
    }
    compare_uint_elements_double("convert_uint_rtz(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uint)convert_uint_rtz(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat_rtz((double)sat_input);
    compare_uint_elements_double("convert_uint_sat_rtz(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uint)((uint)double_rounded_values_rtp[i]));
    actual.value = convert_uint_rtp((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uint)((uint)0 - (uint)1) >= (uint)0;
      bool result_is_negative = double_rounded_values_rtp[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uint)0;
        actual.raw[n] = (uint)0;
      }
    }
    compare_uint_elements_double("convert_uint_rtp(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uint)convert_uint_rtp(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat_rtp((double)sat_input);
    compare_uint_elements_double("convert_uint_sat_rtp(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((uint)((uint)double_rounded_values_rtn[i]));
    actual.value = convert_uint_rtn((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (uint)((uint)0 - (uint)1) >= (uint)0;
      bool result_is_negative = double_rounded_values_rtn[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (uint)0;
        actual.raw[n] = (uint)0;
      }
    }
    compare_uint_elements_double("convert_uint_rtn(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (uint)convert_uint_rtn(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (uint)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (uint)max_expected;
    }
    actual.value = convert_uint_sat_rtn((double)sat_input);
    compare_uint_elements_double("convert_uint_sat_rtn(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

#endif

#ifdef cl_khr_int64

#ifdef cl_khr_fp64

kernel void test_convert_type_long_double() {
  for (size_t i = 0; i < double_values_length; ++i) {
    const double sat_input = (double_values[i] + double_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const long min_expected = (long)(LONG_MIN > -DBL_MAX) ? LONG_MIN : (long)-DBL_MAX;
    const long max_expected = (long)(LONG_MAX < DBL_MAX) ? LONG_MAX : (long)DBL_MAX;
    union { long value; long raw[1]; } expected, actual;
    expected.value = ((long)((long)double_rounded_values[i]));
    actual.value = convert_long((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (long)((long)0 - (long)1) >= (long)0;
      bool result_is_negative = double_rounded_values[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (long)0;
        actual.raw[n] = (long)0;
      }
    }
    compare_long_elements_double("convert_long(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (long)convert_long(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (long)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat((double)sat_input);
    compare_long_elements_double("convert_long_sat(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((long)((long)double_rounded_values_rte[i]));
    actual.value = convert_long_rte((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (long)((long)0 - (long)1) >= (long)0;
      bool result_is_negative = double_rounded_values_rte[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (long)0;
        actual.raw[n] = (long)0;
      }
    }
    compare_long_elements_double("convert_long_rte(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (long)convert_long_rte(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (long)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat_rte((double)sat_input);
    compare_long_elements_double("convert_long_sat_rte(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((long)((long)double_rounded_values_rtz[i]));
    actual.value = convert_long_rtz((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (long)((long)0 - (long)1) >= (long)0;
      bool result_is_negative = double_rounded_values_rtz[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (long)0;
        actual.raw[n] = (long)0;
      }
    }
    compare_long_elements_double("convert_long_rtz(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (long)convert_long_rtz(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (long)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat_rtz((double)sat_input);
    compare_long_elements_double("convert_long_sat_rtz(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((long)((long)double_rounded_values_rtp[i]));
    actual.value = convert_long_rtp((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (long)((long)0 - (long)1) >= (long)0;
      bool result_is_negative = double_rounded_values_rtp[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (long)0;
        actual.raw[n] = (long)0;
      }
    }
    compare_long_elements_double("convert_long_rtp(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (long)convert_long_rtp(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (long)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat_rtp((double)sat_input);
    compare_long_elements_double("convert_long_sat_rtp(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((long)((long)double_rounded_values_rtn[i]));
    actual.value = convert_long_rtn((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (long)((long)0 - (long)1) >= (long)0;
      bool result_is_negative = double_rounded_values_rtn[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (long)0;
        actual.raw[n] = (long)0;
      }
    }
    compare_long_elements_double("convert_long_rtn(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (long)convert_long_rtn(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (long)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (long)max_expected;
    }
    actual.value = convert_long_sat_rtn((double)sat_input);
    compare_long_elements_double("convert_long_sat_rtn(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

#endif

#endif

#ifdef cl_khr_int64

#ifdef cl_khr_fp64

kernel void test_convert_type_ulong_double() {
  for (size_t i = 0; i < double_values_length; ++i) {
    const double sat_input = (double_values[i] + double_sat_offsets[i]);
    // use the destination (integer) type always to avoid rounding errors when
    // comparing floats to int
    const ulong min_expected = (ulong)(0 > -DBL_MAX) ? 0 : (ulong)-DBL_MAX;
    const ulong max_expected = (ulong)(ULONG_MAX < DBL_MAX) ? ULONG_MAX : (ulong)DBL_MAX;
    union { ulong value; ulong raw[1]; } expected, actual;
    expected.value = ((ulong)((ulong)double_rounded_values[i]));
    actual.value = convert_ulong((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ulong)((ulong)0 - (ulong)1) >= (ulong)0;
      bool result_is_negative = double_rounded_values[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ulong)0;
        actual.raw[n] = (ulong)0;
      }
    }
    compare_ulong_elements_double("convert_ulong(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ulong)convert_ulong(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat((double)sat_input);
    compare_ulong_elements_double("convert_ulong_sat(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ulong)((ulong)double_rounded_values_rte[i]));
    actual.value = convert_ulong_rte((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ulong)((ulong)0 - (ulong)1) >= (ulong)0;
      bool result_is_negative = double_rounded_values_rte[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ulong)0;
        actual.raw[n] = (ulong)0;
      }
    }
    compare_ulong_elements_double("convert_ulong_rte(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ulong)convert_ulong_rte(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat_rte((double)sat_input);
    compare_ulong_elements_double("convert_ulong_sat_rte(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ulong)((ulong)double_rounded_values_rtz[i]));
    actual.value = convert_ulong_rtz((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ulong)((ulong)0 - (ulong)1) >= (ulong)0;
      bool result_is_negative = double_rounded_values_rtz[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ulong)0;
        actual.raw[n] = (ulong)0;
      }
    }
    compare_ulong_elements_double("convert_ulong_rtz(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ulong)convert_ulong_rtz(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat_rtz((double)sat_input);
    compare_ulong_elements_double("convert_ulong_sat_rtz(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ulong)((ulong)double_rounded_values_rtp[i]));
    actual.value = convert_ulong_rtp((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ulong)((ulong)0 - (ulong)1) >= (ulong)0;
      bool result_is_negative = double_rounded_values_rtp[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ulong)0;
        actual.raw[n] = (ulong)0;
      }
    }
    compare_ulong_elements_double("convert_ulong_rtp(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ulong)convert_ulong_rtp(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat_rtp((double)sat_input);
    compare_ulong_elements_double("convert_ulong_sat_rtp(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

    expected.value = ((ulong)((ulong)double_rounded_values_rtn[i]));
    actual.value = convert_ulong_rtn((double)double_values[i]);
    for (size_t n=0; n<1; ++n) {
      bool type_is_unsigned = (ulong)((ulong)0 - (ulong)1) >= (ulong)0;
      bool result_is_negative = double_rounded_values_rtn[i] < (double)0;
      if (type_is_unsigned && result_is_negative) {
        // Ignore this result
        expected.raw[n] = (ulong)0;
        actual.raw[n] = (ulong)0;
      }
    }
    compare_ulong_elements_double("convert_ulong_rtn(double)", i, &double_values[i], 0, expected.raw, actual.raw, 1);
    expected.value = (ulong)convert_ulong_rtn(sat_input);
    if (sat_input <= (double)min_expected) {
       expected.value = (ulong)min_expected;
    }
    else if (sat_input >= (double)max_expected) {
       expected.value = (ulong)max_expected;
    }
    actual.value = convert_ulong_sat_rtn((double)sat_input);
    compare_ulong_elements_double("convert_ulong_sat_rtn(double)", i, 0, &sat_input, expected.raw, actual.raw, 1);

  }
}

#endif

#endif

kernel void test_convert_type__misc() {
  union { int8 value; int raw[8]; } qe, qa;
  union { float8 value; float raw[8]; } qo;

  qo.value = (float8)(-23.67f, -23.50f, -23.35f, -23.0f, 23.0f, 23.35f, 23.50f, 23.67f);
  qa.value = convert_int8_rtz(qo.value);
  qe.value = (int8)(-23, -23, -23, -23, 23, 23, 23, 23);
  compare_int_elements_float("convert_int8_rtz(float8)", 0, 0, qo.raw, qe.raw, qa.raw, 8);

  qo.value = (float8)(-23.67f, -23.50f, -23.35f, -23.0f, 23.0f, 23.35f, 23.50f, 23.67f);
  qa.value = convert_int8_rtp(qo.value);
  qe.value = (int8)(-23, -23, -23, -23, 23, 24, 24, 24);
  compare_int_elements_float("convert_int8_rtp(float8)", 0, 0, qo.raw, qe.raw, qa.raw, 8);

  qo.value = (float8)(-23.67f, -23.50f, -23.35f, -23.0f, 23.0f, 23.35f, 23.50f, 23.67f);
  qa.value = convert_int8_rtn(qo.value);
  qe.value = (int8)(-24, -24, -24, -23, 23, 23, 23, 23);
  compare_int_elements_float("convert_int8_rtn(float8)", 0, 0, qo.raw, qe.raw, qa.raw, 8);

  qo.value = (float8)(-23.67f, -23.50f, -23.35f, -23.0f, 23.0f, 23.35f, 23.50f, 23.67f);
  qa.value = convert_int8_rte(qo.value);
  qe.value = (int8)(-24, -24, -23, -23, 23, 23, 24, 24);
  compare_int_elements_float("convert_int8_rte(float8)", 0, 0, qo.raw, qe.raw, qa.raw, 8);

  qo.value = (float8)(-23.67f, -23.50f, -23.35f, -23.0f, 23.0f, 23.35f, 23.50f, 23.67f);
  qa.value = convert_int8(qo.value);
  qe.value = (int8)(-23, -23, -23, -23, 23, 23, 23, 23);
  compare_int_elements_float("convert_int8(float8)", 0, 0, qo.raw, qe.raw, qa.raw, 8);
}

