-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Always inline number conversions #112061
Always inline number conversions #112061
Conversation
Tagging subscribers to this area: @dotnet/area-system-numerics |
@EgorBot -intel using System.Numerics;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
// Actual runner is optional, but if it exists, it has to be like this:
BenchmarkSwitcher.FromAssembly(typeof(Bench).Assembly).Run(args);
public class Bench
{
[Benchmark]
public double GetDouble() => CastNumber<double>(42);
static T CastNumber<T>(int v) where T : INumberBase<T>
{
return T.CreateTruncating(v);
}
} |
Benchmark on linux_azure_genoa:
Benchmark on linux_azure_cascadelake:
|
@hez2010 you should run a benchmark that isn't constant foldable as well; so more accurate numbers can be given. |
@EgorBot -intel using System.Numerics;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
// Actual runner is optional, but if it exists, it has to be like this:
BenchmarkSwitcher.FromAssembly(typeof(Bench).Assembly).Run(args);
public class Bench
{
private int v = 42;
[Benchmark]
public double GetDouble() => CastNumber<double>(this.v);
static T CastNumber<T>(int v) where T : INumberBase<T>
{
return T.CreateTruncating(v);
}
} |
Saved the int to a class field to prevent constant folding and make it always load from the address.
|
* main: System.Net.Http.WinHttpHandler.StartRequestAsync assertion failed (dotnet#109799) Keep test PDB in helix payload for native AOT (dotnet#111949) Build the RID-specific System.IO.Ports packages in the VMR (dotnet#112054) Always inline number conversions (dotnet#112061) Use Contains{Any} in Regex source generator (dotnet#112065) Update dependencies from https://github.com/dotnet/arcade build 20250130.5 (dotnet#112013) JIT: Transform single-reg args to FIELD_LIST in physical promotion (dotnet#111590) Ensure that math calls into the CRT are tracked as needing vzeroupper (dotnet#112011) Use double.ConvertToIntegerNative where safe to do in System.Random (dotnet#112046) JIT: Compute `fgCalledCount` after synthesis (dotnet#112041) Simplify boolean logic in `TimeZoneInfo` (dotnet#112062) JIT: Update type when return temp is freshly created (dotnet#111948) Remove unused build controls and simplify DotNetBuild.props (dotnet#111986) Fix case-insensitive JSON deserialization of enum member names (dotnet#112028) WasmAppBuilder: Remove double computation of a value (dotnet#112047) Disable LTCG for brotli and zlibng. (dotnet#111805) JIT: Improve x86 unsigned to floating cast codegen (dotnet#111595) simplify x86 special intrinsic imports (dotnet#111836) JIT: Try to retain entry weight during profile synthesis (dotnet#111971) Fix explicit offset of ByRefLike fields. (dotnet#111584)
We applied
AggressiveInlining
for mostTryConvert*
, except several leftovers.Apply it for them as well.
Otherwise they will not be inlined: https://godbolt.org/z/h5dz6sKa5
Searched with
bool\s+.*TryConvert
.