Skip to content

Commit

Permalink
Minor fixes (still not working)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-Nuon committed Jan 2, 2024
1 parent c83b8c1 commit 2080e68
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/UTF8_validation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ public utf8_checker() {
}

public void check_utf8_bytes(Vector256<byte> input, Vector256<byte> prev_input) {
Vector256<byte> prev1 = input; // Adjust this as necessary for your logic
// Vector256<byte> prev1 = input; // Adjust this as necessary for your logic
Vector256<byte> prev1 = input.Prev(prev_input, 1);
Vector256<byte> sc = check_special_cases(input, prev1);
error = Avx2.Or(error, check_multibyte_lengths(input, prev_input, sc));
}
Expand All @@ -181,7 +182,7 @@ public void check_eof() {
// This is the first point of entry for this function
// The original C++ implementation is much more extensive and assumes a 512 bit stream as well as several implementations
// In this case I focus solely on AVX2 instructions for prototyping and benchmarking purposes.
// This is the simplest least time-consuming implementation. 0
// This is the simplest least time-consuming implementation.
public void check_next_input(Vector256<byte> input) {

// Skip this for now, we'll come back later
Expand Down
14 changes: 11 additions & 3 deletions test/UTF8ValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace tests;
using System.Text;
using SimdUnicode;

public class Utf8ValidationTests
public class Utf8SIMDValidationTests
{


Expand Down Expand Up @@ -31,8 +31,16 @@ public void TestGoodSequences()
{
fixed (byte* pInput = input)
{
byte* result = SimdUnicode.UTF8.GetPointerToFirstInvalidByte(pInput, input.Length);
Assert.Equal((IntPtr)(pInput + input.Length), (IntPtr)result); // Expecting the end of the string
// Testing SimdUnicode.UTF8.GetPointerToFirstInvalidByte
byte* scalarResult = SimdUnicode.UTF8.GetPointerToFirstInvalidByte(pInput, input.Length);
Assert.True((IntPtr)(pInput + input.Length) == (IntPtr)scalarResult,
"Failure in Scalar function: SimdUnicode.UTF8.GetPointerToFirstInvalidByte");

// Testing Utf8Utility.GetPointerToFirstInvalidByte
byte* SIMDResult = Utf8Utility.GetPointerToFirstInvalidByte(pInput, input.Length);
Assert.True((IntPtr)(pInput + input.Length) == (IntPtr)SIMDResult,
"Failure in SIMD function: Utf8Utility.GetPointerToFirstInvalidByte"); // byte* result = SimdUnicode.UTF8.GetPointerToFirstInvalidByte(pInput, input.Length);
// Assert.Equal((IntPtr)(pInput + input.Length), (IntPtr)result); // Expecting the end of the string
}
}
}
Expand Down

0 comments on commit 2080e68

Please sign in to comment.