Skip to content

Commit 6267a48

Browse files
author
ladeak
committed
Addressing byte continuations
1 parent 7618fed commit 6267a48

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/CHttpServer/CHttpServer/Http3/QPackIntegerDecoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private bool TryDecodeSimd(ReadOnlySpan<byte> buffer, ref int currentIndex, out
227227
Debug.Assert(buffer.Length >= 32 + currentIndex);
228228
var vInput = Vector256.LoadUnsafe(in buffer[currentIndex]);
229229
var initialBits = Avx2.MoveMask(vInput);
230-
var byteCount = 32 - Lzcnt.LeadingZeroCount((uint)initialBits);
230+
var byteCount = BitOperations.TrailingZeroCount(~initialBits);
231231
int bCount = (int)byteCount;
232232
if (byteCount > 5 || vInput[bCount] == 0)
233233
ThrowDecodingException();

tests/CHttpServer.Tests/Http3/QPackIntegerDecoderTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ public void Decode1337_Simd()
183183
Assert.Equal(1337, result);
184184
}
185185

186+
[Fact]
187+
public void Decode1337_Simd_WithMoreBytes()
188+
{
189+
byte[] b = [0b00011111, 0b10011010, 0b00001010, 0b10001010, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
190+
QPackIntegerDecoder decoder = new();
191+
decoder.BeginTryDecode(b[0], 5, out _);
192+
var index = 1;
193+
decoder.TryDecodeIntegerSimd(b, ref index, out int result);
194+
Assert.Equal(1337, result);
195+
}
196+
186197
[Fact]
187198
public void Decode167225_Simd()
188199
{

0 commit comments

Comments
 (0)