-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Allow more than 64 ISA flags for jit interface. #73965
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -120,7 +120,6 @@ public enum InstructionSet | |||||||
X86_MOVBE_X64 = InstructionSet_X86.MOVBE_X64, | ||||||||
X86_X86Serialize_X64 = InstructionSet_X86.X86Serialize_X64, | ||||||||
} | ||||||||
|
||||||||
public enum InstructionSet_ARM64 | ||||||||
{ | ||||||||
ILLEGAL = InstructionSet.ILLEGAL, | ||||||||
|
@@ -240,54 +239,96 @@ public enum InstructionSet_X86 | |||||||
X86Serialize_X64 = 40, | ||||||||
} | ||||||||
|
||||||||
public struct InstructionSetFlags : IEnumerable<InstructionSet> | ||||||||
public unsafe struct InstructionSetFlags : IEnumerable<InstructionSet> | ||||||||
{ | ||||||||
private ulong _flags; | ||||||||
|
||||||||
private const int FlagsFieldCount = 1; | ||||||||
private const int BitsPerFlagsField = 64; | ||||||||
private fixed ulong _flags[FlagsFieldCount]; | ||||||||
public IEnumerable<InstructionSet_ARM64> ARM64Flags => this.Select((x) => (InstructionSet_ARM64)x); | ||||||||
|
||||||||
public IEnumerable<InstructionSet_X64> X64Flags => this.Select((x) => (InstructionSet_X64)x); | ||||||||
|
||||||||
public IEnumerable<InstructionSet_X86> X86Flags => this.Select((x) => (InstructionSet_X86)x); | ||||||||
|
||||||||
public InstructionSetFlags() { } | ||||||||
|
||||||||
private static uint GetFlagsFieldIndex(InstructionSet instructionSet) | ||||||||
{ | ||||||||
uint bitIndex = (uint)instructionSet; | ||||||||
return (uint)(bitIndex / (uint)BitsPerFlagsField); | ||||||||
} | ||||||||
|
||||||||
private static ulong GetRelativeBitMask(InstructionSet instructionSet) | ||||||||
{ | ||||||||
return ((ulong)1) << ((int)instructionSet & 0x3F); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} | ||||||||
|
||||||||
public void AddInstructionSet(InstructionSet instructionSet) | ||||||||
{ | ||||||||
_flags = _flags | (((ulong)1) << (int)instructionSet); | ||||||||
uint index = GetFlagsFieldIndex(instructionSet); | ||||||||
_flags[index] |= GetRelativeBitMask(instructionSet); | ||||||||
} | ||||||||
|
||||||||
public void RemoveInstructionSet(InstructionSet instructionSet) | ||||||||
{ | ||||||||
_flags = _flags & ~(((ulong)1) << (int)instructionSet); | ||||||||
uint index = GetFlagsFieldIndex(instructionSet); | ||||||||
ulong bitIndex = GetRelativeBitMask(instructionSet); | ||||||||
_flags[index] &= ~bitIndex; | ||||||||
} | ||||||||
|
||||||||
public bool HasInstructionSet(InstructionSet instructionSet) | ||||||||
{ | ||||||||
return (_flags & (((ulong)1) << (int)instructionSet)) != 0; | ||||||||
uint index = GetFlagsFieldIndex(instructionSet); | ||||||||
ulong bitIndex = GetRelativeBitMask(instructionSet); | ||||||||
return ((_flags[index] & bitIndex) != 0); | ||||||||
} | ||||||||
|
||||||||
public bool Equals(InstructionSetFlags other) | ||||||||
{ | ||||||||
return _flags == other._flags; | ||||||||
for (int i = 0; i < FlagsFieldCount; i++) | ||||||||
{ | ||||||||
if (_flags[i] != other._flags[i]) | ||||||||
{ | ||||||||
return false; | ||||||||
} | ||||||||
} | ||||||||
return true; | ||||||||
} | ||||||||
|
||||||||
public void Add(InstructionSetFlags other) | ||||||||
{ | ||||||||
_flags |= other._flags; | ||||||||
for (int i = 0; i < FlagsFieldCount; i++) | ||||||||
{ | ||||||||
_flags[i] |= other._flags[i]; | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
public void IntersectionWith(InstructionSetFlags other) | ||||||||
{ | ||||||||
_flags &= other._flags; | ||||||||
for (int i = 0; i < FlagsFieldCount; i++) | ||||||||
{ | ||||||||
_flags[i] &= other._flags[i]; | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
public void Remove(InstructionSetFlags other) | ||||||||
{ | ||||||||
_flags &= ~other._flags; | ||||||||
for (int i = 0; i < FlagsFieldCount; i++) | ||||||||
{ | ||||||||
_flags[i] &= ~other._flags[i]; | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
public bool IsEmpty() | ||||||||
{ | ||||||||
return _flags == 0; | ||||||||
for (int i = 0; i < FlagsFieldCount; i++) | ||||||||
{ | ||||||||
if (_flags[i] != 0) | ||||||||
{ | ||||||||
return false; | ||||||||
} | ||||||||
} | ||||||||
return true; | ||||||||
} | ||||||||
|
||||||||
IEnumerator IEnumerable.GetEnumerator() | ||||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a bug, since it ignores the top 2 bits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetFlagsFieldIndex
gets the 64-bit field in which a giveninstructionSet
is tagged (only the bits 6 and higher matter).GetRelativeBitIndex
then gets the bit offset within that field, which can only be0-63
, so0x3F
should be the correct mask.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetRelativeBitMask
might have been a better name, since its not getting the index but rather a mask that only includes the given index.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have changed name to
GetRelativeBitMask