-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Fix]
unalignment memory load in Neo.VM Unsafe.NotZero(ReadOnlySpan<byte>) and remove the use of unsafe
#3492
Conversation
[fix]
unalignment memory load in Neo.VM Unsafe.NotZero(ReadOnlySpan<byte>)
[fix]
unalignment memory load in Neo.VM Unsafe.NotZero(ReadOnlySpan<byte>)[Fix]
unalignment memory load in Neo.VM Unsafe.NotZero(ReadOnlySpan<byte>)
src/Neo.VM/Utility.cs
Outdated
@@ -27,6 +27,23 @@ static Utility() | |||
StrictUTF8.EncoderFallback = EncoderFallback.ExceptionFallback; | |||
} | |||
|
|||
public static bool NotZero(this ReadOnlySpan<byte> x) |
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 needs to be moved to the extensions library. For ReadOnlySpans.cs
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 needs to be moved to the extensions library. For
ReadOnlySpans.cs
Move it with the rest of the content together?
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.
Just that extension method
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.
Would like this method to be moved to Neo.Extensions
library
src/Neo.VM/Utility.cs
Outdated
int i; | ||
for (i = 0; i + 7 < x.Length; i += 8) | ||
{ | ||
if ((x[i] | x[i + 1] | x[i + 2] | x[i + 3] | x[i + 4] | x[i + 5] | x[i + 6] | x[i + 7]) != 0) |
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 won't be faster as previous version
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 won't be faster as previous version
This won't be faster as previous version
The performance has been optimized,
[Fix]
unalignment memory load in Neo.VM Unsafe.NotZero(ReadOnlySpan<byte>)[Fix]
unalignment memory load in Neo.VM Unsafe.NotZero(ReadOnlySpan<byte>) and remove the use of unsafe
netstandard2.1 problems |
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.
Fix to make compatible with netstandard2.1
. And Move NotZero
method to Neo.Extensions
library.
Error: /Users/runner/work/neo/neo/src/Neo.VM/Utility.cs(38,22): error CS1061: 'ReadOnlySpan<byte>' does not contain a definition for 'IndexOfAnyExcept' and no accessible extension method 'IndexOfAnyExcept' accepting a first argument of type 'ReadOnlySpan<byte>' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/neo/neo/src/Neo.VM/Neo.VM.csproj::TargetFramework=netstandard2.1]
🥲 |
Description
The
Unsafe.NotZero(ReadOnlySpan<byte>)
method inNeo.VM
uselong*
to load data fromReadOnlySpan<byte>
for better performance, but this approach may result in misaligned memory access. This approach is no problem on x86 CPUs, but it may cause bug on some RISC CPUs(for example, some ARM CPUs).Fixes # (issue)
Type of change
Test Configuration:
Checklist: