Skip to content

Commit 3ac4882

Browse files
committed
Added HLSL or intrinsic function with respective semantic checks
1 parent 0454dd8 commit 3ac4882

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def AcoshF128 : Builtin {
9898
}
9999

100100
def AsinF16F128 : Builtin, F16F128MathTemplate {
101-
let Spellings = ["__builtin_asin"];
101+
let Spellings = ["__builtin_asin"];
102102
let Attributes = [FunctionWithBuiltinPrefix, NoThrow,
103103
ConstIgnoringErrnoAndExceptions];
104104
let Prototype = "T(T)";
@@ -1238,6 +1238,7 @@ def NondetermenisticValue : Builtin {
12381238
let Prototype = "void(...)";
12391239
}
12401240

1241+
12411242
def ElementwiseAbs : Builtin {
12421243
let Spellings = ["__builtin_elementwise_abs"];
12431244
let Attributes = [NoThrow, Const, CustomTypeChecking];
@@ -4968,6 +4969,11 @@ def HLSLGroupMemoryBarrierWithGroupSync: LangBuiltin<"HLSL_LANG"> {
49684969
let Attributes = [NoThrow, Const];
49694970
let Prototype = "void()";
49704971
}
4972+
def HLSLOr : LangBuiltin<"HLSL_LANG"> {
4973+
let Spellings = ["__builtin_hlsl_or"];
4974+
let Attributes = [NoThrow, Const];
4975+
let Prototype = "void(...)";
4976+
}
49714977

49724978
// Builtins for XRay.
49734979
def XRayCustomEvent : Builtin {

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ namespace hlsl {
3737
#define _HLSL_16BIT_AVAILABILITY_STAGE(environment, version, stage)
3838
#endif
3939

40+
//===----------------------------------------------------------------------===//
41+
// or builtins
42+
//===----------------------------------------------------------------------===//
43+
44+
/// \fn T or(T x, T y)
45+
/// \brief Returns the bitwise OR of the two input values, \a x and \a y.
46+
/// \param x The first input value and y The second input value.
47+
///
48+
/// \returns The bitwise OR of the two input values.
49+
50+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
51+
bool or (bool, bool);
52+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
53+
bool2 or (bool2, bool2);
54+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
55+
bool3 or (bool3, bool3);
56+
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
57+
bool4 or (bool4, bool4);
58+
4059
//===----------------------------------------------------------------------===//
4160
// abs builtins
4261
//===----------------------------------------------------------------------===//

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,6 +2558,29 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
25582558
}
25592559
break;
25602560
}
2561+
2562+
case Builtin::BI__builtin_hlsl_or: {
2563+
if (SemaRef.checkArgCount(TheCall, 2))
2564+
return true;
2565+
if (CheckVectorElementCallArgs(&SemaRef, TheCall))
2566+
return true;
2567+
2568+
//Ensure input parameter type is bool
2569+
ExprResult A = TheCall->getArg(0);
2570+
QualType ArgTyA = A.get()->getType();
2571+
ExprResult B = TheCall->getArg(1);
2572+
QualType ArgTyB = B.get()->getType();
2573+
if (!ArgTyA->isBooleanType() || !ArgTyB->isBooleanType()) {
2574+
SemaRef.Diag(TheCall->getArg(0)->getBeginLoc(),
2575+
diag::err_typecheck_convert_incompatible)
2576+
<< ArgTyA << SemaRef.Context.BoolTy << 1 << 0 << 0;
2577+
return true;
2578+
}
2579+
// Ensure input expr type is a scalar/vector and the same as the return type
2580+
if (CheckAnyScalarOrVector(&SemaRef, TheCall, 0))
2581+
return true;
2582+
break;
2583+
}
25612584
}
25622585
return false;
25632586
}

0 commit comments

Comments
 (0)