Skip to content

Commit 89a87ca

Browse files
committed
address review comments
1 parent 93c625a commit 89a87ca

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def FloorF16F128 : Builtin, F16F128MathTemplate {
199199

200200
def FmaF16F128 : Builtin, F16F128MathTemplate {
201201
let Spellings = ["__builtin_fma"];
202-
let Attributes = [FunctionWithBuiltinPrefix, NoThrow, ConstIgnoringErrnoAndExceptions];
202+
let Attributes = [FunctionWithBuiltinPrefix, NoThrow, ConstIgnoringErrnoAndExceptions, Constexpr];
203203
let Prototype = "T(T, T, T)";
204204
}
205205

clang/lib/AST/ByteCode/Floating.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ class Floating final {
203203
return R->F.divide(B.F, RM);
204204
}
205205

206+
static APFloat::opStatus fma(const Floating &A, const Floating &B,
207+
const Floating &C, llvm::RoundingMode RM,
208+
Floating *R) {
209+
*R = Floating(A.F);
210+
return R->F.fusedMultiplyAdd(B.F, C.F, RM);
211+
}
212+
206213
static bool neg(const Floating &A, Floating *R) {
207214
*R = -A;
208215
return false;

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ static bool interp__builtin_fma(InterpState &S, CodePtr OpPC,
571571
Floating Result;
572572

573573
llvm::RoundingMode RM = getActiveRoundingMode(S, Call);
574-
Floating::mul(X, Y, RM, &Result);
575-
Floating::add(Result, Z, RM, &Result);
574+
if (!Floating::fma(X, Y, Z, RM, &Result))
575+
return false;
576576

577577
S.Stk.push<Floating>(Result);
578578
return true;

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15325,9 +15325,7 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) {
1532515325
return false;
1532615326

1532715327
llvm::RoundingMode RM = getActiveRoundingMode(Info, E);
15328-
Result.multiply(Y, RM);
15329-
Result.add(Z, RM);
15330-
return true;
15328+
return Result.fusedMultiplyAdd(Y, Z, RM) == APFloat::opOK;
1533115329
}
1533215330

1533315331
case Builtin::BI__arithmetic_fence:

clang/test/Sema/constant-builtins-2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ double g19 = __builtin_fma(1.0, 1.0, 1.0);
5858
float g20 = __builtin_fmaf(1.0f, 1.0f, 1.0f);
5959
long double g21 = __builtin_fmal(1.0L, 1.0L, 1.0L);
6060
#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
61-
__float128 g21_2 = __builtin_fma(1.0q, 1.0q, 1.0q);
61+
__float128 g21_2 = __builtin_fmaf128(1.0q, 1.0q, 1.0q);
6262
#endif
6363

6464
char classify_nan [__builtin_fpclassify(+1, -1, -1, -1, -1, __builtin_nan(""))];

0 commit comments

Comments
 (0)