@@ -383,6 +383,13 @@ HEADER_SHIM long double libm_lgammal(long double x, int *signp) {
383
383
#endif
384
384
385
385
// MARK: - math inlines with relaxed semantics to support optimization.
386
+ #if __swift__ >= 50400
387
+ #define CLANG_RELAX_FP _Pragma( " clang fp reassociate(on) contract(fast) " )
388
+ #else
389
+ // reassociate(on) isn't supported by the clang in pre-swift-5.4 toolchains.
390
+ #define CLANG_RELAX_FP _Pragma( " clang fp contract(fast) " )
391
+ #endif
392
+
386
393
#if !(__i386__ || __x86_64__)
387
394
/// a*b + c evaluated _either_ as two operations or fma, whichever is faster.
388
395
HEADER_SHIM _Float16 _numerics_muladdf16 ( _Float16 a, _Float16 b, _Float16 c) {
@@ -393,14 +400,14 @@ HEADER_SHIM _Float16 _numerics_muladdf16(_Float16 a, _Float16 b, _Float16 c) {
393
400
/// a + b with the "allow reassociation" and "allow FMA formation" flags
394
401
/// set in the IR.
395
402
HEADER_SHIM _Float16 _numerics_relaxed_addf16 ( _Float16 a, _Float16 b) {
396
- #pragma clang fp reassociate ( on ) contract ( fast )
403
+ CLANG_RELAX_FP
397
404
return a + b;
398
405
}
399
406
400
407
/// a * b with the "allow reassociation" and "allow FMA formation" flags
401
408
/// set in the IR.
402
409
HEADER_SHIM _Float16 _numerics_relaxed_mulf16 ( _Float16 a, _Float16 b) {
403
- #pragma clang fp reassociate ( on ) contract ( fast )
410
+ CLANG_RELAX_FP
404
411
return a * b;
405
412
}
406
413
#endif
@@ -414,14 +421,14 @@ HEADER_SHIM float _numerics_muladdf(float a, float b, float c) {
414
421
/// a + b with the "allow reassociation" and "allow FMA formation" flags
415
422
/// set in the IR.
416
423
HEADER_SHIM float _numerics_relaxed_addf( float a, float b) {
417
- #pragma clang fp reassociate ( on ) contract ( fast )
424
+ CLANG_RELAX_FP
418
425
return a + b;
419
426
}
420
427
421
428
/// a * b with the "allow reassociation" and "allow FMA formation" flags
422
429
/// set in the IR.
423
430
HEADER_SHIM float _numerics_relaxed_mulf( float a, float b) {
424
- #pragma clang fp reassociate ( on ) contract ( fast )
431
+ CLANG_RELAX_FP
425
432
return a * b;
426
433
}
427
434
@@ -434,29 +441,29 @@ HEADER_SHIM double _numerics_muladd(double a, double b, double c) {
434
441
/// a + b with the "allow reassociation" and "allow FMA formation" flags
435
442
/// set in the IR.
436
443
HEADER_SHIM double _numerics_relaxed_add( double a, double b) {
437
- #pragma clang fp reassociate ( on ) contract ( fast )
444
+ CLANG_RELAX_FP
438
445
return a + b;
439
446
}
440
447
441
448
/// a * b with the "allow reassociation" and "allow FMA formation" flags
442
449
/// set in the IR.
443
450
HEADER_SHIM double _numerics_relaxed_mul( double a, double b) {
444
- #pragma clang fp reassociate ( on ) contract ( fast )
451
+ CLANG_RELAX_FP
445
452
return a * b;
446
453
}
447
454
448
455
#if !defined _WIN32 && (defined __i386__ || defined __x86_64__)
449
456
/// a + b with the "allow reassociation" and "allow FMA formation" flags
450
457
/// set in the IR.
451
458
HEADER_SHIM long do uble _numerics_relaxed_addl( long do uble a, long do uble b) {
452
- #pragma clang fp reassociate ( on ) contract ( fast )
459
+ CLANG_RELAX_FP
453
460
return a + b;
454
461
}
455
462
456
463
/// a * b with the "allow reassociation" and "allow FMA formation" flags
457
464
/// set in the IR.
458
465
HEADER_SHIM long do uble _numerics_relaxed_mull( long do uble a, long do uble b) {
459
- #pragma clang fp reassociate ( on ) contract ( fast )
466
+ CLANG_RELAX_FP
460
467
return a * b;
461
468
}
462
469
#endif
0 commit comments