@@ -333,39 +333,48 @@ static bool interp__builtin_copysign(InterpState &S, CodePtr OpPC,
333
333
}
334
334
335
335
static bool interp__builtin_fmin (InterpState &S, CodePtr OpPC,
336
- const InterpFrame *Frame, const Function *F) {
336
+ const InterpFrame *Frame, const Function *F,
337
+ bool IsNumBuiltin) {
337
338
const Floating &LHS = getParam<Floating>(Frame, 0 );
338
339
const Floating &RHS = getParam<Floating>(Frame, 1 );
339
340
340
341
Floating Result;
341
342
342
- // When comparing zeroes, return -0.0 if one of the zeroes is negative.
343
- if (LHS.isZero () && RHS.isZero () && RHS.isNegative ())
344
- Result = RHS;
345
- else if (LHS.isNan () || RHS < LHS)
346
- Result = RHS;
347
- else
348
- Result = LHS;
343
+ if (IsNumBuiltin) {
344
+ Result = llvm::minimumnum (LHS.getAPFloat (), RHS.getAPFloat ());
345
+ } else {
346
+ // When comparing zeroes, return -0.0 if one of the zeroes is negative.
347
+ if (LHS.isZero () && RHS.isZero () && RHS.isNegative ())
348
+ Result = RHS;
349
+ else if (LHS.isNan () || RHS < LHS)
350
+ Result = RHS;
351
+ else
352
+ Result = LHS;
353
+ }
349
354
350
355
S.Stk .push <Floating>(Result);
351
356
return true ;
352
357
}
353
358
354
359
static bool interp__builtin_fmax (InterpState &S, CodePtr OpPC,
355
- const InterpFrame *Frame,
356
- const Function *Func ) {
360
+ const InterpFrame *Frame, const Function *Func,
361
+ bool IsNumBuiltin ) {
357
362
const Floating &LHS = getParam<Floating>(Frame, 0 );
358
363
const Floating &RHS = getParam<Floating>(Frame, 1 );
359
364
360
365
Floating Result;
361
366
362
- // When comparing zeroes, return +0.0 if one of the zeroes is positive.
363
- if (LHS.isZero () && RHS.isZero () && LHS.isNegative ())
364
- Result = RHS;
365
- else if (LHS.isNan () || RHS > LHS)
366
- Result = RHS;
367
- else
368
- Result = LHS;
367
+ if (IsNumBuiltin) {
368
+ Result = llvm::maximumnum (LHS.getAPFloat (), RHS.getAPFloat ());
369
+ } else {
370
+ // When comparing zeroes, return +0.0 if one of the zeroes is positive.
371
+ if (LHS.isZero () && RHS.isZero () && LHS.isNegative ())
372
+ Result = RHS;
373
+ else if (LHS.isNan () || RHS > LHS)
374
+ Result = RHS;
375
+ else
376
+ Result = LHS;
377
+ }
369
378
370
379
S.Stk .push <Floating>(Result);
371
380
return true ;
@@ -1701,7 +1710,16 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
1701
1710
case Builtin::BI__builtin_fminl:
1702
1711
case Builtin::BI__builtin_fminf16:
1703
1712
case Builtin::BI__builtin_fminf128:
1704
- if (!interp__builtin_fmin (S, OpPC, Frame, F))
1713
+ if (!interp__builtin_fmin (S, OpPC, Frame, F, /* IsNumBuiltin=*/ false ))
1714
+ return false ;
1715
+ break ;
1716
+
1717
+ case Builtin::BI__builtin_fminimum_num:
1718
+ case Builtin::BI__builtin_fminimum_numf:
1719
+ case Builtin::BI__builtin_fminimum_numl:
1720
+ case Builtin::BI__builtin_fminimum_numf16:
1721
+ case Builtin::BI__builtin_fminimum_numf128:
1722
+ if (!interp__builtin_fmin (S, OpPC, Frame, F, /* IsNumBuiltin=*/ true ))
1705
1723
return false ;
1706
1724
break ;
1707
1725
@@ -1710,7 +1728,16 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
1710
1728
case Builtin::BI__builtin_fmaxl:
1711
1729
case Builtin::BI__builtin_fmaxf16:
1712
1730
case Builtin::BI__builtin_fmaxf128:
1713
- if (!interp__builtin_fmax (S, OpPC, Frame, F))
1731
+ if (!interp__builtin_fmax (S, OpPC, Frame, F, /* IsNumBuiltin=*/ false ))
1732
+ return false ;
1733
+ break ;
1734
+
1735
+ case Builtin::BI__builtin_fmaximum_num:
1736
+ case Builtin::BI__builtin_fmaximum_numf:
1737
+ case Builtin::BI__builtin_fmaximum_numl:
1738
+ case Builtin::BI__builtin_fmaximum_numf16:
1739
+ case Builtin::BI__builtin_fmaximum_numf128:
1740
+ if (!interp__builtin_fmax (S, OpPC, Frame, F, /* IsNumBuiltin=*/ true ))
1714
1741
return false ;
1715
1742
break ;
1716
1743
0 commit comments