1- /* auto-generated on 2024-05-07 22:33:11 -0400. Do not edit! */
1+ /* auto-generated on 2024-07-11 00:01:58 -0400. Do not edit! */
22/* begin file src/simdutf.cpp */
33#include "simdutf.h"
44// We include base64_tables once.
@@ -1522,10 +1522,10 @@ template<>
15221522struct simd16<bool>: base16<bool> {
15231523 static simdutf_really_inline simd16<bool> splat(bool _value) { return vmovq_n_u16(uint16_t(-(!!_value))); }
15241524
1525- simdutf_really_inline simd16<bool> () : base16() {}
1526- simdutf_really_inline simd16<bool> (const uint16x8_t _value) : base16<bool>(_value) {}
1525+ simdutf_really_inline simd16() : base16() {}
1526+ simdutf_really_inline simd16(const uint16x8_t _value) : base16<bool>(_value) {}
15271527 // Splat constructor
1528- simdutf_really_inline simd16<bool> (bool _value) : base16<bool>(splat(_value)) {}
1528+ simdutf_really_inline simd16(bool _value) : base16<bool>(splat(_value)) {}
15291529
15301530};
15311531
@@ -2832,10 +2832,10 @@ template<>
28322832struct simd16<bool>: base16<bool> {
28332833 static simdutf_really_inline simd16<bool> splat(bool _value) { return _mm256_set1_epi16(uint16_t(-(!!_value))); }
28342834
2835- simdutf_really_inline simd16<bool> () : base16() {}
2836- simdutf_really_inline simd16<bool> (const __m256i _value) : base16<bool>(_value) {}
2835+ simdutf_really_inline simd16() : base16() {}
2836+ simdutf_really_inline simd16(const __m256i _value) : base16<bool>(_value) {}
28372837 // Splat constructor
2838- simdutf_really_inline simd16<bool> (bool _value) : base16<bool>(splat(_value)) {}
2838+ simdutf_really_inline simd16(bool _value) : base16<bool>(splat(_value)) {}
28392839
28402840 simdutf_really_inline bitmask_type to_bitmask() const { return _mm256_movemask_epi8(*this); }
28412841 simdutf_really_inline bool any() const { return !_mm256_testz_si256(*this, *this); }
@@ -3803,10 +3803,10 @@ template<>
38033803struct simd16<bool>: base16<bool> {
38043804 static simdutf_really_inline simd16<bool> splat(bool _value) { return _mm_set1_epi16(uint16_t(-(!!_value))); }
38053805
3806- simdutf_really_inline simd16<bool> () : base16() {}
3807- simdutf_really_inline simd16<bool> (const __m128i _value) : base16<bool>(_value) {}
3806+ simdutf_really_inline simd16() : base16() {}
3807+ simdutf_really_inline simd16(const __m128i _value) : base16<bool>(_value) {}
38083808 // Splat constructor
3809- simdutf_really_inline simd16<bool> (bool _value) : base16<bool>(splat(_value)) {}
3809+ simdutf_really_inline simd16(bool _value) : base16<bool>(splat(_value)) {}
38103810
38113811 simdutf_really_inline int to_bitmask() const { return _mm_movemask_epi8(*this); }
38123812 simdutf_really_inline bool any() const { return !_mm_testz_si128(*this, *this); }
@@ -5807,6 +5807,13 @@ result base64_tail_decode_safe(char *dst, size_t& outlen, const char_type *src,
58075807// Returns the number of bytes written. The destination buffer must be large
58085808// enough. It will add padding (=) if needed.
58095809size_t tail_encode_base64(char *dst, const char *src, size_t srclen, base64_options options) {
5810+ // By default, we use padding if we are not using the URL variant.
5811+ // This is check with ((options & base64_url) == 0) which returns true if we are not using the URL variant.
5812+ // However, we also allow 'inversion' of the convention with the base64_reverse_padding option.
5813+ // If the base64_reverse_padding option is set, we use padding if we are using the URL variant,
5814+ // and we omit it if we are not using the URL variant. This is checked with
5815+ // ((options & base64_reverse_padding) == base64_reverse_padding).
5816+ bool use_padding = ((options & base64_url) == 0) ^ ((options & base64_reverse_padding) == base64_reverse_padding);
58105817 // This looks like 3 branches, but we expect the compiler to resolve this to a single branch:
58115818 const char *e0 = (options & base64_url) ? tables::base64::base64_url::e0 : tables::base64::base64_default::e0;
58125819 const char *e1 = (options & base64_url) ? tables::base64::base64_url::e1 : tables::base64::base64_default::e1;
@@ -5830,7 +5837,7 @@ size_t tail_encode_base64(char *dst, const char *src, size_t srclen, base64_opti
58305837 t1 = uint8_t(src[i]);
58315838 *out++ = e0[t1];
58325839 *out++ = e1[(t1 & 0x03) << 4];
5833- if((options & base64_url) == 0 ) {
5840+ if(use_padding ) {
58345841 *out++ = '=';
58355842 *out++ = '=';
58365843 }
@@ -5841,7 +5848,7 @@ size_t tail_encode_base64(char *dst, const char *src, size_t srclen, base64_opti
58415848 *out++ = e0[t1];
58425849 *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
58435850 *out++ = e2[(t2 & 0x0F) << 2];
5844- if((options & base64_url) == 0 ) {
5851+ if(use_padding ) {
58455852 *out++ = '=';
58465853 }
58475854 }
@@ -5869,7 +5876,14 @@ simdutf_warn_unused size_t maximal_binary_length_from_base64(const char_type * i
58695876}
58705877
58715878simdutf_warn_unused size_t base64_length_from_binary(size_t length, base64_options options) noexcept {
5872- if(options & base64_url) {
5879+ // By default, we use padding if we are not using the URL variant.
5880+ // This is check with ((options & base64_url) == 0) which returns true if we are not using the URL variant.
5881+ // However, we also allow 'inversion' of the convention with the base64_reverse_padding option.
5882+ // If the base64_reverse_padding option is set, we use padding if we are using the URL variant,
5883+ // and we omit it if we are not using the URL variant. This is checked with
5884+ // ((options & base64_reverse_padding) == base64_reverse_padding).
5885+ bool use_padding = ((options & base64_url) == 0) ^ ((options & base64_reverse_padding) == base64_reverse_padding);
5886+ if(!use_padding) {
58735887 return length/3 * 4 + ((length % 3) ? (length % 3) + 1 : 0);
58745888 }
58755889 return (length + 2)/3 * 4; // We use padding to make the length a multiple of 4.
@@ -17055,8 +17069,6 @@ result compress_decode_base64(char *dst, const char_type *src, size_t srclen,
1705517069 // can avoid the call to compress_block and decode directly.
1705617070 copy_block(&b, bufferptr);
1705717071 bufferptr += 64;
17058- // base64_decode_block(dst, &b);
17059- // dst += 48;
1706017072 }
1706117073 if (bufferptr >= (block_size - 1) * 64 + buffer) {
1706217074 for (size_t i = 0; i < (block_size - 1); i++) {
@@ -27138,8 +27150,8 @@ simdutf_really_inline __m256i lookup_pshufb_improved(const __m256i input) {
2713827150 return _mm256_add_epi8(result, input);
2713927151}
2714027152
27141- template <base64_options options >
27142- size_t encode_base64(char *dst, const char *src, size_t srclen) {
27153+ template <bool isbase64url >
27154+ size_t encode_base64(char *dst, const char *src, size_t srclen, base64_options options ) {
2714327155 // credit: Wojciech Muła
2714427156 const uint8_t *input = (const uint8_t *)src;
2714527157
@@ -27206,18 +27218,18 @@ size_t encode_base64(char *dst, const char *src, size_t srclen) {
2720627218 const __m256i input3 = _mm256_or_si256(t1_3, t3_3);
2720727219
2720827220 _mm256_storeu_si256(reinterpret_cast<__m256i *>(out),
27209- lookup_pshufb_improved<options == base64_url >(input0));
27221+ lookup_pshufb_improved<isbase64url >(input0));
2721027222 out += 32;
2721127223
2721227224 _mm256_storeu_si256(reinterpret_cast<__m256i *>(out),
27213- lookup_pshufb_improved<options == base64_url >(input1));
27225+ lookup_pshufb_improved<isbase64url >(input1));
2721427226 out += 32;
2721527227
2721627228 _mm256_storeu_si256(reinterpret_cast<__m256i *>(out),
27217- lookup_pshufb_improved<options == base64_url >(input2));
27229+ lookup_pshufb_improved<isbase64url >(input2));
2721827230 out += 32;
2721927231 _mm256_storeu_si256(reinterpret_cast<__m256i *>(out),
27220- lookup_pshufb_improved<options == base64_url >(input3));
27232+ lookup_pshufb_improved<isbase64url >(input3));
2722127233 out += 32;
2722227234 }
2722327235 for (; i + 28 <= srclen; i += 24) {
@@ -27241,7 +27253,7 @@ size_t encode_base64(char *dst, const char *src, size_t srclen) {
2724127253 const __m256i indices = _mm256_or_si256(t1, t3);
2724227254
2724327255 _mm256_storeu_si256(reinterpret_cast<__m256i *>(out),
27244- lookup_pshufb_improved<options == base64_url >(indices));
27256+ lookup_pshufb_improved<isbase64url >(indices));
2724527257 out += 32;
2724627258 }
2724727259 return i / 3 * 4 + scalar::base64::tail_encode_base64((char *)out, src + i,
@@ -30012,9 +30024,9 @@ simdutf_warn_unused size_t implementation::base64_length_from_binary(size_t leng
3001230024
3001330025size_t implementation::binary_to_base64(const char * input, size_t length, char* output, base64_options options) const noexcept {
3001430026 if(options & base64_url) {
30015- return encode_base64<base64_url >(output, input, length);
30027+ return encode_base64<true >(output, input, length, options );
3001630028 } else {
30017- return encode_base64<base64_default >(output, input, length);
30029+ return encode_base64<false >(output, input, length, options );
3001830030 }
3001930031}
3002030032} // namespace haswell
@@ -35675,8 +35687,8 @@ template <bool base64_url> __m128i lookup_pshufb_improved(const __m128i input) {
3567535687 return _mm_add_epi8(result, input);
3567635688}
3567735689
35678- template <base64_options options >
35679- size_t encode_base64(char *dst, const char *src, size_t srclen) {
35690+ template <bool isbase64url >
35691+ size_t encode_base64(char *dst, const char *src, size_t srclen, base64_options options ) {
3568035692 // credit: Wojciech Muła
3568135693 // SSE (lookup: pshufb improved unrolled)
3568235694 const uint8_t *input = (const uint8_t *)src;
@@ -35727,19 +35739,19 @@ size_t encode_base64(char *dst, const char *src, size_t srclen) {
3572735739 const __m128i input3 = _mm_or_si128(t1_3, t3_3);
3572835740
3572935741 _mm_storeu_si128(reinterpret_cast<__m128i *>(out),
35730- lookup_pshufb_improved<options & base64_url >(input0));
35742+ lookup_pshufb_improved<isbase64url >(input0));
3573135743 out += 16;
3573235744
3573335745 _mm_storeu_si128(reinterpret_cast<__m128i *>(out),
35734- lookup_pshufb_improved<options & base64_url >(input1));
35746+ lookup_pshufb_improved<isbase64url >(input1));
3573535747 out += 16;
3573635748
3573735749 _mm_storeu_si128(reinterpret_cast<__m128i *>(out),
35738- lookup_pshufb_improved<options & base64_url >(input2));
35750+ lookup_pshufb_improved<isbase64url >(input2));
3573935751 out += 16;
3574035752
3574135753 _mm_storeu_si128(reinterpret_cast<__m128i *>(out),
35742- lookup_pshufb_improved<options & base64_url >(input3));
35754+ lookup_pshufb_improved<isbase64url >(input3));
3574335755 out += 16;
3574435756 }
3574535757 for (; i + 16 <= srclen; i += 12) {
@@ -35779,7 +35791,7 @@ size_t encode_base64(char *dst, const char *src, size_t srclen) {
3577935791 const __m128i indices = _mm_or_si128(t1, t3);
3578035792
3578135793 _mm_storeu_si128(reinterpret_cast<__m128i *>(out),
35782- lookup_pshufb_improved<options & base64_url >(indices));
35794+ lookup_pshufb_improved<isbase64url >(indices));
3578335795 out += 16;
3578435796 }
3578535797
@@ -38555,10 +38567,10 @@ simdutf_warn_unused size_t implementation::base64_length_from_binary(size_t leng
3855538567}
3855638568
3855738569size_t implementation::binary_to_base64(const char * input, size_t length, char* output, base64_options options) const noexcept {
38558- if(options == base64_url) {
38559- return encode_base64<base64_url >(output, input, length);
38570+ if(options & base64_url) {
38571+ return encode_base64<true >(output, input, length, options );
3856038572 } else {
38561- return encode_base64<base64_default >(output, input, length);
38573+ return encode_base64<false >(output, input, length, options );
3856238574 }
3856338575}
3856438576} // namespace westmere
0 commit comments