Skip to content

Commit 3ff8eb7

Browse files
author
Daniel Lemire
committed
adding runtime dispatching
1 parent ee9ee16 commit 3ff8eb7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/UTF8.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static class UTF8
127127
const byte OVERLONG_4 = 1 << 6;
128128
const byte CARRY = TOO_SHORT | TOO_LONG | TWO_CONTS;
129129

130-
public unsafe static byte* GetPointerToFirstInvalidByte(byte* pInputBuffer, int inputLength)
130+
public unsafe static byte* GetPointerToFirstInvalidByteAvx2(byte* pInputBuffer, int inputLength)
131131
{
132132
int processedLength = 0;
133133

@@ -303,7 +303,18 @@ public static class UTF8
303303

304304
return pInputBuffer + inputLength;
305305
}
306-
}
307306

307+
public unsafe static byte* GetPointerToFirstInvalidByte(byte* pInputBuffer, int inputLength)
308+
{
309+
if (Avx2.IsSupported)
310+
{
311+
return GetPointerToFirstInvalidByteAvx2(pInputBuffer, inputLength);
312+
}
313+
else
314+
{
315+
return GetPointerToFirstInvalidByteScalar(pInputBuffer, inputLength);
316+
}
317+
}
308318

319+
}
309320
}

0 commit comments

Comments
 (0)