/* unescape_html in C with Wasm SIMD: decodes every HTML character reference in * UTF-8 text the way Python's html.unescape does, and copies all other bytes * unchanged. A C port of the repo's Zig implementation (same layout, same * range-coded entity list, same two-stage SIMD render loop), compiled with * zig cc -O3 to compare LLVM codegen against Zig's own wasm backend. * * Memory is 5 pages. One buffer: the output is written from its start and the * input sits IN_OFF bytes in; before the first render the buffer's start is the * range coder's working memory (model, squash, stretch, hist). */ #include #include #include typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; typedef int32_t i32; typedef int16_t i16; #define EXPORT(name) __attribute__((export_name(#name))) static const unsigned char packed_list[6699] = { 222,225,76,127,180,18,170,54,193,110,91,248,93,113,69,179,239,54,43,111,203,206,237,70, 76,133,106,113,86,208,4,143,50,11,77,134,144,94,70,141,120,113,243,229,192,238,161,251, 123,238,10,65,68,73,4,7,224,3,94,225,107,13,36,186,230,234,35,205,158,90,193,42, 160,246,118,232,66,83,107,223,176,186,194,55,247,169,239,169,125,224,237,2,141,189,171,103, 108,141,120,224,7,153,245,108,129,248,80,238,208,72,44,235,208,74,82,77,51,15,226,255, 155,252,118,42,188,217,41,19,156,136,127,67,215,248,149,166,133,198,216,145,130,152,92,65, 114,18,87,41,95,33,159,163,211,124,148,114,115,121,26,31,200,219,94,241,128,46,57,189, 117,227,113,28,5,255,61,46,63,201,188,62,26,137,48,236,162,205,234,155,106,82,22,226, 176,0,81,27,190,65,118,1,15,80,34,231,133,38,21,36,21,243,4,28,253,27,209,84, 73,128,86,69,196,165,205,121,162,11,229,73,40,3,17,134,176,14,179,71,236,191,147,146, 157,189,163,252,10,190,14,191,14,26,172,179,237,4,8,21,133,41,196,99,236,89,67,255, 213,218,79,163,25,195,128,3,231,17,182,111,16,42,178,135,39,200,150,137,106,56,171,44, 137,87,47,75,29,79,239,114,127,131,29,68,136,185,67,193,1,62,201,136,188,192,67,16, 65,88,24,102,49,177,157,200,98,95,203,96,11,252,85,177,51,210,212,238,178,116,159,200, 13,67,175,98,91,248,202,48,19,24,116,126,117,222,250,51,31,54,113,80,113,32,249,120, 79,77,173,222,87,188,130,22,227,229,77,0,203,93,185,253,70,181,206,221,84,197,228,137, 248,210,19,90,42,78,166,105,244,122,21,149,174,84,4,188,191,3,35,66,92,33,119,158, 157,29,99,205,237,223,155,124,113,206,1,164,39,182,103,24,94,98,139,88,203,1,5,6, 245,132,18,82,186,229,142,184,218,158,52,47,150,168,152,122,223,144,114,194,43,6,126,87, 40,112,133,111,38,101,167,9,134,8,182,254,2,15,35,95,223,8,38,160,148,24,169,60, 224,98,88,27,73,188,8,236,83,191,60,217,252,180,72,136,215,17,222,22,19,182,61,170, 7,184,2,80,18,54,24,117,127,169,105,202,125,168,55,112,225,43,249,113,25,27,116,226, 224,99,206,118,174,154,109,132,73,76,191,213,104,154,200,113,234,25,47,161,186,95,154,205, 230,157,92,171,34,136,176,178,196,12,1,84,37,247,214,237,78,156,203,37,156,89,224,29, 224,10,38,122,14,239,232,76,137,88,107,233,41,31,117,87,182,75,12,9,245,187,4,121, 4,196,190,198,27,213,122,48,172,38,222,59,242,142,8,183,255,237,141,105,160,38,229,244, 1,13,66,183,202,255,87,106,157,247,147,138,207,74,211,53,88,118,232,69,52,179,83,174, 218,33,36,213,41,34,48,155,59,16,41,133,134,43,134,127,152,120,150,34,87,202,46,175, 82,62,153,230,200,113,237,134,181,190,23,172,41,181,76,3,212,235,85,189,187,88,130,49, 202,182,232,79,189,40,224,6,203,247,251,184,4,177,227,28,113,117,139,108,83,160,88,134, 164,199,119,75,172,218,138,79,252,252,164,176,171,59,44,244,140,126,173,170,127,185,108,30, 196,143,209,234,60,101,14,200,10,198,138,180,117,111,137,209,210,34,250,217,42,94,85,53, 116,88,245,41,150,196,99,94,102,195,5,18,240,79,56,51,160,207,228,197,243,103,227,126, 59,112,79,63,248,159,10,169,183,104,70,56,132,144,16,118,95,57,149,147,144,67,189,231, 131,91,20,218,39,94,145,172,130,170,249,185,43,102,33,67,61,73,195,135,242,29,4,96, 228,212,78,244,37,233,226,117,66,112,58,37,151,31,19,4,88,81,170,106,60,22,2,191, 190,177,205,36,32,13,154,100,26,193,76,143,175,167,34,236,162,17,130,130,250,25,202,211, 36,142,143,185,170,233,123,68,174,27,224,126,106,36,1,100,186,68,208,61,10,215,176,98, 141,96,61,73,201,56,214,146,197,226,215,213,195,148,105,233,53,237,63,79,59,80,8,245, 178,207,109,205,249,237,67,77,240,20,111,110,117,160,118,142,181,77,135,161,68,40,248,248, 178,171,224,223,181,188,67,156,249,204,192,74,20,113,195,28,189,105,24,212,39,122,126,250, 74,25,115,240,155,172,114,162,210,170,156,126,127,94,192,71,54,152,26,118,94,194,150,99, 1,199,185,236,228,178,62,188,159,68,55,193,255,225,72,62,214,160,252,176,131,176,80,255, 240,160,99,253,70,229,6,160,216,190,201,195,69,154,30,19,234,14,62,137,17,86,32,246, 93,74,153,244,11,35,149,53,164,146,10,199,8,25,13,90,78,245,14,239,130,137,145,248, 91,139,182,230,130,124,216,122,16,157,66,93,159,112,55,33,192,83,145,93,238,213,154,218, 134,43,41,157,218,24,58,52,213,82,178,232,160,33,30,165,179,148,136,53,38,24,75,87, 211,33,65,89,77,10,190,57,111,57,203,78,47,26,224,43,197,92,178,252,85,103,232,192, 240,39,149,61,155,12,130,141,115,71,192,252,73,228,185,158,123,164,155,214,163,190,109,109, 99,191,17,211,225,214,245,57,188,84,126,72,118,208,250,8,118,188,197,4,21,53,148,188, 125,242,122,22,218,37,252,236,232,82,68,78,237,40,235,124,116,21,106,194,214,142,69,77, 99,179,155,20,27,74,240,246,1,116,252,150,136,92,152,147,72,110,186,131,120,89,96,254, 229,57,77,245,124,98,74,109,232,126,199,174,214,120,36,134,18,206,23,92,142,253,98,202, 14,97,239,190,244,216,62,13,72,188,247,242,219,80,35,5,185,131,87,46,131,191,71,227, 161,110,41,169,206,74,111,4,250,201,171,132,186,64,135,145,217,150,25,158,160,241,120,52, 37,154,144,215,59,62,223,59,103,50,114,78,255,154,125,6,16,38,102,200,28,146,204,31, 179,3,248,70,210,155,118,145,153,229,194,154,222,65,101,217,141,22,202,74,217,113,73,66, 106,172,13,189,202,166,214,164,76,121,26,246,9,178,184,94,59,199,192,152,170,143,114,111, 193,253,184,41,98,100,161,222,102,76,28,231,202,226,119,91,130,163,163,178,188,216,131,199, 223,69,38,8,206,253,19,29,204,252,210,25,113,44,147,127,85,92,61,27,116,228,1,94, 55,151,58,42,123,62,81,253,234,154,59,239,67,167,227,87,245,246,137,183,58,213,13,73, 50,35,58,217,51,153,192,80,129,75,130,9,242,130,214,134,139,100,178,232,68,78,195,40, 15,158,166,254,160,33,103,52,195,150,57,83,136,139,34,194,220,108,81,206,217,140,22,208, 69,145,37,168,247,28,65,28,158,206,210,255,164,192,36,192,228,55,186,244,249,121,52,222, 134,232,133,1,122,132,14,253,4,117,7,75,109,201,70,16,118,209,214,82,52,175,174,176, 235,245,71,223,191,199,239,205,168,43,108,11,80,81,202,118,68,89,119,28,35,95,174,38, 192,44,211,19,163,223,37,90,165,162,199,98,156,104,64,188,251,27,229,238,161,170,104,1, 87,122,228,17,51,93,105,137,118,144,10,245,241,140,240,227,69,144,27,220,76,121,69,151, 109,53,198,216,193,11,52,28,113,191,233,63,88,20,196,245,254,126,140,185,49,80,153,138, 148,186,133,171,122,226,175,5,209,196,229,22,156,97,233,161,127,122,239,62,34,49,143,148, 99,182,84,231,86,4,26,145,90,117,8,234,36,179,5,123,73,110,65,251,26,46,56,213, 164,74,246,81,222,43,144,2,138,216,235,217,222,130,167,80,206,94,63,144,152,12,128,189, 183,243,5,193,24,237,134,21,237,117,240,208,227,202,102,19,121,143,108,126,31,143,22,84, 79,90,216,153,71,63,231,13,13,201,246,164,144,65,135,66,66,167,149,170,224,229,240,85, 42,33,175,135,254,189,87,162,17,135,170,156,245,164,29,254,127,207,65,89,147,153,51,246, 185,214,194,13,113,45,195,233,250,149,136,36,249,95,242,210,62,168,214,143,183,17,139,23, 101,90,91,192,40,204,142,34,110,85,146,251,241,102,146,122,45,170,76,64,190,111,47,12, 196,206,235,119,77,117,139,63,195,29,78,200,100,252,100,26,164,177,100,255,57,185,144,213, 175,75,174,17,232,5,6,59,7,68,5,2,103,231,52,187,27,103,244,239,122,242,199,38, 19,236,48,200,185,48,141,49,73,56,187,26,41,14,229,170,55,234,29,165,0,68,97,127, 91,109,157,26,87,131,76,206,112,171,228,64,233,126,38,146,240,76,186,85,39,146,28,144, 107,127,238,65,67,181,165,89,76,4,214,232,155,208,109,170,0,7,66,127,158,87,98,76, 249,234,141,253,83,150,182,61,211,124,64,116,87,3,142,234,6,139,165,8,201,63,110,44, 110,68,228,81,162,211,63,238,157,129,204,173,11,74,167,1,227,109,189,222,160,255,249,255, 120,226,187,206,136,63,211,80,251,241,185,126,21,51,186,70,231,191,113,20,173,47,11,27, 42,45,31,13,241,108,67,200,75,91,112,87,121,211,239,204,67,152,30,13,164,226,200,129, 8,75,208,202,233,232,159,231,112,235,116,37,156,42,216,64,81,254,112,18,160,13,88,228, 160,194,147,232,195,201,168,229,164,36,157,97,89,30,243,193,85,55,125,153,223,155,138,187, 169,152,186,103,236,231,186,85,61,235,87,19,91,178,197,119,103,200,124,56,98,156,110,101, 183,76,163,105,252,35,46,236,153,135,136,185,134,178,97,49,238,24,218,123,32,63,209,70, 81,60,126,19,77,150,193,236,232,176,249,50,15,5,151,150,47,218,71,7,56,95,90,207, 180,197,61,59,158,26,24,31,39,173,72,75,116,241,239,29,105,161,53,72,241,214,125,108, 81,14,4,121,35,74,51,195,29,86,209,21,144,166,74,67,190,102,216,154,211,197,125,253, 11,239,216,25,95,240,146,22,26,142,155,193,38,241,74,191,145,14,95,22,96,107,205,235, 234,56,233,93,209,80,102,138,123,109,33,70,68,26,98,67,6,189,63,111,81,120,237,135, 13,62,165,173,50,173,62,9,84,86,219,221,213,203,139,11,139,46,236,95,32,202,57,18, 37,36,20,233,252,23,7,33,174,200,9,242,100,72,231,97,161,156,90,82,143,127,185,35, 122,79,133,6,30,80,113,52,235,90,46,255,93,124,234,180,97,227,101,208,214,169,182,91, 136,136,18,12,196,36,0,59,109,43,36,242,73,165,214,93,12,1,214,95,134,240,148,173, 125,28,40,133,69,101,37,230,31,146,172,81,153,49,115,196,125,201,160,120,244,26,229,204, 180,156,181,77,149,148,165,17,85,151,132,89,128,11,237,226,168,76,228,212,210,140,248,105, 231,144,6,156,138,250,87,27,57,70,20,96,113,128,194,207,105,87,238,28,61,147,158,140, 90,93,219,65,2,118,112,246,182,117,181,169,210,151,144,213,207,217,180,235,33,126,58,102, 137,56,86,14,103,29,131,158,208,13,58,223,146,33,243,198,116,236,29,70,9,229,106,15, 190,238,227,229,196,172,2,55,254,18,252,216,37,45,192,204,125,137,222,59,88,8,246,10, 136,110,154,22,221,34,24,56,155,254,13,63,8,105,93,1,156,178,45,219,36,59,208,73, 241,14,84,75,180,52,83,109,35,83,177,112,63,9,224,197,192,122,220,93,70,224,219,5, 61,131,28,99,65,249,85,121,213,85,83,180,198,85,21,0,209,103,125,99,88,106,97,244, 40,115,252,230,252,149,107,211,2,218,88,76,160,72,10,51,15,63,28,116,40,201,15,103, 60,83,252,219,245,105,172,243,13,200,177,213,40,65,65,188,205,231,226,241,59,170,9,113, 217,177,169,170,169,201,138,104,94,79,87,114,44,253,87,5,99,224,10,102,156,91,102,241, 63,231,68,184,4,34,149,173,82,19,232,140,223,30,105,200,253,188,94,197,23,121,217,245, 70,64,141,17,76,189,174,250,9,115,109,161,23,43,171,41,99,10,37,148,5,150,118,176, 139,200,5,163,96,204,55,79,70,181,43,32,113,119,103,41,138,185,79,23,95,223,169,233, 136,122,111,129,30,130,111,190,24,241,8,186,86,19,209,252,196,168,138,177,204,60,216,181, 12,254,3,114,57,81,117,125,21,213,51,91,137,127,111,66,2,254,98,33,46,133,129,192, 83,219,28,253,112,247,218,45,176,208,18,221,220,201,179,136,145,34,166,199,135,24,146,59, 136,77,95,45,19,170,136,210,212,253,109,28,68,202,30,161,130,98,208,123,149,35,55,231, 246,48,98,33,112,85,85,74,209,111,136,63,193,112,99,238,28,220,94,189,37,53,20,98, 154,152,75,3,168,131,145,85,47,155,147,75,61,81,188,254,138,13,241,233,46,234,254,193, 229,119,102,195,145,227,122,59,171,213,78,141,214,127,132,66,240,57,47,47,117,55,88,206, 243,220,150,184,106,94,194,3,75,40,46,86,0,233,85,204,138,33,252,103,64,138,141,231, 131,50,179,171,101,218,223,32,95,158,100,232,158,106,53,80,192,120,44,226,132,213,245,160, 158,18,167,125,227,225,84,95,47,163,110,43,79,24,245,92,51,123,202,69,207,92,240,199, 107,253,67,125,191,215,138,115,175,187,227,229,131,160,202,31,60,37,48,72,209,64,192,151, 49,34,153,162,29,59,115,213,223,59,100,244,191,106,51,199,87,230,78,71,103,173,228,97, 44,113,130,253,234,128,3,19,48,2,12,32,191,39,58,213,165,6,39,210,201,24,133,215, 110,154,177,32,174,131,55,117,162,24,89,36,148,8,85,39,137,208,73,51,85,246,154,252, 36,6,250,138,137,176,212,42,39,212,247,230,113,17,95,41,79,89,27,204,95,59,251,201, 23,136,5,117,105,79,185,110,112,71,182,12,163,178,53,16,194,180,166,56,79,92,250,126, 18,177,230,175,143,110,143,251,194,184,232,1,67,129,179,81,39,50,9,64,254,175,162,68, 44,66,193,189,193,36,206,109,192,2,97,119,153,244,101,31,105,65,162,4,235,10,71,144, 246,80,169,0,193,214,77,82,205,36,106,73,57,54,137,109,184,10,246,239,186,243,188,122, 253,182,30,211,189,252,103,215,99,238,211,106,118,78,21,128,179,4,255,87,182,165,136,40, 229,64,48,81,174,145,231,150,118,108,27,37,101,117,4,157,105,151,180,115,110,13,101,4, 95,181,138,16,186,195,119,88,216,16,56,243,8,132,169,234,191,81,44,51,2,143,224,111, 216,218,68,234,29,89,203,232,44,194,53,135,199,221,251,74,165,176,12,190,100,181,186,36, 132,5,78,138,116,57,88,62,15,28,102,180,87,197,247,115,248,172,138,23,61,131,58,198, 95,171,107,55,19,0,48,136,246,90,177,218,227,102,67,23,255,124,100,58,145,248,34,214, 29,67,94,14,175,9,24,166,190,179,236,201,199,101,249,74,149,202,5,42,139,44,36,170, 127,28,5,103,79,36,81,62,197,60,194,196,2,148,113,213,83,1,89,22,128,181,68,121, 109,29,192,186,3,60,87,230,190,112,162,106,16,148,50,153,141,73,189,149,235,41,86,66, 71,81,226,6,8,20,174,74,188,198,38,131,215,180,242,101,159,40,193,34,194,191,248,215, 73,32,238,203,82,242,238,116,242,36,134,188,138,87,216,194,151,249,88,161,237,79,231,198, 192,127,30,211,164,18,117,190,208,2,40,29,132,147,116,95,43,28,103,152,86,105,150,62, 1,110,2,56,245,210,241,19,38,90,219,126,47,195,189,164,234,139,218,237,21,122,146,175, 188,10,167,224,130,11,93,149,144,111,41,109,138,133,160,233,153,114,148,20,49,151,182,41, 34,233,66,153,1,159,230,249,223,14,213,14,68,224,148,140,115,10,95,4,179,133,173,78, 21,81,53,3,220,68,183,72,13,92,182,50,215,93,178,176,192,238,45,103,111,247,33,16, 182,76,119,141,231,21,2,22,146,167,190,245,85,35,133,102,52,98,37,95,185,194,65,97, 148,140,119,126,131,138,71,159,223,41,175,46,230,36,204,22,13,218,248,38,187,251,255,215, 16,254,60,124,102,59,230,110,254,84,51,253,180,108,78,225,116,193,15,131,199,141,153,126, 130,57,20,30,117,102,104,42,50,200,73,63,9,151,198,27,244,196,89,58,202,184,139,62, 211,164,68,91,211,230,194,38,173,118,7,38,103,192,57,0,224,241,222,2,94,113,58,13, 101,170,19,175,253,157,93,204,89,169,142,229,190,174,175,158,47,240,155,111,17,110,101,82, 138,108,178,188,95,230,124,209,247,73,221,116,81,5,131,198,54,45,25,162,142,168,64,66, 139,167,60,196,241,48,146,44,34,58,195,242,50,220,190,174,190,46,4,135,67,11,15,224, 191,218,197,58,14,134,2,241,233,122,6,127,188,77,154,84,22,106,55,252,239,0,189,51, 190,216,252,222,190,71,171,55,51,233,40,180,158,236,252,221,104,47,71,114,45,255,91,39, 39,255,94,79,94,204,149,8,139,210,26,225,124,128,247,194,13,218,72,56,91,237,96,40, 225,15,48,141,102,221,38,159,100,25,233,218,208,236,180,225,147,155,245,96,185,95,157,22, 38,189,241,113,187,124,11,237,7,29,165,219,116,152,92,79,113,131,116,56,251,170,20,236, 35,22,149,111,116,226,79,99,6,127,125,221,149,55,143,79,165,100,57,155,226,220,141,120, 234,138,50,175,32,202,133,91,71,54,135,106,176,235,57,244,107,71,45,165,36,238,72,222, 134,98,109,43,203,189,126,209,2,179,76,212,77,137,85,64,184,70,226,203,10,63,227,249, 204,41,206,104,218,22,228,214,66,236,79,81,76,46,240,122,1,200,153,220,39,207,40,204, 9,152,130,146,133,164,235,46,223,147,99,107,44,246,152,190,219,185,240,107,31,93,254,245, 10,39,61,27,29,57,217,244,94,178,55,113,145,109,253,194,166,178,105,5,20,130,240,170, 88,174,178,239,192,80,180,59,147,65,198,212,217,111,86,108,174,138,47,125,101,113,54,193, 123,166,250,118,29,253,105,11,86,197,42,179,42,215,87,234,56,203,212,35,36,122,2,201, 59,147,54,189,93,208,175,203,113,226,39,197,104,173,46,28,183,201,24,109,184,164,240,126, 85,170,192,223,132,78,241,75,142,221,242,63,145,229,60,108,137,53,253,99,36,178,41,204, 121,195,128,153,178,237,106,80,15,126,165,136,241,34,98,129,205,225,85,111,255,69,28,199, 103,173,24,59,217,130,54,144,4,177,10,84,186,120,231,72,126,245,196,173,230,112,245,41, 134,231,64,167,129,117,107,125,206,33,130,51,197,98,191,174,36,125,191,118,121,48,126,49, 208,39,19,204,21,192,140,101,78,173,3,108,1,80,185,202,134,176,102,201,194,22,22,184, 231,79,215,21,251,164,70,237,137,119,173,240,193,82,157,27,237,34,46,11,239,190,0,204, 251,193,250,196,36,128,53,11,236,212,92,208,128,84,8,126,83,148,130,67,177,186,127,21, 51,38,238,211,90,84,191,170,253,183,169,87,146,14,60,236,43,80,48,111,83,32,93,149, 198,204,155,169,133,81,184,226,11,128,169,64,49,129,198,81,146,9,215,140,141,216,70,125, 114,130,191,197,130,150,28,114,27,55,81,200,240,194,105,203,188,61,75,74,231,18,176,54, 178,215,7,133,73,23,126,224,7,88,117,79,189,104,47,167,244,220,113,239,128,178,108,204, 140,255,77,79,56,129,190,95,10,9,16,26,11,69,128,59,60,40,45,162,48,57,247,45, 179,61,192,83,136,102,78,147,28,218,107,225,38,228,230,25,138,141,227,204,3,128,76,7, 253,92,113,20,89,182,158,165,215,48,208,121,206,220,217,228,221,120,50,84,81,183,118,115, 50,8,160,84,2,184,163,207,179,200,202,52,13,216,109,103,94,215,166,146,57,173,28,191, 136,92,225,223,241,230,126,83,118,171,243,46,51,169,177,181,105,96,35,54,253,231,86,72, 64,33,31,169,63,7,4,49,102,244,34,146,88,166,192,211,134,185,83,181,219,186,167,153, 141,6,152,130,119,203,77,221,244,238,41,74,130,180,20,173,105,130,92,224,136,171,215,139, 207,123,94,156,248,197,202,100,15,156,185,54,116,64,142,154,184,31,214,221,73,44,106,223, 168,63,20,171,11,140,132,239,214,43,150,42,91,132,237,188,70,222,93,72,19,230,47,72, 231,76,119,120,160,239,124,101,228,7,92,31,149,237,2,15,136,208,106,32,17,114,76,54, 177,29,86,80,62,152,202,69,120,207,184,88,71,57,112,81,241,20,120,228,45,11,86,106, 176,104,15,22,188,167,119,76,80,186,123,84,219,68,16,55,157,145,46,47,193,59,123,189, 184,173,156,108,122,244,103,99,55,8,61,106,93,47,35,23,182,68,146,67,211,180,60,107, 109,110,6,165,230,59,231,201,219,75,53,28,170,197,113,151,160,179,90,107,241,107,179,151, 106,102,180,25,234,32,214,130,18,169,99,124,64,6,24,74,159,81,192,7,3,72,13,168, 201,68,39,194,237,127,50,141,178,215,66,240,157,3,54,16,160,75,46,212,106,63,246,79, 113,13,165,129,254,51,110,190,180,229,195,45,222,167,19,246,143,47,76,238,194,105,60,58, 62,74,174,31,23,226,177,203,144,22,198,192,133,185,36,185,78,206,116,243,9,149,108,125, 252,193,36,65,175,78,212,115,192,92,61,247,158,146,115,69,182,88,54,191,209,110,218,44, 202,29,216,174,100,243,176,5,182,55,33,172,220,27,97,53,138,69,84,62,177,242,168,227, 72,132,164,9,180,155,254,36,126,74,133,190,200,7,33,237,140,140,43,211,158,245,233,102, 180,171,199,78,118,101,129,32,85,28,23,103,182,2,219,153,21,122,137,6,148,69,62,77, 31,143,163,209,21,162,113,215,148,115,165,169,249,172,43,121,30,234,56,51,146,66,44,76, 50,17,214,32,141,255,203,93,188,64,172,249,160,116,16,222,189,0,43,83,21,232,117,21, 5,95,19,53,76,205,164,117,212,104,54,36,177,67,52,57,98,205,240,120,248,108,173,151, 209,240,101,131,10,64,169,146,142,212,66,174,79,11,126,222,223,187,239,140,179,66,191,26, 197,184,121,143,41,238,219,19,56,132,43,48,177,241,196,148,254,48,196,183,66,58,167,82, 63,54,62,216,70,184,56,216,94,65,226,236,84,29,126,218,170,70,42,129,61,114,22,42, 129,208,209,124,198,36,29,44,78,167,116,62,81,240,39,203,129,240,145,149,147,228,75,192, 212,104,166,24,122,148,240,205,128,65,83,236,54,131,236,81,238,162,136,190,104,46,147,226, 174,173,23,104,220,120,17,169,172,84,149,210,168,80,103,125,208,49,250,196,84,211,66,196, 219,229,121,11,124,250,228,226,56,218,251,142,228,206,43,130,224,31,53,152,169,53,130,101, 50,77,76,170,106,94,173,237,71,98,82,179,37,227,36,69,248,52,168,13,97,136,195,63, 196,73,8,10,137,26,154,148,155,54,131,140,249,251,201,107,29,191,179,49,33,3,214,16, 9,232,78,106,250,204,189,161,235,173,37,168,227,136,56,250,183,210,247,252,116,143,121,90, 248,225,27,187,5,164,71,112,163,74,114,134,169,159,47,94,159,240,57,123,138,29,166,225, 73,227,220,97,110,16,98,176,179,58,84,114,10,134,181,210,250,66,156,29,128,80,249,37, 194,45,158,75,15,171,32,200,145,129,24,137,216,190,87,178,91,29,2,125,93,241,169,213, 83,34,40,180,182,105,163,80,100,93,141,163,130,43,70,177,229,176,100,164,98,28,138,97, 173,17,128,53,77,90,49,130,124,172,71,127,74,43,236,25,252,30,22,151,229,166,102,76, 131,69,138,118,243,29,155,12,161,10,64,95,209,170,151,228,107,91,11,137,8,19,161,141, 252,251,65,7,36,215,20,82,241,112,153,240,162,175,169,49,61,5,255,223,57,157,78,68, 98,187,13,137,14,149,55,250,78,62,14,103,220,244,1,191,167,174,238,176,159,232,102,137, 254,5,249,126,152,41,232,67,19,128,177,230,199,232,66,253,197,16,54,135,105,47,145,36, 232,196,53,180,198,14,250,7,43,64,178,135,136,141,105,190,102,50,163,126,148,109,127,39, 105,230,163,222,67,3,137,62,146,232,125,193,87,241,186,197,15,24,201,218,42,136,59,171, 63,51,192,75,107,117,143,24,151,110,135,206,255,68,179,155,245,251,187,30,173,195,158,199, 189,76,67,162,141,11,89,48,134,31,236,236,43,225,131,142,120,73,78,99,78,132,156,123, 31,157,50,249,74,36,15,242,228,127,221,99,59,82,159,75,239,132,15,59,13,136,242,46, 131,141,77,149,248,159,74,97,66,174,237,50,66,107,67,20,121,169,116,188,0,238,182,45, 110,224,103,35,78,59,255,187,76,232,54,236,39,110,111,208,6,109,159,230,103,192,199,131, 88,155,30,86,184,145,136,129,129,3,75,6,105,200,6,85,220,53,235,151,29,163,145,118, 50,90,209,192,49,58,27,81,233,216,252,242,244,151,208,57,93,6,85,9,70,83,113,177, 217,126,131,246,45,111,58,184,90,119,195,195,177,29,36,102,201,198,226,103,37,207,42,87, 65,170,127,71,234,252,144,169,233,213,73,43,22,74,101,219,168,45,160,40,53,24,119,164, 134,217,66,178,133,139,63,222,35,62,54,98,164,49,130,238,42,137,48,165,254,215,213,241, 103,113,120,172,155,191,119,94,193,104,217,12,6,75,96,8,156,89,153,235,251,47,137,144, 71,41,178,22,245,251,33,114,236,190,58,232,166,151,233,191,10,250,40,80,0,228,78,247, 149,213,146,146,197,199,131,210,164,145,80,218,144,105,82,169,219,174,191,195,138,37,103,8, 105,14,40,114,114,0,129,35,20,118,47,39,68,67,63,93,253,103,80,102,170,26,159,213, 173,167,138,118,180,32,77,193,128,108,3,204,218,108,146,240,162,253,190,15,168,159,97,71, 182,38,235,103,175,178,17,28,236,165,41,36,37,162,51,54,121,109,168,138,38,150,195,112, 139,157,66,146,238,134,129,118,240,242,96,196,72,179,226,60,84,54,242,73,80,57,167,110, 66,199,4,241,208,228,113,216,177,38,242,241,166,18,9,125,30,13,37,167,144,37,162,106, 207,85,4,78,208,143,85,41,123,183,246,243,233,234,48,25,12,64,234,1,141,160,75,214, 186,252,52,223,242,220,86,241,134,15,139,140,111,34,251,244,233,39,70,43,114,157,100,225, 60,184,30,105,76,141,78,186,135,220,71,94,229,107,1,45,50,62,112,79,124,55,69,61, 222,183,132,45,32,251,108,41,231,79,50,119,193,113,166,132,155,205,143,79,245,81,50,193, 118,51,117,108,198,98,220,128,136,114,240,204,99,112,197,108,42,147,18,179,84,241,2,171, 84,182,39,114,26,79,2,226,123,9,167,68,104,194,156,49,46,27,224,105,100,23,226,8, 114,207,185,175,128,161,174,75,222,16,253,78,67,127,118,155,240,162,188,71,111,134,3,139, 207,89,155,179,118,164,23,110,148,162,34,47,141,103,190,113,193,119,91,58,220,20,77,18, 233,254,209,37,136,100,178,30,66,234,123,245,65,132,196,209,132,173,33,178,192,47,42,23, 230,138,143,140,219,200,63,181,9,176,197,189,100,16,77,137,158,173,145,21,179,203,116,111, 132,193,166,143,138,104,24,215,228,45,155,0,181,167,14,197,166,112,86,169,113,115,112,247, 5,43,213,104,19,73,107,30,224,95,106,158,214,83,148,207,189,187,21,246,78,24,223,28, 163,251,107,18,159,162,25,171,162,201,12,93,206,39,70,69,207,17,52,127,225,121,176,227, 118,212,24,182,72,183,116,66,57,178,196,245,134,70,12,54,250,60,182,23,46,5,9,245, 228,90,97,145,112,151,113,199,186,26,249,125,25,43,155,158,16,218,132,25,236,226,112,129, 146,61,48,54,44,132,127,76,35,45,126,175,81,17,249,255,217,243,96,194,16,50,16,77, 179,37,64,242,198,75,237,94,169,54,66,16,152,43,242,89,216,101,27,180,81,28,216,105, 14,89,15,97,56,64,11,80,247,84,222,254,110,3,46,179,120,206,53,136,193,4,222,42, 44,64,198,15,109,243,197,149,17,152,40,148,127,79,233,158,118,59,49,171,208,173,48,131, 82,15,186,246,162,149,103,111,103,103,101,225,137,95,60,153,244,94,173,215,144,8,19,172, 186,26,162,158,184,26,34,163,54,90,68,15,43,78,22,242,81,187,82,101,43,45,40,135, 247,155,47,156,74,132,122,180,13,8,91,190,61,164,41,80,227,94,82,32,62,28,81,166, 93,19,136,146,108,130,5,187,1,30,11,16,120,92,117,97,248,227,242,243,232,137,86,165, 28,168,42,90,252,23,112,129,157,255,250,193,81,75,229,94,117,46,77,113,218,194,45,38, 63,196,182,243,255,249,160,251,154,142,186,175,162,11,233,253,79,31,168,215,145,188,222,191, 163,25,163,202,163,126,203,44,173,180,224,204,90,57,79,58,102,219,224,138,141,10,165,89, 106,0,107,92,178,45,41,119,226,29,160,157,150,198,102,188,196,14,74,14,135,233,136,237, 149,213,132,161,233,147,224,103,229,124,105,38,18,172,9,39,14,150,30,112,83,112,124,166, 37,38,40,158,32,172,24,195,34,229,99,117,105,213,153,186,160,39,66,117,219,128,164,162, 69,75,203,94,168,180,134,47,69,166,63,255,33,132,38,84,241,229,29,180,174,79,206,148, 149,237,12,193,44,86,240,227,246,30,106,243,137,129,125,123,122,197,17,197,234,218,33,133, 126,78,65,5,6,2,178,105,10,48,39,52,245,167,206,19,98,99,25,115,1,155,94,156, 104,21,187,46,181,125,207,114,166,109,89,183,71,75,226,210,43,32,190,0,0,0,0,0, 0,0,0, }; #define ENTITY_COUNT 2125u #define INPUT_CAP 104000u #define MODEL_BITS 14 #define MODEL_LIMIT 3 #define MIX_SHIFT 11 #define MIX_W0 16384 #define K (1u << 20) #define HASH_A 0x2545F491u #define HASH_B 0x9E3779B1u #define HIST_SIZE 16130u #define SQUASH_E0_BITS 0x40a732ac33de5528ULL #define SQUASH_STEP_BITS 0x3fefe00ffaabffbcULL #define MODEL_BYTES ((1u << MODEL_BITS) * 2) #define SQUASH_OFF MODEL_BYTES #define STRETCH_OFF (SQUASH_OFF + 4095 * 2) #define HIST_OFF (STRETCH_OFF + 4096 * 2) #define IN_OFF ((((HIST_OFF + HIST_SIZE) > (INPUT_CAP / 5 + 64)) ? (HIST_OFF + HIST_SIZE) : (INPUT_CAP / 5 + 64)) + 63) / 64 * 64 #define OUTPUT_CAP (INPUT_CAP / 5 * 6 + 8) #define PAD 128 #define FAST_BITS 12 #define FAST_TAIL 32 #define FAST_MAXLEN 7 #define LEG_BITS 8 #define LEG_TAIL 16 #define LONG_BITS 11 #define LONG_MASK ((1 << LONG_BITS) - 1) #define EMPTY (~(u64)0) #define WINDOW 2048 #define FAST_MUL 0xa59d054b12f5b905ULL #define LEG_MUL 0xf880d97d1854e551ULL #define LONG_MUL 0xa0c2995f40498cb3ULL static const i32 rate[4] = {43690, 26214, 18724, 14563}; typedef struct { u64 key, val; } Entry; typedef struct { u8 name[32]; u64 val; } Long; static u8 buf[IN_OFF + INPUT_CAP + PAD] __attribute__((aligned(64))); #define input (buf + IN_OFF) #define output buf static u16 *const model = (u16 *)buf; static u16 *const squash = (u16 *)(buf + SQUASH_OFF); static i16 *const stretch = (i16 *)(buf + STRETCH_OFF); static u8 *const hist = buf + HIST_OFF; static Entry fast[(1 << FAST_BITS) + FAST_TAIL]; static Entry leg[(1 << LEG_BITS) + LEG_TAIL]; static Long longs[506] __attribute__((aligned(16))); static u16 long_slots[1 << LONG_BITS]; static u8 leg_max[4096]; static u32 pos[WINDOW + 16]; static u8 len_mask[64] __attribute__((aligned(16))); /* The match model's position list, in stage 1's still-zero position list. */ static u16 *const last = (u16 *)pos; static i32 weights[3]; static u32 rc_in, rc_range, rc_code; static u32 ready = 0; static const u16 c1[32] = { 0x20AC, 0x81, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x8D, 0x017D, 0x8F, 0x90, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x9D, 0x017E, 0x0178, }; static const u32 utf8_marks[5] = {0, 0, 0x80C0, 0x8080E0, 0x808080F0}; #define ONES 0x0101010101010101ULL #define HIGH 0x8080808080808080ULL static inline u64 ld64(const u8 *p) { u64 x; __builtin_memcpy(&x, p, 8); return x; } static inline void st64(u8 *p, u64 x) { __builtin_memcpy(p, &x, 8); } static inline void st32(u8 *p, u32 x) { __builtin_memcpy(p, &x, 4); } static inline v128_t ld(const u8 *p) { return wasm_v128_load(p); } static inline void st(const u8 *p, v128_t v) { wasm_v128_store((u8 *)p, v); } static inline u32 amps(v128_t v) { return wasm_i8x16_bitmask(wasm_i8x16_eq(v, wasm_i8x16_splat('&'))); } static inline u32 semis(v128_t v) { return wasm_i8x16_bitmask(wasm_i8x16_eq(v, wasm_i8x16_splat(';'))); } static inline u32 leg_slot(u64 w) { return ((u32)w & 0xFFFF) * 0x9E3779B1u >> 20; } static inline u32 long_hash(u64 head7, u64 len) { return (u32)(((head7 | len << 56) * LONG_MUL) >> (64 - LONG_BITS)); } /* A code point as UTF-8 bytes in a word, low byte first. */ static u32 utf8(u32 v, u32 *len) { u32 n = 1 + (v > 0x7F) + (v > 0x7FF) + (v > 0xFFFF); u32 bits = (v >> 18) | (v >> 12 & 0x3F) << 8 | (v >> 6 & 0x3F) << 16 | (v & 0x3F) << 24; *len = n; return n == 1 ? v : (u32)((i32)bits >> (32 - 8 * n)) | utf8_marks[n]; } /* squash[x + 2047] = 4096 / (1 + e^(-x / 256)) rounded, for x = -2047..2047, and * stretch, its inverse. Only IEEE multiply, add and divide, so every machine * (and the packer) gets the same bits. */ static void build_squash(void) { double e, step; u64 e_bits = SQUASH_E0_BITS, s_bits = SQUASH_STEP_BITS; __builtin_memcpy(&e, &e_bits, 8); __builtin_memcpy(&step, &s_bits, 8); u32 pi = 0; for (u32 x = 0; x < 4095; x++) { u32 v = ((u32)(8192.0 / (1.0 + e)) + 1) >> 1; squash[x] = (u16)v; while (pi <= v) stretch[pi++] = (i16)((i32)x - 2047); e *= step; } } /* Decode an nbits-bit field, one bit at a time. Each bit's probability is the * logistic mix of the model entries chosen by the nctx contexts; after the bit * is known, each weight moves by error * stretch(p) and each entry steps toward * the bit. */ static u32 symN(const u32 *ctx, int nctx, u32 nbits) { u32 node = 1, top = 1u << nbits; for (;;) { i32 stretched[3]; u32 slot[3]; i32 dot = 0; for (int k = 0; k < nctx; k++) { u32 s = ((ctx[k] + node * HASH_A) * HASH_B) >> (32 - MODEL_BITS); slot[k] = s; stretched[k] = stretch[(model[s] >> 4) ^ 0x800]; dot += stretched[k] * (weights[k] + MIX_W0); } i32 d = dot >> 16; if (d < -2047) d = -2047; if (d > 2047) d = 2047; u32 p = squash[d + 2047]; u32 bound = (rc_range >> 12) * p; u32 bit = rc_code < bound; if (bit) rc_range = bound; else { rc_code -= bound; rc_range -= bound; } while (rc_range < (1u << 24)) { rc_range <<= 8; rc_code = (rc_code << 8) | packed_list[rc_in]; rc_in++; } i32 one = (i32)bit << 12; i32 err = one - (i32)p; for (int k = 0; k < nctx; k++) { weights[k] += (stretched[k] * err) >> MIX_SHIFT; u16 e = model[slot[k]]; i32 q = (i32)((e >> 4) ^ 0x800); u32 n = e & 15; q += ((one - q) * rate[n]) >> 16; model[slot[k]] = (u16)(((q ^ 0x800) << 4) | (n + (n < MODEL_LIMIT))); } node = node * 2 + bit; if (node >= top) break; } return node - top; } static void init(void) { __builtin_memset(fast, 0xFF, sizeof fast); __builtin_memset(leg, 0xFF, sizeof leg); __builtin_memset(len_mask, 0xFF, 32); build_squash(); rc_in = 4; rc_range = 0xFFFFFFFFu; rc_code = (u32)packed_list[0] << 24 | (u32)packed_list[1] << 16 | (u32)packed_list[2] << 8 | packed_list[3]; u32 cp = 0, hn = 1; size_t nl = 0; for (u32 r = 0; r < ENTITY_COUNT; r++) { u32 ctx[3]; ctx[0] = K; u32 nb = symN(ctx, 1, 5); u32 d = nb; if (nb > 1) { ctx[0] = 2 * K + nb; d = (1u << (nb - 1)) + symN(ctx, 1, nb - 1); } cp += d; u32 vn = 0, vn2 = 0; u64 val = utf8(cp, &vn); ctx[0] = 3 * K + (d == 0); if (symN(ctx, 1, 1)) { ctx[0] = 4 * K; val |= (u64)utf8(symN(ctx, 1, 16), &vn2) << (8 * vn); } val |= (u64)(vn + vn2) << 56; ctx[0] = 5 * K + (cp < 256); u32 legacy = symN(ctx, 1, 1); u8 name[40]; __builtin_memset(name, 0, 40); u32 n = 0, h = 0, mp = 0, ml = 0; for (;;) { ctx[0] = 8 * K + (h & 63); ctx[1] = 9 * K + (h & 4095); ctx[2] = 13 * K + (ml ? (u32)hist[mp] : 0) * 16 + (ml < 3 ? ml : 3); u32 c = symN(ctx, 3, 6); if (ml && hist[mp] == c) { ml++; mp++; } else ml = 0; hist[hn] = (u8)c; hn++; if (c == 0) break; name[n] = (u8)(c < 11 ? c + '0' - 1 : c < 37 ? c + 'A' - 11 : c + 'a' - 37); n++; h = h << 6 | c; if (n >= 2) { u16 *l = &last[h & 4095]; if (ml == 0 && *l) { mp = *l; ml = 1; } *l = (u16)hn; } } const u8 *nm = name; if (n <= FAST_MAXLEN) { u64 key = ld64(nm) | (u64)';' << (8 * n); Entry *e = &fast[(key * FAST_MUL) >> (64 - FAST_BITS)]; while (e->key != EMPTY) e++; e->key = key; e->val = val; if (legacy) { key = ld64(nm) | (u64)n << 56; e = &leg[(key * LEG_MUL) >> (64 - LEG_BITS)]; while (e->key != EMPTY) e++; e->key = key; e->val = val; u32 s = leg_slot(key); /* only the first two bytes matter */ if (leg_max[s] < n) leg_max[s] = (u8)n; } } else { Long *l = &longs[nl++]; /* The hash covers the name's first 7 bytes (with a ';' patched in at * name[n], as the lookup's masked load sees it) and the length. */ name[n] = ';'; u32 hh = long_hash(ld64(nm) & 0x00FFFFFFFFFFFFFFULL, n); name[n] = 0; __builtin_memcpy(l->name, name, 32); l->val = val | (u64)n << 59; while (long_slots[hh]) hh = (hh + 1) & LONG_MASK; long_slots[hh] = (u16)(nl); } } ready = 1; } EXPORT(input_ptr) u32 input_ptr(void) { return (u32)(uintptr_t)input; } EXPORT(input_utf8_cap) u32 input_utf8_cap(void) { return INPUT_CAP; } EXPORT(output_ptr) u32 output_ptr(void) { return (u32)(uintptr_t)output; } EXPORT(output_utf8_cap) u32 output_utf8_cap(void) { return OUTPUT_CAP; } EXPORT(render) u64 render(u32 len_) { if (!ready) init(); size_t size = len_ < INPUT_CAP ? len_ : INPUT_CAP; const u8 *src = input; u8 *dst = output; const v128_t zero = wasm_i8x16_splat(0); st(src + size, zero); st(src + size + 16, zero); st(src + size + 32, zero); st(src + size + 48, zero); /* Stage 1 lists the position of every `&` in a window; stage 2 copies the * text between references and decodes each one. */ size_t e = 0, o = 0, base = 0; while (base < size) { size_t lim = size - base > WINDOW ? base + WINDOW : size; size_t count = 0; while (true) { u64 mm = (u64)amps(ld(src + base)) | (u64)amps(ld(src + base + 16)) << 16 | (u64)amps(ld(src + base + 32)) << 32 | (u64)amps(ld(src + base + 48)) << 48; size_t cnt = __builtin_popcountll(mm); u32 b = (u32)base; u32 *out = pos + count; out[0] = b + __builtin_ctzll(mm); mm &= mm - 1; out[1] = b + __builtin_ctzll(mm); mm &= mm - 1; out[2] = b + __builtin_ctzll(mm); mm &= mm - 1; out[3] = b + __builtin_ctzll(mm); mm &= mm - 1; if (cnt > 4) { out[4] = b + __builtin_ctzll(mm); mm &= mm - 1; out[5] = b + __builtin_ctzll(mm); mm &= mm - 1; out[6] = b + __builtin_ctzll(mm); mm &= mm - 1; out[7] = b + __builtin_ctzll(mm); mm &= mm - 1; size_t k = 8; while (mm) { out[k] = b + __builtin_ctzll(mm); mm &= mm - 1; k++; } } count += cnt; base += 64; if (base >= lim) break; } for (size_t q = 0; q < count; q++) { size_t i = pos[q]; /* Output and input are one buffer, so the compiler cannot move a load * across a store: everything this reference needs is loaded first. */ u64 w = ld64(src + i + 1); /* Copy the text since the last reference; src[i] is `&` and i < size. */ { size_t len = i - e; v128_t ca = ld(src + e), cb = ld(src + e + 16); st(dst + o, ca); st(dst + o + 16, cb); if (len > 32) { size_t j = 32; do { st(dst + o + j, ld(src + e + j)); j += 16; } while (j < len); } o += len; } if ((u8)w == '#') { /* Decimal and hexadecimal share one branch-free path: classify 8 * bytes, take the digits before the first other byte, and fold. */ u32 hex = (((u32)w >> 8 & 0xFF) | 0x20) == 'x'; const u8 *p = src + i + 2 + hex; u64 d = ld64(p); u64 t = d ^ 0x3030303030303030ULL; u64 digit = ~(((t & ~HIGH) + 0x7676767676767676ULL) | t) & HIGH; u64 y = d | 0x2020202020202020ULL, ty = y & ~HIGH; u64 letter = (ty + ONES * (0x80 - 'a')) & ~(ty + ONES * (0x7F - 'f')) & ~y & HIGH; u64 stop = ~(digit | (hex ? letter : 0)) & HIGH; u32 v; size_t end; if (stop) { u32 nb = __builtin_ctzll(stop) & 0x38; if (!nb) goto bare; u64 x = ((d & 0x0F0F0F0F0F0F0F0FULL) + 9 * (letter >> 7)) << (64 - nb); x = (x * (hex ? 16 : 10) + (x >> 8)) & 0x00FF00FF00FF00FFULL; x = (x * (hex ? 256 : 100) + (x >> 16)) & 0x0000FFFF0000FFFFULL; v = (u32)(x * (hex ? 65536 : 10000) + (x >> 32)); end = (size_t)(p - src) + (nb >> 3); } else { /* Eight or more digits: saturate past U+10FFFF. */ u32 radix = hex ? 16 : 10; v = 0; for (;;) { u32 c = (u32)*p - '0'; if (c > 9) { c = ((*p | 0x20) - 'a') + 10; if (c < 10) c = 16; } if (c >= radix) break; v = v * radix + c; if (v > 0x10FFFF) v = 0x110000; p++; } end = (size_t)(p - src); } i = end + (src[end] == ';'); if (v - 0x80 < 0x20) v = c1[v - 0x80]; else if (v == 0 || v - 0xD800 < 0x800 || v > 0x10FFFF) v = 0xFFFD; u32 vlen, word = utf8(v, &vlen); st32(dst + o, word); o += vlen; e = i; continue; } { u64 t = w ^ (ONES * ';'); u64 z = (t - ONES) & ~t & HIGH; if (z) { /* Bit index of the `;` byte; the key is the name and its `;`. */ u32 kb = __builtin_ctzll(z) & 0x38; u64 key = w & (((u64)2 << (kb + 7)) - 1); const Entry *en = &fast[(key * FAST_MUL) >> (64 - FAST_BITS)]; u64 k = en->key; while (k != key && k != EMPTY) k = (++en)->key; if (k == key) { u64 val = en->val; st64(dst + o, val); o += val >> 56; i += 2 + (kb >> 3); e = i; continue; } } else { /* No `;` in 8 bytes: a name of 8 to 31 bytes needs its `;` in * the next 24. */ v128_t s0 = ld(src + i + 1), s1 = ld(src + i + 17); u32 sm = semis(s0) | semis(s1) << 16; if (sm) { size_t len = __builtin_ctz(sm); u32 h = long_hash(w & 0x00FFFFFFFFFFFFFFULL, len); const u8 *lm = len_mask; v128_t m0 = ld(lm + 32 - len), m1 = ld(lm + 48 - len); u64 found = 0; while (long_slots[h]) { const Long *l = &longs[long_slots[h] - 1]; v128_t diff = wasm_v128_or( wasm_v128_xor(wasm_v128_and(s0, m0), ld(l->name)), wasm_v128_xor(wasm_v128_and(s1, m1), ld(l->name + 16))); if (l->val >> 59 == len && !wasm_v128_any_true(diff)) { found = l->val; break; } h = (h + 1) & LONG_MASK; } if (found) { st64(dst + o, found); o += (found >> 56) & 7; i += 2 + len; e = i; continue; } } } /* Without `;`, the longest legacy name that is a prefix. */ for (size_t k = leg_max[leg_slot(w)]; k >= 2; k--) { u64 key = (w & (((u64)1 << (8 * k)) - 1)) | (u64)k << 56; const Entry *en = &leg[(key * LEG_MUL) >> (64 - LEG_BITS)]; for (;;) { if (en->key == key) { st64(dst + o, en->val); o += en->val >> 56; i += 1 + k; goto next; } if (en->key == EMPTY) break; en++; } } } bare: dst[o] = '&'; o += 1; i += 1; next: e = i; } } /* Without a reference the input is the output. */ if (e == 0) return (u64)(u32)(uintptr_t)input << 32 | size; for (size_t j = e; j < size; j += 16) st(dst + o + (j - e), ld(src + j)); o += size - e; return (u64)(u32)(uintptr_t)output << 32 | o; }