Commit 4c1fbd3
[mono][llvm] Recognize MathF.Abs/Log and Single/Double.MinNumber/MaxNumber as intrinsics
Mono's LLVM backend has end-to-end plumbing for OP_FMA, OP_FCOPYSIGN,
OP_SQRTF, etc., but a handful of obvious BCL entry points fall through
to the C# implementations:
* `MathF.Abs(float)` and `MathF.Log(float)` are not recognized in the
MathF block of intrinsics.c, even though MathF.Sqrt/Sin/Cos/Exp/Log2/
Log10/Floor/Ceiling/Truncate all are. (Math.Abs(float) is recognized
via the Math (float) fallback, but Math.Log(float) doesn't exist —
only MathF.Log does.) Adding INTRINS_LOGF + OP_LOGF closes the
gap; MathF.Abs reuses the existing OP_ABSF / INTRINS_ABSF.
* `Single.MinNumber/MaxNumber` and `Double.MinNumber/MaxNumber`
(forwarders for INumber<TSelf>.{Min,Max}Number) are IEEE 754-2008
numNum semantics: when exactly one argument is NaN, return the
non-NaN; when both are NaN, return NaN. These map exactly to
llvm.minnum / llvm.maxnum, which on AArch64 lower to a single
fminnm/fmaxnm instruction. Without recognition the C# bodies inline
to a fcmp+select chain — semantically correct, but several
instructions on every target.
Mono had no recognition for the Single/Double primitive classes
previously; this adds a focused block that only handles MinNumber and
MaxNumber. (Min/Max forward to Math/MathF and are caught by the
existing recognition there.)
Adds:
* OP_LOGF / OP_FMINNUM / OP_FMAXNUM / OP_RMINNUM / OP_RMAXNUM in
mini-ops.h.
* INTRINS_LOGF / INTRINS_MINNUM / INTRINS_MINNUMF / INTRINS_MAXNUM /
INTRINS_MAXNUMF in llvm-intrinsics.h.
* Case handlers in mini-llvm.c (OP_LOGF reuses the existing
scalar-1-arg pattern; the four num/numF ops share a single block
that selects the correct intrinsic by opcode).
* Recognition in intrinsics.c — MathF.Abs/MathF.Log added to the
existing MathF (float) block; MinNumber/MaxNumber added in a new
Single/Double block placed after the Math block.
Validation: on the PR dotnet#129299 branch (emsdk 5.0.6 / LLVM 23) stacked
with the Min/Max NaN fix from PR dotnet#129593, full AOT + LLVM run of
System.Runtime.Tests on iossimulator-arm64:
HalfTests 1442/1442 pass
HalfTests_GenericMath 356/356 pass
SingleTests 1334/1334 pass
DoubleTests 1559/1559 pass
(no regression vs the dotnet#129593-only baseline; covers MinNumber/
MaxNumber on Single/Double)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 4e663eb commit 4c1fbd3
4 files changed
Lines changed: 81 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
106 | 108 | | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
110 | 112 | | |
111 | 113 | | |
112 | 114 | | |
| 115 | + | |
| 116 | + | |
113 | 117 | | |
114 | 118 | | |
115 | 119 | | |
| |||
285 | 289 | | |
286 | 290 | | |
287 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
288 | 318 | | |
289 | 319 | | |
290 | 320 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| |||
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
99 | 112 | | |
100 | 113 | | |
101 | 114 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7494 | 7494 | | |
7495 | 7495 | | |
7496 | 7496 | | |
| 7497 | + | |
| 7498 | + | |
| 7499 | + | |
| 7500 | + | |
| 7501 | + | |
| 7502 | + | |
| 7503 | + | |
7497 | 7504 | | |
7498 | 7505 | | |
7499 | 7506 | | |
| |||
7703 | 7710 | | |
7704 | 7711 | | |
7705 | 7712 | | |
| 7713 | + | |
| 7714 | + | |
| 7715 | + | |
| 7716 | + | |
| 7717 | + | |
| 7718 | + | |
| 7719 | + | |
| 7720 | + | |
| 7721 | + | |
| 7722 | + | |
| 7723 | + | |
| 7724 | + | |
| 7725 | + | |
| 7726 | + | |
| 7727 | + | |
| 7728 | + | |
| 7729 | + | |
| 7730 | + | |
| 7731 | + | |
| 7732 | + | |
| 7733 | + | |
| 7734 | + | |
| 7735 | + | |
| 7736 | + | |
| 7737 | + | |
7706 | 7738 | | |
7707 | 7739 | | |
7708 | 7740 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
684 | 684 | | |
685 | 685 | | |
686 | 686 | | |
| 687 | + | |
| 688 | + | |
687 | 689 | | |
688 | 690 | | |
689 | 691 | | |
| 692 | + | |
| 693 | + | |
690 | 694 | | |
691 | 695 | | |
692 | 696 | | |
| |||
740 | 744 | | |
741 | 745 | | |
742 | 746 | | |
| 747 | + | |
743 | 748 | | |
744 | 749 | | |
745 | 750 | | |
| |||
0 commit comments