Add codegen for llvm cos and sin elementwise builtins The sin and cos elementwise builtins are necessary for HLSL codegen. Tests were added to make sure that the expected errors are encountered when these functions are given inputs of incompatible types. The new builtins are restricted to floating point types only. Reviewed By: craig.topper, fhahn Differential Revision: https://reviews.llvm.org/D135011
76 lines
2.5 KiB
C++
76 lines
2.5 KiB
C++
// RUN: %clang_cc1 %s -std=c++17 -pedantic -verify -triple=x86_64-apple-darwin9
|
|
|
|
// Simple is_const implementation.
|
|
struct true_type {
|
|
static const bool value = true;
|
|
};
|
|
|
|
struct false_type {
|
|
static const bool value = false;
|
|
};
|
|
|
|
template <class T> struct is_const : false_type {};
|
|
template <class T> struct is_const<const T> : true_type {};
|
|
|
|
// expected-no-diagnostics
|
|
|
|
void test_builtin_elementwise_abs() {
|
|
const int a = 2;
|
|
int b = 1;
|
|
static_assert(!is_const<decltype(__builtin_elementwise_abs(a))>::value);
|
|
static_assert(!is_const<decltype(__builtin_elementwise_abs(b))>::value);
|
|
}
|
|
|
|
void test_builtin_elementwise_add_sat() {
|
|
const int a = 2;
|
|
int b = 1;
|
|
static_assert(!is_const<decltype(__builtin_elementwise_add_sat(a, b))>::value);
|
|
static_assert(!is_const<decltype(__builtin_elementwise_add_sat(b, a))>::value);
|
|
static_assert(!is_const<decltype(__builtin_elementwise_add_sat(a, a))>::value);
|
|
}
|
|
|
|
void test_builtin_elementwise_sub_sat() {
|
|
const int a = 2;
|
|
int b = 1;
|
|
static_assert(!is_const<decltype(__builtin_elementwise_sub_sat(a, b))>::value);
|
|
static_assert(!is_const<decltype(__builtin_elementwise_sub_sat(b, a))>::value);
|
|
static_assert(!is_const<decltype(__builtin_elementwise_sub_sat(a, a))>::value);
|
|
}
|
|
|
|
void test_builtin_elementwise_max() {
|
|
const int a = 2;
|
|
int b = 1;
|
|
static_assert(!is_const<decltype(__builtin_elementwise_max(a, b))>::value);
|
|
static_assert(!is_const<decltype(__builtin_elementwise_max(b, a))>::value);
|
|
static_assert(!is_const<decltype(__builtin_elementwise_max(a, a))>::value);
|
|
}
|
|
|
|
void test_builtin_elementwise_min() {
|
|
const int a = 2;
|
|
int b = 1;
|
|
static_assert(!is_const<decltype(__builtin_elementwise_min(a, b))>::value);
|
|
static_assert(!is_const<decltype(__builtin_elementwise_min(b, a))>::value);
|
|
static_assert(!is_const<decltype(__builtin_elementwise_min(a, a))>::value);
|
|
}
|
|
|
|
void test_builtin_elementwise_ceil() {
|
|
const float a = 42.0;
|
|
float b = 42.3;
|
|
static_assert(!is_const<decltype(__builtin_elementwise_ceil(a))>::value);
|
|
static_assert(!is_const<decltype(__builtin_elementwise_ceil(b))>::value);
|
|
}
|
|
|
|
void test_builtin_elementwise_cos() {
|
|
const float a = 42.0;
|
|
float b = 42.3;
|
|
static_assert(!is_const<decltype(__builtin_elementwise_cos(a))>::value);
|
|
static_assert(!is_const<decltype(__builtin_elementwise_cos(b))>::value);
|
|
}
|
|
|
|
void test_builtin_elementwise_sin() {
|
|
const float a = 42.0;
|
|
float b = 42.3;
|
|
static_assert(!is_const<decltype(__builtin_elementwise_sin(a))>::value);
|
|
static_assert(!is_const<decltype(__builtin_elementwise_sin(b))>::value);
|
|
}
|