зеркало из https://github.com/microsoft/clang.git
Implement codegen for __builtin_isnormal.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104118 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
c3f984fa13
Коммит
6349ce94d1
|
@ -364,11 +364,25 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
|
|||
|
||||
// TODO: BI__builtin_isinf_sign
|
||||
// isinf_sign(x) -> isinf(x) ? (signbit(x) ? -1 : 1) : 0
|
||||
// TODO: BI__builtin_isnormal
|
||||
// isnormal(x) -> x != x && fabs(x) < infinity && fabsf(x) >= float_min
|
||||
// where floatmin is the minimum value for the fp type. Not sure if this is
|
||||
// APFloat::getSmallest or getSmallestNormalized.
|
||||
|
||||
|
||||
case Builtin::BI__builtin_isnormal: {
|
||||
// isnormal(x) --> x == x && fabsf(x) < infinity && fabsf(x) >= float_min
|
||||
Value *V = EmitScalarExpr(E->getArg(0));
|
||||
Value *Eq = Builder.CreateFCmpOEQ(V, V, "iseq");
|
||||
|
||||
Value *Abs = EmitFAbs(*this, V, E->getArg(0)->getType());
|
||||
Value *IsLessThanInf =
|
||||
Builder.CreateFCmpULT(Abs, ConstantFP::getInfinity(V->getType()),"isinf");
|
||||
APFloat Smallest = APFloat::getSmallestNormalized(
|
||||
getContext().getFloatTypeSemantics(E->getArg(0)->getType()));
|
||||
Value *IsNormal =
|
||||
Builder.CreateFCmpUGE(Abs, ConstantFP::get(V->getContext(), Smallest),
|
||||
"isnormal");
|
||||
V = Builder.CreateAnd(Eq, IsLessThanInf, "and");
|
||||
V = Builder.CreateAnd(V, IsNormal, "and");
|
||||
return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType())));
|
||||
}
|
||||
|
||||
case Builtin::BI__builtin_isfinite: {
|
||||
// isfinite(x) --> x == x && fabs(x) != infinity; }
|
||||
Value *V = EmitScalarExpr(E->getArg(0));
|
||||
|
|
|
@ -185,5 +185,13 @@ void test_float_builtins(float F, double D, long double LD) {
|
|||
// CHECK: call float @fabsf
|
||||
// CHECK: fcmp une float {{.*}}, 0x7FF0000000000000
|
||||
// CHECK: and i1
|
||||
|
||||
res = __builtin_isnormal(F);
|
||||
// CHECK: fcmp oeq float
|
||||
// CHECK: call float @fabsf
|
||||
// CHECK: fcmp ult float {{.*}}, 0x7FF0000000000000
|
||||
// CHECK: fcmp uge float {{.*}}, 0x3810000000000000
|
||||
// CHECK: and i1
|
||||
// CHECK: and i1
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче