Skip to content

Commit 2345253

Browse files
avx2
1 parent ccea6e2 commit 2345253

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

source/encoding.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,14 @@ int aws_base64_decode(const struct aws_byte_cursor *AWS_RESTRICT to_decode, stru
418418
return aws_raise_error(AWS_ERROR_SHORT_BUFFER);
419419
}
420420

421-
if (aws_common_private_has_avx2()) {
421+
/*
422+
* Note: avx2 version relies on input being padded to 4 byte boundary.
423+
* Regular base64 is always padded to 4, but for url variant padding is skipped.
424+
* Fall back to software version for inputs that are not divisible by 4 cleanly (aka base64 url),
425+
* as those are a corner case and we dont need them as often.
426+
* Reconsider, writing intrinsic version is usage becomes more widespread.
427+
*/
428+
if ((to_decode->len % 4 == 0) && aws_common_private_has_avx2()) {
422429
size_t result = aws_common_private_base64_decode_sse41(to_decode->ptr, output->buffer, to_decode->len);
423430
if (result == SIZE_MAX) {
424431
return aws_raise_error(AWS_ERROR_INVALID_BASE64_STR);

0 commit comments

Comments
 (0)