mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-17 16:32:11 +01:00
Compare commits
60
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
786fc74b92 | ||
|
|
a86fd7fa79 | ||
|
|
341dd50800 | ||
|
|
a83b5cabaf | ||
|
|
8a4f61501b | ||
|
|
592bc14ed1 | ||
|
|
f73f95b698 | ||
|
|
28a54baa19 | ||
|
|
b60a2cacd9 | ||
|
|
f7b1b87c70 | ||
|
|
13f2e44aca | ||
|
|
128d0386bd | ||
|
|
1b9a6cb85b | ||
|
|
77f855206d | ||
|
|
40ffa334ee | ||
|
|
e88e28259e | ||
|
|
6a30c1ede0 | ||
|
|
9c07523a84 | ||
|
|
816475b285 | ||
|
|
d0451190ca | ||
|
|
3842c519c9 | ||
|
|
ea50956b5a | ||
|
|
fd90553a8f | ||
|
|
963a574f7d | ||
|
|
edd87f0eda | ||
|
|
56d5aa0907 | ||
|
|
6bfaf0f008 | ||
|
|
b9a10d051a | ||
|
|
7f93a94e7a | ||
|
|
a0698fc1a2 | ||
|
|
d8796aa6d9 | ||
|
|
a12771373e | ||
|
|
c90cc7b657 | ||
|
|
b2b8961126 | ||
|
|
f6945c0612 | ||
|
|
76e6872498 | ||
|
|
98c66ef761 | ||
|
|
91857f4c4b | ||
|
|
08797bc713 | ||
|
|
ec32eb3eb7 | ||
|
|
a51867dc63 | ||
|
|
3358730f6f | ||
|
|
97f5bec0e3 | ||
|
|
b0826d2ab7 | ||
|
|
a0984dcdd3 | ||
|
|
b8f87debe3 | ||
|
|
e77d73e3ce | ||
|
|
0a6cce5e0e | ||
|
|
abd37fa3f8 | ||
|
|
baec831fc8 | ||
|
|
8ccaf81e96 | ||
|
|
be546c3587 | ||
|
|
5764f77913 | ||
|
|
2dddd388bc | ||
|
|
1dd7ad4413 | ||
|
|
a7ef82f7db | ||
|
|
9b228fab2a | ||
|
|
96f097c51f | ||
|
|
08f7e3dba4 | ||
|
|
ab5f974b66 |
No files matched your search
@@ -39,3 +39,4 @@ Leo Neat <lneat@google.com>
|
||||
Mike Kaufman <mkaufman@microsoft.com>
|
||||
Muhammad Aldo Firmansyah <TheCrott@users.noreply.github.com>
|
||||
Nigel Tao <nigeltao@golang.org>
|
||||
Peter Kasting <pkasting@chromium.org>
|
||||
+9
-3
@@ -29,17 +29,23 @@ mkdir -p gen/bin
|
||||
|
||||
sources=$@
|
||||
if [ $# -eq 0 ]; then
|
||||
sources=fuzz/c/std/*_fuzzer.c
|
||||
sources=fuzz/c/std/*_fuzzer.c*
|
||||
fi
|
||||
|
||||
for f in $sources; do
|
||||
f=${f%_fuzzer.c}
|
||||
f=${f%_fuzzer.cc}
|
||||
f=${f%/}
|
||||
f=${f##*/}
|
||||
if [ -z $f ]; then
|
||||
continue
|
||||
fi
|
||||
echo "Building gen/bin/fuzz-$f"
|
||||
|
||||
$CC -DWUFFS_CONFIG__FUZZLIB_MAIN fuzz/c/std/${f}_fuzzer.c -o gen/bin/fuzz-$f
|
||||
if [ -e fuzz/c/std/${f}_fuzzer.c ]; then
|
||||
echo "Building (C) gen/bin/fuzz-$f"
|
||||
$CC -DWUFFS_CONFIG__FUZZLIB_MAIN fuzz/c/std/${f}_fuzzer.c -o gen/bin/fuzz-$f
|
||||
elif [ -e fuzz/c/std/${f}_fuzzer.cc ]; then
|
||||
echo "Building (C++) gen/bin/fuzz-$f"
|
||||
$CXX -DWUFFS_CONFIG__FUZZLIB_MAIN fuzz/c/std/${f}_fuzzer.cc -o gen/bin/fuzz-$f
|
||||
fi
|
||||
done
|
||||
@@ -167,8 +167,12 @@ const grSingleFileGuidance = `
|
||||
const grPragmaPush = `
|
||||
// Wuffs' C code is generated automatically, not hand-written. These warnings'
|
||||
// costs outweigh the benefits.
|
||||
//
|
||||
// The "elif defined(__clang__)" isn't redundant. While vanilla clang defines
|
||||
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#pragma GCC diagnostic ignored "-Wunreachable-code"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
@@ -176,6 +180,16 @@ const grPragmaPush = `
|
||||
#if defined(__cplusplus)
|
||||
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||
#endif
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
||||
#pragma clang diagnostic ignored "-Wunreachable-code"
|
||||
#pragma clang diagnostic ignored "-Wunused-function"
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
#if defined(__cplusplus)
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
`
|
||||
@@ -183,6 +197,8 @@ const grPragmaPush = `
|
||||
const grPragmaPop = `
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
`
|
||||
|
||||
@@ -27,7 +27,7 @@ if x < 5 {
|
||||
|
||||
} else {
|
||||
x = 1
|
||||
// At this point, "x == 1" is a fact, but "x < 5" is not.
|
||||
// At this point, "x == 1" is a fact, but "x < 5" is not.
|
||||
|
||||
// This assertion creates the "x < 5" fact.
|
||||
assert x < 5
|
||||
|
||||
@@ -190,5 +190,5 @@ on its title, but primarily concerns lossy compression of volumetric data.
|
||||
|
||||
Robert and Nadarajan's ["New Algorithms For Random Access Text
|
||||
Compression"](https://www.researchgate.net/publication/4231766_New_Algorithms_For_Random_Access_Text_Compression)
|
||||
cannot compress aribrary data, only 7-bit ASCII. The largest document they
|
||||
cannot compress arbitrary data, only 7-bit ASCII. The largest document they
|
||||
consider is also only 17 KiB in size.
|
||||
@@ -747,7 +747,7 @@ main1(int argc, char** argv) {
|
||||
if (g_flags.remaining_argc > 1) {
|
||||
return g_usage;
|
||||
} else if (g_flags.remaining_argc == 1) {
|
||||
in = fopen(g_flags.remaining_argv[0], "r");
|
||||
in = fopen(g_flags.remaining_argv[0], "rb");
|
||||
if (!in) {
|
||||
return std::string("main: cannot read input file");
|
||||
}
|
||||
@@ -767,7 +767,7 @@ compute_exit_code(std::string status_msg) {
|
||||
}
|
||||
fputs(status_msg.c_str(), stderr);
|
||||
fputc('\n', stderr);
|
||||
// Return an exit code of 1 for regular (forseen) errors, e.g. badly
|
||||
// Return an exit code of 1 for regular (foreseen) errors, e.g. badly
|
||||
// formatted or unsupported input.
|
||||
//
|
||||
// Return an exit code of 2 for internal (exceptional) errors, e.g. defensive
|
||||
|
||||
@@ -605,7 +605,7 @@ compute_exit_code(const char* status_msg) {
|
||||
}
|
||||
ignore_return_value(write(STDERR_FD, status_msg, n));
|
||||
ignore_return_value(write(STDERR_FD, "\n", 1));
|
||||
// Return an exit code of 1 for regular (forseen) errors, e.g. badly
|
||||
// Return an exit code of 1 for regular (foreseen) errors, e.g. badly
|
||||
// formatted or unsupported input.
|
||||
//
|
||||
// Return an exit code of 2 for internal (exceptional) errors, e.g. defensive
|
||||
|
||||
@@ -94,7 +94,7 @@ load_image(const char* filename) {
|
||||
FILE* file = stdin;
|
||||
const char* adj_filename = "<stdin>";
|
||||
if (filename) {
|
||||
FILE* f = fopen(filename, "r");
|
||||
FILE* f = fopen(filename, "rb");
|
||||
if (f == NULL) {
|
||||
printf("%s: could not open file\n", filename);
|
||||
return false;
|
||||
|
||||
@@ -339,7 +339,7 @@ main1(int argc, char** argv) {
|
||||
if (g_flags.remaining_argc > 1) {
|
||||
return g_usage;
|
||||
} else if (g_flags.remaining_argc == 1) {
|
||||
in = fopen(g_flags.remaining_argv[0], "r");
|
||||
in = fopen(g_flags.remaining_argv[0], "rb");
|
||||
if (!in) {
|
||||
return std::string("main: cannot read input file");
|
||||
}
|
||||
@@ -362,7 +362,7 @@ compute_exit_code(std::string status_msg) {
|
||||
}
|
||||
fputs(status_msg.c_str(), stderr);
|
||||
fputc('\n', stderr);
|
||||
// Return an exit code of 1 for regular (forseen) errors, e.g. badly
|
||||
// Return an exit code of 1 for regular (foreseen) errors, e.g. badly
|
||||
// formatted or unsupported input.
|
||||
//
|
||||
// Return an exit code of 2 for internal (exceptional) errors, e.g. defensive
|
||||
|
||||
@@ -548,7 +548,7 @@ main1(int argc, char** argv) {
|
||||
if (g_flags.remaining_argc > 1) {
|
||||
return g_usage;
|
||||
} else if (g_flags.remaining_argc == 1) {
|
||||
in = fopen(g_flags.remaining_argv[0], "r");
|
||||
in = fopen(g_flags.remaining_argv[0], "rb");
|
||||
if (!in) {
|
||||
return std::string("main: cannot read input file");
|
||||
}
|
||||
@@ -571,7 +571,7 @@ compute_exit_code(std::string status_msg) {
|
||||
return 0;
|
||||
}
|
||||
std::cerr << status_msg << '\n';
|
||||
// Return an exit code of 1 for regular (forseen) errors, e.g. badly
|
||||
// Return an exit code of 1 for regular (foreseen) errors, e.g. badly
|
||||
// formatted or unsupported input.
|
||||
//
|
||||
// Return an exit code of 2 for internal (exceptional) errors, e.g. defensive
|
||||
|
||||
+14
-32
@@ -1074,7 +1074,7 @@ write_dst(const void* s, size_t n) {
|
||||
return write_dst_slow(s, n);
|
||||
}
|
||||
|
||||
#define TRY_INDENT_WITH_LEADING_NEW_LINE \
|
||||
#define TRY_INDENT \
|
||||
do { \
|
||||
uint32_t adj = (g_num_input_blank_lines > 1) ? 1 : 0; \
|
||||
g_num_input_blank_lines = 0; \
|
||||
@@ -1086,20 +1086,6 @@ write_dst(const void* s, size_t n) {
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
// TRY_INDENT_SANS_LEADING_NEW_LINE is used after comments, which print their
|
||||
// own "\n".
|
||||
#define TRY_INDENT_SANS_LEADING_NEW_LINE \
|
||||
do { \
|
||||
uint32_t adj = (g_num_input_blank_lines > 1) ? 1 : 0; \
|
||||
g_num_input_blank_lines = 0; \
|
||||
uint32_t indent = g_depth * g_bytes_per_indent_depth; \
|
||||
TRY(write_dst(g_two_new_lines_then_256_indent_bytes + 2 - adj, \
|
||||
adj + (indent & 0xFF))); \
|
||||
for (indent >>= 8; indent > 0; indent--) { \
|
||||
TRY(write_dst(g_two_new_lines_then_256_indent_bytes + 2, 0x100)); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
// ----
|
||||
|
||||
const char* //
|
||||
@@ -1155,12 +1141,12 @@ handle_token(wuffs_base__token t, bool start_of_token_chain) {
|
||||
(g_ctx != context::in_dict_after_brace) &&
|
||||
!g_flags.compact_output) {
|
||||
if (g_is_after_comment) {
|
||||
TRY_INDENT_SANS_LEADING_NEW_LINE;
|
||||
TRY_INDENT;
|
||||
} else {
|
||||
if (g_flags.output_extra_comma) {
|
||||
TRY(write_dst(",", 1));
|
||||
}
|
||||
TRY_INDENT_WITH_LEADING_NEW_LINE;
|
||||
TRY_INDENT;
|
||||
}
|
||||
} else {
|
||||
g_num_input_blank_lines = 0;
|
||||
@@ -1181,7 +1167,7 @@ handle_token(wuffs_base__token t, bool start_of_token_chain) {
|
||||
// continuation of a multi-token chain.
|
||||
if (start_of_token_chain) {
|
||||
if (g_is_after_comment) {
|
||||
TRY_INDENT_SANS_LEADING_NEW_LINE;
|
||||
TRY_INDENT;
|
||||
} else if (g_ctx == context::in_dict_after_key) {
|
||||
TRY(write_dst(": ", g_flags.compact_output ? 1 : 2));
|
||||
} else if (g_ctx != context::none) {
|
||||
@@ -1190,7 +1176,7 @@ handle_token(wuffs_base__token t, bool start_of_token_chain) {
|
||||
TRY(write_dst(",", 1));
|
||||
}
|
||||
if (!g_flags.compact_output) {
|
||||
TRY_INDENT_WITH_LEADING_NEW_LINE;
|
||||
TRY_INDENT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1336,11 +1322,16 @@ main1(int argc, char** argv) {
|
||||
if (g_flags.compact_output) {
|
||||
TRY(write_dst(g_src.data.ptr + g_cursor_index - token_length,
|
||||
token_length));
|
||||
if (!t.continued() &&
|
||||
(t.value_base_detail() &
|
||||
WUFFS_BASE__TOKEN__VBD__FILLER__COMMENT_LINE)) {
|
||||
TRY(write_dst("\n", 1));
|
||||
}
|
||||
|
||||
} else {
|
||||
if (start_of_token_chain) {
|
||||
if (g_is_after_comment) {
|
||||
TRY_INDENT_SANS_LEADING_NEW_LINE;
|
||||
TRY_INDENT;
|
||||
} else if (g_ctx != context::none) {
|
||||
if (g_ctx == context::in_dict_after_key) {
|
||||
TRY(write_dst(":", 1));
|
||||
@@ -1349,16 +1340,11 @@ main1(int argc, char** argv) {
|
||||
(g_ctx != context::end_of_data)) {
|
||||
TRY(write_dst(",", 1));
|
||||
}
|
||||
TRY_INDENT_WITH_LEADING_NEW_LINE;
|
||||
TRY_INDENT;
|
||||
}
|
||||
}
|
||||
TRY(write_dst(g_src.data.ptr + g_cursor_index - token_length,
|
||||
token_length));
|
||||
if (!t.continued() &&
|
||||
(t.value_base_detail() &
|
||||
WUFFS_BASE__TOKEN__VBD__FILLER__COMMENT_BLOCK)) {
|
||||
TRY(write_dst("\n", 1));
|
||||
}
|
||||
g_is_after_comment = true;
|
||||
}
|
||||
if (g_ctx == context::in_list_after_bracket) {
|
||||
@@ -1366,11 +1352,7 @@ main1(int argc, char** argv) {
|
||||
} else if (g_ctx == context::in_dict_after_brace) {
|
||||
g_ctx = context::in_dict_after_value;
|
||||
}
|
||||
g_num_input_blank_lines =
|
||||
(t.value_base_detail() &
|
||||
WUFFS_BASE__TOKEN__VBD__FILLER__COMMENT_LINE)
|
||||
? 1
|
||||
: 0;
|
||||
g_num_input_blank_lines = 0;
|
||||
|
||||
} else {
|
||||
uint8_t* p = g_src.data.ptr + g_cursor_index - token_length;
|
||||
@@ -1446,7 +1428,7 @@ compute_exit_code(const char* status_msg) {
|
||||
const int stderr_fd = 2;
|
||||
ignore_return_value(write(stderr_fd, status_msg, n));
|
||||
ignore_return_value(write(stderr_fd, "\n", 1));
|
||||
// Return an exit code of 1 for regular (forseen) errors, e.g. badly
|
||||
// Return an exit code of 1 for regular (foreseen) errors, e.g. badly
|
||||
// formatted or unsupported input.
|
||||
//
|
||||
// Return an exit code of 2 for internal (exceptional) errors, e.g. defensive
|
||||
|
||||
+1
-1
@@ -224,7 +224,7 @@ compute_exit_code(const char* status_msg) {
|
||||
const int stderr_fd = 2;
|
||||
ignore_return_value(write(stderr_fd, status_msg, n));
|
||||
ignore_return_value(write(stderr_fd, "\n", 1));
|
||||
// Return an exit code of 1 for regular (forseen) errors, e.g. badly
|
||||
// Return an exit code of 1 for regular (foreseen) errors, e.g. badly
|
||||
// formatted or unsupported input.
|
||||
//
|
||||
// Return an exit code of 2 for internal (exceptional) errors, e.g. defensive
|
||||
|
||||
@@ -66,7 +66,7 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
wuffs_base__status status = wuffs_bmp__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
(hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0);
|
||||
hash >>= 1;
|
||||
hash = wuffs_base__u64__rotate_right(hash, 1);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
|
||||
+15
-13
@@ -221,12 +221,13 @@ fuzz_one_token(wuffs_base__token t,
|
||||
}
|
||||
|
||||
uint64_t //
|
||||
buffer_limit(uint64_t hash_6_bits, uint64_t min, uint64_t max) {
|
||||
buffer_limit(uint64_t hash, uint64_t min, uint64_t max) {
|
||||
hash &= 0x3F;
|
||||
uint64_t n;
|
||||
if (hash_6_bits < 0x20) {
|
||||
n = min + hash_6_bits;
|
||||
if (hash < 0x20) {
|
||||
n = min + hash;
|
||||
} else {
|
||||
n = max - (0x3F - hash_6_bits);
|
||||
n = max - (0x3F - hash);
|
||||
}
|
||||
if (n < min) {
|
||||
return min;
|
||||
@@ -237,15 +238,15 @@ buffer_limit(uint64_t hash_6_bits, uint64_t min, uint64_t max) {
|
||||
}
|
||||
|
||||
const char* //
|
||||
fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash_56_bits) {
|
||||
fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash) {
|
||||
uint64_t tok_limit = buffer_limit(
|
||||
hash_56_bits & 0x3F, WUFFS_CBOR__DECODER_DST_TOKEN_BUFFER_LENGTH_MIN_INCL,
|
||||
hash & 0x3F, WUFFS_CBOR__DECODER_DST_TOKEN_BUFFER_LENGTH_MIN_INCL,
|
||||
TOK_BUFFER_ARRAY_SIZE);
|
||||
uint64_t hash_50_bits = hash_56_bits >> 6;
|
||||
hash = wuffs_base__u64__rotate_right(hash, 6);
|
||||
|
||||
uint64_t src_limit =
|
||||
buffer_limit(hash_50_bits & 0x3F,
|
||||
WUFFS_CBOR__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL, 4096);
|
||||
uint64_t src_limit = buffer_limit(
|
||||
hash & 0x3F, WUFFS_CBOR__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL, 4096);
|
||||
hash = wuffs_base__u64__rotate_right(hash, 6);
|
||||
|
||||
// ----
|
||||
|
||||
@@ -261,8 +262,9 @@ fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash_56_bits) {
|
||||
wuffs_base__token_buffer tok = ((wuffs_base__token_buffer){
|
||||
.data = ((wuffs_base__slice_token){
|
||||
.ptr = tok_array,
|
||||
.len = (tok_limit < TOK_BUFFER_ARRAY_SIZE) ? tok_limit
|
||||
: TOK_BUFFER_ARRAY_SIZE,
|
||||
.len = (size_t)((tok_limit < TOK_BUFFER_ARRAY_SIZE)
|
||||
? tok_limit
|
||||
: TOK_BUFFER_ARRAY_SIZE),
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -407,7 +409,7 @@ fuzz(wuffs_base__io_buffer* full_src, uint64_t hash) {
|
||||
// The fuzz_complex implementation adds many more Wuffs API specific checks
|
||||
// (e.g. that the sum of the tokens' lengths do not exceed the input length).
|
||||
if ((hash & 0xFF) != 0xA5) {
|
||||
return fuzz_complex(full_src, hash >> 8);
|
||||
return fuzz_complex(full_src, wuffs_base__u64__rotate_right(hash, 8));
|
||||
}
|
||||
return fuzz_simple(full_src);
|
||||
}
|
||||
+26
-2
@@ -61,17 +61,41 @@ It should print "PASS", amongst other information, and exit(0).
|
||||
#include "../fuzzlib/fuzzlib.c"
|
||||
#include "../fuzzlib/fuzzlib_image_decoder.c"
|
||||
|
||||
void set_quirks(wuffs_gif__decoder* dec, uint64_t hash) {
|
||||
uint32_t quirks[] = {
|
||||
WUFFS_GIF__QUIRK_DELAY_NUM_DECODED_FRAMES,
|
||||
WUFFS_GIF__QUIRK_FIRST_FRAME_LOCAL_PALETTE_MEANS_BLACK_BACKGROUND,
|
||||
WUFFS_GIF__QUIRK_HONOR_BACKGROUND_COLOR,
|
||||
WUFFS_GIF__QUIRK_IGNORE_TOO_MUCH_PIXEL_DATA,
|
||||
WUFFS_GIF__QUIRK_IMAGE_BOUNDS_ARE_STRICT,
|
||||
WUFFS_GIF__QUIRK_REJECT_EMPTY_FRAME,
|
||||
WUFFS_GIF__QUIRK_REJECT_EMPTY_PALETTE,
|
||||
0,
|
||||
};
|
||||
|
||||
uint32_t i;
|
||||
for (i = 0; quirks[i]; i++) {
|
||||
uint64_t bit = 1 << (i & 63);
|
||||
if (hash & bit) {
|
||||
wuffs_gif__decoder__set_quirk_enabled(dec, quirks[i], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char* //
|
||||
fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
wuffs_gif__decoder dec;
|
||||
wuffs_base__status status = wuffs_gif__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
(hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0);
|
||||
hash >>= 1;
|
||||
hash = wuffs_base__u64__rotate_right(hash, 1);
|
||||
uint64_t hash_8_bits = hash & 0xFF;
|
||||
hash = wuffs_base__u64__rotate_right(hash, 8);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
set_quirks(&dec, hash);
|
||||
return fuzz_image_decoder(
|
||||
src, hash,
|
||||
src, hash_8_bits,
|
||||
wuffs_gif__decoder__upcast_as__wuffs_base__image_decoder(&dec));
|
||||
}
|
||||
@@ -50,6 +50,8 @@ It should print "PASS", amongst other information, and exit(0).
|
||||
// modules we use makes that process explicit. Preprocessing means that such
|
||||
// code simply isn't compiled.
|
||||
#define WUFFS_CONFIG__MODULES
|
||||
#define WUFFS_CONFIG__MODULE__AUX__BASE
|
||||
#define WUFFS_CONFIG__MODULE__AUX__JSON
|
||||
#define WUFFS_CONFIG__MODULE__BASE
|
||||
#define WUFFS_CONFIG__MODULE__JSON
|
||||
|
||||
@@ -209,12 +211,13 @@ fuzz_one_token(wuffs_base__token t,
|
||||
}
|
||||
|
||||
uint64_t //
|
||||
buffer_limit(uint64_t hash_6_bits, uint64_t min, uint64_t max) {
|
||||
buffer_limit(uint64_t hash, uint64_t min, uint64_t max) {
|
||||
hash &= 0x3F;
|
||||
uint64_t n;
|
||||
if (hash_6_bits < 0x20) {
|
||||
n = min + hash_6_bits;
|
||||
if (hash < 0x20) {
|
||||
n = min + hash;
|
||||
} else {
|
||||
n = max - (0x3F - hash_6_bits);
|
||||
n = max - (0x3F - hash);
|
||||
}
|
||||
if (n < min) {
|
||||
return min;
|
||||
@@ -224,47 +227,47 @@ buffer_limit(uint64_t hash_6_bits, uint64_t min, uint64_t max) {
|
||||
return n;
|
||||
}
|
||||
|
||||
void set_quirks(wuffs_json__decoder* dec, uint64_t hash_44_bits) {
|
||||
uint32_t quirks[] = {
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_A,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_CAPITAL_U,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_E,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_QUESTION_MARK,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_SINGLE_QUOTE,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_V,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_ZERO,
|
||||
WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK,
|
||||
WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE,
|
||||
WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA,
|
||||
WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS,
|
||||
WUFFS_JSON__QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR,
|
||||
WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK,
|
||||
WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER,
|
||||
WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE,
|
||||
0,
|
||||
};
|
||||
uint32_t g_quirks[] = {
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_A,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_CAPITAL_U,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_E,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_QUESTION_MARK,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_SINGLE_QUOTE,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_V,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_X_AS_CODE_POINTS,
|
||||
WUFFS_JSON__QUIRK_ALLOW_BACKSLASH_ZERO,
|
||||
WUFFS_JSON__QUIRK_ALLOW_COMMENT_BLOCK,
|
||||
WUFFS_JSON__QUIRK_ALLOW_COMMENT_LINE,
|
||||
WUFFS_JSON__QUIRK_ALLOW_EXTRA_COMMA,
|
||||
WUFFS_JSON__QUIRK_ALLOW_INF_NAN_NUMBERS,
|
||||
WUFFS_JSON__QUIRK_ALLOW_LEADING_ASCII_RECORD_SEPARATOR,
|
||||
WUFFS_JSON__QUIRK_ALLOW_LEADING_UNICODE_BYTE_ORDER_MARK,
|
||||
WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER,
|
||||
WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T,
|
||||
WUFFS_JSON__QUIRK_REPLACE_INVALID_UNICODE,
|
||||
0,
|
||||
};
|
||||
|
||||
void set_quirks(wuffs_json__decoder* dec, uint64_t hash) {
|
||||
uint32_t i;
|
||||
for (i = 0; quirks[i]; i++) {
|
||||
uint64_t bit = 1 << (i % 44);
|
||||
if (hash_44_bits & bit) {
|
||||
wuffs_json__decoder__set_quirk_enabled(dec, quirks[i], true);
|
||||
for (i = 0; g_quirks[i]; i++) {
|
||||
uint64_t bit = 1 << (i & 63);
|
||||
if (hash & bit) {
|
||||
wuffs_json__decoder__set_quirk_enabled(dec, g_quirks[i], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char* //
|
||||
fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash_56_bits) {
|
||||
fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash) {
|
||||
uint64_t tok_limit = buffer_limit(
|
||||
hash_56_bits & 0x3F, WUFFS_JSON__DECODER_DST_TOKEN_BUFFER_LENGTH_MIN_INCL,
|
||||
hash & 0x3F, WUFFS_JSON__DECODER_DST_TOKEN_BUFFER_LENGTH_MIN_INCL,
|
||||
TOK_BUFFER_ARRAY_SIZE);
|
||||
uint64_t hash_50_bits = hash_56_bits >> 6;
|
||||
hash = wuffs_base__u64__rotate_right(hash, 6);
|
||||
|
||||
uint64_t src_limit =
|
||||
buffer_limit(hash_50_bits & 0x3F,
|
||||
WUFFS_JSON__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL, 4096);
|
||||
uint64_t hash_44_bits = hash_50_bits >> 6;
|
||||
uint64_t src_limit = buffer_limit(
|
||||
hash & 0x3F, WUFFS_JSON__DECODER_SRC_IO_BUFFER_LENGTH_MIN_INCL, 4096);
|
||||
hash = wuffs_base__u64__rotate_right(hash, 6);
|
||||
|
||||
// ----
|
||||
|
||||
@@ -275,14 +278,15 @@ fuzz_complex(wuffs_base__io_buffer* full_src, uint64_t hash_56_bits) {
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
set_quirks(&dec, hash_44_bits);
|
||||
set_quirks(&dec, hash);
|
||||
|
||||
wuffs_base__token tok_array[TOK_BUFFER_ARRAY_SIZE];
|
||||
wuffs_base__token_buffer tok = ((wuffs_base__token_buffer){
|
||||
.data = ((wuffs_base__slice_token){
|
||||
.ptr = tok_array,
|
||||
.len = (tok_limit < TOK_BUFFER_ARRAY_SIZE) ? tok_limit
|
||||
: TOK_BUFFER_ARRAY_SIZE,
|
||||
.len = (size_t)((tok_limit < TOK_BUFFER_ARRAY_SIZE)
|
||||
? tok_limit
|
||||
: TOK_BUFFER_ARRAY_SIZE),
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -413,8 +417,103 @@ fuzz_simple(wuffs_base__io_buffer* full_src) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#include <vector>
|
||||
|
||||
class Callbacks : public wuffs_aux::DecodeJsonCallbacks {
|
||||
public:
|
||||
Callbacks() : m_depth(0) {}
|
||||
|
||||
std::string AppendNull() override { return ""; }
|
||||
|
||||
std::string AppendBool(bool val) override { return ""; }
|
||||
|
||||
std::string AppendI64(int64_t val) override { return ""; }
|
||||
|
||||
std::string AppendF64(double val) override { return ""; }
|
||||
|
||||
std::string AppendTextString(std::string&& val) override { return ""; }
|
||||
|
||||
std::string Push(uint32_t flags) override {
|
||||
m_depth++;
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string Pop(uint32_t flags) override {
|
||||
m_depth--;
|
||||
if (m_depth < 0) {
|
||||
fprintf(stderr, "negative depth\n");
|
||||
intentional_segfault();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void Done(wuffs_aux::DecodeJsonResult& result,
|
||||
wuffs_aux::sync_io::Input& input,
|
||||
wuffs_aux::IOBuffer& buffer) override {
|
||||
if (result.error_message.empty()) {
|
||||
if (m_depth != 0) {
|
||||
fprintf(stderr, "no error message but final depth is non-zero\n");
|
||||
intentional_segfault();
|
||||
}
|
||||
} else if (result.error_message.find("internal error:") !=
|
||||
std::string::npos) {
|
||||
fprintf(stderr, "internal errors shouldn't occur: \"%s\"\n",
|
||||
result.error_message.c_str());
|
||||
intentional_segfault();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int64_t m_depth;
|
||||
};
|
||||
|
||||
void //
|
||||
fuzz_cpp(const uint8_t* in_ptr, size_t in_len, uint64_t hash) {
|
||||
static const char* json_pointers[16] = {
|
||||
"", //
|
||||
"", //
|
||||
"", //
|
||||
"", //
|
||||
"", //
|
||||
"", //
|
||||
"", //
|
||||
"", //
|
||||
"", //
|
||||
"", //
|
||||
"/", //
|
||||
"/2/3/4/5", //
|
||||
"/k0", //
|
||||
"/k0/1", //
|
||||
"/x/y", //
|
||||
"/~0/~1/~n", //
|
||||
};
|
||||
const char* json_pointer = json_pointers[hash & 15];
|
||||
hash = wuffs_base__u64__rotate_right(hash, 4);
|
||||
|
||||
std::vector<uint32_t> quirks;
|
||||
for (uint32_t i = 0; g_quirks[i]; i++) {
|
||||
uint64_t bit = 1 << (i & 63);
|
||||
if (hash & bit) {
|
||||
quirks.push_back(g_quirks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Callbacks callbacks;
|
||||
wuffs_aux::sync_io::MemoryInput input(in_ptr, in_len);
|
||||
wuffs_aux::DecodeJson(
|
||||
callbacks, input,
|
||||
wuffs_base__make_slice_u32(quirks.data(), quirks.size()), json_pointer);
|
||||
}
|
||||
#endif // defined(__cplusplus)
|
||||
|
||||
const char* //
|
||||
fuzz(wuffs_base__io_buffer* full_src, uint64_t hash) {
|
||||
#if defined(__cplusplus)
|
||||
fuzz_cpp(full_src->reader_pointer(), full_src->reader_length(),
|
||||
wuffs_base__u64__rotate_right(hash, 32));
|
||||
#endif // defined(__cplusplus)
|
||||
|
||||
// Send 99.6% of inputs to fuzz_complex and the remainder to fuzz_simple. The
|
||||
// 0xA5 constant is arbitrary but non-zero. If the hash function maps the
|
||||
// empty input to 0, this still sends the empty input to fuzz_complex.
|
||||
@@ -427,7 +526,7 @@ fuzz(wuffs_base__io_buffer* full_src, uint64_t hash) {
|
||||
// The fuzz_complex implementation adds many more Wuffs API specific checks
|
||||
// (e.g. that the sum of the tokens' lengths do not exceed the input length).
|
||||
if ((hash & 0xFF) != 0xA5) {
|
||||
return fuzz_complex(full_src, hash >> 8);
|
||||
return fuzz_complex(full_src, wuffs_base__u64__rotate_right(hash, 8));
|
||||
}
|
||||
return fuzz_simple(full_src);
|
||||
}
|
||||
@@ -70,7 +70,7 @@ fuzz(wuffs_base__io_buffer* src, uint64_t hash) {
|
||||
wuffs_base__status status = wuffs_png__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
(hash & 1) ? WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED : 0);
|
||||
hash >>= 1;
|
||||
hash = wuffs_base__u64__rotate_right(hash, 1);
|
||||
if (!wuffs_base__status__is_ok(&status)) {
|
||||
return wuffs_base__status__message(&status);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
// Prepare the low-level CBOR decoder.
|
||||
wuffs_cbor__decoder::unique_ptr dec = wuffs_cbor__decoder::alloc();
|
||||
if (!dec) {
|
||||
ret_error_message = "wuffs_aux::CborDecoder: out of memory";
|
||||
ret_error_message = "wuffs_aux::DecodeCbor: out of memory";
|
||||
goto done;
|
||||
}
|
||||
for (size_t i = 0; i < quirks.len; i++) {
|
||||
@@ -72,7 +72,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
wuffs_base__status tok_status = wuffs_base__make_status(nullptr);
|
||||
|
||||
// Prepare other state.
|
||||
uint32_t depth = 0;
|
||||
int32_t depth = 0;
|
||||
std::string str;
|
||||
int64_t extension_category = 0;
|
||||
uint64_t extension_detail = 0;
|
||||
@@ -99,17 +99,17 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
goto done;
|
||||
} else if (cursor_index != io_buf->meta.ri) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad cursor_index";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad cursor_index";
|
||||
goto done;
|
||||
} else if (io_buf->meta.closed) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: io_buf is closed";
|
||||
"wuffs_aux::DecodeCbor: internal error: io_buf is closed";
|
||||
goto done;
|
||||
}
|
||||
io_buf->compact();
|
||||
if (io_buf->meta.wi >= io_buf->data.len) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: io_buf is full";
|
||||
"wuffs_aux::DecodeCbor: internal error: io_buf is full";
|
||||
goto done;
|
||||
}
|
||||
cursor_index = io_buf->meta.ri;
|
||||
@@ -121,11 +121,19 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
|
||||
if (WUFFS_CBOR__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad WORKBUF_LEN";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad WORKBUF_LEN";
|
||||
goto done;
|
||||
}
|
||||
wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8();
|
||||
tok_status = dec->decode_tokens(&tok_buf, io_buf, work_buf);
|
||||
if ((tok_buf.meta.ri > tok_buf.meta.wi) ||
|
||||
(tok_buf.meta.wi > tok_buf.data.len) ||
|
||||
(io_buf->meta.ri > io_buf->meta.wi) ||
|
||||
(io_buf->meta.wi > io_buf->data.len)) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeCbor: internal error: bad buffer indexes";
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++];
|
||||
@@ -133,7 +141,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
if ((io_buf->meta.ri < cursor_index) ||
|
||||
((io_buf->meta.ri - cursor_index) < token_len)) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad token indexes";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad token indexes";
|
||||
goto done;
|
||||
}
|
||||
uint8_t* token_ptr = io_buf->data.ptr + cursor_index;
|
||||
@@ -169,7 +177,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
}
|
||||
}
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad extended token";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad extended token";
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -184,10 +192,20 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
goto done;
|
||||
}
|
||||
depth++;
|
||||
if (depth > WUFFS_CBOR__DECODER_DEPTH_MAX_INCL) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeCbor: internal error: bad depth";
|
||||
goto done;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
ret_error_message = callbacks.Pop(static_cast<uint32_t>(vbd));
|
||||
depth--;
|
||||
if (depth < 0) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeCbor: internal error: bad depth";
|
||||
goto done;
|
||||
}
|
||||
goto parsed_a_value;
|
||||
}
|
||||
|
||||
@@ -324,7 +342,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
|
||||
fail:
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: unexpected token";
|
||||
"wuffs_aux::DecodeCbor: internal error: unexpected token";
|
||||
goto done;
|
||||
|
||||
parsed_a_value:
|
||||
|
||||
@@ -34,60 +34,65 @@ DecodeJsonCallbacks::Done(DecodeJsonResult& result,
|
||||
sync_io::Input& input,
|
||||
IOBuffer& buffer) {}
|
||||
|
||||
const char DecodeJson_BadJsonPointer[] =
|
||||
const char DecodeJson_BadJsonPointer[] = //
|
||||
"wuffs_aux::DecodeJson: bad JSON Pointer";
|
||||
const char DecodeJson_NoMatch[] = "wuffs_aux::DecodeJson: no match";
|
||||
const char DecodeJson_NoMatch[] = //
|
||||
"wuffs_aux::DecodeJson: no match";
|
||||
|
||||
// --------
|
||||
|
||||
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
|
||||
while (tok_buf.meta.ri >= tok_buf.meta.wi) { \
|
||||
if (tok_status.repr == nullptr) { \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_write) { \
|
||||
tok_buf.compact(); \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_read) { \
|
||||
if (!io_error_message.empty()) { \
|
||||
ret_error_message = std::move(io_error_message); \
|
||||
goto done; \
|
||||
} else if (cursor_index != io_buf->meta.ri) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad cursor_index"; \
|
||||
goto done; \
|
||||
} else if (io_buf->meta.closed) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
|
||||
goto done; \
|
||||
} \
|
||||
io_buf->compact(); \
|
||||
if (io_buf->meta.wi >= io_buf->data.len) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
|
||||
goto done; \
|
||||
} \
|
||||
cursor_index = io_buf->meta.ri; \
|
||||
io_error_message = input.CopyIn(io_buf); \
|
||||
} else { \
|
||||
ret_error_message = tok_status.message(); \
|
||||
goto done; \
|
||||
} \
|
||||
if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN"; \
|
||||
goto done; \
|
||||
} \
|
||||
wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8(); \
|
||||
tok_status = dec->decode_tokens(&tok_buf, io_buf, work_buf); \
|
||||
} \
|
||||
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \
|
||||
uint64_t token_len = token.length(); \
|
||||
if ((io_buf->meta.ri < cursor_index) || \
|
||||
((io_buf->meta.ri - cursor_index) < token_len)) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad token indexes"; \
|
||||
goto done; \
|
||||
} \
|
||||
uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \
|
||||
(void)(token_ptr); \
|
||||
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
|
||||
while (tok_buf.meta.ri >= tok_buf.meta.wi) { \
|
||||
if (tok_status.repr == nullptr) { \
|
||||
goto done; \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_write) { \
|
||||
tok_buf.compact(); \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_read) { \
|
||||
if (!io_error_message.empty()) { \
|
||||
ret_error_message = std::move(io_error_message); \
|
||||
goto done; \
|
||||
} else if (cursor_index != io_buf->meta.ri) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad cursor_index"; \
|
||||
goto done; \
|
||||
} else if (io_buf->meta.closed) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
|
||||
goto done; \
|
||||
} \
|
||||
io_buf->compact(); \
|
||||
if (io_buf->meta.wi >= io_buf->data.len) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
|
||||
goto done; \
|
||||
} \
|
||||
cursor_index = io_buf->meta.ri; \
|
||||
io_error_message = input.CopyIn(io_buf); \
|
||||
} else { \
|
||||
ret_error_message = tok_status.message(); \
|
||||
goto done; \
|
||||
} \
|
||||
tok_status = \
|
||||
dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8()); \
|
||||
if ((tok_buf.meta.ri > tok_buf.meta.wi) || \
|
||||
(tok_buf.meta.wi > tok_buf.data.len) || \
|
||||
(io_buf->meta.ri > io_buf->meta.wi) || \
|
||||
(io_buf->meta.wi > io_buf->data.len)) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad buffer indexes"; \
|
||||
goto done; \
|
||||
} \
|
||||
} \
|
||||
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \
|
||||
uint64_t token_len = token.length(); \
|
||||
if ((io_buf->meta.ri < cursor_index) || \
|
||||
((io_buf->meta.ri - cursor_index) < token_len)) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad token indexes"; \
|
||||
goto done; \
|
||||
} \
|
||||
uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \
|
||||
(void)(token_ptr); \
|
||||
cursor_index += static_cast<size_t>(token_len)
|
||||
|
||||
// --------
|
||||
@@ -95,7 +100,8 @@ const char DecodeJson_NoMatch[] = "wuffs_aux::DecodeJson: no match";
|
||||
namespace {
|
||||
|
||||
// DecodeJson_SplitJsonPointer returns ("bar", 8) for ("/foo/bar/b~1z/qux", 5,
|
||||
// etc). It returns a 0 size_t when s has invalid JSON Pointer syntax.
|
||||
// etc). It returns a 0 size_t when s has invalid JSON Pointer syntax or i is
|
||||
// out of bounds.
|
||||
//
|
||||
// The string returned is unescaped. If calling it again, this time with i=8,
|
||||
// the "b~1z" substring would be returned as "b/z".
|
||||
@@ -104,6 +110,9 @@ DecodeJson_SplitJsonPointer(std::string& s,
|
||||
size_t i,
|
||||
bool allow_tilde_n_tilde_r_tilde_t) {
|
||||
std::string fragment;
|
||||
if (i > s.size()) {
|
||||
return std::make_pair(std::string(), 0);
|
||||
}
|
||||
while (i < s.size()) {
|
||||
char c = s[i];
|
||||
if (c == '/') {
|
||||
@@ -310,8 +319,8 @@ check_that_a_value_follows:
|
||||
continue;
|
||||
}
|
||||
|
||||
// Undo the last part of WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN, so that
|
||||
// we're only peeking at the next token.
|
||||
// Undo the last part of WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN, so
|
||||
// that we're only peeking at the next token.
|
||||
tok_buf.meta.ri--;
|
||||
cursor_index -= static_cast<size_t>(token_len);
|
||||
|
||||
@@ -358,6 +367,10 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
if (!dec) {
|
||||
ret_error_message = "wuffs_aux::DecodeJson: out of memory";
|
||||
goto done;
|
||||
} else if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN";
|
||||
goto done;
|
||||
}
|
||||
bool allow_tilde_n_tilde_r_tilde_t = false;
|
||||
for (size_t i = 0; i < quirks.len; i++) {
|
||||
@@ -373,10 +386,11 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
wuffs_base__token_buffer tok_buf =
|
||||
wuffs_base__slice_token__writer(wuffs_base__make_slice_token(
|
||||
&tok_array[0], (sizeof(tok_array) / sizeof(tok_array[0]))));
|
||||
wuffs_base__status tok_status = wuffs_base__make_status(nullptr);
|
||||
wuffs_base__status tok_status =
|
||||
dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8());
|
||||
|
||||
// Prepare other state.
|
||||
uint32_t depth = 0;
|
||||
int32_t depth = 0;
|
||||
std::string str;
|
||||
|
||||
// Walk the (optional) JSON Pointer.
|
||||
@@ -387,7 +401,7 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
}
|
||||
std::pair<std::string, size_t> split = DecodeJson_SplitJsonPointer(
|
||||
json_pointer, i + 1, allow_tilde_n_tilde_r_tilde_t);
|
||||
i = std::move(split.second);
|
||||
i = split.second;
|
||||
if (i == 0) {
|
||||
ret_error_message = DecodeJson_BadJsonPointer;
|
||||
goto done;
|
||||
@@ -419,10 +433,20 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
goto done;
|
||||
}
|
||||
depth++;
|
||||
if (depth > WUFFS_JSON__DECODER_DEPTH_MAX_INCL) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeJson: internal error: bad depth";
|
||||
goto done;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
ret_error_message = callbacks.Pop(static_cast<uint32_t>(vbd));
|
||||
depth--;
|
||||
if (depth < 0) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeJson: internal error: bad depth";
|
||||
goto done;
|
||||
}
|
||||
goto parsed_a_value;
|
||||
}
|
||||
|
||||
@@ -522,7 +546,22 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
goto done;
|
||||
|
||||
parsed_a_value:
|
||||
if (!ret_error_message.empty() || (depth == 0)) {
|
||||
// If an error was encountered, we are done. Otherwise, (depth == 0)
|
||||
// after parsing a value is equivalent to having decoded the entire JSON
|
||||
// value (for an empty json_pointer query) or having decoded the
|
||||
// pointed-to JSON value (for a non-empty json_pointer query). In the
|
||||
// latter case, we are also done.
|
||||
//
|
||||
// However, if quirks like WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER or
|
||||
// WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF are passed, decoding
|
||||
// the entire JSON value should also consume any trailing filler, in case
|
||||
// the DecodeJson caller wants to subsequently check that the input is
|
||||
// completely exhausted (and otherwise raise "valid JSON followed by
|
||||
// further (unexpected) data"). We aren't done yet. Instead, keep the
|
||||
// loop running until WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN's
|
||||
// decode_tokens returns an ok status.
|
||||
if (!ret_error_message.empty() ||
|
||||
((depth == 0) && !json_pointer.empty())) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,26 +29,16 @@
|
||||
// Its (non-zero) value is arbitrary, based on md5sum("disabled").
|
||||
#define WUFFS_BASE__DISABLED ((uint32_t)0x075AE3D2)
|
||||
|
||||
// Denote intentional fallthroughs for -Wimplicit-fallthrough.
|
||||
//
|
||||
// The order matters here. Clang also defines "__GNUC__".
|
||||
#if defined(__clang__) && defined(__cplusplus) && (__cplusplus >= 201103L)
|
||||
#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]
|
||||
#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)
|
||||
#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))
|
||||
#else
|
||||
#define WUFFS_BASE__FALLTHROUGH
|
||||
#endif
|
||||
|
||||
// Use switch cases for coroutine suspension points, similar to the technique
|
||||
// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
|
||||
//
|
||||
// The implicit fallthrough is intentional.
|
||||
//
|
||||
// We use trivial macros instead of an explicit assignment and case statement
|
||||
// so that clang-format doesn't get confused by the unusual "case"s.
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
|
||||
coro_susp_point = n; \
|
||||
WUFFS_BASE__FALLTHROUGH; \
|
||||
case n:;
|
||||
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
|
||||
@@ -60,8 +60,8 @@
|
||||
|
||||
// To simplify Wuffs code, "cpu_arch >= arm_xxx" requires xxx but also
|
||||
// unaligned little-endian load/stores.
|
||||
#if defined(__ARM_FEATURE_UNALIGNED) && defined(__BYTE_ORDER__) && \
|
||||
(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||
#if defined(__ARM_FEATURE_UNALIGNED) && !defined(__native_client__) && \
|
||||
defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||
// Not all gcc versions define __ARM_ACLE, even if they support crc32
|
||||
// intrinsics. Look for __ARM_FEATURE_CRC32 instead.
|
||||
#if defined(__ARM_FEATURE_CRC32)
|
||||
@@ -76,11 +76,13 @@
|
||||
|
||||
// Similarly, "cpu_arch >= x86_sse42" requires SSE4.2 but also PCLMUL and
|
||||
// POPCNT. This is checked at runtime via cpuid, not at compile time.
|
||||
#if defined(__x86_64__)
|
||||
//
|
||||
// Likewise, "cpu_arch >= x86_avx2" also requires PCLMUL, POPCNT and SSE4.2.
|
||||
#if defined(__x86_64__) && !defined(__native_client__)
|
||||
#include <cpuid.h>
|
||||
#include <x86intrin.h>
|
||||
#define WUFFS_BASE__CPU_ARCH__X86_64
|
||||
#endif // defined(__x86_64__)
|
||||
#endif // defined(__x86_64__) && !defined(__native_client__)
|
||||
|
||||
#elif defined(_MSC_VER) // (#if-chain ref AVOID_CPU_ARCH_1)
|
||||
|
||||
@@ -148,6 +150,82 @@ wuffs_base__cpu_arch__have_arm_neon() {
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_NEON)
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__cpu_arch__have_x86_avx2() {
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
// GCC defines these macros but MSVC does not.
|
||||
// - bit_AVX2 = (1 << 5)
|
||||
const unsigned int avx2_ebx7 = 0x00000020;
|
||||
// GCC defines these macros but MSVC does not.
|
||||
// - bit_PCLMUL = (1 << 1)
|
||||
// - bit_POPCNT = (1 << 23)
|
||||
// - bit_SSE4_2 = (1 << 20)
|
||||
const unsigned int avx2_ecx1 = 0x00900002;
|
||||
|
||||
// clang defines __GNUC__ and clang-cl defines _MSC_VER (but not __GNUC__).
|
||||
#if defined(__GNUC__)
|
||||
unsigned int eax7 = 0;
|
||||
unsigned int ebx7 = 0;
|
||||
unsigned int ecx7 = 0;
|
||||
unsigned int edx7 = 0;
|
||||
if (__get_cpuid_count(7, 0, &eax7, &ebx7, &ecx7, &edx7) &&
|
||||
((ebx7 & avx2_ebx7) == avx2_ebx7)) {
|
||||
unsigned int eax1 = 0;
|
||||
unsigned int ebx1 = 0;
|
||||
unsigned int ecx1 = 0;
|
||||
unsigned int edx1 = 0;
|
||||
if (__get_cpuid(1, &eax1, &ebx1, &ecx1, &edx1) &&
|
||||
((ecx1 & avx2_ecx1) == avx2_ecx1)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#elif defined(_MSC_VER) // defined(__GNUC__)
|
||||
int x7[4];
|
||||
__cpuidex(x7, 7, 0);
|
||||
if ((((unsigned int)(x7[1])) & avx2_ebx7) == avx2_ebx7) {
|
||||
int x1[4];
|
||||
__cpuid(x1, 1);
|
||||
if ((((unsigned int)(x1[2])) & avx2_ecx1) == avx2_ecx1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error "WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#endif // defined(__GNUC__); defined(_MSC_VER)
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__cpu_arch__have_x86_bmi2() {
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
// GCC defines these macros but MSVC does not.
|
||||
// - bit_BMI2 = (1 << 8)
|
||||
const unsigned int bmi2_ebx7 = 0x00000100;
|
||||
|
||||
// clang defines __GNUC__ and clang-cl defines _MSC_VER (but not __GNUC__).
|
||||
#if defined(__GNUC__)
|
||||
unsigned int eax7 = 0;
|
||||
unsigned int ebx7 = 0;
|
||||
unsigned int ecx7 = 0;
|
||||
unsigned int edx7 = 0;
|
||||
if (__get_cpuid_count(7, 0, &eax7, &ebx7, &ecx7, &edx7) &&
|
||||
((ebx7 & bmi2_ebx7) == bmi2_ebx7)) {
|
||||
return true;
|
||||
}
|
||||
#elif defined(_MSC_VER) // defined(__GNUC__)
|
||||
int x7[4];
|
||||
__cpuidex(x7, 7, 0);
|
||||
if ((((unsigned int)(x7[1])) & bmi2_ebx7) == bmi2_ebx7) {
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
#error "WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#endif // defined(__GNUC__); defined(_MSC_VER)
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__cpu_arch__have_x86_sse42() {
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
@@ -163,13 +241,16 @@ wuffs_base__cpu_arch__have_x86_sse42() {
|
||||
unsigned int ebx1 = 0;
|
||||
unsigned int ecx1 = 0;
|
||||
unsigned int edx1 = 0;
|
||||
if (__get_cpuid(1, &eax1, &ebx1, &ecx1, &edx1)) {
|
||||
return (ecx1 & sse42_ecx1) == sse42_ecx1;
|
||||
if (__get_cpuid(1, &eax1, &ebx1, &ecx1, &edx1) &&
|
||||
((ecx1 & sse42_ecx1) == sse42_ecx1)) {
|
||||
return true;
|
||||
}
|
||||
#elif defined(_MSC_VER) // defined(__GNUC__)
|
||||
int x[4];
|
||||
__cpuid(x, 1);
|
||||
return (((unsigned int)(x[2])) & sse42_ecx1) == sse42_ecx1;
|
||||
int x1[4];
|
||||
__cpuid(x1, 1);
|
||||
if ((((unsigned int)(x1[2])) & sse42_ecx1) == sse42_ecx1) {
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
#error "WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#endif // defined(__GNUC__); defined(_MSC_VER)
|
||||
@@ -500,6 +581,56 @@ wuffs_base__u64__max(uint64_t x, uint64_t y) {
|
||||
|
||||
// --------
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__u8__rotate_left(uint8_t x, uint32_t n) {
|
||||
n &= 7;
|
||||
return ((uint8_t)(x << n)) | ((uint8_t)(x >> (8 - n)));
|
||||
}
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__u8__rotate_right(uint8_t x, uint32_t n) {
|
||||
n &= 7;
|
||||
return ((uint8_t)(x >> n)) | ((uint8_t)(x << (8 - n)));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__u16__rotate_left(uint16_t x, uint32_t n) {
|
||||
n &= 15;
|
||||
return ((uint16_t)(x << n)) | ((uint16_t)(x >> (16 - n)));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__u16__rotate_right(uint16_t x, uint32_t n) {
|
||||
n &= 15;
|
||||
return ((uint16_t)(x >> n)) | ((uint16_t)(x << (16 - n)));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__rotate_left(uint32_t x, uint32_t n) {
|
||||
n &= 31;
|
||||
return ((uint32_t)(x << n)) | ((uint32_t)(x >> (32 - n)));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__rotate_right(uint32_t x, uint32_t n) {
|
||||
n &= 31;
|
||||
return ((uint32_t)(x >> n)) | ((uint32_t)(x << (32 - n)));
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__u64__rotate_left(uint64_t x, uint32_t n) {
|
||||
n &= 63;
|
||||
return ((uint64_t)(x << n)) | ((uint64_t)(x >> (64 - n)));
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__u64__rotate_right(uint64_t x, uint32_t n) {
|
||||
n &= 63;
|
||||
return ((uint64_t)(x >> n)) | ((uint64_t)(x << (64 - n)));
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// Saturating arithmetic (sat_add, sat_sub) branchless bit-twiddling algorithms
|
||||
// are per https://locklessinc.com/articles/sat_arithmetic/
|
||||
//
|
||||
|
||||
@@ -139,13 +139,18 @@ wuffs_base__parse_number_i64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
ret.value = 0;
|
||||
return ret;
|
||||
} else if (negative) {
|
||||
if (r.value > 0x8000000000000000) {
|
||||
goto fail_out_of_bounds;
|
||||
if (r.value < 0x8000000000000000) {
|
||||
wuffs_base__result_i64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = -(int64_t)(r.value);
|
||||
return ret;
|
||||
} else if (r.value == 0x8000000000000000) {
|
||||
wuffs_base__result_i64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = INT64_MIN;
|
||||
return ret;
|
||||
}
|
||||
wuffs_base__result_i64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = -(int64_t)(r.value);
|
||||
return ret;
|
||||
goto fail_out_of_bounds;
|
||||
} else if (r.value > 0x7FFFFFFFFFFFFFFF) {
|
||||
goto fail_out_of_bounds;
|
||||
} else {
|
||||
|
||||
@@ -117,11 +117,12 @@ wuffs_base__io_reader__set(wuffs_base__io_buffer* b,
|
||||
const uint8_t** ptr_io0_r,
|
||||
const uint8_t** ptr_io1_r,
|
||||
const uint8_t** ptr_io2_r,
|
||||
wuffs_base__slice_u8 data) {
|
||||
wuffs_base__slice_u8 data,
|
||||
uint64_t history_position) {
|
||||
b->data = data;
|
||||
b->meta.wi = data.len;
|
||||
b->meta.ri = 0;
|
||||
b->meta.pos = 0;
|
||||
b->meta.pos = history_position;
|
||||
b->meta.closed = false;
|
||||
|
||||
*ptr_iop_r = data.ptr;
|
||||
@@ -228,6 +229,46 @@ wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
return length;
|
||||
}
|
||||
|
||||
// wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast
|
||||
// copies the previous byte (the one immediately before *ptr_iop_w), copying 8
|
||||
// byte chunks at a time. Each chunk contains 8 repetitions of the same byte.
|
||||
//
|
||||
// In terms of number of bytes copied, length is rounded up to a multiple of 8.
|
||||
// As a special case, a zero length rounds up to 8 (even though 0 is already a
|
||||
// multiple of 8), since there is always at least one 8 byte chunk copied.
|
||||
//
|
||||
// In terms of advancing *ptr_iop_w, length is not rounded up.
|
||||
//
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance == 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
uint8_t* p = *ptr_iop_w;
|
||||
uint64_t x = p[-1];
|
||||
x |= x << 8;
|
||||
x |= x << 16;
|
||||
x |= x << 32;
|
||||
uint32_t n = length;
|
||||
while (1) {
|
||||
wuffs_base__poke_u64le__no_bounds_check(p, x);
|
||||
if (n <= 8) {
|
||||
p += n;
|
||||
break;
|
||||
}
|
||||
p += 8;
|
||||
n -= 8;
|
||||
}
|
||||
*ptr_iop_w = p;
|
||||
return length;
|
||||
}
|
||||
|
||||
// wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast is
|
||||
// like the wuffs_base__io_writer__limited_copy_u32_from_history_fast function
|
||||
// above, but copies 8 byte chunks at a time.
|
||||
@@ -315,11 +356,12 @@ wuffs_base__io_writer__set(wuffs_base__io_buffer* b,
|
||||
uint8_t** ptr_io0_w,
|
||||
uint8_t** ptr_io1_w,
|
||||
uint8_t** ptr_io2_w,
|
||||
wuffs_base__slice_u8 data) {
|
||||
wuffs_base__slice_u8 data,
|
||||
uint64_t history_position) {
|
||||
b->data = data;
|
||||
b->meta.wi = 0;
|
||||
b->meta.ri = 0;
|
||||
b->meta.pos = 0;
|
||||
b->meta.pos = history_position;
|
||||
b->meta.closed = false;
|
||||
|
||||
*ptr_iop_w = data.ptr;
|
||||
|
||||
@@ -4094,6 +4094,34 @@ wuffs_base__pixel_swizzler__y__y_16be(uint8_t* dst_ptr,
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__y_16le__y_16be(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len2 = dst_len / 2;
|
||||
size_t src_len2 = src_len / 2;
|
||||
size_t len = (dst_len2 < src_len2) ? dst_len2 : src_len2;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
while (n >= 1) {
|
||||
uint8_t s0 = s[0];
|
||||
uint8_t s1 = s[1];
|
||||
d[0] = s1;
|
||||
d[1] = s0;
|
||||
|
||||
s += 1 * 2;
|
||||
d += 1 * 2;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
@@ -4180,13 +4208,18 @@ wuffs_base__pixel_swizzler__prepare__y_16be(wuffs_base__pixel_swizzler* p,
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
return wuffs_base__pixel_swizzler__y__y_16be;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16LE:
|
||||
return wuffs_base__pixel_swizzler__y_16le__y_16be;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:
|
||||
return wuffs_base__pixel_swizzler__copy_2_2;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__y_16be;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
return wuffs_base__pixel_swizzler__xxx__y_16be;
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
|
||||
@@ -250,8 +250,8 @@ func (g *gen) writeBuiltinIOReader(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
return nil
|
||||
|
||||
case t.IDPosition:
|
||||
b.printf("wuffs_base__u64__sat_add(%s->meta.pos, ((uint64_t)(%s%s - %s%s)))",
|
||||
recvName, iopPrefix, recvName, io0Prefix, recvName)
|
||||
b.printf("wuffs_base__u64__sat_add((%s ? %s->meta.pos : 0), ((uint64_t)(%s%s - %s%s)))",
|
||||
recvName, recvName, iopPrefix, recvName, io0Prefix, recvName)
|
||||
return nil
|
||||
|
||||
case t.IDSince:
|
||||
@@ -308,6 +308,7 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
|
||||
switch method {
|
||||
case t.IDLimitedCopyU32FromHistory,
|
||||
t.IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast,
|
||||
t.IDLimitedCopyU32FromHistory8ByteChunksFast,
|
||||
t.IDLimitedCopyU32FromHistoryFast:
|
||||
b.printf("wuffs_base__io_writer__%s(\n&%s%s, %s%s, %s%s",
|
||||
@@ -357,9 +358,13 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args []
|
||||
b.printf("((uint64_t)(%s%s - %s%s))", iopPrefix, recvName, io0Prefix, recvName)
|
||||
return nil
|
||||
|
||||
case t.IDHistoryPosition:
|
||||
b.printf("(%s ? %s->meta.pos : 0)", recvName, recvName)
|
||||
return nil
|
||||
|
||||
case t.IDPosition:
|
||||
b.printf("wuffs_base__u64__sat_add(%s->meta.pos, ((uint64_t)(%s%s - %s%s)))",
|
||||
recvName, iopPrefix, recvName, io0Prefix, recvName)
|
||||
b.printf("wuffs_base__u64__sat_add((%s ? %s->meta.pos : 0), ((uint64_t)(%s%s - %s%s)))",
|
||||
recvName, recvName, iopPrefix, recvName, io0Prefix, recvName)
|
||||
return nil
|
||||
|
||||
case t.IDSince:
|
||||
@@ -451,7 +456,8 @@ func (g *gen) writeBuiltinCPUArch(b *buffer, recv *a.Expr, method t.ID, args []*
|
||||
return g.writeBuiltinCPUArchARMCRC32(b, recv, method, args, sideEffectsOnly, depth)
|
||||
case id.IsBuiltInCPUArchARMNeon():
|
||||
return g.writeBuiltinCPUArchARMNeon(b, recv, method, args, sideEffectsOnly, depth)
|
||||
case id == t.IDX86SSE42Utility, id == t.IDX86M128I:
|
||||
case id == t.IDX86SSE42Utility, id == t.IDX86M128I,
|
||||
id == t.IDX86AVX2Utility, id == t.IDX86M256I:
|
||||
return g.writeBuiltinCPUArchX86(b, recv, method, args, sideEffectsOnly, depth)
|
||||
}
|
||||
return fmt.Errorf("internal error: unsupported cpu_arch method %s.%s",
|
||||
@@ -629,6 +635,27 @@ func (g *gen) writeBuiltinCPUArchX86(b *buffer, recv *a.Expr, method t.ID, args
|
||||
fName, tName, ptr = "_mm_lddqu_si128", "const __m128i*)(const void*", true
|
||||
case "make_m128i_zeroes":
|
||||
fName, tName = "_mm_setzero_si128", ""
|
||||
|
||||
case "make_m256i_multiple_u8":
|
||||
fName, tName = "_mm256_set_epi8", "int8_t"
|
||||
case "make_m256i_multiple_u16":
|
||||
fName, tName = "_mm256_set_epi16", "int16_t"
|
||||
case "make_m256i_multiple_u32":
|
||||
fName, tName = "_mm256_set_epi32", "int32_t"
|
||||
case "make_m256i_multiple_u64":
|
||||
fName, tName = "_mm256_set_epi64x", "int64_t"
|
||||
case "make_m256i_repeat_u8":
|
||||
fName, tName = "_mm256_set1_epi8", "int8_t"
|
||||
case "make_m256i_repeat_u16":
|
||||
fName, tName = "_mm256_set1_epi16", "int16_t"
|
||||
case "make_m256i_repeat_u32":
|
||||
fName, tName = "_mm256_set1_epi32", "int32_t"
|
||||
case "make_m256i_repeat_u64":
|
||||
fName, tName = "_mm256_set1_epi64x", "int64_t"
|
||||
case "make_m256i_slice256":
|
||||
fName, tName, ptr = "_mm256_lddqu_si256", "const __m256i*)(const void*", true
|
||||
case "make_m256i_zeroes":
|
||||
fName, tName = "_mm256_setzero_si256", ""
|
||||
default:
|
||||
return fmt.Errorf("internal error: unsupported cpu_arch method %q", methodStr)
|
||||
}
|
||||
|
||||
@@ -200,8 +200,8 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
maxIOBinds = 100
|
||||
maxTemp = 10000
|
||||
maxIOManips = 100
|
||||
maxTemp = 10000
|
||||
)
|
||||
|
||||
type status struct {
|
||||
|
||||
+91
-79
@@ -29,9 +29,8 @@ const BaseAllImplC = "" +
|
||||
""
|
||||
|
||||
const BaseFundamentalPrivateH = "" +
|
||||
"// ---------------- Fundamentals\n\n// WUFFS_BASE__MAGIC is a magic number to check that initializers are called.\n// It's not foolproof, given C doesn't automatically zero memory before use,\n// but it should catch 99.99% of cases.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"wuffs\").\n#define WUFFS_BASE__MAGIC ((uint32_t)0x3CCB6C71)\n\n// WUFFS_BASE__DISABLED is a magic number to indicate that a non-recoverable\n// error was previously encountered.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"disabled\").\n#define WUFFS_BASE__DISABLED ((uint32_t)0x075AE3D2)\n\n// Denote intentional fallthroughs for -Wimplicit-fallthrough.\n//\n// The order matters here. Clang also defines \"__GNUC__\".\n#if defined(__clang__) && defined(__cplusplus) && (__cplusplus >= 201103L)\n#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]\n#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)\n#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))\n#else\n#define WUFFS_BASE__FALLTHROUGH\n#endif\n\n// Use switch " +
|
||||
"cases for coroutine suspension points, similar to the technique\n// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\n//\n// We use trivial macros instead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \\\n coro_susp_point = n; \\\n WUFFS_BASE__FALLTHROUGH; \\\n case n:;\n\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \\\n if (!status.repr) { \\\n goto ok; \\\n } else if (*status.repr != '$') { \\\n goto exit; \\\n } \\\n coro_susp_point = n; \\\n goto suspend; " +
|
||||
" \\\n case n:;\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n#else\n#define WUFFS_BASE__LIKELY(expr) (expr)\n#define WUFFS_BASE__UNLIKELY(expr) (expr)\n#endif\n\n" +
|
||||
"// ---------------- Fundamentals\n\n// WUFFS_BASE__MAGIC is a magic number to check that initializers are called.\n// It's not foolproof, given C doesn't automatically zero memory before use,\n// but it should catch 99.99% of cases.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"wuffs\").\n#define WUFFS_BASE__MAGIC ((uint32_t)0x3CCB6C71)\n\n// WUFFS_BASE__DISABLED is a magic number to indicate that a non-recoverable\n// error was previously encountered.\n//\n// Its (non-zero) value is arbitrary, based on md5sum(\"disabled\").\n#define WUFFS_BASE__DISABLED ((uint32_t)0x075AE3D2)\n\n// Use switch cases for coroutine suspension points, similar to the technique\n// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html\n//\n// The implicit fallthrough is intentional.\n//\n// We use trivial macros instead of an explicit assignment and case statement\n// so that clang-format doesn't get confused by the unusual \"case\"s.\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;\n#define WUFFS_BASE__COROUTINE_SUSPENSION_" +
|
||||
"POINT(n) \\\n coro_susp_point = n; \\\n case n:;\n\n#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \\\n if (!status.repr) { \\\n goto ok; \\\n } else if (*status.repr != '$') { \\\n goto exit; \\\n } \\\n coro_susp_point = n; \\\n goto suspend; \\\n case n:;\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__LIKELY(expr) (__builtin_expect(!!(expr), 1))\n#define WUFFS_BASE__UNLIKELY(expr) (__builtin_expect(!!(expr), 0))\n#else\n#define WUFFS_BASE__LIKELY(expr) (expr)\n#define WUFFS_BASE__UNLIKELY(expr) (expr)\n#endif\n\n" +
|
||||
"" +
|
||||
"// --------\n\nstatic inline wuffs_base__empty_struct //\nwuffs_base__ignore_status(wuffs_base__status z) {\n return wuffs_base__make_empty_struct();\n}\n\nstatic inline wuffs_base__status //\nwuffs_base__status__ensure_not_a_suspension(wuffs_base__status z) {\n if (z.repr && (*z.repr == '$')) {\n z.repr = wuffs_base__error__cannot_return_a_suspension;\n }\n return z;\n}\n\n" +
|
||||
"" +
|
||||
@@ -54,14 +53,17 @@ const BaseFundamentalPublicH = "" +
|
||||
"// ---------------- Version\n\n// WUFFS_VERSION is the major.minor.patch version, as per https://semver.org/,\n// as a uint64_t. The major number is the high 32 bits. The minor number is the\n// middle 16 bits. The patch number is the low 16 bits. The pre-release label\n// and build metadata are part of the string representation (such as\n// \"1.2.3-beta+456.20181231\") but not the uint64_t representation.\n//\n// WUFFS_VERSION_PRE_RELEASE_LABEL (such as \"\", \"beta\" or \"rc.1\") being\n// non-empty denotes a developer preview, not a release version, and has no\n// backwards or forwards compatibility guarantees.\n//\n// WUFFS_VERSION_BUILD_METADATA_XXX, if non-zero, are the number of commits and\n// the last commit date in the repository used to build this library. Within\n// each major.minor branch, the commit count should increase monotonically.\n//\n// ¡ Some code generation programs can override WUFFS_VERSION.\n#define WUFFS_VERSION 0\n#define WUFFS_VERSION_MAJOR 0\n#define WUFFS_VERSION_MINOR 0\n#define WUFFS_VERSION_PATCH 0\n#de" +
|
||||
"fine WUFFS_VERSION_PRE_RELEASE_LABEL \"work.in.progress\"\n#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 0\n#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 0\n#define WUFFS_VERSION_STRING \"0.0.0+0.00000000\"\n\n" +
|
||||
"" +
|
||||
"// ---------------- Configuration\n\n// Define WUFFS_CONFIG__AVOID_CPU_ARCH to avoid any code tied to a specific CPU\n// architecture, such as SSE SIMD for the x86 CPU family.\n#if defined(WUFFS_CONFIG__AVOID_CPU_ARCH) // (#if-chain ref AVOID_CPU_ARCH_0)\n// No-op.\n#else // (#if-chain ref AVOID_CPU_ARCH_0)\n\n// The \"defined(__clang__)\" isn't redundant. While vanilla clang defines\n// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.\n#if defined(__GNUC__) || defined(__clang__)\n#define WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(arg) __attribute__((target(arg)))\n#else\n#define WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(arg)\n#endif // defined(__GNUC__) || defined(__clang__)\n\n#if defined(__GNUC__) // (#if-chain ref AVOID_CPU_ARCH_1)\n\n// To simplify Wuffs code, \"cpu_arch >= arm_xxx\" requires xxx but also\n// unaligned little-endian load/stores.\n#if defined(__ARM_FEATURE_UNALIGNED) && defined(__BYTE_ORDER__) && \\\n (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)\n// Not all gcc versions define __ARM_ACLE, even if they support crc32" +
|
||||
"\n// intrinsics. Look for __ARM_FEATURE_CRC32 instead.\n#if defined(__ARM_FEATURE_CRC32)\n#include <arm_acle.h>\n#define WUFFS_BASE__CPU_ARCH__ARM_CRC32\n#endif // defined(__ARM_FEATURE_CRC32)\n#if defined(__ARM_NEON)\n#include <arm_neon.h>\n#define WUFFS_BASE__CPU_ARCH__ARM_NEON\n#endif // defined(__ARM_NEON)\n#endif // defined(__ARM_FEATURE_UNALIGNED) etc\n\n// Similarly, \"cpu_arch >= x86_sse42\" requires SSE4.2 but also PCLMUL and\n// POPCNT. This is checked at runtime via cpuid, not at compile time.\n#if defined(__x86_64__)\n#include <cpuid.h>\n#include <x86intrin.h>\n#define WUFFS_BASE__CPU_ARCH__X86_64\n#endif // defined(__x86_64__)\n\n#elif defined(_MSC_VER) // (#if-chain ref AVOID_CPU_ARCH_1)\n\n#if defined(_M_X64)\n#if defined(__AVX__) || defined(__clang__)\n\n// We need <intrin.h> for the __cpuid function.\n#include <intrin.h>\n// That's not enough for X64 SIMD, with clang-cl, if we want to use\n// \"__attribute__((target(arg)))\" without e.g. \"/arch:AVX\".\n//\n// Some web pages suggest that <immintrin.h> is all you need, as i" +
|
||||
"t pulls in\n// the earlier SIMD families like SSE4.2, but that doesn't seem to work in\n// practice, possibly for the same reason that just <intrin.h> doesn't work.\n#include <immintrin.h> // AVX, AVX2, FMA, POPCNT\n#include <nmmintrin.h> // SSE4.2\n#include <wmmintrin.h> // AES, PCLMUL\n#define WUFFS_BASE__CPU_ARCH__X86_64\n\n#else // defined(__AVX__) || defined(__clang__)\n\n// clang-cl (which defines both __clang__ and _MSC_VER) supports\n// \"__attribute__((target(arg)))\".\n//\n// For MSVC's cl.exe (unlike clang or gcc), SIMD capability is a compile-time\n// property of the source file (e.g. a /arch:AVX or -mavx compiler flag), not\n// of individual functions (that can be conditionally selected at runtime).\n#pragma message(\"Wuffs with MSVC+X64 needs /arch:AVX for best performance\")\n\n#endif // defined(__AVX__) || defined(__clang__)\n#endif // defined(_M_X64)\n\n#endif // (#if-chain ref AVOID_CPU_ARCH_1)\n#endif // (#if-chain ref AVOID_CPU_ARCH_0)\n\n" +
|
||||
"// ---------------- Configuration\n\n// Define WUFFS_CONFIG__AVOID_CPU_ARCH to avoid any code tied to a specific CPU\n// architecture, such as SSE SIMD for the x86 CPU family.\n#if defined(WUFFS_CONFIG__AVOID_CPU_ARCH) // (#if-chain ref AVOID_CPU_ARCH_0)\n// No-op.\n#else // (#if-chain ref AVOID_CPU_ARCH_0)\n\n// The \"defined(__clang__)\" isn't redundant. While vanilla clang defines\n// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.\n#if defined(__GNUC__) || defined(__clang__)\n#define WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(arg) __attribute__((target(arg)))\n#else\n#define WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(arg)\n#endif // defined(__GNUC__) || defined(__clang__)\n\n#if defined(__GNUC__) // (#if-chain ref AVOID_CPU_ARCH_1)\n\n// To simplify Wuffs code, \"cpu_arch >= arm_xxx\" requires xxx but also\n// unaligned little-endian load/stores.\n#if defined(__ARM_FEATURE_UNALIGNED) && !defined(__native_client__) && \\\n defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)\n// Not all gcc versions define __ARM_A" +
|
||||
"CLE, even if they support crc32\n// intrinsics. Look for __ARM_FEATURE_CRC32 instead.\n#if defined(__ARM_FEATURE_CRC32)\n#include <arm_acle.h>\n#define WUFFS_BASE__CPU_ARCH__ARM_CRC32\n#endif // defined(__ARM_FEATURE_CRC32)\n#if defined(__ARM_NEON)\n#include <arm_neon.h>\n#define WUFFS_BASE__CPU_ARCH__ARM_NEON\n#endif // defined(__ARM_NEON)\n#endif // defined(__ARM_FEATURE_UNALIGNED) etc\n\n// Similarly, \"cpu_arch >= x86_sse42\" requires SSE4.2 but also PCLMUL and\n// POPCNT. This is checked at runtime via cpuid, not at compile time.\n//\n// Likewise, \"cpu_arch >= x86_avx2\" also requires PCLMUL, POPCNT and SSE4.2.\n#if defined(__x86_64__) && !defined(__native_client__)\n#include <cpuid.h>\n#include <x86intrin.h>\n#define WUFFS_BASE__CPU_ARCH__X86_64\n#endif // defined(__x86_64__) && !defined(__native_client__)\n\n#elif defined(_MSC_VER) // (#if-chain ref AVOID_CPU_ARCH_1)\n\n#if defined(_M_X64)\n#if defined(__AVX__) || defined(__clang__)\n\n// We need <intrin.h> for the __cpuid function.\n#include <intrin.h>\n// That's not enough for" +
|
||||
" X64 SIMD, with clang-cl, if we want to use\n// \"__attribute__((target(arg)))\" without e.g. \"/arch:AVX\".\n//\n// Some web pages suggest that <immintrin.h> is all you need, as it pulls in\n// the earlier SIMD families like SSE4.2, but that doesn't seem to work in\n// practice, possibly for the same reason that just <intrin.h> doesn't work.\n#include <immintrin.h> // AVX, AVX2, FMA, POPCNT\n#include <nmmintrin.h> // SSE4.2\n#include <wmmintrin.h> // AES, PCLMUL\n#define WUFFS_BASE__CPU_ARCH__X86_64\n\n#else // defined(__AVX__) || defined(__clang__)\n\n// clang-cl (which defines both __clang__ and _MSC_VER) supports\n// \"__attribute__((target(arg)))\".\n//\n// For MSVC's cl.exe (unlike clang or gcc), SIMD capability is a compile-time\n// property of the source file (e.g. a /arch:AVX or -mavx compiler flag), not\n// of individual functions (that can be conditionally selected at runtime).\n#pragma message(\"Wuffs with MSVC+X64 needs /arch:AVX for best performance\")\n\n#endif // defined(__AVX__) || defined(__clang__)\n#endif // defi" +
|
||||
"ned(_M_X64)\n\n#endif // (#if-chain ref AVOID_CPU_ARCH_1)\n#endif // (#if-chain ref AVOID_CPU_ARCH_0)\n\n" +
|
||||
"" +
|
||||
"// --------\n\n// Define WUFFS_CONFIG__STATIC_FUNCTIONS to make all of Wuffs' functions have\n// static storage. The motivation is discussed in the \"ALLOW STATIC\n// IMPLEMENTATION\" section of\n// https://raw.githubusercontent.com/nothings/stb/master/docs/stb_howto.txt\n#if defined(WUFFS_CONFIG__STATIC_FUNCTIONS)\n#define WUFFS_BASE__MAYBE_STATIC static\n#else\n#define WUFFS_BASE__MAYBE_STATIC\n#endif // defined(WUFFS_CONFIG__STATIC_FUNCTIONS)\n\n" +
|
||||
"" +
|
||||
"// ---------------- CPU Architecture\n\nstatic inline bool //\nwuffs_base__cpu_arch__have_arm_crc32() {\n#if defined(WUFFS_BASE__CPU_ARCH__ARM_CRC32)\n return true;\n#else\n return false;\n#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_CRC32)\n}\n\nstatic inline bool //\nwuffs_base__cpu_arch__have_arm_neon() {\n#if defined(WUFFS_BASE__CPU_ARCH__ARM_NEON)\n return true;\n#else\n return false;\n#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_NEON)\n}\n\nstatic inline bool //\nwuffs_base__cpu_arch__have_x86_sse42() {\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n // GCC defines these macros but MSVC does not.\n // - bit_PCLMUL = (1 << 1)\n // - bit_POPCNT = (1 << 23)\n // - bit_SSE4_2 = (1 << 20)\n const unsigned int sse42_ecx1 = 0x00900002;\n\n // clang defines __GNUC__ and clang-cl defines _MSC_VER (but not __GNUC__).\n#if defined(__GNUC__)\n unsigned int eax1 = 0;\n unsigned int ebx1 = 0;\n unsigned int ecx1 = 0;\n unsigned int edx1 = 0;\n if (__get_cpuid(1, &eax1, &ebx1, &ecx1, &edx1)) {\n return (ecx1 & sse42_ecx1) == sse42_" +
|
||||
"ecx1;\n }\n#elif defined(_MSC_VER) // defined(__GNUC__)\n int x[4];\n __cpuid(x, 1);\n return (((unsigned int)(x[2])) & sse42_ecx1) == sse42_ecx1;\n#else\n#error \"WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler\"\n#endif // defined(__GNUC__); defined(_MSC_VER)\n#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)\n return false;\n}\n\n" +
|
||||
"// ---------------- CPU Architecture\n\nstatic inline bool //\nwuffs_base__cpu_arch__have_arm_crc32() {\n#if defined(WUFFS_BASE__CPU_ARCH__ARM_CRC32)\n return true;\n#else\n return false;\n#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_CRC32)\n}\n\nstatic inline bool //\nwuffs_base__cpu_arch__have_arm_neon() {\n#if defined(WUFFS_BASE__CPU_ARCH__ARM_NEON)\n return true;\n#else\n return false;\n#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_NEON)\n}\n\nstatic inline bool //\nwuffs_base__cpu_arch__have_x86_avx2() {\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n // GCC defines these macros but MSVC does not.\n // - bit_AVX2 = (1 << 5)\n const unsigned int avx2_ebx7 = 0x00000020;\n // GCC defines these macros but MSVC does not.\n // - bit_PCLMUL = (1 << 1)\n // - bit_POPCNT = (1 << 23)\n // - bit_SSE4_2 = (1 << 20)\n const unsigned int avx2_ecx1 = 0x00900002;\n\n // clang defines __GNUC__ and clang-cl defines _MSC_VER (but not __GNUC__).\n#if defined(__GNUC__)\n unsigned int eax7 = 0;\n unsigned int ebx7 = 0;\n unsigned int ecx7 =" +
|
||||
" 0;\n unsigned int edx7 = 0;\n if (__get_cpuid_count(7, 0, &eax7, &ebx7, &ecx7, &edx7) &&\n ((ebx7 & avx2_ebx7) == avx2_ebx7)) {\n unsigned int eax1 = 0;\n unsigned int ebx1 = 0;\n unsigned int ecx1 = 0;\n unsigned int edx1 = 0;\n if (__get_cpuid(1, &eax1, &ebx1, &ecx1, &edx1) &&\n ((ecx1 & avx2_ecx1) == avx2_ecx1)) {\n return true;\n }\n }\n#elif defined(_MSC_VER) // defined(__GNUC__)\n int x7[4];\n __cpuidex(x7, 7, 0);\n if ((((unsigned int)(x7[1])) & avx2_ebx7) == avx2_ebx7) {\n int x1[4];\n __cpuid(x1, 1);\n if ((((unsigned int)(x1[2])) & avx2_ecx1) == avx2_ecx1) {\n return true;\n }\n }\n#else\n#error \"WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler\"\n#endif // defined(__GNUC__); defined(_MSC_VER)\n#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)\n return false;\n}\n\nstatic inline bool //\nwuffs_base__cpu_arch__have_x86_bmi2() {\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n // GCC defines these macros but MSVC does not.\n // - bit_BMI2 = (1 << 8)\n const u" +
|
||||
"nsigned int bmi2_ebx7 = 0x00000100;\n\n // clang defines __GNUC__ and clang-cl defines _MSC_VER (but not __GNUC__).\n#if defined(__GNUC__)\n unsigned int eax7 = 0;\n unsigned int ebx7 = 0;\n unsigned int ecx7 = 0;\n unsigned int edx7 = 0;\n if (__get_cpuid_count(7, 0, &eax7, &ebx7, &ecx7, &edx7) &&\n ((ebx7 & bmi2_ebx7) == bmi2_ebx7)) {\n return true;\n }\n#elif defined(_MSC_VER) // defined(__GNUC__)\n int x7[4];\n __cpuidex(x7, 7, 0);\n if ((((unsigned int)(x7[1])) & bmi2_ebx7) == bmi2_ebx7) {\n return true;\n }\n#else\n#error \"WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler\"\n#endif // defined(__GNUC__); defined(_MSC_VER)\n#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)\n return false;\n}\n\nstatic inline bool //\nwuffs_base__cpu_arch__have_x86_sse42() {\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n // GCC defines these macros but MSVC does not.\n // - bit_PCLMUL = (1 << 1)\n // - bit_POPCNT = (1 << 23)\n // - bit_SSE4_2 = (1 << 20)\n const unsigned int sse42_ecx1 = 0x00900002;\n\n // clan" +
|
||||
"g defines __GNUC__ and clang-cl defines _MSC_VER (but not __GNUC__).\n#if defined(__GNUC__)\n unsigned int eax1 = 0;\n unsigned int ebx1 = 0;\n unsigned int ecx1 = 0;\n unsigned int edx1 = 0;\n if (__get_cpuid(1, &eax1, &ebx1, &ecx1, &edx1) &&\n ((ecx1 & sse42_ecx1) == sse42_ecx1)) {\n return true;\n }\n#elif defined(_MSC_VER) // defined(__GNUC__)\n int x1[4];\n __cpuid(x1, 1);\n if ((((unsigned int)(x1[2])) & sse42_ecx1) == sse42_ecx1) {\n return true;\n }\n#else\n#error \"WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler\"\n#endif // defined(__GNUC__); defined(_MSC_VER)\n#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)\n return false;\n}\n\n" +
|
||||
"" +
|
||||
"// ---------------- Fundamentals\n\n// Wuffs assumes that:\n// - converting a uint32_t to a size_t will never overflow.\n// - converting a size_t to a uint64_t will never overflow.\n#if defined(__WORDSIZE)\n#if (__WORDSIZE != 32) && (__WORDSIZE != 64)\n#error \"Wuffs requires a word size of either 32 or 64 bits\"\n#endif\n#endif\n\n// Clang also defines \"__GNUC__\".\n#if defined(__GNUC__)\n#define WUFFS_BASE__POTENTIALLY_UNUSED __attribute__((unused))\n#define WUFFS_BASE__WARN_UNUSED_RESULT __attribute__((warn_unused_result))\n#else\n#define WUFFS_BASE__POTENTIALLY_UNUSED\n#define WUFFS_BASE__WARN_UNUSED_RESULT\n#endif\n\n" +
|
||||
"" +
|
||||
@@ -88,6 +90,9 @@ const BaseFundamentalPublicH = "" +
|
||||
"int32_t //\nwuffs_base__i32__max(int32_t x, int32_t y) {\n return x > y ? x : y;\n}\n\nstatic inline int64_t //\nwuffs_base__i64__min(int64_t x, int64_t y) {\n return x < y ? x : y;\n}\n\nstatic inline int64_t //\nwuffs_base__i64__max(int64_t x, int64_t y) {\n return x > y ? x : y;\n}\n\nstatic inline uint8_t //\nwuffs_base__u8__min(uint8_t x, uint8_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint8_t //\nwuffs_base__u8__max(uint8_t x, uint8_t y) {\n return x > y ? x : y;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__min(uint16_t x, uint16_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__max(uint16_t x, uint16_t y) {\n return x > y ? x : y;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__min(uint32_t x, uint32_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__max(uint32_t x, uint32_t y) {\n return x > y ? x : y;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__min(uint64_t x, uint64_t y) {\n return x < y ? x : y;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__m" +
|
||||
"ax(uint64_t x, uint64_t y) {\n return x > y ? x : y;\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\nstatic inline uint8_t //\nwuffs_base__u8__rotate_left(uint8_t x, uint32_t n) {\n n &= 7;\n return ((uint8_t)(x << n)) | ((uint8_t)(x >> (8 - n)));\n}\n\nstatic inline uint8_t //\nwuffs_base__u8__rotate_right(uint8_t x, uint32_t n) {\n n &= 7;\n return ((uint8_t)(x >> n)) | ((uint8_t)(x << (8 - n)));\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__rotate_left(uint16_t x, uint32_t n) {\n n &= 15;\n return ((uint16_t)(x << n)) | ((uint16_t)(x >> (16 - n)));\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__rotate_right(uint16_t x, uint32_t n) {\n n &= 15;\n return ((uint16_t)(x >> n)) | ((uint16_t)(x << (16 - n)));\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__rotate_left(uint32_t x, uint32_t n) {\n n &= 31;\n return ((uint32_t)(x << n)) | ((uint32_t)(x >> (32 - n)));\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__rotate_right(uint32_t x, uint32_t n) {\n n &= 31;\n return ((uint32_t)(x >> n)) | ((uint32_t)(x << (32 - n)));\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__rotate_left(uint64_t x, uint32_t n) " +
|
||||
"{\n n &= 63;\n return ((uint64_t)(x << n)) | ((uint64_t)(x >> (64 - n)));\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__rotate_right(uint64_t x, uint32_t n) {\n n &= 63;\n return ((uint64_t)(x >> n)) | ((uint64_t)(x << (64 - n)));\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\n// Saturating arithmetic (sat_add, sat_sub) branchless bit-twiddling algorithms\n// are per https://locklessinc.com/articles/sat_arithmetic/\n//\n// It is important that the underlying types are unsigned integers, as signed\n// integer arithmetic overflow is undefined behavior in C.\n\nstatic inline uint8_t //\nwuffs_base__u8__sat_add(uint8_t x, uint8_t y) {\n uint8_t res = (uint8_t)(x + y);\n res |= (uint8_t)(-(res < x));\n return res;\n}\n\nstatic inline uint8_t //\nwuffs_base__u8__sat_sub(uint8_t x, uint8_t y) {\n uint8_t res = (uint8_t)(x - y);\n res &= (uint8_t)(-(res <= x));\n return res;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__sat_add(uint16_t x, uint16_t y) {\n uint16_t res = (uint16_t)(x + y);\n res |= (uint16_t)(-(res < x));\n return res;\n}\n\nstatic inline uint16_t //\nwuffs_base__u16__sat_sub(uint16_t x, uint16_t y) {\n uint16_t res = (uint16_t)(x - y);\n res &= (uint16_t)(-(res <= x));\n return res;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__sat_add(uint32_t x, uint32_t y) {\n uint32" +
|
||||
"_t res = (uint32_t)(x + y);\n res |= (uint32_t)(-(res < x));\n return res;\n}\n\nstatic inline uint32_t //\nwuffs_base__u32__sat_sub(uint32_t x, uint32_t y) {\n uint32_t res = (uint32_t)(x - y);\n res &= (uint32_t)(-(res <= x));\n return res;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__sat_add(uint64_t x, uint64_t y) {\n uint64_t res = (uint64_t)(x + y);\n res |= (uint64_t)(-(res < x));\n return res;\n}\n\nstatic inline uint64_t //\nwuffs_base__u64__sat_sub(uint64_t x, uint64_t y) {\n uint64_t res = (uint64_t)(x - y);\n res &= (uint64_t)(-(res <= x));\n return res;\n}\n\n" +
|
||||
"" +
|
||||
@@ -218,14 +223,16 @@ const BaseIOPrivateH = "" +
|
||||
"" +
|
||||
"// --------\n\nstatic inline void //\nwuffs_base__io_reader__limit(const uint8_t** ptr_io2_r,\n const uint8_t* iop_r,\n uint64_t limit) {\n if (((uint64_t)(*ptr_io2_r - iop_r)) > limit) {\n *ptr_io2_r = iop_r + limit;\n }\n}\n\nstatic inline uint32_t //\nwuffs_base__io_reader__limited_copy_u32_to_slice(const uint8_t** ptr_iop_r,\n const uint8_t* io2_r,\n uint32_t length,\n wuffs_base__slice_u8 dst) {\n const uint8_t* iop_r = *ptr_iop_r;\n size_t n = dst.len;\n if (n > length) {\n n = length;\n }\n if (n > ((size_t)(io2_r - iop_r))) {\n n = (size_t)(io2_r - iop_r);\n }\n if (n > 0) {\n memmove(dst.ptr, iop_r, n);\n *ptr_iop_r += n;\n }\n return (uint32_t)(n);\n}\n\n// wuffs_base__io_reader__match7 returns whether the io_reader's upcoming bytes\n// start with the given prefix (up to 7 bytes long). It is peek-like, not\n" +
|
||||
"// read-like, in that there are no side-effects.\n//\n// The low 3 bits of a hold the prefix length, n.\n//\n// The high 56 bits of a hold the prefix itself, in little-endian order. The\n// first prefix byte is in bits 8..=15, the second prefix byte is in bits\n// 16..=23, etc. The high (8 * (7 - n)) bits are ignored.\n//\n// There are three possible return values:\n// - 0 means success.\n// - 1 means inconclusive, equivalent to \"$short read\".\n// - 2 means failure.\nstatic inline uint32_t //\nwuffs_base__io_reader__match7(const uint8_t* iop_r,\n const uint8_t* io2_r,\n wuffs_base__io_buffer* r,\n uint64_t a) {\n uint32_t n = a & 7;\n a >>= 8;\n if ((io2_r - iop_r) >= 8) {\n uint64_t x = wuffs_base__peek_u64le__no_bounds_check(iop_r);\n uint32_t shift = 8 * (8 - n);\n return ((a << shift) == (x << shift)) ? 0 : 2;\n }\n for (; n > 0; n--) {\n if (iop_r >= io2_r) {\n return (r && r->meta.closed) ? 2 : 1;\n } else if (*iop_" +
|
||||
"r != ((uint8_t)(a))) {\n return 2;\n }\n iop_r++;\n a >>= 8;\n }\n return 0;\n}\n\nstatic inline wuffs_base__io_buffer* //\nwuffs_base__io_reader__set(wuffs_base__io_buffer* b,\n const uint8_t** ptr_iop_r,\n const uint8_t** ptr_io0_r,\n const uint8_t** ptr_io1_r,\n const uint8_t** ptr_io2_r,\n wuffs_base__slice_u8 data) {\n b->data = data;\n b->meta.wi = data.len;\n b->meta.ri = 0;\n b->meta.pos = 0;\n b->meta.closed = false;\n\n *ptr_iop_r = data.ptr;\n *ptr_io0_r = data.ptr;\n *ptr_io1_r = data.ptr;\n *ptr_io2_r = data.ptr + data.len;\n\n return b;\n}\n\n" +
|
||||
"r != ((uint8_t)(a))) {\n return 2;\n }\n iop_r++;\n a >>= 8;\n }\n return 0;\n}\n\nstatic inline wuffs_base__io_buffer* //\nwuffs_base__io_reader__set(wuffs_base__io_buffer* b,\n const uint8_t** ptr_iop_r,\n const uint8_t** ptr_io0_r,\n const uint8_t** ptr_io1_r,\n const uint8_t** ptr_io2_r,\n wuffs_base__slice_u8 data,\n uint64_t history_position) {\n b->data = data;\n b->meta.wi = data.len;\n b->meta.ri = 0;\n b->meta.pos = history_position;\n b->meta.closed = false;\n\n *ptr_iop_r = data.ptr;\n *ptr_io0_r = data.ptr;\n *ptr_io1_r = data.ptr;\n *ptr_io2_r = data.ptr + data.len;\n\n return b;\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\nstatic inline uint64_t //\nwuffs_base__io_writer__copy_from_slice(uint8_t** ptr_iop_w,\n uint8_t* io2_w,\n wuffs_base__slice_u8 src) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = src.len;\n if (n > ((size_t)(io2_w - iop_w))) {\n n = (size_t)(io2_w - iop_w);\n }\n if (n > 0) {\n memmove(iop_w, src.ptr, n);\n *ptr_iop_w += n;\n }\n return (uint64_t)(n);\n}\n\nstatic inline void //\nwuffs_base__io_writer__limit(uint8_t** ptr_io2_w,\n uint8_t* iop_w,\n uint64_t limit) {\n if (((uint64_t)(*ptr_io2_w - iop_w)) > limit) {\n *ptr_io2_w = iop_w + limit;\n }\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__limited_copy_u32_from_history(uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n uint8_t* io2_w,\n uint32_t length,\n " +
|
||||
" uint32_t distance) {\n if (!distance) {\n return 0;\n }\n uint8_t* p = *ptr_iop_w;\n if ((size_t)(p - io1_w) < (size_t)(distance)) {\n return 0;\n }\n uint8_t* q = p - distance;\n size_t n = (size_t)(io2_w - p);\n if ((size_t)(length) > n) {\n length = (uint32_t)(n);\n } else {\n n = (size_t)(length);\n }\n // TODO: unrolling by 3 seems best for the std/deflate benchmarks, but that\n // is mostly because 3 is the minimum length for the deflate format. This\n // function implementation shouldn't overfit to that one format. Perhaps the\n // limited_copy_u32_from_history Wuffs method should also take an unroll hint\n // argument, and the cgen can look if that argument is the constant\n // expression '3'.\n //\n // See also wuffs_base__io_writer__limited_copy_u32_from_history_fast below.\n for (; n >= 3; n -= 3) {\n *p++ = *q++;\n *p++ = *q++;\n *p++ = *q++;\n }\n for (; n; n--) {\n *p++ = *q++;\n }\n *ptr_iop_w = p;\n return length;\n}\n\n// wuffs_base__io_w" +
|
||||
"riter__limited_copy_u32_from_history_fast is like the\n// wuffs_base__io_writer__limited_copy_u32_from_history function above, but has\n// stronger pre-conditions.\n//\n// The caller needs to prove that:\n// - length <= (io2_w - *ptr_iop_w)\n// - distance >= 1\n// - distance <= (*ptr_iop_w - io1_w)\nstatic inline uint32_t //\nwuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n uint8_t* io2_w,\n uint32_t length,\n uint32_t distance) {\n uint8_t* p = *ptr_iop_w;\n uint8_t* q = p - distance;\n uint32_t n = length;\n for (; n >= 3; n -= 3) {\n *p++ = *q++;\n *p++ = *q++;\n *p++ = *q++;\n }\n for (; n; n--) {\n *p++ = *q++;\n }\n *ptr_iop_w = p;\n return length;\n}\n\n// wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast" +
|
||||
" is\n// like the wuffs_base__io_writer__limited_copy_u32_from_history_fast function\n// above, but copies 8 byte chunks at a time.\n//\n// In terms of number of bytes copied, length is rounded up to a multiple of 8.\n// As a special case, a zero length rounds up to 8 (even though 0 is already a\n// multiple of 8), since there is always at least one 8 byte chunk copied.\n//\n// In terms of advancing *ptr_iop_w, length is not rounded up.\n//\n// The caller needs to prove that:\n// - (length + 8) <= (io2_w - *ptr_iop_w)\n// - distance >= 8\n// - distance <= (*ptr_iop_w - io1_w)\nstatic inline uint32_t //\nwuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(\n uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n uint8_t* io2_w,\n uint32_t length,\n uint32_t distance) {\n uint8_t* p = *ptr_iop_w;\n uint8_t* q = p - distance;\n uint32_t n = length;\n while (1) {\n memcpy(p, q, 8);\n if (n <= 8) {\n p += n;\n break;\n }\n p += 8;\n q += 8;\n n -= 8;\n }\n *ptr_iop_w = p;\n ret" +
|
||||
"urn length;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__limited_copy_u32_from_reader(uint8_t** ptr_iop_w,\n uint8_t* io2_w,\n uint32_t length,\n const uint8_t** ptr_iop_r,\n const uint8_t* io2_r) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = length;\n if (n > ((size_t)(io2_w - iop_w))) {\n n = (size_t)(io2_w - iop_w);\n }\n const uint8_t* iop_r = *ptr_iop_r;\n if (n > ((size_t)(io2_r - iop_r))) {\n n = (size_t)(io2_r - iop_r);\n }\n if (n > 0) {\n memmove(iop_w, iop_r, n);\n *ptr_iop_w += n;\n *ptr_iop_r += n;\n }\n return (uint32_t)(n);\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__limited_copy_u32_from_slice(uint8_t** ptr_iop_w,\n uint8_t* io2_w,\n uint32_t length,\n " +
|
||||
" wuffs_base__slice_u8 src) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > ((size_t)(io2_w - iop_w))) {\n n = (size_t)(io2_w - iop_w);\n }\n if (n > 0) {\n memmove(iop_w, src.ptr, n);\n *ptr_iop_w += n;\n }\n return (uint32_t)(n);\n}\n\nstatic inline wuffs_base__io_buffer* //\nwuffs_base__io_writer__set(wuffs_base__io_buffer* b,\n uint8_t** ptr_iop_w,\n uint8_t** ptr_io0_w,\n uint8_t** ptr_io1_w,\n uint8_t** ptr_io2_w,\n wuffs_base__slice_u8 data) {\n b->data = data;\n b->meta.wi = 0;\n b->meta.ri = 0;\n b->meta.pos = 0;\n b->meta.closed = false;\n\n *ptr_iop_w = data.ptr;\n *ptr_io0_w = data.ptr;\n *ptr_io1_w = data.ptr;\n *ptr_io2_w = data.ptr + data.len;\n\n return b;\n}\n\n" +
|
||||
"riter__limited_copy_u32_from_history_fast is like the\n// wuffs_base__io_writer__limited_copy_u32_from_history function above, but has\n// stronger pre-conditions.\n//\n// The caller needs to prove that:\n// - length <= (io2_w - *ptr_iop_w)\n// - distance >= 1\n// - distance <= (*ptr_iop_w - io1_w)\nstatic inline uint32_t //\nwuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n uint8_t* io2_w,\n uint32_t length,\n uint32_t distance) {\n uint8_t* p = *ptr_iop_w;\n uint8_t* q = p - distance;\n uint32_t n = length;\n for (; n >= 3; n -= 3) {\n *p++ = *q++;\n *p++ = *q++;\n *p++ = *q++;\n }\n for (; n; n--) {\n *p++ = *q++;\n }\n *ptr_iop_w = p;\n return length;\n}\n\n// wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_dist" +
|
||||
"ance_1_fast\n// copies the previous byte (the one immediately before *ptr_iop_w), copying 8\n// byte chunks at a time. Each chunk contains 8 repetitions of the same byte.\n//\n// In terms of number of bytes copied, length is rounded up to a multiple of 8.\n// As a special case, a zero length rounds up to 8 (even though 0 is already a\n// multiple of 8), since there is always at least one 8 byte chunk copied.\n//\n// In terms of advancing *ptr_iop_w, length is not rounded up.\n//\n// The caller needs to prove that:\n// - (length + 8) <= (io2_w - *ptr_iop_w)\n// - distance == 1\n// - distance <= (*ptr_iop_w - io1_w)\nstatic inline uint32_t //\nwuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(\n uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n uint8_t* io2_w,\n uint32_t length,\n uint32_t distance) {\n uint8_t* p = *ptr_iop_w;\n uint64_t x = p[-1];\n x |= x << 8;\n x |= x << 16;\n x |= x << 32;\n uint32_t n = length;\n while (1) {\n wuffs_base__poke_u64le__no_bounds_check(" +
|
||||
"p, x);\n if (n <= 8) {\n p += n;\n break;\n }\n p += 8;\n n -= 8;\n }\n *ptr_iop_w = p;\n return length;\n}\n\n// wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast is\n// like the wuffs_base__io_writer__limited_copy_u32_from_history_fast function\n// above, but copies 8 byte chunks at a time.\n//\n// In terms of number of bytes copied, length is rounded up to a multiple of 8.\n// As a special case, a zero length rounds up to 8 (even though 0 is already a\n// multiple of 8), since there is always at least one 8 byte chunk copied.\n//\n// In terms of advancing *ptr_iop_w, length is not rounded up.\n//\n// The caller needs to prove that:\n// - (length + 8) <= (io2_w - *ptr_iop_w)\n// - distance >= 8\n// - distance <= (*ptr_iop_w - io1_w)\nstatic inline uint32_t //\nwuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(\n uint8_t** ptr_iop_w,\n uint8_t* io1_w,\n uint8_t* io2_w,\n uint32_t length,\n uint32_t distance) {\n uint8_t* p = *ptr_iop_w;\n u" +
|
||||
"int8_t* q = p - distance;\n uint32_t n = length;\n while (1) {\n memcpy(p, q, 8);\n if (n <= 8) {\n p += n;\n break;\n }\n p += 8;\n q += 8;\n n -= 8;\n }\n *ptr_iop_w = p;\n return length;\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__limited_copy_u32_from_reader(uint8_t** ptr_iop_w,\n uint8_t* io2_w,\n uint32_t length,\n const uint8_t** ptr_iop_r,\n const uint8_t* io2_r) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = length;\n if (n > ((size_t)(io2_w - iop_w))) {\n n = (size_t)(io2_w - iop_w);\n }\n const uint8_t* iop_r = *ptr_iop_r;\n if (n > ((size_t)(io2_r - iop_r))) {\n n = (size_t)(io2_r - iop_r);\n }\n if (n > 0) {\n memmove(iop_w, iop_r, n);\n *ptr_iop_w += n;\n *ptr_iop_r += n;\n }\n return (uint32_t)(n);\n}\n\nstatic inline uint32_t //\nwuffs_base__io_writer__limited_co" +
|
||||
"py_u32_from_slice(uint8_t** ptr_iop_w,\n uint8_t* io2_w,\n uint32_t length,\n wuffs_base__slice_u8 src) {\n uint8_t* iop_w = *ptr_iop_w;\n size_t n = src.len;\n if (n > length) {\n n = length;\n }\n if (n > ((size_t)(io2_w - iop_w))) {\n n = (size_t)(io2_w - iop_w);\n }\n if (n > 0) {\n memmove(iop_w, src.ptr, n);\n *ptr_iop_w += n;\n }\n return (uint32_t)(n);\n}\n\nstatic inline wuffs_base__io_buffer* //\nwuffs_base__io_writer__set(wuffs_base__io_buffer* b,\n uint8_t** ptr_iop_w,\n uint8_t** ptr_io0_w,\n uint8_t** ptr_io1_w,\n uint8_t** ptr_io2_w,\n wuffs_base__slice_u8 data,\n uint64_t history_position) {\n b->data = data;\n b->meta.wi = 0;\n b->meta.ri = 0;\n b->meta.pos = history_position;\n b->meta.closed = " +
|
||||
"false;\n\n *ptr_iop_w = data.ptr;\n *ptr_io0_w = data.ptr;\n *ptr_io1_w = data.ptr;\n *ptr_io2_w = data.ptr + data.len;\n\n return b;\n}\n\n" +
|
||||
"" +
|
||||
"// ---------------- I/O (Utility)\n\n#define wuffs_base__utility__empty_io_reader wuffs_base__empty_io_reader\n#define wuffs_base__utility__empty_io_writer wuffs_base__empty_io_writer\n" +
|
||||
""
|
||||
@@ -516,11 +523,12 @@ const BaseIntConvSubmoduleC = "" +
|
||||
" 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x80 ..= 0x87.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x88 ..= 0x8F.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x90 ..= 0x97.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x98 ..= 0x9F.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xA0 ..= 0xA7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xA8 ..= 0xAF.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xB0 ..= 0xB7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xB8 ..= 0xBF.\n\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xC0 ..= 0xC7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xC8 ..= 0xCF.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xD0 ..= 0xD7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xD8 ..= 0xDF.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xE0 ..= 0xE7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xE8 ..= 0xEF.\n 0x00, 0x00, 0x00, 0x00, 0x0" +
|
||||
"0, 0x00, 0x00, 0x00, // 0xF0 ..= 0xF7.\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xF8 ..= 0xFF.\n // 0 1 2 3 4 5 6 7\n // 8 9 A B C D E F\n};\n\nstatic const uint8_t wuffs_base__private_implementation__encode_base16[16] = {\n 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, // 0x00 ..= 0x07.\n 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, // 0x08 ..= 0x0F.\n};\n\n" +
|
||||
"" +
|
||||
"// --------\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_i64 //\nwuffs_base__parse_number_i64(wuffs_base__slice_u8 s, uint32_t options) {\n uint8_t* p = s.ptr;\n uint8_t* q = s.ptr + s.len;\n\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (; (p < q) && (*p == '_'); p++) {\n }\n }\n\n bool negative = false;\n if (p >= q) {\n goto fail_bad_argument;\n } else if (*p == '-') {\n p++;\n negative = true;\n } else if (*p == '+') {\n p++;\n }\n\n do {\n wuffs_base__result_u64 r = wuffs_base__parse_number_u64(\n wuffs_base__make_slice_u8(p, (size_t)(q - p)), options);\n if (r.status.repr != NULL) {\n wuffs_base__result_i64 ret;\n ret.status.repr = r.status.repr;\n ret.value = 0;\n return ret;\n } else if (negative) {\n if (r.value > 0x8000000000000000) {\n goto fail_out_of_bounds;\n }\n wuffs_base__result_i64 ret;\n ret.status.repr = NULL;\n ret.value = -(int64_t)(r.value);\n return ret;\n } else if (r.value > 0x7FFFFFFFFFFF" +
|
||||
"FFFF) {\n goto fail_out_of_bounds;\n } else {\n wuffs_base__result_i64 ret;\n ret.status.repr = NULL;\n ret.value = +(int64_t)(r.value);\n return ret;\n }\n } while (0);\n\nfail_bad_argument:\n do {\n wuffs_base__result_i64 ret;\n ret.status.repr = wuffs_base__error__bad_argument;\n ret.value = 0;\n return ret;\n } while (0);\n\nfail_out_of_bounds:\n do {\n wuffs_base__result_i64 ret;\n ret.status.repr = wuffs_base__error__out_of_bounds;\n ret.value = 0;\n return ret;\n } while (0);\n}\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_u64 //\nwuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {\n uint8_t* p = s.ptr;\n uint8_t* q = s.ptr + s.len;\n\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (; (p < q) && (*p == '_'); p++) {\n }\n }\n\n if (p >= q) {\n goto fail_bad_argument;\n\n } else if (*p == '0') {\n p++;\n if (p >= q) {\n goto ok_zero;\n }\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n " +
|
||||
"if (*p == '_') {\n p++;\n for (; p < q; p++) {\n if (*p != '_') {\n if (options &\n WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {\n goto decimal;\n }\n goto fail_bad_argument;\n }\n }\n goto ok_zero;\n }\n }\n\n if ((*p == 'x') || (*p == 'X')) {\n p++;\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (; (p < q) && (*p == '_'); p++) {\n }\n }\n if (p < q) {\n goto hexadecimal;\n }\n\n } else if ((*p == 'd') || (*p == 'D')) {\n p++;\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (; (p < q) && (*p == '_'); p++) {\n }\n }\n if (p < q) {\n goto decimal;\n }\n }\n\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {\n goto decimal;\n }\n goto fail_bad_argument;\n }\n\ndecimal:\n do {\n uint64_t v = wuffs_base__parse_number__decimal_digi" +
|
||||
"ts[*p++];\n if (v == 0) {\n goto fail_bad_argument;\n }\n v &= 0x0F;\n\n // UINT64_MAX is 18446744073709551615, which is ((10 * max10) + max1).\n const uint64_t max10 = 1844674407370955161u;\n const uint8_t max1 = 5;\n\n for (; p < q; p++) {\n if ((*p == '_') &&\n (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {\n continue;\n }\n uint8_t digit = wuffs_base__parse_number__decimal_digits[*p];\n if (digit == 0) {\n goto fail_bad_argument;\n }\n digit &= 0x0F;\n if ((v > max10) || ((v == max10) && (digit > max1))) {\n goto fail_out_of_bounds;\n }\n v = (10 * v) + ((uint64_t)(digit));\n }\n\n wuffs_base__result_u64 ret;\n ret.status.repr = NULL;\n ret.value = v;\n return ret;\n } while (0);\n\nhexadecimal:\n do {\n uint64_t v = wuffs_base__parse_number__hexadecimal_digits[*p++];\n if (v == 0) {\n goto fail_bad_argument;\n }\n v &= 0x0F;\n\n for (; p < q; p++) {\n if ((*p == '_') &&\n (options" +
|
||||
" & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {\n continue;\n }\n uint8_t digit = wuffs_base__parse_number__hexadecimal_digits[*p];\n if (digit == 0) {\n goto fail_bad_argument;\n }\n digit &= 0x0F;\n if ((v >> 60) != 0) {\n goto fail_out_of_bounds;\n }\n v = (v << 4) | ((uint64_t)(digit));\n }\n\n wuffs_base__result_u64 ret;\n ret.status.repr = NULL;\n ret.value = v;\n return ret;\n } while (0);\n\nok_zero:\n do {\n wuffs_base__result_u64 ret;\n ret.status.repr = NULL;\n ret.value = 0;\n return ret;\n } while (0);\n\nfail_bad_argument:\n do {\n wuffs_base__result_u64 ret;\n ret.status.repr = wuffs_base__error__bad_argument;\n ret.value = 0;\n return ret;\n } while (0);\n\nfail_out_of_bounds:\n do {\n wuffs_base__result_u64 ret;\n ret.status.repr = wuffs_base__error__out_of_bounds;\n ret.value = 0;\n return ret;\n } while (0);\n}\n\n" +
|
||||
"// --------\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_i64 //\nwuffs_base__parse_number_i64(wuffs_base__slice_u8 s, uint32_t options) {\n uint8_t* p = s.ptr;\n uint8_t* q = s.ptr + s.len;\n\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (; (p < q) && (*p == '_'); p++) {\n }\n }\n\n bool negative = false;\n if (p >= q) {\n goto fail_bad_argument;\n } else if (*p == '-') {\n p++;\n negative = true;\n } else if (*p == '+') {\n p++;\n }\n\n do {\n wuffs_base__result_u64 r = wuffs_base__parse_number_u64(\n wuffs_base__make_slice_u8(p, (size_t)(q - p)), options);\n if (r.status.repr != NULL) {\n wuffs_base__result_i64 ret;\n ret.status.repr = r.status.repr;\n ret.value = 0;\n return ret;\n } else if (negative) {\n if (r.value < 0x8000000000000000) {\n wuffs_base__result_i64 ret;\n ret.status.repr = NULL;\n ret.value = -(int64_t)(r.value);\n return ret;\n } else if (r.value == 0x8000000000000000) {\n wuffs_base__re" +
|
||||
"sult_i64 ret;\n ret.status.repr = NULL;\n ret.value = INT64_MIN;\n return ret;\n }\n goto fail_out_of_bounds;\n } else if (r.value > 0x7FFFFFFFFFFFFFFF) {\n goto fail_out_of_bounds;\n } else {\n wuffs_base__result_i64 ret;\n ret.status.repr = NULL;\n ret.value = +(int64_t)(r.value);\n return ret;\n }\n } while (0);\n\nfail_bad_argument:\n do {\n wuffs_base__result_i64 ret;\n ret.status.repr = wuffs_base__error__bad_argument;\n ret.value = 0;\n return ret;\n } while (0);\n\nfail_out_of_bounds:\n do {\n wuffs_base__result_i64 ret;\n ret.status.repr = wuffs_base__error__out_of_bounds;\n ret.value = 0;\n return ret;\n } while (0);\n}\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__result_u64 //\nwuffs_base__parse_number_u64(wuffs_base__slice_u8 s, uint32_t options) {\n uint8_t* p = s.ptr;\n uint8_t* q = s.ptr + s.len;\n\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (; (p < q) && (*p == '_'); p++) {\n }\n }\n\n if (p >= q) {\n goto" +
|
||||
" fail_bad_argument;\n\n } else if (*p == '0') {\n p++;\n if (p >= q) {\n goto ok_zero;\n }\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n if (*p == '_') {\n p++;\n for (; p < q; p++) {\n if (*p != '_') {\n if (options &\n WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {\n goto decimal;\n }\n goto fail_bad_argument;\n }\n }\n goto ok_zero;\n }\n }\n\n if ((*p == 'x') || (*p == 'X')) {\n p++;\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (; (p < q) && (*p == '_'); p++) {\n }\n }\n if (p < q) {\n goto hexadecimal;\n }\n\n } else if ((*p == 'd') || (*p == 'D')) {\n p++;\n if (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES) {\n for (; (p < q) && (*p == '_'); p++) {\n }\n }\n if (p < q) {\n goto decimal;\n }\n }\n\n if (options & WUFFS_BASE__PARSE_" +
|
||||
"NUMBER_XXX__ALLOW_MULTIPLE_LEADING_ZEROES) {\n goto decimal;\n }\n goto fail_bad_argument;\n }\n\ndecimal:\n do {\n uint64_t v = wuffs_base__parse_number__decimal_digits[*p++];\n if (v == 0) {\n goto fail_bad_argument;\n }\n v &= 0x0F;\n\n // UINT64_MAX is 18446744073709551615, which is ((10 * max10) + max1).\n const uint64_t max10 = 1844674407370955161u;\n const uint8_t max1 = 5;\n\n for (; p < q; p++) {\n if ((*p == '_') &&\n (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {\n continue;\n }\n uint8_t digit = wuffs_base__parse_number__decimal_digits[*p];\n if (digit == 0) {\n goto fail_bad_argument;\n }\n digit &= 0x0F;\n if ((v > max10) || ((v == max10) && (digit > max1))) {\n goto fail_out_of_bounds;\n }\n v = (10 * v) + ((uint64_t)(digit));\n }\n\n wuffs_base__result_u64 ret;\n ret.status.repr = NULL;\n ret.value = v;\n return ret;\n } while (0);\n\nhexadecimal:\n do {\n uint64_t v = wuffs_base__par" +
|
||||
"se_number__hexadecimal_digits[*p++];\n if (v == 0) {\n goto fail_bad_argument;\n }\n v &= 0x0F;\n\n for (; p < q; p++) {\n if ((*p == '_') &&\n (options & WUFFS_BASE__PARSE_NUMBER_XXX__ALLOW_UNDERSCORES)) {\n continue;\n }\n uint8_t digit = wuffs_base__parse_number__hexadecimal_digits[*p];\n if (digit == 0) {\n goto fail_bad_argument;\n }\n digit &= 0x0F;\n if ((v >> 60) != 0) {\n goto fail_out_of_bounds;\n }\n v = (v << 4) | ((uint64_t)(digit));\n }\n\n wuffs_base__result_u64 ret;\n ret.status.repr = NULL;\n ret.value = v;\n return ret;\n } while (0);\n\nok_zero:\n do {\n wuffs_base__result_u64 ret;\n ret.status.repr = NULL;\n ret.value = 0;\n return ret;\n } while (0);\n\nfail_bad_argument:\n do {\n wuffs_base__result_u64 ret;\n ret.status.repr = wuffs_base__error__bad_argument;\n ret.value = 0;\n return ret;\n } while (0);\n\nfail_out_of_bounds:\n do {\n wuffs_base__result_u64 ret;\n ret.status.repr = wuffs_base" +
|
||||
"__error__out_of_bounds;\n ret.value = 0;\n return ret;\n } while (0);\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\n// wuffs_base__render_number__first_hundred contains the decimal encodings of\n// the first one hundred numbers [0 ..= 99].\nstatic const uint8_t wuffs_base__render_number__first_hundred[200] = {\n '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', //\n '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', //\n '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', //\n '1', '5', '1', '6', '1', '7', '1', '8', '1', '9', //\n '2', '0', '2', '1', '2', '2', '2', '3', '2', '4', //\n '2', '5', '2', '6', '2', '7', '2', '8', '2', '9', //\n '3', '0', '3', '1', '3', '2', '3', '3', '3', '4', //\n '3', '5', '3', '6', '3', '7', '3', '8', '3', '9', //\n '4', '0', '4', '1', '4', '2', '4', '3', '4', '4', //\n '4', '5', '4', '6', '4', '7', '4', '8', '4', '9', //\n '5', '0', '5', '1', '5', '2', '5', '3', '5', '4', //\n '5', '5', '5', '6', '5', '7', '5', '8', '5', '9', //\n '6', '0', '6', '1', '6', '2', '6', '3', '6', '4', //\n '6', '5', '6', '6', '6', '7', '6', '8', '6', '9', //\n '" +
|
||||
"7', '0', '7', '1', '7', '2', '7', '3', '7', '4', //\n '7', '5', '7', '6', '7', '7', '7', '8', '7', '9', //\n '8', '0', '8', '1', '8', '2', '8', '3', '8', '4', //\n '8', '5', '8', '6', '8', '7', '8', '8', '8', '9', //\n '9', '0', '9', '1', '9', '2', '9', '3', '9', '4', //\n '9', '5', '9', '6', '9', '7', '9', '8', '9', '9', //\n};\n\nstatic size_t //\nwuffs_base__private_implementation__render_number_u64(wuffs_base__slice_u8 dst,\n uint64_t x,\n uint32_t options,\n bool neg) {\n uint8_t buf[WUFFS_BASE__U64__BYTE_LENGTH__MAX_INCL];\n uint8_t* ptr = &buf[0] + sizeof(buf);\n\n while (x >= 100) {\n size_t index = ((size_t)((x % 100) * 2));\n x /= 100;\n uint8_t s0 = wuffs_base__render_number__first_hundred[index + 0];\n uint8_t s1 = wuffs_base__render_number__first_hundred[index + 1];\n ptr -= 2;\n ptr[0] = s0;\n ptr[1] = s1;\n }\n\n if " +
|
||||
@@ -706,45 +714,46 @@ const BasePixConvSubmoduleC = "" +
|
||||
" size_t dst_len,\n uint8_t* dst_palette_ptr,\n size_t dst_palette_len,\n const uint8_t* src_ptr,\n size_t src_len) {\n size_t dst_len8 = dst_len / 8;\n size_t len = (dst_len8 < src_len) ? dst_len8 : src_len;\n uint8_t* d = dst_ptr;\n const uint8_t* s = src_ptr;\n size_t n = len;\n\n while (n >= 1) {\n wuffs_base__poke_u64le__no_bounds_check(\n d + (0 * 8), 0xFFFF000000000000 | (0x010101010101 * (uint64_t)s[0]));\n\n s += 1 * 1;\n d += 1 * 8;\n n -= 1;\n }\n\n return len;\n}\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__xxxxxxxx__y_16be(uint8_t* dst_ptr,\n size_t dst_len,\n uint8_t* dst_palette_ptr,\n size_t dst_palette_len,\n const uint8_t* src_ptr,\n " +
|
||||
" size_t src_len) {\n size_t dst_len8 = dst_len / 8;\n size_t src_len2 = src_len / 2;\n size_t len = (dst_len8 < src_len2) ? dst_len8 : src_len2;\n uint8_t* d = dst_ptr;\n const uint8_t* s = src_ptr;\n size_t n = len;\n\n while (n >= 1) {\n uint64_t s0 =\n ((uint64_t)(wuffs_base__peek_u16be__no_bounds_check(s + (0 * 2))));\n wuffs_base__poke_u64le__no_bounds_check(\n d + (0 * 8), 0xFFFF000000000000 | (0x000100010001 * s0));\n\n s += 1 * 2;\n d += 1 * 8;\n n -= 1;\n }\n\n return len;\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__y__y_16be(uint8_t* dst_ptr,\n size_t dst_len,\n uint8_t* dst_palette_ptr,\n size_t dst_palette_len,\n const uint8_t* src_ptr,\n size_t src_len) {\n size_t src_len2 = src_len / 2;\n size_t len = (dst_len < src_len2) ? dst_len : src_len2;\n uint8_t* d = dst_ptr;\n const uint8_t* s = src_ptr;\n size_t n = len;\n\n while (n >= 1) {\n d[0] = s[0];\n\n s += 1 * 2;\n d += 1 * 1;\n n -= 1;\n }\n\n return len;\n}\n\n" +
|
||||
"// --------\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__y__y_16be(uint8_t* dst_ptr,\n size_t dst_len,\n uint8_t* dst_palette_ptr,\n size_t dst_palette_len,\n const uint8_t* src_ptr,\n size_t src_len) {\n size_t src_len2 = src_len / 2;\n size_t len = (dst_len < src_len2) ? dst_len : src_len2;\n uint8_t* d = dst_ptr;\n const uint8_t* s = src_ptr;\n size_t n = len;\n\n while (n >= 1) {\n d[0] = s[0];\n\n s += 1 * 2;\n d += 1 * 1;\n n -= 1;\n }\n\n return len;\n}\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__y_16le__y_16be(uint8_t* dst_ptr,\n size_t dst_len,\n uint8_t* dst_palette_ptr,\n size_t dst_palette_len,\n const uint8_t* src_ptr,\n " +
|
||||
" size_t src_len) {\n size_t dst_len2 = dst_len / 2;\n size_t src_len2 = src_len / 2;\n size_t len = (dst_len2 < src_len2) ? dst_len2 : src_len2;\n uint8_t* d = dst_ptr;\n const uint8_t* s = src_ptr;\n size_t n = len;\n\n while (n >= 1) {\n uint8_t s0 = s[0];\n uint8_t s1 = s[1];\n d[0] = s1;\n d[1] = s0;\n\n s += 1 * 2;\n d += 1 * 2;\n n -= 1;\n }\n\n return len;\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__transparent_black_src(\n uint8_t* dst_ptr,\n size_t dst_len,\n uint8_t* dst_palette_ptr,\n size_t dst_palette_len,\n uint64_t num_pixels,\n uint32_t dst_pixfmt_bytes_per_pixel) {\n uint64_t n = ((uint64_t)dst_len) / dst_pixfmt_bytes_per_pixel;\n if (n > num_pixels) {\n n = num_pixels;\n }\n memset(dst_ptr, 0, ((size_t)(n * dst_pixfmt_bytes_per_pixel)));\n return n;\n}\n\nstatic uint64_t //\nwuffs_base__pixel_swizzler__transparent_black_src_over(\n uint8_t* dst_ptr,\n size_t dst_len,\n uint8_t* dst_palette_ptr,\n size_t dst_palette_len,\n uint64_t num_pixels,\n uint32_t dst_pixfmt_bytes_per_pixel) {\n uint64_t n = ((uint64_t)dst_len) / dst_pixfmt_bytes_per_pixel;\n if (n > num_pixels) {\n n = num_pixels;\n }\n return n;\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__y(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__Y:\n return wuffs_base__pixel_swizzler__copy_1_1;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n return wuffs_base__pixel_swizzler__bgr_565__y;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n return wuffs_base__pixel_swizzler__xxx__y;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BA" +
|
||||
"SE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n if (wuffs_base__cpu_arch__have_x86_sse42()) {\n return wuffs_base__pixel_swizzler__xxxx__y__sse42;\n }\n#endif\n return wuffs_base__pixel_swizzler__xxxx__y;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL_4X16LE:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL_4X16LE:\n return wuffs_base__pixel_swizzler__xxxxxxxx__y;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__y_16be(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n " +
|
||||
" wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__Y:\n return wuffs_base__pixel_swizzler__y__y_16be;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n return wuffs_base__pixel_swizzler__bgr_565__y_16be;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n return wuffs_base__pixel_swizzler__xxx__y_16be;\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n return wuffs_base__pixel_swizzler__xxxx__y_16be;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL_4X16LE:\n" +
|
||||
" case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL_4X16LE:\n return wuffs_base__pixel_swizzler__xxxxxxxx__y_16be;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__indexed__bgra_nonpremul(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__copy_1_1;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n if (wuffs_base__pixel_swizzler__squash_align4_bgr_565_8888(\n " +
|
||||
" dst_palette.ptr, dst_palette.len, src_palette.ptr,\n src_palette.len, true) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__bgr_565__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__bgr_565__index_bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n if (wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src(\n dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,\n src_palette.len) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n " +
|
||||
" return NULL;\n }\n return wuffs_base__pixel_swizzler__xxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__xxx__index_bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__index_bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:" +
|
||||
"\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxxxxxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__index_bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n if (wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src(\n dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,\n src_palette.len) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__xxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n " +
|
||||
" if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__bgra_premul__index_bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(\n dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,\n src_palette.len) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__index_bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_P" +
|
||||
"REMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n if (wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src(\n dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,\n src_palette.len) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__xxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(\n dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,\n src_palette.len) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__bgra_premul__index_bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n // TODO.\n break;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__" +
|
||||
"func //\nwuffs_base__pixel_swizzler__prepare__indexed__bgra_binary(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__copy_1_1;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n if (wuffs_base__pixel_swizzler__squash_align4_bgr_565_8888(\n dst_palette.ptr, dst_palette.len, src_palette.ptr,\n src_palette.len, false) !=\n (WUFFS_BASE__PI" +
|
||||
"XEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr_565__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr_565__index_binary_alpha__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__xxx__index_binary_alpha__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n if " +
|
||||
"(wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__xxxx__index_binary_alpha__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxxxxxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__xxxxxxxx__index_binary_alpha__src_over;\n }\n return" +
|
||||
" NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(\n dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,\n src_palette.len) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__xxx__index_binary_alpha__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(\n dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,\n src_palette.len) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n switch (b" +
|
||||
"lend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__xxxx__index_binary_alpha__src_over;\n }\n return NULL;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__bgr_565(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n return wuffs_base__pixel_swizzler__copy_2_2;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n return wuffs_base__pixel_swizzler__bgr__bgr_565;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n return wuffs_base__pixel_swizzler__bgr" +
|
||||
"w__bgr_565;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:\n return wuffs_base__pixel_swizzler__bgrw_4x16le__bgr_565;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n return wuffs_base__pixel_swizzler__rgbw__bgr_565;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__bgr(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n return wuffs_base__pixel_swizzler__bgr_565__bgr;\n\n case WUFFS_BASE__" +
|
||||
"PIXEL_FORMAT__BGR:\n return wuffs_base__pixel_swizzler__copy_3_3;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n return wuffs_base__pixel_swizzler__bgrw__bgr;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:\n return wuffs_base__pixel_swizzler__bgrw_4x16le__bgr;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n return wuffs_base__pixel_swizzler__swap_rgb_bgr;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n if (wuffs_base__cpu_arch__have_x86_sse42()) {\n return wuffs_base__pixel_swizzler__bgrw__rgb__sse42;\n }\n#endif\n return wuffs_base__pixel_swizzler__bgrw__rgb;\n }\n return NULL;\n}\n\nstatic wuff" +
|
||||
"s_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__bgra_nonpremul(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:" +
|
||||
"\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__copy_4_4;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src_over;\n }\n return NULL;\n\n " +
|
||||
" case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n if (wuffs_base__cpu_arch__have_x86_sse42()) {\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__sse42;\n }\n#endif\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremu" +
|
||||
"l__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n // TODO.\n break;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__bgra_nonpremul_4x16le(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul_4x16le__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul_4x16le__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr__bgra_nonpre" +
|
||||
"mul_4x16le__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul_4x16le__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul_4x16le__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__copy_8_8;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul_4x16le__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n " +
|
||||
" return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul_4x16le__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul_4x16le__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__rgba_nonpremul__bgra_nonpremul_4x16le__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__rgba_nonpremul__bgra_nonpremul_4x16le__src_over;\n }\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul_4x16le__src;\n case WUF" +
|
||||
"FS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul_4x16le__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n // TODO.\n break;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__bgra_premul(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr_565__bgra_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr_565__bgra_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n switch (blend) {\n case WUFFS_BASE_" +
|
||||
"_PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr__bgra_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n s" +
|
||||
"witch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__copy_4_4;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n if (wuffs_base__cpu_arch__have_x86_sse42()) {\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__sse42;\n }\n#endif\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;\n case WUFFS_BASE__PIXEL_BLEN" +
|
||||
"D__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__rgba_premul__src_over;\n }\n return NULL;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__bgrx(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n return wuffs_base__pixel_swizzler__bgr_565__bgrx;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n return wuffs_base__pixel_swizzler__xxx__xxxx;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n return wuffs_base__pixel_swizzler__bgrw__bgrx;\n\n case WUFFS_BASE__PIXEL_FORMAT_" +
|
||||
"_BGRA_NONPREMUL_4X16LE:\n return wuffs_base__pixel_swizzler__bgrw_4x16le__bgrx;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n return wuffs_base__pixel_swizzler__copy_4_4;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n return wuffs_base__pixel_swizzler__bgrw__rgbx;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__rgb(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n return wuffs_base" +
|
||||
"__pixel_swizzler__bgr_565__rgb;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n return wuffs_base__pixel_swizzler__swap_rgb_bgr;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n if (wuffs_base__cpu_arch__have_x86_sse42()) {\n return wuffs_base__pixel_swizzler__bgrw__rgb__sse42;\n }\n#endif\n return wuffs_base__pixel_swizzler__bgrw__rgb;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n return wuffs_base__pixel_swizzler__bgrw_4x16le__rgb;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n return wuffs_base__pixel_swizzler__copy_3_3;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n return wuffs_base__pixel_swizzler__bgrw__bgr;\n }\n return NULL;\n}\n\nstatic wuffs" +
|
||||
"_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__rgba_nonpremul(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr_565__rgba_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr_565__rgba_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n" +
|
||||
" switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n if (wuffs_base__cpu_arch__have_x86_sse42()) {\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__sse42;\n }\n#endif\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_" +
|
||||
"premul__rgba_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__copy_4_4;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul" +
|
||||
"__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n // TODO.\n break;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__rgba_premul(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr_565__rgba_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr_565__rgba_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr__rgba_premul__src;\n case WUFFS_BASE_" +
|
||||
"_PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n " +
|
||||
"if (wuffs_base__cpu_arch__have_x86_sse42()) {\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__sse42;\n }\n#endif\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__rgba_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__copy_4_4;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_premul__src_over;\n }\n ret" +
|
||||
"urn NULL;\n }\n return NULL;\n}\n\n" +
|
||||
" wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__Y:\n return wuffs_base__pixel_swizzler__y__y_16be;\n\n case WUFFS_BASE__PIXEL_FORMAT__Y_16LE:\n return wuffs_base__pixel_swizzler__y_16le__y_16be;\n\n case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:\n return wuffs_base__pixel_swizzler__copy_2_2;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n return wuffs_base__pixel_swizzler__bgr_565__y_16be;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n return wuffs_base__pixel_swizzler__xxx__y_16be;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n return wuffs_base__pixel_swizzler__xxx" +
|
||||
"x__y_16be;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL_4X16LE:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL_4X16LE:\n return wuffs_base__pixel_swizzler__xxxxxxxx__y_16be;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__indexed__bgra_nonpremul(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__copy_1_1;\n }\n return NULL;" +
|
||||
"\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n if (wuffs_base__pixel_swizzler__squash_align4_bgr_565_8888(\n dst_palette.ptr, dst_palette.len, src_palette.ptr,\n src_palette.len, true) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__bgr_565__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__bgr_565__index_bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n if (wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src(\n " +
|
||||
" dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,\n src_palette.len) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__xxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__xxx__index_bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_O" +
|
||||
"VER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__index_bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxxxxxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__index_bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n if (wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src(\n dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,\n src_palette.len) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__P" +
|
||||
"ALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__xxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__bgra_premul__index_bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(\n dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,\n src_palette.len) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxxx__index__src;\n case WUFFS_BASE__PI" +
|
||||
"XEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__index_bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n if (wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src(\n dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,\n src_palette.len) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__xxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(\n dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,\n src_palette.len) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n return wuffs_base__pixel_swizzler__bgra_premul__ind" +
|
||||
"ex_bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n // TODO.\n break;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__indexed__bgra_binary(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__INDEXED__BGRA_BINARY:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__copy_1_1;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n if (wuff" +
|
||||
"s_base__pixel_swizzler__squash_align4_bgr_565_8888(\n dst_palette.ptr, dst_palette.len, src_palette.ptr,\n src_palette.len, false) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr_565__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr_565__index_binary_alpha__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__xxx__index_binary_alpha__src_over;\n " +
|
||||
" }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__xxxx__index_binary_alpha__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:\n if (wuffs_base__slice_u8__copy_from_slice(dst_palette, src_palette) !=\n WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_sw" +
|
||||
"izzler__xxxxxxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__xxxxxxxx__index_binary_alpha__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(\n dst_palette.ptr, dst_palette.len, NULL, 0, src_palette.ptr,\n src_palette.len) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__xxx__index_binary_alpha__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n if (wuffs_base__pixel_swizzler__swap_rgbx_bgrx(\n dst_palette.ptr, dst_palette." +
|
||||
"len, NULL, 0, src_palette.ptr,\n src_palette.len) !=\n (WUFFS_BASE__PIXEL_FORMAT__INDEXED__PALETTE_BYTE_LENGTH / 4)) {\n return NULL;\n }\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__xxxx__index__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__xxxx__index_binary_alpha__src_over;\n }\n return NULL;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__bgr_565(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n return wuffs_base__pixel_swizzler__copy_2_2;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n return wuffs_base__pixel_swizzler__bgr__bgr_565;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL" +
|
||||
":\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n return wuffs_base__pixel_swizzler__bgrw__bgr_565;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:\n return wuffs_base__pixel_swizzler__bgrw_4x16le__bgr_565;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n return wuffs_base__pixel_swizzler__rgbw__bgr_565;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__bgr(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n " +
|
||||
"wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n return wuffs_base__pixel_swizzler__bgr_565__bgr;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n return wuffs_base__pixel_swizzler__copy_3_3;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n return wuffs_base__pixel_swizzler__bgrw__bgr;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL_4X16LE:\n return wuffs_base__pixel_swizzler__bgrw_4x16le__bgr;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n return wuffs_base__pixel_swizzler__swap_rgb_bgr;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n if (wuffs_base__cpu_arch" +
|
||||
"__have_x86_sse42()) {\n return wuffs_base__pixel_swizzler__bgrw__rgb__sse42;\n }\n#endif\n return wuffs_base__pixel_swizzler__bgrw__rgb;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__bgra_nonpremul(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src;\n case WUFFS_" +
|
||||
"BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__copy_4_4;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_premul__b" +
|
||||
"gra_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n if (wuffs_base__cpu_arch__have_x86_sse42()) {\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__sse42;\n }\n#endif\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n retur" +
|
||||
"n wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n // TODO.\n break;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__bgra_nonpremul_4x16le(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul_4x16le__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr_565__bgra_nonpremul_4x16le__src_over;\n }\n " +
|
||||
" return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr__bgra_nonpremul_4x16le__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul_4x16le__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul_4x16le__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__copy_8_8;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x" +
|
||||
"16le__bgra_nonpremul_4x16le__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul_4x16le__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul_4x16le__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__rgba_nonpremul__bgra_nonpremul_4x16le__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__rgba_nonpremul__bgra_nonpremul_4x16le__src_over;\n }\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT" +
|
||||
"__RGBA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul_4x16le__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul_4x16le__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n // TODO.\n break;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__bgra_premul(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr_565__bgra_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n " +
|
||||
" return wuffs_base__pixel_swizzler__bgr_565__bgra_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr__bgra_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr__bgra_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__S" +
|
||||
"RC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__bgra_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__copy_4_4;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n if (wuffs_base__cpu_arch__have_x86_sse42()) {\n " +
|
||||
" return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__sse42;\n }\n#endif\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__rgba_premul__src_over;\n }\n return NULL;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__bgrx(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n return wuffs_base__pixel_swizzler__bgr_565__bgrx;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n return wuffs_base__pixel_swizzler__xxx__xxxx;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n " +
|
||||
" case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n return wuffs_base__pixel_swizzler__bgrw__bgrx;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n return wuffs_base__pixel_swizzler__bgrw_4x16le__bgrx;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n return wuffs_base__pixel_swizzler__copy_4_4;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n return wuffs_base__pixel_swizzler__bgrw__rgbx;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__rgb(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 " +
|
||||
"src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n return wuffs_base__pixel_swizzler__bgr_565__rgb;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n return wuffs_base__pixel_swizzler__swap_rgb_bgr;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n if (wuffs_base__cpu_arch__have_x86_sse42()) {\n return wuffs_base__pixel_swizzler__bgrw__rgb__sse42;\n }\n#endif\n return wuffs_base__pixel_swizzler__bgrw__rgb;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n return wuffs_base__pixel_swizzler__bgrw_4x16le__rgb;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n return wuffs_base__pixel_swizzler__copy_3_3;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_" +
|
||||
"PREMUL:\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n return wuffs_base__pixel_swizzler__bgrw__bgr;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__rgba_nonpremul(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr_565__rgba_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr_565__rgba_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGR:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src;\n case WUFFS_B" +
|
||||
"ASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr__rgba_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n if (wuffs_base__cpu_arch__have_x86_sse42()) {\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__sse42;\n }\n#endif\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_nonpremul__src_over;\n }\n " +
|
||||
" return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__rgba_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__BGRX:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGB:\n // TODO.\n break;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__copy_4_4;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return" +
|
||||
" wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_nonpremul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_BINARY:\n case WUFFS_BASE__PIXEL_FORMAT__RGBX:\n // TODO.\n break;\n }\n return NULL;\n}\n\nstatic wuffs_base__pixel_swizzler__func //\nwuffs_base__pixel_swizzler__prepare__rgba_premul(\n wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n switch (dst_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__BGR_565:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr_565__rgba_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr_565__rgba_premul__src_over;\n }\n return NULL;\n\n case WUFFS_" +
|
||||
"BASE__PIXEL_FORMAT__BGR:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgr__rgba_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgr__rgba_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__rgba_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul_4x16le__rgba_premul__src_over;\n }\n " +
|
||||
" return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n#if defined(WUFFS_BASE__CPU_ARCH__X86_64)\n if (wuffs_base__cpu_arch__have_x86_sse42()) {\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx__sse42;\n }\n#endif\n return wuffs_base__pixel_swizzler__swap_rgbx_bgrx;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__rgba_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_NONPREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_nonpremul__bgra_premul__src_over;\n }\n return NULL;\n\n case WUFFS_BASE__PIXEL_FORMAT__RGBA_PREMUL:\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n return w" +
|
||||
"uffs_base__pixel_swizzler__copy_4_4;\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n return wuffs_base__pixel_swizzler__bgra_premul__bgra_premul__src_over;\n }\n return NULL;\n }\n return NULL;\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\nWUFFS_BASE__MAYBE_STATIC wuffs_base__status //\nwuffs_base__pixel_swizzler__prepare(wuffs_base__pixel_swizzler* p,\n wuffs_base__pixel_format dst_pixfmt,\n wuffs_base__slice_u8 dst_palette,\n wuffs_base__pixel_format src_pixfmt,\n wuffs_base__slice_u8 src_palette,\n wuffs_base__pixel_blend blend) {\n if (!p) {\n return wuffs_base__make_status(wuffs_base__error__bad_receiver);\n }\n p->private_impl.func = NULL;\n p->private_impl.transparent_black_func = NULL;\n p->private_impl.dst_pixfmt_bytes_per_pixel = 0;\n p->private_impl.src_pixfmt_bytes_per_pixel = 0;\n\n wuffs_base__pixel_swizzler__func func = NULL;\n wuffs_base__pixel_swizzler__transparent_black_func transparent_black_func =\n NULL;\n\n uint32_t dst_pixfmt_bits_per_pixel =\n wuffs_base__pixel_format__bits_per_pixel(&dst_pixfmt);\n if ((dst_pixfmt_bits_per_pixel == " +
|
||||
"0) ||\n ((dst_pixfmt_bits_per_pixel & 7) != 0)) {\n return wuffs_base__make_status(\n wuffs_base__error__unsupported_pixel_swizzler_option);\n }\n\n uint32_t src_pixfmt_bits_per_pixel =\n wuffs_base__pixel_format__bits_per_pixel(&src_pixfmt);\n if ((src_pixfmt_bits_per_pixel == 0) ||\n ((src_pixfmt_bits_per_pixel & 7) != 0)) {\n return wuffs_base__make_status(\n wuffs_base__error__unsupported_pixel_swizzler_option);\n }\n\n // TODO: support many more formats.\n\n switch (blend) {\n case WUFFS_BASE__PIXEL_BLEND__SRC:\n transparent_black_func =\n wuffs_base__pixel_swizzler__transparent_black_src;\n break;\n\n case WUFFS_BASE__PIXEL_BLEND__SRC_OVER:\n transparent_black_func =\n wuffs_base__pixel_swizzler__transparent_black_src_over;\n break;\n }\n\n switch (src_pixfmt.repr) {\n case WUFFS_BASE__PIXEL_FORMAT__Y:\n func = wuffs_base__pixel_swizzler__prepare__y(p, dst_pixfmt, dst_palette,\n src_palette" +
|
||||
@@ -793,18 +802,18 @@ const AuxBaseHh = "" +
|
||||
|
||||
const AuxCborCc = "" +
|
||||
"// ---------------- Auxiliary - CBOR\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__AUX__CBOR)\n\n#include <utility>\n\nnamespace wuffs_aux {\n\nDecodeCborResult::DecodeCborResult(std::string&& error_message0,\n uint64_t cursor_position0)\n : error_message(std::move(error_message0)),\n cursor_position(cursor_position0) {}\n\nDecodeCborCallbacks::~DecodeCborCallbacks() {}\n\nvoid //\nDecodeCborCallbacks::Done(DecodeCborResult& result,\n sync_io::Input& input,\n IOBuffer& buffer) {}\n\nDecodeCborResult //\nDecodeCbor(DecodeCborCallbacks& callbacks,\n sync_io::Input& input,\n wuffs_base__slice_u32 quirks) {\n // Prepare the wuffs_base__io_buffer and the resultant error_message.\n wuffs_base__io_buffer* io_buf = input.BringsItsOwnIOBuffer();\n wuffs_base__io_buffer fallback_io_buf = wuffs_base__empty_io_buffer();\n std::unique_ptr<uint8_t[]> fallback_io_array(nullptr);\n if (!io_buf) {\n fallback_" +
|
||||
"io_array = std::unique_ptr<uint8_t[]>(new uint8_t[4096]);\n fallback_io_buf = wuffs_base__ptr_u8__writer(fallback_io_array.get(), 4096);\n io_buf = &fallback_io_buf;\n }\n // cursor_index is discussed at\n // https://nigeltao.github.io/blog/2020/jsonptr.html#the-cursor-index\n size_t cursor_index = 0;\n std::string ret_error_message;\n std::string io_error_message;\n\n do {\n // Prepare the low-level CBOR decoder.\n wuffs_cbor__decoder::unique_ptr dec = wuffs_cbor__decoder::alloc();\n if (!dec) {\n ret_error_message = \"wuffs_aux::CborDecoder: out of memory\";\n goto done;\n }\n for (size_t i = 0; i < quirks.len; i++) {\n dec->set_quirk_enabled(quirks.ptr[i], true);\n }\n\n // Prepare the wuffs_base__tok_buffer. 256 tokens is 2KiB.\n wuffs_base__token tok_array[256];\n wuffs_base__token_buffer tok_buf =\n wuffs_base__slice_token__writer(wuffs_base__make_slice_token(\n &tok_array[0], (sizeof(tok_array) / sizeof(tok_array[0]))));\n wuffs_base__status tok_status = " +
|
||||
"wuffs_base__make_status(nullptr);\n\n // Prepare other state.\n uint32_t depth = 0;\n std::string str;\n int64_t extension_category = 0;\n uint64_t extension_detail = 0;\n\n // Valid token's VBCs range in 0 ..= 15. Values over that are for tokens\n // from outside of the base package, such as the CBOR package.\n constexpr int64_t EXT_CAT__CBOR_TAG = 16;\n\n // Loop, doing these two things:\n // 1. Get the next token.\n // 2. Process that token.\n while (true) {\n // 1. Get the next token.\n\n while (tok_buf.meta.ri >= tok_buf.meta.wi) {\n if (tok_status.repr == nullptr) {\n // No-op.\n } else if (tok_status.repr == wuffs_base__suspension__short_write) {\n tok_buf.compact();\n } else if (tok_status.repr == wuffs_base__suspension__short_read) {\n // Read from input to io_buf.\n if (!io_error_message.empty()) {\n ret_error_message = std::move(io_error_message);\n goto done;\n } else if (cursor_index != io_" +
|
||||
"buf->meta.ri) {\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: bad cursor_index\";\n goto done;\n } else if (io_buf->meta.closed) {\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: io_buf is closed\";\n goto done;\n }\n io_buf->compact();\n if (io_buf->meta.wi >= io_buf->data.len) {\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: io_buf is full\";\n goto done;\n }\n cursor_index = io_buf->meta.ri;\n io_error_message = input.CopyIn(io_buf);\n } else {\n ret_error_message = tok_status.message();\n goto done;\n }\n\n if (WUFFS_CBOR__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: bad WORKBUF_LEN\";\n goto done;\n }\n wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8(" +
|
||||
");\n tok_status = dec->decode_tokens(&tok_buf, io_buf, work_buf);\n }\n\n wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++];\n uint64_t token_len = token.length();\n if ((io_buf->meta.ri < cursor_index) ||\n ((io_buf->meta.ri - cursor_index) < token_len)) {\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: bad token indexes\";\n goto done;\n }\n uint8_t* token_ptr = io_buf->data.ptr + cursor_index;\n cursor_index += static_cast<size_t>(token_len);\n\n // 2. Process that token.\n\n uint64_t vbd = token.value_base_detail();\n\n if (extension_category != 0) {\n int64_t ext = token.value_extension();\n if ((ext >= 0) && !token.continued()) {\n extension_detail = (extension_detail\n << WUFFS_BASE__TOKEN__VALUE_EXTENSION__NUM_BITS) |\n static_cast<uint64_t>(ext);\n switch (extension_category) {\n case WUFFS_BASE__TOKEN__VBC__IN" +
|
||||
"LINE_INTEGER_SIGNED:\n extension_category = 0;\n ret_error_message =\n callbacks.AppendI64(static_cast<int64_t>(extension_detail));\n goto parsed_a_value;\n case WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_UNSIGNED:\n extension_category = 0;\n ret_error_message = callbacks.AppendU64(extension_detail);\n goto parsed_a_value;\n case EXT_CAT__CBOR_TAG:\n extension_category = 0;\n ret_error_message = callbacks.AppendCborTag(extension_detail);\n if (!ret_error_message.empty()) {\n goto done;\n }\n continue;\n }\n }\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: bad extended token\";\n goto done;\n }\n\n switch (token.value_base_category()) {\n case WUFFS_BASE__TOKEN__VBC__FILLER:\n continue;\n\n case WUFFS_BASE__TOKEN__VBC__STRUCTURE: {\n if (vbd & WUFFS_" +
|
||||
"BASE__TOKEN__VBD__STRUCTURE__PUSH) {\n ret_error_message = callbacks.Push(static_cast<uint32_t>(vbd));\n if (!ret_error_message.empty()) {\n goto done;\n }\n depth++;\n continue;\n }\n ret_error_message = callbacks.Pop(static_cast<uint32_t>(vbd));\n depth--;\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__STRING: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP) {\n // No-op.\n } else if (vbd &\n WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY) {\n const char* ptr = // Convert from (uint8_t*).\n static_cast<const char*>(static_cast<void*>(token_ptr));\n str.append(ptr, static_cast<size_t>(token_len));\n } else {\n goto fail;\n }\n if (token.continued()) {\n continue;\n }\n ret_error_message =\n (vbd & WUFFS_BASE__T" +
|
||||
"OKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8)\n ? callbacks.AppendTextString(std::move(str))\n : callbacks.AppendByteString(std::move(str));\n str.clear();\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__UNICODE_CODE_POINT: {\n uint8_t u[WUFFS_BASE__UTF_8__BYTE_LENGTH__MAX_INCL];\n size_t n = wuffs_base__utf_8__encode(\n wuffs_base__make_slice_u8(\n &u[0], WUFFS_BASE__UTF_8__BYTE_LENGTH__MAX_INCL),\n static_cast<uint32_t>(vbd));\n const char* ptr = // Convert from (uint8_t*).\n static_cast<const char*>(static_cast<void*>(&u[0]));\n str.append(ptr, n);\n if (token.continued()) {\n continue;\n }\n goto fail;\n }\n\n case WUFFS_BASE__TOKEN__VBC__LITERAL: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__LITERAL__NULL) {\n ret_error_message = callbacks.AppendNull();\n } else if (vbd & WUFFS_BASE__TOKEN__VBD_" +
|
||||
"_LITERAL__UNDEFINED) {\n ret_error_message = callbacks.AppendUndefined();\n } else {\n ret_error_message = callbacks.AppendBool(\n vbd & WUFFS_BASE__TOKEN__VBD__LITERAL__TRUE);\n }\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__NUMBER: {\n const uint64_t cfp_fbbe_fifb =\n WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT |\n WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_BINARY_BIG_ENDIAN |\n WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_IGNORE_FIRST_BYTE;\n if ((vbd & cfp_fbbe_fifb) == cfp_fbbe_fifb) {\n double f;\n switch (token_len) {\n case 3:\n f = wuffs_base__ieee_754_bit_representation__from_u16_to_f64(\n wuffs_base__peek_u16be__no_bounds_check(token_ptr + 1));\n break;\n case 5:\n f = wuffs_base__ieee_754_bit_representation__from_u32_to_f64(\n wuffs_base__peek" +
|
||||
"_u32be__no_bounds_check(token_ptr + 1));\n break;\n case 9:\n f = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n wuffs_base__peek_u64be__no_bounds_check(token_ptr + 1));\n break;\n default:\n goto fail;\n }\n ret_error_message = callbacks.AppendF64(f);\n goto parsed_a_value;\n }\n goto fail;\n }\n\n case WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_SIGNED: {\n if (token.continued()) {\n extension_category = WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_SIGNED;\n extension_detail =\n static_cast<uint64_t>(token.value_base_detail__sign_extended());\n continue;\n }\n ret_error_message =\n callbacks.AppendI64(token.value_base_detail__sign_extended());\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_UNSIGNED: {\n if (token.continu" +
|
||||
"ed()) {\n extension_category =\n WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_UNSIGNED;\n extension_detail = vbd;\n continue;\n }\n ret_error_message = callbacks.AppendU64(vbd);\n goto parsed_a_value;\n }\n }\n\n if (token.value_major() == WUFFS_CBOR__TOKEN_VALUE_MAJOR) {\n uint64_t value_minor = token.value_minor();\n if (value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__MINUS_1_MINUS_X) {\n if (token_len == 9) {\n ret_error_message = callbacks.AppendMinus1MinusX(\n wuffs_base__peek_u64be__no_bounds_check(token_ptr + 1));\n goto parsed_a_value;\n }\n } else if (value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__SIMPLE_VALUE) {\n ret_error_message =\n callbacks.AppendCborSimpleValue(static_cast<uint8_t>(\n value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK));\n goto parsed_a_value;\n } else if (value_minor & WUFFS_CBOR__TOKE" +
|
||||
"N_VALUE_MINOR__TAG) {\n if (token.continued()) {\n extension_category = EXT_CAT__CBOR_TAG;\n extension_detail =\n value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK;\n continue;\n }\n ret_error_message = callbacks.AppendCborTag(\n value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK);\n if (!ret_error_message.empty()) {\n goto done;\n }\n continue;\n }\n }\n\n fail:\n ret_error_message =\n \"wuffs_aux::CborDecoder: internal error: unexpected token\";\n goto done;\n\n parsed_a_value:\n if (!ret_error_message.empty() || (depth == 0)) {\n goto done;\n }\n }\n } while (false);\n\ndone:\n DecodeCborResult result(\n std::move(ret_error_message),\n wuffs_base__u64__sat_add(io_buf->meta.pos, cursor_index));\n callbacks.Done(result, input, *io_buf);\n return result;\n}\n\n} // namespace wuffs_aux\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n " +
|
||||
"// defined(WUFFS_CONFIG__MODULE__AUX__CBOR)\n" +
|
||||
"io_array = std::unique_ptr<uint8_t[]>(new uint8_t[4096]);\n fallback_io_buf = wuffs_base__ptr_u8__writer(fallback_io_array.get(), 4096);\n io_buf = &fallback_io_buf;\n }\n // cursor_index is discussed at\n // https://nigeltao.github.io/blog/2020/jsonptr.html#the-cursor-index\n size_t cursor_index = 0;\n std::string ret_error_message;\n std::string io_error_message;\n\n do {\n // Prepare the low-level CBOR decoder.\n wuffs_cbor__decoder::unique_ptr dec = wuffs_cbor__decoder::alloc();\n if (!dec) {\n ret_error_message = \"wuffs_aux::DecodeCbor: out of memory\";\n goto done;\n }\n for (size_t i = 0; i < quirks.len; i++) {\n dec->set_quirk_enabled(quirks.ptr[i], true);\n }\n\n // Prepare the wuffs_base__tok_buffer. 256 tokens is 2KiB.\n wuffs_base__token tok_array[256];\n wuffs_base__token_buffer tok_buf =\n wuffs_base__slice_token__writer(wuffs_base__make_slice_token(\n &tok_array[0], (sizeof(tok_array) / sizeof(tok_array[0]))));\n wuffs_base__status tok_status = w" +
|
||||
"uffs_base__make_status(nullptr);\n\n // Prepare other state.\n int32_t depth = 0;\n std::string str;\n int64_t extension_category = 0;\n uint64_t extension_detail = 0;\n\n // Valid token's VBCs range in 0 ..= 15. Values over that are for tokens\n // from outside of the base package, such as the CBOR package.\n constexpr int64_t EXT_CAT__CBOR_TAG = 16;\n\n // Loop, doing these two things:\n // 1. Get the next token.\n // 2. Process that token.\n while (true) {\n // 1. Get the next token.\n\n while (tok_buf.meta.ri >= tok_buf.meta.wi) {\n if (tok_status.repr == nullptr) {\n // No-op.\n } else if (tok_status.repr == wuffs_base__suspension__short_write) {\n tok_buf.compact();\n } else if (tok_status.repr == wuffs_base__suspension__short_read) {\n // Read from input to io_buf.\n if (!io_error_message.empty()) {\n ret_error_message = std::move(io_error_message);\n goto done;\n } else if (cursor_index != io_bu" +
|
||||
"f->meta.ri) {\n ret_error_message =\n \"wuffs_aux::DecodeCbor: internal error: bad cursor_index\";\n goto done;\n } else if (io_buf->meta.closed) {\n ret_error_message =\n \"wuffs_aux::DecodeCbor: internal error: io_buf is closed\";\n goto done;\n }\n io_buf->compact();\n if (io_buf->meta.wi >= io_buf->data.len) {\n ret_error_message =\n \"wuffs_aux::DecodeCbor: internal error: io_buf is full\";\n goto done;\n }\n cursor_index = io_buf->meta.ri;\n io_error_message = input.CopyIn(io_buf);\n } else {\n ret_error_message = tok_status.message();\n goto done;\n }\n\n if (WUFFS_CBOR__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {\n ret_error_message =\n \"wuffs_aux::DecodeCbor: internal error: bad WORKBUF_LEN\";\n goto done;\n }\n wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8();\n " +
|
||||
" tok_status = dec->decode_tokens(&tok_buf, io_buf, work_buf);\n if ((tok_buf.meta.ri > tok_buf.meta.wi) ||\n (tok_buf.meta.wi > tok_buf.data.len) ||\n (io_buf->meta.ri > io_buf->meta.wi) ||\n (io_buf->meta.wi > io_buf->data.len)) {\n ret_error_message =\n \"wuffs_aux::DecodeCbor: internal error: bad buffer indexes\";\n goto done;\n }\n }\n\n wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++];\n uint64_t token_len = token.length();\n if ((io_buf->meta.ri < cursor_index) ||\n ((io_buf->meta.ri - cursor_index) < token_len)) {\n ret_error_message =\n \"wuffs_aux::DecodeCbor: internal error: bad token indexes\";\n goto done;\n }\n uint8_t* token_ptr = io_buf->data.ptr + cursor_index;\n cursor_index += static_cast<size_t>(token_len);\n\n // 2. Process that token.\n\n uint64_t vbd = token.value_base_detail();\n\n if (extension_category != 0) {\n int64_t ext = token." +
|
||||
"value_extension();\n if ((ext >= 0) && !token.continued()) {\n extension_detail = (extension_detail\n << WUFFS_BASE__TOKEN__VALUE_EXTENSION__NUM_BITS) |\n static_cast<uint64_t>(ext);\n switch (extension_category) {\n case WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_SIGNED:\n extension_category = 0;\n ret_error_message =\n callbacks.AppendI64(static_cast<int64_t>(extension_detail));\n goto parsed_a_value;\n case WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_UNSIGNED:\n extension_category = 0;\n ret_error_message = callbacks.AppendU64(extension_detail);\n goto parsed_a_value;\n case EXT_CAT__CBOR_TAG:\n extension_category = 0;\n ret_error_message = callbacks.AppendCborTag(extension_detail);\n if (!ret_error_message.empty()) {\n goto done;\n }\n continue;\n " +
|
||||
" }\n }\n ret_error_message =\n \"wuffs_aux::DecodeCbor: internal error: bad extended token\";\n goto done;\n }\n\n switch (token.value_base_category()) {\n case WUFFS_BASE__TOKEN__VBC__FILLER:\n continue;\n\n case WUFFS_BASE__TOKEN__VBC__STRUCTURE: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__STRUCTURE__PUSH) {\n ret_error_message = callbacks.Push(static_cast<uint32_t>(vbd));\n if (!ret_error_message.empty()) {\n goto done;\n }\n depth++;\n if (depth > WUFFS_CBOR__DECODER_DEPTH_MAX_INCL) {\n ret_error_message =\n \"wuffs_aux::DecodeCbor: internal error: bad depth\";\n goto done;\n }\n continue;\n }\n ret_error_message = callbacks.Pop(static_cast<uint32_t>(vbd));\n depth--;\n if (depth < 0) {\n ret_error_message =\n \"wuffs_aux::DecodeCbor: internal error: bad depth\";\n g" +
|
||||
"oto done;\n }\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__STRING: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP) {\n // No-op.\n } else if (vbd &\n WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY) {\n const char* ptr = // Convert from (uint8_t*).\n static_cast<const char*>(static_cast<void*>(token_ptr));\n str.append(ptr, static_cast<size_t>(token_len));\n } else {\n goto fail;\n }\n if (token.continued()) {\n continue;\n }\n ret_error_message =\n (vbd & WUFFS_BASE__TOKEN__VBD__STRING__CHAIN_MUST_BE_UTF_8)\n ? callbacks.AppendTextString(std::move(str))\n : callbacks.AppendByteString(std::move(str));\n str.clear();\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__UNICODE_CODE_POINT: {\n uint8_t u[WUFFS_BASE__" +
|
||||
"UTF_8__BYTE_LENGTH__MAX_INCL];\n size_t n = wuffs_base__utf_8__encode(\n wuffs_base__make_slice_u8(\n &u[0], WUFFS_BASE__UTF_8__BYTE_LENGTH__MAX_INCL),\n static_cast<uint32_t>(vbd));\n const char* ptr = // Convert from (uint8_t*).\n static_cast<const char*>(static_cast<void*>(&u[0]));\n str.append(ptr, n);\n if (token.continued()) {\n continue;\n }\n goto fail;\n }\n\n case WUFFS_BASE__TOKEN__VBC__LITERAL: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__LITERAL__NULL) {\n ret_error_message = callbacks.AppendNull();\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__LITERAL__UNDEFINED) {\n ret_error_message = callbacks.AppendUndefined();\n } else {\n ret_error_message = callbacks.AppendBool(\n vbd & WUFFS_BASE__TOKEN__VBD__LITERAL__TRUE);\n }\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__NUMBER: {\n " +
|
||||
" const uint64_t cfp_fbbe_fifb =\n WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT |\n WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_BINARY_BIG_ENDIAN |\n WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_IGNORE_FIRST_BYTE;\n if ((vbd & cfp_fbbe_fifb) == cfp_fbbe_fifb) {\n double f;\n switch (token_len) {\n case 3:\n f = wuffs_base__ieee_754_bit_representation__from_u16_to_f64(\n wuffs_base__peek_u16be__no_bounds_check(token_ptr + 1));\n break;\n case 5:\n f = wuffs_base__ieee_754_bit_representation__from_u32_to_f64(\n wuffs_base__peek_u32be__no_bounds_check(token_ptr + 1));\n break;\n case 9:\n f = wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n wuffs_base__peek_u64be__no_bounds_check(token_ptr + 1));\n break;\n default:\n goto fail;\n " +
|
||||
" }\n ret_error_message = callbacks.AppendF64(f);\n goto parsed_a_value;\n }\n goto fail;\n }\n\n case WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_SIGNED: {\n if (token.continued()) {\n extension_category = WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_SIGNED;\n extension_detail =\n static_cast<uint64_t>(token.value_base_detail__sign_extended());\n continue;\n }\n ret_error_message =\n callbacks.AppendI64(token.value_base_detail__sign_extended());\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_UNSIGNED: {\n if (token.continued()) {\n extension_category =\n WUFFS_BASE__TOKEN__VBC__INLINE_INTEGER_UNSIGNED;\n extension_detail = vbd;\n continue;\n }\n ret_error_message = callbacks.AppendU64(vbd);\n goto parsed_a_value;\n }\n }\n\n if (token.value_major() == WUFFS_CB" +
|
||||
"OR__TOKEN_VALUE_MAJOR) {\n uint64_t value_minor = token.value_minor();\n if (value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__MINUS_1_MINUS_X) {\n if (token_len == 9) {\n ret_error_message = callbacks.AppendMinus1MinusX(\n wuffs_base__peek_u64be__no_bounds_check(token_ptr + 1));\n goto parsed_a_value;\n }\n } else if (value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__SIMPLE_VALUE) {\n ret_error_message =\n callbacks.AppendCborSimpleValue(static_cast<uint8_t>(\n value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK));\n goto parsed_a_value;\n } else if (value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__TAG) {\n if (token.continued()) {\n extension_category = EXT_CAT__CBOR_TAG;\n extension_detail =\n value_minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK;\n continue;\n }\n ret_error_message = callbacks.AppendCborTag(\n value_" +
|
||||
"minor & WUFFS_CBOR__TOKEN_VALUE_MINOR__DETAIL_MASK);\n if (!ret_error_message.empty()) {\n goto done;\n }\n continue;\n }\n }\n\n fail:\n ret_error_message =\n \"wuffs_aux::DecodeCbor: internal error: unexpected token\";\n goto done;\n\n parsed_a_value:\n if (!ret_error_message.empty() || (depth == 0)) {\n goto done;\n }\n }\n } while (false);\n\ndone:\n DecodeCborResult result(\n std::move(ret_error_message),\n wuffs_base__u64__sat_add(io_buf->meta.pos, cursor_index));\n callbacks.Done(result, input, *io_buf);\n return result;\n}\n\n} // namespace wuffs_aux\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n // defined(WUFFS_CONFIG__MODULE__AUX__CBOR)\n" +
|
||||
""
|
||||
|
||||
const AuxCborHh = "" +
|
||||
@@ -847,31 +856,34 @@ const AuxImageHh = "" +
|
||||
""
|
||||
|
||||
const AuxJsonCc = "" +
|
||||
"// ---------------- Auxiliary - JSON\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__AUX__JSON)\n\n#include <utility>\n\nnamespace wuffs_aux {\n\nDecodeJsonResult::DecodeJsonResult(std::string&& error_message0,\n uint64_t cursor_position0)\n : error_message(std::move(error_message0)),\n cursor_position(cursor_position0) {}\n\nDecodeJsonCallbacks::~DecodeJsonCallbacks() {}\n\nvoid //\nDecodeJsonCallbacks::Done(DecodeJsonResult& result,\n sync_io::Input& input,\n IOBuffer& buffer) {}\n\nconst char DecodeJson_BadJsonPointer[] =\n \"wuffs_aux::DecodeJson: bad JSON Pointer\";\nconst char DecodeJson_NoMatch[] = \"wuffs_aux::DecodeJson: no match\";\n\n" +
|
||||
"// ---------------- Auxiliary - JSON\n\n#if !defined(WUFFS_CONFIG__MODULES) || defined(WUFFS_CONFIG__MODULE__AUX__JSON)\n\n#include <utility>\n\nnamespace wuffs_aux {\n\nDecodeJsonResult::DecodeJsonResult(std::string&& error_message0,\n uint64_t cursor_position0)\n : error_message(std::move(error_message0)),\n cursor_position(cursor_position0) {}\n\nDecodeJsonCallbacks::~DecodeJsonCallbacks() {}\n\nvoid //\nDecodeJsonCallbacks::Done(DecodeJsonResult& result,\n sync_io::Input& input,\n IOBuffer& buffer) {}\n\nconst char DecodeJson_BadJsonPointer[] = //\n \"wuffs_aux::DecodeJson: bad JSON Pointer\";\nconst char DecodeJson_NoMatch[] = //\n \"wuffs_aux::DecodeJson: no match\";\n\n" +
|
||||
"" +
|
||||
"// --------\n\n#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \\\n while (tok_buf.meta.ri >= tok_buf.meta.wi) { \\\n if (tok_status.repr == nullptr) { \\\n } else if (tok_status.repr == wuffs_base__suspension__short_write) { \\\n tok_buf.compact(); \\\n } else if (tok_status.repr == wuffs_base__suspension__short_read) { \\\n if (!io_error_message.empty()) { \\\n ret_error_message = std::move(io_error_message); \\\n goto done; \\\n } else if (cursor_index != io_buf->meta.ri) { \\\n ret_error_message = \\\n \"wuffs_aux::DecodeJson: internal error: bad cursor_index\"; \\\n goto done; \\\n } else if (io_buf->meta.closed" +
|
||||
") { \\\n ret_error_message = \\\n \"wuffs_aux::DecodeJson: internal error: io_buf is closed\"; \\\n goto done; \\\n } \\\n io_buf->compact(); \\\n if (io_buf->meta.wi >= io_buf->data.len) { \\\n ret_error_message = \\\n \"wuffs_aux::DecodeJson: internal error: io_buf is full\"; \\\n goto done; \\\n } \\\n cursor_index = io_buf->meta.ri; \\\n io_error_message = input.CopyIn(io_buf); \\\n } else { \\\n ret_" +
|
||||
"error_message = tok_status.message(); \\\n goto done; \\\n } \\\n if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) { \\\n ret_error_message = \\\n \"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN\"; \\\n goto done; \\\n } \\\n wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8(); \\\n tok_status = dec->decode_tokens(&tok_buf, io_buf, work_buf); \\\n } \\\n wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \\\n uint64_t token_len = token.length(); \\\n if ((io_buf->meta.ri < cursor_index) || " +
|
||||
" \\\n ((io_buf->meta.ri - cursor_index) < token_len)) { \\\n ret_error_message = \\\n \"wuffs_aux::DecodeJson: internal error: bad token indexes\"; \\\n goto done; \\\n } \\\n uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \\\n (void)(token_ptr); \\\n cursor_index += static_cast<size_t>(token_len)\n\n" +
|
||||
"// --------\n\n#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \\\n while (tok_buf.meta.ri >= tok_buf.meta.wi) { \\\n if (tok_status.repr == nullptr) { \\\n goto done; \\\n } else if (tok_status.repr == wuffs_base__suspension__short_write) { \\\n tok_buf.compact(); \\\n } else if (tok_status.repr == wuffs_base__suspension__short_read) { \\\n if (!io_error_message.empty()) { \\\n ret_error_message = std::move(io_error_message); \\\n goto done; \\\n } else if (cursor_index != io_buf->meta.ri) { \\\n ret_error_message = \\\n \"wuffs_aux::DecodeJson: internal error: bad cursor_index\"; " +
|
||||
" \\\n goto done; \\\n } else if (io_buf->meta.closed) { \\\n ret_error_message = \\\n \"wuffs_aux::DecodeJson: internal error: io_buf is closed\"; \\\n goto done; \\\n } \\\n io_buf->compact(); \\\n if (io_buf->meta.wi >= io_buf->data.len) { \\\n ret_error_message = \\\n \"wuffs_aux::DecodeJson: internal error: io_buf is full\"; \\\n goto done; \\\n } \\\n cursor_index = io_buf->meta.ri; \\\n i" +
|
||||
"o_error_message = input.CopyIn(io_buf); \\\n } else { \\\n ret_error_message = tok_status.message(); \\\n goto done; \\\n } \\\n tok_status = \\\n dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8()); \\\n if ((tok_buf.meta.ri > tok_buf.meta.wi) || \\\n (tok_buf.meta.wi > tok_buf.data.len) || \\\n (io_buf->meta.ri > io_buf->meta.wi) || \\\n (io_buf->meta.wi > io_buf->data.len)) { \\\n ret_error_message = \\\n \"wuffs_aux::DecodeJson: internal error: bad buffer indexes\"; \\\n goto done; " +
|
||||
" \\\n } \\\n } \\\n wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \\\n uint64_t token_len = token.length(); \\\n if ((io_buf->meta.ri < cursor_index) || \\\n ((io_buf->meta.ri - cursor_index) < token_len)) { \\\n ret_error_message = \\\n \"wuffs_aux::DecodeJson: internal error: bad token indexes\"; \\\n goto done; \\\n } \\\n uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \\\n (void)(token_ptr); \\\n cursor_index += static_ca" +
|
||||
"st<size_t>(token_len)\n\n" +
|
||||
"" +
|
||||
"// --------\n\nnamespace {\n\n// DecodeJson_SplitJsonPointer returns (\"bar\", 8) for (\"/foo/bar/b~1z/qux\", 5,\n// etc). It returns a 0 size_t when s has invalid JSON Pointer syntax.\n//\n// The string returned is unescaped. If calling it again, this time with i=8,\n// the \"b~1z\" substring would be returned as \"b/z\".\nstd::pair<std::string, size_t> //\nDecodeJson_SplitJsonPointer(std::string& s,\n size_t i,\n bool allow_tilde_n_tilde_r_tilde_t) {\n std::string fragment;\n while (i < s.size()) {\n char c = s[i];\n if (c == '/') {\n break;\n } else if (c != '~') {\n fragment.push_back(c);\n i++;\n continue;\n }\n i++;\n if (i >= s.size()) {\n return std::make_pair(std::string(), 0);\n }\n c = s[i];\n if (c == '0') {\n fragment.push_back('~');\n i++;\n continue;\n } else if (c == '1') {\n fragment.push_back('/');\n i++;\n continue;\n } else if (allow_tilde_n_tilde_r_tilde_t) {\n if (c == 'n') {\n " +
|
||||
"fragment.push_back('\\n');\n i++;\n continue;\n } else if (c == 'r') {\n fragment.push_back('\\r');\n i++;\n continue;\n } else if (c == 't') {\n fragment.push_back('\\t');\n i++;\n continue;\n }\n }\n return std::make_pair(std::string(), 0);\n }\n return std::make_pair(std::move(fragment), i);\n}\n\n" +
|
||||
"// --------\n\nnamespace {\n\n// DecodeJson_SplitJsonPointer returns (\"bar\", 8) for (\"/foo/bar/b~1z/qux\", 5,\n// etc). It returns a 0 size_t when s has invalid JSON Pointer syntax or i is\n// out of bounds.\n//\n// The string returned is unescaped. If calling it again, this time with i=8,\n// the \"b~1z\" substring would be returned as \"b/z\".\nstd::pair<std::string, size_t> //\nDecodeJson_SplitJsonPointer(std::string& s,\n size_t i,\n bool allow_tilde_n_tilde_r_tilde_t) {\n std::string fragment;\n if (i > s.size()) {\n return std::make_pair(std::string(), 0);\n }\n while (i < s.size()) {\n char c = s[i];\n if (c == '/') {\n break;\n } else if (c != '~') {\n fragment.push_back(c);\n i++;\n continue;\n }\n i++;\n if (i >= s.size()) {\n return std::make_pair(std::string(), 0);\n }\n c = s[i];\n if (c == '0') {\n fragment.push_back('~');\n i++;\n continue;\n } else if (c == '1') {\n fragment.push_back('/');\n i++" +
|
||||
";\n continue;\n } else if (allow_tilde_n_tilde_r_tilde_t) {\n if (c == 'n') {\n fragment.push_back('\\n');\n i++;\n continue;\n } else if (c == 'r') {\n fragment.push_back('\\r');\n i++;\n continue;\n } else if (c == 't') {\n fragment.push_back('\\t');\n i++;\n continue;\n }\n }\n return std::make_pair(std::string(), 0);\n }\n return std::make_pair(std::move(fragment), i);\n}\n\n" +
|
||||
"" +
|
||||
"// --------\n\nstd::string //\nDecodeJson_WalkJsonPointerFragment(wuffs_base__token_buffer& tok_buf,\n wuffs_base__status& tok_status,\n wuffs_json__decoder::unique_ptr& dec,\n wuffs_base__io_buffer* io_buf,\n std::string& io_error_message,\n size_t& cursor_index,\n sync_io::Input& input,\n std::string& json_pointer_fragment) {\n std::string ret_error_message;\n while (true) {\n WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN;\n\n int64_t vbc = token.value_base_category();\n uint64_t vbd = token.value_base_detail();\n if (vbc == WUFFS_BASE__TOKEN__VBC__FILLER) {\n continue;\n } else if ((vbc != WUFFS_BASE__TOKEN__VBC__STRUCTURE) ||\n !(vbd & WUFFS_BASE__TOKEN__VBD__STRUCTURE__PUSH)) {\n return DecodeJson_NoMatch;\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__ST" +
|
||||
"RUCTURE__TO_LIST) {\n goto do_list;\n }\n goto do_dict;\n }\n\ndo_dict:\n // Alternate between these two things:\n // 1. Decode the next dict key (a string). If it matches the fragment, we're\n // done (success). If we've reached the dict's end (VBD__STRUCTURE__POP)\n // so that there was no next dict key, we're done (failure).\n // 2. Otherwise, skip the next dict value.\n while (true) {\n for (std::string str; true;) {\n WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN;\n\n int64_t vbc = token.value_base_category();\n uint64_t vbd = token.value_base_detail();\n switch (vbc) {\n case WUFFS_BASE__TOKEN__VBC__FILLER:\n continue;\n\n case WUFFS_BASE__TOKEN__VBC__STRUCTURE:\n if (vbd & WUFFS_BASE__TOKEN__VBD__STRUCTURE__PUSH) {\n goto fail;\n }\n return DecodeJson_NoMatch;\n\n case WUFFS_BASE__TOKEN__VBC__STRING: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP) {\n // No-op.\n } els" +
|
||||
"e if (vbd &\n WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY) {\n const char* ptr = // Convert from (uint8_t*).\n static_cast<const char*>(static_cast<void*>(token_ptr));\n str.append(ptr, static_cast<size_t>(token_len));\n } else {\n goto fail;\n }\n break;\n }\n\n case WUFFS_BASE__TOKEN__VBC__UNICODE_CODE_POINT: {\n uint8_t u[WUFFS_BASE__UTF_8__BYTE_LENGTH__MAX_INCL];\n size_t n = wuffs_base__utf_8__encode(\n wuffs_base__make_slice_u8(\n &u[0], WUFFS_BASE__UTF_8__BYTE_LENGTH__MAX_INCL),\n static_cast<uint32_t>(vbd));\n const char* ptr = // Convert from (uint8_t*).\n static_cast<const char*>(static_cast<void*>(&u[0]));\n str.append(ptr, n);\n break;\n }\n\n default:\n goto fail;\n }\n\n if (token.continued()) {\n continue;\n }\n if (str == json_pointer_fragment) {\n " +
|
||||
" return \"\";\n }\n goto skip_the_next_dict_value;\n }\n\n skip_the_next_dict_value:\n for (uint32_t skip_depth = 0; true;) {\n WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN;\n\n int64_t vbc = token.value_base_category();\n uint64_t vbd = token.value_base_detail();\n if (token.continued() || (vbc == WUFFS_BASE__TOKEN__VBC__FILLER)) {\n continue;\n } else if (vbc == WUFFS_BASE__TOKEN__VBC__STRUCTURE) {\n if (vbd & WUFFS_BASE__TOKEN__VBD__STRUCTURE__PUSH) {\n skip_depth++;\n continue;\n }\n skip_depth--;\n }\n\n if (skip_depth == 0) {\n break;\n }\n } // skip_the_next_dict_value\n } // do_dict\n\ndo_list:\n do {\n wuffs_base__result_u64 result_u64 = wuffs_base__parse_number_u64(\n wuffs_base__make_slice_u8(\n static_cast<uint8_t*>(static_cast<void*>(\n const_cast<char*>(json_pointer_fragment.data()))),\n json_pointer_fragment.size()),\n WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTI" +
|
||||
"ONS);\n if (!result_u64.status.is_ok()) {\n return DecodeJson_NoMatch;\n }\n uint64_t remaining = result_u64.value;\n if (remaining == 0) {\n goto check_that_a_value_follows;\n }\n for (uint32_t skip_depth = 0; true;) {\n WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN;\n\n int64_t vbc = token.value_base_category();\n uint64_t vbd = token.value_base_detail();\n if (token.continued() || (vbc == WUFFS_BASE__TOKEN__VBC__FILLER)) {\n continue;\n } else if (vbc == WUFFS_BASE__TOKEN__VBC__STRUCTURE) {\n if (vbd & WUFFS_BASE__TOKEN__VBD__STRUCTURE__PUSH) {\n skip_depth++;\n continue;\n }\n if (skip_depth == 0) {\n return DecodeJson_NoMatch;\n }\n skip_depth--;\n }\n\n if (skip_depth > 0) {\n continue;\n }\n remaining--;\n if (remaining == 0) {\n goto check_that_a_value_follows;\n }\n }\n } while (false); // do_list\n\ncheck_that_a_value_follows:\n while (true) {\n WUFFS_AUX__DECODE_JSON" +
|
||||
"__GET_THE_NEXT_TOKEN;\n\n int64_t vbc = token.value_base_category();\n uint64_t vbd = token.value_base_detail();\n if (vbc == WUFFS_BASE__TOKEN__VBC__FILLER) {\n continue;\n }\n\n // Undo the last part of WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN, so that\n // we're only peeking at the next token.\n tok_buf.meta.ri--;\n cursor_index -= static_cast<size_t>(token_len);\n\n if ((vbc == WUFFS_BASE__TOKEN__VBC__STRUCTURE) &&\n (vbd & WUFFS_BASE__TOKEN__VBD__STRUCTURE__POP)) {\n return DecodeJson_NoMatch;\n }\n return \"\";\n } // check_that_a_value_follows\n\nfail:\n return \"wuffs_aux::DecodeJson: internal error: unexpected token\";\ndone:\n return ret_error_message;\n}\n\n} // namespace\n\n" +
|
||||
"__GET_THE_NEXT_TOKEN;\n\n int64_t vbc = token.value_base_category();\n uint64_t vbd = token.value_base_detail();\n if (vbc == WUFFS_BASE__TOKEN__VBC__FILLER) {\n continue;\n }\n\n // Undo the last part of WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN, so\n // that we're only peeking at the next token.\n tok_buf.meta.ri--;\n cursor_index -= static_cast<size_t>(token_len);\n\n if ((vbc == WUFFS_BASE__TOKEN__VBC__STRUCTURE) &&\n (vbd & WUFFS_BASE__TOKEN__VBD__STRUCTURE__POP)) {\n return DecodeJson_NoMatch;\n }\n return \"\";\n } // check_that_a_value_follows\n\nfail:\n return \"wuffs_aux::DecodeJson: internal error: unexpected token\";\ndone:\n return ret_error_message;\n}\n\n} // namespace\n\n" +
|
||||
"" +
|
||||
"// --------\n\nDecodeJsonResult //\nDecodeJson(DecodeJsonCallbacks& callbacks,\n sync_io::Input& input,\n wuffs_base__slice_u32 quirks,\n std::string json_pointer) {\n // Prepare the wuffs_base__io_buffer and the resultant error_message.\n wuffs_base__io_buffer* io_buf = input.BringsItsOwnIOBuffer();\n wuffs_base__io_buffer fallback_io_buf = wuffs_base__empty_io_buffer();\n std::unique_ptr<uint8_t[]> fallback_io_array(nullptr);\n if (!io_buf) {\n fallback_io_array = std::unique_ptr<uint8_t[]>(new uint8_t[4096]);\n fallback_io_buf = wuffs_base__ptr_u8__writer(fallback_io_array.get(), 4096);\n io_buf = &fallback_io_buf;\n }\n // cursor_index is discussed at\n // https://nigeltao.github.io/blog/2020/jsonptr.html#the-cursor-index\n size_t cursor_index = 0;\n std::string ret_error_message;\n std::string io_error_message;\n\n do {\n // Prepare the low-level JSON decoder.\n wuffs_json__decoder::unique_ptr dec = wuffs_json__decoder::alloc();\n if (!dec) {\n ret_error_message = " +
|
||||
"\"wuffs_aux::DecodeJson: out of memory\";\n goto done;\n }\n bool allow_tilde_n_tilde_r_tilde_t = false;\n for (size_t i = 0; i < quirks.len; i++) {\n dec->set_quirk_enabled(quirks.ptr[i], true);\n if (quirks.ptr[i] ==\n WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T) {\n allow_tilde_n_tilde_r_tilde_t = true;\n }\n }\n\n // Prepare the wuffs_base__tok_buffer. 256 tokens is 2KiB.\n wuffs_base__token tok_array[256];\n wuffs_base__token_buffer tok_buf =\n wuffs_base__slice_token__writer(wuffs_base__make_slice_token(\n &tok_array[0], (sizeof(tok_array) / sizeof(tok_array[0]))));\n wuffs_base__status tok_status = wuffs_base__make_status(nullptr);\n\n // Prepare other state.\n uint32_t depth = 0;\n std::string str;\n\n // Walk the (optional) JSON Pointer.\n for (size_t i = 0; i < json_pointer.size();) {\n if (json_pointer[i] != '/') {\n ret_error_message = DecodeJson_BadJsonPointer;\n goto done;\n }\n std::pair<" +
|
||||
"std::string, size_t> split = DecodeJson_SplitJsonPointer(\n json_pointer, i + 1, allow_tilde_n_tilde_r_tilde_t);\n i = std::move(split.second);\n if (i == 0) {\n ret_error_message = DecodeJson_BadJsonPointer;\n goto done;\n }\n ret_error_message = DecodeJson_WalkJsonPointerFragment(\n tok_buf, tok_status, dec, io_buf, io_error_message, cursor_index,\n input, split.first);\n if (!ret_error_message.empty()) {\n goto done;\n }\n }\n\n // Loop, doing these two things:\n // 1. Get the next token.\n // 2. Process that token.\n while (true) {\n WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN;\n\n int64_t vbc = token.value_base_category();\n uint64_t vbd = token.value_base_detail();\n switch (vbc) {\n case WUFFS_BASE__TOKEN__VBC__FILLER:\n continue;\n\n case WUFFS_BASE__TOKEN__VBC__STRUCTURE: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__STRUCTURE__PUSH) {\n ret_error_message = callbacks.Push(static_cas" +
|
||||
"t<uint32_t>(vbd));\n if (!ret_error_message.empty()) {\n goto done;\n }\n depth++;\n continue;\n }\n ret_error_message = callbacks.Pop(static_cast<uint32_t>(vbd));\n depth--;\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__STRING: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP) {\n // No-op.\n } else if (vbd &\n WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY) {\n const char* ptr = // Convert from (uint8_t*).\n static_cast<const char*>(static_cast<void*>(token_ptr));\n str.append(ptr, static_cast<size_t>(token_len));\n } else {\n goto fail;\n }\n if (token.continued()) {\n continue;\n }\n ret_error_message = callbacks.AppendTextString(std::move(str));\n str.clear();\n goto parsed_a_value;\n }\n\n case WUFFS_" +
|
||||
"BASE__TOKEN__VBC__UNICODE_CODE_POINT: {\n uint8_t u[WUFFS_BASE__UTF_8__BYTE_LENGTH__MAX_INCL];\n size_t n = wuffs_base__utf_8__encode(\n wuffs_base__make_slice_u8(\n &u[0], WUFFS_BASE__UTF_8__BYTE_LENGTH__MAX_INCL),\n static_cast<uint32_t>(vbd));\n const char* ptr = // Convert from (uint8_t*).\n static_cast<const char*>(static_cast<void*>(&u[0]));\n str.append(ptr, n);\n if (token.continued()) {\n continue;\n }\n goto fail;\n }\n\n case WUFFS_BASE__TOKEN__VBC__LITERAL: {\n ret_error_message =\n (vbd & WUFFS_BASE__TOKEN__VBD__LITERAL__NULL)\n ? callbacks.AppendNull()\n : callbacks.AppendBool(vbd &\n WUFFS_BASE__TOKEN__VBD__LITERAL__TRUE);\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__NUMBER: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_TEXT) {\n " +
|
||||
" if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_INTEGER_SIGNED) {\n wuffs_base__result_i64 r = wuffs_base__parse_number_i64(\n wuffs_base__make_slice_u8(token_ptr,\n static_cast<size_t>(token_len)),\n WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);\n if (r.status.is_ok()) {\n ret_error_message = callbacks.AppendI64(r.value);\n goto parsed_a_value;\n }\n }\n if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT) {\n wuffs_base__result_f64 r = wuffs_base__parse_number_f64(\n wuffs_base__make_slice_u8(token_ptr,\n static_cast<size_t>(token_len)),\n WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);\n if (r.status.is_ok()) {\n ret_error_message = callbacks.AppendF64(r.value);\n goto parsed_a_value;\n }" +
|
||||
"\n }\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_NEG_INF) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n 0xFFF0000000000000ul));\n goto parsed_a_value;\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_POS_INF) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n 0x7FF0000000000000ul));\n goto parsed_a_value;\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_NEG_NAN) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n 0xFFFFFFFFFFFFFFFFul));\n goto parsed_a_value;\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_POS_NAN) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee" +
|
||||
"_754_bit_representation__from_u64_to_f64(\n 0x7FFFFFFFFFFFFFFFul));\n goto parsed_a_value;\n }\n goto fail;\n }\n }\n\n fail:\n ret_error_message =\n \"wuffs_aux::DecodeJson: internal error: unexpected token\";\n goto done;\n\n parsed_a_value:\n if (!ret_error_message.empty() || (depth == 0)) {\n goto done;\n }\n }\n } while (false);\n\ndone:\n DecodeJsonResult result(\n std::move(ret_error_message),\n wuffs_base__u64__sat_add(io_buf->meta.pos, cursor_index));\n callbacks.Done(result, input, *io_buf);\n return result;\n}\n\n#undef WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN\n\n} // namespace wuffs_aux\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n // defined(WUFFS_CONFIG__MODULE__AUX__JSON)\n" +
|
||||
"\"wuffs_aux::DecodeJson: out of memory\";\n goto done;\n } else if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {\n ret_error_message =\n \"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN\";\n goto done;\n }\n bool allow_tilde_n_tilde_r_tilde_t = false;\n for (size_t i = 0; i < quirks.len; i++) {\n dec->set_quirk_enabled(quirks.ptr[i], true);\n if (quirks.ptr[i] ==\n WUFFS_JSON__QUIRK_JSON_POINTER_ALLOW_TILDE_N_TILDE_R_TILDE_T) {\n allow_tilde_n_tilde_r_tilde_t = true;\n }\n }\n\n // Prepare the wuffs_base__tok_buffer. 256 tokens is 2KiB.\n wuffs_base__token tok_array[256];\n wuffs_base__token_buffer tok_buf =\n wuffs_base__slice_token__writer(wuffs_base__make_slice_token(\n &tok_array[0], (sizeof(tok_array) / sizeof(tok_array[0]))));\n wuffs_base__status tok_status =\n dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8());\n\n // Prepare other state.\n int32_t depth = 0;\n std::string str;\n" +
|
||||
"\n // Walk the (optional) JSON Pointer.\n for (size_t i = 0; i < json_pointer.size();) {\n if (json_pointer[i] != '/') {\n ret_error_message = DecodeJson_BadJsonPointer;\n goto done;\n }\n std::pair<std::string, size_t> split = DecodeJson_SplitJsonPointer(\n json_pointer, i + 1, allow_tilde_n_tilde_r_tilde_t);\n i = split.second;\n if (i == 0) {\n ret_error_message = DecodeJson_BadJsonPointer;\n goto done;\n }\n ret_error_message = DecodeJson_WalkJsonPointerFragment(\n tok_buf, tok_status, dec, io_buf, io_error_message, cursor_index,\n input, split.first);\n if (!ret_error_message.empty()) {\n goto done;\n }\n }\n\n // Loop, doing these two things:\n // 1. Get the next token.\n // 2. Process that token.\n while (true) {\n WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN;\n\n int64_t vbc = token.value_base_category();\n uint64_t vbd = token.value_base_detail();\n switch (vbc) {\n case WUFFS_B" +
|
||||
"ASE__TOKEN__VBC__FILLER:\n continue;\n\n case WUFFS_BASE__TOKEN__VBC__STRUCTURE: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__STRUCTURE__PUSH) {\n ret_error_message = callbacks.Push(static_cast<uint32_t>(vbd));\n if (!ret_error_message.empty()) {\n goto done;\n }\n depth++;\n if (depth > WUFFS_JSON__DECODER_DEPTH_MAX_INCL) {\n ret_error_message =\n \"wuffs_aux::DecodeJson: internal error: bad depth\";\n goto done;\n }\n continue;\n }\n ret_error_message = callbacks.Pop(static_cast<uint32_t>(vbd));\n depth--;\n if (depth < 0) {\n ret_error_message =\n \"wuffs_aux::DecodeJson: internal error: bad depth\";\n goto done;\n }\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__STRING: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_0_DST_1_SRC_DROP) {\n // No-op." +
|
||||
"\n } else if (vbd &\n WUFFS_BASE__TOKEN__VBD__STRING__CONVERT_1_DST_1_SRC_COPY) {\n const char* ptr = // Convert from (uint8_t*).\n static_cast<const char*>(static_cast<void*>(token_ptr));\n str.append(ptr, static_cast<size_t>(token_len));\n } else {\n goto fail;\n }\n if (token.continued()) {\n continue;\n }\n ret_error_message = callbacks.AppendTextString(std::move(str));\n str.clear();\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__UNICODE_CODE_POINT: {\n uint8_t u[WUFFS_BASE__UTF_8__BYTE_LENGTH__MAX_INCL];\n size_t n = wuffs_base__utf_8__encode(\n wuffs_base__make_slice_u8(\n &u[0], WUFFS_BASE__UTF_8__BYTE_LENGTH__MAX_INCL),\n static_cast<uint32_t>(vbd));\n const char* ptr = // Convert from (uint8_t*).\n static_cast<const char*>(static_cast<void*>(&u[0]));\n str." +
|
||||
"append(ptr, n);\n if (token.continued()) {\n continue;\n }\n goto fail;\n }\n\n case WUFFS_BASE__TOKEN__VBC__LITERAL: {\n ret_error_message =\n (vbd & WUFFS_BASE__TOKEN__VBD__LITERAL__NULL)\n ? callbacks.AppendNull()\n : callbacks.AppendBool(vbd &\n WUFFS_BASE__TOKEN__VBD__LITERAL__TRUE);\n goto parsed_a_value;\n }\n\n case WUFFS_BASE__TOKEN__VBC__NUMBER: {\n if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__FORMAT_TEXT) {\n if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_INTEGER_SIGNED) {\n wuffs_base__result_i64 r = wuffs_base__parse_number_i64(\n wuffs_base__make_slice_u8(token_ptr,\n static_cast<size_t>(token_len)),\n WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);\n if (r.status.is_ok()) {\n ret_error_message = callbacks.AppendI64" +
|
||||
"(r.value);\n goto parsed_a_value;\n }\n }\n if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_FLOATING_POINT) {\n wuffs_base__result_f64 r = wuffs_base__parse_number_f64(\n wuffs_base__make_slice_u8(token_ptr,\n static_cast<size_t>(token_len)),\n WUFFS_BASE__PARSE_NUMBER_XXX__DEFAULT_OPTIONS);\n if (r.status.is_ok()) {\n ret_error_message = callbacks.AppendF64(r.value);\n goto parsed_a_value;\n }\n }\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_NEG_INF) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n 0xFFF0000000000000ul));\n goto parsed_a_value;\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_POS_INF) {\n ret_error_message = callbacks.AppendF64(\n " +
|
||||
" wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n 0x7FF0000000000000ul));\n goto parsed_a_value;\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_NEG_NAN) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n 0xFFFFFFFFFFFFFFFFul));\n goto parsed_a_value;\n } else if (vbd & WUFFS_BASE__TOKEN__VBD__NUMBER__CONTENT_POS_NAN) {\n ret_error_message = callbacks.AppendF64(\n wuffs_base__ieee_754_bit_representation__from_u64_to_f64(\n 0x7FFFFFFFFFFFFFFFul));\n goto parsed_a_value;\n }\n goto fail;\n }\n }\n\n fail:\n ret_error_message =\n \"wuffs_aux::DecodeJson: internal error: unexpected token\";\n goto done;\n\n parsed_a_value:\n // If an error was encountered, we are done. Otherwise, (depth == 0)\n // after parsing a value is equivalent to havi" +
|
||||
"ng decoded the entire JSON\n // value (for an empty json_pointer query) or having decoded the\n // pointed-to JSON value (for a non-empty json_pointer query). In the\n // latter case, we are also done.\n //\n // However, if quirks like WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER or\n // WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF are passed, decoding\n // the entire JSON value should also consume any trailing filler, in case\n // the DecodeJson caller wants to subsequently check that the input is\n // completely exhausted (and otherwise raise \"valid JSON followed by\n // further (unexpected) data\"). We aren't done yet. Instead, keep the\n // loop running until WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN's\n // decode_tokens returns an ok status.\n if (!ret_error_message.empty() ||\n ((depth == 0) && !json_pointer.empty())) {\n goto done;\n }\n }\n } while (false);\n\ndone:\n DecodeJsonResult result(\n std::move(ret_error_message),\n " +
|
||||
" wuffs_base__u64__sat_add(io_buf->meta.pos, cursor_index));\n callbacks.Done(result, input, *io_buf);\n return result;\n}\n\n#undef WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN\n\n} // namespace wuffs_aux\n\n#endif // !defined(WUFFS_CONFIG__MODULES) ||\n // defined(WUFFS_CONFIG__MODULE__AUX__JSON)\n" +
|
||||
""
|
||||
|
||||
const AuxJsonHh = "" +
|
||||
|
||||
@@ -587,6 +587,7 @@ var cTypeNames = [...]string{
|
||||
t.IDARMNeonU32x4: "uint32x4_t",
|
||||
t.IDARMNeonU64x2: "uint64x2_t",
|
||||
t.IDX86M128I: "__m128i",
|
||||
t.IDX86M256I: "__m256i",
|
||||
}
|
||||
|
||||
const noSuchCOperator = " no_such_C_operator "
|
||||
|
||||
+12
-6
@@ -40,7 +40,7 @@ type funk struct {
|
||||
derivedVars map[t.ID]struct{}
|
||||
jumpTargets map[a.Loop]string
|
||||
coroSuspPoint uint32
|
||||
ioBinds uint32
|
||||
ioManips uint32
|
||||
tempW uint32
|
||||
tempR uint32
|
||||
usesEmptyIOBuffer bool
|
||||
@@ -271,7 +271,7 @@ func (g *gen) writeFuncImpl(b *buffer, n *a.Func) error {
|
||||
if n.Effect().Coroutine() {
|
||||
b.writex(k.bBodySuspend)
|
||||
} else if k.hasGotoOK {
|
||||
b.writes("\ngoto ok;\nok:\n") // The goto avoids the "unused label" warning.
|
||||
b.writes("\nok:\n")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,6 +292,9 @@ func (g *gen) gatherFuncImpl(_ *buffer, n *a.Func) error {
|
||||
if n.Public() && n.Effect().Coroutine() {
|
||||
g.numPublicCoroutines[n.Receiver()]++
|
||||
coroID = g.numPublicCoroutines[n.Receiver()]
|
||||
if coroID >= 0x8000 {
|
||||
return fmt.Errorf("too many coroutines for %q", n.Receiver().Str(g.tm))
|
||||
}
|
||||
}
|
||||
|
||||
g.currFunk = funk{
|
||||
@@ -498,11 +501,17 @@ func (g *gen) writeFuncImplBody(b *buffer) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeFuncImplBodySuspend(b *buffer) error {
|
||||
if (g.currFunk.coroSuspPoint > 0) || g.currFunk.astFunc.Effect().Coroutine() {
|
||||
if !g.currFunk.hasGotoOK {
|
||||
b.writes("\ngoto ok;") // Avoid the "unused label" warning.
|
||||
}
|
||||
b.writes("\nok:\n")
|
||||
}
|
||||
|
||||
if g.currFunk.coroSuspPoint > 0 {
|
||||
// We've reached the end of the function body. Reset the coroutine
|
||||
// suspension point so that the next call to this function starts at
|
||||
// the top.
|
||||
b.writes("\ngoto ok;\nok:\n") // The goto avoids the "unused label" warning.
|
||||
b.printf("self->private_impl.%s%s[0] = 0;\n",
|
||||
pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm))
|
||||
b.writes("goto exit;\n}\n\n") // Close the coroutine switch.
|
||||
@@ -520,9 +529,6 @@ func (g *gen) writeFuncImplBodySuspend(b *buffer) error {
|
||||
return err
|
||||
}
|
||||
b.writes("\n")
|
||||
|
||||
} else if g.currFunk.astFunc.Effect().Coroutine() {
|
||||
b.writes("\ngoto ok;\nok:\n") // The goto avoids the "unused label" warning.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -185,8 +185,8 @@ loop:
|
||||
return err
|
||||
}
|
||||
|
||||
case a.KIOBind:
|
||||
if err := h.doIOBind(r, o.AsIOBind(), depth); err != nil {
|
||||
case a.KIOManip:
|
||||
if err := h.doIOManip(r, o.AsIOManip(), depth); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -324,13 +324,18 @@ func (h *livenessHelper) doExpr1(r livenesses, n *a.Expr, allToStrong bool, dept
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *livenessHelper) doIOBind(r livenesses, n *a.IOBind, depth uint32) error {
|
||||
func (h *livenessHelper) doIOManip(r livenesses, n *a.IOManip, depth uint32) error {
|
||||
if err := h.doExpr(r, n.IO()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := h.doExpr(r, n.Arg1()); err != nil {
|
||||
return err
|
||||
}
|
||||
if histPos := n.HistoryPosition(); histPos != nil {
|
||||
if err := h.doExpr(r, n.HistoryPosition()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return h.doBlock(r, n.Body(), depth)
|
||||
}
|
||||
|
||||
|
||||
@@ -60,8 +60,8 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
return g.writeStatementAssign(b, n.Operator(), n.LHS(), n.RHS(), depth)
|
||||
case a.KChoose:
|
||||
return g.writeStatementChoose(b, n.AsChoose(), depth)
|
||||
case a.KIOBind:
|
||||
return g.writeStatementIOBind(b, n.AsIOBind(), depth)
|
||||
case a.KIOManip:
|
||||
return g.writeStatementIOManip(b, n.AsIOManip(), depth)
|
||||
case a.KIf:
|
||||
return g.writeStatementIf(b, n.AsIf(), depth)
|
||||
case a.KIterate:
|
||||
@@ -279,18 +279,26 @@ func cpuArchCNames(asserts []*a.Node) (caMacro string, caName string, caAttribut
|
||||
caMacro, caName, caAttribute =
|
||||
"X86_64", "x86_sse42",
|
||||
"WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(\"pclmul,popcnt,sse4.2\")"
|
||||
case t.IDX86AVX2:
|
||||
caMacro, caName, caAttribute =
|
||||
"X86_64", "x86_avx2",
|
||||
"WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(\"pclmul,popcnt,sse4.2,avx2\")"
|
||||
case t.IDX86BMI2:
|
||||
caMacro, caName, caAttribute =
|
||||
"X86_64", "x86_bmi2",
|
||||
"WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET(\"bmi2\")"
|
||||
}
|
||||
}
|
||||
}
|
||||
return caMacro, caName, caAttribute, nil
|
||||
}
|
||||
|
||||
func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error {
|
||||
if g.currFunk.ioBinds > maxIOBinds {
|
||||
func (g *gen) writeStatementIOManip(b *buffer, n *a.IOManip, depth uint32) error {
|
||||
if g.currFunk.ioManips > maxIOManips {
|
||||
return fmt.Errorf("too many temporary variables required")
|
||||
}
|
||||
ioBindNum := g.currFunk.ioBinds
|
||||
g.currFunk.ioBinds++
|
||||
ioBindNum := g.currFunk.ioManips
|
||||
g.currFunk.ioManips++
|
||||
|
||||
e := n.IO()
|
||||
prefix := vPrefix
|
||||
@@ -335,6 +343,10 @@ func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error {
|
||||
if err := g.writeExpr(b, n.Arg1(), false, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(",\n")
|
||||
if err := g.writeExpr(b, n.HistoryPosition(), false, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(");\n")
|
||||
|
||||
} else {
|
||||
@@ -670,6 +682,7 @@ func (g *gen) writeCoroSuspPoint(b *buffer, maybeSuspend bool) error {
|
||||
macro := ""
|
||||
if maybeSuspend {
|
||||
macro = "_MAYBE_SUSPEND"
|
||||
g.currFunk.hasGotoOK = true
|
||||
}
|
||||
b.printf("WUFFS_BASE__COROUTINE_SUSPENSION_POINT%s(%d);\n", macro, g.currFunk.coroSuspPoint)
|
||||
return nil
|
||||
|
||||
@@ -64,8 +64,8 @@ func (g *gen) needDerivedVar(name t.ID) bool {
|
||||
}
|
||||
}
|
||||
|
||||
case a.KIOBind:
|
||||
if p.AsIOBind().IO().IsArgsDotFoo() == name {
|
||||
case a.KIOManip:
|
||||
if p.AsIOManip().IO().IsArgsDotFoo() == name {
|
||||
return errNeedDerivedVar
|
||||
}
|
||||
}
|
||||
|
||||
+20
-17
@@ -46,7 +46,7 @@ const (
|
||||
KField
|
||||
KFile
|
||||
KFunc
|
||||
KIOBind
|
||||
KIOManip
|
||||
KIf
|
||||
KIterate
|
||||
KJump
|
||||
@@ -78,7 +78,7 @@ var kindStrings = [...]string{
|
||||
KField: "KField",
|
||||
KFile: "KFile",
|
||||
KFunc: "KFunc",
|
||||
KIOBind: "KIOBind",
|
||||
KIOManip: "KIOManip",
|
||||
KIf: "KIf",
|
||||
KIterate: "KIterate",
|
||||
KJump: "KJump",
|
||||
@@ -169,7 +169,7 @@ type Node struct {
|
||||
// Field . . name Field
|
||||
// File . . . File
|
||||
// Func funcName receiverPkg receiverName Func
|
||||
// IOBind . . . IOBind
|
||||
// IOManip keyword . . IOManip
|
||||
// If . . . If
|
||||
// Iterate advance label length Iterate
|
||||
// Jump keyword label . Jump
|
||||
@@ -208,7 +208,7 @@ func (n *Node) AsExpr() *Expr { return (*Expr)(n) }
|
||||
func (n *Node) AsField() *Field { return (*Field)(n) }
|
||||
func (n *Node) AsFile() *File { return (*File)(n) }
|
||||
func (n *Node) AsFunc() *Func { return (*Func)(n) }
|
||||
func (n *Node) AsIOBind() *IOBind { return (*IOBind)(n) }
|
||||
func (n *Node) AsIOManip() *IOManip { return (*IOManip)(n) }
|
||||
func (n *Node) AsIf() *If { return (*If)(n) }
|
||||
func (n *Node) AsIterate() *Iterate { return (*Iterate)(n) }
|
||||
func (n *Node) AsJump() *Jump { return (*Jump)(n) }
|
||||
@@ -491,7 +491,7 @@ func (n *Assert) IsChooseCPUArch() bool {
|
||||
return false
|
||||
}
|
||||
switch rhs.Ident() {
|
||||
case t.IDARMCRC32, t.IDARMNeon, t.IDX86SSE42, t.IDX86AVX2:
|
||||
case t.IDARMCRC32, t.IDARMNeon, t.IDX86SSE42, t.IDX86AVX2, t.IDX86BMI2:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -583,26 +583,29 @@ func NewField(flags Flags, name t.ID, xType *TypeExpr) *Field {
|
||||
}
|
||||
}
|
||||
|
||||
// IOBind is "io_bind (io:LHS, data:MHS) { List2 }" or "io_limit (io:LHS,
|
||||
// limit:MHS) { List2 }":
|
||||
// IOManip is "io_bind (io:LHS, data:MHS, history_position:RHS) { List2 }" or
|
||||
// "io_limit (io:LHS, limit:MHS) { List2 }":
|
||||
// - ID0: <IDIOBind|IDIOLimit>
|
||||
// - LHS: <Expr>
|
||||
// - MHS: <Expr>
|
||||
// - RHS: <Expr>
|
||||
// - List2: <Statement> body
|
||||
type IOBind Node
|
||||
type IOManip Node
|
||||
|
||||
func (n *IOBind) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *IOBind) Keyword() t.ID { return n.id0 }
|
||||
func (n *IOBind) IO() *Expr { return n.lhs.AsExpr() }
|
||||
func (n *IOBind) Arg1() *Expr { return n.mhs.AsExpr() }
|
||||
func (n *IOBind) Body() []*Node { return n.list2 }
|
||||
func (n *IOManip) AsNode() *Node { return (*Node)(n) }
|
||||
func (n *IOManip) Keyword() t.ID { return n.id0 }
|
||||
func (n *IOManip) IO() *Expr { return n.lhs.AsExpr() }
|
||||
func (n *IOManip) Arg1() *Expr { return n.mhs.AsExpr() }
|
||||
func (n *IOManip) HistoryPosition() *Expr { return n.rhs.AsExpr() }
|
||||
func (n *IOManip) Body() []*Node { return n.list2 }
|
||||
|
||||
func NewIOBind(keyword t.ID, io *Expr, arg1 *Expr, body []*Node) *IOBind {
|
||||
return &IOBind{
|
||||
kind: KIOBind,
|
||||
func NewIOManip(keyword t.ID, io *Expr, arg1 *Expr, historyPosition *Expr, body []*Node) *IOManip {
|
||||
return &IOManip{
|
||||
kind: KIOManip,
|
||||
id0: keyword,
|
||||
lhs: io.AsNode(),
|
||||
mhs: arg1.AsNode(),
|
||||
rhs: historyPosition.AsNode(),
|
||||
list2: body,
|
||||
}
|
||||
}
|
||||
@@ -1149,7 +1152,7 @@ func NewFile(filename string, topLevelDecls []*Node) *File {
|
||||
// - Assert
|
||||
// - Assign
|
||||
// - Choose
|
||||
// - IOBind
|
||||
// - IOManip
|
||||
// - If
|
||||
// - Iterate
|
||||
// - Jump
|
||||
|
||||
@@ -306,6 +306,9 @@ var Types = []string{
|
||||
|
||||
"x86_sse42_utility",
|
||||
"x86_m128i",
|
||||
|
||||
"x86_avx2_utility",
|
||||
"x86_m256i",
|
||||
}
|
||||
|
||||
var Funcs = [][]string{
|
||||
@@ -525,6 +528,7 @@ var funcsOther = [...]string{
|
||||
|
||||
"io_writer.count_since(mark: u64) u64",
|
||||
"io_writer.history_length() u64",
|
||||
"io_writer.history_position() u64",
|
||||
"io_writer.length() u64",
|
||||
"io_writer.mark() u64",
|
||||
"io_writer.position() u64",
|
||||
@@ -549,6 +553,13 @@ var funcsOther = [...]string{
|
||||
// For now, that's all implicitly checked (i.e. hard coded).
|
||||
"io_writer.limited_copy_u32_from_history_8_byte_chunks_fast!(up_to: u32, distance: u32) u32",
|
||||
|
||||
// TODO: this should have explicit pre-conditions:
|
||||
// - (up_to + 8) <= this.length()
|
||||
// - distance == 1
|
||||
// - distance <= this.history_length()
|
||||
// For now, that's all implicitly checked (i.e. hard coded).
|
||||
"io_writer.limited_copy_u32_from_history_8_byte_chunks_distance_1_fast!(up_to: u32, distance: u32) u32",
|
||||
|
||||
// ---- token_writer
|
||||
|
||||
"token_writer.write_simple_token_fast!(" +
|
||||
@@ -766,6 +777,58 @@ var funcsOther = [...]string{
|
||||
"x86_m128i._mm_unpacklo_epi64(b: x86_m128i) x86_m128i",
|
||||
"x86_m128i._mm_unpacklo_epi8(b: x86_m128i) x86_m128i",
|
||||
"x86_m128i._mm_xor_si128(b: x86_m128i) x86_m128i",
|
||||
|
||||
// ---- x86_avx2_utility
|
||||
|
||||
"x86_avx2_utility.make_m256i_multiple_u8(" +
|
||||
"a00: u8, a01: u8, a02: u8, a03: u8," +
|
||||
"a04: u8, a05: u8, a06: u8, a07: u8," +
|
||||
"a08: u8, a09: u8, a10: u8, a11: u8," +
|
||||
"a12: u8, a13: u8, a14: u8, a15: u8," +
|
||||
"a16: u8, a17: u8, a18: u8, a19: u8," +
|
||||
"a20: u8, a21: u8, a22: u8, a23: u8," +
|
||||
"a24: u8, a25: u8, a26: u8, a27: u8," +
|
||||
"a28: u8, a29: u8, a30: u8, a31: u8) x86_m256i",
|
||||
"x86_avx2_utility.make_m256i_multiple_u16(" +
|
||||
"a00: u16, a01: u16, a02: u16, a03: u16," +
|
||||
"a04: u16, a05: u16, a06: u16, a07: u16," +
|
||||
"a08: u16, a09: u16, a10: u16, a11: u16," +
|
||||
"a12: u16, a13: u16, a14: u16, a15: u16) x86_m256i",
|
||||
"x86_avx2_utility.make_m256i_multiple_u32(" +
|
||||
"a00: u32, a01: u32, a02: u32, a03: u32," +
|
||||
"a04: u32, a05: u32, a06: u32, a07: u32) x86_m256i",
|
||||
"x86_avx2_utility.make_m256i_multiple_u64(" +
|
||||
"a00: u64, a01: u64, a02: u64, a03: u64) x86_m256i",
|
||||
|
||||
"x86_avx2_utility.make_m256i_repeat_u8(a: u8) x86_m256i",
|
||||
"x86_avx2_utility.make_m256i_repeat_u16(a: u16) x86_m256i",
|
||||
"x86_avx2_utility.make_m256i_repeat_u32(a: u32) x86_m256i",
|
||||
"x86_avx2_utility.make_m256i_repeat_u64(a: u64) x86_m256i",
|
||||
|
||||
"x86_avx2_utility.make_m256i_slice256(a: slice base.u8) x86_m256i",
|
||||
|
||||
"x86_avx2_utility.make_m256i_zeroes() x86_m256i",
|
||||
|
||||
// ---- x86_m256i
|
||||
|
||||
// TODO: generate these methods automatically?
|
||||
|
||||
"x86_m256i._mm256_add_epi16(b: x86_m256i) x86_m256i",
|
||||
"x86_m256i._mm256_add_epi32(b: x86_m256i) x86_m256i",
|
||||
"x86_m256i._mm256_add_epi64(b: x86_m256i) x86_m256i",
|
||||
"x86_m256i._mm256_add_epi8(b: x86_m256i) x86_m256i",
|
||||
"x86_m256i._mm256_extracti128_si256(imm8: u32) x86_m128i",
|
||||
"x86_m256i._mm256_madd_epi16(b: x86_m256i) x86_m256i",
|
||||
"x86_m256i._mm256_maddubs_epi16(b: x86_m256i) x86_m256i",
|
||||
"x86_m256i._mm256_sad_epu8(b: x86_m256i) x86_m256i",
|
||||
"x86_m256i._mm256_slli_epi16(imm8: u32) x86_m256i",
|
||||
"x86_m256i._mm256_slli_epi32(imm8: u32) x86_m256i",
|
||||
"x86_m256i._mm256_slli_epi64(imm8: u32) x86_m256i",
|
||||
"x86_m256i._mm256_slli_si256(imm8: u32) x86_m256i",
|
||||
"x86_m256i._mm256_srli_epi16(imm8: u32) x86_m256i",
|
||||
"x86_m256i._mm256_srli_epi32(imm8: u32) x86_m256i",
|
||||
"x86_m256i._mm256_srli_epi64(imm8: u32) x86_m256i",
|
||||
"x86_m256i._mm256_srli_si256(imm8: u32) x86_m256i",
|
||||
}
|
||||
|
||||
var Interfaces = []string{
|
||||
|
||||
+38
-9
@@ -250,14 +250,19 @@ func (q *checker) bcheckStatement(n *a.Node) error {
|
||||
case a.KChoose:
|
||||
// No-op.
|
||||
|
||||
case a.KIOBind:
|
||||
n := n.AsIOBind()
|
||||
case a.KIOManip:
|
||||
n := n.AsIOManip()
|
||||
if _, err := q.bcheckExpr(n.IO(), 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := q.bcheckExpr(n.Arg1(), 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if histPos := n.HistoryPosition(); histPos != nil {
|
||||
if _, err := q.bcheckExpr(histPos, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := q.bcheckBlock(n.Body()); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1160,13 +1165,18 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
|
||||
return bounds{}, err
|
||||
}
|
||||
|
||||
} else if method == t.IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast {
|
||||
if err := q.canLimitedCopyU32FromHistoryFast(recv, n.Args(), eight, nil, one); err != nil {
|
||||
return bounds{}, err
|
||||
}
|
||||
|
||||
} else if method == t.IDLimitedCopyU32FromHistory8ByteChunksFast {
|
||||
if err := q.canLimitedCopyU32FromHistoryFast(recv, n.Args(), eight, eight); err != nil {
|
||||
if err := q.canLimitedCopyU32FromHistoryFast(recv, n.Args(), eight, eight, nil); err != nil {
|
||||
return bounds{}, err
|
||||
}
|
||||
|
||||
} else if method == t.IDLimitedCopyU32FromHistoryFast {
|
||||
if err := q.canLimitedCopyU32FromHistoryFast(recv, n.Args(), nil, one); err != nil {
|
||||
if err := q.canLimitedCopyU32FromHistoryFast(recv, n.Args(), nil, one, nil); err != nil {
|
||||
return bounds{}, err
|
||||
}
|
||||
|
||||
@@ -1272,10 +1282,11 @@ func (q *checker) canUndoByte(recv *a.Expr) error {
|
||||
return fmt.Errorf("check: could not prove %s.can_undo_byte()", recv.Str(q.tm))
|
||||
}
|
||||
|
||||
func (q *checker) canLimitedCopyU32FromHistoryFast(recv *a.Expr, args []*a.Node, adj *big.Int, minDistance *big.Int) error {
|
||||
func (q *checker) canLimitedCopyU32FromHistoryFast(recv *a.Expr, args []*a.Node, adj *big.Int, minDistance *big.Int, exactDistance *big.Int) error {
|
||||
// As per cgen's io-private.h, there are three pre-conditions:
|
||||
// - (upTo + adj) <= this.length()
|
||||
// - distance >= minDistance
|
||||
// - either (distance >= minDistance) or (distance == exactDistance),
|
||||
// depending on which of minDistance and exactDistance is non-nil.
|
||||
// - distance <= this.history_length()
|
||||
//
|
||||
// adj may be nil, in which case (upTo + adj) is just upTo.
|
||||
@@ -1335,8 +1346,8 @@ check0:
|
||||
}
|
||||
|
||||
// Check "distance >= minDistance".
|
||||
check1:
|
||||
for {
|
||||
check1a:
|
||||
for minDistance != nil {
|
||||
for _, x := range q.facts {
|
||||
if x.Operator() != t.IDXBinaryGreaterEq {
|
||||
continue
|
||||
@@ -1347,11 +1358,29 @@ check1:
|
||||
if rcv := x.RHS().AsExpr().ConstValue(); (rcv == nil) || (rcv.Cmp(minDistance) < 0) {
|
||||
continue
|
||||
}
|
||||
break check1
|
||||
break check1a
|
||||
}
|
||||
return fmt.Errorf("check: could not prove %s >= %v", distance.Str(q.tm), minDistance)
|
||||
}
|
||||
|
||||
// Check "distance == exactDistance".
|
||||
check1b:
|
||||
for exactDistance != nil {
|
||||
for _, x := range q.facts {
|
||||
if x.Operator() != t.IDXBinaryEqEq {
|
||||
continue
|
||||
}
|
||||
if lhs := x.LHS().AsExpr(); !lhs.Eq(distance) {
|
||||
continue
|
||||
}
|
||||
if rcv := x.RHS().AsExpr().ConstValue(); (rcv == nil) || (rcv.Cmp(exactDistance) != 0) {
|
||||
continue
|
||||
}
|
||||
break check1b
|
||||
}
|
||||
return fmt.Errorf("check: could not prove %s == %v", distance.Str(q.tm), exactDistance)
|
||||
}
|
||||
|
||||
// Check "distance <= this.history_length()".
|
||||
check2:
|
||||
for {
|
||||
|
||||
@@ -91,6 +91,9 @@ var (
|
||||
typeExprX86SSE42Utility = a.NewTypeExpr(0, t.IDBase, t.IDX86SSE42Utility, nil, nil, nil)
|
||||
typeExprX86M128I = a.NewTypeExpr(0, t.IDBase, t.IDX86M128I, nil, nil, nil)
|
||||
|
||||
typeExprX86AVX2Utility = a.NewTypeExpr(0, t.IDBase, t.IDX86AVX2Utility, nil, nil, nil)
|
||||
typeExprX86M256I = a.NewTypeExpr(0, t.IDBase, t.IDX86M256I, nil, nil, nil)
|
||||
|
||||
typeExprSliceU8 = a.NewTypeExpr(t.IDSlice, 0, 0, nil, nil, typeExprU8)
|
||||
typeExprTableU8 = a.NewTypeExpr(t.IDTable, 0, 0, nil, nil, typeExprU8)
|
||||
)
|
||||
@@ -154,6 +157,9 @@ var builtInTypeMap = typeMap{
|
||||
|
||||
t.IDX86SSE42Utility: typeExprX86SSE42Utility,
|
||||
t.IDX86M128I: typeExprX86M128I,
|
||||
|
||||
t.IDX86AVX2Utility: typeExprX86AVX2Utility,
|
||||
t.IDX86M256I: typeExprX86M256I,
|
||||
}
|
||||
|
||||
func (c *Checker) parseBuiltInFuncs(m map[t.QQID]*a.Func, ss []string) error {
|
||||
|
||||
+15
-2
@@ -28,6 +28,7 @@ const (
|
||||
cpuArchBitsARMCRC32 = cpuArchBits(0x00000001)
|
||||
cpuArchBitsARMNeon = cpuArchBits(0x00000002)
|
||||
cpuArchBitsX86SSE42 = cpuArchBits(0x00000004)
|
||||
cpuArchBitsX86AVX2 = cpuArchBits(0x00000008)
|
||||
)
|
||||
|
||||
func calcCPUArchBits(n *a.Func) (ret cpuArchBits) {
|
||||
@@ -43,6 +44,8 @@ func calcCPUArchBits(n *a.Func) (ret cpuArchBits) {
|
||||
ret |= cpuArchBitsARMNeon
|
||||
case t.IDX86SSE42:
|
||||
ret |= cpuArchBitsX86SSE42
|
||||
case t.IDX86AVX2:
|
||||
ret |= cpuArchBitsX86SSE42 | cpuArchBitsX86AVX2
|
||||
}
|
||||
}
|
||||
return ret
|
||||
@@ -146,8 +149,8 @@ func (q *checker) tcheckStatement(n *a.Node) error {
|
||||
}
|
||||
return nil
|
||||
|
||||
case a.KIOBind:
|
||||
n := n.AsIOBind()
|
||||
case a.KIOManip:
|
||||
n := n.AsIOManip()
|
||||
if err := q.tcheckExpr(n.IO(), 0); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -168,6 +171,16 @@ func (q *checker) tcheckStatement(n *a.Node) error {
|
||||
n.Keyword().Str(q.tm), n.Arg1().Str(q.tm), typ.Str(q.tm), arg1Typ.Str(q.tm))
|
||||
}
|
||||
|
||||
if n.Keyword() == t.IDIOBind {
|
||||
if err := q.tcheckExpr(n.HistoryPosition(), 0); err != nil {
|
||||
return err
|
||||
}
|
||||
if typ := n.HistoryPosition().MType(); !typ.IsIdeal() && !typ.EqIgnoringRefinements(typeExprU64) {
|
||||
return fmt.Errorf("check: %s expression %q, of type %q, does not have type %q",
|
||||
n.Keyword().Str(q.tm), n.HistoryPosition().Str(q.tm), typ.Str(q.tm), typeExprU64.Str(q.tm))
|
||||
}
|
||||
}
|
||||
|
||||
for _, o := range n.Body() {
|
||||
// TODO: prohibit jumps (breaks, continues), rets (returns, yields)
|
||||
// and retry-calling ? methods while inside an io_bind body.
|
||||
|
||||
+33
-19
@@ -861,7 +861,7 @@ func (p *parser) parseStatement1() (*a.Node, error) {
|
||||
return a.NewChoose(name, args).AsNode(), nil
|
||||
|
||||
case t.IDIOBind, t.IDIOLimit:
|
||||
return p.parseIOBindNode()
|
||||
return p.parseIOManipNode()
|
||||
|
||||
case t.IDIf:
|
||||
o, err := p.parseIf()
|
||||
@@ -1050,7 +1050,7 @@ func (p *parser) parseAsserts() ([]*a.Node, error) {
|
||||
return asserts, nil
|
||||
}
|
||||
|
||||
func (p *parser) parseIOBindNode() (*a.Node, error) {
|
||||
func (p *parser) parseIOManipNode() (*a.Node, error) {
|
||||
keyword := p.peek1()
|
||||
p.src = p.src[1:]
|
||||
|
||||
@@ -1123,6 +1123,36 @@ func (p *parser) parseIOBindNode() (*a.Node, error) {
|
||||
io.Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
|
||||
histPos := (*a.Expr)(nil)
|
||||
if keyword == t.IDIOBind {
|
||||
if x := p.peek1(); x != t.IDComma {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ",", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
if x := p.peek1(); x != t.IDHistoryPosition {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected "history_position", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
if x := p.peek1(); x != t.IDColon {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ":", got %q at %s:%d`, got, p.filename, p.line())
|
||||
}
|
||||
p.src = p.src[1:]
|
||||
|
||||
histPos, err = p.parseExpr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if histPos.Effect() != 0 {
|
||||
return nil, fmt.Errorf(`parse: argument %q is not effect-free at %s:%d`,
|
||||
io.Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
}
|
||||
|
||||
if x := p.peek1(); x != t.IDCloseParen {
|
||||
got := p.tm.ByID(x)
|
||||
return nil, fmt.Errorf(`parse: expected ")", got %q at %s:%d`, got, p.filename, p.line())
|
||||
@@ -1134,7 +1164,7 @@ func (p *parser) parseIOBindNode() (*a.Node, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return a.NewIOBind(keyword, io, arg1, body).AsNode(), nil
|
||||
return a.NewIOManip(keyword, io, arg1, histPos, body).AsNode(), nil
|
||||
}
|
||||
|
||||
func (p *parser) parseIf() (*a.If, error) {
|
||||
@@ -1354,22 +1384,6 @@ func (p *parser) parseArgNode() (*a.Node, error) {
|
||||
return a.NewArg(name, value).AsNode(), nil
|
||||
}
|
||||
|
||||
func (p *parser) parseIOBindExprNode() (*a.Node, error) {
|
||||
e, err := p.parseExpr()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch e.Operator() {
|
||||
case 0:
|
||||
return e.AsNode(), nil
|
||||
case t.IDDot:
|
||||
if lhs := e.LHS().AsExpr(); lhs.Operator() == 0 && lhs.Ident() == t.IDArgs {
|
||||
return e.AsNode(), nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf(`parse: expected "args.something", got %q at %s:%d`, e.Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
|
||||
func (p *parser) parseVarNode() (*a.Node, error) {
|
||||
id, err := p.parseIdent()
|
||||
if err != nil {
|
||||
|
||||
+48
-40
@@ -490,27 +490,29 @@ const (
|
||||
|
||||
IDDecodeFrameOptions = ID(0x158)
|
||||
|
||||
IDCanUndoByte = ID(0x160)
|
||||
IDCountSince = ID(0x161)
|
||||
IDHistoryLength = ID(0x162)
|
||||
IDIsClosed = ID(0x163)
|
||||
IDMark = ID(0x164)
|
||||
IDMatch15 = ID(0x165)
|
||||
IDMatch31 = ID(0x166)
|
||||
IDMatch7 = ID(0x167)
|
||||
IDPosition = ID(0x168)
|
||||
IDSince = ID(0x169)
|
||||
IDSkip = ID(0x16A)
|
||||
IDSkipU32 = ID(0x16B)
|
||||
IDSkipU32Fast = ID(0x16C)
|
||||
IDCanUndoByte = ID(0x160)
|
||||
IDCountSince = ID(0x161)
|
||||
IDHistoryLength = ID(0x162)
|
||||
IDHistoryPosition = ID(0x163)
|
||||
IDIsClosed = ID(0x164)
|
||||
IDMark = ID(0x165)
|
||||
IDMatch15 = ID(0x166)
|
||||
IDMatch31 = ID(0x167)
|
||||
IDMatch7 = ID(0x168)
|
||||
IDPosition = ID(0x169)
|
||||
IDSince = ID(0x16A)
|
||||
IDSkip = ID(0x16B)
|
||||
IDSkipU32 = ID(0x16C)
|
||||
IDSkipU32Fast = ID(0x16D)
|
||||
|
||||
IDCopyFromSlice = ID(0x170)
|
||||
IDLimitedCopyU32FromHistory = ID(0x171)
|
||||
IDLimitedCopyU32FromHistory8ByteChunksFast = ID(0x172)
|
||||
IDLimitedCopyU32FromHistoryFast = ID(0x173)
|
||||
IDLimitedCopyU32FromReader = ID(0x174)
|
||||
IDLimitedCopyU32FromSlice = ID(0x175)
|
||||
IDLimitedCopyU32ToSlice = ID(0x176)
|
||||
IDCopyFromSlice = ID(0x170)
|
||||
IDLimitedCopyU32FromHistory = ID(0x171)
|
||||
IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast = ID(0x172)
|
||||
IDLimitedCopyU32FromHistory8ByteChunksFast = ID(0x173)
|
||||
IDLimitedCopyU32FromHistoryFast = ID(0x174)
|
||||
IDLimitedCopyU32FromReader = ID(0x175)
|
||||
IDLimitedCopyU32FromSlice = ID(0x176)
|
||||
IDLimitedCopyU32ToSlice = ID(0x177)
|
||||
|
||||
// -------- 0x180 block.
|
||||
|
||||
@@ -709,8 +711,10 @@ const (
|
||||
IDX86SSE42Utility = ID(0x391)
|
||||
IDX86AVX2 = ID(0x392)
|
||||
IDX86AVX2Utility = ID(0x393)
|
||||
IDX86BMI2 = ID(0x394)
|
||||
|
||||
IDX86M128I = ID(0x3A0)
|
||||
IDX86M256I = ID(0x3A1)
|
||||
)
|
||||
|
||||
var builtInsByID = [nBuiltInIDs]string{
|
||||
@@ -914,27 +918,29 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
|
||||
IDDecodeFrameOptions: "decode_frame_options",
|
||||
|
||||
IDCanUndoByte: "can_undo_byte",
|
||||
IDCountSince: "count_since",
|
||||
IDHistoryLength: "history_length",
|
||||
IDIsClosed: "is_closed",
|
||||
IDMark: "mark",
|
||||
IDMatch15: "match15",
|
||||
IDMatch31: "match31",
|
||||
IDMatch7: "match7",
|
||||
IDPosition: "position",
|
||||
IDSince: "since",
|
||||
IDSkip: "skip",
|
||||
IDSkipU32: "skip_u32",
|
||||
IDSkipU32Fast: "skip_u32_fast",
|
||||
IDCanUndoByte: "can_undo_byte",
|
||||
IDCountSince: "count_since",
|
||||
IDHistoryLength: "history_length",
|
||||
IDHistoryPosition: "history_position",
|
||||
IDIsClosed: "is_closed",
|
||||
IDMark: "mark",
|
||||
IDMatch15: "match15",
|
||||
IDMatch31: "match31",
|
||||
IDMatch7: "match7",
|
||||
IDPosition: "position",
|
||||
IDSince: "since",
|
||||
IDSkip: "skip",
|
||||
IDSkipU32: "skip_u32",
|
||||
IDSkipU32Fast: "skip_u32_fast",
|
||||
|
||||
IDCopyFromSlice: "copy_from_slice",
|
||||
IDLimitedCopyU32FromHistory: "limited_copy_u32_from_history",
|
||||
IDLimitedCopyU32FromHistory8ByteChunksFast: "limited_copy_u32_from_history_8_byte_chunks_fast",
|
||||
IDLimitedCopyU32FromHistoryFast: "limited_copy_u32_from_history_fast",
|
||||
IDLimitedCopyU32FromReader: "limited_copy_u32_from_reader",
|
||||
IDLimitedCopyU32FromSlice: "limited_copy_u32_from_slice",
|
||||
IDLimitedCopyU32ToSlice: "limited_copy_u32_to_slice",
|
||||
IDCopyFromSlice: "copy_from_slice",
|
||||
IDLimitedCopyU32FromHistory: "limited_copy_u32_from_history",
|
||||
IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast: "limited_copy_u32_from_history_8_byte_chunks_distance_1_fast",
|
||||
IDLimitedCopyU32FromHistory8ByteChunksFast: "limited_copy_u32_from_history_8_byte_chunks_fast",
|
||||
IDLimitedCopyU32FromHistoryFast: "limited_copy_u32_from_history_fast",
|
||||
IDLimitedCopyU32FromReader: "limited_copy_u32_from_reader",
|
||||
IDLimitedCopyU32FromSlice: "limited_copy_u32_from_slice",
|
||||
IDLimitedCopyU32ToSlice: "limited_copy_u32_to_slice",
|
||||
|
||||
// -------- 0x180 block.
|
||||
|
||||
@@ -1120,8 +1126,10 @@ var builtInsByID = [nBuiltInIDs]string{
|
||||
IDX86SSE42Utility: "x86_sse42_utility",
|
||||
IDX86AVX2: "x86_avx2",
|
||||
IDX86AVX2Utility: "x86_avx2_utility",
|
||||
IDX86BMI2: "x86_bmi2",
|
||||
|
||||
IDX86M128I: "x86_m128i",
|
||||
IDX86M256I: "x86_m256i",
|
||||
}
|
||||
|
||||
var builtInsByName = map[string]ID{}
|
||||
|
||||
@@ -10,8 +10,12 @@
|
||||
|
||||
// Wuffs' C code is generated automatically, not hand-written. These warnings'
|
||||
// costs outweigh the benefits.
|
||||
//
|
||||
// The "elif defined(__clang__)" isn't redundant. While vanilla clang defines
|
||||
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#pragma GCC diagnostic ignored "-Wunreachable-code"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
@@ -19,6 +23,16 @@
|
||||
#if defined(__cplusplus)
|
||||
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||
#endif
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
||||
#pragma clang diagnostic ignored "-Wunreachable-code"
|
||||
#pragma clang diagnostic ignored "-Wunused-function"
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
#if defined(__cplusplus)
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Copyright 2017 The Wuffs Authors.
|
||||
@@ -99,8 +113,8 @@ extern "C" {
|
||||
|
||||
// To simplify Wuffs code, "cpu_arch >= arm_xxx" requires xxx but also
|
||||
// unaligned little-endian load/stores.
|
||||
#if defined(__ARM_FEATURE_UNALIGNED) && defined(__BYTE_ORDER__) && \
|
||||
(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||
#if defined(__ARM_FEATURE_UNALIGNED) && !defined(__native_client__) && \
|
||||
defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||
// Not all gcc versions define __ARM_ACLE, even if they support crc32
|
||||
// intrinsics. Look for __ARM_FEATURE_CRC32 instead.
|
||||
#if defined(__ARM_FEATURE_CRC32)
|
||||
@@ -115,11 +129,13 @@ extern "C" {
|
||||
|
||||
// Similarly, "cpu_arch >= x86_sse42" requires SSE4.2 but also PCLMUL and
|
||||
// POPCNT. This is checked at runtime via cpuid, not at compile time.
|
||||
#if defined(__x86_64__)
|
||||
//
|
||||
// Likewise, "cpu_arch >= x86_avx2" also requires PCLMUL, POPCNT and SSE4.2.
|
||||
#if defined(__x86_64__) && !defined(__native_client__)
|
||||
#include <cpuid.h>
|
||||
#include <x86intrin.h>
|
||||
#define WUFFS_BASE__CPU_ARCH__X86_64
|
||||
#endif // defined(__x86_64__)
|
||||
#endif // defined(__x86_64__) && !defined(__native_client__)
|
||||
|
||||
#elif defined(_MSC_VER) // (#if-chain ref AVOID_CPU_ARCH_1)
|
||||
|
||||
@@ -187,6 +203,82 @@ wuffs_base__cpu_arch__have_arm_neon() {
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_NEON)
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__cpu_arch__have_x86_avx2() {
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
// GCC defines these macros but MSVC does not.
|
||||
// - bit_AVX2 = (1 << 5)
|
||||
const unsigned int avx2_ebx7 = 0x00000020;
|
||||
// GCC defines these macros but MSVC does not.
|
||||
// - bit_PCLMUL = (1 << 1)
|
||||
// - bit_POPCNT = (1 << 23)
|
||||
// - bit_SSE4_2 = (1 << 20)
|
||||
const unsigned int avx2_ecx1 = 0x00900002;
|
||||
|
||||
// clang defines __GNUC__ and clang-cl defines _MSC_VER (but not __GNUC__).
|
||||
#if defined(__GNUC__)
|
||||
unsigned int eax7 = 0;
|
||||
unsigned int ebx7 = 0;
|
||||
unsigned int ecx7 = 0;
|
||||
unsigned int edx7 = 0;
|
||||
if (__get_cpuid_count(7, 0, &eax7, &ebx7, &ecx7, &edx7) &&
|
||||
((ebx7 & avx2_ebx7) == avx2_ebx7)) {
|
||||
unsigned int eax1 = 0;
|
||||
unsigned int ebx1 = 0;
|
||||
unsigned int ecx1 = 0;
|
||||
unsigned int edx1 = 0;
|
||||
if (__get_cpuid(1, &eax1, &ebx1, &ecx1, &edx1) &&
|
||||
((ecx1 & avx2_ecx1) == avx2_ecx1)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#elif defined(_MSC_VER) // defined(__GNUC__)
|
||||
int x7[4];
|
||||
__cpuidex(x7, 7, 0);
|
||||
if ((((unsigned int)(x7[1])) & avx2_ebx7) == avx2_ebx7) {
|
||||
int x1[4];
|
||||
__cpuid(x1, 1);
|
||||
if ((((unsigned int)(x1[2])) & avx2_ecx1) == avx2_ecx1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error "WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#endif // defined(__GNUC__); defined(_MSC_VER)
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__cpu_arch__have_x86_bmi2() {
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
// GCC defines these macros but MSVC does not.
|
||||
// - bit_BMI2 = (1 << 8)
|
||||
const unsigned int bmi2_ebx7 = 0x00000100;
|
||||
|
||||
// clang defines __GNUC__ and clang-cl defines _MSC_VER (but not __GNUC__).
|
||||
#if defined(__GNUC__)
|
||||
unsigned int eax7 = 0;
|
||||
unsigned int ebx7 = 0;
|
||||
unsigned int ecx7 = 0;
|
||||
unsigned int edx7 = 0;
|
||||
if (__get_cpuid_count(7, 0, &eax7, &ebx7, &ecx7, &edx7) &&
|
||||
((ebx7 & bmi2_ebx7) == bmi2_ebx7)) {
|
||||
return true;
|
||||
}
|
||||
#elif defined(_MSC_VER) // defined(__GNUC__)
|
||||
int x7[4];
|
||||
__cpuidex(x7, 7, 0);
|
||||
if ((((unsigned int)(x7[1])) & bmi2_ebx7) == bmi2_ebx7) {
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
#error "WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#endif // defined(__GNUC__); defined(_MSC_VER)
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__cpu_arch__have_x86_sse42() {
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
@@ -202,13 +294,16 @@ wuffs_base__cpu_arch__have_x86_sse42() {
|
||||
unsigned int ebx1 = 0;
|
||||
unsigned int ecx1 = 0;
|
||||
unsigned int edx1 = 0;
|
||||
if (__get_cpuid(1, &eax1, &ebx1, &ecx1, &edx1)) {
|
||||
return (ecx1 & sse42_ecx1) == sse42_ecx1;
|
||||
if (__get_cpuid(1, &eax1, &ebx1, &ecx1, &edx1) &&
|
||||
((ecx1 & sse42_ecx1) == sse42_ecx1)) {
|
||||
return true;
|
||||
}
|
||||
#elif defined(_MSC_VER) // defined(__GNUC__)
|
||||
int x[4];
|
||||
__cpuid(x, 1);
|
||||
return (((unsigned int)(x[2])) & sse42_ecx1) == sse42_ecx1;
|
||||
int x1[4];
|
||||
__cpuid(x1, 1);
|
||||
if ((((unsigned int)(x1[2])) & sse42_ecx1) == sse42_ecx1) {
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
#error "WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#endif // defined(__GNUC__); defined(_MSC_VER)
|
||||
@@ -711,6 +806,56 @@ wuffs_base__u64__max(uint64_t x, uint64_t y) {
|
||||
|
||||
// --------
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__u8__rotate_left(uint8_t x, uint32_t n) {
|
||||
n &= 7;
|
||||
return ((uint8_t)(x << n)) | ((uint8_t)(x >> (8 - n)));
|
||||
}
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__u8__rotate_right(uint8_t x, uint32_t n) {
|
||||
n &= 7;
|
||||
return ((uint8_t)(x >> n)) | ((uint8_t)(x << (8 - n)));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__u16__rotate_left(uint16_t x, uint32_t n) {
|
||||
n &= 15;
|
||||
return ((uint16_t)(x << n)) | ((uint16_t)(x >> (16 - n)));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__u16__rotate_right(uint16_t x, uint32_t n) {
|
||||
n &= 15;
|
||||
return ((uint16_t)(x >> n)) | ((uint16_t)(x << (16 - n)));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__rotate_left(uint32_t x, uint32_t n) {
|
||||
n &= 31;
|
||||
return ((uint32_t)(x << n)) | ((uint32_t)(x >> (32 - n)));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__rotate_right(uint32_t x, uint32_t n) {
|
||||
n &= 31;
|
||||
return ((uint32_t)(x >> n)) | ((uint32_t)(x << (32 - n)));
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__u64__rotate_left(uint64_t x, uint32_t n) {
|
||||
n &= 63;
|
||||
return ((uint64_t)(x << n)) | ((uint64_t)(x >> (64 - n)));
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__u64__rotate_right(uint64_t x, uint32_t n) {
|
||||
n &= 63;
|
||||
return ((uint64_t)(x >> n)) | ((uint64_t)(x << (64 - n)));
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// Saturating arithmetic (sat_add, sat_sub) branchless bit-twiddling algorithms
|
||||
// are per https://locklessinc.com/articles/sat_arithmetic/
|
||||
//
|
||||
@@ -6958,6 +7103,7 @@ struct wuffs_deflate__decoder__struct {
|
||||
|
||||
uint32_t f_bits;
|
||||
uint32_t f_n_bits;
|
||||
uint64_t f_transformed_history_count;
|
||||
uint32_t f_history_index;
|
||||
uint32_t f_n_huffs_bits[2];
|
||||
bool f_end_of_block;
|
||||
@@ -6966,6 +7112,10 @@ struct wuffs_deflate__decoder__struct {
|
||||
uint32_t p_decode_blocks[1];
|
||||
uint32_t p_decode_uncompressed[1];
|
||||
uint32_t p_init_dynamic_huffman[1];
|
||||
wuffs_base__status (*choosy_decode_huffman_fast64)(
|
||||
wuffs_deflate__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
uint32_t p_decode_huffman_slow[1];
|
||||
} private_impl;
|
||||
|
||||
@@ -9962,26 +10112,16 @@ extern "C" {
|
||||
// Its (non-zero) value is arbitrary, based on md5sum("disabled").
|
||||
#define WUFFS_BASE__DISABLED ((uint32_t)0x075AE3D2)
|
||||
|
||||
// Denote intentional fallthroughs for -Wimplicit-fallthrough.
|
||||
//
|
||||
// The order matters here. Clang also defines "__GNUC__".
|
||||
#if defined(__clang__) && defined(__cplusplus) && (__cplusplus >= 201103L)
|
||||
#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]
|
||||
#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)
|
||||
#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))
|
||||
#else
|
||||
#define WUFFS_BASE__FALLTHROUGH
|
||||
#endif
|
||||
|
||||
// Use switch cases for coroutine suspension points, similar to the technique
|
||||
// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
|
||||
//
|
||||
// The implicit fallthrough is intentional.
|
||||
//
|
||||
// We use trivial macros instead of an explicit assignment and case statement
|
||||
// so that clang-format doesn't get confused by the unusual "case"s.
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
|
||||
coro_susp_point = n; \
|
||||
WUFFS_BASE__FALLTHROUGH; \
|
||||
case n:;
|
||||
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
@@ -10324,11 +10464,12 @@ wuffs_base__io_reader__set(wuffs_base__io_buffer* b,
|
||||
const uint8_t** ptr_io0_r,
|
||||
const uint8_t** ptr_io1_r,
|
||||
const uint8_t** ptr_io2_r,
|
||||
wuffs_base__slice_u8 data) {
|
||||
wuffs_base__slice_u8 data,
|
||||
uint64_t history_position) {
|
||||
b->data = data;
|
||||
b->meta.wi = data.len;
|
||||
b->meta.ri = 0;
|
||||
b->meta.pos = 0;
|
||||
b->meta.pos = history_position;
|
||||
b->meta.closed = false;
|
||||
|
||||
*ptr_iop_r = data.ptr;
|
||||
@@ -10435,6 +10576,46 @@ wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
return length;
|
||||
}
|
||||
|
||||
// wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast
|
||||
// copies the previous byte (the one immediately before *ptr_iop_w), copying 8
|
||||
// byte chunks at a time. Each chunk contains 8 repetitions of the same byte.
|
||||
//
|
||||
// In terms of number of bytes copied, length is rounded up to a multiple of 8.
|
||||
// As a special case, a zero length rounds up to 8 (even though 0 is already a
|
||||
// multiple of 8), since there is always at least one 8 byte chunk copied.
|
||||
//
|
||||
// In terms of advancing *ptr_iop_w, length is not rounded up.
|
||||
//
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance == 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
uint8_t* p = *ptr_iop_w;
|
||||
uint64_t x = p[-1];
|
||||
x |= x << 8;
|
||||
x |= x << 16;
|
||||
x |= x << 32;
|
||||
uint32_t n = length;
|
||||
while (1) {
|
||||
wuffs_base__poke_u64le__no_bounds_check(p, x);
|
||||
if (n <= 8) {
|
||||
p += n;
|
||||
break;
|
||||
}
|
||||
p += 8;
|
||||
n -= 8;
|
||||
}
|
||||
*ptr_iop_w = p;
|
||||
return length;
|
||||
}
|
||||
|
||||
// wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast is
|
||||
// like the wuffs_base__io_writer__limited_copy_u32_from_history_fast function
|
||||
// above, but copies 8 byte chunks at a time.
|
||||
@@ -10522,11 +10703,12 @@ wuffs_base__io_writer__set(wuffs_base__io_buffer* b,
|
||||
uint8_t** ptr_io0_w,
|
||||
uint8_t** ptr_io1_w,
|
||||
uint8_t** ptr_io2_w,
|
||||
wuffs_base__slice_u8 data) {
|
||||
wuffs_base__slice_u8 data,
|
||||
uint64_t history_position) {
|
||||
b->data = data;
|
||||
b->meta.wi = 0;
|
||||
b->meta.ri = 0;
|
||||
b->meta.pos = 0;
|
||||
b->meta.pos = history_position;
|
||||
b->meta.closed = false;
|
||||
|
||||
*ptr_iop_w = data.ptr;
|
||||
@@ -14091,13 +14273,18 @@ wuffs_base__parse_number_i64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
ret.value = 0;
|
||||
return ret;
|
||||
} else if (negative) {
|
||||
if (r.value > 0x8000000000000000) {
|
||||
goto fail_out_of_bounds;
|
||||
if (r.value < 0x8000000000000000) {
|
||||
wuffs_base__result_i64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = -(int64_t)(r.value);
|
||||
return ret;
|
||||
} else if (r.value == 0x8000000000000000) {
|
||||
wuffs_base__result_i64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = INT64_MIN;
|
||||
return ret;
|
||||
}
|
||||
wuffs_base__result_i64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = -(int64_t)(r.value);
|
||||
return ret;
|
||||
goto fail_out_of_bounds;
|
||||
} else if (r.value > 0x7FFFFFFFFFFFFFFF) {
|
||||
goto fail_out_of_bounds;
|
||||
} else {
|
||||
@@ -19020,6 +19207,34 @@ wuffs_base__pixel_swizzler__y__y_16be(uint8_t* dst_ptr,
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__y_16le__y_16be(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len2 = dst_len / 2;
|
||||
size_t src_len2 = src_len / 2;
|
||||
size_t len = (dst_len2 < src_len2) ? dst_len2 : src_len2;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
while (n >= 1) {
|
||||
uint8_t s0 = s[0];
|
||||
uint8_t s1 = s[1];
|
||||
d[0] = s1;
|
||||
d[1] = s0;
|
||||
|
||||
s += 1 * 2;
|
||||
d += 1 * 2;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
@@ -19106,13 +19321,18 @@ wuffs_base__pixel_swizzler__prepare__y_16be(wuffs_base__pixel_swizzler* p,
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
return wuffs_base__pixel_swizzler__y__y_16be;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16LE:
|
||||
return wuffs_base__pixel_swizzler__y_16le__y_16be;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:
|
||||
return wuffs_base__pixel_swizzler__copy_2_2;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__y_16be;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
return wuffs_base__pixel_swizzler__xxx__y_16be;
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
@@ -20754,8 +20974,8 @@ wuffs_adler32__hasher__up_x86_sse42(
|
||||
__m128i v_ones = {0};
|
||||
__m128i v_weights__left = {0};
|
||||
__m128i v_weights_right = {0};
|
||||
__m128i v_p__left = {0};
|
||||
__m128i v_p_right = {0};
|
||||
__m128i v_q__left = {0};
|
||||
__m128i v_q_right = {0};
|
||||
__m128i v_v1 = {0};
|
||||
__m128i v_v2 = {0};
|
||||
__m128i v_v2j = {0};
|
||||
@@ -20786,13 +21006,13 @@ wuffs_adler32__hasher__up_x86_sse42(
|
||||
v_p.len = 32;
|
||||
uint8_t* i_end0_p = v_p.ptr + (((i_slice_p.len - (size_t)(v_p.ptr - i_slice_p.ptr)) / 32) * 32);
|
||||
while (v_p.ptr < i_end0_p) {
|
||||
v_p__left = _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr));
|
||||
v_p_right = _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr + 16));
|
||||
v_q__left = _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr));
|
||||
v_q_right = _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr + 16));
|
||||
v_v2j = _mm_add_epi32(v_v2j, v_v1);
|
||||
v_v1 = _mm_add_epi32(v_v1, _mm_sad_epu8(v_p__left, v_zeroes));
|
||||
v_v1 = _mm_add_epi32(v_v1, _mm_sad_epu8(v_p_right, v_zeroes));
|
||||
v_v2k = _mm_add_epi32(v_v2k, _mm_madd_epi16(v_ones, _mm_maddubs_epi16(v_p__left, v_weights__left)));
|
||||
v_v2k = _mm_add_epi32(v_v2k, _mm_madd_epi16(v_ones, _mm_maddubs_epi16(v_p_right, v_weights_right)));
|
||||
v_v1 = _mm_add_epi32(v_v1, _mm_sad_epu8(v_q__left, v_zeroes));
|
||||
v_v1 = _mm_add_epi32(v_v1, _mm_sad_epu8(v_q_right, v_zeroes));
|
||||
v_v2k = _mm_add_epi32(v_v2k, _mm_madd_epi16(v_ones, _mm_maddubs_epi16(v_q__left, v_weights__left)));
|
||||
v_v2k = _mm_add_epi32(v_v2k, _mm_madd_epi16(v_ones, _mm_maddubs_epi16(v_q_right, v_weights_right)));
|
||||
v_p.ptr += 32;
|
||||
}
|
||||
v_p.len = 0;
|
||||
@@ -21157,7 +21377,7 @@ wuffs_bmp__decoder__decode_image_config(
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_padding -= 14;
|
||||
self->private_impl.f_io_redirect_pos = wuffs_base__u64__sat_add(((uint64_t)(self->private_impl.f_padding)), wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src))));
|
||||
self->private_impl.f_io_redirect_pos = wuffs_base__u64__sat_add(((uint64_t)(self->private_impl.f_padding)), wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))));
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint32_t t_2;
|
||||
@@ -21906,7 +22126,7 @@ wuffs_bmp__decoder__decode_image_config(
|
||||
} else if (self->private_impl.f_bits_per_pixel == 32) {
|
||||
self->private_impl.f_pad_per_row = 0;
|
||||
}
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
if (a_dst != NULL) {
|
||||
v_dst_pixfmt = 2164295816;
|
||||
if ((self->private_impl.f_channel_num_bits[0] > 8) ||
|
||||
@@ -21926,7 +22146,6 @@ wuffs_bmp__decoder__decode_image_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -22005,7 +22224,7 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
@@ -22035,7 +22254,6 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -22223,7 +22441,6 @@ wuffs_bmp__decoder__decode_frame(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -22337,7 +22554,6 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -22600,7 +22816,6 @@ wuffs_bmp__decoder__swizzle_rle(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -22741,7 +22956,6 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -22910,7 +23124,6 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -23996,7 +24209,6 @@ wuffs_cbor__decoder__decode_tokens(
|
||||
label__outer__break:;
|
||||
self->private_impl.f_end_of_data = true;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_tokens[0] = 0;
|
||||
goto exit;
|
||||
@@ -24614,6 +24826,13 @@ wuffs_crc32__ieee_hasher__up_arm_crc32(
|
||||
wuffs_base__slice_u8 a_x);
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_CRC32)
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_crc32__ieee_hasher__up_x86_avx2(
|
||||
wuffs_crc32__ieee_hasher* self,
|
||||
wuffs_base__slice_u8 a_x);
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_crc32__ieee_hasher__up_x86_sse42(
|
||||
@@ -24733,6 +24952,9 @@ wuffs_crc32__ieee_hasher__update_u32(
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__ARM_CRC32)
|
||||
wuffs_base__cpu_arch__have_arm_crc32() ? &wuffs_crc32__ieee_hasher__up_arm_crc32 :
|
||||
#endif
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
wuffs_base__cpu_arch__have_x86_avx2() ? &wuffs_crc32__ieee_hasher__up_x86_avx2 :
|
||||
#endif
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
wuffs_base__cpu_arch__have_x86_sse42() ? &wuffs_crc32__ieee_hasher__up_x86_sse42 :
|
||||
#endif
|
||||
@@ -24920,6 +25142,125 @@ wuffs_crc32__ieee_hasher__up_arm_crc32(
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_CRC32)
|
||||
// ‼ WUFFS MULTI-FILE SECTION -arm_crc32
|
||||
|
||||
// ‼ WUFFS MULTI-FILE SECTION +x86_avx2
|
||||
// -------- func crc32.ieee_hasher.up_x86_avx2
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2,avx2")
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_crc32__ieee_hasher__up_x86_avx2(
|
||||
wuffs_crc32__ieee_hasher* self,
|
||||
wuffs_base__slice_u8 a_x) {
|
||||
uint32_t v_s = 0;
|
||||
wuffs_base__slice_u8 v_p = {0};
|
||||
__m128i v_k = {0};
|
||||
__m128i v_x0 = {0};
|
||||
__m128i v_x1 = {0};
|
||||
__m128i v_x2 = {0};
|
||||
__m128i v_x3 = {0};
|
||||
__m128i v_y0 = {0};
|
||||
__m128i v_y1 = {0};
|
||||
__m128i v_y2 = {0};
|
||||
__m128i v_y3 = {0};
|
||||
uint64_t v_tail_index = 0;
|
||||
|
||||
v_s = (4294967295 ^ self->private_impl.f_state);
|
||||
while ((((uint64_t)(a_x.len)) > 0) && ((15 & ((uint32_t)(0xFFF & (uintptr_t)(a_x.ptr)))) != 0)) {
|
||||
v_s = (WUFFS_CRC32__IEEE_TABLE[0][(((uint8_t)((v_s & 255))) ^ a_x.ptr[0])] ^ (v_s >> 8));
|
||||
a_x = wuffs_base__slice_u8__subslice_i(a_x, 1);
|
||||
}
|
||||
if (((uint64_t)(a_x.len)) < 64) {
|
||||
{
|
||||
wuffs_base__slice_u8 i_slice_p = a_x;
|
||||
v_p.ptr = i_slice_p.ptr;
|
||||
v_p.len = 1;
|
||||
uint8_t* i_end0_p = i_slice_p.ptr + i_slice_p.len;
|
||||
while (v_p.ptr < i_end0_p) {
|
||||
v_s = (WUFFS_CRC32__IEEE_TABLE[0][(((uint8_t)((v_s & 255))) ^ v_p.ptr[0])] ^ (v_s >> 8));
|
||||
v_p.ptr += 1;
|
||||
}
|
||||
v_p.len = 0;
|
||||
}
|
||||
self->private_impl.f_state = (4294967295 ^ v_s);
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
v_x0 = _mm_lddqu_si128((const __m128i*)(const void*)(a_x.ptr + 0));
|
||||
v_x1 = _mm_lddqu_si128((const __m128i*)(const void*)(a_x.ptr + 16));
|
||||
v_x2 = _mm_lddqu_si128((const __m128i*)(const void*)(a_x.ptr + 32));
|
||||
v_x3 = _mm_lddqu_si128((const __m128i*)(const void*)(a_x.ptr + 48));
|
||||
v_x0 = _mm_xor_si128(v_x0, _mm_cvtsi32_si128((int32_t)(v_s)));
|
||||
v_k = _mm_lddqu_si128((const __m128i*)(const void*)(WUFFS_CRC32__IEEE_X86_SSE42_K1K2));
|
||||
{
|
||||
wuffs_base__slice_u8 i_slice_p = wuffs_base__slice_u8__subslice_i(a_x, 64);
|
||||
v_p.ptr = i_slice_p.ptr;
|
||||
v_p.len = 64;
|
||||
uint8_t* i_end0_p = v_p.ptr + (((i_slice_p.len - (size_t)(v_p.ptr - i_slice_p.ptr)) / 64) * 64);
|
||||
while (v_p.ptr < i_end0_p) {
|
||||
v_y0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(0));
|
||||
v_y1 = _mm_clmulepi64_si128(v_x1, v_k, (int32_t)(0));
|
||||
v_y2 = _mm_clmulepi64_si128(v_x2, v_k, (int32_t)(0));
|
||||
v_y3 = _mm_clmulepi64_si128(v_x3, v_k, (int32_t)(0));
|
||||
v_x0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(17));
|
||||
v_x1 = _mm_clmulepi64_si128(v_x1, v_k, (int32_t)(17));
|
||||
v_x2 = _mm_clmulepi64_si128(v_x2, v_k, (int32_t)(17));
|
||||
v_x3 = _mm_clmulepi64_si128(v_x3, v_k, (int32_t)(17));
|
||||
v_x0 = _mm_xor_si128(_mm_xor_si128(v_x0, v_y0), _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr + 0)));
|
||||
v_x1 = _mm_xor_si128(_mm_xor_si128(v_x1, v_y1), _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr + 16)));
|
||||
v_x2 = _mm_xor_si128(_mm_xor_si128(v_x2, v_y2), _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr + 32)));
|
||||
v_x3 = _mm_xor_si128(_mm_xor_si128(v_x3, v_y3), _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr + 48)));
|
||||
v_p.ptr += 64;
|
||||
}
|
||||
v_p.len = 0;
|
||||
}
|
||||
v_k = _mm_lddqu_si128((const __m128i*)(const void*)(WUFFS_CRC32__IEEE_X86_SSE42_K3K4));
|
||||
v_y0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(0));
|
||||
v_x0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(17));
|
||||
v_x0 = _mm_xor_si128(v_x0, v_x1);
|
||||
v_x0 = _mm_xor_si128(v_x0, v_y0);
|
||||
v_y0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(0));
|
||||
v_x0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(17));
|
||||
v_x0 = _mm_xor_si128(v_x0, v_x2);
|
||||
v_x0 = _mm_xor_si128(v_x0, v_y0);
|
||||
v_y0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(0));
|
||||
v_x0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(17));
|
||||
v_x0 = _mm_xor_si128(v_x0, v_x3);
|
||||
v_x0 = _mm_xor_si128(v_x0, v_y0);
|
||||
v_x1 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(16));
|
||||
v_x2 = _mm_set_epi32((int32_t)(0), (int32_t)(4294967295), (int32_t)(0), (int32_t)(4294967295));
|
||||
v_x0 = _mm_srli_si128(v_x0, (int32_t)(8));
|
||||
v_x0 = _mm_xor_si128(v_x0, v_x1);
|
||||
v_k = _mm_lddqu_si128((const __m128i*)(const void*)(WUFFS_CRC32__IEEE_X86_SSE42_K5ZZ));
|
||||
v_x1 = _mm_srli_si128(v_x0, (int32_t)(4));
|
||||
v_x0 = _mm_and_si128(v_x0, v_x2);
|
||||
v_x0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(0));
|
||||
v_x0 = _mm_xor_si128(v_x0, v_x1);
|
||||
v_k = _mm_lddqu_si128((const __m128i*)(const void*)(WUFFS_CRC32__IEEE_X86_SSE42_PXMU));
|
||||
v_x1 = _mm_and_si128(v_x0, v_x2);
|
||||
v_x1 = _mm_clmulepi64_si128(v_x1, v_k, (int32_t)(16));
|
||||
v_x1 = _mm_and_si128(v_x1, v_x2);
|
||||
v_x1 = _mm_clmulepi64_si128(v_x1, v_k, (int32_t)(0));
|
||||
v_x0 = _mm_xor_si128(v_x0, v_x1);
|
||||
v_s = ((uint32_t)(_mm_extract_epi32(v_x0, (int32_t)(1))));
|
||||
v_tail_index = (((uint64_t)(a_x.len)) & 18446744073709551552u);
|
||||
if (v_tail_index < ((uint64_t)(a_x.len))) {
|
||||
{
|
||||
wuffs_base__slice_u8 i_slice_p = wuffs_base__slice_u8__subslice_i(a_x, v_tail_index);
|
||||
v_p.ptr = i_slice_p.ptr;
|
||||
v_p.len = 1;
|
||||
uint8_t* i_end0_p = i_slice_p.ptr + i_slice_p.len;
|
||||
while (v_p.ptr < i_end0_p) {
|
||||
v_s = (WUFFS_CRC32__IEEE_TABLE[0][(((uint8_t)((v_s & 255))) ^ v_p.ptr[0])] ^ (v_s >> 8));
|
||||
v_p.ptr += 1;
|
||||
}
|
||||
v_p.len = 0;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_state = (4294967295 ^ v_s);
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
// ‼ WUFFS MULTI-FILE SECTION -x86_avx2
|
||||
|
||||
// ‼ WUFFS MULTI-FILE SECTION +x86_sse42
|
||||
// -------- func crc32.ieee_hasher.up_x86_sse42
|
||||
|
||||
@@ -25161,6 +25502,14 @@ wuffs_deflate__decoder__init_huff(
|
||||
uint32_t a_n_codes1,
|
||||
uint32_t a_base_symbol);
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
static wuffs_base__status
|
||||
wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
wuffs_deflate__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
wuffs_deflate__decoder* self,
|
||||
@@ -25173,6 +25522,12 @@ wuffs_deflate__decoder__decode_huffman_fast64(
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
wuffs_deflate__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_deflate__decoder__decode_huffman_slow(
|
||||
wuffs_deflate__decoder* self,
|
||||
@@ -25234,6 +25589,8 @@ wuffs_deflate__decoder__initialize(
|
||||
}
|
||||
}
|
||||
|
||||
self->private_impl.choosy_decode_huffman_fast64 = &wuffs_deflate__decoder__decode_huffman_fast64__choosy_default;
|
||||
|
||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||
self->private_impl.vtable_for__wuffs_base__io_transformer.vtable_name =
|
||||
wuffs_base__io_transformer__vtable_name;
|
||||
@@ -25380,6 +25737,11 @@ wuffs_deflate__decoder__transform_io(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
self->private_impl.choosy_decode_huffman_fast64 = (
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
wuffs_base__cpu_arch__have_x86_bmi2() ? &wuffs_deflate__decoder__decode_huffman_bmi2 :
|
||||
#endif
|
||||
self->private_impl.choosy_decode_huffman_fast64);
|
||||
while (true) {
|
||||
v_mark = ((uint64_t)(iop_a_dst - io0_a_dst));
|
||||
{
|
||||
@@ -25402,12 +25764,12 @@ wuffs_deflate__decoder__transform_io(
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_transformed_history_count, wuffs_base__io__count_since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst))));
|
||||
wuffs_deflate__decoder__add_history(self, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst)), io0_a_dst));
|
||||
status = v_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -25565,7 +25927,6 @@ wuffs_deflate__decoder__decode_blocks(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_blocks[0] = 0;
|
||||
goto exit;
|
||||
@@ -25685,7 +26046,6 @@ wuffs_deflate__decoder__decode_uncompressed(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_uncompressed[0] = 0;
|
||||
goto exit;
|
||||
@@ -26268,6 +26628,223 @@ wuffs_deflate__decoder__init_huff(
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
// ‼ WUFFS MULTI-FILE SECTION +x86_bmi2
|
||||
// -------- func deflate.decoder.decode_huffman_bmi2
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("bmi2")
|
||||
static wuffs_base__status
|
||||
wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
wuffs_deflate__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint64_t v_bits = 0;
|
||||
uint32_t v_n_bits = 0;
|
||||
uint32_t v_table_entry = 0;
|
||||
uint32_t v_table_entry_n_bits = 0;
|
||||
uint64_t v_lmask = 0;
|
||||
uint64_t v_dmask = 0;
|
||||
uint32_t v_redir_top = 0;
|
||||
uint32_t v_redir_mask = 0;
|
||||
uint32_t v_length = 0;
|
||||
uint32_t v_dist_minus_1 = 0;
|
||||
uint32_t v_hlen = 0;
|
||||
uint32_t v_hdist = 0;
|
||||
uint32_t v_hdist_adjustment = 0;
|
||||
|
||||
uint8_t* iop_a_dst = NULL;
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
io2_a_dst = io0_a_dst + a_dst->data.len;
|
||||
if (a_dst->meta.closed) {
|
||||
io2_a_dst = iop_a_dst;
|
||||
}
|
||||
}
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
if ((self->private_impl.f_n_bits >= 8) || ((self->private_impl.f_bits >> (self->private_impl.f_n_bits & 7)) != 0)) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_n_bits);
|
||||
goto exit;
|
||||
}
|
||||
v_bits = ((uint64_t)(self->private_impl.f_bits));
|
||||
v_n_bits = self->private_impl.f_n_bits;
|
||||
v_lmask = ((((uint64_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1);
|
||||
v_dmask = ((((uint64_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1);
|
||||
if (self->private_impl.f_transformed_history_count < (a_dst ? a_dst->meta.pos : 0)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist_adjustment = ((uint32_t)(((self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0)) & 4294967295)));
|
||||
label__loop__continue:;
|
||||
while ((((uint64_t)(io2_a_dst - iop_a_dst)) >= 266) && (((uint64_t)(io2_a_src - iop_a_src)) >= 8)) {
|
||||
v_bits |= ((uint64_t)(wuffs_base__peek_u64le__no_bounds_check(iop_a_src) << (v_n_bits & 63)));
|
||||
iop_a_src += ((63 - (v_n_bits & 63)) >> 3);
|
||||
v_n_bits |= 56;
|
||||
v_table_entry = self->private_data.f_huffs[0][(v_bits & v_lmask)];
|
||||
v_table_entry_n_bits = (v_table_entry & 15);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
if ((v_table_entry >> 31) != 0) {
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(((v_table_entry >> 8) & 255)))), iop_a_dst += 1);
|
||||
goto label__loop__continue;
|
||||
} else if ((v_table_entry >> 30) != 0) {
|
||||
} else if ((v_table_entry >> 29) != 0) {
|
||||
self->private_impl.f_end_of_block = true;
|
||||
goto label__loop__break;
|
||||
} else if ((v_table_entry >> 28) != 0) {
|
||||
v_redir_top = ((v_table_entry >> 8) & 65535);
|
||||
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
|
||||
v_table_entry = self->private_data.f_huffs[0][((v_redir_top + (((uint32_t)((v_bits & 4294967295))) & v_redir_mask)) & 1023)];
|
||||
v_table_entry_n_bits = (v_table_entry & 15);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
if ((v_table_entry >> 31) != 0) {
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(((v_table_entry >> 8) & 255)))), iop_a_dst += 1);
|
||||
goto label__loop__continue;
|
||||
} else if ((v_table_entry >> 30) != 0) {
|
||||
} else if ((v_table_entry >> 29) != 0) {
|
||||
self->private_impl.f_end_of_block = true;
|
||||
goto label__loop__break;
|
||||
} else if ((v_table_entry >> 28) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state);
|
||||
goto exit;
|
||||
} else if ((v_table_entry >> 27) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_huffman_code);
|
||||
goto exit;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state);
|
||||
goto exit;
|
||||
}
|
||||
} else if ((v_table_entry >> 27) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_huffman_code);
|
||||
goto exit;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state);
|
||||
goto exit;
|
||||
}
|
||||
v_length = (((v_table_entry >> 8) & 255) + 3);
|
||||
v_table_entry_n_bits = ((v_table_entry >> 4) & 15);
|
||||
if (v_table_entry_n_bits > 0) {
|
||||
v_length = (((v_length + 253 + ((uint32_t)(((v_bits) & WUFFS_BASE__LOW_BITS_MASK__U64(v_table_entry_n_bits))))) & 255) + 3);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
}
|
||||
v_table_entry = self->private_data.f_huffs[1][(v_bits & v_dmask)];
|
||||
v_table_entry_n_bits = (v_table_entry & 15);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
if ((v_table_entry >> 28) == 1) {
|
||||
v_redir_top = ((v_table_entry >> 8) & 65535);
|
||||
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
|
||||
v_table_entry = self->private_data.f_huffs[1][((v_redir_top + (((uint32_t)((v_bits & 4294967295))) & v_redir_mask)) & 1023)];
|
||||
v_table_entry_n_bits = (v_table_entry & 15);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
}
|
||||
if ((v_table_entry >> 24) != 64) {
|
||||
if ((v_table_entry >> 24) == 8) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_huffman_code);
|
||||
goto exit;
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state);
|
||||
goto exit;
|
||||
}
|
||||
v_dist_minus_1 = ((v_table_entry >> 8) & 32767);
|
||||
v_table_entry_n_bits = ((v_table_entry >> 4) & 15);
|
||||
v_dist_minus_1 = ((v_dist_minus_1 + ((uint32_t)(((v_bits) & WUFFS_BASE__LOW_BITS_MASK__U64(v_table_entry_n_bits))))) & 32767);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
while (true) {
|
||||
if (((uint64_t)((v_dist_minus_1 + 1))) > ((uint64_t)(iop_a_dst - io0_a_dst))) {
|
||||
v_hlen = 0;
|
||||
v_hdist = ((uint32_t)((((uint64_t)((v_dist_minus_1 + 1))) - ((uint64_t)(iop_a_dst - io0_a_dst)))));
|
||||
if (v_length > v_hdist) {
|
||||
v_length -= v_hdist;
|
||||
v_hlen = v_hdist;
|
||||
} else {
|
||||
v_hlen = v_length;
|
||||
v_length = 0;
|
||||
}
|
||||
v_hdist += v_hdist_adjustment;
|
||||
if (self->private_impl.f_history_index < v_hdist) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767)));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
if ((((uint64_t)((v_dist_minus_1 + 1))) > ((uint64_t)(iop_a_dst - io0_a_dst))) || (((uint64_t)(v_length)) > ((uint64_t)(io2_a_dst - iop_a_dst))) || (((uint64_t)((v_length + 8))) > ((uint64_t)(io2_a_dst - iop_a_dst)))) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_distance);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
if ((v_dist_minus_1 + 1) >= 8) {
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
} else if ((v_dist_minus_1 + 1) == 1) {
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
} else {
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_fast(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
}
|
||||
goto label__0__break;
|
||||
}
|
||||
label__0__break:;
|
||||
}
|
||||
label__loop__break:;
|
||||
if (v_n_bits > 63) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_n_bits);
|
||||
goto exit;
|
||||
}
|
||||
while (v_n_bits >= 8) {
|
||||
v_n_bits -= 8;
|
||||
if (iop_a_src > io1_a_src) {
|
||||
iop_a_src--;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_bits = ((uint32_t)((v_bits & ((((uint64_t)(1)) << v_n_bits) - 1))));
|
||||
self->private_impl.f_n_bits = v_n_bits;
|
||||
if ((self->private_impl.f_n_bits >= 8) || ((self->private_impl.f_bits >> self->private_impl.f_n_bits) != 0)) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_n_bits);
|
||||
goto exit;
|
||||
}
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
// ‼ WUFFS MULTI-FILE SECTION -x86_bmi2
|
||||
|
||||
// -------- func deflate.decoder.decode_huffman_fast32
|
||||
|
||||
static wuffs_base__status
|
||||
@@ -26289,6 +26866,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
uint32_t v_dist_minus_1 = 0;
|
||||
uint32_t v_hlen = 0;
|
||||
uint32_t v_hdist = 0;
|
||||
uint32_t v_hdist_adjustment = 0;
|
||||
|
||||
uint8_t* iop_a_dst = NULL;
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
@@ -26322,6 +26900,11 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
v_n_bits = self->private_impl.f_n_bits;
|
||||
v_lmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1);
|
||||
v_dmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1);
|
||||
if (self->private_impl.f_transformed_history_count < (a_dst ? a_dst->meta.pos : 0)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist_adjustment = ((uint32_t)(((self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0)) & 4294967295)));
|
||||
label__loop__continue:;
|
||||
while ((((uint64_t)(io2_a_dst - iop_a_dst)) >= 266) && (((uint64_t)(io2_a_src - iop_a_src)) >= 12)) {
|
||||
if (v_n_bits < 15) {
|
||||
@@ -26464,6 +27047,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
v_hlen = v_length;
|
||||
v_length = 0;
|
||||
}
|
||||
v_hdist += v_hdist_adjustment;
|
||||
if (self->private_impl.f_history_index < v_hdist) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
@@ -26525,6 +27109,14 @@ wuffs_deflate__decoder__decode_huffman_fast64(
|
||||
wuffs_deflate__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
return (*self->private_impl.choosy_decode_huffman_fast64)(self, a_dst, a_src);
|
||||
}
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
wuffs_deflate__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint64_t v_bits = 0;
|
||||
@@ -26539,6 +27131,7 @@ wuffs_deflate__decoder__decode_huffman_fast64(
|
||||
uint32_t v_dist_minus_1 = 0;
|
||||
uint32_t v_hlen = 0;
|
||||
uint32_t v_hdist = 0;
|
||||
uint32_t v_hdist_adjustment = 0;
|
||||
|
||||
uint8_t* iop_a_dst = NULL;
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
@@ -26572,6 +27165,11 @@ wuffs_deflate__decoder__decode_huffman_fast64(
|
||||
v_n_bits = self->private_impl.f_n_bits;
|
||||
v_lmask = ((((uint64_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1);
|
||||
v_dmask = ((((uint64_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1);
|
||||
if (self->private_impl.f_transformed_history_count < (a_dst ? a_dst->meta.pos : 0)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist_adjustment = ((uint32_t)(((self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0)) & 4294967295)));
|
||||
label__loop__continue:;
|
||||
while ((((uint64_t)(io2_a_dst - iop_a_dst)) >= 266) && (((uint64_t)(io2_a_src - iop_a_src)) >= 8)) {
|
||||
v_bits |= ((uint64_t)(wuffs_base__peek_u64le__no_bounds_check(iop_a_src) << (v_n_bits & 63)));
|
||||
@@ -26662,6 +27260,7 @@ wuffs_deflate__decoder__decode_huffman_fast64(
|
||||
v_hlen = v_length;
|
||||
v_length = 0;
|
||||
}
|
||||
v_hdist += v_hdist_adjustment;
|
||||
if (self->private_impl.f_history_index < v_hdist) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
@@ -26680,6 +27279,9 @@ wuffs_deflate__decoder__decode_huffman_fast64(
|
||||
if ((v_dist_minus_1 + 1) >= 8) {
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
} else if ((v_dist_minus_1 + 1) == 1) {
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
} else {
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_fast(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
@@ -26993,6 +27595,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_hlen = v_length;
|
||||
v_length = 0;
|
||||
}
|
||||
v_hdist += ((uint32_t)((((uint64_t)(self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0))) & 4294967295)));
|
||||
if (self->private_impl.f_history_index < v_hdist) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
@@ -27055,7 +27658,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_huffman_slow[0] = 0;
|
||||
goto exit;
|
||||
@@ -27327,7 +27929,6 @@ wuffs_lzw__decoder__transform_io(
|
||||
}
|
||||
label__0__break:;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -27571,7 +28172,6 @@ wuffs_lzw__decoder__write_to(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_write_to[0] = 0;
|
||||
goto exit;
|
||||
@@ -28061,7 +28661,7 @@ wuffs_gif__decoder__tell_me_more(
|
||||
while (true) {
|
||||
label__0__continue:;
|
||||
while (true) {
|
||||
if (wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src))) != self->private_impl.f_metadata_io_position) {
|
||||
if (wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) != self->private_impl.f_metadata_io_position) {
|
||||
if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
2,
|
||||
@@ -28100,13 +28700,13 @@ wuffs_gif__decoder__tell_me_more(
|
||||
} else {
|
||||
iop_a_src += 1;
|
||||
}
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add(wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src))), v_chunk_length);
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add(wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))), v_chunk_length);
|
||||
if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
3,
|
||||
self->private_impl.f_metadata_fourcc,
|
||||
0,
|
||||
wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src))),
|
||||
wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))),
|
||||
self->private_impl.f_metadata_io_position);
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__even_more_information);
|
||||
@@ -28127,7 +28727,6 @@ wuffs_gif__decoder__tell_me_more(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_tell_me_more[0] = 0;
|
||||
goto exit;
|
||||
@@ -28395,7 +28994,6 @@ wuffs_gif__decoder__decode_frame_config(
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1);
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -28634,9 +29232,9 @@ wuffs_gif__decoder__decode_up_to_id_part1(
|
||||
|
||||
if ( ! self->private_impl.f_restarted) {
|
||||
if (self->private_impl.f_call_sequence != 2) {
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
}
|
||||
} else if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
} else if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
} else {
|
||||
@@ -29061,7 +29659,6 @@ wuffs_gif__decoder__decode_extension(
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_extension[0] = 0;
|
||||
goto exit;
|
||||
@@ -29130,7 +29727,6 @@ wuffs_gif__decoder__skip_blocks(
|
||||
iop_a_src += self->private_data.s_skip_blocks[0].scratch;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_skip_blocks[0] = 0;
|
||||
goto exit;
|
||||
@@ -29323,13 +29919,13 @@ wuffs_gif__decoder__decode_ae(
|
||||
} else if (self->private_impl.f_ignore_metadata) {
|
||||
} else if (v_is_iccp && self->private_impl.f_report_metadata_iccp) {
|
||||
self->private_impl.f_metadata_fourcc = 1229144912;
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_call_sequence = 1;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
} else if (v_is_xmp && self->private_impl.f_report_metadata_xmp) {
|
||||
self->private_impl.f_metadata_fourcc = 1481461792;
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_call_sequence = 1;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
@@ -29349,7 +29945,6 @@ wuffs_gif__decoder__decode_ae(
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_ae[0] = 0;
|
||||
goto exit;
|
||||
@@ -29819,7 +30414,6 @@ wuffs_gif__decoder__decode_id_part1(
|
||||
wuffs_lzw__decoder__set_literal_width(&self->private_data.f_lzw, ((uint32_t)(v_lw)));
|
||||
self->private_impl.f_previous_lzw_decode_ended_abruptly = true;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_id_part1[0] = 0;
|
||||
goto exit;
|
||||
@@ -29955,7 +30549,8 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
wuffs_base__slice_u8__subslice_ij(wuffs_base__make_slice_u8(self->private_data.f_compressed,
|
||||
4096),
|
||||
self->private_impl.f_compressed_ri,
|
||||
self->private_impl.f_compressed_wi));
|
||||
self->private_impl.f_compressed_wi),
|
||||
0);
|
||||
v_mark = ((uint64_t)(iop_v_r - io0_v_r));
|
||||
{
|
||||
u_r.meta.ri = ((size_t)(iop_v_r - u_r.data.ptr));
|
||||
@@ -30026,7 +30621,6 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_id_part2[0] = 0;
|
||||
goto exit;
|
||||
@@ -30636,7 +31230,6 @@ wuffs_gzip__decoder__transform_io(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -32093,7 +32686,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
self->private_impl.f_end_of_data = true;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_tokens[0] = 0;
|
||||
goto exit;
|
||||
@@ -32395,7 +32987,6 @@ wuffs_json__decoder__decode_leading(
|
||||
}
|
||||
label__0__break:;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_leading[0] = 0;
|
||||
goto exit;
|
||||
@@ -32537,16 +33128,19 @@ wuffs_json__decoder__decode_comment(
|
||||
}
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
if (v_length > 0) {
|
||||
if (a_src && a_src->meta.closed) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
self->private_impl.f_comment_type = 2;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
} else if (v_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
}
|
||||
if (a_src && a_src->meta.closed) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
v_length = 0;
|
||||
@@ -32554,10 +33148,9 @@ wuffs_json__decoder__decode_comment(
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 10) {
|
||||
iop_a_src += 1;
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)((v_length + 1))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
self->private_impl.f_comment_type = 2;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
@@ -32576,7 +33169,6 @@ wuffs_json__decoder__decode_comment(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_comment[0] = 0;
|
||||
goto exit;
|
||||
@@ -32737,7 +33329,6 @@ wuffs_json__decoder__decode_inf_nan(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_inf_nan[0] = 0;
|
||||
goto exit;
|
||||
@@ -32883,7 +33474,6 @@ wuffs_json__decoder__decode_trailer(
|
||||
}
|
||||
label__outer__break:;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_trailer[0] = 0;
|
||||
goto exit;
|
||||
@@ -33328,7 +33918,7 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
if (16 != wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
if (16 != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
@@ -33358,7 +33948,6 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -33467,7 +34056,6 @@ wuffs_nie__decoder__decode_frame(
|
||||
label__0__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -33557,7 +34145,6 @@ wuffs_nie__decoder__swizzle(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -34157,7 +34744,6 @@ wuffs_zlib__decoder__transform_io(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -36296,7 +36882,7 @@ wuffs_png__decoder__decode_image_config(
|
||||
status = wuffs_base__make_status(wuffs_png__error__missing_palette);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
if (a_dst != NULL) {
|
||||
wuffs_base__image_config__set(
|
||||
a_dst,
|
||||
@@ -36309,7 +36895,6 @@ wuffs_png__decoder__decode_image_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -36388,7 +36973,7 @@ wuffs_png__decoder__decode_ihdr(
|
||||
}
|
||||
v_a32 = t_0;
|
||||
}
|
||||
if (v_a32 >= 2147483648) {
|
||||
if ((v_a32 == 0) || (v_a32 >= 2147483648)) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_header);
|
||||
goto exit;
|
||||
} else if (v_a32 >= 16777216) {
|
||||
@@ -36425,7 +37010,7 @@ wuffs_png__decoder__decode_ihdr(
|
||||
}
|
||||
v_a32 = t_1;
|
||||
}
|
||||
if (v_a32 >= 2147483648) {
|
||||
if ((v_a32 == 0) || (v_a32 >= 2147483648)) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_header);
|
||||
goto exit;
|
||||
} else if (v_a32 >= 16777216) {
|
||||
@@ -36558,7 +37143,7 @@ wuffs_png__decoder__assign_filter_distance(
|
||||
self->private_impl.f_src_pixfmt = 536870920;
|
||||
self->private_impl.f_filter_distance = 1;
|
||||
} else if (self->private_impl.f_depth == 16) {
|
||||
self->private_impl.f_dst_pixfmt = 536870920;
|
||||
self->private_impl.f_dst_pixfmt = 536870923;
|
||||
self->private_impl.f_src_pixfmt = 537919499;
|
||||
self->private_impl.f_filter_distance = 2;
|
||||
}
|
||||
@@ -37005,7 +37590,7 @@ wuffs_png__decoder__decode_frame_config(
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
@@ -37035,7 +37620,6 @@ wuffs_png__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -37162,7 +37746,6 @@ wuffs_png__decoder__decode_frame(
|
||||
label__0__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -37241,7 +37824,8 @@ wuffs_png__decoder__decode_pass(
|
||||
&io2_v_w,
|
||||
wuffs_base__slice_u8__subslice_ij(a_workbuf,
|
||||
self->private_impl.f_workbuf_wi,
|
||||
self->private_impl.f_pass_workbuf_length));
|
||||
self->private_impl.f_pass_workbuf_length),
|
||||
self->private_impl.f_workbuf_wi);
|
||||
{
|
||||
const uint8_t *o_1_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
@@ -37461,7 +38045,6 @@ wuffs_png__decoder__decode_pass(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_pass[0] = 0;
|
||||
goto exit;
|
||||
@@ -38141,7 +38724,7 @@ wuffs_wbmp__decoder__decode_image_config(
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
if (a_dst != NULL) {
|
||||
wuffs_base__image_config__set(
|
||||
a_dst,
|
||||
@@ -38235,7 +38818,7 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
@@ -38265,7 +38848,6 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -38430,7 +39012,6 @@ wuffs_wbmp__decoder__decode_frame(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -38767,7 +39348,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
// Prepare the low-level CBOR decoder.
|
||||
wuffs_cbor__decoder::unique_ptr dec = wuffs_cbor__decoder::alloc();
|
||||
if (!dec) {
|
||||
ret_error_message = "wuffs_aux::CborDecoder: out of memory";
|
||||
ret_error_message = "wuffs_aux::DecodeCbor: out of memory";
|
||||
goto done;
|
||||
}
|
||||
for (size_t i = 0; i < quirks.len; i++) {
|
||||
@@ -38782,7 +39363,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
wuffs_base__status tok_status = wuffs_base__make_status(nullptr);
|
||||
|
||||
// Prepare other state.
|
||||
uint32_t depth = 0;
|
||||
int32_t depth = 0;
|
||||
std::string str;
|
||||
int64_t extension_category = 0;
|
||||
uint64_t extension_detail = 0;
|
||||
@@ -38809,17 +39390,17 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
goto done;
|
||||
} else if (cursor_index != io_buf->meta.ri) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad cursor_index";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad cursor_index";
|
||||
goto done;
|
||||
} else if (io_buf->meta.closed) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: io_buf is closed";
|
||||
"wuffs_aux::DecodeCbor: internal error: io_buf is closed";
|
||||
goto done;
|
||||
}
|
||||
io_buf->compact();
|
||||
if (io_buf->meta.wi >= io_buf->data.len) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: io_buf is full";
|
||||
"wuffs_aux::DecodeCbor: internal error: io_buf is full";
|
||||
goto done;
|
||||
}
|
||||
cursor_index = io_buf->meta.ri;
|
||||
@@ -38831,11 +39412,19 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
|
||||
if (WUFFS_CBOR__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad WORKBUF_LEN";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad WORKBUF_LEN";
|
||||
goto done;
|
||||
}
|
||||
wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8();
|
||||
tok_status = dec->decode_tokens(&tok_buf, io_buf, work_buf);
|
||||
if ((tok_buf.meta.ri > tok_buf.meta.wi) ||
|
||||
(tok_buf.meta.wi > tok_buf.data.len) ||
|
||||
(io_buf->meta.ri > io_buf->meta.wi) ||
|
||||
(io_buf->meta.wi > io_buf->data.len)) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeCbor: internal error: bad buffer indexes";
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++];
|
||||
@@ -38843,7 +39432,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
if ((io_buf->meta.ri < cursor_index) ||
|
||||
((io_buf->meta.ri - cursor_index) < token_len)) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad token indexes";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad token indexes";
|
||||
goto done;
|
||||
}
|
||||
uint8_t* token_ptr = io_buf->data.ptr + cursor_index;
|
||||
@@ -38879,7 +39468,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
}
|
||||
}
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad extended token";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad extended token";
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -38894,10 +39483,20 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
goto done;
|
||||
}
|
||||
depth++;
|
||||
if (depth > WUFFS_CBOR__DECODER_DEPTH_MAX_INCL) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeCbor: internal error: bad depth";
|
||||
goto done;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
ret_error_message = callbacks.Pop(static_cast<uint32_t>(vbd));
|
||||
depth--;
|
||||
if (depth < 0) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeCbor: internal error: bad depth";
|
||||
goto done;
|
||||
}
|
||||
goto parsed_a_value;
|
||||
}
|
||||
|
||||
@@ -39034,7 +39633,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
|
||||
fail:
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: unexpected token";
|
||||
"wuffs_aux::DecodeCbor: internal error: unexpected token";
|
||||
goto done;
|
||||
|
||||
parsed_a_value:
|
||||
@@ -39501,60 +40100,65 @@ DecodeJsonCallbacks::Done(DecodeJsonResult& result,
|
||||
sync_io::Input& input,
|
||||
IOBuffer& buffer) {}
|
||||
|
||||
const char DecodeJson_BadJsonPointer[] =
|
||||
const char DecodeJson_BadJsonPointer[] = //
|
||||
"wuffs_aux::DecodeJson: bad JSON Pointer";
|
||||
const char DecodeJson_NoMatch[] = "wuffs_aux::DecodeJson: no match";
|
||||
const char DecodeJson_NoMatch[] = //
|
||||
"wuffs_aux::DecodeJson: no match";
|
||||
|
||||
// --------
|
||||
|
||||
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
|
||||
while (tok_buf.meta.ri >= tok_buf.meta.wi) { \
|
||||
if (tok_status.repr == nullptr) { \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_write) { \
|
||||
tok_buf.compact(); \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_read) { \
|
||||
if (!io_error_message.empty()) { \
|
||||
ret_error_message = std::move(io_error_message); \
|
||||
goto done; \
|
||||
} else if (cursor_index != io_buf->meta.ri) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad cursor_index"; \
|
||||
goto done; \
|
||||
} else if (io_buf->meta.closed) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
|
||||
goto done; \
|
||||
} \
|
||||
io_buf->compact(); \
|
||||
if (io_buf->meta.wi >= io_buf->data.len) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
|
||||
goto done; \
|
||||
} \
|
||||
cursor_index = io_buf->meta.ri; \
|
||||
io_error_message = input.CopyIn(io_buf); \
|
||||
} else { \
|
||||
ret_error_message = tok_status.message(); \
|
||||
goto done; \
|
||||
} \
|
||||
if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN"; \
|
||||
goto done; \
|
||||
} \
|
||||
wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8(); \
|
||||
tok_status = dec->decode_tokens(&tok_buf, io_buf, work_buf); \
|
||||
} \
|
||||
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \
|
||||
uint64_t token_len = token.length(); \
|
||||
if ((io_buf->meta.ri < cursor_index) || \
|
||||
((io_buf->meta.ri - cursor_index) < token_len)) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad token indexes"; \
|
||||
goto done; \
|
||||
} \
|
||||
uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \
|
||||
(void)(token_ptr); \
|
||||
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
|
||||
while (tok_buf.meta.ri >= tok_buf.meta.wi) { \
|
||||
if (tok_status.repr == nullptr) { \
|
||||
goto done; \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_write) { \
|
||||
tok_buf.compact(); \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_read) { \
|
||||
if (!io_error_message.empty()) { \
|
||||
ret_error_message = std::move(io_error_message); \
|
||||
goto done; \
|
||||
} else if (cursor_index != io_buf->meta.ri) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad cursor_index"; \
|
||||
goto done; \
|
||||
} else if (io_buf->meta.closed) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
|
||||
goto done; \
|
||||
} \
|
||||
io_buf->compact(); \
|
||||
if (io_buf->meta.wi >= io_buf->data.len) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
|
||||
goto done; \
|
||||
} \
|
||||
cursor_index = io_buf->meta.ri; \
|
||||
io_error_message = input.CopyIn(io_buf); \
|
||||
} else { \
|
||||
ret_error_message = tok_status.message(); \
|
||||
goto done; \
|
||||
} \
|
||||
tok_status = \
|
||||
dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8()); \
|
||||
if ((tok_buf.meta.ri > tok_buf.meta.wi) || \
|
||||
(tok_buf.meta.wi > tok_buf.data.len) || \
|
||||
(io_buf->meta.ri > io_buf->meta.wi) || \
|
||||
(io_buf->meta.wi > io_buf->data.len)) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad buffer indexes"; \
|
||||
goto done; \
|
||||
} \
|
||||
} \
|
||||
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \
|
||||
uint64_t token_len = token.length(); \
|
||||
if ((io_buf->meta.ri < cursor_index) || \
|
||||
((io_buf->meta.ri - cursor_index) < token_len)) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad token indexes"; \
|
||||
goto done; \
|
||||
} \
|
||||
uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \
|
||||
(void)(token_ptr); \
|
||||
cursor_index += static_cast<size_t>(token_len)
|
||||
|
||||
// --------
|
||||
@@ -39562,7 +40166,8 @@ const char DecodeJson_NoMatch[] = "wuffs_aux::DecodeJson: no match";
|
||||
namespace {
|
||||
|
||||
// DecodeJson_SplitJsonPointer returns ("bar", 8) for ("/foo/bar/b~1z/qux", 5,
|
||||
// etc). It returns a 0 size_t when s has invalid JSON Pointer syntax.
|
||||
// etc). It returns a 0 size_t when s has invalid JSON Pointer syntax or i is
|
||||
// out of bounds.
|
||||
//
|
||||
// The string returned is unescaped. If calling it again, this time with i=8,
|
||||
// the "b~1z" substring would be returned as "b/z".
|
||||
@@ -39571,6 +40176,9 @@ DecodeJson_SplitJsonPointer(std::string& s,
|
||||
size_t i,
|
||||
bool allow_tilde_n_tilde_r_tilde_t) {
|
||||
std::string fragment;
|
||||
if (i > s.size()) {
|
||||
return std::make_pair(std::string(), 0);
|
||||
}
|
||||
while (i < s.size()) {
|
||||
char c = s[i];
|
||||
if (c == '/') {
|
||||
@@ -39777,8 +40385,8 @@ check_that_a_value_follows:
|
||||
continue;
|
||||
}
|
||||
|
||||
// Undo the last part of WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN, so that
|
||||
// we're only peeking at the next token.
|
||||
// Undo the last part of WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN, so
|
||||
// that we're only peeking at the next token.
|
||||
tok_buf.meta.ri--;
|
||||
cursor_index -= static_cast<size_t>(token_len);
|
||||
|
||||
@@ -39825,6 +40433,10 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
if (!dec) {
|
||||
ret_error_message = "wuffs_aux::DecodeJson: out of memory";
|
||||
goto done;
|
||||
} else if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN";
|
||||
goto done;
|
||||
}
|
||||
bool allow_tilde_n_tilde_r_tilde_t = false;
|
||||
for (size_t i = 0; i < quirks.len; i++) {
|
||||
@@ -39840,10 +40452,11 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
wuffs_base__token_buffer tok_buf =
|
||||
wuffs_base__slice_token__writer(wuffs_base__make_slice_token(
|
||||
&tok_array[0], (sizeof(tok_array) / sizeof(tok_array[0]))));
|
||||
wuffs_base__status tok_status = wuffs_base__make_status(nullptr);
|
||||
wuffs_base__status tok_status =
|
||||
dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8());
|
||||
|
||||
// Prepare other state.
|
||||
uint32_t depth = 0;
|
||||
int32_t depth = 0;
|
||||
std::string str;
|
||||
|
||||
// Walk the (optional) JSON Pointer.
|
||||
@@ -39854,7 +40467,7 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
}
|
||||
std::pair<std::string, size_t> split = DecodeJson_SplitJsonPointer(
|
||||
json_pointer, i + 1, allow_tilde_n_tilde_r_tilde_t);
|
||||
i = std::move(split.second);
|
||||
i = split.second;
|
||||
if (i == 0) {
|
||||
ret_error_message = DecodeJson_BadJsonPointer;
|
||||
goto done;
|
||||
@@ -39886,10 +40499,20 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
goto done;
|
||||
}
|
||||
depth++;
|
||||
if (depth > WUFFS_JSON__DECODER_DEPTH_MAX_INCL) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeJson: internal error: bad depth";
|
||||
goto done;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
ret_error_message = callbacks.Pop(static_cast<uint32_t>(vbd));
|
||||
depth--;
|
||||
if (depth < 0) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeJson: internal error: bad depth";
|
||||
goto done;
|
||||
}
|
||||
goto parsed_a_value;
|
||||
}
|
||||
|
||||
@@ -39989,7 +40612,22 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
goto done;
|
||||
|
||||
parsed_a_value:
|
||||
if (!ret_error_message.empty() || (depth == 0)) {
|
||||
// If an error was encountered, we are done. Otherwise, (depth == 0)
|
||||
// after parsing a value is equivalent to having decoded the entire JSON
|
||||
// value (for an empty json_pointer query) or having decoded the
|
||||
// pointed-to JSON value (for a non-empty json_pointer query). In the
|
||||
// latter case, we are also done.
|
||||
//
|
||||
// However, if quirks like WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER or
|
||||
// WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF are passed, decoding
|
||||
// the entire JSON value should also consume any trailing filler, in case
|
||||
// the DecodeJson caller wants to subsequently check that the input is
|
||||
// completely exhausted (and otherwise raise "valid JSON followed by
|
||||
// further (unexpected) data"). We aren't done yet. Instead, keep the
|
||||
// loop running until WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN's
|
||||
// decode_tokens returns an ok status.
|
||||
if (!ret_error_message.empty() ||
|
||||
((depth == 0) && !json_pointer.empty())) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
@@ -40016,6 +40654,8 @@ done:
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif // WUFFS_INCLUDE_GUARD
|
||||
+815
-175
@@ -10,8 +10,12 @@
|
||||
|
||||
// Wuffs' C code is generated automatically, not hand-written. These warnings'
|
||||
// costs outweigh the benefits.
|
||||
//
|
||||
// The "elif defined(__clang__)" isn't redundant. While vanilla clang defines
|
||||
// __GNUC__, clang-cl (which mimics MSVC's cl.exe) does not.
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
#pragma GCC diagnostic ignored "-Wunreachable-code"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
@@ -19,6 +23,16 @@
|
||||
#if defined(__cplusplus)
|
||||
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||
#endif
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wimplicit-fallthrough"
|
||||
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
||||
#pragma clang diagnostic ignored "-Wunreachable-code"
|
||||
#pragma clang diagnostic ignored "-Wunused-function"
|
||||
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||
#if defined(__cplusplus)
|
||||
#pragma clang diagnostic ignored "-Wold-style-cast"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Copyright 2017 The Wuffs Authors.
|
||||
@@ -70,15 +84,15 @@ extern "C" {
|
||||
// each major.minor branch, the commit count should increase monotonically.
|
||||
//
|
||||
// WUFFS_VERSION was overridden by "wuffs gen -version" based on revision
|
||||
// c86ac5baef05b2e373b818eca0cf2c9c38785197 committed on 2021-04-03.
|
||||
// a86fd7fa795943a91dd80f2c92c8194286682ad8 committed on 2021-08-15.
|
||||
#define WUFFS_VERSION 0x000030000
|
||||
#define WUFFS_VERSION_MAJOR 0
|
||||
#define WUFFS_VERSION_MINOR 3
|
||||
#define WUFFS_VERSION_PATCH 0
|
||||
#define WUFFS_VERSION_PRE_RELEASE_LABEL "beta.1"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3024
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20210403
|
||||
#define WUFFS_VERSION_STRING "0.3.0-beta.1+3024.20210403"
|
||||
#define WUFFS_VERSION_PRE_RELEASE_LABEL "beta.9"
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_COUNT 3084
|
||||
#define WUFFS_VERSION_BUILD_METADATA_COMMIT_DATE 20210815
|
||||
#define WUFFS_VERSION_STRING "0.3.0-beta.9+3084.20210815"
|
||||
|
||||
// ---------------- Configuration
|
||||
|
||||
@@ -100,8 +114,8 @@ extern "C" {
|
||||
|
||||
// To simplify Wuffs code, "cpu_arch >= arm_xxx" requires xxx but also
|
||||
// unaligned little-endian load/stores.
|
||||
#if defined(__ARM_FEATURE_UNALIGNED) && defined(__BYTE_ORDER__) && \
|
||||
(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||
#if defined(__ARM_FEATURE_UNALIGNED) && !defined(__native_client__) && \
|
||||
defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||
// Not all gcc versions define __ARM_ACLE, even if they support crc32
|
||||
// intrinsics. Look for __ARM_FEATURE_CRC32 instead.
|
||||
#if defined(__ARM_FEATURE_CRC32)
|
||||
@@ -116,11 +130,13 @@ extern "C" {
|
||||
|
||||
// Similarly, "cpu_arch >= x86_sse42" requires SSE4.2 but also PCLMUL and
|
||||
// POPCNT. This is checked at runtime via cpuid, not at compile time.
|
||||
#if defined(__x86_64__)
|
||||
//
|
||||
// Likewise, "cpu_arch >= x86_avx2" also requires PCLMUL, POPCNT and SSE4.2.
|
||||
#if defined(__x86_64__) && !defined(__native_client__)
|
||||
#include <cpuid.h>
|
||||
#include <x86intrin.h>
|
||||
#define WUFFS_BASE__CPU_ARCH__X86_64
|
||||
#endif // defined(__x86_64__)
|
||||
#endif // defined(__x86_64__) && !defined(__native_client__)
|
||||
|
||||
#elif defined(_MSC_VER) // (#if-chain ref AVOID_CPU_ARCH_1)
|
||||
|
||||
@@ -188,6 +204,82 @@ wuffs_base__cpu_arch__have_arm_neon() {
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_NEON)
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__cpu_arch__have_x86_avx2() {
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
// GCC defines these macros but MSVC does not.
|
||||
// - bit_AVX2 = (1 << 5)
|
||||
const unsigned int avx2_ebx7 = 0x00000020;
|
||||
// GCC defines these macros but MSVC does not.
|
||||
// - bit_PCLMUL = (1 << 1)
|
||||
// - bit_POPCNT = (1 << 23)
|
||||
// - bit_SSE4_2 = (1 << 20)
|
||||
const unsigned int avx2_ecx1 = 0x00900002;
|
||||
|
||||
// clang defines __GNUC__ and clang-cl defines _MSC_VER (but not __GNUC__).
|
||||
#if defined(__GNUC__)
|
||||
unsigned int eax7 = 0;
|
||||
unsigned int ebx7 = 0;
|
||||
unsigned int ecx7 = 0;
|
||||
unsigned int edx7 = 0;
|
||||
if (__get_cpuid_count(7, 0, &eax7, &ebx7, &ecx7, &edx7) &&
|
||||
((ebx7 & avx2_ebx7) == avx2_ebx7)) {
|
||||
unsigned int eax1 = 0;
|
||||
unsigned int ebx1 = 0;
|
||||
unsigned int ecx1 = 0;
|
||||
unsigned int edx1 = 0;
|
||||
if (__get_cpuid(1, &eax1, &ebx1, &ecx1, &edx1) &&
|
||||
((ecx1 & avx2_ecx1) == avx2_ecx1)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#elif defined(_MSC_VER) // defined(__GNUC__)
|
||||
int x7[4];
|
||||
__cpuidex(x7, 7, 0);
|
||||
if ((((unsigned int)(x7[1])) & avx2_ebx7) == avx2_ebx7) {
|
||||
int x1[4];
|
||||
__cpuid(x1, 1);
|
||||
if ((((unsigned int)(x1[2])) & avx2_ecx1) == avx2_ecx1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error "WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#endif // defined(__GNUC__); defined(_MSC_VER)
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__cpu_arch__have_x86_bmi2() {
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
// GCC defines these macros but MSVC does not.
|
||||
// - bit_BMI2 = (1 << 8)
|
||||
const unsigned int bmi2_ebx7 = 0x00000100;
|
||||
|
||||
// clang defines __GNUC__ and clang-cl defines _MSC_VER (but not __GNUC__).
|
||||
#if defined(__GNUC__)
|
||||
unsigned int eax7 = 0;
|
||||
unsigned int ebx7 = 0;
|
||||
unsigned int ecx7 = 0;
|
||||
unsigned int edx7 = 0;
|
||||
if (__get_cpuid_count(7, 0, &eax7, &ebx7, &ecx7, &edx7) &&
|
||||
((ebx7 & bmi2_ebx7) == bmi2_ebx7)) {
|
||||
return true;
|
||||
}
|
||||
#elif defined(_MSC_VER) // defined(__GNUC__)
|
||||
int x7[4];
|
||||
__cpuidex(x7, 7, 0);
|
||||
if ((((unsigned int)(x7[1])) & bmi2_ebx7) == bmi2_ebx7) {
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
#error "WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#endif // defined(__GNUC__); defined(_MSC_VER)
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool //
|
||||
wuffs_base__cpu_arch__have_x86_sse42() {
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
@@ -203,13 +295,16 @@ wuffs_base__cpu_arch__have_x86_sse42() {
|
||||
unsigned int ebx1 = 0;
|
||||
unsigned int ecx1 = 0;
|
||||
unsigned int edx1 = 0;
|
||||
if (__get_cpuid(1, &eax1, &ebx1, &ecx1, &edx1)) {
|
||||
return (ecx1 & sse42_ecx1) == sse42_ecx1;
|
||||
if (__get_cpuid(1, &eax1, &ebx1, &ecx1, &edx1) &&
|
||||
((ecx1 & sse42_ecx1) == sse42_ecx1)) {
|
||||
return true;
|
||||
}
|
||||
#elif defined(_MSC_VER) // defined(__GNUC__)
|
||||
int x[4];
|
||||
__cpuid(x, 1);
|
||||
return (((unsigned int)(x[2])) & sse42_ecx1) == sse42_ecx1;
|
||||
int x1[4];
|
||||
__cpuid(x1, 1);
|
||||
if ((((unsigned int)(x1[2])) & sse42_ecx1) == sse42_ecx1) {
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
#error "WUFFS_BASE__CPU_ARCH__ETC combined with an unsupported compiler"
|
||||
#endif // defined(__GNUC__); defined(_MSC_VER)
|
||||
@@ -712,6 +807,56 @@ wuffs_base__u64__max(uint64_t x, uint64_t y) {
|
||||
|
||||
// --------
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__u8__rotate_left(uint8_t x, uint32_t n) {
|
||||
n &= 7;
|
||||
return ((uint8_t)(x << n)) | ((uint8_t)(x >> (8 - n)));
|
||||
}
|
||||
|
||||
static inline uint8_t //
|
||||
wuffs_base__u8__rotate_right(uint8_t x, uint32_t n) {
|
||||
n &= 7;
|
||||
return ((uint8_t)(x >> n)) | ((uint8_t)(x << (8 - n)));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__u16__rotate_left(uint16_t x, uint32_t n) {
|
||||
n &= 15;
|
||||
return ((uint16_t)(x << n)) | ((uint16_t)(x >> (16 - n)));
|
||||
}
|
||||
|
||||
static inline uint16_t //
|
||||
wuffs_base__u16__rotate_right(uint16_t x, uint32_t n) {
|
||||
n &= 15;
|
||||
return ((uint16_t)(x >> n)) | ((uint16_t)(x << (16 - n)));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__rotate_left(uint32_t x, uint32_t n) {
|
||||
n &= 31;
|
||||
return ((uint32_t)(x << n)) | ((uint32_t)(x >> (32 - n)));
|
||||
}
|
||||
|
||||
static inline uint32_t //
|
||||
wuffs_base__u32__rotate_right(uint32_t x, uint32_t n) {
|
||||
n &= 31;
|
||||
return ((uint32_t)(x >> n)) | ((uint32_t)(x << (32 - n)));
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__u64__rotate_left(uint64_t x, uint32_t n) {
|
||||
n &= 63;
|
||||
return ((uint64_t)(x << n)) | ((uint64_t)(x >> (64 - n)));
|
||||
}
|
||||
|
||||
static inline uint64_t //
|
||||
wuffs_base__u64__rotate_right(uint64_t x, uint32_t n) {
|
||||
n &= 63;
|
||||
return ((uint64_t)(x >> n)) | ((uint64_t)(x << (64 - n)));
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// Saturating arithmetic (sat_add, sat_sub) branchless bit-twiddling algorithms
|
||||
// are per https://locklessinc.com/articles/sat_arithmetic/
|
||||
//
|
||||
@@ -6959,6 +7104,7 @@ struct wuffs_deflate__decoder__struct {
|
||||
|
||||
uint32_t f_bits;
|
||||
uint32_t f_n_bits;
|
||||
uint64_t f_transformed_history_count;
|
||||
uint32_t f_history_index;
|
||||
uint32_t f_n_huffs_bits[2];
|
||||
bool f_end_of_block;
|
||||
@@ -6967,6 +7113,10 @@ struct wuffs_deflate__decoder__struct {
|
||||
uint32_t p_decode_blocks[1];
|
||||
uint32_t p_decode_uncompressed[1];
|
||||
uint32_t p_init_dynamic_huffman[1];
|
||||
wuffs_base__status (*choosy_decode_huffman_fast64)(
|
||||
wuffs_deflate__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
uint32_t p_decode_huffman_slow[1];
|
||||
} private_impl;
|
||||
|
||||
@@ -9963,26 +10113,16 @@ extern "C" {
|
||||
// Its (non-zero) value is arbitrary, based on md5sum("disabled").
|
||||
#define WUFFS_BASE__DISABLED ((uint32_t)0x075AE3D2)
|
||||
|
||||
// Denote intentional fallthroughs for -Wimplicit-fallthrough.
|
||||
//
|
||||
// The order matters here. Clang also defines "__GNUC__".
|
||||
#if defined(__clang__) && defined(__cplusplus) && (__cplusplus >= 201103L)
|
||||
#define WUFFS_BASE__FALLTHROUGH [[clang::fallthrough]]
|
||||
#elif !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 7)
|
||||
#define WUFFS_BASE__FALLTHROUGH __attribute__((fallthrough))
|
||||
#else
|
||||
#define WUFFS_BASE__FALLTHROUGH
|
||||
#endif
|
||||
|
||||
// Use switch cases for coroutine suspension points, similar to the technique
|
||||
// in https://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
|
||||
//
|
||||
// The implicit fallthrough is intentional.
|
||||
//
|
||||
// We use trivial macros instead of an explicit assignment and case statement
|
||||
// so that clang-format doesn't get confused by the unusual "case"s.
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0 case 0:;
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT(n) \
|
||||
coro_susp_point = n; \
|
||||
WUFFS_BASE__FALLTHROUGH; \
|
||||
case n:;
|
||||
|
||||
#define WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(n) \
|
||||
@@ -10325,11 +10465,12 @@ wuffs_base__io_reader__set(wuffs_base__io_buffer* b,
|
||||
const uint8_t** ptr_io0_r,
|
||||
const uint8_t** ptr_io1_r,
|
||||
const uint8_t** ptr_io2_r,
|
||||
wuffs_base__slice_u8 data) {
|
||||
wuffs_base__slice_u8 data,
|
||||
uint64_t history_position) {
|
||||
b->data = data;
|
||||
b->meta.wi = data.len;
|
||||
b->meta.ri = 0;
|
||||
b->meta.pos = 0;
|
||||
b->meta.pos = history_position;
|
||||
b->meta.closed = false;
|
||||
|
||||
*ptr_iop_r = data.ptr;
|
||||
@@ -10436,6 +10577,46 @@ wuffs_base__io_writer__limited_copy_u32_from_history_fast(uint8_t** ptr_iop_w,
|
||||
return length;
|
||||
}
|
||||
|
||||
// wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast
|
||||
// copies the previous byte (the one immediately before *ptr_iop_w), copying 8
|
||||
// byte chunks at a time. Each chunk contains 8 repetitions of the same byte.
|
||||
//
|
||||
// In terms of number of bytes copied, length is rounded up to a multiple of 8.
|
||||
// As a special case, a zero length rounds up to 8 (even though 0 is already a
|
||||
// multiple of 8), since there is always at least one 8 byte chunk copied.
|
||||
//
|
||||
// In terms of advancing *ptr_iop_w, length is not rounded up.
|
||||
//
|
||||
// The caller needs to prove that:
|
||||
// - (length + 8) <= (io2_w - *ptr_iop_w)
|
||||
// - distance == 1
|
||||
// - distance <= (*ptr_iop_w - io1_w)
|
||||
static inline uint32_t //
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
uint8_t** ptr_iop_w,
|
||||
uint8_t* io1_w,
|
||||
uint8_t* io2_w,
|
||||
uint32_t length,
|
||||
uint32_t distance) {
|
||||
uint8_t* p = *ptr_iop_w;
|
||||
uint64_t x = p[-1];
|
||||
x |= x << 8;
|
||||
x |= x << 16;
|
||||
x |= x << 32;
|
||||
uint32_t n = length;
|
||||
while (1) {
|
||||
wuffs_base__poke_u64le__no_bounds_check(p, x);
|
||||
if (n <= 8) {
|
||||
p += n;
|
||||
break;
|
||||
}
|
||||
p += 8;
|
||||
n -= 8;
|
||||
}
|
||||
*ptr_iop_w = p;
|
||||
return length;
|
||||
}
|
||||
|
||||
// wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast is
|
||||
// like the wuffs_base__io_writer__limited_copy_u32_from_history_fast function
|
||||
// above, but copies 8 byte chunks at a time.
|
||||
@@ -10523,11 +10704,12 @@ wuffs_base__io_writer__set(wuffs_base__io_buffer* b,
|
||||
uint8_t** ptr_io0_w,
|
||||
uint8_t** ptr_io1_w,
|
||||
uint8_t** ptr_io2_w,
|
||||
wuffs_base__slice_u8 data) {
|
||||
wuffs_base__slice_u8 data,
|
||||
uint64_t history_position) {
|
||||
b->data = data;
|
||||
b->meta.wi = 0;
|
||||
b->meta.ri = 0;
|
||||
b->meta.pos = 0;
|
||||
b->meta.pos = history_position;
|
||||
b->meta.closed = false;
|
||||
|
||||
*ptr_iop_w = data.ptr;
|
||||
@@ -14092,13 +14274,18 @@ wuffs_base__parse_number_i64(wuffs_base__slice_u8 s, uint32_t options) {
|
||||
ret.value = 0;
|
||||
return ret;
|
||||
} else if (negative) {
|
||||
if (r.value > 0x8000000000000000) {
|
||||
goto fail_out_of_bounds;
|
||||
if (r.value < 0x8000000000000000) {
|
||||
wuffs_base__result_i64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = -(int64_t)(r.value);
|
||||
return ret;
|
||||
} else if (r.value == 0x8000000000000000) {
|
||||
wuffs_base__result_i64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = INT64_MIN;
|
||||
return ret;
|
||||
}
|
||||
wuffs_base__result_i64 ret;
|
||||
ret.status.repr = NULL;
|
||||
ret.value = -(int64_t)(r.value);
|
||||
return ret;
|
||||
goto fail_out_of_bounds;
|
||||
} else if (r.value > 0x7FFFFFFFFFFFFFFF) {
|
||||
goto fail_out_of_bounds;
|
||||
} else {
|
||||
@@ -19021,6 +19208,34 @@ wuffs_base__pixel_swizzler__y__y_16be(uint8_t* dst_ptr,
|
||||
return len;
|
||||
}
|
||||
|
||||
static uint64_t //
|
||||
wuffs_base__pixel_swizzler__y_16le__y_16be(uint8_t* dst_ptr,
|
||||
size_t dst_len,
|
||||
uint8_t* dst_palette_ptr,
|
||||
size_t dst_palette_len,
|
||||
const uint8_t* src_ptr,
|
||||
size_t src_len) {
|
||||
size_t dst_len2 = dst_len / 2;
|
||||
size_t src_len2 = src_len / 2;
|
||||
size_t len = (dst_len2 < src_len2) ? dst_len2 : src_len2;
|
||||
uint8_t* d = dst_ptr;
|
||||
const uint8_t* s = src_ptr;
|
||||
size_t n = len;
|
||||
|
||||
while (n >= 1) {
|
||||
uint8_t s0 = s[0];
|
||||
uint8_t s1 = s[1];
|
||||
d[0] = s1;
|
||||
d[1] = s0;
|
||||
|
||||
s += 1 * 2;
|
||||
d += 1 * 2;
|
||||
n -= 1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
static uint64_t //
|
||||
@@ -19107,13 +19322,18 @@ wuffs_base__pixel_swizzler__prepare__y_16be(wuffs_base__pixel_swizzler* p,
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y:
|
||||
return wuffs_base__pixel_swizzler__y__y_16be;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16LE:
|
||||
return wuffs_base__pixel_swizzler__y_16le__y_16be;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__Y_16BE:
|
||||
return wuffs_base__pixel_swizzler__copy_2_2;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR_565:
|
||||
return wuffs_base__pixel_swizzler__bgr_565__y_16be;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGR:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__RGB:
|
||||
return wuffs_base__pixel_swizzler__xxx__y_16be;
|
||||
break;
|
||||
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL:
|
||||
case WUFFS_BASE__PIXEL_FORMAT__BGRA_PREMUL:
|
||||
@@ -20755,8 +20975,8 @@ wuffs_adler32__hasher__up_x86_sse42(
|
||||
__m128i v_ones = {0};
|
||||
__m128i v_weights__left = {0};
|
||||
__m128i v_weights_right = {0};
|
||||
__m128i v_p__left = {0};
|
||||
__m128i v_p_right = {0};
|
||||
__m128i v_q__left = {0};
|
||||
__m128i v_q_right = {0};
|
||||
__m128i v_v1 = {0};
|
||||
__m128i v_v2 = {0};
|
||||
__m128i v_v2j = {0};
|
||||
@@ -20787,13 +21007,13 @@ wuffs_adler32__hasher__up_x86_sse42(
|
||||
v_p.len = 32;
|
||||
uint8_t* i_end0_p = v_p.ptr + (((i_slice_p.len - (size_t)(v_p.ptr - i_slice_p.ptr)) / 32) * 32);
|
||||
while (v_p.ptr < i_end0_p) {
|
||||
v_p__left = _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr));
|
||||
v_p_right = _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr + 16));
|
||||
v_q__left = _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr));
|
||||
v_q_right = _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr + 16));
|
||||
v_v2j = _mm_add_epi32(v_v2j, v_v1);
|
||||
v_v1 = _mm_add_epi32(v_v1, _mm_sad_epu8(v_p__left, v_zeroes));
|
||||
v_v1 = _mm_add_epi32(v_v1, _mm_sad_epu8(v_p_right, v_zeroes));
|
||||
v_v2k = _mm_add_epi32(v_v2k, _mm_madd_epi16(v_ones, _mm_maddubs_epi16(v_p__left, v_weights__left)));
|
||||
v_v2k = _mm_add_epi32(v_v2k, _mm_madd_epi16(v_ones, _mm_maddubs_epi16(v_p_right, v_weights_right)));
|
||||
v_v1 = _mm_add_epi32(v_v1, _mm_sad_epu8(v_q__left, v_zeroes));
|
||||
v_v1 = _mm_add_epi32(v_v1, _mm_sad_epu8(v_q_right, v_zeroes));
|
||||
v_v2k = _mm_add_epi32(v_v2k, _mm_madd_epi16(v_ones, _mm_maddubs_epi16(v_q__left, v_weights__left)));
|
||||
v_v2k = _mm_add_epi32(v_v2k, _mm_madd_epi16(v_ones, _mm_maddubs_epi16(v_q_right, v_weights_right)));
|
||||
v_p.ptr += 32;
|
||||
}
|
||||
v_p.len = 0;
|
||||
@@ -21158,7 +21378,7 @@ wuffs_bmp__decoder__decode_image_config(
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_padding -= 14;
|
||||
self->private_impl.f_io_redirect_pos = wuffs_base__u64__sat_add(((uint64_t)(self->private_impl.f_padding)), wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src))));
|
||||
self->private_impl.f_io_redirect_pos = wuffs_base__u64__sat_add(((uint64_t)(self->private_impl.f_padding)), wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))));
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(6);
|
||||
uint32_t t_2;
|
||||
@@ -21907,7 +22127,7 @@ wuffs_bmp__decoder__decode_image_config(
|
||||
} else if (self->private_impl.f_bits_per_pixel == 32) {
|
||||
self->private_impl.f_pad_per_row = 0;
|
||||
}
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
if (a_dst != NULL) {
|
||||
v_dst_pixfmt = 2164295816;
|
||||
if ((self->private_impl.f_channel_num_bits[0] > 8) ||
|
||||
@@ -21927,7 +22147,6 @@ wuffs_bmp__decoder__decode_image_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -22006,7 +22225,7 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
@@ -22036,7 +22255,6 @@ wuffs_bmp__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -22224,7 +22442,6 @@ wuffs_bmp__decoder__decode_frame(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -22338,7 +22555,6 @@ wuffs_bmp__decoder__swizzle_none(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -22601,7 +22817,6 @@ wuffs_bmp__decoder__swizzle_rle(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -22742,7 +22957,6 @@ wuffs_bmp__decoder__swizzle_bitfields(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -22911,7 +23125,6 @@ wuffs_bmp__decoder__swizzle_low_bit_depth(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -23997,7 +24210,6 @@ wuffs_cbor__decoder__decode_tokens(
|
||||
label__outer__break:;
|
||||
self->private_impl.f_end_of_data = true;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_tokens[0] = 0;
|
||||
goto exit;
|
||||
@@ -24615,6 +24827,13 @@ wuffs_crc32__ieee_hasher__up_arm_crc32(
|
||||
wuffs_base__slice_u8 a_x);
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_CRC32)
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_crc32__ieee_hasher__up_x86_avx2(
|
||||
wuffs_crc32__ieee_hasher* self,
|
||||
wuffs_base__slice_u8 a_x);
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_crc32__ieee_hasher__up_x86_sse42(
|
||||
@@ -24734,6 +24953,9 @@ wuffs_crc32__ieee_hasher__update_u32(
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__ARM_CRC32)
|
||||
wuffs_base__cpu_arch__have_arm_crc32() ? &wuffs_crc32__ieee_hasher__up_arm_crc32 :
|
||||
#endif
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
wuffs_base__cpu_arch__have_x86_avx2() ? &wuffs_crc32__ieee_hasher__up_x86_avx2 :
|
||||
#endif
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
wuffs_base__cpu_arch__have_x86_sse42() ? &wuffs_crc32__ieee_hasher__up_x86_sse42 :
|
||||
#endif
|
||||
@@ -24921,6 +25143,125 @@ wuffs_crc32__ieee_hasher__up_arm_crc32(
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__ARM_CRC32)
|
||||
// ‼ WUFFS MULTI-FILE SECTION -arm_crc32
|
||||
|
||||
// ‼ WUFFS MULTI-FILE SECTION +x86_avx2
|
||||
// -------- func crc32.ieee_hasher.up_x86_avx2
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("pclmul,popcnt,sse4.2,avx2")
|
||||
static wuffs_base__empty_struct
|
||||
wuffs_crc32__ieee_hasher__up_x86_avx2(
|
||||
wuffs_crc32__ieee_hasher* self,
|
||||
wuffs_base__slice_u8 a_x) {
|
||||
uint32_t v_s = 0;
|
||||
wuffs_base__slice_u8 v_p = {0};
|
||||
__m128i v_k = {0};
|
||||
__m128i v_x0 = {0};
|
||||
__m128i v_x1 = {0};
|
||||
__m128i v_x2 = {0};
|
||||
__m128i v_x3 = {0};
|
||||
__m128i v_y0 = {0};
|
||||
__m128i v_y1 = {0};
|
||||
__m128i v_y2 = {0};
|
||||
__m128i v_y3 = {0};
|
||||
uint64_t v_tail_index = 0;
|
||||
|
||||
v_s = (4294967295 ^ self->private_impl.f_state);
|
||||
while ((((uint64_t)(a_x.len)) > 0) && ((15 & ((uint32_t)(0xFFF & (uintptr_t)(a_x.ptr)))) != 0)) {
|
||||
v_s = (WUFFS_CRC32__IEEE_TABLE[0][(((uint8_t)((v_s & 255))) ^ a_x.ptr[0])] ^ (v_s >> 8));
|
||||
a_x = wuffs_base__slice_u8__subslice_i(a_x, 1);
|
||||
}
|
||||
if (((uint64_t)(a_x.len)) < 64) {
|
||||
{
|
||||
wuffs_base__slice_u8 i_slice_p = a_x;
|
||||
v_p.ptr = i_slice_p.ptr;
|
||||
v_p.len = 1;
|
||||
uint8_t* i_end0_p = i_slice_p.ptr + i_slice_p.len;
|
||||
while (v_p.ptr < i_end0_p) {
|
||||
v_s = (WUFFS_CRC32__IEEE_TABLE[0][(((uint8_t)((v_s & 255))) ^ v_p.ptr[0])] ^ (v_s >> 8));
|
||||
v_p.ptr += 1;
|
||||
}
|
||||
v_p.len = 0;
|
||||
}
|
||||
self->private_impl.f_state = (4294967295 ^ v_s);
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
v_x0 = _mm_lddqu_si128((const __m128i*)(const void*)(a_x.ptr + 0));
|
||||
v_x1 = _mm_lddqu_si128((const __m128i*)(const void*)(a_x.ptr + 16));
|
||||
v_x2 = _mm_lddqu_si128((const __m128i*)(const void*)(a_x.ptr + 32));
|
||||
v_x3 = _mm_lddqu_si128((const __m128i*)(const void*)(a_x.ptr + 48));
|
||||
v_x0 = _mm_xor_si128(v_x0, _mm_cvtsi32_si128((int32_t)(v_s)));
|
||||
v_k = _mm_lddqu_si128((const __m128i*)(const void*)(WUFFS_CRC32__IEEE_X86_SSE42_K1K2));
|
||||
{
|
||||
wuffs_base__slice_u8 i_slice_p = wuffs_base__slice_u8__subslice_i(a_x, 64);
|
||||
v_p.ptr = i_slice_p.ptr;
|
||||
v_p.len = 64;
|
||||
uint8_t* i_end0_p = v_p.ptr + (((i_slice_p.len - (size_t)(v_p.ptr - i_slice_p.ptr)) / 64) * 64);
|
||||
while (v_p.ptr < i_end0_p) {
|
||||
v_y0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(0));
|
||||
v_y1 = _mm_clmulepi64_si128(v_x1, v_k, (int32_t)(0));
|
||||
v_y2 = _mm_clmulepi64_si128(v_x2, v_k, (int32_t)(0));
|
||||
v_y3 = _mm_clmulepi64_si128(v_x3, v_k, (int32_t)(0));
|
||||
v_x0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(17));
|
||||
v_x1 = _mm_clmulepi64_si128(v_x1, v_k, (int32_t)(17));
|
||||
v_x2 = _mm_clmulepi64_si128(v_x2, v_k, (int32_t)(17));
|
||||
v_x3 = _mm_clmulepi64_si128(v_x3, v_k, (int32_t)(17));
|
||||
v_x0 = _mm_xor_si128(_mm_xor_si128(v_x0, v_y0), _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr + 0)));
|
||||
v_x1 = _mm_xor_si128(_mm_xor_si128(v_x1, v_y1), _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr + 16)));
|
||||
v_x2 = _mm_xor_si128(_mm_xor_si128(v_x2, v_y2), _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr + 32)));
|
||||
v_x3 = _mm_xor_si128(_mm_xor_si128(v_x3, v_y3), _mm_lddqu_si128((const __m128i*)(const void*)(v_p.ptr + 48)));
|
||||
v_p.ptr += 64;
|
||||
}
|
||||
v_p.len = 0;
|
||||
}
|
||||
v_k = _mm_lddqu_si128((const __m128i*)(const void*)(WUFFS_CRC32__IEEE_X86_SSE42_K3K4));
|
||||
v_y0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(0));
|
||||
v_x0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(17));
|
||||
v_x0 = _mm_xor_si128(v_x0, v_x1);
|
||||
v_x0 = _mm_xor_si128(v_x0, v_y0);
|
||||
v_y0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(0));
|
||||
v_x0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(17));
|
||||
v_x0 = _mm_xor_si128(v_x0, v_x2);
|
||||
v_x0 = _mm_xor_si128(v_x0, v_y0);
|
||||
v_y0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(0));
|
||||
v_x0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(17));
|
||||
v_x0 = _mm_xor_si128(v_x0, v_x3);
|
||||
v_x0 = _mm_xor_si128(v_x0, v_y0);
|
||||
v_x1 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(16));
|
||||
v_x2 = _mm_set_epi32((int32_t)(0), (int32_t)(4294967295), (int32_t)(0), (int32_t)(4294967295));
|
||||
v_x0 = _mm_srli_si128(v_x0, (int32_t)(8));
|
||||
v_x0 = _mm_xor_si128(v_x0, v_x1);
|
||||
v_k = _mm_lddqu_si128((const __m128i*)(const void*)(WUFFS_CRC32__IEEE_X86_SSE42_K5ZZ));
|
||||
v_x1 = _mm_srli_si128(v_x0, (int32_t)(4));
|
||||
v_x0 = _mm_and_si128(v_x0, v_x2);
|
||||
v_x0 = _mm_clmulepi64_si128(v_x0, v_k, (int32_t)(0));
|
||||
v_x0 = _mm_xor_si128(v_x0, v_x1);
|
||||
v_k = _mm_lddqu_si128((const __m128i*)(const void*)(WUFFS_CRC32__IEEE_X86_SSE42_PXMU));
|
||||
v_x1 = _mm_and_si128(v_x0, v_x2);
|
||||
v_x1 = _mm_clmulepi64_si128(v_x1, v_k, (int32_t)(16));
|
||||
v_x1 = _mm_and_si128(v_x1, v_x2);
|
||||
v_x1 = _mm_clmulepi64_si128(v_x1, v_k, (int32_t)(0));
|
||||
v_x0 = _mm_xor_si128(v_x0, v_x1);
|
||||
v_s = ((uint32_t)(_mm_extract_epi32(v_x0, (int32_t)(1))));
|
||||
v_tail_index = (((uint64_t)(a_x.len)) & 18446744073709551552u);
|
||||
if (v_tail_index < ((uint64_t)(a_x.len))) {
|
||||
{
|
||||
wuffs_base__slice_u8 i_slice_p = wuffs_base__slice_u8__subslice_i(a_x, v_tail_index);
|
||||
v_p.ptr = i_slice_p.ptr;
|
||||
v_p.len = 1;
|
||||
uint8_t* i_end0_p = i_slice_p.ptr + i_slice_p.len;
|
||||
while (v_p.ptr < i_end0_p) {
|
||||
v_s = (WUFFS_CRC32__IEEE_TABLE[0][(((uint8_t)((v_s & 255))) ^ v_p.ptr[0])] ^ (v_s >> 8));
|
||||
v_p.ptr += 1;
|
||||
}
|
||||
v_p.len = 0;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_state = (4294967295 ^ v_s);
|
||||
return wuffs_base__make_empty_struct();
|
||||
}
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
// ‼ WUFFS MULTI-FILE SECTION -x86_avx2
|
||||
|
||||
// ‼ WUFFS MULTI-FILE SECTION +x86_sse42
|
||||
// -------- func crc32.ieee_hasher.up_x86_sse42
|
||||
|
||||
@@ -25162,6 +25503,14 @@ wuffs_deflate__decoder__init_huff(
|
||||
uint32_t a_n_codes1,
|
||||
uint32_t a_base_symbol);
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
static wuffs_base__status
|
||||
wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
wuffs_deflate__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
wuffs_deflate__decoder* self,
|
||||
@@ -25174,6 +25523,12 @@ wuffs_deflate__decoder__decode_huffman_fast64(
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
wuffs_deflate__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src);
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_deflate__decoder__decode_huffman_slow(
|
||||
wuffs_deflate__decoder* self,
|
||||
@@ -25235,6 +25590,8 @@ wuffs_deflate__decoder__initialize(
|
||||
}
|
||||
}
|
||||
|
||||
self->private_impl.choosy_decode_huffman_fast64 = &wuffs_deflate__decoder__decode_huffman_fast64__choosy_default;
|
||||
|
||||
self->private_impl.magic = WUFFS_BASE__MAGIC;
|
||||
self->private_impl.vtable_for__wuffs_base__io_transformer.vtable_name =
|
||||
wuffs_base__io_transformer__vtable_name;
|
||||
@@ -25381,6 +25738,11 @@ wuffs_deflate__decoder__transform_io(
|
||||
switch (coro_susp_point) {
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_0;
|
||||
|
||||
self->private_impl.choosy_decode_huffman_fast64 = (
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
wuffs_base__cpu_arch__have_x86_bmi2() ? &wuffs_deflate__decoder__decode_huffman_bmi2 :
|
||||
#endif
|
||||
self->private_impl.choosy_decode_huffman_fast64);
|
||||
while (true) {
|
||||
v_mark = ((uint64_t)(iop_a_dst - io0_a_dst));
|
||||
{
|
||||
@@ -25403,12 +25765,12 @@ wuffs_deflate__decoder__transform_io(
|
||||
}
|
||||
goto ok;
|
||||
}
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_transformed_history_count, wuffs_base__io__count_since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst))));
|
||||
wuffs_deflate__decoder__add_history(self, wuffs_base__io__since(v_mark, ((uint64_t)(iop_a_dst - io0_a_dst)), io0_a_dst));
|
||||
status = v_status;
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -25566,7 +25928,6 @@ wuffs_deflate__decoder__decode_blocks(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_blocks[0] = 0;
|
||||
goto exit;
|
||||
@@ -25686,7 +26047,6 @@ wuffs_deflate__decoder__decode_uncompressed(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_uncompressed[0] = 0;
|
||||
goto exit;
|
||||
@@ -26269,6 +26629,223 @@ wuffs_deflate__decoder__init_huff(
|
||||
return wuffs_base__make_status(NULL);
|
||||
}
|
||||
|
||||
// ‼ WUFFS MULTI-FILE SECTION +x86_bmi2
|
||||
// -------- func deflate.decoder.decode_huffman_bmi2
|
||||
|
||||
#if defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
WUFFS_BASE__MAYBE_ATTRIBUTE_TARGET("bmi2")
|
||||
static wuffs_base__status
|
||||
wuffs_deflate__decoder__decode_huffman_bmi2(
|
||||
wuffs_deflate__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint64_t v_bits = 0;
|
||||
uint32_t v_n_bits = 0;
|
||||
uint32_t v_table_entry = 0;
|
||||
uint32_t v_table_entry_n_bits = 0;
|
||||
uint64_t v_lmask = 0;
|
||||
uint64_t v_dmask = 0;
|
||||
uint32_t v_redir_top = 0;
|
||||
uint32_t v_redir_mask = 0;
|
||||
uint32_t v_length = 0;
|
||||
uint32_t v_dist_minus_1 = 0;
|
||||
uint32_t v_hlen = 0;
|
||||
uint32_t v_hdist = 0;
|
||||
uint32_t v_hdist_adjustment = 0;
|
||||
|
||||
uint8_t* iop_a_dst = NULL;
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io1_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
uint8_t* io2_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_dst) {
|
||||
io0_a_dst = a_dst->data.ptr;
|
||||
io1_a_dst = io0_a_dst + a_dst->meta.wi;
|
||||
iop_a_dst = io1_a_dst;
|
||||
io2_a_dst = io0_a_dst + a_dst->data.len;
|
||||
if (a_dst->meta.closed) {
|
||||
io2_a_dst = iop_a_dst;
|
||||
}
|
||||
}
|
||||
const uint8_t* iop_a_src = NULL;
|
||||
const uint8_t* io0_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io1_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
const uint8_t* io2_a_src WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
if (a_src) {
|
||||
io0_a_src = a_src->data.ptr;
|
||||
io1_a_src = io0_a_src + a_src->meta.ri;
|
||||
iop_a_src = io1_a_src;
|
||||
io2_a_src = io0_a_src + a_src->meta.wi;
|
||||
}
|
||||
|
||||
if ((self->private_impl.f_n_bits >= 8) || ((self->private_impl.f_bits >> (self->private_impl.f_n_bits & 7)) != 0)) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_n_bits);
|
||||
goto exit;
|
||||
}
|
||||
v_bits = ((uint64_t)(self->private_impl.f_bits));
|
||||
v_n_bits = self->private_impl.f_n_bits;
|
||||
v_lmask = ((((uint64_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1);
|
||||
v_dmask = ((((uint64_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1);
|
||||
if (self->private_impl.f_transformed_history_count < (a_dst ? a_dst->meta.pos : 0)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist_adjustment = ((uint32_t)(((self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0)) & 4294967295)));
|
||||
label__loop__continue:;
|
||||
while ((((uint64_t)(io2_a_dst - iop_a_dst)) >= 266) && (((uint64_t)(io2_a_src - iop_a_src)) >= 8)) {
|
||||
v_bits |= ((uint64_t)(wuffs_base__peek_u64le__no_bounds_check(iop_a_src) << (v_n_bits & 63)));
|
||||
iop_a_src += ((63 - (v_n_bits & 63)) >> 3);
|
||||
v_n_bits |= 56;
|
||||
v_table_entry = self->private_data.f_huffs[0][(v_bits & v_lmask)];
|
||||
v_table_entry_n_bits = (v_table_entry & 15);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
if ((v_table_entry >> 31) != 0) {
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(((v_table_entry >> 8) & 255)))), iop_a_dst += 1);
|
||||
goto label__loop__continue;
|
||||
} else if ((v_table_entry >> 30) != 0) {
|
||||
} else if ((v_table_entry >> 29) != 0) {
|
||||
self->private_impl.f_end_of_block = true;
|
||||
goto label__loop__break;
|
||||
} else if ((v_table_entry >> 28) != 0) {
|
||||
v_redir_top = ((v_table_entry >> 8) & 65535);
|
||||
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
|
||||
v_table_entry = self->private_data.f_huffs[0][((v_redir_top + (((uint32_t)((v_bits & 4294967295))) & v_redir_mask)) & 1023)];
|
||||
v_table_entry_n_bits = (v_table_entry & 15);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
if ((v_table_entry >> 31) != 0) {
|
||||
(wuffs_base__poke_u8be__no_bounds_check(iop_a_dst, ((uint8_t)(((v_table_entry >> 8) & 255)))), iop_a_dst += 1);
|
||||
goto label__loop__continue;
|
||||
} else if ((v_table_entry >> 30) != 0) {
|
||||
} else if ((v_table_entry >> 29) != 0) {
|
||||
self->private_impl.f_end_of_block = true;
|
||||
goto label__loop__break;
|
||||
} else if ((v_table_entry >> 28) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state);
|
||||
goto exit;
|
||||
} else if ((v_table_entry >> 27) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_huffman_code);
|
||||
goto exit;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state);
|
||||
goto exit;
|
||||
}
|
||||
} else if ((v_table_entry >> 27) != 0) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_huffman_code);
|
||||
goto exit;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state);
|
||||
goto exit;
|
||||
}
|
||||
v_length = (((v_table_entry >> 8) & 255) + 3);
|
||||
v_table_entry_n_bits = ((v_table_entry >> 4) & 15);
|
||||
if (v_table_entry_n_bits > 0) {
|
||||
v_length = (((v_length + 253 + ((uint32_t)(((v_bits) & WUFFS_BASE__LOW_BITS_MASK__U64(v_table_entry_n_bits))))) & 255) + 3);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
}
|
||||
v_table_entry = self->private_data.f_huffs[1][(v_bits & v_dmask)];
|
||||
v_table_entry_n_bits = (v_table_entry & 15);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
if ((v_table_entry >> 28) == 1) {
|
||||
v_redir_top = ((v_table_entry >> 8) & 65535);
|
||||
v_redir_mask = ((((uint32_t)(1)) << ((v_table_entry >> 4) & 15)) - 1);
|
||||
v_table_entry = self->private_data.f_huffs[1][((v_redir_top + (((uint32_t)((v_bits & 4294967295))) & v_redir_mask)) & 1023)];
|
||||
v_table_entry_n_bits = (v_table_entry & 15);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
}
|
||||
if ((v_table_entry >> 24) != 64) {
|
||||
if ((v_table_entry >> 24) == 8) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_huffman_code);
|
||||
goto exit;
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_huffman_decoder_state);
|
||||
goto exit;
|
||||
}
|
||||
v_dist_minus_1 = ((v_table_entry >> 8) & 32767);
|
||||
v_table_entry_n_bits = ((v_table_entry >> 4) & 15);
|
||||
v_dist_minus_1 = ((v_dist_minus_1 + ((uint32_t)(((v_bits) & WUFFS_BASE__LOW_BITS_MASK__U64(v_table_entry_n_bits))))) & 32767);
|
||||
v_bits >>= v_table_entry_n_bits;
|
||||
v_n_bits -= v_table_entry_n_bits;
|
||||
while (true) {
|
||||
if (((uint64_t)((v_dist_minus_1 + 1))) > ((uint64_t)(iop_a_dst - io0_a_dst))) {
|
||||
v_hlen = 0;
|
||||
v_hdist = ((uint32_t)((((uint64_t)((v_dist_minus_1 + 1))) - ((uint64_t)(iop_a_dst - io0_a_dst)))));
|
||||
if (v_length > v_hdist) {
|
||||
v_length -= v_hdist;
|
||||
v_hlen = v_hdist;
|
||||
} else {
|
||||
v_hlen = v_length;
|
||||
v_length = 0;
|
||||
}
|
||||
v_hdist += v_hdist_adjustment;
|
||||
if (self->private_impl.f_history_index < v_hdist) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist = (self->private_impl.f_history_index - v_hdist);
|
||||
wuffs_base__io_writer__limited_copy_u32_from_slice(
|
||||
&iop_a_dst, io2_a_dst,v_hlen, wuffs_base__slice_u8__subslice_i(wuffs_base__make_slice_u8(self->private_data.f_history, 33025), (v_hdist & 32767)));
|
||||
if (v_length == 0) {
|
||||
goto label__loop__continue;
|
||||
}
|
||||
if ((((uint64_t)((v_dist_minus_1 + 1))) > ((uint64_t)(iop_a_dst - io0_a_dst))) || (((uint64_t)(v_length)) > ((uint64_t)(io2_a_dst - iop_a_dst))) || (((uint64_t)((v_length + 8))) > ((uint64_t)(io2_a_dst - iop_a_dst)))) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_distance);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
if ((v_dist_minus_1 + 1) >= 8) {
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
} else if ((v_dist_minus_1 + 1) == 1) {
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
} else {
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_fast(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
}
|
||||
goto label__0__break;
|
||||
}
|
||||
label__0__break:;
|
||||
}
|
||||
label__loop__break:;
|
||||
if (v_n_bits > 63) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_n_bits);
|
||||
goto exit;
|
||||
}
|
||||
while (v_n_bits >= 8) {
|
||||
v_n_bits -= 8;
|
||||
if (iop_a_src > io1_a_src) {
|
||||
iop_a_src--;
|
||||
} else {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_i_o);
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
self->private_impl.f_bits = ((uint32_t)((v_bits & ((((uint64_t)(1)) << v_n_bits) - 1))));
|
||||
self->private_impl.f_n_bits = v_n_bits;
|
||||
if ((self->private_impl.f_n_bits >= 8) || ((self->private_impl.f_bits >> self->private_impl.f_n_bits) != 0)) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__internal_error_inconsistent_n_bits);
|
||||
goto exit;
|
||||
}
|
||||
goto exit;
|
||||
exit:
|
||||
if (a_dst) {
|
||||
a_dst->meta.wi = ((size_t)(iop_a_dst - a_dst->data.ptr));
|
||||
}
|
||||
if (a_src) {
|
||||
a_src->meta.ri = ((size_t)(iop_a_src - a_src->data.ptr));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif // defined(WUFFS_BASE__CPU_ARCH__X86_64)
|
||||
// ‼ WUFFS MULTI-FILE SECTION -x86_bmi2
|
||||
|
||||
// -------- func deflate.decoder.decode_huffman_fast32
|
||||
|
||||
static wuffs_base__status
|
||||
@@ -26290,6 +26867,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
uint32_t v_dist_minus_1 = 0;
|
||||
uint32_t v_hlen = 0;
|
||||
uint32_t v_hdist = 0;
|
||||
uint32_t v_hdist_adjustment = 0;
|
||||
|
||||
uint8_t* iop_a_dst = NULL;
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
@@ -26323,6 +26901,11 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
v_n_bits = self->private_impl.f_n_bits;
|
||||
v_lmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1);
|
||||
v_dmask = ((((uint32_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1);
|
||||
if (self->private_impl.f_transformed_history_count < (a_dst ? a_dst->meta.pos : 0)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist_adjustment = ((uint32_t)(((self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0)) & 4294967295)));
|
||||
label__loop__continue:;
|
||||
while ((((uint64_t)(io2_a_dst - iop_a_dst)) >= 266) && (((uint64_t)(io2_a_src - iop_a_src)) >= 12)) {
|
||||
if (v_n_bits < 15) {
|
||||
@@ -26465,6 +27048,7 @@ wuffs_deflate__decoder__decode_huffman_fast32(
|
||||
v_hlen = v_length;
|
||||
v_length = 0;
|
||||
}
|
||||
v_hdist += v_hdist_adjustment;
|
||||
if (self->private_impl.f_history_index < v_hdist) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
@@ -26526,6 +27110,14 @@ wuffs_deflate__decoder__decode_huffman_fast64(
|
||||
wuffs_deflate__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
return (*self->private_impl.choosy_decode_huffman_fast64)(self, a_dst, a_src);
|
||||
}
|
||||
|
||||
static wuffs_base__status
|
||||
wuffs_deflate__decoder__decode_huffman_fast64__choosy_default(
|
||||
wuffs_deflate__decoder* self,
|
||||
wuffs_base__io_buffer* a_dst,
|
||||
wuffs_base__io_buffer* a_src) {
|
||||
wuffs_base__status status = wuffs_base__make_status(NULL);
|
||||
|
||||
uint64_t v_bits = 0;
|
||||
@@ -26540,6 +27132,7 @@ wuffs_deflate__decoder__decode_huffman_fast64(
|
||||
uint32_t v_dist_minus_1 = 0;
|
||||
uint32_t v_hlen = 0;
|
||||
uint32_t v_hdist = 0;
|
||||
uint32_t v_hdist_adjustment = 0;
|
||||
|
||||
uint8_t* iop_a_dst = NULL;
|
||||
uint8_t* io0_a_dst WUFFS_BASE__POTENTIALLY_UNUSED = NULL;
|
||||
@@ -26573,6 +27166,11 @@ wuffs_deflate__decoder__decode_huffman_fast64(
|
||||
v_n_bits = self->private_impl.f_n_bits;
|
||||
v_lmask = ((((uint64_t)(1)) << self->private_impl.f_n_huffs_bits[0]) - 1);
|
||||
v_dmask = ((((uint64_t)(1)) << self->private_impl.f_n_huffs_bits[1]) - 1);
|
||||
if (self->private_impl.f_transformed_history_count < (a_dst ? a_dst->meta.pos : 0)) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_i_o_position);
|
||||
goto exit;
|
||||
}
|
||||
v_hdist_adjustment = ((uint32_t)(((self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0)) & 4294967295)));
|
||||
label__loop__continue:;
|
||||
while ((((uint64_t)(io2_a_dst - iop_a_dst)) >= 266) && (((uint64_t)(io2_a_src - iop_a_src)) >= 8)) {
|
||||
v_bits |= ((uint64_t)(wuffs_base__peek_u64le__no_bounds_check(iop_a_src) << (v_n_bits & 63)));
|
||||
@@ -26663,6 +27261,7 @@ wuffs_deflate__decoder__decode_huffman_fast64(
|
||||
v_hlen = v_length;
|
||||
v_length = 0;
|
||||
}
|
||||
v_hdist += v_hdist_adjustment;
|
||||
if (self->private_impl.f_history_index < v_hdist) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
@@ -26681,6 +27280,9 @@ wuffs_deflate__decoder__decode_huffman_fast64(
|
||||
if ((v_dist_minus_1 + 1) >= 8) {
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_fast(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
} else if ((v_dist_minus_1 + 1) == 1) {
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_8_byte_chunks_distance_1_fast(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
} else {
|
||||
wuffs_base__io_writer__limited_copy_u32_from_history_fast(
|
||||
&iop_a_dst, io0_a_dst, io2_a_dst, v_length, (v_dist_minus_1 + 1));
|
||||
@@ -26994,6 +27596,7 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
v_hlen = v_length;
|
||||
v_length = 0;
|
||||
}
|
||||
v_hdist += ((uint32_t)((((uint64_t)(self->private_impl.f_transformed_history_count - (a_dst ? a_dst->meta.pos : 0))) & 4294967295)));
|
||||
if (self->private_impl.f_history_index < v_hdist) {
|
||||
status = wuffs_base__make_status(wuffs_deflate__error__bad_distance);
|
||||
goto exit;
|
||||
@@ -27056,7 +27659,6 @@ wuffs_deflate__decoder__decode_huffman_slow(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_huffman_slow[0] = 0;
|
||||
goto exit;
|
||||
@@ -27328,7 +27930,6 @@ wuffs_lzw__decoder__transform_io(
|
||||
}
|
||||
label__0__break:;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -27572,7 +28173,6 @@ wuffs_lzw__decoder__write_to(
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(1);
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_write_to[0] = 0;
|
||||
goto exit;
|
||||
@@ -28062,7 +28662,7 @@ wuffs_gif__decoder__tell_me_more(
|
||||
while (true) {
|
||||
label__0__continue:;
|
||||
while (true) {
|
||||
if (wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src))) != self->private_impl.f_metadata_io_position) {
|
||||
if (wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))) != self->private_impl.f_metadata_io_position) {
|
||||
if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
2,
|
||||
@@ -28101,13 +28701,13 @@ wuffs_gif__decoder__tell_me_more(
|
||||
} else {
|
||||
iop_a_src += 1;
|
||||
}
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add(wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src))), v_chunk_length);
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add(wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))), v_chunk_length);
|
||||
if (a_minfo != NULL) {
|
||||
wuffs_base__more_information__set(a_minfo,
|
||||
3,
|
||||
self->private_impl.f_metadata_fourcc,
|
||||
0,
|
||||
wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src))),
|
||||
wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src))),
|
||||
self->private_impl.f_metadata_io_position);
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__even_more_information);
|
||||
@@ -28128,7 +28728,6 @@ wuffs_gif__decoder__tell_me_more(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_tell_me_more[0] = 0;
|
||||
goto exit;
|
||||
@@ -28396,7 +28995,6 @@ wuffs_gif__decoder__decode_frame_config(
|
||||
wuffs_base__u64__sat_add_indirect(&self->private_impl.f_num_decoded_frame_configs_value, 1);
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -28635,9 +29233,9 @@ wuffs_gif__decoder__decode_up_to_id_part1(
|
||||
|
||||
if ( ! self->private_impl.f_restarted) {
|
||||
if (self->private_impl.f_call_sequence != 2) {
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
}
|
||||
} else if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
} else if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
} else {
|
||||
@@ -29062,7 +29660,6 @@ wuffs_gif__decoder__decode_extension(
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_extension[0] = 0;
|
||||
goto exit;
|
||||
@@ -29131,7 +29728,6 @@ wuffs_gif__decoder__skip_blocks(
|
||||
iop_a_src += self->private_data.s_skip_blocks[0].scratch;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_skip_blocks[0] = 0;
|
||||
goto exit;
|
||||
@@ -29324,13 +29920,13 @@ wuffs_gif__decoder__decode_ae(
|
||||
} else if (self->private_impl.f_ignore_metadata) {
|
||||
} else if (v_is_iccp && self->private_impl.f_report_metadata_iccp) {
|
||||
self->private_impl.f_metadata_fourcc = 1229144912;
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_call_sequence = 1;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
} else if (v_is_xmp && self->private_impl.f_report_metadata_xmp) {
|
||||
self->private_impl.f_metadata_fourcc = 1481461792;
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_metadata_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_call_sequence = 1;
|
||||
status = wuffs_base__make_status(wuffs_base__note__metadata_reported);
|
||||
goto ok;
|
||||
@@ -29350,7 +29946,6 @@ wuffs_gif__decoder__decode_ae(
|
||||
goto suspend;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_ae[0] = 0;
|
||||
goto exit;
|
||||
@@ -29820,7 +30415,6 @@ wuffs_gif__decoder__decode_id_part1(
|
||||
wuffs_lzw__decoder__set_literal_width(&self->private_data.f_lzw, ((uint32_t)(v_lw)));
|
||||
self->private_impl.f_previous_lzw_decode_ended_abruptly = true;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_id_part1[0] = 0;
|
||||
goto exit;
|
||||
@@ -29956,7 +30550,8 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
wuffs_base__slice_u8__subslice_ij(wuffs_base__make_slice_u8(self->private_data.f_compressed,
|
||||
4096),
|
||||
self->private_impl.f_compressed_ri,
|
||||
self->private_impl.f_compressed_wi));
|
||||
self->private_impl.f_compressed_wi),
|
||||
0);
|
||||
v_mark = ((uint64_t)(iop_v_r - io0_v_r));
|
||||
{
|
||||
u_r.meta.ri = ((size_t)(iop_v_r - u_r.data.ptr));
|
||||
@@ -30027,7 +30622,6 @@ wuffs_gif__decoder__decode_id_part2(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_id_part2[0] = 0;
|
||||
goto exit;
|
||||
@@ -30637,7 +31231,6 @@ wuffs_gzip__decoder__transform_io(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -32094,7 +32687,6 @@ wuffs_json__decoder__decode_tokens(
|
||||
}
|
||||
self->private_impl.f_end_of_data = true;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_tokens[0] = 0;
|
||||
goto exit;
|
||||
@@ -32396,7 +32988,6 @@ wuffs_json__decoder__decode_leading(
|
||||
}
|
||||
label__0__break:;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_leading[0] = 0;
|
||||
goto exit;
|
||||
@@ -32538,16 +33129,19 @@ wuffs_json__decoder__decode_comment(
|
||||
}
|
||||
while (true) {
|
||||
if (((uint64_t)(io2_a_src - iop_a_src)) <= 0) {
|
||||
if (v_length > 0) {
|
||||
if (a_src && a_src->meta.closed) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
self->private_impl.f_comment_type = 2;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
} else if (v_length > 0) {
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)(1)) << WUFFS_BASE__TOKEN__CONTINUED__SHIFT) |
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
}
|
||||
if (a_src && a_src->meta.closed) {
|
||||
status = wuffs_base__make_status(wuffs_json__error__bad_input);
|
||||
goto exit;
|
||||
}
|
||||
status = wuffs_base__make_status(wuffs_base__suspension__short_read);
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(6);
|
||||
v_length = 0;
|
||||
@@ -32555,10 +33149,9 @@ wuffs_json__decoder__decode_comment(
|
||||
}
|
||||
v_c = wuffs_base__peek_u8be__no_bounds_check(iop_a_src);
|
||||
if (v_c == 10) {
|
||||
iop_a_src += 1;
|
||||
*iop_a_dst++ = wuffs_base__make_token(
|
||||
(((uint64_t)(4)) << WUFFS_BASE__TOKEN__VALUE_MINOR__SHIFT) |
|
||||
(((uint64_t)((v_length + 1))) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
(((uint64_t)(v_length)) << WUFFS_BASE__TOKEN__LENGTH__SHIFT));
|
||||
self->private_impl.f_comment_type = 2;
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
@@ -32577,7 +33170,6 @@ wuffs_json__decoder__decode_comment(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_comment[0] = 0;
|
||||
goto exit;
|
||||
@@ -32738,7 +33330,6 @@ wuffs_json__decoder__decode_inf_nan(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_inf_nan[0] = 0;
|
||||
goto exit;
|
||||
@@ -32884,7 +33475,6 @@ wuffs_json__decoder__decode_trailer(
|
||||
}
|
||||
label__outer__break:;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_trailer[0] = 0;
|
||||
goto exit;
|
||||
@@ -33329,7 +33919,7 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
if (16 != wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
if (16 != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
@@ -33359,7 +33949,6 @@ wuffs_nie__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -33468,7 +34057,6 @@ wuffs_nie__decoder__decode_frame(
|
||||
label__0__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -33558,7 +34146,6 @@ wuffs_nie__decoder__swizzle(
|
||||
status = wuffs_base__make_status(NULL);
|
||||
goto ok;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
goto exit;
|
||||
exit:
|
||||
@@ -34158,7 +34745,6 @@ wuffs_zlib__decoder__transform_io(
|
||||
goto exit;
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_transform_io[0] = 0;
|
||||
goto exit;
|
||||
@@ -36297,7 +36883,7 @@ wuffs_png__decoder__decode_image_config(
|
||||
status = wuffs_base__make_status(wuffs_png__error__missing_palette);
|
||||
goto exit;
|
||||
}
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
if (a_dst != NULL) {
|
||||
wuffs_base__image_config__set(
|
||||
a_dst,
|
||||
@@ -36310,7 +36896,6 @@ wuffs_png__decoder__decode_image_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 3;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_image_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -36389,7 +36974,7 @@ wuffs_png__decoder__decode_ihdr(
|
||||
}
|
||||
v_a32 = t_0;
|
||||
}
|
||||
if (v_a32 >= 2147483648) {
|
||||
if ((v_a32 == 0) || (v_a32 >= 2147483648)) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_header);
|
||||
goto exit;
|
||||
} else if (v_a32 >= 16777216) {
|
||||
@@ -36426,7 +37011,7 @@ wuffs_png__decoder__decode_ihdr(
|
||||
}
|
||||
v_a32 = t_1;
|
||||
}
|
||||
if (v_a32 >= 2147483648) {
|
||||
if ((v_a32 == 0) || (v_a32 >= 2147483648)) {
|
||||
status = wuffs_base__make_status(wuffs_png__error__bad_header);
|
||||
goto exit;
|
||||
} else if (v_a32 >= 16777216) {
|
||||
@@ -36559,7 +37144,7 @@ wuffs_png__decoder__assign_filter_distance(
|
||||
self->private_impl.f_src_pixfmt = 536870920;
|
||||
self->private_impl.f_filter_distance = 1;
|
||||
} else if (self->private_impl.f_depth == 16) {
|
||||
self->private_impl.f_dst_pixfmt = 536870920;
|
||||
self->private_impl.f_dst_pixfmt = 536870923;
|
||||
self->private_impl.f_src_pixfmt = 537919499;
|
||||
self->private_impl.f_filter_distance = 2;
|
||||
}
|
||||
@@ -37006,7 +37591,7 @@ wuffs_png__decoder__decode_frame_config(
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
@@ -37036,7 +37621,6 @@ wuffs_png__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -37163,7 +37747,6 @@ wuffs_png__decoder__decode_frame(
|
||||
label__0__break:;
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -37242,7 +37825,8 @@ wuffs_png__decoder__decode_pass(
|
||||
&io2_v_w,
|
||||
wuffs_base__slice_u8__subslice_ij(a_workbuf,
|
||||
self->private_impl.f_workbuf_wi,
|
||||
self->private_impl.f_pass_workbuf_length));
|
||||
self->private_impl.f_pass_workbuf_length),
|
||||
self->private_impl.f_workbuf_wi);
|
||||
{
|
||||
const uint8_t *o_1_io2_a_src = io2_a_src;
|
||||
wuffs_base__io_reader__limit(&io2_a_src, iop_a_src,
|
||||
@@ -37462,7 +38046,6 @@ wuffs_png__decoder__decode_pass(
|
||||
}
|
||||
}
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_pass[0] = 0;
|
||||
goto exit;
|
||||
@@ -38142,7 +38725,7 @@ wuffs_wbmp__decoder__decode_image_config(
|
||||
}
|
||||
v_i += 1;
|
||||
}
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
self->private_impl.f_frame_config_io_position = wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)));
|
||||
if (a_dst != NULL) {
|
||||
wuffs_base__image_config__set(
|
||||
a_dst,
|
||||
@@ -38236,7 +38819,7 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
goto suspend;
|
||||
}
|
||||
} else if (self->private_impl.f_call_sequence == 3) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add(a_src->meta.pos, ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
if (self->private_impl.f_frame_config_io_position != wuffs_base__u64__sat_add((a_src ? a_src->meta.pos : 0), ((uint64_t)(iop_a_src - io0_a_src)))) {
|
||||
status = wuffs_base__make_status(wuffs_base__error__bad_restart);
|
||||
goto exit;
|
||||
}
|
||||
@@ -38266,7 +38849,6 @@ wuffs_wbmp__decoder__decode_frame_config(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 4;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame_config[0] = 0;
|
||||
goto exit;
|
||||
@@ -38431,7 +39013,6 @@ wuffs_wbmp__decoder__decode_frame(
|
||||
}
|
||||
self->private_impl.f_call_sequence = 255;
|
||||
|
||||
goto ok;
|
||||
ok:
|
||||
self->private_impl.p_decode_frame[0] = 0;
|
||||
goto exit;
|
||||
@@ -38768,7 +39349,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
// Prepare the low-level CBOR decoder.
|
||||
wuffs_cbor__decoder::unique_ptr dec = wuffs_cbor__decoder::alloc();
|
||||
if (!dec) {
|
||||
ret_error_message = "wuffs_aux::CborDecoder: out of memory";
|
||||
ret_error_message = "wuffs_aux::DecodeCbor: out of memory";
|
||||
goto done;
|
||||
}
|
||||
for (size_t i = 0; i < quirks.len; i++) {
|
||||
@@ -38783,7 +39364,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
wuffs_base__status tok_status = wuffs_base__make_status(nullptr);
|
||||
|
||||
// Prepare other state.
|
||||
uint32_t depth = 0;
|
||||
int32_t depth = 0;
|
||||
std::string str;
|
||||
int64_t extension_category = 0;
|
||||
uint64_t extension_detail = 0;
|
||||
@@ -38810,17 +39391,17 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
goto done;
|
||||
} else if (cursor_index != io_buf->meta.ri) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad cursor_index";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad cursor_index";
|
||||
goto done;
|
||||
} else if (io_buf->meta.closed) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: io_buf is closed";
|
||||
"wuffs_aux::DecodeCbor: internal error: io_buf is closed";
|
||||
goto done;
|
||||
}
|
||||
io_buf->compact();
|
||||
if (io_buf->meta.wi >= io_buf->data.len) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: io_buf is full";
|
||||
"wuffs_aux::DecodeCbor: internal error: io_buf is full";
|
||||
goto done;
|
||||
}
|
||||
cursor_index = io_buf->meta.ri;
|
||||
@@ -38832,11 +39413,19 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
|
||||
if (WUFFS_CBOR__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad WORKBUF_LEN";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad WORKBUF_LEN";
|
||||
goto done;
|
||||
}
|
||||
wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8();
|
||||
tok_status = dec->decode_tokens(&tok_buf, io_buf, work_buf);
|
||||
if ((tok_buf.meta.ri > tok_buf.meta.wi) ||
|
||||
(tok_buf.meta.wi > tok_buf.data.len) ||
|
||||
(io_buf->meta.ri > io_buf->meta.wi) ||
|
||||
(io_buf->meta.wi > io_buf->data.len)) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeCbor: internal error: bad buffer indexes";
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++];
|
||||
@@ -38844,7 +39433,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
if ((io_buf->meta.ri < cursor_index) ||
|
||||
((io_buf->meta.ri - cursor_index) < token_len)) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad token indexes";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad token indexes";
|
||||
goto done;
|
||||
}
|
||||
uint8_t* token_ptr = io_buf->data.ptr + cursor_index;
|
||||
@@ -38880,7 +39469,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
}
|
||||
}
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: bad extended token";
|
||||
"wuffs_aux::DecodeCbor: internal error: bad extended token";
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -38895,10 +39484,20 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
goto done;
|
||||
}
|
||||
depth++;
|
||||
if (depth > WUFFS_CBOR__DECODER_DEPTH_MAX_INCL) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeCbor: internal error: bad depth";
|
||||
goto done;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
ret_error_message = callbacks.Pop(static_cast<uint32_t>(vbd));
|
||||
depth--;
|
||||
if (depth < 0) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeCbor: internal error: bad depth";
|
||||
goto done;
|
||||
}
|
||||
goto parsed_a_value;
|
||||
}
|
||||
|
||||
@@ -39035,7 +39634,7 @@ DecodeCbor(DecodeCborCallbacks& callbacks,
|
||||
|
||||
fail:
|
||||
ret_error_message =
|
||||
"wuffs_aux::CborDecoder: internal error: unexpected token";
|
||||
"wuffs_aux::DecodeCbor: internal error: unexpected token";
|
||||
goto done;
|
||||
|
||||
parsed_a_value:
|
||||
@@ -39502,60 +40101,65 @@ DecodeJsonCallbacks::Done(DecodeJsonResult& result,
|
||||
sync_io::Input& input,
|
||||
IOBuffer& buffer) {}
|
||||
|
||||
const char DecodeJson_BadJsonPointer[] =
|
||||
const char DecodeJson_BadJsonPointer[] = //
|
||||
"wuffs_aux::DecodeJson: bad JSON Pointer";
|
||||
const char DecodeJson_NoMatch[] = "wuffs_aux::DecodeJson: no match";
|
||||
const char DecodeJson_NoMatch[] = //
|
||||
"wuffs_aux::DecodeJson: no match";
|
||||
|
||||
// --------
|
||||
|
||||
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
|
||||
while (tok_buf.meta.ri >= tok_buf.meta.wi) { \
|
||||
if (tok_status.repr == nullptr) { \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_write) { \
|
||||
tok_buf.compact(); \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_read) { \
|
||||
if (!io_error_message.empty()) { \
|
||||
ret_error_message = std::move(io_error_message); \
|
||||
goto done; \
|
||||
} else if (cursor_index != io_buf->meta.ri) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad cursor_index"; \
|
||||
goto done; \
|
||||
} else if (io_buf->meta.closed) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
|
||||
goto done; \
|
||||
} \
|
||||
io_buf->compact(); \
|
||||
if (io_buf->meta.wi >= io_buf->data.len) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
|
||||
goto done; \
|
||||
} \
|
||||
cursor_index = io_buf->meta.ri; \
|
||||
io_error_message = input.CopyIn(io_buf); \
|
||||
} else { \
|
||||
ret_error_message = tok_status.message(); \
|
||||
goto done; \
|
||||
} \
|
||||
if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN"; \
|
||||
goto done; \
|
||||
} \
|
||||
wuffs_base__slice_u8 work_buf = wuffs_base__empty_slice_u8(); \
|
||||
tok_status = dec->decode_tokens(&tok_buf, io_buf, work_buf); \
|
||||
} \
|
||||
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \
|
||||
uint64_t token_len = token.length(); \
|
||||
if ((io_buf->meta.ri < cursor_index) || \
|
||||
((io_buf->meta.ri - cursor_index) < token_len)) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad token indexes"; \
|
||||
goto done; \
|
||||
} \
|
||||
uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \
|
||||
(void)(token_ptr); \
|
||||
#define WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN \
|
||||
while (tok_buf.meta.ri >= tok_buf.meta.wi) { \
|
||||
if (tok_status.repr == nullptr) { \
|
||||
goto done; \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_write) { \
|
||||
tok_buf.compact(); \
|
||||
} else if (tok_status.repr == wuffs_base__suspension__short_read) { \
|
||||
if (!io_error_message.empty()) { \
|
||||
ret_error_message = std::move(io_error_message); \
|
||||
goto done; \
|
||||
} else if (cursor_index != io_buf->meta.ri) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad cursor_index"; \
|
||||
goto done; \
|
||||
} else if (io_buf->meta.closed) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is closed"; \
|
||||
goto done; \
|
||||
} \
|
||||
io_buf->compact(); \
|
||||
if (io_buf->meta.wi >= io_buf->data.len) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: io_buf is full"; \
|
||||
goto done; \
|
||||
} \
|
||||
cursor_index = io_buf->meta.ri; \
|
||||
io_error_message = input.CopyIn(io_buf); \
|
||||
} else { \
|
||||
ret_error_message = tok_status.message(); \
|
||||
goto done; \
|
||||
} \
|
||||
tok_status = \
|
||||
dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8()); \
|
||||
if ((tok_buf.meta.ri > tok_buf.meta.wi) || \
|
||||
(tok_buf.meta.wi > tok_buf.data.len) || \
|
||||
(io_buf->meta.ri > io_buf->meta.wi) || \
|
||||
(io_buf->meta.wi > io_buf->data.len)) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad buffer indexes"; \
|
||||
goto done; \
|
||||
} \
|
||||
} \
|
||||
wuffs_base__token token = tok_buf.data.ptr[tok_buf.meta.ri++]; \
|
||||
uint64_t token_len = token.length(); \
|
||||
if ((io_buf->meta.ri < cursor_index) || \
|
||||
((io_buf->meta.ri - cursor_index) < token_len)) { \
|
||||
ret_error_message = \
|
||||
"wuffs_aux::DecodeJson: internal error: bad token indexes"; \
|
||||
goto done; \
|
||||
} \
|
||||
uint8_t* token_ptr = io_buf->data.ptr + cursor_index; \
|
||||
(void)(token_ptr); \
|
||||
cursor_index += static_cast<size_t>(token_len)
|
||||
|
||||
// --------
|
||||
@@ -39563,7 +40167,8 @@ const char DecodeJson_NoMatch[] = "wuffs_aux::DecodeJson: no match";
|
||||
namespace {
|
||||
|
||||
// DecodeJson_SplitJsonPointer returns ("bar", 8) for ("/foo/bar/b~1z/qux", 5,
|
||||
// etc). It returns a 0 size_t when s has invalid JSON Pointer syntax.
|
||||
// etc). It returns a 0 size_t when s has invalid JSON Pointer syntax or i is
|
||||
// out of bounds.
|
||||
//
|
||||
// The string returned is unescaped. If calling it again, this time with i=8,
|
||||
// the "b~1z" substring would be returned as "b/z".
|
||||
@@ -39572,6 +40177,9 @@ DecodeJson_SplitJsonPointer(std::string& s,
|
||||
size_t i,
|
||||
bool allow_tilde_n_tilde_r_tilde_t) {
|
||||
std::string fragment;
|
||||
if (i > s.size()) {
|
||||
return std::make_pair(std::string(), 0);
|
||||
}
|
||||
while (i < s.size()) {
|
||||
char c = s[i];
|
||||
if (c == '/') {
|
||||
@@ -39778,8 +40386,8 @@ check_that_a_value_follows:
|
||||
continue;
|
||||
}
|
||||
|
||||
// Undo the last part of WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN, so that
|
||||
// we're only peeking at the next token.
|
||||
// Undo the last part of WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN, so
|
||||
// that we're only peeking at the next token.
|
||||
tok_buf.meta.ri--;
|
||||
cursor_index -= static_cast<size_t>(token_len);
|
||||
|
||||
@@ -39826,6 +40434,10 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
if (!dec) {
|
||||
ret_error_message = "wuffs_aux::DecodeJson: out of memory";
|
||||
goto done;
|
||||
} else if (WUFFS_JSON__DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE != 0) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeJson: internal error: bad WORKBUF_LEN";
|
||||
goto done;
|
||||
}
|
||||
bool allow_tilde_n_tilde_r_tilde_t = false;
|
||||
for (size_t i = 0; i < quirks.len; i++) {
|
||||
@@ -39841,10 +40453,11 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
wuffs_base__token_buffer tok_buf =
|
||||
wuffs_base__slice_token__writer(wuffs_base__make_slice_token(
|
||||
&tok_array[0], (sizeof(tok_array) / sizeof(tok_array[0]))));
|
||||
wuffs_base__status tok_status = wuffs_base__make_status(nullptr);
|
||||
wuffs_base__status tok_status =
|
||||
dec->decode_tokens(&tok_buf, io_buf, wuffs_base__empty_slice_u8());
|
||||
|
||||
// Prepare other state.
|
||||
uint32_t depth = 0;
|
||||
int32_t depth = 0;
|
||||
std::string str;
|
||||
|
||||
// Walk the (optional) JSON Pointer.
|
||||
@@ -39855,7 +40468,7 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
}
|
||||
std::pair<std::string, size_t> split = DecodeJson_SplitJsonPointer(
|
||||
json_pointer, i + 1, allow_tilde_n_tilde_r_tilde_t);
|
||||
i = std::move(split.second);
|
||||
i = split.second;
|
||||
if (i == 0) {
|
||||
ret_error_message = DecodeJson_BadJsonPointer;
|
||||
goto done;
|
||||
@@ -39887,10 +40500,20 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
goto done;
|
||||
}
|
||||
depth++;
|
||||
if (depth > WUFFS_JSON__DECODER_DEPTH_MAX_INCL) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeJson: internal error: bad depth";
|
||||
goto done;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
ret_error_message = callbacks.Pop(static_cast<uint32_t>(vbd));
|
||||
depth--;
|
||||
if (depth < 0) {
|
||||
ret_error_message =
|
||||
"wuffs_aux::DecodeJson: internal error: bad depth";
|
||||
goto done;
|
||||
}
|
||||
goto parsed_a_value;
|
||||
}
|
||||
|
||||
@@ -39990,7 +40613,22 @@ DecodeJson(DecodeJsonCallbacks& callbacks,
|
||||
goto done;
|
||||
|
||||
parsed_a_value:
|
||||
if (!ret_error_message.empty() || (depth == 0)) {
|
||||
// If an error was encountered, we are done. Otherwise, (depth == 0)
|
||||
// after parsing a value is equivalent to having decoded the entire JSON
|
||||
// value (for an empty json_pointer query) or having decoded the
|
||||
// pointed-to JSON value (for a non-empty json_pointer query). In the
|
||||
// latter case, we are also done.
|
||||
//
|
||||
// However, if quirks like WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER or
|
||||
// WUFFS_JSON__QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF are passed, decoding
|
||||
// the entire JSON value should also consume any trailing filler, in case
|
||||
// the DecodeJson caller wants to subsequently check that the input is
|
||||
// completely exhausted (and otherwise raise "valid JSON followed by
|
||||
// further (unexpected) data"). We aren't done yet. Instead, keep the
|
||||
// loop running until WUFFS_AUX__DECODE_JSON__GET_THE_NEXT_TOKEN's
|
||||
// decode_tokens returns an ok status.
|
||||
if (!ret_error_message.empty() ||
|
||||
((depth == 0) && !json_pointer.empty())) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
@@ -40017,6 +40655,8 @@ done:
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#elif defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif // WUFFS_INCLUDE_GUARD
|
||||
@@ -31,6 +31,7 @@ extern crate png;
|
||||
extern crate rustc_version_runtime;
|
||||
|
||||
use std::time::Instant;
|
||||
use std::convert::TryInto;
|
||||
|
||||
const ITERSCALE: u64 = 50;
|
||||
const REPS: u64 = 5;
|
||||
@@ -153,13 +154,9 @@ fn decode(dst0: &mut [u8], dst1: &mut [u8], src: &[u8]) -> u64 {
|
||||
return num_bytes;
|
||||
} else if info.color_type == png::ColorType::RGB {
|
||||
// Convert RGB => BGRA.
|
||||
for i in 0..((num_bytes / 3) as usize) {
|
||||
dst1[(4 * i) + 0] = dst0[(3 * i) + 2];
|
||||
dst1[(4 * i) + 1] = dst0[(3 * i) + 1];
|
||||
dst1[(4 * i) + 2] = dst0[(3 * i) + 0];
|
||||
dst1[(4 * i) + 3] = 0xFF;
|
||||
}
|
||||
return (num_bytes / 3) * 4;
|
||||
let new_size = ((num_bytes / 3) * 4) as usize;
|
||||
rgb_to_bgra(&dst0[..num_bytes as usize], &mut dst1[..new_size]);
|
||||
return new_size as u64;
|
||||
} else if info.color_type == png::ColorType::RGBA {
|
||||
// Convert RGBA => BGRA.
|
||||
for i in 0..((num_bytes / 4) as usize) {
|
||||
@@ -172,3 +169,35 @@ fn decode(dst0: &mut [u8], dst1: &mut [u8], src: &[u8]) -> u64 {
|
||||
// Returning 0 should lead to a panic (when want_num_bytes != 0).
|
||||
0
|
||||
}
|
||||
|
||||
/// Copy `src` (treated as 3-byte chunks) into `dst`
|
||||
/// (treated as 4-byte chunks), filling out `dst` by adding
|
||||
/// a `0xff` "alpha value" at the end of each entry.
|
||||
///
|
||||
/// # Panics:
|
||||
///
|
||||
/// Will panic if
|
||||
///
|
||||
/// * The length of `src` is not a multiple of 3.
|
||||
/// * The length of `dst` is not a multiple of 4.
|
||||
/// * `src` and `dst` do not have the same length in chunks.
|
||||
#[inline]
|
||||
pub fn rgb_to_bgra(src: &[u8], dst: &mut [u8]) {
|
||||
let nsrc = src.len();
|
||||
let ndst = dst.len();
|
||||
assert_eq!(0, nsrc % 3);
|
||||
assert_eq!(0, ndst % 4);
|
||||
assert_eq!(nsrc, (ndst / 4) * 3);
|
||||
for (s, d) in src.chunks_exact(3).zip(dst.chunks_exact_mut(4)) {
|
||||
let s: &[u8; 3] = s.try_into().unwrap();
|
||||
let d: &mut [u8; 4] = d.try_into().unwrap();
|
||||
// R
|
||||
d[0] = s[2];
|
||||
// G
|
||||
d[1] = s[1];
|
||||
// B
|
||||
d[2] = s[0];
|
||||
// A
|
||||
d[3] = 0xff;
|
||||
}
|
||||
}
|
||||
@@ -261,7 +261,7 @@ process_file(char* filename) {
|
||||
g_file = NULL;
|
||||
}
|
||||
g_filename = filename;
|
||||
g_file = fopen(g_filename, "r");
|
||||
g_file = fopen(g_filename, "rb");
|
||||
if (!g_file) {
|
||||
fprintf(stderr, "main: could not open %s\n", g_filename);
|
||||
return false;
|
||||
|
||||
@@ -416,7 +416,7 @@ compute_exit_code(const char* status_msg) {
|
||||
n = strnlen(status_msg, 2047);
|
||||
}
|
||||
fprintf(stderr, "%s\n", status_msg);
|
||||
// Return an exit code of 1 for regular (forseen) errors, e.g. badly
|
||||
// Return an exit code of 1 for regular (foreseen) errors, e.g. badly
|
||||
// formatted or unsupported input.
|
||||
//
|
||||
// Return an exit code of 2 for internal (exceptional) errors, e.g. defensive
|
||||
|
||||
@@ -304,7 +304,7 @@ compute_exit_code(const char* status_msg) {
|
||||
n = strnlen(status_msg, 2047);
|
||||
}
|
||||
fprintf(stderr, "%s\n", status_msg);
|
||||
// Return an exit code of 1 for regular (forseen) errors, e.g. badly
|
||||
// Return an exit code of 1 for regular (foreseen) errors, e.g. badly
|
||||
// formatted or unsupported input.
|
||||
//
|
||||
// Return an exit code of 2 for internal (exceptional) errors, e.g. defensive
|
||||
|
||||
@@ -25,6 +25,10 @@ pub func hasher.update_u32!(x: slice base.u8) base.u32 {
|
||||
if not this.started {
|
||||
this.started = true
|
||||
this.state = 1
|
||||
// There used to be an up_x86_avx2 implementation too, but while it
|
||||
// made the std/adler32 micro-benchmarks better, it also made the
|
||||
// std/zlib and std/png micro-benchmarks worse. See commit baec831f
|
||||
// "Add std/adler32 hasher.up_x86_avx2".
|
||||
choose up = [
|
||||
up_arm_neon,
|
||||
up_x86_sse42]
|
||||
|
||||
@@ -28,8 +28,8 @@ pri func hasher.up_x86_sse42!(x: slice base.u8),
|
||||
var ones : base.x86_m128i
|
||||
var weights__left : base.x86_m128i
|
||||
var weights_right : base.x86_m128i
|
||||
var p__left : base.x86_m128i
|
||||
var p_right : base.x86_m128i
|
||||
var q__left : base.x86_m128i
|
||||
var q_right : base.x86_m128i
|
||||
var v1 : base.x86_m128i
|
||||
var v2 : base.x86_m128i
|
||||
var v2j : base.x86_m128i
|
||||
@@ -92,13 +92,13 @@ pri func hasher.up_x86_sse42!(x: slice base.u8),
|
||||
|
||||
// The inner loop.
|
||||
iterate (p = args.x)(length: 32, advance: 32, unroll: 1) {
|
||||
// Split the 32-byte p into left and right halves. SSE4.2 works
|
||||
// with 16-byte registers.
|
||||
// SSE4.2 works with 16-byte registers. Split the 32-byte p into
|
||||
// left and right halves.
|
||||
//
|
||||
// Let p__left = [u8×16: p00, p01, p02, ..., p15]
|
||||
// Let p_right = [u8×16: p16, p17, p18, ..., p31]
|
||||
p__left = util.make_m128i_slice128(a: p[.. 16])
|
||||
p_right = util.make_m128i_slice128(a: p[16 .. 32])
|
||||
// Let q__left = [u8×16: p00, p01, p02, ..., p15]
|
||||
// Let q_right = [u8×16: p16, p17, p18, ..., p31]
|
||||
q__left = util.make_m128i_slice128(a: p[.. 16])
|
||||
q_right = util.make_m128i_slice128(a: p[16 .. 32])
|
||||
|
||||
// For v2j, we need to calculate the sums of the s1j terms for each
|
||||
// of p's 32 elements. This is simply 32 times the same number,
|
||||
@@ -108,14 +108,14 @@ pri func hasher.up_x86_sse42!(x: slice base.u8),
|
||||
|
||||
// For v1, we need to add the elements of p. Computing the sum of
|
||||
// absolute differences (_mm_sad_epu8) with zero just sums the
|
||||
// elements. p__left._mm_sad_epu8(b: zeroes) equals
|
||||
// elements. q__left._mm_sad_epu8(b: zeroes) equals
|
||||
// [u64×2: p00 + p01 + ... + p07, p08 + p09 + ... + p15]
|
||||
// This is equivalent (little-endian) to:
|
||||
// [u32×4: p00 + p01 + ... + p07, 0, p08 + p09 + ... + p15, 0]
|
||||
// We accumulate those "sum of p__left elements" in v1, and ditto
|
||||
// for the p_right elements.
|
||||
v1 = v1._mm_add_epi32(b: p__left._mm_sad_epu8(b: zeroes))
|
||||
v1 = v1._mm_add_epi32(b: p_right._mm_sad_epu8(b: zeroes))
|
||||
// We accumulate those "sum of q__left's elements" in v1, and ditto
|
||||
// for q_right's elements.
|
||||
v1 = v1._mm_add_epi32(b: q__left._mm_sad_epu8(b: zeroes))
|
||||
v1 = v1._mm_add_epi32(b: q_right._mm_sad_epu8(b: zeroes))
|
||||
|
||||
// For v2k, we need to calculate a weighted sum: ((32 * p00) + (31
|
||||
// * p01) + (30 * p02) + ... + (1 * p31)), which splits naturally
|
||||
@@ -128,19 +128,19 @@ pri func hasher.up_x86_sse42!(x: slice base.u8),
|
||||
// ...
|
||||
// ((18*p14)+(17*p15))]
|
||||
//
|
||||
// The ones._mm_madd_epi16(b: etc) call is likewise a multiply-add
|
||||
// (note that it's "madd" not "add"). Multiplying by 1 is a no-op,
|
||||
// so this sums u16 pairs to produce u32 values:
|
||||
// The ones._mm_madd_epi16(b: etc) call is a multiply-add (note
|
||||
// that it's "madd" not "add"). Multiplying by 1 is a no-op, so
|
||||
// this sums u16 pairs to produce u32 values:
|
||||
// [u32×4: ((32*p00)+(31*p01)+(30*p02)+(29*p03)),
|
||||
// ((28*p04)+(27*p05)+(26*p06)+(25*p07)),
|
||||
// ...
|
||||
// ((20*p12)+(19*p13)+(18*p14)+(17*p15))]
|
||||
//
|
||||
// Ditto again for the p_right elements.
|
||||
// Ditto again for q_right's elements.
|
||||
v2k = v2k._mm_add_epi32(b: ones._mm_madd_epi16(b:
|
||||
p__left._mm_maddubs_epi16(b: weights__left)))
|
||||
q__left._mm_maddubs_epi16(b: weights__left)))
|
||||
v2k = v2k._mm_add_epi32(b: ones._mm_madd_epi16(b:
|
||||
p_right._mm_maddubs_epi16(b: weights_right)))
|
||||
q_right._mm_maddubs_epi16(b: weights_right)))
|
||||
}
|
||||
|
||||
// Merge the four parallel u32 sums (v1) into the single u32 sum (s1).
|
||||
|
||||
@@ -27,6 +27,7 @@ pub func ieee_hasher.update_u32!(x: slice base.u8) base.u32 {
|
||||
if this.state == 0 {
|
||||
choose up = [
|
||||
up_arm_crc32,
|
||||
up_x86_avx2,
|
||||
up_x86_sse42]
|
||||
}
|
||||
this.up!(x: args.x)
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
// Copyright 2021 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// --------
|
||||
|
||||
// See "SIMD Implementations" in README.md for a link to Gopal et al. "Fast CRC
|
||||
// Computation for Generic Polynomials Using PCLMULQDQ Instruction".
|
||||
|
||||
// up_x86_avx2 is exactly the same as up_x86_sse42 except for the "choose
|
||||
// cpu_arch >= x86_avx2". With AVX, PCLMULQDQ has a three-operand form, not
|
||||
// just a two-operand form: https://www.felixcloutier.com/x86/pclmulqdq
|
||||
pri func ieee_hasher.up_x86_avx2!(x: slice base.u8),
|
||||
choose cpu_arch >= x86_avx2,
|
||||
{
|
||||
var s : base.u32
|
||||
var p : slice base.u8
|
||||
|
||||
var util : base.x86_sse42_utility
|
||||
var k : base.x86_m128i
|
||||
var x0 : base.x86_m128i
|
||||
var x1 : base.x86_m128i
|
||||
var x2 : base.x86_m128i
|
||||
var x3 : base.x86_m128i
|
||||
var y0 : base.x86_m128i
|
||||
var y1 : base.x86_m128i
|
||||
var y2 : base.x86_m128i
|
||||
var y3 : base.x86_m128i
|
||||
|
||||
var tail_index : base.u64
|
||||
|
||||
s = 0xFFFF_FFFF ^ this.state
|
||||
|
||||
// Align to a 16-byte boundary.
|
||||
while (args.x.length() > 0) and ((15 & args.x.uintptr_low_12_bits()) <> 0) {
|
||||
s = IEEE_TABLE[0][((s & 0xFF) as base.u8) ^ args.x[0]] ^ (s >> 8)
|
||||
args.x = args.x[1 ..]
|
||||
} endwhile
|
||||
|
||||
// For short inputs, just do a simple loop.
|
||||
if args.x.length() < 64 {
|
||||
iterate (p = args.x)(length: 1, advance: 1, unroll: 1) {
|
||||
s = IEEE_TABLE[0][((s & 0xFF) as base.u8) ^ p[0]] ^ (s >> 8)
|
||||
}
|
||||
this.state = 0xFFFF_FFFF ^ s
|
||||
return nothing
|
||||
}
|
||||
|
||||
// Load 128×4 = 512 bits from the first 64-byte chunk.
|
||||
x0 = util.make_m128i_slice128(a: args.x[0x00 .. 0x10])
|
||||
x1 = util.make_m128i_slice128(a: args.x[0x10 .. 0x20])
|
||||
x2 = util.make_m128i_slice128(a: args.x[0x20 .. 0x30])
|
||||
x3 = util.make_m128i_slice128(a: args.x[0x30 .. 0x40])
|
||||
|
||||
// Combine with the initial state.
|
||||
x0 = x0._mm_xor_si128(b: util.make_m128i_single_u32(a: s))
|
||||
|
||||
// Process the remaining 64-byte chunks.
|
||||
k = util.make_m128i_slice128(a: IEEE_X86_SSE42_K1K2[.. 16])
|
||||
iterate (p = args.x[64 ..])(length: 64, advance: 64, unroll: 1) {
|
||||
y0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
y1 = x1._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
y2 = x2._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
y3 = x3._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x1 = x1._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x2 = x2._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x3 = x3._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
|
||||
x0 = x0._mm_xor_si128(b: y0)._mm_xor_si128(b: util.make_m128i_slice128(a: p[0x00 .. 0x10]))
|
||||
x1 = x1._mm_xor_si128(b: y1)._mm_xor_si128(b: util.make_m128i_slice128(a: p[0x10 .. 0x20]))
|
||||
x2 = x2._mm_xor_si128(b: y2)._mm_xor_si128(b: util.make_m128i_slice128(a: p[0x20 .. 0x30]))
|
||||
x3 = x3._mm_xor_si128(b: y3)._mm_xor_si128(b: util.make_m128i_slice128(a: p[0x30 .. 0x40]))
|
||||
}
|
||||
|
||||
// Reduce 128×4 = 512 bits to 128 bits.
|
||||
k = util.make_m128i_slice128(a: IEEE_X86_SSE42_K3K4[.. 16])
|
||||
y0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x0 = x0._mm_xor_si128(b: x1)
|
||||
x0 = x0._mm_xor_si128(b: y0)
|
||||
y0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x0 = x0._mm_xor_si128(b: x2)
|
||||
x0 = x0._mm_xor_si128(b: y0)
|
||||
y0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x11)
|
||||
x0 = x0._mm_xor_si128(b: x3)
|
||||
x0 = x0._mm_xor_si128(b: y0)
|
||||
|
||||
// Reduce 128 bits to 64 bits.
|
||||
x1 = x0._mm_clmulepi64_si128(b: k, imm8: 0x10)
|
||||
x2 = util.make_m128i_multiple_u32(
|
||||
a00: 0xFFFF_FFFF,
|
||||
a01: 0x0000_0000,
|
||||
a02: 0xFFFF_FFFF,
|
||||
a03: 0x0000_0000)
|
||||
x0 = x0._mm_srli_si128(imm8: 8)
|
||||
x0 = x0._mm_xor_si128(b: x1)
|
||||
k = util.make_m128i_slice128(a: IEEE_X86_SSE42_K5ZZ[.. 16])
|
||||
x1 = x0._mm_srli_si128(imm8: 4)
|
||||
x0 = x0._mm_and_si128(b: x2)
|
||||
x0 = x0._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_xor_si128(b: x1)
|
||||
|
||||
// Reduce 64 bits to 32 bits (Barrett Reduction) and extract.
|
||||
//
|
||||
// Barrett Reduction is Algorithm 1 (page 14) of Gopal et al., after
|
||||
// adjusting for bit-reflection as per Figure 12 (page 21).
|
||||
k = util.make_m128i_slice128(a: IEEE_X86_SSE42_PXMU[.. 16])
|
||||
x1 = x0._mm_and_si128(b: x2)
|
||||
x1 = x1._mm_clmulepi64_si128(b: k, imm8: 0x10)
|
||||
x1 = x1._mm_and_si128(b: x2)
|
||||
x1 = x1._mm_clmulepi64_si128(b: k, imm8: 0x00)
|
||||
x0 = x0._mm_xor_si128(b: x1)
|
||||
s = x0._mm_extract_epi32(imm8: 1)
|
||||
|
||||
// Handle the tail of args.x that wasn't a complete 64-byte chunk.
|
||||
tail_index = args.x.length() & 0xFFFF_FFFF_FFFF_FFC0 // And-not 64.
|
||||
if tail_index < args.x.length() {
|
||||
iterate (p = args.x[tail_index ..])(length: 1, advance: 1, unroll: 1) {
|
||||
s = IEEE_TABLE[0][((s & 0xFF) as base.u8) ^ p[0]] ^ (s >> 8)
|
||||
}
|
||||
}
|
||||
|
||||
this.state = 0xFFFF_FFFF ^ s
|
||||
}
|
||||
@@ -70,6 +70,14 @@ pub struct decoder? implements base.io_transformer(
|
||||
bits : base.u32,
|
||||
n_bits : base.u32,
|
||||
|
||||
// transformed_history_count is the number of bytes written to the history
|
||||
// ringbuffer due to calling transform_io. It excludes any pre-history
|
||||
// written by explicit calls to add_history. It also excludes any bytes
|
||||
// decoded from the final transform_io call (the one that doesn't suspend)
|
||||
// as there is no further need for tracking history (for resolving back-
|
||||
// references) once the decoding completes.
|
||||
transformed_history_count : base.u64,
|
||||
|
||||
// history_index indexes the history array, defined below.
|
||||
history_index : base.u32,
|
||||
|
||||
@@ -203,12 +211,15 @@ pub func decoder.transform_io?(dst: base.io_writer, src: base.io_reader, workbuf
|
||||
var mark : base.u64
|
||||
var status : base.status
|
||||
|
||||
choose decode_huffman_fast64 = [decode_huffman_bmi2]
|
||||
|
||||
while true {
|
||||
mark = args.dst.mark()
|
||||
status =? this.decode_blocks?(dst: args.dst, src: args.src)
|
||||
if not status.is_suspension() {
|
||||
return status
|
||||
}
|
||||
this.transformed_history_count ~sat+= args.dst.count_since(mark: mark)
|
||||
// TODO: should "since" be "since!", as the return value lets you
|
||||
// modify the state of args.dst, so future mutations (via the slice)
|
||||
// can change the veracity of any args.dst assertions?
|
||||
|
||||
@@ -0,0 +1,306 @@
|
||||
// Copyright 2021 The Wuffs Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// decode_huffman_bmi2 is exactly the same as decode_huffman_fast64 except for
|
||||
// the "choose cpu_arch >= x86_bmi2". Unsurprisingly, having Bit Manipulation
|
||||
// Instructions available to the compiler can help this function's performance.
|
||||
pri func decoder.decode_huffman_bmi2!(dst: base.io_writer, src: base.io_reader) base.status,
|
||||
choose cpu_arch >= x86_bmi2,
|
||||
{
|
||||
// When editing this function, consider making the equivalent change to the
|
||||
// decode_huffman_slow function. Keep the diff between the two
|
||||
// decode_huffman_*.wuffs files as small as possible, while retaining both
|
||||
// correctness and performance.
|
||||
|
||||
var bits : base.u64
|
||||
var n_bits : base.u32
|
||||
var table_entry : base.u32
|
||||
var table_entry_n_bits : base.u32[..= 15]
|
||||
var lmask : base.u64[..= 511]
|
||||
var dmask : base.u64[..= 511]
|
||||
var redir_top : base.u32[..= 0xFFFF]
|
||||
var redir_mask : base.u32[..= 0x7FFF]
|
||||
var length : base.u32[..= 258]
|
||||
var dist_minus_1 : base.u32[..= 0x7FFF]
|
||||
var hlen : base.u32[..= 0x7FFF]
|
||||
var hdist : base.u32
|
||||
var hdist_adjustment : base.u32
|
||||
|
||||
if (this.n_bits >= 8) or ((this.bits >> (this.n_bits & 7)) <> 0) {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
|
||||
bits = this.bits as base.u64
|
||||
n_bits = this.n_bits
|
||||
|
||||
lmask = ((1 as base.u64) << this.n_huffs_bits[0]) - 1
|
||||
dmask = ((1 as base.u64) << this.n_huffs_bits[1]) - 1
|
||||
|
||||
if this.transformed_history_count < args.dst.history_position() {
|
||||
return base."#bad I/O position"
|
||||
}
|
||||
hdist_adjustment = ((this.transformed_history_count - args.dst.history_position()) & 0xFFFF_FFFF) as base.u32
|
||||
|
||||
// Check up front, on each iteration, that we have enough buffer space to
|
||||
// both read (8 bytes) and write (266 bytes) as much as we need to. Doing
|
||||
// this check once (per iteration), up front, removes the need to check
|
||||
// multiple times inside the loop body, so it's faster overall.
|
||||
//
|
||||
// For writing, a literal code obviously corresponds to writing 1 byte, and
|
||||
// 258 is the maximum length in a length-distance pair, as specified in the
|
||||
// RFC section 3.2.5. Compressed blocks (length and distance codes).
|
||||
//
|
||||
// We adjust 258 up to (258 + 8) = 266 since it can be faster to overshoot
|
||||
// a little and make multiple-of-8-byte copies even when the length in the
|
||||
// length-distance pair isn't an exact multiple-of-8. Strictly speaking,
|
||||
// 264 (an exact multiple-of-8) is the tight bound but (258 + 8) is easier
|
||||
// for the Wuffs proof system, as length's type is refined to [..= 258],
|
||||
//
|
||||
// For reading, strictly speaking, we only need 6 bytes (48 bits) of
|
||||
// available input, because the H-L Literal/Length code is up to 15 bits
|
||||
// plus up to 5 extra bits, the H-D Distance code is up to 15 bits plus up
|
||||
// to 13 extra bits and 15 + 5 + 15 + 13 == 48. However, it's faster to
|
||||
// read 64 bits than 48 bits or (48 - n_bits) bits.
|
||||
while.loop(args.dst.length() >= 266) and (args.src.length() >= 8) {
|
||||
// Ensure that we have at least 56 bits of input.
|
||||
//
|
||||
// This is "Variant 4" of
|
||||
// https://fgiesen.wordpress.com/2018/02/20/reading-bits-in-far-too-many-ways-part-2/
|
||||
//
|
||||
// 56, the number of bits in 7 bytes, is a property of that "Variant 4"
|
||||
// bit-reading technique, and not related to the DEFLATE format per se.
|
||||
//
|
||||
// The "& 63" is a no-op, and not part of the original "Variant 4"
|
||||
// technique, but satisfies Wuffs' overflow/underflow checks.
|
||||
bits |= args.src.peek_u64le() ~mod<< (n_bits & 63)
|
||||
args.src.skip_u32_fast!(actual: (63 - (n_bits & 63)) >> 3, worst_case: 8)
|
||||
n_bits |= 56
|
||||
|
||||
// Decode an lcode symbol from H-L.
|
||||
table_entry = this.huffs[0][bits & lmask]
|
||||
table_entry_n_bits = table_entry & 0x0F
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits ~mod-= table_entry_n_bits
|
||||
|
||||
if (table_entry >> 31) <> 0 {
|
||||
// Literal.
|
||||
args.dst.write_u8_fast!(a: ((table_entry >> 8) & 0xFF) as base.u8)
|
||||
continue.loop
|
||||
} else if (table_entry >> 30) <> 0 {
|
||||
// No-op; code continues past the if-else chain.
|
||||
} else if (table_entry >> 29) <> 0 {
|
||||
// End of block.
|
||||
this.end_of_block = true
|
||||
break.loop
|
||||
} else if (table_entry >> 28) <> 0 {
|
||||
// Redirect.
|
||||
redir_top = (table_entry >> 8) & 0xFFFF
|
||||
redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
|
||||
table_entry = this.huffs[0][
|
||||
(redir_top + (((bits & 0xFFFF_FFFF) as base.u32) & redir_mask)) & HUFFS_TABLE_MASK]
|
||||
table_entry_n_bits = table_entry & 0x0F
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits ~mod-= table_entry_n_bits
|
||||
|
||||
if (table_entry >> 31) <> 0 {
|
||||
// Literal.
|
||||
args.dst.write_u8_fast!(a: ((table_entry >> 8) & 0xFF) as base.u8)
|
||||
continue.loop
|
||||
} else if (table_entry >> 30) <> 0 {
|
||||
// No-op; code continues past the if-else chain.
|
||||
} else if (table_entry >> 29) <> 0 {
|
||||
// End of block.
|
||||
this.end_of_block = true
|
||||
break.loop
|
||||
} else if (table_entry >> 28) <> 0 {
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
} else if (table_entry >> 27) <> 0 {
|
||||
return "#bad Huffman code"
|
||||
} else {
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
} else if (table_entry >> 27) <> 0 {
|
||||
return "#bad Huffman code"
|
||||
} else {
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
// length = base_number_minus_3 + 3 + extra_bits.
|
||||
//
|
||||
// The -3 is from the bias in script/print-deflate-magic-numbers.go.
|
||||
// That bias makes the "& 0xFF" 1 and 15-ish lines below correct.
|
||||
length = ((table_entry >> 8) & 0xFF) + 3
|
||||
table_entry_n_bits = (table_entry >> 4) & 0x0F
|
||||
if table_entry_n_bits > 0 {
|
||||
// The "+ 253" is the same as "- 3", after the "& 0xFF", but the
|
||||
// plus form won't require an underflow check.
|
||||
length = ((length + 253 + (bits.low_bits(n: table_entry_n_bits) as base.u32)) & 0xFF) + 3
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits ~mod-= table_entry_n_bits
|
||||
}
|
||||
|
||||
// Decode a dcode symbol from H-D.
|
||||
table_entry = this.huffs[1][bits & dmask]
|
||||
table_entry_n_bits = table_entry & 15
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits ~mod-= table_entry_n_bits
|
||||
|
||||
// Check for a redirect.
|
||||
if (table_entry >> 28) == 1 {
|
||||
redir_top = (table_entry >> 8) & 0xFFFF
|
||||
redir_mask = ((1 as base.u32) << ((table_entry >> 4) & 0x0F)) - 1
|
||||
table_entry = this.huffs[1][
|
||||
(redir_top + (((bits & 0xFFFF_FFFF) as base.u32) & redir_mask)) & HUFFS_TABLE_MASK]
|
||||
table_entry_n_bits = table_entry & 0x0F
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits ~mod-= table_entry_n_bits
|
||||
}
|
||||
|
||||
// For H-D, all symbols should be base_number + extra_bits.
|
||||
if (table_entry >> 24) <> 0x40 {
|
||||
if (table_entry >> 24) == 0x08 {
|
||||
return "#bad Huffman code"
|
||||
}
|
||||
return "#internal error: inconsistent Huffman decoder state"
|
||||
}
|
||||
|
||||
// dist_minus_1 = base_number_minus_1 + extra_bits.
|
||||
// distance = dist_minus_1 + 1.
|
||||
//
|
||||
// The -1 is from the bias in script/print-deflate-magic-numbers.go.
|
||||
// That bias makes the "& 0x7FFF" 2 and 15-ish lines below correct and
|
||||
// undoing that bias makes proving (dist_minus_1 + 1) > 0 trivial.
|
||||
dist_minus_1 = (table_entry >> 8) & 0x7FFF
|
||||
table_entry_n_bits = (table_entry >> 4) & 0x0F
|
||||
|
||||
dist_minus_1 = (dist_minus_1 + (bits.low_bits(n: table_entry_n_bits) as base.u32)) & 0x7FFF
|
||||
bits >>= table_entry_n_bits
|
||||
n_bits ~mod-= table_entry_n_bits
|
||||
|
||||
// The "while true { etc; break }" is a redundant version of "etc", but
|
||||
// its presence minimizes the diff between decode_huffman_fastxx and
|
||||
// decode_huffman_slow.
|
||||
while true,
|
||||
pre args.dst.length() >= 266,
|
||||
{
|
||||
// We can therefore prove:
|
||||
assert (length as base.u64) <= args.dst.length() via "a <= b: a <= c; c <= b"(c: 266)
|
||||
assert ((length + 8) as base.u64) <= args.dst.length() via "a <= b: a <= c; c <= b"(c: 266)
|
||||
|
||||
// Copy from this.history.
|
||||
if ((dist_minus_1 + 1) as base.u64) > args.dst.history_length() {
|
||||
// Set (hlen, hdist) to be the length-distance pair to copy
|
||||
// from this.history, and (length, distance) to be the
|
||||
// remaining length-distance pair to copy from args.dst.
|
||||
hlen = 0
|
||||
hdist = (((dist_minus_1 + 1) as base.u64) - args.dst.history_length()) as base.u32
|
||||
if length > hdist {
|
||||
assert hdist < length via "a < b: b > a"()
|
||||
assert hdist < 0x8000 via "a < b: a < c; c <= b"(c: length)
|
||||
length -= hdist
|
||||
hlen = hdist
|
||||
} else {
|
||||
hlen = length
|
||||
length = 0
|
||||
}
|
||||
hdist ~mod+= hdist_adjustment
|
||||
if this.history_index < hdist {
|
||||
return "#bad distance"
|
||||
}
|
||||
// Re-purpose the hdist variable as the this.history index to
|
||||
// start copying from.
|
||||
hdist = this.history_index - hdist
|
||||
|
||||
// Copy from hdist to the end of this.history.
|
||||
//
|
||||
// This copying is simpler than the decode_huffman_slow version
|
||||
// because it cannot yield. We have already checked that
|
||||
// args.dst.length() is large enough.
|
||||
args.dst.limited_copy_u32_from_slice!(
|
||||
up_to: hlen, s: this.history[hdist & 0x7FFF ..])
|
||||
|
||||
if length == 0 {
|
||||
// No need to copy from args.dst.
|
||||
continue.loop
|
||||
}
|
||||
|
||||
if (((dist_minus_1 + 1) as base.u64) > args.dst.history_length()) or
|
||||
((length as base.u64) > args.dst.length()) or
|
||||
(((length + 8) as base.u64) > args.dst.length()) {
|
||||
return "#internal error: inconsistent distance"
|
||||
}
|
||||
}
|
||||
// Once again, redundant but explicit assertions.
|
||||
assert (dist_minus_1 + 1) >= 1
|
||||
assert ((dist_minus_1 + 1) as base.u64) <= args.dst.history_length()
|
||||
assert (length as base.u64) <= args.dst.length()
|
||||
assert ((length + 8) as base.u64) <= args.dst.length()
|
||||
|
||||
// Copy from args.dst.
|
||||
//
|
||||
// For short distances, less than 8 bytes, copying atomic 8-byte
|
||||
// chunks can result in incorrect output, so we fall back to a
|
||||
// slower 1-byte-at-a-time copy. Deflate's copy-from-history can
|
||||
// pick up freshly written bytes. A length = 5, distance = 2 copy
|
||||
// starting with "abc" should give "abcbcbcb" but the 8-byte chunk
|
||||
// technique would give "abcbc???", the exact output depending on
|
||||
// what was previously in the writer buffer.
|
||||
if (dist_minus_1 + 1) >= 8 {
|
||||
args.dst.limited_copy_u32_from_history_8_byte_chunks_fast!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
} else if (dist_minus_1 + 1) == 1 {
|
||||
// (distance == 1) is essentially RLE (Run Length Encoding). It
|
||||
// happens often enough that it's worth special-casing.
|
||||
args.dst.limited_copy_u32_from_history_8_byte_chunks_distance_1_fast!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
} else {
|
||||
args.dst.limited_copy_u32_from_history_fast!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
}
|
||||
break
|
||||
} endwhile
|
||||
} endwhile.loop
|
||||
|
||||
// Ensure n_bits < 8 by rewindng args.src, if we loaded too many of its
|
||||
// bytes into the bits variable.
|
||||
//
|
||||
// Note that we can unconditionally call undo_read (without resulting in an
|
||||
// "invalid I/O operation" error code) only because this whole function can
|
||||
// never suspend, as all of its I/O operations were checked beforehand for
|
||||
// sufficient buffer space. Otherwise, resuming from the suspension could
|
||||
// mean that the (possibly different) args.src is no longer rewindable,
|
||||
// even if conceptually, this function was responsible for reading the
|
||||
// bytes we want to rewind.
|
||||
if n_bits > 63 {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
while n_bits >= 8,
|
||||
post n_bits < 8,
|
||||
{
|
||||
n_bits -= 8
|
||||
if args.src.can_undo_byte() {
|
||||
args.src.undo_byte!()
|
||||
} else {
|
||||
return "#internal error: inconsistent I/O"
|
||||
}
|
||||
} endwhile
|
||||
|
||||
this.bits = (bits & (((1 as base.u64) << n_bits) - 1)) as base.u32
|
||||
this.n_bits = n_bits
|
||||
|
||||
if (this.n_bits >= 8) or ((this.bits >> this.n_bits) <> 0) {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
var dist_minus_1 : base.u32[..= 0x7FFF]
|
||||
var hlen : base.u32[..= 0x7FFF]
|
||||
var hdist : base.u32
|
||||
var hdist_adjustment : base.u32
|
||||
|
||||
if (this.n_bits >= 8) or ((this.bits >> (this.n_bits & 7)) <> 0) {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
@@ -43,6 +44,11 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
lmask = ((1 as base.u32) << this.n_huffs_bits[0]) - 1
|
||||
dmask = ((1 as base.u32) << this.n_huffs_bits[1]) - 1
|
||||
|
||||
if this.transformed_history_count < args.dst.history_position() {
|
||||
return base."#bad I/O position"
|
||||
}
|
||||
hdist_adjustment = ((this.transformed_history_count - args.dst.history_position()) & 0xFFFF_FFFF) as base.u32
|
||||
|
||||
// Check up front, on each iteration, that we have enough buffer space to
|
||||
// both read (12 bytes) and write (266 bytes) as much as we need to. Doing
|
||||
// this check once (per iteration), up front, removes the need to check
|
||||
@@ -314,6 +320,7 @@ pri func decoder.decode_huffman_fast32!(dst: base.io_writer, src: base.io_reader
|
||||
hlen = length
|
||||
length = 0
|
||||
}
|
||||
hdist ~mod+= hdist_adjustment
|
||||
if this.history_index < hdist {
|
||||
return "#bad distance"
|
||||
}
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
// TODO: describe how the xxx_fastxx version differs from the xxx_slow one, the
|
||||
// assumptions that xxx_fastxx makes, and how that makes it fast.
|
||||
pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader) base.status {
|
||||
pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader) base.status,
|
||||
choosy,
|
||||
{
|
||||
// When editing this function, consider making the equivalent change to the
|
||||
// decode_huffman_slow function. Keep the diff between the two
|
||||
// decode_huffman_*.wuffs files as small as possible, while retaining both
|
||||
@@ -32,6 +34,7 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
var dist_minus_1 : base.u32[..= 0x7FFF]
|
||||
var hlen : base.u32[..= 0x7FFF]
|
||||
var hdist : base.u32
|
||||
var hdist_adjustment : base.u32
|
||||
|
||||
if (this.n_bits >= 8) or ((this.bits >> (this.n_bits & 7)) <> 0) {
|
||||
return "#internal error: inconsistent n_bits"
|
||||
@@ -43,6 +46,11 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
lmask = ((1 as base.u64) << this.n_huffs_bits[0]) - 1
|
||||
dmask = ((1 as base.u64) << this.n_huffs_bits[1]) - 1
|
||||
|
||||
if this.transformed_history_count < args.dst.history_position() {
|
||||
return base."#bad I/O position"
|
||||
}
|
||||
hdist_adjustment = ((this.transformed_history_count - args.dst.history_position()) & 0xFFFF_FFFF) as base.u32
|
||||
|
||||
// Check up front, on each iteration, that we have enough buffer space to
|
||||
// both read (8 bytes) and write (266 bytes) as much as we need to. Doing
|
||||
// this check once (per iteration), up front, removes the need to check
|
||||
@@ -206,6 +214,7 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
hlen = length
|
||||
length = 0
|
||||
}
|
||||
hdist ~mod+= hdist_adjustment
|
||||
if this.history_index < hdist {
|
||||
return "#bad distance"
|
||||
}
|
||||
@@ -250,6 +259,11 @@ pri func decoder.decode_huffman_fast64!(dst: base.io_writer, src: base.io_reader
|
||||
if (dist_minus_1 + 1) >= 8 {
|
||||
args.dst.limited_copy_u32_from_history_8_byte_chunks_fast!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
} else if (dist_minus_1 + 1) == 1 {
|
||||
// (distance == 1) is essentially RLE (Run Length Encoding). It
|
||||
// happens often enough that it's worth special-casing.
|
||||
args.dst.limited_copy_u32_from_history_8_byte_chunks_distance_1_fast!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
} else {
|
||||
args.dst.limited_copy_u32_from_history_fast!(
|
||||
up_to: length, distance: (dist_minus_1 + 1))
|
||||
|
||||
@@ -217,6 +217,7 @@ pri func decoder.decode_huffman_slow?(dst: base.io_writer, src: base.io_reader)
|
||||
hlen = length
|
||||
length = 0
|
||||
}
|
||||
hdist ~mod+= ((this.transformed_history_count ~mod- args.dst.history_position()) & 0xFFFF_FFFF) as base.u32
|
||||
if this.history_index < hdist {
|
||||
return "#bad distance"
|
||||
}
|
||||
|
||||
@@ -929,7 +929,7 @@ pri func decoder.decode_id_part2?(dst: ptr base.pixel_buffer, src: base.io_reade
|
||||
if (this.compressed_ri > this.compressed_wi) or (this.compressed_wi > 4096) {
|
||||
return "#internal error: inconsistent ri/wi"
|
||||
}
|
||||
io_bind (io: r, data: this.compressed[this.compressed_ri .. this.compressed_wi]) {
|
||||
io_bind (io: r, data: this.compressed[this.compressed_ri .. this.compressed_wi], history_position: 0) {
|
||||
mark = r.mark()
|
||||
lzw_status =? this.lzw.transform_io?(
|
||||
dst: this.util.empty_io_writer(), src: r, workbuf: this.util.empty_slice_u8())
|
||||
|
||||
@@ -1530,7 +1530,16 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
pre args.dst.length() > 0,
|
||||
{
|
||||
if args.src.length() <= 0 {
|
||||
if length > 0 {
|
||||
if args.src.is_closed() {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
base.TOKEN__VBD__FILLER__COMMENT_LINE,
|
||||
continued: 0,
|
||||
length: length)
|
||||
this.comment_type = 2
|
||||
return ok
|
||||
} else if length > 0 {
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
@@ -1538,9 +1547,6 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
continued: 1,
|
||||
length: length)
|
||||
}
|
||||
if args.src.is_closed() {
|
||||
return "#bad input"
|
||||
}
|
||||
yield? base."$short read"
|
||||
length = 0
|
||||
continue.comment_line
|
||||
@@ -1548,13 +1554,12 @@ pri func decoder.decode_comment?(dst: base.token_writer, src: base.io_reader) {
|
||||
|
||||
c = args.src.peek_u8()
|
||||
if c == '\n' {
|
||||
args.src.skip_u32_fast!(actual: 1, worst_case: 1)
|
||||
args.dst.write_simple_token_fast!(
|
||||
value_major: 0,
|
||||
value_minor: (base.TOKEN__VBC__FILLER << 21) |
|
||||
base.TOKEN__VBD__FILLER__COMMENT_LINE,
|
||||
continued: 0,
|
||||
length: length + 1)
|
||||
length: length)
|
||||
this.comment_type = 2
|
||||
return ok
|
||||
}
|
||||
|
||||
@@ -109,15 +109,17 @@ pub const QUIRK_ALLOW_COMMENT_BLOCK : base.u32 = 0x4909_9400 | 0x0B
|
||||
// When this quirk is enabled, "// C/C++ style line comments\n" are accepted
|
||||
// anywhere whitespace would be. See also QUIRK_ALLOW_TRAILING_FILLER.
|
||||
//
|
||||
// A line comment may not omit the ending "\n", even if there is no input
|
||||
// afterwards (i.e. the prospective line comment ends with the end-of-file).
|
||||
// Line comments are terminated by a '\n' byte. '\r' bytes are irrelevant. When
|
||||
// combined with QUIRK_ALLOW_TRAILING_FILLER, a line comment at the end of the
|
||||
// file may omit the final '\n' byte.
|
||||
//
|
||||
// They produce WUFFS_BASE__TOKEN__VBD__FILLER__COMMENT_LINE tokens. The token
|
||||
// chain's source bytes includes the starting "//" and the ending "\n".
|
||||
// chain's source bytes includes the starting "//" but always excludes the
|
||||
// ending "\n", regardless of whether it met the end of the file instead.
|
||||
//
|
||||
// Even if the line comments are on consecutive lines, each line comment is a
|
||||
// separate token chain. There may be whitespace tokens between one line
|
||||
// comment's ending "\n" and the next one's starting "//".
|
||||
// separate token chain. Between them is at least one "\n" and maybe other
|
||||
// whitespace, which are not part of a line comment token chain.
|
||||
//
|
||||
// To avoid ambiguity (as comments can contain new lines), this quirk cannot be
|
||||
// combined with QUIRK_EXPECT_TRAILING_NEW_LINE_OR_EOF.
|
||||
|
||||
@@ -219,7 +219,7 @@ pri func decoder.decode_ihdr?(src: base.io_reader) {
|
||||
var a8 : base.u8
|
||||
|
||||
a32 = args.src.read_u32be?()
|
||||
if a32 >= 0x8000_0000 {
|
||||
if (a32 == 0) or (a32 >= 0x8000_0000) {
|
||||
return "#bad header"
|
||||
} else if a32 >= 0x0100_0000 {
|
||||
return "#unsupported PNG file"
|
||||
@@ -227,7 +227,7 @@ pri func decoder.decode_ihdr?(src: base.io_reader) {
|
||||
this.width = a32
|
||||
|
||||
a32 = args.src.read_u32be?()
|
||||
if a32 >= 0x8000_0000 {
|
||||
if (a32 == 0) or (a32 >= 0x8000_0000) {
|
||||
return "#bad header"
|
||||
} else if a32 >= 0x0100_0000 {
|
||||
return "#unsupported PNG file"
|
||||
@@ -303,7 +303,7 @@ pri func decoder.assign_filter_distance!() {
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__Y
|
||||
this.filter_distance = 1
|
||||
} else if this.depth == 16 {
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__Y // TODO: PIXEL_FORMAT__Y_16LE
|
||||
this.dst_pixfmt = base.PIXEL_FORMAT__Y_16LE
|
||||
this.src_pixfmt = base.PIXEL_FORMAT__Y_16BE
|
||||
this.filter_distance = 2
|
||||
}
|
||||
@@ -574,7 +574,7 @@ pri func decoder.decode_pass?(src: base.io_reader, workbuf: slice base.u8) {
|
||||
this.pass_workbuf_length > args.workbuf.length()) {
|
||||
return base."#bad workbuf length"
|
||||
}
|
||||
io_bind (io: w, data: args.workbuf[this.workbuf_wi .. this.pass_workbuf_length]) {
|
||||
io_bind (io: w, data: args.workbuf[this.workbuf_wi .. this.pass_workbuf_length], history_position: this.workbuf_wi) {
|
||||
io_limit (io: args.src, limit: this.chunk_length) {
|
||||
w_mark = w.mark()
|
||||
r_mark = args.src.mark()
|
||||
|
||||
@@ -14,12 +14,171 @@
|
||||
|
||||
// ----------------
|
||||
|
||||
// Uncomment this line to test and bench miniz instead of zlib-the-library.
|
||||
// Uncomment one of these #define lines to test and bench alternative mimic
|
||||
// libraries (libdeflate or miniz) instead of zlib-the-library.
|
||||
//
|
||||
// These are collectively referred to as
|
||||
// WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_ZLIB.
|
||||
//
|
||||
// #define WUFFS_MIMICLIB_USE_LIBDEFLATE_INSTEAD_OF_ZLIB 1
|
||||
// #define WUFFS_MIMICLIB_USE_MINIZ_INSTEAD_OF_ZLIB 1
|
||||
|
||||
#ifdef WUFFS_MIMICLIB_USE_MINIZ_INSTEAD_OF_ZLIB
|
||||
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_ZLIB
|
||||
#if defined(WUFFS_MIMICLIB_USE_LIBDEFLATE_INSTEAD_OF_ZLIB)
|
||||
#include "libdeflate.h"
|
||||
|
||||
#define WUFFS_MIMICLIB_DEFLATE_DOES_NOT_SUPPORT_STREAMING 1
|
||||
|
||||
#define WUFFS_MIMICLIB_ZLIB_DOES_NOT_SUPPORT_DICTIONARIES 1
|
||||
|
||||
uint32_t global_mimiclib_deflate_unused_u32;
|
||||
|
||||
typedef enum libdeflate_result (*libdeflate_decompress_func)(
|
||||
struct libdeflate_decompressor* decompressor,
|
||||
const void* in,
|
||||
size_t in_nbytes,
|
||||
void* out,
|
||||
size_t out_nbytes_avail,
|
||||
size_t* actual_in_nbytes_ret,
|
||||
size_t* actual_out_nbytes_ret);
|
||||
|
||||
const char* //
|
||||
libdeflate_result_as_const_char_star(enum libdeflate_result r) {
|
||||
switch (r) {
|
||||
case LIBDEFLATE_SUCCESS:
|
||||
return NULL;
|
||||
case LIBDEFLATE_BAD_DATA:
|
||||
return "libdeflate: bad data";
|
||||
case LIBDEFLATE_SHORT_OUTPUT:
|
||||
return "libdeflate: short output";
|
||||
case LIBDEFLATE_INSUFFICIENT_SPACE:
|
||||
return "libdeflate: insufficient space";
|
||||
}
|
||||
return "libdeflate: unknown error";
|
||||
}
|
||||
|
||||
const char* //
|
||||
mimic_bench_adler32(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
global_mimiclib_deflate_unused_u32 = 1;
|
||||
while (src->meta.ri < src->meta.wi) {
|
||||
uint8_t* ptr = src->data.ptr + src->meta.ri;
|
||||
size_t len = src->meta.wi - src->meta.ri;
|
||||
if (len > 0x7FFFFFFF) {
|
||||
return "src length is too large";
|
||||
} else if (len > rlimit) {
|
||||
len = rlimit;
|
||||
}
|
||||
global_mimiclib_deflate_unused_u32 =
|
||||
libdeflate_adler32(global_mimiclib_deflate_unused_u32, ptr, len);
|
||||
src->meta.ri += len;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
mimic_bench_crc32_ieee(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
global_mimiclib_deflate_unused_u32 = 0;
|
||||
while (src->meta.ri < src->meta.wi) {
|
||||
uint8_t* ptr = src->data.ptr + src->meta.ri;
|
||||
size_t len = src->meta.wi - src->meta.ri;
|
||||
if (len > 0x7FFFFFFF) {
|
||||
return "src length is too large";
|
||||
} else if (len > rlimit) {
|
||||
len = rlimit;
|
||||
}
|
||||
global_mimiclib_deflate_unused_u32 =
|
||||
libdeflate_crc32(global_mimiclib_deflate_unused_u32, ptr, len);
|
||||
src->meta.ri += len;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
mimic_deflate_gzip_zlib_decode(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit,
|
||||
libdeflate_decompress_func func) {
|
||||
struct libdeflate_decompressor* dec = libdeflate_alloc_decompressor();
|
||||
if (!dec) {
|
||||
return "libdeflate: alloc failed";
|
||||
}
|
||||
size_t n_dst = 0;
|
||||
size_t n_src = 0;
|
||||
enum libdeflate_result res =
|
||||
(*func)(dec, wuffs_base__io_buffer__reader_pointer(src),
|
||||
((size_t)wuffs_base__u64__min(
|
||||
rlimit, wuffs_base__io_buffer__reader_length(src))),
|
||||
wuffs_base__io_buffer__writer_pointer(dst),
|
||||
((size_t)wuffs_base__u64__min(
|
||||
wlimit, wuffs_base__io_buffer__writer_length(dst))),
|
||||
&n_src, &n_dst);
|
||||
if (res == LIBDEFLATE_SUCCESS) {
|
||||
dst->meta.wi += n_dst;
|
||||
src->meta.ri += n_src;
|
||||
}
|
||||
libdeflate_free_decompressor(dec);
|
||||
return libdeflate_result_as_const_char_star(res);
|
||||
}
|
||||
|
||||
const char* //
|
||||
mimic_deflate_decode(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
return mimic_deflate_gzip_zlib_decode(dst, src, wuffs_initialize_flags,
|
||||
wlimit, rlimit,
|
||||
&libdeflate_deflate_decompress_ex);
|
||||
}
|
||||
|
||||
const char* //
|
||||
mimic_gzip_decode(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
return mimic_deflate_gzip_zlib_decode(dst, src, wuffs_initialize_flags,
|
||||
wlimit, rlimit,
|
||||
&libdeflate_gzip_decompress_ex);
|
||||
}
|
||||
|
||||
const char* //
|
||||
mimic_zlib_decode(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
uint32_t wuffs_initialize_flags,
|
||||
uint64_t wlimit,
|
||||
uint64_t rlimit) {
|
||||
return mimic_deflate_gzip_zlib_decode(dst, src, wuffs_initialize_flags,
|
||||
wlimit, rlimit,
|
||||
&libdeflate_zlib_decompress_ex);
|
||||
}
|
||||
|
||||
const char* //
|
||||
mimic_zlib_decode_with_dictionary(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
wuffs_base__slice_u8 dictionary) {
|
||||
return "libdeflate does not implement zlib dictionaries";
|
||||
}
|
||||
|
||||
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_ZLIB
|
||||
#elif defined(WUFFS_MIMICLIB_USE_MINIZ_INSTEAD_OF_ZLIB)
|
||||
#include "/path/to/your/copy/of/github.com/richgel999/miniz/miniz_tinfl.c"
|
||||
|
||||
// We deliberately do not define the
|
||||
// WUFFS_MIMICLIB_DEFLATE_DOES_NOT_SUPPORT_STREAMING macro.
|
||||
|
||||
#define WUFFS_MIMICLIB_ZLIB_DOES_NOT_SUPPORT_DICTIONARIES 1
|
||||
|
||||
const char* //
|
||||
mimic_bench_adler32(wuffs_base__io_buffer* dst,
|
||||
wuffs_base__io_buffer* src,
|
||||
@@ -101,9 +260,16 @@ mimic_zlib_decode_with_dictionary(wuffs_base__io_buffer* dst,
|
||||
return "miniz does not implement zlib dictionaries";
|
||||
}
|
||||
|
||||
#else // WUFFS_MIMICLIB_USE_MINIZ_INSTEAD_OF_ZLIB
|
||||
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_ZLIB
|
||||
#else
|
||||
#include "zlib.h"
|
||||
|
||||
// We deliberately do not define the
|
||||
// WUFFS_MIMICLIB_DEFLATE_DOES_NOT_SUPPORT_STREAMING macro.
|
||||
|
||||
// We deliberately do not define the
|
||||
// WUFFS_MIMICLIB_ZLIB_DOES_NOT_SUPPORT_DICTIONARIES macro.
|
||||
|
||||
uint32_t global_mimiclib_deflate_unused_u32;
|
||||
|
||||
const char* //
|
||||
@@ -299,4 +465,5 @@ mimic_zlib_decode_with_dictionary(wuffs_base__io_buffer* dst,
|
||||
UINT64_MAX, zlib_flavor_zlib);
|
||||
}
|
||||
|
||||
#endif // WUFFS_MIMICLIB_USE_MINIZ_INSTEAD_OF_ZLIB
|
||||
#endif
|
||||
// -------------------------------- WUFFS_MIMICLIB_USE_XXX_INSTEAD_OF_ZLIB
|
||||
@@ -37,7 +37,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC -lz
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC -ldeflate -lz
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC -lz
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC -ldeflate -lz
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
|
||||
@@ -37,7 +37,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC -lz
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC -ldeflate -lz
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
@@ -749,10 +749,9 @@ test_mimic_deflate_decode_deflate_distance_code_31() {
|
||||
const char* have = do_test_io_buffers(mimic_deflate_decode,
|
||||
&g_deflate_deflate_distance_code_31_gt,
|
||||
UINT64_MAX, UINT64_MAX);
|
||||
const char* want = "inflate failed (data error)";
|
||||
if ((have != want) &&
|
||||
((have == NULL) || (want == NULL) || strcmp(have, want))) {
|
||||
RETURN_FAIL("have \"%s\", want \"%s\"", have, want);
|
||||
if (!strings_are_equal(have, "inflate failed (data error)") &&
|
||||
!strings_are_equal(have, "libdeflate: bad data")) {
|
||||
RETURN_FAIL("have \"%s\", want \"bad data\" or similar", have);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -924,7 +923,9 @@ proc g_tests[] = {
|
||||
test_mimic_deflate_decode_deflate_huffman_primlen_9,
|
||||
test_mimic_deflate_decode_midsummer,
|
||||
test_mimic_deflate_decode_pi_just_one_read,
|
||||
#ifndef WUFFS_MIMICLIB_DEFLATE_DOES_NOT_SUPPORT_STREAMING
|
||||
test_mimic_deflate_decode_pi_many_big_reads,
|
||||
#endif
|
||||
test_mimic_deflate_decode_romeo,
|
||||
test_mimic_deflate_decode_romeo_fixed,
|
||||
|
||||
@@ -947,7 +948,9 @@ proc g_benches[] = {
|
||||
bench_mimic_deflate_decode_1k_full_init,
|
||||
bench_mimic_deflate_decode_10k_full_init,
|
||||
bench_mimic_deflate_decode_100k_just_one_read,
|
||||
#ifndef WUFFS_MIMICLIB_DEFLATE_DOES_NOT_SUPPORT_STREAMING
|
||||
bench_mimic_deflate_decode_100k_many_big_reads,
|
||||
#endif
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
|
||||
+61
-1
@@ -37,7 +37,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC -lz
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC -ldeflate -lz
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
@@ -216,6 +216,65 @@ test_wuffs_gzip_checksum_verify_good() {
|
||||
return do_test_wuffs_gzip_checksum(false, 0);
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_gzip_decode_infrequent_compaction() {
|
||||
CHECK_FOCUS(__func__);
|
||||
|
||||
wuffs_gzip__decoder dec;
|
||||
CHECK_STATUS("initialize",
|
||||
wuffs_gzip__decoder__initialize(
|
||||
&dec, sizeof dec, WUFFS_VERSION,
|
||||
WUFFS_INITIALIZE__LEAVE_INTERNAL_BUFFERS_UNINITIALIZED));
|
||||
|
||||
wuffs_base__io_buffer dst = ((wuffs_base__io_buffer){
|
||||
.data = g_have_slice_u8,
|
||||
});
|
||||
|
||||
// src_bytes holds the first 50 Fibonacci numbers, gzipped using Python's
|
||||
// gzip module.
|
||||
uint8_t src_bytes[183] = {
|
||||
0x1F, 0x8B, 0x08, 0x00, 0x07, 0x22, 0x16, 0x61, 0x02, 0xFF, 0x15, 0x8F,
|
||||
0xC1, 0x11, 0x00, 0x31, 0x08, 0x02, 0xFF, 0x54, 0x23, 0x6A, 0x44, 0xFB,
|
||||
0x6F, 0xEC, 0xB8, 0xC9, 0xCB, 0x59, 0x09, 0x6B, 0x80, 0x7E, 0x89, 0xC2,
|
||||
0xC3, 0x82, 0x85, 0x24, 0xAA, 0xF1, 0x3C, 0x1D, 0xD8, 0x8D, 0xAC, 0x42,
|
||||
0x49, 0x18, 0x06, 0x6E, 0x05, 0xBE, 0x13, 0xF2, 0x6D, 0xA3, 0xB9, 0xC4,
|
||||
0x68, 0x1E, 0x18, 0xD7, 0x03, 0x4A, 0xF4, 0x57, 0x3B, 0x4F, 0xE8, 0xA9,
|
||||
0x59, 0xE8, 0x45, 0x9A, 0x26, 0xEB, 0x0A, 0xBC, 0x71, 0x02, 0x45, 0xAD,
|
||||
0xD7, 0x1E, 0x3B, 0xF3, 0xB0, 0x95, 0xD1, 0xE1, 0xDE, 0x9E, 0x9C, 0x73,
|
||||
0xB9, 0xB6, 0xE2, 0x50, 0x2F, 0xFB, 0x69, 0xF1, 0x14, 0xB9, 0x2E, 0xBD,
|
||||
0x4C, 0xF5, 0x5F, 0xD4, 0x57, 0x61, 0x88, 0x6C, 0x9A, 0x53, 0xA8, 0x8B,
|
||||
0x5D, 0x3A, 0x3A, 0xE5, 0xC8, 0xAD, 0x35, 0xC2, 0xCA, 0xC6, 0xDE, 0x9E,
|
||||
0xF7, 0x36, 0xD8, 0x96, 0x1A, 0x9D, 0x0B, 0x6F, 0xD0, 0x66, 0xD7, 0x5D,
|
||||
0x82, 0x4C, 0x62, 0xE5, 0xF3, 0xE8, 0xFA, 0x0B, 0x8B, 0x59, 0x64, 0x6B,
|
||||
0x8A, 0xF4, 0x84, 0x3C, 0xD9, 0xFC, 0x85, 0x0A, 0xBD, 0xA1, 0x67, 0x3F,
|
||||
0x0D, 0x24, 0xAD, 0xDA, 0xD2, 0x87, 0x0F, 0x12, 0x69, 0x4A, 0xA8, 0x3B,
|
||||
0x01, 0x00, 0x00,
|
||||
};
|
||||
wuffs_base__io_buffer src =
|
||||
wuffs_base__ptr_u8__reader(src_bytes, sizeof src_bytes, true);
|
||||
|
||||
// Decode 5 source bytes at a time. Compact every 15 source bytes.
|
||||
for (size_t i = 0; i < src.data.len; i += 5) {
|
||||
src.meta.wi = i;
|
||||
wuffs_base__status status =
|
||||
wuffs_gzip__decoder__transform_io(&dec, &dst, &src, g_work_slice_u8);
|
||||
if (status.repr != wuffs_base__suspension__short_read) {
|
||||
RETURN_FAIL("i=%zu: have \"%s\", want \"%s\"", i, status.repr,
|
||||
wuffs_base__suspension__short_read);
|
||||
}
|
||||
if (i % 15 == 0) {
|
||||
dst.meta.ri = dst.meta.wi;
|
||||
wuffs_base__io_buffer__compact(&dst);
|
||||
}
|
||||
}
|
||||
|
||||
src.meta.wi = src.data.len;
|
||||
src.meta.closed = true;
|
||||
CHECK_STATUS("final transform_io", wuffs_gzip__decoder__transform_io(
|
||||
&dec, &dst, &src, g_work_slice_u8));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* //
|
||||
test_wuffs_gzip_decode_midsummer() {
|
||||
CHECK_FOCUS(__func__);
|
||||
@@ -299,6 +358,7 @@ proc g_tests[] = {
|
||||
test_wuffs_gzip_checksum_verify_bad0,
|
||||
test_wuffs_gzip_checksum_verify_bad7,
|
||||
test_wuffs_gzip_checksum_verify_good,
|
||||
test_wuffs_gzip_decode_infrequent_compaction,
|
||||
test_wuffs_gzip_decode_interface,
|
||||
test_wuffs_gzip_decode_midsummer,
|
||||
test_wuffs_gzip_decode_pi,
|
||||
|
||||
+15
-5
@@ -3427,6 +3427,14 @@ test_wuffs_json_decode_quirk_allow_trailing_comments() {
|
||||
// - '4' means that there is non-filler after eof-or-'\n'
|
||||
// - '5' means that there is non-filler before eof-or-'\n'
|
||||
//
|
||||
// The second and third bytes are digits such that the overall string starts
|
||||
// with a three digit number, which is parsed as the top-level JSON value and
|
||||
// everything afterwards is trailer.
|
||||
//
|
||||
// That three digit number modulo 100 also acts as a 'line number' (matching
|
||||
// the tc loop variable), starting counting from zero, so that the 6th test
|
||||
// case, tc == 5, is the line starting with "something hundred and five".
|
||||
//
|
||||
// WUFFS_JSON__QUIRK_ALLOW_TRAILING_FILLER (together with
|
||||
// WUFFS_JSON__QUIRK_ALLOW_COMMENT_ETC) should decode the '1's, '2's and '3's
|
||||
// completely and the '4's and '5's up to but excluding the non-filler.
|
||||
@@ -3443,11 +3451,13 @@ test_wuffs_json_decode_quirk_allow_trailing_comments() {
|
||||
"306 /*foo*/ \n", //
|
||||
"307 /*foo*/ \n\n", //
|
||||
"308/*bar\nbaz*/\n\n", //
|
||||
"309 // qux\n\n", //
|
||||
"310 /*c0*/ /*c1*/\n\n", //
|
||||
"311 /*c0*/ \n\n // c2 \n\n", //
|
||||
"412 \n9", //
|
||||
"513 9", //
|
||||
"309 // qux", //
|
||||
"310 // qux\n", //
|
||||
"311 // qux\n\n", //
|
||||
"312 /*c0*/ /*c1*/\n\n", //
|
||||
"313 /*c0*/ \n\n // c2 \n\n", //
|
||||
"414 \n9", //
|
||||
"515 9", //
|
||||
};
|
||||
|
||||
int tc;
|
||||
|
||||
+3
-1
@@ -37,7 +37,7 @@ the first "./a.out" with "./a.out -bench". Combine these changes with the
|
||||
"wuffs mimic cflags" to run the mimic benchmarks.
|
||||
*/
|
||||
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC -lz
|
||||
// ¿ wuffs mimic cflags: -DWUFFS_MIMIC -ldeflate -lz
|
||||
|
||||
// Wuffs ships as a "single file C library" or "header file library" as per
|
||||
// https://github.com/nothings/stb/blob/master/docs/stb_howto.txt
|
||||
@@ -384,7 +384,9 @@ proc g_tests[] = {
|
||||
|
||||
test_mimic_zlib_decode_midsummer,
|
||||
test_mimic_zlib_decode_pi,
|
||||
#ifndef WUFFS_MIMICLIB_ZLIB_DOES_NOT_SUPPORT_DICTIONARIES
|
||||
test_mimic_zlib_decode_sheep,
|
||||
#endif
|
||||
|
||||
#endif // WUFFS_MIMIC
|
||||
|
||||
|
||||
@@ -671,7 +671,7 @@ read_file(wuffs_base__io_buffer* dst, const char* path) {
|
||||
original_path);
|
||||
}
|
||||
|
||||
FILE* f = fopen(path, "r");
|
||||
FILE* f = fopen(path, "rb");
|
||||
if (!f) {
|
||||
RETURN_FAIL("read_file(\"%s\"): %s (errno=%d)", path, strerror(errno),
|
||||
errno);
|
||||
@@ -819,6 +819,16 @@ check_io_buffers_equal(const char* prefix,
|
||||
return g_fail_msg;
|
||||
}
|
||||
|
||||
bool //
|
||||
strings_are_equal(const char* s, const char* t) {
|
||||
if (s == t) {
|
||||
return true;
|
||||
} else if ((s == NULL) || (t == NULL)) {
|
||||
return false;
|
||||
}
|
||||
return strcmp(s, t) == 0;
|
||||
}
|
||||
|
||||
// throughput_counter is whether to count dst or src bytes, or neither, when
|
||||
// calculating a benchmark's MB/s throughput number.
|
||||
//
|
||||
|
||||
@@ -24,6 +24,12 @@ world examples of various file formats, or deriviations of them.
|
||||
|
||||
---
|
||||
|
||||
The non-ascii directory holds trivial UTF-8 (but not ASCII) text files.
|
||||
|
||||
---
|
||||
|
||||
`archive.*` archives a subset of other files in this directory.
|
||||
|
||||
`animated-red-blue.gif` is an original animation by Nigel Tao
|
||||
<nigeltao@golang.org>.
|
||||
|
||||
@@ -60,6 +66,8 @@ Museum of art.
|
||||
[www.metmuseum.org](http://www.metmuseum.org/art/collection/search/436532)
|
||||
lists that image as in the public domain.
|
||||
|
||||
`hello.sh` is a trivial shell script.
|
||||
|
||||
`hibiscus.regular.*` are various encodings of a photo of "Hibiscus and Parrots"
|
||||
by Louis Comfort Tiffany, held by the Metropolitan Museum of Art.
|
||||
[www.metmuseum.org](http://www.metmuseum.org/art/collection/search/13503) lists
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash -eu
|
||||
# Copyright 2021 The Wuffs Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# ----------------
|
||||
|
||||
# This file should have the "executable" Unix permission bit.
|
||||
|
||||
echo hello
|
||||
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
α U+03B1 GREEK SMALL LETTER ALPHA. UTF-8: [C3 B1].
|
||||
β U+03B2 GREEK SMALL LETTER BETA. UTF-8: [C3 B2].
|
||||
@@ -0,0 +1,3 @@
|
||||
😻 U+1F63B SMILING CAT FACE WITH HEART-SHAPED EYES. UTF-8: [F0 9F 98 BB].
|
||||
|
||||
This code point is outside of the Unicode BMP (Basic Multilingual Plane).
|
||||
Binary file not shown.
Reference in new issue
Block a user