-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JIT] X64 - Three instruction replacement sequence for multiply in ce…
…rtain cases (#76981) * Using 3 instruction sequence for x64 multiply * Do not do this in morph. Do it in codegen now. * Fixing codegen * Only allow values under 127 and do not skip mov - correctness testing * Try to fix tests * cleanup * Moving to Lowering * Quick fix * Fully works in lowering now * Account for all ints * Take into account codegen opts * Minor cleanup * Minor cleanup * Fixed test * Added int multiply disasm checks. Fixed SuperFileCheck namespace bug. Made SuperFileCheck anchors more likely to match. * Update comments * Update comments * Update comments * Update comments * Formatting * Fixing build * Fixing build again * minor rename * Feedback. Removed use of FULL-LINE as it is more readable not strictly necessary. Forgot to add an additional instruction to a disasm test. * Formatting
- Loading branch information
Showing
5 changed files
with
303 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace CodeGenTests | ||
{ | ||
static class IntMultiply | ||
{ | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static uint UInt32_MultiplyWithUInt32MaxValue(uint value) | ||
{ | ||
// X64: mov [[REG0:[a-z]+]], [[REG1:[a-z]+]] | ||
// X64-NEXT: neg [[REG0]] | ||
return value * UInt32.MaxValue; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static ulong UInt64_MultiplyWithUInt32MaxValue(ulong value) | ||
{ | ||
// X64: mov [[REG0:[a-z]+]], [[REG1:[a-z]+]] | ||
// X64-NEXT: shl [[REG0]], 32 | ||
// X64-NEXT: sub [[REG0]], [[REG1]] | ||
return value * (ulong)UInt32.MaxValue; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static ulong UInt64_MultiplyWithUInt32MaxValuePlusOne(ulong value) | ||
{ | ||
// X64: mov [[REG0:[a-z]+]], [[REG1:[a-z]+]] | ||
// X64-NEXT: shl [[REG0]], 32 | ||
return value * ((ulong)UInt32.MaxValue + 1); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static ulong UInt64_MultiplyWithUInt32MaxValuePlusTwo(ulong value) | ||
{ | ||
// X64: mov [[REG0:[a-z]+]], [[REG1:[a-z]+]] | ||
// X64-NEXT: shl [[REG0]], 32 | ||
// X64-NEXT: add [[REG0]], [[REG1]] | ||
return value * ((ulong)UInt32.MaxValue + 2); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static ulong UInt64_MultiplyWith2(ulong value) | ||
{ | ||
// X64: lea [[REG0:[a-z]+]], {{\[}}[[REG1:[a-z]+]]+[[REG1]]{{\]}} | ||
return value * 2; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static ulong UInt64_MultiplyWith3(ulong value) | ||
{ | ||
// X64: lea [[REG0:[a-z]+]], {{\[}}[[REG1:[a-z]+]]+2*[[REG1]]{{\]}} | ||
return value * 3; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static ulong UInt64_MultiplyWith4(ulong value) | ||
{ | ||
// X64: mov [[REG0:[a-z]+]], [[REG1:[a-z]+]] | ||
// X64-NEXT: shl [[REG0]], 2 | ||
return value * 4; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static ulong UInt64_MultiplyWith5(ulong value) | ||
{ | ||
// X64: lea [[REG0:[a-z]+]], {{\[}}[[REG1:[a-z]+]]+4*[[REG1]]{{\]}} | ||
return value * 5; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static ulong UInt64_MultiplyWith6(ulong value) | ||
{ | ||
// X64: lea [[REG0:[a-z]+]], {{\[}}[[REG1:[a-z]+]]+2*[[REG1]]{{\]}} | ||
// X64-NEXT: add [[REG0]], [[REG0]] | ||
return value * 6; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static ulong UInt64_MultiplyWith7(ulong value) | ||
{ | ||
// X64: mov [[REG0:[a-z]+]], [[REG1:[a-z]+]] | ||
// X64-NEXT: shl [[REG0]], 3 | ||
// X64-NEXT: sub [[REG0]], [[REG1]] | ||
return value * 7; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static ulong UInt64_MultiplyWith8(ulong value) | ||
{ | ||
// X64: mov [[REG0:[a-z]+]], [[REG1:[a-z]+]] | ||
// X64-NEXT: shl [[REG0]], 3 | ||
return value * 8; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static ulong UInt64_MultiplyWith9(ulong value) | ||
{ | ||
// X64: lea [[REG0:[a-z]+]], {{\[}}[[REG1:[a-z]+]]+8*[[REG1]]{{\]}} | ||
return value * 9; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static ulong UInt64_MultiplyWith15(ulong value) | ||
{ | ||
// X64: mov [[REG0:[a-z]+]], [[REG1:[a-z]+]] | ||
// X64-NEXT: shl [[REG0]], 4 | ||
// X64-NEXT: sub [[REG0]], [[REG1]] | ||
return value * 15; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static ulong UInt64_MultiplyWith16(ulong value) | ||
{ | ||
// X64: mov [[REG0:[a-z]+]], [[REG1:[a-z]+]] | ||
// X64-NEXT: shl [[REG0]], 4 | ||
return value * 16; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static ulong UInt64_MultiplyWith17(ulong value) | ||
{ | ||
// X64: mov [[REG0:[a-z]+]], [[REG1:[a-z]+]] | ||
// X64-NEXT: shl [[REG0]], 4 | ||
// X64-NEXT: add [[REG0]], [[REG1]] | ||
return value * 17; | ||
} | ||
|
||
static int Main() | ||
{ | ||
if (UInt32_MultiplyWithUInt32MaxValue(1) != UInt32.MaxValue) | ||
return 0; | ||
|
||
if (UInt64_MultiplyWithUInt32MaxValue(1) != (ulong)UInt32.MaxValue) | ||
return 0; | ||
|
||
if (UInt64_MultiplyWithUInt32MaxValuePlusOne(1) != ((ulong)UInt32.MaxValue + 1)) | ||
return 0; | ||
|
||
if (UInt64_MultiplyWithUInt32MaxValuePlusTwo(1) != ((ulong)UInt32.MaxValue + 2)) | ||
return 0; | ||
|
||
if (UInt64_MultiplyWith2(1) != 2) | ||
return 0; | ||
|
||
if (UInt64_MultiplyWith3(1) != 3) | ||
return 0; | ||
|
||
if (UInt64_MultiplyWith4(1) != 4) | ||
return 0; | ||
|
||
if (UInt64_MultiplyWith5(1) != 5) | ||
return 0; | ||
|
||
if (UInt64_MultiplyWith6(1) != 6) | ||
return 0; | ||
|
||
if (UInt64_MultiplyWith7(1) != 7) | ||
return 0; | ||
|
||
if (UInt64_MultiplyWith8(1) != 8) | ||
return 0; | ||
|
||
if (UInt64_MultiplyWith9(1) != 9) | ||
return 0; | ||
|
||
if (UInt64_MultiplyWith15(1) != 15) | ||
return 0; | ||
|
||
if (UInt64_MultiplyWith16(1) != 16) | ||
return 0; | ||
|
||
if (UInt64_MultiplyWith17(1) != 17) | ||
return 0; | ||
|
||
return 100; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DebugType>None</DebugType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs"> | ||
<HasDisasmCheck>true</HasDisasmCheck> | ||
</Compile> | ||
|
||
<CLRTestEnvironmentVariable Include="COMPlus_TieredCompilation" Value="0" /> | ||
<CLRTestEnvironmentVariable Include="COMPlus_JITMinOpts" Value="0" /> | ||
</ItemGroup> | ||
</Project> |