|
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! */ |
2 | 2 | /* begin file src/simdutf.cpp */ |
3 | 3 | #include "simdutf.h" |
4 | 4 | // We include base64_tables once. |
@@ -1522,10 +1522,10 @@ template<> |
1522 | 1522 | struct simd16<bool>: base16<bool> { |
1523 | 1523 | static simdutf_really_inline simd16<bool> splat(bool _value) { return vmovq_n_u16(uint16_t(-(!!_value))); } |
1524 | 1524 |
|
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) {} |
1527 | 1527 | // 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)) {} |
1529 | 1529 |
|
1530 | 1530 | }; |
1531 | 1531 |
|
@@ -2832,10 +2832,10 @@ template<> |
2832 | 2832 | struct simd16<bool>: base16<bool> { |
2833 | 2833 | static simdutf_really_inline simd16<bool> splat(bool _value) { return _mm256_set1_epi16(uint16_t(-(!!_value))); } |
2834 | 2834 |
|
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) {} |
2837 | 2837 | // 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)) {} |
2839 | 2839 |
|
2840 | 2840 | simdutf_really_inline bitmask_type to_bitmask() const { return _mm256_movemask_epi8(*this); } |
2841 | 2841 | simdutf_really_inline bool any() const { return !_mm256_testz_si256(*this, *this); } |
@@ -3803,10 +3803,10 @@ template<> |
3803 | 3803 | struct simd16<bool>: base16<bool> { |
3804 | 3804 | static simdutf_really_inline simd16<bool> splat(bool _value) { return _mm_set1_epi16(uint16_t(-(!!_value))); } |
3805 | 3805 |
|
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) {} |
3808 | 3808 | // 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)) {} |
3810 | 3810 |
|
3811 | 3811 | simdutf_really_inline int to_bitmask() const { return _mm_movemask_epi8(*this); } |
3812 | 3812 | 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, |
5807 | 5807 | // Returns the number of bytes written. The destination buffer must be large |
5808 | 5808 | // enough. It will add padding (=) if needed. |
5809 | 5809 | size_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); |
5810 | 5817 | // This looks like 3 branches, but we expect the compiler to resolve this to a single branch: |
5811 | 5818 | const char *e0 = (options & base64_url) ? tables::base64::base64_url::e0 : tables::base64::base64_default::e0; |
5812 | 5819 | 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 |
5830 | 5837 | t1 = uint8_t(src[i]); |
5831 | 5838 | *out++ = e0[t1]; |
5832 | 5839 | *out++ = e1[(t1 & 0x03) << 4]; |
5833 | | - if((options & base64_url) == 0) { |
| 5840 | + if(use_padding) { |
5834 | 5841 | *out++ = '='; |
5835 | 5842 | *out++ = '='; |
5836 | 5843 | } |
@@ -5841,7 +5848,7 @@ size_t tail_encode_base64(char *dst, const char *src, size_t srclen, base64_opti |
5841 | 5848 | *out++ = e0[t1]; |
5842 | 5849 | *out++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)]; |
5843 | 5850 | *out++ = e2[(t2 & 0x0F) << 2]; |
5844 | | - if((options & base64_url) == 0) { |
| 5851 | + if(use_padding) { |
5845 | 5852 | *out++ = '='; |
5846 | 5853 | } |
5847 | 5854 | } |
@@ -5869,7 +5876,14 @@ simdutf_warn_unused size_t maximal_binary_length_from_base64(const char_type * i |
5869 | 5876 | } |
5870 | 5877 |
|
5871 | 5878 | simdutf_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) { |
5873 | 5887 | return length/3 * 4 + ((length % 3) ? (length % 3) + 1 : 0); |
5874 | 5888 | } |
5875 | 5889 | 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, |
17055 | 17069 | // can avoid the call to compress_block and decode directly. |
17056 | 17070 | copy_block(&b, bufferptr); |
17057 | 17071 | bufferptr += 64; |
17058 | | - // base64_decode_block(dst, &b); |
17059 | | - // dst += 48; |
17060 | 17072 | } |
17061 | 17073 | if (bufferptr >= (block_size - 1) * 64 + buffer) { |
17062 | 17074 | for (size_t i = 0; i < (block_size - 1); i++) { |
@@ -27138,8 +27150,8 @@ simdutf_really_inline __m256i lookup_pshufb_improved(const __m256i input) { |
27138 | 27150 | return _mm256_add_epi8(result, input); |
27139 | 27151 | } |
27140 | 27152 |
|
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) { |
27143 | 27155 | // credit: Wojciech Muła |
27144 | 27156 | const uint8_t *input = (const uint8_t *)src; |
27145 | 27157 |
|
@@ -27206,18 +27218,18 @@ size_t encode_base64(char *dst, const char *src, size_t srclen) { |
27206 | 27218 | const __m256i input3 = _mm256_or_si256(t1_3, t3_3); |
27207 | 27219 |
|
27208 | 27220 | _mm256_storeu_si256(reinterpret_cast<__m256i *>(out), |
27209 | | - lookup_pshufb_improved<options == base64_url>(input0)); |
| 27221 | + lookup_pshufb_improved<isbase64url>(input0)); |
27210 | 27222 | out += 32; |
27211 | 27223 |
|
27212 | 27224 | _mm256_storeu_si256(reinterpret_cast<__m256i *>(out), |
27213 | | - lookup_pshufb_improved<options == base64_url>(input1)); |
| 27225 | + lookup_pshufb_improved<isbase64url>(input1)); |
27214 | 27226 | out += 32; |
27215 | 27227 |
|
27216 | 27228 | _mm256_storeu_si256(reinterpret_cast<__m256i *>(out), |
27217 | | - lookup_pshufb_improved<options == base64_url>(input2)); |
| 27229 | + lookup_pshufb_improved<isbase64url>(input2)); |
27218 | 27230 | out += 32; |
27219 | 27231 | _mm256_storeu_si256(reinterpret_cast<__m256i *>(out), |
27220 | | - lookup_pshufb_improved<options == base64_url>(input3)); |
| 27232 | + lookup_pshufb_improved<isbase64url>(input3)); |
27221 | 27233 | out += 32; |
27222 | 27234 | } |
27223 | 27235 | for (; i + 28 <= srclen; i += 24) { |
@@ -27241,7 +27253,7 @@ size_t encode_base64(char *dst, const char *src, size_t srclen) { |
27241 | 27253 | const __m256i indices = _mm256_or_si256(t1, t3); |
27242 | 27254 |
|
27243 | 27255 | _mm256_storeu_si256(reinterpret_cast<__m256i *>(out), |
27244 | | - lookup_pshufb_improved<options == base64_url>(indices)); |
| 27256 | + lookup_pshufb_improved<isbase64url>(indices)); |
27245 | 27257 | out += 32; |
27246 | 27258 | } |
27247 | 27259 | 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 |
30012 | 30024 |
|
30013 | 30025 | size_t implementation::binary_to_base64(const char * input, size_t length, char* output, base64_options options) const noexcept { |
30014 | 30026 | if(options & base64_url) { |
30015 | | - return encode_base64<base64_url>(output, input, length); |
| 30027 | + return encode_base64<true>(output, input, length, options); |
30016 | 30028 | } else { |
30017 | | - return encode_base64<base64_default>(output, input, length); |
| 30029 | + return encode_base64<false>(output, input, length, options); |
30018 | 30030 | } |
30019 | 30031 | } |
30020 | 30032 | } // namespace haswell |
@@ -35675,8 +35687,8 @@ template <bool base64_url> __m128i lookup_pshufb_improved(const __m128i input) { |
35675 | 35687 | return _mm_add_epi8(result, input); |
35676 | 35688 | } |
35677 | 35689 |
|
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) { |
35680 | 35692 | // credit: Wojciech Muła |
35681 | 35693 | // SSE (lookup: pshufb improved unrolled) |
35682 | 35694 | const uint8_t *input = (const uint8_t *)src; |
@@ -35727,19 +35739,19 @@ size_t encode_base64(char *dst, const char *src, size_t srclen) { |
35727 | 35739 | const __m128i input3 = _mm_or_si128(t1_3, t3_3); |
35728 | 35740 |
|
35729 | 35741 | _mm_storeu_si128(reinterpret_cast<__m128i *>(out), |
35730 | | - lookup_pshufb_improved<options & base64_url>(input0)); |
| 35742 | + lookup_pshufb_improved<isbase64url>(input0)); |
35731 | 35743 | out += 16; |
35732 | 35744 |
|
35733 | 35745 | _mm_storeu_si128(reinterpret_cast<__m128i *>(out), |
35734 | | - lookup_pshufb_improved<options & base64_url>(input1)); |
| 35746 | + lookup_pshufb_improved<isbase64url>(input1)); |
35735 | 35747 | out += 16; |
35736 | 35748 |
|
35737 | 35749 | _mm_storeu_si128(reinterpret_cast<__m128i *>(out), |
35738 | | - lookup_pshufb_improved<options & base64_url>(input2)); |
| 35750 | + lookup_pshufb_improved<isbase64url>(input2)); |
35739 | 35751 | out += 16; |
35740 | 35752 |
|
35741 | 35753 | _mm_storeu_si128(reinterpret_cast<__m128i *>(out), |
35742 | | - lookup_pshufb_improved<options & base64_url>(input3)); |
| 35754 | + lookup_pshufb_improved<isbase64url>(input3)); |
35743 | 35755 | out += 16; |
35744 | 35756 | } |
35745 | 35757 | for (; i + 16 <= srclen; i += 12) { |
@@ -35779,7 +35791,7 @@ size_t encode_base64(char *dst, const char *src, size_t srclen) { |
35779 | 35791 | const __m128i indices = _mm_or_si128(t1, t3); |
35780 | 35792 |
|
35781 | 35793 | _mm_storeu_si128(reinterpret_cast<__m128i *>(out), |
35782 | | - lookup_pshufb_improved<options & base64_url>(indices)); |
| 35794 | + lookup_pshufb_improved<isbase64url>(indices)); |
35783 | 35795 | out += 16; |
35784 | 35796 | } |
35785 | 35797 |
|
@@ -38555,10 +38567,10 @@ simdutf_warn_unused size_t implementation::base64_length_from_binary(size_t leng |
38555 | 38567 | } |
38556 | 38568 |
|
38557 | 38569 | size_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); |
38560 | 38572 | } else { |
38561 | | - return encode_base64<base64_default>(output, input, length); |
| 38573 | + return encode_base64<false>(output, input, length, options); |
38562 | 38574 | } |
38563 | 38575 | } |
38564 | 38576 | } // namespace westmere |
|