diff --git a/.gitignore b/.gitignore index 0e6a68346..2dfd80aca 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ core venv *.wasm + +./platforms/Arduino/node_modules diff --git a/CMakeLists.txt b/CMakeLists.txt index b8475a34a..3c757a2e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,9 +57,9 @@ if (BUILD_EMULATOR) src/Edward/RFC.cpp ) - add_definitions(-DINFO=0) - add_definitions(-DDEBUG=0) - add_definitions(-DTRACE=0) + add_definitions(-DINFO=1) + add_definitions(-DDEBUG=1) + add_definitions(-DTRACE=1) add_definitions(-DWARN=0) # Set default compile flags for GCC @@ -67,6 +67,7 @@ if (BUILD_EMULATOR) add_compile_options(-g -v -Wall -Wextra -Wunused -O3) endif (CMAKE_COMPILER_IS_GNUCXX) + add_compile_options(-g ) # WARDuino CLI add_executable(wdcli platforms/CLI-Emulator/main.cpp ${SOURCE_FILES}) target_link_libraries(wdcli PRIVATE Threads::Threads) diff --git a/benchmarks/benchmarks.cpp b/benchmarks/benchmarks.cpp index aafb22613..9611805a7 100644 --- a/benchmarks/benchmarks.cpp +++ b/benchmarks/benchmarks.cpp @@ -108,10 +108,12 @@ int run_benchmarks(size_t num_benchmarks, string benchmarks[], } int main(int argc, const char *argv[]) { - string benchmarks[] = {"tak", "fib", "fac", "gcd", "catalan", "primes"}; - uint32_t expected[] = {7, 91, 82, 62882, 244, 1824}; + string benchmarks[] = {"tak", "fac", "fib", "gcd", "catalan", "primes"}; + uint32_t expected[] = {7, 82, 91, 62882, 244, 1824}; + size_t num = (size_t)(sizeof(benchmarks) / sizeof(string *)); size_t correct = run_benchmarks(num, benchmarks, expected); + bool pass = (num == correct); printf("SUMMARY: %s (%zu / %zu)\n", pass ? "PASS" : "FAIL", correct, num); return pass ? 0 : 1; diff --git a/benchmarks/makefile b/benchmarks/makefile index 95b6bc364..0c962a5cc 100644 --- a/benchmarks/makefile +++ b/benchmarks/makefile @@ -14,8 +14,8 @@ DEBUGFLAGS = -DDEBUG=$(DEBUG) -DTRACE=$(TRACE) -DINFO=$(INFO) -DWARN=$(WARN) CXX = g++ CC = gcc -CFLAGS = -g -Wall -c -CXXFLAGS = -g -v -std=c++11 -I ../lib/json/single_include -Wall +CFLAGS = -Wall -c O3 +CXXFLAGS = -v -O3 -std=c++11 -I ../lib/json/single_include -Wall @@ -35,11 +35,11 @@ CXXSOURCES = \ ../src/WARDuino/CallbackHandler.cpp \ ../src/Primitives/emulated.cpp \ ../src/Interpreter/instructions.cpp \ + ../src/Interpreter/interpreter.cpp \ ../src/Edward/RFC.cpp \ ../src/Edward/proxy.cpp \ ../src/Edward/proxy_supervisor.cpp \ ../src/Utils/sockets.cpp \ - ../lib/json/single_include/nlohmann/json.hpp \ benchmarks.cpp all: $(OUTPUTDIR)$(TARGET) $(addprefix tasks/,$(addsuffix /wast/impl.wasm, $(TASKS))) diff --git a/platforms/Arduino/Makefile b/platforms/Arduino/Makefile index 941f95d5c..b0ebd9c6b 100644 --- a/platforms/Arduino/Makefile +++ b/platforms/Arduino/Makefile @@ -42,7 +42,7 @@ compile: Arduino.ino ifndef FQBN $(error FQBN is not set. Use a .config file) endif - arduino-cli compile --fqbn $(FQBN) Arduino.ino + arduino-cli compile --fqbn $(FQBN) Arduino.ino --build-property build.partitions=huge_app --build-property upload.maximum_size=3145728 recompile: clean compile diff --git a/platforms/Arduino/asconfig.json b/platforms/Arduino/asconfig.json new file mode 100644 index 000000000..166fb4fe4 --- /dev/null +++ b/platforms/Arduino/asconfig.json @@ -0,0 +1,32 @@ +{ + "entries": [ + "src/main.ts" + ], + "targets": { + "debug": { + "debug": true, + "outFile": "blink.wasm", + "textFile": "bin/main.debug.wast" + }, + "release": { + "converge": true, + "optimizeLevel": 3, + "outFile": "blink.wasm", + "shrinkLevel": 2 + } + }, + "options": { + "disable": [ + "mutable-globals", + "sign-extension", + "nontrapping-f2i", + "bulk-memory" + ], + "exportTable": true, + "exportRuntime": false, + "maximumMemory": 2, + "noAssert": false, + "runtime": "stub", + "sourceMap": true + } +} diff --git a/platforms/Arduino/blink.wasm.map b/platforms/Arduino/blink.wasm.map new file mode 100644 index 000000000..05e1437cc --- /dev/null +++ b/platforms/Arduino/blink.wasm.map @@ -0,0 +1 @@ +{"version":3,"sources":["~lib/rt/common.ts","src/main.ts"],"names":[],"mappings":"6PCqBY,EAAK,EAAb,EACA,EAGA,EACiB,EAAK,EAAlB,EACM,GAAN,EACa,EAAK,EAAlB,EACM,GAAN,EACgB,EAAE,EAAE,GAAI,GAAxB,EACI,EAAE,EAAF,CAAJ,E","sourceRoot":"./blink","sourcesContent":["// Alignment guarantees\n\n// @ts-ignore: decorator\n@inline export const AL_BITS: u32 = 4; // 16 bytes to fit up to v128\n// @ts-ignore: decorator\n@inline export const AL_SIZE: usize = 1 << AL_BITS;\n// @ts-ignore: decorator\n@inline export const AL_MASK: usize = AL_SIZE - 1;\n\n// Extra debugging\n\n// @ts-ignore: decorator\n@inline export const DEBUG = true;\n// @ts-ignore: decorator\n@inline export const TRACE = false;\n// @ts-ignore: decorator\n@inline export const RTRACE = isDefined(ASC_RTRACE);\n// @ts-ignore: decorator\n@inline export const PROFILE = isDefined(ASC_PROFILE);\n\n// Memory manager\n\n// ╒════════════ Memory manager block layout (32-bit) ═════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤\n// │ MM info │ -4\n// ╞>ptr═══════════════════════════════════════════════════════════╡\n// │ ... │\n@unmanaged export class BLOCK {\n /** Memory manager info. */\n mmInfo: usize;\n}\n\n/** Overhead of a memory manager block. */\n// @ts-ignore: decorator\n@inline export const BLOCK_OVERHEAD: usize = offsetof();\n\n/** Maximum size of a memory manager block's payload. */\n// @ts-ignore: decorator\n@inline export const BLOCK_MAXSIZE: usize = (1 << 30) - BLOCK_OVERHEAD;\n\n// Garbage collector\n\n// ╒══════════ Garbage collector object layout (32-bit) ═══════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤\n// │ Memory manager block │ -20\n// ╞═══════════════════════════════════════════════════════════════╡\n// │ GC info │ -16\n// ├───────────────────────────────────────────────────────────────┤\n// │ GC info │ -12\n// ├───────────────────────────────────────────────────────────────┤\n// │ RT id │ -8\n// ├───────────────────────────────────────────────────────────────┤\n// │ RT size │ -4\n// ╞>ptr═══════════════════════════════════════════════════════════╡\n// │ ... │\n@unmanaged export class OBJECT extends BLOCK {\n /** Garbage collector info. */\n gcInfo: u32;\n /** Garbage collector info. */\n gcInfo2: u32;\n /** Runtime class id. */\n rtId: u32;\n /** Runtime object size. */\n rtSize: u32;\n}\n\n/** Overhead of a garbage collector object. Excludes memory manager block overhead. */\n// @ts-ignore: decorator\n@inline export const OBJECT_OVERHEAD: usize = (offsetof() - BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK;\n\n/** Maximum size of a garbage collector object's payload. */\n// @ts-ignore: decorator\n@inline export const OBJECT_MAXSIZE: usize = BLOCK_MAXSIZE - OBJECT_OVERHEAD;\n\n/** Total of memory manager and garbage collector overhead. */\n// @ts-ignore: decorator\n@inline export const TOTAL_OVERHEAD: usize = BLOCK_OVERHEAD + OBJECT_OVERHEAD;\n","// Blinking LED example\n@external(\"env\", \"chip_pin_mode\") export declare function pinMode(pin: u32, mode: u32): void;\n@external(\"env\", \"chip_digital_write\") export declare function digitalWrite(pin: u32, value: u32): void;\n@external(\"env\", \"chip_delay\") export declare function delay(ms: u32): void;\n@external(\"env\", \"display_init\") export declare function initDisplay(): void;\n@external(\"env\", \"display_draw_rect\") export declare function displayDrawRect(x:i32,y:i32,w:i32,h:i32): void;\n\nenum PinVoltage {\n /** Low voltage on a digital I/O pin */\n LOW = 0,\n /** High voltage on a digital I/O pin */\n HIGH = 1,\n}\n\n\nexport function main(): void {\n const led: u32 = 4;\n const pause: u32 = 1000;\n\t\t\t\tconst OUTPUT: u32 = 3;\n\t\t\t\tlet x:i32 = 0;\n\n pinMode(led, OUTPUT);\n\t\t\t\tinitDisplay();\n\n\n while (true) {\n digitalWrite(led, PinVoltage.HIGH);\n delay(pause);\n digitalWrite(led, PinVoltage.LOW);\n\t\t\t\t\t\t\t\tdelay(pause);\n\t\t\t\t\t\t\t\tdisplayDrawRect(x,0,150,150);\n\t\t\t\t\t\t\t\tx = x+10;\n\t\t\t\t}\n}\n"]} \ No newline at end of file diff --git a/platforms/Arduino/display.ts b/platforms/Arduino/display.ts new file mode 100644 index 000000000..93c24304c --- /dev/null +++ b/platforms/Arduino/display.ts @@ -0,0 +1,28 @@ +// Blinking LED example +@external("env", "chip_pin_mode") export declare function pinMode(pin: u32, mode: u32): void; +@external("env", "chip_digital_write") export declare function digitalWrite(pin: u32, value: u32): void; +@external("env", "chip_delay") export declare function delay(ms: u32): void; + + +enum PinVoltage { + /** Low voltage on a digital I/O pin */ + LOW = 0, + /** High voltage on a digital I/O pin */ + HIGH = 1, +} + + +export function main(): void { + const led: u32 = 4; + const pause: u32 = 1000; + const OUTPUT: u32 = 3; + + pinMode(led, OUTPUT); + + while (true) { + digitalWrite(led, PinVoltage.HIGH); + delay(pause); + digitalWrite(led, PinVoltage.LOW); + delay(pause); + } +} diff --git a/platforms/Arduino/package-lock.json b/platforms/Arduino/package-lock.json new file mode 100644 index 000000000..4b2d912ef --- /dev/null +++ b/platforms/Arduino/package-lock.json @@ -0,0 +1,50 @@ +{ + "name": "Arduino", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "assemblyscript": "^0.27.29" + } + }, + "node_modules/assemblyscript": { + "version": "0.27.29", + "resolved": "https://registry.npmjs.org/assemblyscript/-/assemblyscript-0.27.29.tgz", + "integrity": "sha512-pH6udb7aE2F0t6cTh+0uCepmucykhMnAmm7k0kkAU3SY7LvpIngEBZWM6p5VCguu4EpmKGwEuZpZbEXzJ/frHQ==", + "license": "Apache-2.0", + "dependencies": { + "binaryen": "116.0.0-nightly.20240114", + "long": "^5.2.1" + }, + "bin": { + "asc": "bin/asc.js", + "asinit": "bin/asinit.js" + }, + "engines": { + "node": ">=16", + "npm": ">=7" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/assemblyscript" + } + }, + "node_modules/binaryen": { + "version": "116.0.0-nightly.20240114", + "resolved": "https://registry.npmjs.org/binaryen/-/binaryen-116.0.0-nightly.20240114.tgz", + "integrity": "sha512-0GZrojJnuhoe+hiwji7QFaL3tBlJoA+KFUN7ouYSDGZLSo9CKM8swQX8n/UcbR0d1VuZKU+nhogNzv423JEu5A==", + "license": "Apache-2.0", + "bin": { + "wasm-opt": "bin/wasm-opt", + "wasm2js": "bin/wasm2js" + } + }, + "node_modules/long": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", + "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==", + "license": "Apache-2.0" + } + } +} diff --git a/platforms/Arduino/package.json b/platforms/Arduino/package.json new file mode 100644 index 000000000..b1b689000 --- /dev/null +++ b/platforms/Arduino/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "assemblyscript": "^0.27.29" + } +} diff --git a/platforms/Arduino/src/main.ts b/platforms/Arduino/src/main.ts new file mode 100644 index 000000000..f154a4eb4 --- /dev/null +++ b/platforms/Arduino/src/main.ts @@ -0,0 +1,34 @@ +// Blinking LED example +@external("env", "chip_pin_mode") export declare function pinMode(pin: u32, mode: u32): void; +@external("env", "chip_digital_write") export declare function digitalWrite(pin: u32, value: u32): void; +@external("env", "chip_delay") export declare function delay(ms: u32): void; +@external("env", "display_init") export declare function initDisplay(): void; +@external("env", "display_draw_rect") export declare function displayDrawRect(x:i32,y:i32,w:i32,h:i32): void; + +enum PinVoltage { + /** Low voltage on a digital I/O pin */ + LOW = 0, + /** High voltage on a digital I/O pin */ + HIGH = 1, +} + + +export function main(): void { + const led: u32 = 4; + const pause: u32 = 1000; + const OUTPUT: u32 = 3; + let x:i32 = 0; + + pinMode(led, OUTPUT); + initDisplay(); + + + while (true) { + digitalWrite(led, PinVoltage.HIGH); + delay(pause); + digitalWrite(led, PinVoltage.LOW); + delay(pause); + displayDrawRect(x,0,150,150); + x = x+10; + } +} diff --git a/src/Interpreter/instructions.cpp b/src/Interpreter/instructions.cpp index 6f19643d7..b18ecacf7 100644 --- a/src/Interpreter/instructions.cpp +++ b/src/Interpreter/instructions.cpp @@ -74,23 +74,6 @@ bool proxy_call(Module *m, uint32_t fidx) { | call_indirect typeidx */ -/* -Instruction: call funcidx - -Webassembly Description: - -1. Let 𝐹 be the current frame. -2. Assert: due to validation, 𝐹.module.funcaddrs[𝑥] exists. -3. Let 𝑎 be the function address 𝐹.module.funcaddrs[𝑥]. -4. Invoke the function instance at address 𝑎. - -Formal specification: - -𝐹.module.funcaddrs[𝑥] = 𝑎 ------------------------------------ -𝐹; (call 𝑥) -> 𝐹; (invoke 𝑎) -*/ - /** * 0x02 */ @@ -276,9 +259,27 @@ bool i_instr_return(Module *m) { return true; } -/** - * 0x10 call - */ +/* + +0x10 call + +Instruction: call funcidx + +Webassembly Description: + +1. Let 𝐹 be the current frame. +2. Assert: due to validation, 𝐹.module.funcaddrs[𝑥] exists. +3. Let 𝑎 be the function address 𝐹.module.funcaddrs[𝑥]. +4. Invoke the function instance at address 𝑎. + +Formal specification: + + 𝐹.module.funcaddrs[𝑥] = 𝑎 +----------------------------------- + 𝐹; (call 𝑥) -> 𝐹; (invoke 𝑎) + +*/ + bool i_instr_call(Module *m) { uint32_t fidx = read_LEB_32(&m->pc_ptr); @@ -686,7 +687,7 @@ bool i_instr_math_u64(Module *m, uint8_t opcode) { } /** - * 0x0d binop64 + * */ bool i_instr_math_f32(Module *m, uint8_t opcode) { float g = m->stack[m->sp - 1].value.f32; @@ -1265,276 +1266,3 @@ bool i_instr_callback(Module *m, uint8_t opcode) { // TODO return true; } - -bool interpret(Module *m, bool waiting) { - uint8_t *block_ptr; - uint8_t opcode; - - // keep track of occurring errors - bool success = true; - - // set to true when finishes successfully - bool program_done = false; - - while ((!program_done && success) || waiting) { - if (m->warduino->program_state == WARDUINOstep) { - m->warduino->debugger->pauseRuntime(m); - } - - while (m->warduino->program_state != WARDUINOinit && - m->warduino->debugger->checkDebugMessages( - m, &m->warduino->program_state)) { - } - fflush(stdout); - // esp_task_wdt_reset(); - - // Resolve 1 callback event if queue is not empty and VM not paused, and - // no event currently resolving - CallbackHandler::resolve_event(); - - // Sleep interpret loop if 'paused' or 'waiting drone' - if (m->warduino->program_state == WARDUINOpause || - m->warduino->program_state == PROXYhalt) { - // wait until new debug messages arrive - if (m->warduino->program_state == WARDUINOpause) { - warduino::unique_lock lock( - m->warduino->debugger->messageQueueMutex); - m->warduino->debugger->messageQueueConditionVariable.wait( - lock, [m] { return m->warduino->debugger->freshMessages; }); - } - continue; - } - - // Program state is not paused - - // If BP and not the one we just unpaused - if (m->warduino->debugger->isBreakpoint(m->pc_ptr) && - m->warduino->debugger->skipBreakpoint != m->pc_ptr && - m->warduino->program_state != PROXYrun) { - m->warduino->debugger->pauseRuntime(m); - m->warduino->debugger->notifyBreakpoint(m, m->pc_ptr); - continue; - } - m->warduino->debugger->skipBreakpoint = nullptr; - - // Take snapshot before executing an instruction - m->warduino->debugger->sendAsyncSnapshots(m); - - opcode = *m->pc_ptr; - block_ptr = m->pc_ptr; - m->pc_ptr += 1; - - dbg_dump_stack(m); - dbg_trace(" PC: %p OPCODE: <%s> in %s\n", block_ptr, - opcode_repr(opcode), - m->pc_ptr > m->bytes && m->pc_ptr < m->bytes + m->byte_count - ? "module" - : "patch"); - - switch (opcode) { - // - // Control flow operators - // - case 0x00: // unreachable - sprintf(exception, "%s", "unreachable"); - success &= false; - case 0x01: // nop - continue; - case 0x02: // block - success &= i_instr_block(m, block_ptr); - continue; - case 0x03: // loop - success &= i_instr_loop(m, block_ptr); - continue; - case 0x04: // if - success &= i_instr_if(m, block_ptr); - continue; - case 0x05: // else - success &= i_instr_else(m); - continue; - case 0x0b: // end - success &= i_instr_end(m, &program_done); - continue; - case 0x0c: // br - success &= i_instr_br(m); - continue; - case 0x0d: // br_if - success &= i_instr_br_if(m); - continue; - case 0x0e: // br_table - success &= i_instr_br_table(m); - continue; - case 0x0f: // return - success &= i_instr_return(m); - continue; - - // - // Call operators - // - case 0x10: { // call - success &= i_instr_call(m); - continue; - } - case 0x11: { // call_indirect - success &= i_instr_call_indirect(m); - continue; - } - // - // Parametric operators - // - case 0x1a: // drop - success &= i_instr_drop(m); - continue; - case 0x1b: // select - success &= i_instr_select(m); - continue; - - // - // Variable access - // - case 0x20: // get_local - success &= i_instr_get_local(m); - continue; - case 0x21: // set_local - success &= i_instr_set_local(m); - continue; - case 0x22: // tee_local - success &= i_instr_tee_local(m); - continue; - case 0x23: // get_global - success &= i_instr_get_global(m); - continue; - case 0x24: // set_global - success &= i_instr_set_global(m); - continue; - - // - // Memory-related operators - // - case 0x3f: // current_memory - success &= i_instr_current_memory(m); - continue; - case 0x40: // grow_memory - success &= i_instr_grow_memory(m); - continue; - // Memory load operators - case 0x28 ... 0x35: - success &= i_instr_mem_load(m, opcode); - continue; - // Memory store operators - case 0x36 ... 0x3e: - success &= i_instr_mem_store(m, opcode); - continue; - - // - // Constants - // - case 0x41 ... 0x44: // i32.const - success &= i_instr_const(m, opcode); - continue; - - // - // Comparison operators - // - - // unary - case 0x45: // i32.eqz - case 0x50: // i64.eqz - success &= i_instr_unary_u32(m, opcode); - continue; - - // i32 binary - case 0x46 ... 0x4f: - success &= i_instr_math_u32(m, opcode); - continue; - case 0x51 ... 0x5a: - success &= i_instr_math_u64(m, opcode); - continue; - case 0x5b ... 0x60: - success &= i_instr_math_f32(m, opcode); - continue; - case 0x61 ... 0x66: - success &= i_instr_math_f64(m, opcode); - continue; - - // - // Numeric operators - // - - // unary i32 - case 0x67 ... 0x69: - success &= i_instr_unary_i32(m, opcode); - continue; - - // unary i64 - case 0x79 ... 0x7b: - success &= i_instr_unary_i64(m, opcode); - continue; - - case 0x8b ... 0x91: // unary f32 - case 0x99 ... 0x9f: // unary f64 - success &= i_instr_unary_floating(m, opcode); - continue; - - // i32 binary - case 0x6a ... 0x78: - success &= i_instr_binary_i32(m, opcode); - continue; - - // i64 binary - case 0x7c ... 0x8a: - success &= i_instr_binary_i64(m, opcode); - continue; - - // f32 binary - case 0x92 ... 0x98: - success &= i_instr_binary_f32(m, opcode); - continue; - - // f64 binary - case 0xa0 ... 0xa6: - success &= i_instr_binary_f64(m, opcode); - continue; - - // conversion operations - case 0xa7 ... 0xbb: - success &= i_instr_conversion(m, opcode); - continue; - - // callback operations - case 0xe0 ... 0xe3: - success &= i_instr_callback(m, opcode); - continue; - default: - sprintf(exception, "unrecognized opcode 0x%x", opcode); - if (m->options.return_exception) { - m->exception = strdup(exception); - } - return false; - } - } - - if (m->warduino->program_state == PROXYrun) { - dbg_info("Trap was thrown during proxy call.\n"); - RFC *rfc = m->warduino->debugger->topProxyCall(); - rfc->success = false; - rfc->exception = strdup(exception); - rfc->exception_size = strlen(exception); - m->warduino->debugger->sendProxyCallResult(m); - } - - // Resolve all unhandled callback events - while (CallbackHandler::resolving_event && CallbackHandler::resolve_event()) - ; - - dbg_trace("Interpretation ended %s with status %s\n", - program_done ? "expectedly" : "unexpectedly", - success ? "ok" : "error"); - if (!success && m->options.return_exception) { - m->exception = strdup(exception); - } else if (!success) { - FATAL("%s\n", exception); - } - - return success; -} diff --git a/src/Interpreter/instructions.h b/src/Interpreter/instructions.h index 54a80f1bd..1ac57d8c8 100644 --- a/src/Interpreter/instructions.h +++ b/src/Interpreter/instructions.h @@ -1,5 +1,204 @@ #include "../WARDuino.h" +// Defining the instruction constants + +#define UNREACHABLE 0x00 +#define NOP 0x01 +#define BLOCK_I 0x02 +#define LOOP 0x03 +#define IF 0x04 +#define ELSE 0x05 + +#define END 0x0b +#define BR 0x0c +#define BR_IF 0x0d +#define BR_TABLE 0x0e +#define RETURN 0x0f + +#define CALL 0x10 +#define CALL_INDIRECT 0x11 +#define DROP 0x1a +#define SELECT 0x1b +#define GET_LOCAL 0x20 +#define SET_LOCAL 0x21 +#define TEE_LOCAL 0x22 +#define GET_GLOBAL 0x23 +#define SET_GLOBAL 0x24 +#define CURRENT_MEMORY 0x3f +#define GROW_MEMORY 0x40 +#define MEMORY_LOAD_START 0x28 +#define MEMORY_LOAD_END 0x35 +#define MEMORY_STORE_START 0x36 +#define MEMORY_STORE_END 0x3e + +#define CONST_START 0x41 +#define CONST_END 0x44 + +#define I32_CONST 0x41 +#define I64_CONST 0x42 +#define F32_CONST 0x43 +#define F64_CONST 0x44 + +#define F32_ABS 0x8b +#define F32_NEG 0x8c +#define F32_CEIL 0x8d +#define F32_FLOOR 0x8e +#define F32_TRUNC 0x8f +#define F32_NEAREST 0x90 +#define F32_SQRT 0x91 +#define F64_ABS 0x99 +#define F64_NEG 0x9a +#define F64_CEIL 0x9b +#define F64_FLOOR 0x9c +#define F64_TRUNC 0x9d +#define F64_NEAREST 0x9e +#define F64_SQRT 0x9f + +// binary boolean operators I32 unsigned int +#define I32_EQ 0x46 +#define I32_NE 0x47 +#define I32_LT_S 0x48 +#define I32_LT_U 0x49 +#define I32_GT_S 0x4a +#define I32_GT_U 0x4b +#define I32_LE_S 0x4c +#define I32_LE_U 0x4d +#define I32_GE_S 0x4e +#define I32_GE_U 0x4f + +// binary boolean operators I64 +#define I64_EQ 0x51 +#define I64_NE 0x52 +#define I64_LT_S 0x53 +#define I64_LT_U 0x54 +#define I64_GT_S 0x55 +#define I64_GT_U 0x56 +#define I64_LE_S 0x57 +#define I64_LE_U 0x58 +#define I64_GE_S 0x59 +#define I64_GE_U 0x5a + +#define I32_ADD 0x6a +#define I32_SUB 0x6b +#define I32_MUL 0x6c +#define I32_DIV_S 0x6d +#define I32_DIV_U 0x6e +#define I32_REM_S 0x6f +#define I32_REM_U 0x70 +#define I32_AND 0x71 +#define I32_OR 0x72 +#define I32_XOR 0x73 +#define I32_SHL 0x74 +#define I32_SHR_S 0x75 +#define I32_SHR_U 0x76 +#define I32_ROTL 0x77 +#define I32_ROTR 0x78 + +#define F32_ADD 0x92 +#define F32_SUB 0x93 +#define F32_MUL 0x94 +#define F32_DIV 0x95 +#define F32_MIN 0x96 +#define F32_MAX 0x97 +#define F32_COPYSIGN 0x98 + +#define I64_ADD 0x7c +#define I64_SUB 0x7d +#define I64_MUL 0x7e +#define I64_DIV_S 0x7f +#define I64_DIV_U 0x80 +#define I64_REM_S 0x81 +#define I64_REM_U 0x82 +#define I64_AND 0x83 +#define I64_OR 0x84 +#define I64_XOR 0x85 +#define I64_SHL 0x86 +#define I64_SHR_S 0x87 +#define I64_SHR_U 0x88 +#define I64_ROTL 0x89 +#define I64_ROTR 0x8a + +#define F64_ADD 0xa0 +#define F64_SUB 0xa1 +#define F64_MUL 0xa2 +#define F64_DIV 0xa3 +#define F64_MIN 0xa4 +#define F64_MAX 0xa5 +#define F64_COPYSIGN 0xa6 + +#define I32_WRAP_I64 0xa7 +#define I32_TRUNC_F32_S 0xa8 +#define I32_TRUNC_F32_U 0xa9 +#define I32_TRUNC_F64_S 0xaa +#define I32_TRUNC_F64_U 0xab +#define I64_EXTEND_I32_S 0xac +#define I64_EXTEND_I32_U 0xad +#define I64_TRUNC_F32_S 0xae +#define I64_TRUNC_F32_U 0xaf +#define I64_TRUNC_F64_S 0xb0 +#define I64_TRUNC_F64_U 0xb1 +#define F32_CONVERT_I32_S 0xb2 +#define F32_CONVERT_I32_U 0xb3 +#define F32_CONVERT_I64_S 0xb4 +#define F32_CONVERT_I64_U 0xb5 +#define F32_DEMOTE_F64 0xb6 +#define F64_CONVERT_I32_S 0xb7 +#define F64_CONVERT_I32_U 0xb8 +#define F64_CONVERT_I64_S 0xb9 +#define F64_CONVERT_I64_U 0xba +#define F64_PROMOTE_F32 0xbb +#define I32_REINTERPRET_F32 0xbc +#define I64_REINTERPRET_F64 0xbd +#define F32_REINTERPRET_I32 0xbe +#define F64_REINTERPRET_I64 0xbf + +#define I32_EQ 0x46 +#define I32_NE 0x47 +#define I32_LT_S 0x48 +#define I32_LT_U 0x49 +#define I32_GT_S 0x4a +#define I32_GT_U 0x4b +#define I32_LE_S 0x4c +#define I32_LE_U 0x4d +#define I32_GE_S 0x4e +#define I32_GE_U 0x4f + +#define I64_EQ 0x51 +#define I64_NE 0x52 +#define I64_LT_S 0x53 +#define I64_LT_U 0x54 +#define I64_GT_S 0x55 +#define I64_GT_U 0x56 +#define I64_LE_S 0x57 +#define I64_LE_U 0x58 +#define I64_GE_S 0x59 +#define I64_GE_U 0x5a + +#define F64_EQ 0x61 +#define F64_NE 0x62 +#define F64_LT 0x63 +#define F64_GT 0x64 +#define F64_LE 0x65 +#define F64_GE 0x66 + +#define I64_CLZ 0x79 +#define I64_CTZ 0x7a +#define I64_POPCNT 0x7b + +#define I32_EQZ 0x45 +#define I64_EQZ 0x50 + +#define F32_EQ 0x5b +#define F32_NE 0x5c +#define F32_LT 0x5d +#define F32_GT 0x5e +#define F32_LE 0x5f +#define F32_GE 0x60 + +#define I32_CLZ 0x67 +#define I32_CTZ 0x68 +#define I32_POPCNT 0x69 + bool i_instr_block(Module *m, uint8_t *block_ptr); bool i_instr_loop(Module *m, uint8_t *block_ptr); diff --git a/src/Interpreter/interpreter.cpp b/src/Interpreter/interpreter.cpp index e3f368aea..be24d0ada 100644 --- a/src/Interpreter/interpreter.cpp +++ b/src/Interpreter/interpreter.cpp @@ -81,13 +81,13 @@ void Interpreter::setup_call(Module *m, uint32_t fidx) { push_block(m, func, m->sp - type->param_count); #if TRACE - dbg_warn(" >> fn0x%x(%d) %s(", fidx, fidx, + dbg_warn(" >> fn0x%x(%arg0_64) %s(", fidx, fidx, func->export_name ? func->export_name : "") for (int p = ((int)type->param_count) - 1; p >= 0; p--) { dbg_warn("%s%s", value_repr(&m->stack[m->sp - p]), p ? " " : ""); } - dbg_warn("), %d locals, %d results\n", func->local_count, + dbg_warn("), %arg0_64 locals, %arg0_64 results\n", func->local_count, type->result_count); #endif @@ -188,6 +188,1470 @@ bool Interpreter::load(Module *m, uint8_t type, uint32_t addr, return true; } +void Interpreter::threadedInterpreter(Module *m) { + /* + + -- DATA needed for executing instructions -- + + */ + // instruction states and local variables + uint8_t opcode; + uint8_t *block_ptr; + StackValue *target; + + // TODO check whether we can don't need all these variables with the correct + // type + // int32_t stack variables (shouldn't they be pointer to the stack?) + int32_t arg0; + int32_t arg1; + int32_t result; + + uint32_t arg0_uint; + uint32_t arg1_uint; + uint32_t result_uint; + + // doubles + double arg0_d; + double arg1_d; + double result_d; + // floats + float arg0_f; + float arg1_f; + // int64_t stack variables + float fresult; + uint64_t arg0_64; + uint64_t arg1_64; + + uint64_t arg0_int64_t; + uint64_t arg1_int64_t; + uint64_t result_uint64_t; + + uint32_t flags; + uint32_t offset; + uint32_t addr; + + // Block pointers + Block *block = nullptr; + uint32_t fidx; + std::__1::map::iterator block_itr; + + // Jump table for instruction dispatch + void *jumpTable[256] = {0}; + + // set all instructions to undefined + for (int i = 0; i < 256; i++) { + jumpTable[i] = &&undefinedInstruction; + } + + goto initJumpTable; + + /* + + -- INSTRUCTIONS -- + + */ + + /** + * 0x24 set_global + */ +i_instr_set_global: + arg0 = read_LEB_32(&m->pc_ptr); + m->globals[arg0] = m->stack[m->sp--]; +#if TRACE + debug(" - arg: 0x%x, got %s\n", arg, value_repr(&m->stack[m->sp + 1])); +#endif + goto nextInstruction; + +/** + * 0x11 call_indirect + */ +i_instr_call_indirect: + + // uint32_t tidx = + read_LEB_32(&m->pc_ptr); // TODO: use tidx? + /// (void)tidx; + + read_LEB(&m->pc_ptr, 1); // reserved immediate + arg0 = m->stack[m->sp--].value.uint32; + if (m->options.mangle_table_index) { + // val is the table address + the index (not sized for the + // pointer size) so get the actual (sized) index +#if TRACE + debug(" - entries: %p, original val: 0x%x, new val: 0x%x\n", + m->table.entries, val, + (uint32_t)((uint64_t)m->table.entries) - val); +#endif + // val = val - (uint32_t)((uint64_t)m->table.entries & 0xFFFFFFFF); + arg0 = arg0 - (uint32_t)((uint64_t)m->table.entries); + } + if (arg0 >= m->table.maximum) { + sprintf(exception, + "undefined element 0x%" PRIx32 " (max: 0x%" PRIx32 ") in table", + arg0, m->table.maximum); + exit(1); + } + + arg1 = m->table.entries[arg0]; +#if TRACE + debug(" - call_indirect tidx: %d, val: 0x%x, arg1: 0x%x\n", tidx, val, + arg1); +#endif + + if (arg1 < m->import_count) { + // THUNK thunk_out(m, arg1); // import/thunk call + } else { + Block *func = &m->functions[arg1]; + Type *ftype = func->type; + + if (m->csp >= CALLSTACK_SIZE) { + sprintf(exception, "call stack exhausted"); + exit(1); + } + + /* + The typesystem should have already validated the call + if (ftype->mask != m->types[tidx].mask) { + sprintf(exception, + "indirect call type mismatch (call type and function type " + "differ)"); + exit(1); + }*/ + + m->warduino->interpreter->setup_call(m, arg1); // regular function call + + /* + // Validate signatures match + if ((int)(ftype->param_count + func->local_count) != + m->sp - m->fp + 1) { + sprintf(exception, + "indirect call type mismatch (param counts differ)"); + exit(1); + } + + + + for (uint32_t f = 0; f < ftype->param_count; f++) { + if (ftype->params[f] != m->stack[m->fp + f].value_type) { + sprintf(exception, + "indirect call type mismatch (param types differ)"); + exit(1); + } + }*/ + +#if TRACE + debug( + " - tidx: %d, table idx: %d, " + "calling function arg1: %d at: 0x%p\n", + tidx, val, arg1, m->pc_ptr); +#endif + } + goto nextInstruction; + +i_instr_grow_memory: + read_LEB_32(&m->pc_ptr); // ignore reserved + arg0 = m->memory.pages; + arg1 = m->stack[m->sp].value.uint32; + m->stack[m->sp].value.uint32 = arg0; + if (arg1 == 0) { + goto nextInstruction; + } else if (arg1 + arg0 > m->memory.maximum) { + m->stack[m->sp].value.uint32 = static_cast(-1); + goto nextInstruction; + } + m->memory.pages += arg1; + m->memory.bytes = (uint8_t *)arecalloc( + m->memory.bytes, arg0 * PAGE_SIZE, m->memory.pages * PAGE_SIZE, + 1 /*sizeof(uint32_t)*/, "Module->memory.bytes", true); + goto nextInstruction; + +i_instr_br_table: + arg0 = read_LEB_32(&m->pc_ptr); + if (arg0 > BR_TABLE_SIZE) { + // TODO: check this prior to runtime + sprintf(exception, "br_table size %" PRIu32 " exceeds max %d\n", arg0, + BR_TABLE_SIZE); + // todo + exit(1); + } + for (uint32_t i = 0; i < arg0; i++) { + m->br_table[i] = read_LEB_32(&m->pc_ptr); + } + arg1 = read_LEB_32(&m->pc_ptr); + result = m->stack[m->sp--].value.int32; + + if (result >= 0 && result < (int32_t)arg0) { + arg1 = m->br_table[result]; + } + + m->csp -= arg1; + // set to end for pop_block + m->pc_ptr = m->callstack[m->csp].block->br_ptr; +#if TRACE + debug(" - count: %d, didx: %d, to: 0x%p\n", count, didx, m->pc_ptr); +#endif + goto nextInstruction; + +i_instr_mem_load: + flags = read_LEB_32(&m->pc_ptr); + offset = read_LEB_32(&m->pc_ptr); + addr = m->stack[m->sp--].value.uint32; + + if (flags != 2 && TRACE) { + dbg_info( + " - unaligned load - flags: 0x%x," + " offset: 0x%x, addr: 0x%x\n", + flags, offset, addr); + } + // TODO + m->warduino->interpreter->load(m, I32 + (0x28 - opcode), addr, offset); + goto nextInstruction; + +i_instr_mem_store: + target = &m->stack[m->sp--]; + flags = read_LEB_32(&m->pc_ptr); + offset = read_LEB_32(&m->pc_ptr); + + addr = m->stack[m->sp--].value.uint32; + + if (flags != 2 && TRACE) { + dbg_info( + " - unaligned store - flags: 0x%x," + " offset: 0x%x, addr: 0x%x, val: %s\n", + flags, offset, addr, value_repr(target)); + } + + if (offset + addr < addr && !m->options.disable_memory_bounds) { + m->warduino->interpreter->report_overflow( + m, m->memory.bytes + offset + addr); + } + + addr += offset; + m->warduino->interpreter->store(m, I32 + (0x36 - opcode), addr, *target); + goto nextInstruction; + +i_instr_const: + target = &m->stack[++m->sp]; + + switch (opcode) { + case I32_CONST: // i32.const + target->value_type = I32; + target->value.uint32 = read_LEB_signed(&m->pc_ptr, 32); + break; + case I64_CONST: // i64.const + target->value_type = I64; + target->value.int64 = read_LEB_signed(&m->pc_ptr, 64); + break; + case F32_CONST: // f32.const + target->value_type = F32; + memcpy(&target->value.uint32, m->pc_ptr, 4); + m->pc_ptr += 4; + break; + case F64_CONST: // f64.const + target->value_type = F64; + memcpy(&target->value.uint64, m->pc_ptr, 8); + m->pc_ptr += 8; + break; + default: + goto undefinedInstruction; + } + goto nextInstruction; + +/* + Set_local on the stack +*/ +set_local: + arg0 = read_LEB_32(&m->pc_ptr); + m->stack[m->fp + arg0] = m->stack[m->sp--]; + goto nextInstruction; + +get_local: + arg0 = read_LEB_32(&m->pc_ptr); + m->stack[++m->sp] = m->stack[m->fp + arg0]; + goto nextInstruction; + +tee_local: + arg0 = read_LEB_32(&m->pc_ptr); + m->stack[m->fp + arg0] = m->stack[m->sp]; + goto nextInstruction; + +loop: + read_LEB_32(&m->pc_ptr); // ignore block type + if (m->csp >= CALLSTACK_SIZE) { + sprintf(exception, "call stack exhausted"); + exit(1); + } + m->warduino->interpreter->push_block(m, m->block_lookup[block_ptr], m->sp); + goto nextInstruction; + +block: + read_LEB_32(&m->pc_ptr); // ignore block type + if (m->csp >= CALLSTACK_SIZE) { + sprintf(exception, "call stack exhausted"); + exit(1); + } + block_itr = m->block_lookup.find(block_ptr); + ASSERT(block_itr != m->block_lookup.end(), "could not find block"); + m->warduino->interpreter->push_block(m, block_itr->second, m->sp); + goto nextInstruction; + + /** + * 0x04 if + */ +i_instr_if: + read_LEB_32(&m->pc_ptr); // ignore block type + block = m->block_lookup[block_ptr]; + + if (m->csp >= CALLSTACK_SIZE) { + sprintf(exception, "call stack exhausted"); + exit(0); + } + m->warduino->interpreter->push_block(m, block, m->sp); + + arg0 = m->stack[m->sp--].value.uint32; + if (arg0 == 0) { // if false (I32) + // branch to else block or after end of if + if (block->else_ptr == nullptr) { + // no else block, pop if block and skip end + m->csp -= 1; + m->pc_ptr = block->br_ptr + 1; + } else { + m->pc_ptr = block->else_ptr; + } + } + // if true, keep going +#if TRACE + debug(" - arg0: 0x%x jump to 0x%x, block: %s\n", arg0, + (uint32_t)(m->pc_ptr - m->bytes), block_repr(block)); +#endif + goto nextInstruction; + +i_instr_drop: + m->sp--; + goto nextInstruction; + +/** + * 0x05 else + */ +i_instr_else: + block = m->callstack[m->csp].block; + m->pc_ptr = block->br_ptr; +#if TRACE + debug(" - of %s jump to 0x%p\n", block_repr(block), m->pc_ptr); +#endif + goto nextInstruction; + +i_instr_end: + block = m->warduino->interpreter->pop_block(m); + + if (block == nullptr) { + return; // an exception (set by pop_block) + } + + if (block->block_type == 0x00) { // Function + if (m->csp == -1) { + return; // break loop + } else { + // Keep going at return address + } + } else if (block->block_type == 0x01) { // init_expr + return; // // break loop + } else { + } + goto nextInstruction; + +i_instr_br_if: + // condition + arg0 = read_LEB_32(&m->pc_ptr); + arg1 = m->stack[m->sp--].value.uint32; + if (arg1) { // if true + m->csp -= arg0; + // set to end for pop_block + m->pc_ptr = m->callstack[m->csp].block->br_ptr; + } + goto nextInstruction; + +i_instr_br: + m->csp -= read_LEB_32(&m->pc_ptr); + // set to end for pop_block + m->pc_ptr = m->callstack[m->csp].block->br_ptr; + goto nextInstruction; + +call: + fidx = read_LEB_32(&m->pc_ptr); + if (fidx < m->import_count) { + // primitive call + ((Primitive)m->functions[fidx].func_ptr)(m); + } else { + if (m->csp >= CALLSTACK_SIZE) { + sprintf(exception, "call stack exhausted"); + exit(1); + } + // regular function call + m->warduino->interpreter->setup_call(m, fidx); + } + goto nextInstruction; + +ret: + while (m->csp >= 0 && m->callstack[m->csp].block->block_type != 0x00) { + m->csp--; + } + // Set the program count to the end of the function + // The actual pop_block and return is handled by the end opcode. + m->pc_ptr = m->callstack[0].block->end_ptr; + goto nextInstruction; + +i_instr_select: + arg0 = m->stack[m->sp--].value.uint32; + m->sp--; + if (!arg0) { // use a instead of b + m->stack[m->sp] = m->stack[m->sp + 1]; + } + goto nextInstruction; + +// Binary boolean operators 32 bit +i_instr_math_u32: + arg0_uint = m->stack[m->sp - 1].value.uint32; + arg1_uint = m->stack[m->sp].value.uint32; + m->sp -= 1; + switch (opcode) { + case I32_EQ: + result_uint = static_cast(arg0_uint == arg1_uint); + break; + case I32_NE: + result_uint = static_cast(arg0_uint != arg1_uint); + break; + case I32_LT_S: + result_uint = + static_cast((int32_t)arg0_uint < (int32_t)arg1_uint); + break; + case I32_LT_U: + result_uint = static_cast(arg0_uint < arg1_uint); + break; + case I32_GT_S: + result_uint = + static_cast((int32_t)arg0_uint > (int32_t)arg1_uint); + break; + case I32_GT_U: + result_uint = static_cast(arg0_uint > arg1_uint); + break; + case I32_LE_S: + result_uint = + static_cast((int32_t)arg0_uint <= (int32_t)arg1_uint); + break; + case I32_LE_U: + result_uint = static_cast(arg0_uint <= arg1_uint); + break; + case I32_GE_S: + result_uint = + static_cast((int32_t)arg0_uint >= (int32_t)arg1_uint); + break; + case I32_GE_U: + result_uint = static_cast(arg0_uint >= arg1_uint); + break; + default: + printf("ran into an undefined instruction:: 0x%02hhX ", opcode); + exit(1); + } + // m->stack[m->sp].value_type = I32; (This is already set to I32 in the + // stack) + m->stack[m->sp].value.uint32 = result_uint; + goto nextInstruction; + /// check arg0_64 + +i_instr_binary_i32: + // TODO: verify if this should not be done with int32_t instead + arg0_uint = m->stack[m->sp - 1].value.uint32; + arg1_uint = m->stack[m->sp].value.uint32; + m->sp -= 1; + + if (opcode >= 0x6d && opcode <= 0x70 && arg1_uint == 0) { + sprintf(exception, "integer divide by zero"); + exit(1); + } + switch (opcode) { + // case 0x6a: o = __builtin_add_overflow(a, b, &c); break; + // // i32.add case 0x6b: o = __builtin_sub_overflow(a, b, + // &c); break; // i32.sub + case I32_ADD: + result = arg0_uint + arg1_uint; + break; // i32.add + case I32_SUB: + result = arg0_uint - arg1_uint; + break; // i32.sub + case I32_MUL: + result = arg0_uint * arg1_uint; + break; // i32.mul + case I32_DIV_S: + if (arg0_uint == 0x80000000 && arg1_uint == (uint32_t)-1) { + sprintf(exception, "integer overflow"); + exit(1); + } + result = (int32_t)arg0_uint / (int32_t)arg1_uint; + break; // i32.div_s + case I32_DIV_U: + result = arg0_uint / arg1_uint; + break; // i32.div_u + case I32_REM_S: + if (arg0_uint == 0x80000000 && arg1_uint == (uint32_t)-1) { + result = 0; + } else { + result = (int32_t)arg0_uint % (int32_t)arg1_uint; + }; + break; // i32.rem_s + case I32_REM_U: + result = (uint32_t)(arg0_uint % arg1_uint); + break; // i32.rem_u + case I32_AND: + result = arg0_uint & arg1_uint; + break; // i32.and + case I32_OR: + result = arg0_uint | arg1_uint; + break; // i32.or + case I32_XOR: + result = arg0_uint ^ arg1_uint; + break; // i32.xor + case I32_SHL: + result = arg0_uint << arg1_uint; + break; // i32.shl + case I32_SHR_S: + result = (int32_t)arg0_uint >> + arg1_uint; // NOLINT(hicpp-signed-bitwise) + break; // i32.shr_s + case I32_SHR_U: + result = arg0_uint >> arg1_uint; + break; // i32.shr_u + case I32_ROTL: + result = rotl32(arg0_uint, arg1_uint); + break; // i32.rotl + case I32_ROTR: + result = rotr32(arg0_uint, arg1_uint); + break; // i32.rotr + default: + exit(1); + } + // m->stack[m->sp].value_type = I32; (This is already set to I32 in the + // stack) + m->stack[m->sp].value.uint32 = (uint32_t)result; + goto nextInstruction; + +math_binop_64_bool: + arg0_64 = m->stack[m->sp - 1].value.uint64; + arg1_64 = m->stack[m->sp].value.uint64; + m->sp -= 1; + switch (opcode) { + case I64_EQ: + result = static_cast(arg0_64 == arg1_64); + break; + case I64_NE: + result = static_cast(arg0_64 != arg1_64); + break; + case I64_LT_S: + result = static_cast((int64_t)arg0_64 < (int64_t)arg1_64); + break; + case I64_LT_U: + result = static_cast(arg0_64 < arg1_64); + break; + case I64_GT_S: + result = static_cast((int64_t)arg0_64 > (int64_t)arg1_64); + break; + case I64_GT_U: + result = static_cast(arg0_64 > arg1_64); + break; + case I64_LE_S: + result = + static_cast((int64_t)arg0_64 <= (int64_t)arg1_64); + break; + case I64_LE_U: + result = static_cast(arg0_64 <= arg1_64); + break; + case I64_GE_S: + result = + static_cast((int64_t)arg0_64 >= (int64_t)arg1_64); + break; + case I64_GE_U: + result = static_cast(arg0_64 >= arg1_64); + break; + default: + printf("ran into an undefined instruction:: 0x%02hhX ", opcode); + exit(1); + } + m->stack[m->sp].value_type = I32; + m->stack[m->sp].value.uint32 = result; + goto nextInstruction; + +i32_eqz: // i32.eqz + m->stack[m->sp].value.uint32 = + static_cast(m->stack[m->sp].value.uint32 == 0); + goto nextInstruction; + +i64_eqz: // i64.eqz + m->stack[m->sp].value_type = I32; + m->stack[m->sp].value.uint32 = + static_cast(m->stack[m->sp].value.uint64 == 0); + goto nextInstruction; + +i_instr_binary_i64: + arg0_int64_t = m->stack[m->sp - 1].value.uint64; + arg1_int64_t = m->stack[m->sp].value.uint64; + m->sp -= 1; + if (opcode >= 0x7f && opcode <= 0x82 && arg1_int64_t == 0) { + sprintf(exception, "integer divide by zero"); + exit(1); + } + switch (opcode) { + case I64_ADD: + result_uint64_t = arg0_int64_t + arg1_int64_t; + break; // i64.add + case I64_SUB: + result_uint64_t = arg0_int64_t - arg1_int64_t; + break; // i64.sub + case I64_MUL: + result_uint64_t = arg0_int64_t * arg1_int64_t; + break; // i64.mul + case I64_DIV_S: + if (arg0_int64_t == 0x8000000000000000 && + arg1_int64_t == (uint32_t)-1) { + sprintf(exception, "integer overflow"); + exit(1); + } + result_uint64_t = (int64_t)arg0_int64_t / (int64_t)arg1_int64_t; + break; // i64.div_s + case I64_DIV_U: + result_uint64_t = arg0_int64_t / arg1_int64_t; + break; // i64.div_u + case I64_REM_S: + if (arg0_int64_t == 0x8000000000000000 && + arg1_int64_t == (uint32_t)-1) { + result_uint64_t = 0; + } else { + result_uint64_t = (int64_t)arg0_int64_t % (int64_t)arg1_int64_t; + } + break; // i64.rem_s + case I64_REM_U: + result_uint64_t = arg0_int64_t % arg1_int64_t; + break; // i64.rem_u + case I64_AND: + result_uint64_t = arg0_int64_t & arg1_int64_t; + break; // i64.and + case I64_OR: + result_uint64_t = arg0_int64_t | arg1_int64_t; + break; // i64.or + case I64_XOR: + result_uint64_t = arg0_int64_t ^ arg1_int64_t; + break; // i64.xor + case I64_SHL: + result_uint64_t = arg0_int64_t << arg1_int64_t; + break; // i64.shl + case I64_SHR_S: + result_uint64_t = ((int64_t)arg0_int64_t) >> + arg1_int64_t; // NOLINT(hicpp-signed-bitwise) + break; // i64.shr_s + case I64_SHR_U: + result_uint64_t = arg0_int64_t >> arg1_int64_t; + break; // i64.shr_u + case I64_ROTL: + result_uint64_t = rotl64(arg0_int64_t, arg1_int64_t); + break; // i64.rotl + case I64_ROTR: + result_uint64_t = rotr64(arg0_int64_t, arg1_int64_t); + break; // i64.rotr + default: + printf("ran into an undefined instruction:: 0x%02hhX ", opcode); + exit(1); + } + m->stack[m->sp].value.uint64 = result_uint64_t; + + goto nextInstruction; + +i_instr_unary_u32: + switch (opcode) { + case I32_EQZ: // i32.eqz + m->stack[m->sp].value.uint32 = + static_cast(m->stack[m->sp].value.uint32 == 0); + break; + case I64_EQZ: // i64.eqz + m->stack[m->sp].value_type = I32; + m->stack[m->sp].value.uint32 = + static_cast(m->stack[m->sp].value.uint64 == 0); + break; + default: + goto undefinedInstruction; + } + goto nextInstruction; + + /* + i_instr_math_u32: + arg0 = m->stack[m->sp - 1].value.uint32; + arg1 = m->stack[m->sp].value.uint32; + result; + m->sp -= 1; + switch (opcode) { + case I32_EQ: + result = static_cast(arg0 == arg1); + break; // i32.eq + case I32_NE: + result = static_cast(arg0 != arg1); + break; // i32.ne + case I32_LT_S: + result = static_cast((int32_t)arg0 < (int32_t)arg1); + break; // i32.lt_s + case I32_LT_U: + result = static_cast(arg0 < arg1); + break; // i32.lt_u + case I32_GT_S: + result = static_cast((int32_t)arg0 > (int32_t)arg1); + break; // i32.gt_s + case I32_GT_U: + result = static_cast(arg0 > arg1); + break; // i32.gt_u + case I32_LE_S: + result = static_cast((int32_t)arg0 <= (int32_t)arg1); + break; // i32.le_s + case I32_LE_U: + result = static_cast(arg0 <= arg1); + break; // i32.le_u + case I32_GE_S: + result = static_cast((int32_t)arg0 >= (int32_t)arg1); + break; // i32.ge_s + case I32_GE_U: + result = static_cast(arg0 >= arg1); + break; // i32.ge_u + default: + goto undefinedInstruction; + } + m->stack[m->sp].value_type = I32; + m->stack[m->sp].value.uint32 = result; + goto nextInstruction; + */ + +i_instr_math_u64: + arg0_64 = m->stack[m->sp - 1].value.uint64; + arg1_64 = m->stack[m->sp].value.uint64; + result; + m->sp -= 1; + switch (opcode) { + case I64_EQ: + result = static_cast(arg0_64 == arg1_64); + break; // i64.eq + case I64_NE: + result = static_cast(arg0_64 != arg1_64); + break; // i64.ne + case I64_LT_S: + result = static_cast((int64_t)arg0_64 < (int64_t)arg1_64); + break; // i64.lt_s + case I64_LT_U: + result = static_cast(arg0_64 < arg1_64); + break; // i64.lt_u + case I64_GT_S: + result = static_cast((int64_t)arg0_64 > (int64_t)arg1_64); + break; // i64.gt_s + case I64_GT_U: + result = static_cast(arg0_64 > arg1_64); + break; // i64.gt_u + case I64_LE_S: + result = + static_cast((int64_t)arg0_64 <= (int64_t)arg1_64); + break; // i64.le_s + case I64_LE_U: + result = static_cast(arg0_64 <= arg1_64); + break; // i64.le_u + case I64_GE_S: + result = + static_cast((int64_t)arg0_64 >= (int64_t)arg1_64); + break; // i64.ge_s + case I64_GE_U: + result = static_cast(arg0_64 >= arg1_64); + break; // i64.ge_u + default: + goto undefinedInstruction; + } + m->stack[m->sp].value_type = I32; + m->stack[m->sp].value.uint32 = result; + goto nextInstruction; + +i_instr_math_f32: + arg0_f = m->stack[m->sp - 1].value.f32; + arg1_f = m->stack[m->sp].value.f32; + m->sp -= 1; + switch (opcode) { + case F32_EQ: + result = static_cast(arg0_f == arg1_f); + break; // f32.eq + case F32_NE: + result = static_cast(arg0_f != arg1_f); + break; // f32.ne + case F32_LT: + result = static_cast(arg0_f < arg1_f); + break; // f32.lt + case F32_GT: + result = static_cast(arg0_f > arg1_f); + break; // f32.gt + case F32_LE: + result = static_cast(arg0_f <= arg1_f); + break; // f32.le + case F32_GE: + result = static_cast(arg0_f >= arg1_f); + break; // f32.ge + default: + goto undefinedInstruction; + } + m->stack[m->sp].value_type = I32; + m->stack[m->sp].value.uint32 = result; + goto nextInstruction; + +i_instr_math_f64: + arg0_d = m->stack[m->sp - 1].value.f64; + arg1_d = m->stack[m->sp].value.f64; + m->sp -= 1; + switch (opcode) { + case F64_EQ: + result = static_cast(arg0_d == arg1_d); + break; // f64.eq + case F64_NE: + result = static_cast(arg0_d != arg1_d); + break; // f64.ne + case F64_LT: + result = static_cast(arg0_d < arg1_d); + break; // f64.lt + case F64_GT: + result = static_cast(arg0_d > arg1_d); + break; // f64.gt + case F64_LE: + result = static_cast(arg0_d <= arg1_d); + break; // f64.le + case F64_GE: + result = static_cast(arg0_d >= arg1_d); + break; // f64.ge + default: + goto undefinedInstruction; + } + m->stack[m->sp].value_type = I32; + m->stack[m->sp].value.uint32 = result; + goto nextInstruction; + +i_instr_unary_i32: + arg0 = m->stack[m->sp].value.uint32; + switch (opcode) { + case I32_CLZ: + result = arg0 == 0 ? 32 : __builtin_clz(arg0); + break; // i32.clz + case I32_CTZ: + result = arg0 == 0 ? 32 : __builtin_ctz(arg0); + break; // i32.ctz + case I32_POPCNT: + result = __builtin_popcount(arg0); + break; // i32.popcnt + default: + printf("ran into an undefined instruction:: 0x%02hhX ", opcode); + exit(1); + } + m->stack[m->sp].value.uint32 = result; + goto nextInstruction; + +i_instr_unary_i64: + arg0_64 = m->stack[m->sp].value.uint64; + switch (opcode) { + case I64_CLZ: + result_uint64_t = arg0_64 == 0 ? 64 : __builtin_clzll(arg0_64); + break; // i64.clz + case I64_CTZ: + result_uint64_t = arg0_64 == 0 ? 64 : __builtin_ctzll(arg0_64); + break; // i64.ctz + case I64_POPCNT: + result_uint64_t = __builtin_popcountll(arg0_64); + break; // i64.popcnt + default: + printf("ran into an undefined instruction:: 0x%02hhX ", opcode); + exit(1); + } + m->stack[m->sp].value.uint64 = result_uint64_t; + goto nextInstruction; + +i_instr_unary_floating: + switch (opcode) { + // unary f32 + case F32_ABS: + m->stack[m->sp].value.f32 = fabs(m->stack[m->sp].value.f32); + break; // f32.abs + case F32_NEG: + m->stack[m->sp].value.f32 = -m->stack[m->sp].value.f32; + break; // f32.neg + case F32_CEIL: + m->stack[m->sp].value.f32 = ceil(m->stack[m->sp].value.f32); + break; // f32.ceil + case F32_FLOOR: + m->stack[m->sp].value.f32 = floor(m->stack[m->sp].value.f32); + break; // f32.floor + case F32_TRUNC: + m->stack[m->sp].value.f32 = trunc(m->stack[m->sp].value.f32); + break; // f32.trunc + case F32_NEAREST: + m->stack[m->sp].value.f32 = rint(m->stack[m->sp].value.f32); + break; // f32.nearest + case F32_SQRT: + m->stack[m->sp].value.f32 = sqrt(m->stack[m->sp].value.f32); + break; // f32.sqrt + // unary f64 + case F64_ABS: + m->stack[m->sp].value.f64 = fabs(m->stack[m->sp].value.f64); + break; // f64.abs + case F64_NEG: + m->stack[m->sp].value.f64 = -m->stack[m->sp].value.f64; + break; // f64.neg + case F64_CEIL: + m->stack[m->sp].value.f64 = ceil(m->stack[m->sp].value.f64); + break; // f64.ceil + case F64_FLOOR: + m->stack[m->sp].value.f64 = floor(m->stack[m->sp].value.f64); + break; // f64.floor + case F64_TRUNC: + m->stack[m->sp].value.f64 = trunc(m->stack[m->sp].value.f64); + break; // f64.trunc + case F64_NEAREST: + m->stack[m->sp].value.f64 = rint(m->stack[m->sp].value.f64); + break; // f64.nearest + case F64_SQRT: + m->stack[m->sp].value.f64 = sqrt(m->stack[m->sp].value.f64); + break; // f64.sqrt + default: + printf("ran into an undefined instruction:: 0x%02hhX ", opcode); + exit(1); + } + + goto nextInstruction; + +i_instr_binary_f32: + arg0_f = m->stack[m->sp - 1].value.f32; + arg1_f = m->stack[m->sp].value.f32; + m->sp -= 1; + switch (opcode) { + case F32_ADD: + fresult = arg0_f + arg1_f; + break; // f32.add + case F32_SUB: + fresult = arg0_f - arg1_f; + break; // f32.sub + case F32_MUL: + fresult = arg0_f * arg1_f; + break; // f32.mul + case F32_DIV: + fresult = arg0_f / arg1_f; + break; // f32.div + case F32_MIN: + fresult = (float)wa_fmin(arg0_f, arg1_f); + break; // f32.min + case F32_MAX: + fresult = (float)wa_fmax(arg0_f, arg1_f); + break; // f32.max + case F32_COPYSIGN: + fresult = std::signbit(arg1_f) ? -fabs(arg0_f) : fabs(arg0_f); + break; // f32.copysign + default: + printf("ran into an undefined instruction:: 0x%02hhX ", opcode); + exit(1); + } + m->stack[m->sp].value.f32 = fresult; + goto nextInstruction; + +i_instr_binary_f64: + arg0_d = m->stack[m->sp - 1].value.f64; + arg1_d = m->stack[m->sp].value.f64; + m->sp -= 1; + switch (opcode) { + case F64_ADD: + result_d = arg0_d + arg1_d; + break; // f64.add + case F64_SUB: + result_d = arg0_d - arg1_d; + break; // f64.sub + case F64_MUL: + result_d = arg0_d * arg1_d; + break; // f64.mul + case F64_DIV: + result_d = arg0_d / arg1_d; + break; // f64.div + case F64_MIN: + result_d = wa_fmin(arg0_d, arg1_d); + break; // f64.min + case F64_MAX: + result_d = wa_fmax(arg0_d, arg1_d); + break; // f64.max + case F64_COPYSIGN: + result_d = std::signbit(arg1_d) ? -fabs(arg0_d) : fabs(arg0_d); + break; // f64.copysign + default: + printf("ran into an undefined instruction:: 0x%02hhX ", opcode); + exit(1); + } + m->stack[m->sp].value.f64 = result_d; + goto nextInstruction; + +/** + * + */ +i_instr_conversion: + switch (opcode) { + case I32_WRAP_I64: + m->stack[m->sp].value.uint64 &= 0x00000000ffffffff; + m->stack[m->sp].value_type = I32; + break; // i32.wrap/i64 + case I32_TRUNC_F32_S: + if (std::isnan(m->stack[m->sp].value.f32)) { + sprintf(exception, "invalid conversion to integer"); + exit(1); + } else if (m->stack[m->sp].value.f32 >= INT32_MAX || + m->stack[m->sp].value.f32 < INT32_MIN) { + sprintf(exception, "integer overflow"); + exit(1); + } + m->stack[m->sp].value.int32 = m->stack[m->sp].value.f32; + m->stack[m->sp].value_type = I32; + break; // i32.trunc_s/f32 + case I32_TRUNC_F32_U: + if (std::isnan(m->stack[m->sp].value.f32)) { + sprintf(exception, "invalid conversion to integer"); + exit(1); + } else if (m->stack[m->sp].value.f32 >= UINT32_MAX || + m->stack[m->sp].value.f32 <= -1) { + sprintf(exception, "integer overflow"); + exit(1); + } + m->stack[m->sp].value.uint32 = m->stack[m->sp].value.f32; + m->stack[m->sp].value_type = I32; + break; // i32.trunc_u/f32 + case I32_TRUNC_F64_S: + if (std::isnan(m->stack[m->sp].value.f64)) { + sprintf(exception, "invalid conversion to integer"); + exit(1); + } else if (m->stack[m->sp].value.f64 > INT32_MAX || + m->stack[m->sp].value.f64 < INT32_MIN) { + sprintf(exception, "integer overflow"); + exit(1); + } + m->stack[m->sp].value.int32 = m->stack[m->sp].value.f64; + m->stack[m->sp].value_type = I32; + break; // i32.trunc_s/f64 + case I32_TRUNC_F64_U: + if (std::isnan(m->stack[m->sp].value.f64)) { + sprintf(exception, "invalid conversion to integer"); + exit(1); + } else if (m->stack[m->sp].value.f64 > UINT32_MAX || + m->stack[m->sp].value.f64 <= -1) { + sprintf(exception, "integer overflow"); + exit(1); + } + m->stack[m->sp].value.uint32 = m->stack[m->sp].value.f64; + m->stack[m->sp].value_type = I32; + break; // i32.trunc_u/f64 + case I64_EXTEND_I32_S: + m->stack[m->sp].value.uint64 = m->stack[m->sp].value.uint32; + sext_32_64(&m->stack[m->sp].value.uint64); + m->stack[m->sp].value_type = I64; + break; // i64.extend_s/i32 + case I64_EXTEND_I32_U: + m->stack[m->sp].value.uint64 = m->stack[m->sp].value.uint32; + m->stack[m->sp].value_type = I64; + break; // i64.extend_u/i32 + case I64_TRUNC_F32_S: + if (std::isnan(m->stack[m->sp].value.f32)) { + sprintf(exception, "invalid conversion to integer"); + exit(1); + } else if (m->stack[m->sp].value.f32 >= INT64_MAX || + m->stack[m->sp].value.f32 < INT64_MIN) { + sprintf(exception, "integer overflow"); + exit(1); + } + m->stack[m->sp].value.int64 = m->stack[m->sp].value.f32; + m->stack[m->sp].value_type = I64; + break; // i64.trunc_s/f32 + case I64_TRUNC_F32_U: + if (std::isnan(m->stack[m->sp].value.f32)) { + sprintf(exception, "invalid conversion to integer"); + exit(1); + } else if (m->stack[m->sp].value.f32 >= UINT64_MAX || + m->stack[m->sp].value.f32 <= -1) { + sprintf(exception, "integer overflow"); + exit(1); + } + m->stack[m->sp].value.uint64 = m->stack[m->sp].value.f32; + m->stack[m->sp].value_type = I64; + break; // i64.trunc_u/f32 + case I64_TRUNC_F64_S: + if (std::isnan(m->stack[m->sp].value.f64)) { + sprintf(exception, "invalid conversion to integer"); + exit(1); + } else if (m->stack[m->sp].value.f64 >= INT64_MAX || + m->stack[m->sp].value.f64 < INT64_MIN) { + sprintf(exception, "integer overflow"); + exit(1); + } + m->stack[m->sp].value.int64 = m->stack[m->sp].value.f64; + m->stack[m->sp].value_type = I64; + break; // i64.trunc_s/f64 + case I64_TRUNC_F64_U: + if (std::isnan(m->stack[m->sp].value.f64)) { + sprintf(exception, "invalid conversion to integer"); + exit(1); + } else if (m->stack[m->sp].value.f64 >= UINT64_MAX || + m->stack[m->sp].value.f64 <= -1) { + sprintf(exception, "integer overflow"); + exit(1); + } + m->stack[m->sp].value.uint64 = m->stack[m->sp].value.f64; + m->stack[m->sp].value_type = I64; + break; // i64.trunc_u/f64 + case F32_CONVERT_I32_S: + m->stack[m->sp].value.f32 = m->stack[m->sp].value.int32; + m->stack[m->sp].value_type = F32; + break; // f32.convert_s/i32 + case F32_CONVERT_I32_U: + m->stack[m->sp].value.f32 = m->stack[m->sp].value.uint32; + m->stack[m->sp].value_type = F32; + break; // f32.convert_u/i32 + case F32_CONVERT_I64_S: + m->stack[m->sp].value.f32 = m->stack[m->sp].value.int64; + m->stack[m->sp].value_type = F32; + break; // f32.convert_s/i64 + case F32_CONVERT_I64_U: + m->stack[m->sp].value.f32 = m->stack[m->sp].value.uint64; + m->stack[m->sp].value_type = F32; + break; // f32.convert_u/i64 + case F32_DEMOTE_F64: + m->stack[m->sp].value.f32 = (float)m->stack[m->sp].value.f64; + m->stack[m->sp].value_type = F32; + break; // f32.demote/f64 + case F64_CONVERT_I32_S: + m->stack[m->sp].value.f64 = m->stack[m->sp].value.int32; + m->stack[m->sp].value_type = F64; + break; // f64.convert_s/i32 + case F64_CONVERT_I32_U: + m->stack[m->sp].value.f64 = m->stack[m->sp].value.uint32; + m->stack[m->sp].value_type = F64; + break; // f64.convert_u/i32 + case F64_CONVERT_I64_S: + m->stack[m->sp].value.f64 = m->stack[m->sp].value.int64; + m->stack[m->sp].value_type = F64; + break; // f64.convert_s/i64 + case F64_CONVERT_I64_U: + m->stack[m->sp].value.f64 = m->stack[m->sp].value.uint64; + m->stack[m->sp].value_type = F64; + break; // f64.convert_u/i64 + case F64_PROMOTE_F32: + m->stack[m->sp].value.f64 = m->stack[m->sp].value.f32; + m->stack[m->sp].value_type = F64; + break; // f64.promote/f32 + + // reinterpretations + case I32_REINTERPRET_F32: + m->stack[m->sp].value_type = I32; + break; // i32.reinterpret/f32 + case I64_REINTERPRET_F64: + m->stack[m->sp].value_type = I64; + break; // i64.reinterpret/f64 + case F32_REINTERPRET_I32: // memmove(&m->stack[m->sp].value.f32, + // &m->stack[m->sp].value.uint32, 4); + m->stack[m->sp].value_type = F32; + break; // f32.reinterpret/i32 + case F64_REINTERPRET_I64: + m->stack[m->sp].value_type = F64; + break; // f64.reinterpret/i64 + default: + exit(1); + } + + goto nextInstruction; + + // Administrative instructions + +/** + * 0x23 get_global + */ +i_instr_get_global: + arg0 = read_LEB_32(&m->pc_ptr); +#if TRACE + debug(" - arg: 0x%x, got %s\n", arg0, value_repr(&m->globals[arg0])); +#endif + m->stack[++m->sp] = m->globals[arg0]; + goto nextInstruction; + +nextInstruction: + /* + BIG DUMP OF OLD CODE + */ + + if (m->warduino->program_state == WARDUINOstep) { + m->warduino->debugger->pauseRuntime(m); + } + + while (m->warduino->program_state != WARDUINOinit && + m->warduino->debugger->checkDebugMessages( + m, &m->warduino->program_state)) { + } + fflush(stdout); + // esp_task_wdt_reset(); + + // Resolve 1 callback event if queue is not empty and VM not paused, and + // no event currently resolving + CallbackHandler::resolve_event(); + + // Sleep interpret loop if 'paused' or 'waiting drone' + if (m->warduino->program_state == WARDUINOpause || + m->warduino->program_state == PROXYhalt) { + // wait until new debug messages arrive + if (m->warduino->program_state == WARDUINOpause) { + warduino::unique_lock lock( + m->warduino->debugger->messageQueueMutex); + m->warduino->debugger->messageQueueConditionVariable.wait( + lock, [m] { return m->warduino->debugger->freshMessages; }); + } + goto nextInstruction; + } + + // Program state is not paused + + // If BP and not the one we just unpaused + if (m->warduino->debugger->isBreakpoint(m->pc_ptr) && + m->warduino->debugger->skipBreakpoint != m->pc_ptr && + m->warduino->program_state != PROXYrun) { + m->warduino->debugger->pauseRuntime(m); + m->warduino->debugger->notifyBreakpoint(m, m->pc_ptr); + goto nextInstruction; + } + m->warduino->debugger->skipBreakpoint = nullptr; + + // Take snapshot before executing an instruction + m->warduino->debugger->sendAsyncSnapshots(m); + + dbg_dump_stack(m); + dbg_trace(" <<<>><<>> PC: %p OPCODE: <%s> in %s\n", block_ptr, + opcode_repr(opcode), + m->pc_ptr > m->bytes && m->pc_ptr < m->bytes + m->byte_count + ? "module" + : "patch"); + + // END DUMP OF OLD CODE + opcode = *m->pc_ptr; + block_ptr = m->pc_ptr; + m->pc_ptr += 1; + goto *jumpTable[opcode]; + +undefinedInstruction: + printf("ran into an undefined instruction:: 0x%02hhX ", opcode); + exit(0); + +// initialize of the jump table should only happen once +initJumpTable: + jumpTable[NOP] = &&nextInstruction; + + // set the jump table for the instructions + jumpTable[I32_CONST] = &&i_instr_const; + jumpTable[I64_CONST] = &&i_instr_const; + jumpTable[F32_CONST] = &&i_instr_const; + jumpTable[F64_CONST] = &&i_instr_const; + + jumpTable[SET_LOCAL] = &&set_local; + jumpTable[GET_LOCAL] = &&get_local; + jumpTable[LOOP] = &&loop; + jumpTable[BLOCK_I] = &█ + jumpTable[END] = &&i_instr_end; + jumpTable[CALL] = &&call; + jumpTable[BR_IF] = &&i_instr_br_if; + jumpTable[BR] = &&i_instr_br; + jumpTable[RETURN] = &&ret; + jumpTable[TEE_LOCAL] = &&tee_local; + jumpTable[SELECT] = &&i_instr_select; + + jumpTable[BR_TABLE] = &&i_instr_br_table; + + // boolean instructions for 32 bit + jumpTable[I32_EQ] = &&i_instr_math_u32; + jumpTable[I32_NE] = &&i_instr_math_u32; + jumpTable[I32_LT_S] = &&i_instr_math_u32; + jumpTable[I32_LT_U] = &&i_instr_math_u32; + jumpTable[I32_GT_S] = &&i_instr_math_u32; + jumpTable[I32_GT_U] = &&i_instr_math_u32; + jumpTable[I32_LE_S] = &&i_instr_math_u32; + jumpTable[I32_LE_U] = &&i_instr_math_u32; + jumpTable[I32_GE_S] = &&i_instr_math_u32; + jumpTable[I32_GE_U] = &&i_instr_math_u32; + // boolean instructions for 64 bit + jumpTable[I64_EQ] = &&math_binop_64_bool; + jumpTable[I64_NE] = &&math_binop_64_bool; + jumpTable[I64_LT_S] = &&math_binop_64_bool; + jumpTable[I64_LT_U] = &&math_binop_64_bool; + jumpTable[I64_GT_S] = &&math_binop_64_bool; + jumpTable[I64_GT_U] = &&math_binop_64_bool; + jumpTable[I64_LE_S] = &&math_binop_64_bool; + jumpTable[I64_LE_U] = &&math_binop_64_bool; + jumpTable[I64_GE_S] = &&math_binop_64_bool; + jumpTable[I64_GE_U] = &&math_binop_64_bool; + // binop instructions for 32 bit + jumpTable[I32_ADD] = &&i_instr_binary_i32; + jumpTable[I32_SUB] = &&i_instr_binary_i32; + jumpTable[I32_MUL] = &&i_instr_binary_i32; + jumpTable[I32_DIV_S] = &&i_instr_binary_i32; + jumpTable[I32_DIV_U] = &&i_instr_binary_i32; + jumpTable[I32_REM_S] = &&i_instr_binary_i32; + jumpTable[I32_REM_U] = &&i_instr_binary_i32; + jumpTable[I32_AND] = &&i_instr_binary_i32; + jumpTable[I32_OR] = &&i_instr_binary_i32; + jumpTable[I32_XOR] = &&i_instr_binary_i32; + jumpTable[I32_SHL] = &&i_instr_binary_i32; + jumpTable[I32_SHR_S] = &&i_instr_binary_i32; + jumpTable[I32_SHR_U] = &&i_instr_binary_i32; + jumpTable[I32_ROTL] = &&i_instr_binary_i32; + jumpTable[I32_ROTR] = &&i_instr_binary_i32; + + jumpTable[F32_ADD] = &&i_instr_binary_f32; + jumpTable[F32_SUB] = &&i_instr_binary_f32; + jumpTable[F32_MUL] = &&i_instr_binary_f32; + jumpTable[F32_DIV] = &&i_instr_binary_f32; + jumpTable[F32_MIN] = &&i_instr_binary_f32; + jumpTable[F32_MAX] = &&i_instr_binary_f32; + jumpTable[F32_COPYSIGN] = &&i_instr_binary_f32; + + jumpTable[I64_ADD] = &&i_instr_binary_i64; + jumpTable[I64_SUB] = &&i_instr_binary_i64; + jumpTable[I64_MUL] = &&i_instr_binary_i64; + jumpTable[I64_DIV_S] = &&i_instr_binary_i64; + jumpTable[I64_DIV_U] = &&i_instr_binary_i64; + jumpTable[I64_REM_S] = &&i_instr_binary_i64; + jumpTable[I64_REM_U] = &&i_instr_binary_i64; + jumpTable[I64_AND] = &&i_instr_binary_i64; + jumpTable[I64_OR] = &&i_instr_binary_i64; + jumpTable[I64_XOR] = &&i_instr_binary_i64; + jumpTable[I64_SHL] = &&i_instr_binary_i64; + jumpTable[I64_SHR_S] = &&i_instr_binary_i64; + jumpTable[I64_SHR_U] = &&i_instr_binary_i64; + jumpTable[I64_ROTL] = &&i_instr_binary_i64; + jumpTable[I64_ROTR] = &&i_instr_binary_i64; + + jumpTable[F32_ABS] = &&i_instr_unary_floating; + jumpTable[F32_NEG] = &&i_instr_unary_floating; + jumpTable[F32_CEIL] = &&i_instr_unary_floating; + jumpTable[F32_FLOOR] = &&i_instr_unary_floating; + jumpTable[F32_TRUNC] = &&i_instr_unary_floating; + jumpTable[F32_NEAREST] = &&i_instr_unary_floating; + jumpTable[F32_SQRT] = &&i_instr_unary_floating; + jumpTable[F64_ABS] = &&i_instr_unary_floating; + jumpTable[F64_NEG] = &&i_instr_unary_floating; + jumpTable[F64_CEIL] = &&i_instr_unary_floating; + jumpTable[F64_FLOOR] = &&i_instr_unary_floating; + jumpTable[F64_TRUNC] = &&i_instr_unary_floating; + jumpTable[F64_NEAREST] = &&i_instr_unary_floating; + jumpTable[F64_SQRT] = &&i_instr_unary_floating; + + jumpTable[F64_ADD] = &&i_instr_binary_f64; + jumpTable[F64_SUB] = &&i_instr_binary_f64; + jumpTable[F64_MUL] = &&i_instr_binary_f64; + jumpTable[F64_DIV] = &&i_instr_binary_f64; + jumpTable[F64_MIN] = &&i_instr_binary_f64; + jumpTable[F64_MAX] = &&i_instr_binary_f64; + jumpTable[F64_COPYSIGN] = &&i_instr_binary_f64; + + jumpTable[I32_WRAP_I64] = &&i_instr_conversion; + jumpTable[I32_TRUNC_F32_S] = &&i_instr_conversion; + jumpTable[I32_TRUNC_F32_U] = &&i_instr_conversion; + jumpTable[I32_TRUNC_F64_S] = &&i_instr_conversion; + jumpTable[I32_TRUNC_F64_U] = &&i_instr_conversion; + jumpTable[I64_EXTEND_I32_S] = &&i_instr_conversion; + jumpTable[I64_EXTEND_I32_U] = &&i_instr_conversion; + jumpTable[I64_TRUNC_F32_S] = &&i_instr_conversion; + jumpTable[I64_TRUNC_F32_U] = &&i_instr_conversion; + jumpTable[I64_TRUNC_F64_S] = &&i_instr_conversion; + jumpTable[I64_TRUNC_F64_U] = &&i_instr_conversion; + jumpTable[F32_CONVERT_I32_S] = &&i_instr_conversion; + jumpTable[F32_CONVERT_I32_U] = &&i_instr_conversion; + jumpTable[F32_CONVERT_I64_S] = &&i_instr_conversion; + jumpTable[F32_CONVERT_I64_U] = &&i_instr_conversion; + jumpTable[F32_DEMOTE_F64] = &&i_instr_conversion; + jumpTable[F64_CONVERT_I32_S] = &&i_instr_conversion; + jumpTable[F64_CONVERT_I32_U] = &&i_instr_conversion; + jumpTable[F64_CONVERT_I64_S] = &&i_instr_conversion; + jumpTable[F64_CONVERT_I64_U] = &&i_instr_conversion; + jumpTable[F64_PROMOTE_F32] = &&i_instr_conversion; + jumpTable[I32_REINTERPRET_F32] = &&i_instr_conversion; + jumpTable[I64_REINTERPRET_F64] = &&i_instr_conversion; + jumpTable[F32_REINTERPRET_I32] = &&i_instr_conversion; + jumpTable[F64_REINTERPRET_I64] = &&i_instr_conversion; + + // math + /* jumpTable[I32_EQ] = &&i_instr_math_u32; + jumpTable[I32_NE] = &&i_instr_math_u32; + jumpTable[I32_LT_S] = &&i_instr_math_u32; + jumpTable[I32_LT_U] = &&i_instr_math_u32; + jumpTable[I32_GT_S] = &&i_instr_math_u32; + jumpTable[I32_GT_U] = &&i_instr_math_u32; + jumpTable[I32_LE_S] = &&i_instr_math_u32; + jumpTable[I32_LE_U] = &&i_instr_math_u32; + jumpTable[I32_GE_S] = &&i_instr_math_u32; + jumpTable[I32_GE_U] = &&i_instr_math_u32;*/ + + jumpTable[I64_EQ] = &&i_instr_math_u64; + jumpTable[I64_NE] = &&i_instr_math_u64; + jumpTable[I64_LT_S] = &&i_instr_math_u64; + jumpTable[I64_LT_U] = &&i_instr_math_u64; + jumpTable[I64_GT_S] = &&i_instr_math_u64; + jumpTable[I64_GT_U] = &&i_instr_math_u64; + jumpTable[I64_LE_S] = &&i_instr_math_u64; + jumpTable[I64_LE_U] = &&i_instr_math_u64; + jumpTable[I64_GE_S] = &&i_instr_math_u64; + jumpTable[I64_GE_U] = &&i_instr_math_u64; + + jumpTable[F64_EQ] = &&i_instr_math_f64; + jumpTable[F64_NE] = &&i_instr_math_f64; + jumpTable[F64_LT] = &&i_instr_math_f64; + jumpTable[F64_GT] = &&i_instr_math_f64; + jumpTable[F64_LE] = &&i_instr_math_f64; + jumpTable[F64_GE] = &&i_instr_math_f64; + + jumpTable[I64_CLZ] = &&i_instr_unary_i64; + jumpTable[I64_CTZ] = &&i_instr_unary_i64; + jumpTable[I64_POPCNT] = &&i_instr_unary_i64; + + jumpTable[I32_EQZ] = &&i32_eqz; + jumpTable[I64_EQZ] = &&i64_eqz; + + jumpTable[F32_EQ] = &&i_instr_math_f32; + jumpTable[F32_NE] = &&i_instr_math_f32; + jumpTable[F32_LT] = &&i_instr_math_f32; + jumpTable[F32_GT] = &&i_instr_math_f32; + jumpTable[F32_LE] = &&i_instr_math_f32; + jumpTable[F32_GE] = &&i_instr_math_f32; + + jumpTable[I32_CLZ] = &&i_instr_unary_i32; + jumpTable[I32_CTZ] = &&i_instr_unary_i32; + jumpTable[I32_POPCNT] = &&i_instr_unary_i32; + + jumpTable[CALL_INDIRECT] = &&i_instr_call_indirect; + jumpTable[GROW_MEMORY] = &&i_instr_grow_memory; + + jumpTable[SET_GLOBAL] = &&i_instr_set_global; + jumpTable[GET_GLOBAL] = &&i_instr_get_global; + + jumpTable[IF] = &&i_instr_if; + jumpTable[ELSE] = &&i_instr_else; + + jumpTable[DROP] = &&i_instr_drop; + + int i = MEMORY_LOAD_START; + while (i <= MEMORY_LOAD_END) { + jumpTable[i] = &&i_instr_mem_load; + i++; + } + + jumpTable[MEMORY_LOAD_END] = &&i_instr_mem_load; + + i = MEMORY_STORE_START; + while (i <= MEMORY_STORE_END) { + jumpTable[i] = &&i_instr_mem_store; + i++; + } + jumpTable[MEMORY_STORE_END] = &&i_instr_mem_store; + + goto nextInstruction; +} + bool Interpreter::interpret(Module *m, bool waiting) { uint8_t *block_ptr; uint8_t opcode; @@ -210,8 +1674,8 @@ bool Interpreter::interpret(Module *m, bool waiting) { fflush(stdout); // esp_task_wdt_reset(); - // Resolve 1 callback event if queue is not empty and VM not paused, and - // no event currently resolving + // Resolve 1 callback event if queue is not empty and VM not paused, + // and no event currently resolving CallbackHandler::resolve_event(); // Sleep interpret loop if 'paused' or 'waiting drone' @@ -257,24 +1721,24 @@ bool Interpreter::interpret(Module *m, bool waiting) { // // Control flow operators // - case 0x00: // unreachable + case UNREACHABLE: sprintf(exception, "%s", "unreachable"); success &= false; - case 0x01: // nop + case NOP: continue; - case 0x02: // block + case BLOCK_I: success &= i_instr_block(m, block_ptr); continue; - case 0x03: // loop + case LOOP: success &= i_instr_loop(m, block_ptr); continue; - case 0x04: // if + case IF: success &= i_instr_if(m, block_ptr); continue; - case 0x05: // else + case ELSE: // else success &= i_instr_else(m); continue; - case 0x0b: // end + case END: // end success &= i_instr_end(m, &program_done); continue; case 0x0c: // br @@ -428,7 +1892,9 @@ bool Interpreter::interpret(Module *m, bool waiting) { success &= i_instr_callback(m, opcode); continue; default: - sprintf(exception, "unrecognized opcode 0x%x", opcode); + printf("unrecognized opcode 0x%x \n", opcode); + + sprintf(exception, "unrecognized opcode 0x%x \n", opcode); if (m->options.return_exception) { m->exception = strdup(exception); } @@ -446,8 +1912,8 @@ bool Interpreter::interpret(Module *m, bool waiting) { } // Resolve all unhandled callback events - while (CallbackHandler::resolving_event && CallbackHandler::resolve_event()) - ; + while (CallbackHandler::resolving_event && + CallbackHandler::resolve_event()); dbg_trace("Interpretation ended %s with status %s\n", program_done ? "expectedly" : "unexpectedly", diff --git a/src/Interpreter/interpreter.h b/src/Interpreter/interpreter.h index d11260d34..7f36821b7 100644 --- a/src/Interpreter/interpreter.h +++ b/src/Interpreter/interpreter.h @@ -5,6 +5,7 @@ #include "../WARDuino/internals.h" class Interpreter { + public: /** * Push a new frame on to the call stack @@ -12,6 +13,7 @@ class Interpreter { * @param block * @param sp stack pointer to return to */ + void push_block(Module *m, Block *block, int sp); /** @@ -45,6 +47,9 @@ class Interpreter { */ bool interpret(Module *m, bool waiting = false); + // threaded interpreter test + void threadedInterpreter(Module *m); + /* Stateful operations * ************************************************************************/ @@ -52,6 +57,8 @@ class Interpreter { bool load(Module *m, uint8_t type, uint32_t addr, uint32_t offset); + + static void report_overflow(Module *m, uint8_t *maddr); protected: diff --git a/src/Primitives/arduino.cpp b/src/Primitives/arduino.cpp index 0100451ec..79c5789a2 100644 --- a/src/Primitives/arduino.cpp +++ b/src/Primitives/arduino.cpp @@ -25,17 +25,53 @@ #include "../WARDuino/CallbackHandler.h" #include "primitives.h" -// NEOPIXEL -#include -#define PIN 33 -#define NUMPIXELS 64 -Adafruit_NeoPixel pixels = - Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); #define delay_us(ms) delayMicroseconds(ms) #include SPIClass *spi = new SPIClass(); +#define DISPLAY + +#ifdef DISPLAY + +#include +#include + +#define TFT_RST 18 +#define TFT_CLK 19 +#define TFT_DC 21 +#define TFT_CS 22 +#define TFT_MOSI 23 +#define TFT_MISO 25 + +#define LCD_BL 5 // BL --> LEDK + +Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO); + + +void setupDisplay() { + // Enable backlight. + pinMode(LCD_BL, OUTPUT); + digitalWrite(LCD_BL, LOW); + tft.begin(); + + printf("STARTING DISPLAY\n" ); + + tft.fillScreen(ILI9341_GREEN); + + tft.setCursor(0, 0); + tft.setTextColor(ILI9341_WHITE); + tft.setTextSize(1); + tft.println("Hello World!"); + + + +} + + +#endif + + // Hardware SPI void write_spi_byte(unsigned char c) { spi->beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0)); @@ -132,7 +168,22 @@ int resolve_isr(int pin) { // Primitives #define NUM_PRIMITIVES 0 -#define NUM_PRIMITIVES_ARDUINO 38 +#define NUM_PRIMITIVES_ARDUINO 36 + + +// NEOPIXEL (TODO fix primitives API) +#ifdef NEOPIXEL + +#include +#define PIN 33 +#define NUMPIXELS 64 +Adafruit_NeoPixel pixels = + Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); + +#define NUM_PRIMITIVES_ARDUINO = 40; + +#endif + #define ALL_PRIMITIVES (NUM_PRIMITIVES + NUM_PRIMITIVES_ARDUINO) @@ -486,6 +537,8 @@ def_prim(chip_digital_write, twoToNoneU32) { yield(); uint8_t pin = arg1.uint32; uint8_t val = arg0.uint32; + printf("chip_pin_write %i \n", pin); + digitalWrite(pin, val); pop_args(2); return true; @@ -549,6 +602,8 @@ def_prim(write_spi_bytes_16, twoToNoneU32) { return true; } +#ifdef NEOPIXEL + def_prim(init_pixels, NoneToNoneU32) { pixels.begin(); return true; @@ -575,6 +630,8 @@ def_prim(clear_pixels, NoneToNoneU32) { return true; } +#endif + // LED Control primitives def_prim(chip_ledc_set_duty, threeToNoneU32) { @@ -903,6 +960,30 @@ int32_t http_post_request(Module *m, const String url, const String body, return httpResponseCode; } + +//------------------------------------------------------ +// Display Primitives +//------------------------------------------------------ + +def_prim(display_init, NoneToNoneU32) { + setupDisplay(); + return true; +} + +def_prim(display_draw_rect, NoneToNoneU32) { + int16_t x = (int16_t)arg3.int32; + int16_t y = (int16_t)arg2.int32; + int16_t w = (int16_t)arg1.int32; + int16_t h = (int16_t)arg0.int32; + //uint16 color = arg0.uint32; + tft.drawRect(x, y, w, h, 0xFFFF); + printf("DRAW RECT x:%i y:%i w:%i h:%i\n", x,y,w,h); + + pop_args(4); + return true; +} + + //------------------------------------------------------ // Installing all the primitives & ISRs //------------------------------------------------------ @@ -975,16 +1056,25 @@ void install_primitives() { install_primitive(mqtt_unsubscribe); install_primitive(mqtt_loop); + + #ifdef NEOPIXEL + install_primitive(init_pixels); install_primitive(set_pixel_color); install_primitive(clear_pixels); install_primitive(show_pixels); + + #endif // temporary primitives needed for analogWrite in ESP32 install_primitive(chip_analog_write); install_primitive(chip_ledc_attach); install_primitive(chip_ledc_set_duty); + // Display primitives + install_primitive(display_init); + install_primitive(display_draw_rect); + dbg_info("INSTALLING ISRs\n"); install_isrs(); } diff --git a/src/WARDuino/CallbackHandler.cpp b/src/WARDuino/CallbackHandler.cpp index 210fe794f..4ba100ea3 100644 --- a/src/WARDuino/CallbackHandler.cpp +++ b/src/WARDuino/CallbackHandler.cpp @@ -196,8 +196,7 @@ Callback::Callback(Module *m, std::string id, uint32_t tidx) { } void Callback::resolve_event(const Event &e) { - dbg_trace("Callback(%s, %i): resolving Event(%s, \"%s\")\n", topic.c_str(), - table_index, e.topic.c_str(), e.payload); +// dbg_trace("Callback(%s, %i): resolving Event(%s, \"%s\")\n", topic.c_str(), table_index, e.topic.c_str(), e.payload); // Copy topic and payload to linear memory uint32_t start = 10000; // TODO use reserved area in linear memory diff --git a/src/WARDuino/WARDuino.cpp b/src/WARDuino/WARDuino.cpp index 215821c01..dd58341d9 100644 --- a/src/WARDuino/WARDuino.cpp +++ b/src/WARDuino/WARDuino.cpp @@ -269,7 +269,7 @@ void WARDuino::run_init_expr(Module *m, uint8_t type, uint8_t **pc) { // WARNING: running code here to get initial value! dbg_info(" running init_expr at 0x%p: %s\n", m->pc_ptr, block_repr(&block)); - interpreter->interpret(m); + interpreter->threadedInterpreter(m); *pc = m->pc_ptr; ASSERT(m->stack[m->sp].value_type == type, @@ -915,10 +915,10 @@ bool WARDuino::invoke(Module *m, uint32_t fidx, uint32_t arity, dbg_dump_stack(m); interpreter->setup_call(m, fidx); dbg_trace("Call setup\n"); - result = interpreter->interpret(m); + interpreter->threadedInterpreter(m); dbg_trace("Interpretation ended\n"); dbg_dump_stack(m); - return result; + return true; } void WARDuino::setInterpreter(Interpreter *interpreter) { diff --git a/src/WARDuino/internals.h b/src/WARDuino/internals.h index d0f6b2638..cf8e07f36 100644 --- a/src/WARDuino/internals.h +++ b/src/WARDuino/internals.h @@ -119,6 +119,7 @@ typedef struct Module { Memory memory; uint32_t global_count = 0; // number of globals StackValue *globals = nullptr; // globals + // Runtime state uint8_t *pc_ptr = nullptr; // program counter int sp = -1; // operand stack pointer diff --git a/tests/latch/latch-0.2.1.tgz b/tests/latch/latch-0.2.1.tgz deleted file mode 100644 index c33e08a81..000000000 Binary files a/tests/latch/latch-0.2.1.tgz and /dev/null differ diff --git a/tests/threading/run.cpp b/tests/threading/run.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/tutorials/assemblyscript/bin/main.debug.wasm.map b/tutorials/assemblyscript/bin/main.debug.wasm.map new file mode 100644 index 000000000..c46cd376b --- /dev/null +++ b/tutorials/assemblyscript/bin/main.debug.wasm.map @@ -0,0 +1 @@ +{"version":3,"sources":["~lib/rt/common.ts","~lib/as-warduino/assembly/index.ts","main/ascii.ts","~lib/util/number.ts","~lib/util/math.ts","~lib/util/string.ts","~lib/shared/runtime.ts","~lib/util/sort.ts","~lib/string.ts","~lib/rt/stub.ts","~lib/util/error.ts","~lib/number.ts","~lib/memory.ts","~lib/util/memory.ts"],"names":[],"mappings":"yYQ+pBmB,EAAb,EACa,EAAmC,EAAyB,EAA5C,CAAP,EAAT,CAAb,MACa,CAAb,EACA,IAAO,EAAS,EAAT,GACmB,EAAf,GAAT,EACI,EAAK,GAAL,CAAJ,EAEM,EAAkB,EAAD,CAAjB,CAAJ,EAA0B,GAC1B,EAAU,GAAV,GACS,EAAK,GAAL,CAAJ,EACL,EAAU,GAAV,GAEK,EAAK,IAAL,CAAgB,IAAjB,GAA2B,EAAS,EAAT,CAAa,EAAb,KAA/B,EACsB,EAAf,GAA4B,IAA5B,CAAuC,IAAxC,CAAJ,EACE,EAAU,GAAV,EAAa,EAAU,GAAV,EACb,IAGJ,EAAU,GAAV,IAEF,EAAU,GAAV,OAEK,EAAP,MCzqBc,EAAlB,EACkB,EAAsB,EAAtB,CAA4B,EAA7B,CAAyC,IAAD,CAAzC,CAAhB,EACI,EAAY,EAAZ,CAAJ,EAC4B,EAAY,EAAZ,CAAwB,IAAxB,CAAmC,MAAD,CAAnC,CAAgD,EAAvD,CAAlB,EACsB,IAAa,SAAjB,CAAlB,EACgB,EAAZ,EAA2B,EAA3B,CAAJ,EACkB,EAAZ,EAA2B,EAA3B,CAAJ,EAAkC,IAG7B,EAAT,iBAWI,EAAO,MAAP,CAAJ,EAA0C,cAC9B,EAAZ,EACU,EAAS,EAAT,CAAV,EACkB,EAAY,IATrB,EAAO,EAAP,CAAwB,EAAxB,CAAoC,IAAD,CAApC,CAAgD,EAAjD,CAAP,GASA,EACgB,EAAM,EAAN,CAAhB,EACA,EAAe,EAAf,EACO,EAAP,8CA+CI,EAAO,MAAP,CAAJ,EAA2C,eACzB,EAAkB,EAAlB,CAAR,EAAV,EACgC,EAAM,EAAzB,CAAb,EACA,EAAgB,EAAhB,EACA,EAAiB,EAAjB,EACA,EAAc,EAAd,EACA,EAAgB,EAAhB,EACO,EAAM,EAAN,CAAP,ID1C4B,EAA0B,EAA7C,GAAuE,EAAvE,CAAP,OA+oBe,EAAO,EAAc,EAAd,CAAP,CAAb,EACa,EAAb,EACA,IAAO,EAAM,EAAN,GACmB,EAAf,GAAT,EACI,EAAK,GAAL,CAAJ,EACY,EAAQ,EAAlB,GACA,OAEI,EAAkB,EAAD,CAAjB,CAAJ,EAAiC,EAAS,EAAT,CAAP,GACjB,EAAK,GAAL,CAAJ,EACI,EAAM,EAAN,CAAU,GAAV,CAAT,EACS,EAAK,EAAL,CAAU,GAAV,CAAT,EACW,EAAQ,EAAM,EAAN,CAAU,EAAV,CAAnB,GACA,EAAU,GAAV,GAQK,EAAK,IAAL,CAAgB,IAAjB,CAAJ,EACM,EAAK,IAAL,GAAe,EAAM,EAAN,CAAU,EAAV,KAAnB,EAC0B,EAAf,GAAT,EACK,EAAK,IAAL,CAAgB,IAAjB,CAAJ,EACO,IAAY,EAAK,GAAL,CAAgB,EAAjB,CAAX,CAAmC,EAAK,GAAL,CAAnC,CAAL,EACS,EAAM,EAAN,CAAW,GAAX,CAAT,EACS,EAAM,EAAN,CAAW,EAAX,CAAgB,GAAhB,CAAT,EACS,EAAM,EAAN,CAAW,EAAX,CAAgB,GAAhB,CAAT,EACS,EAAW,EAAX,CAAgB,GAAhB,CAAT,EACW,EAAQ,EAAM,EAAN,CAAW,EAAM,EAAN,CAAX,CAAsB,EAAM,EAAN,CAAtB,CAAgC,EAAhC,CAAnB,GACA,EAAU,GAAV,EAAa,EAAO,GAAP,EACb,IAGA,EAAa,EAAb,CAAJ,EACM,EAAa,EAAb,CAAJ,EAAkD,eAC7C,IAAL,IAGK,EAAM,EAAN,CAAW,GAAX,CAAT,EACS,EAAM,EAAN,CAAW,EAAX,CAAgB,GAAhB,CAAT,EACS,EAAW,EAAX,CAAgB,GAAhB,CAAT,EACW,EAAQ,EAAM,EAAN,CAAU,EAAV,CAAnB,GACU,EAAQ,EAAlB,GACA,EAAU,GAAV,IAEF,EAAO,GAAP,OAEE,EAAJ,EACY,WAAU,EAApB,IAEK,EAAS,EAAT,CAAP,MA5D0D,EAAK,EAAvB,EAAwC,EAAtE,EAAV,EACa,EAAwB,IAAY,EAAwB,EAAgB,IAAzF,CACO,EAAP,0BAHyD,KAA8B,gBPlkB1D,EAAM,QAAzB,EAAuD,EAAM,EAA7B,EAA5C,OOxGa,EAAO,EAAP,CAAb,EACmC,EAAK,EAAL,CAAkB,EAA3C,EAAV,EACW,EAAwB,EAAnC,GACI,EAAJ,EAAuB,EAAwB,EAAnC,IACL,EAAP,uBALyC,cLwHvC,EAAQ,IAAR,CAAJ,EACM,EAAQ,GAAR,CAAJ,EACS,EAAQ,EAAS,EAAb,CAAJ,CAAP,EAEO,EAAQ,EAAS,IAAb,CAAJ,CAA8B,EAAS,GAAb,CAA1B,CAAP,IAGE,EAAQ,KAAR,CAAJ,EACS,EAAQ,EAAS,IAAb,CAAJ,CAAP,EAEO,EAAQ,EAAS,MAAb,CAAJ,CAAmC,EAAS,KAAb,CAA/B,CAAP,aAyCJ,IAAO,EAAO,IAAP,GAEG,EAAM,IAAN,CAAR,EACQ,EAAM,IAAN,CAAR,EACM,EAAN,EAES,EAAI,GAAJ,CAAT,EACS,EAAI,GAAJ,CAAT,EAE6B,GAAU,EAAa,EAAb,CAAV,CAAf,GAAd,EAC6B,GAAU,EAAa,EAAb,CAAV,CAAf,GAAd,EAEA,EAAU,GAAV,EACW,EAAU,EAAU,EAAV,CAAV,CAAwB,EAAW,EAAW,EAAX,CAAX,CAAnC,QAGE,EAAO,GAAP,CAAJ,EACW,EAAM,GAAN,CAAT,EACS,EAAM,GAAN,CAAT,EACM,EAAN,EACA,EAAU,GAAV,EACuB,GAAU,EAAa,EAAb,CAAV,CAAV,GAAb,EACW,EAAU,EAAU,EAAV,CAAV,CAAwB,EAAnC,IAGE,EAAO,EAAP,CAAJ,EACE,EAAU,GAAV,EACuB,GAAU,EAAc,EAAd,CAAV,CAAV,GAAb,EACW,EAAU,EAAU,EAAV,CAAV,CAAwB,EAAnC,IAEA,EAAU,GAAV,EACY,EAAc,EAAd,CAAZ,EACW,EAAU,EAAU,EAAV,CAAV,CAAwB,EAAnC,OAoCF,IAAO,EAAU,EAAV,GACL,EAAU,GAAV,EAEE,EAAU,EAAU,EAAV,CAAV,CACU,KAAQ,CAAa,GAAb,CAAsB,EAAvB,CAAP,CAAV,GAFF,GAIA,EAAQ,GAAR,OAEE,EAAS,EAAT,CAAJ,EACa,EAAkB,KAAO,CAAc,EAAd,CAAP,CAAV,GAAnB,YA9FE,EAAW,IAxCE,EAAV,CAAoB,EAApB,CAAP,GAwCA,EACU,EAAc,GAAT,CAAL,CAAuB,EAAc,EAAT,CAAL,CAAxB,CAA+C,EAA/C,CAAP,IAEQ,GAAe,IAAc,IACvC,IAAO,EAAO,EAAP,GACL,EAAO,GAAP,EACA,EAAK,GAAL,EACA,EAAM,GAAN,OAEF,IAAO,EAAO,EAAP,GACL,EAAO,GAAP,EACA,YAEK,EAAI,EAAJ,CAAP,SAoJW,CAAX,EACK,EAAS,EAAQ,EAAR,CAAT,CAAwB,EAAzB,CAAJ,EACsB,EAAJ,CAAa,GAAjB,CAAZ,EACW,EAAO,EAAP,CAAX,EACA,EACE,OACW,EAAU,EAAU,EAAV,CAAV,CAAkC,GAAa,EAAM,GAAZ,CAAqB,EAArB,CAAP,CAAV,GAAnC,GACA,EAAQ,GAAR,EACO,SAET,EACE,OACQ,EAAM,EAAN,CAAR,EACW,EAAU,EAAU,EAAV,CAAV,CAAkC,GAAa,EAAM,EAAI,EAAJ,EAAZ,CAAyB,EAAzB,CAAP,CAAV,GAAnC,GACM,EAAN,EACO,eA4BP,EAAQ,EAAR,MAAa,EAAQ,EAAR,EAAjB,EACuB,eAElB,EAAD,CAAJ,EAAmB,GAAP,EAEA,EAAU,EAAV,CAAiB,EAAlB,CAAX,EACI,EAAJ,IAAmB,EAAD,CAAR,GAGN,EAAS,EAAT,CAAJ,EACgC,EAAf,EAAf,EACgC,EAAY,EAAZ,CAAiB,EAAlB,CAAwB,EAAjD,EAAN,EACA,EAAgB,EAAyB,EAAzB,GAA+B,IAAO,IA9FpD,EAAoB,EAApB,EAGa,EAAQ,EAAK,EADvB,IA6FI,EAAS,EAAT,CAAJ,EACW,EAAS,EAAJ,CAAL,CAAmB,EAAnB,CAAwB,EAAzB,CAAf,EACgC,EAAY,EAAZ,CAAiB,EAAlB,CAAwB,EAAjD,EAAN,EACA,EAAgB,EAAyB,EAAzB,GAA+B,IAAO,IAxFpD,EAAoB,EAApB,EAGW,IAAQ,CAAK,EADrB,IAwFO,EAAZ,IACyB,CAAO,EAAjB,EAAf,EACgC,EAAY,EAAZ,CAAiB,EAAlB,CAAwB,EAAjD,EAAN,EACgB,EAAyB,EAAzB,GAA+B,CAAO,EAAU,EAAhE,IAEE,EAAJ,EAAqB,EAAwB,EAAnC,IACH,EAAP,IQ7TgB,EAAM,EAAb,EAAP,OE1EF,IAAO,IAAM,EAAM,EAAN,OACD,WAAiB,WAAT,GAAlB,GACA,YAIG,EAAO,EAAP,CAAa,EAAd,CAAJ,EACE,IAAO,EAAK,EAAL,GACM,EAAqB,EAAV,GAAtB,GACW,EAAQ,EAAR,CAAqB,EAAO,EAAP,CAAV,GAAtB,GACW,EAAQ,EAAR,CAAqB,EAAO,EAAP,CAAV,GAAtB,GACW,EAAO,EAAP,CAAqB,EAAM,EAAN,CAAV,GAAtB,GACA,EAAO,GAAP,EAAW,EAAQ,GAAR,EAAY,EAAK,GAAL,OAErB,EAAI,EAAJ,CAAJ,EACa,EAAoB,EAAV,GAArB,GACW,EAAO,EAAP,CAAoB,EAAM,EAAN,CAAV,GAArB,GACA,EAAQ,GAAR,EAAW,EAAO,GAAP,GAET,EAAI,EAAJ,CAAJ,EACa,EAAgB,EAAV,GAAjB,GACA,EAAQ,GAAR,EAAW,EAAO,GAAP,GAET,EAAI,EAAJ,CAAJ,EACa,EAAgB,EAAV,GAAjB,GACA,EAAQ,GAAR,EAAW,EAAO,GAAP,GAET,EAAI,EAAJ,CAAJ,EACY,WAAiB,WAAT,GAAlB,IAEF,EAKE,EAAK,EAAL,CAAJ,EACE,QAAQ,EAAY,EAAZ,KAED,OAmBA,OAkBA,QArCG,AACQ,EAAV,GAAJ,EACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACA,EAAK,GAAL,EACA,IAAO,EAAK,EAAL,GACS,EAAM,EAAN,CAAV,GAAJ,EACW,EAAM,EAAK,EAAL,CAAU,EAAK,EAAL,CAAV,CAAjB,GACc,EAAM,EAAN,CAAV,GAAJ,EACW,EAAO,EAAP,CAAU,EAAK,EAAL,CAAU,EAAK,EAAL,CAAV,CAArB,GACc,EAAM,EAAN,CAAV,GAAJ,EACW,EAAO,EAAP,CAAU,EAAK,EAAL,CAAU,EAAK,EAAL,CAAV,CAArB,GACc,EAAM,EAAN,CAAV,GAAJ,EACW,EAAO,EAAP,CAAW,EAAK,EAAL,CAAU,EAAK,EAAL,CAAV,CAAtB,GACA,EAAO,GAAP,EAAW,EAAQ,GAAR,EAAY,EAAK,GAAL,OAEzB,GAEM,AACQ,EAAV,GAAJ,EACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACA,EAAK,GAAL,EACA,IAAO,EAAK,EAAL,GACS,EAAM,EAAN,CAAV,GAAJ,EACW,EAAM,EAAK,EAAL,CAAU,EAAK,EAAL,CAAV,CAAjB,GACc,EAAM,EAAN,CAAV,GAAJ,EACW,EAAO,EAAP,CAAU,EAAK,EAAL,CAAU,EAAK,EAAL,CAAV,CAArB,GACc,EAAM,EAAN,CAAV,GAAJ,EACW,EAAO,EAAP,CAAU,EAAK,EAAL,CAAU,EAAK,EAAL,CAAV,CAArB,GACc,EAAM,EAAN,CAAV,GAAJ,EACW,EAAO,EAAP,CAAW,EAAK,EAAL,CAAU,EAAK,EAAL,CAAV,CAAtB,GACA,EAAO,GAAP,EAAW,EAAQ,GAAR,EAAY,EAAK,GAAL,OAEzB,GAEM,AACQ,EAAV,GAAJ,EACU,WAAiB,WAAT,GAAlB,GACA,EAAK,GAAL,EACA,IAAO,EAAK,EAAL,GACS,EAAM,EAAN,CAAV,GAAJ,EACW,EAAM,EAAK,EAAL,CAAS,EAAK,EAAL,CAAT,CAAjB,GACc,EAAM,EAAN,CAAV,GAAJ,EACW,EAAO,EAAP,CAAU,EAAK,EAAL,CAAS,EAAK,EAAL,CAAT,CAArB,GACc,EAAM,EAAN,CAAV,GAAJ,EACW,EAAO,EAAP,CAAU,EAAK,EAAL,CAAS,EAAK,EAAL,CAAT,CAArB,GACc,EAAM,EAAN,CAAV,GAAJ,EACW,EAAO,EAAP,CAAW,EAAK,EAAL,CAAS,EAAK,EAAL,CAAT,CAAtB,GACA,EAAO,GAAP,EAAW,EAAQ,GAAR,EAAY,EAAK,GAAL,OAEzB,IAMF,EAAI,EAAJ,CAAJ,EACY,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,IAEE,EAAI,EAAJ,CAAJ,EACY,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,IAEE,EAAI,EAAJ,CAAJ,EACY,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,IAEE,EAAI,EAAJ,CAAJ,EACY,WAAiB,WAAT,GAAlB,GACU,WAAiB,WAAT,GAAlB,IAEE,EAAI,EAAJ,CAAJ,EACY,WAAiB,WAAT,GAAlB,UDhHA,EAAQ,IAAK,IAAK,ICuHhB,EAAQ,EAAR,CAAJ,EAAiB,GACb,EAAmB,EAAnB,EACE,EAAM,EAAN,CAAa,EAAb,GAAoB,EAAK,EAAL,CAAF,CAAlB,CADoB,EAEf,EAAM,EAAK,EAAlB,EACA,GAGA,EAAO,EAAP,CAAJ,EACM,EAAmB,EAAnB,EACG,EAAM,EAAN,CAAa,EAAO,EAAP,CAAd,CADoB,EAEtB,IAAO,EAAO,EAAP,GACA,EAAD,CAAJ,EAAQ,GACN,KAAF,EACU,WAAiB,WAAT,GAAlB,QAEF,IAAO,EAAK,EAAL,GACM,EAAgB,EAAV,GAAjB,GACA,EAAQ,GAAR,EACA,EAAQ,GAAR,EACA,EAAQ,GAAR,QAIN,IAAO,IACK,WAAiB,WAAT,GAAlB,GACE,KAAF,QAGE,EAAmB,EAAnB,EACG,EAAM,EAAN,CAAa,EAAO,EAAP,CAAd,CADoB,EAEtB,IAAQ,EAAO,EAAP,CAAY,EAAb,GACA,EAAD,CAAJ,EAAQ,GACE,EAAS,KAAF,EAAP,CAAqB,EAAM,EAAN,CAAT,GAAtB,QAEF,IAAO,EAAK,EAAL,GACL,EAAK,GAAL,EACW,EAAO,EAAP,CAAoB,EAAM,EAAN,CAAV,GAArB,SAIN,IAAO,IACK,EAAS,KAAF,EAAP,CAAqB,EAAM,EAAN,CAAT,GAAtB,eLlGoB,IAAe,EAAf,CAAtB,EACuB,IAAgB,EAAhB,CAAvB,EACqB,EAAW,EAAX,CAArB,EACI,EAAW,EAAX,CAAJ,EAAyB,GAAP,EACiB,EAAS,EAAlC,EAAV,EACY,EAAwB,EAAyB,EAA7D,EACY,EAAyB,EAAzB,CAAmC,EAA0B,EAAzE,EACO,EAAP,IAXO,EAAY,EAAZ,EAAP,MNlFM,EAAN,EACgB,EAAhB,EAEA,IAAO,EAAS,GAAT,GACuB,QAApB,EAAN,EAEM,GAAY,ESoES,ETpET,EAAZ,EAAN,EACM,GAAY,EAAc,EAAd,EAAZ,EAAN,EACM,GAAY,EAAc,EAAd,EAAZ,EAAN,EACM,GAAY,EAAc,EAAd,EAAZ,EAA+B,GAA/B,EAAN,EAEI,EAAQ,GAAR,CAAJ,IACS,IACL,MAIJ","sourceRoot":"./main.debug","sourcesContent":["// Alignment guarantees\n\n// @ts-ignore: decorator\n@inline export const AL_BITS: u32 = 4; // 16 bytes to fit up to v128\n// @ts-ignore: decorator\n@inline export const AL_SIZE: usize = 1 << AL_BITS;\n// @ts-ignore: decorator\n@inline export const AL_MASK: usize = AL_SIZE - 1;\n\n// Extra debugging\n\n// @ts-ignore: decorator\n@inline export const DEBUG = true;\n// @ts-ignore: decorator\n@inline export const TRACE = false;\n// @ts-ignore: decorator\n@inline export const RTRACE = isDefined(ASC_RTRACE);\n// @ts-ignore: decorator\n@inline export const PROFILE = isDefined(ASC_PROFILE);\n\n// Memory manager\n\n// ╒════════════ Memory manager block layout (32-bit) ═════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤\n// │ MM info │ -4\n// ╞>ptr═══════════════════════════════════════════════════════════╡\n// │ ... │\n@unmanaged export class BLOCK {\n /** Memory manager info. */\n mmInfo: usize;\n}\n\n/** Overhead of a memory manager block. */\n// @ts-ignore: decorator\n@inline export const BLOCK_OVERHEAD: usize = offsetof();\n\n/** Maximum size of a memory manager block's payload. */\n// @ts-ignore: decorator\n@inline export const BLOCK_MAXSIZE: usize = (1 << 30) - BLOCK_OVERHEAD;\n\n// Garbage collector\n\n// ╒══════════ Garbage collector object layout (32-bit) ═══════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤\n// │ Memory manager block │ -20\n// ╞═══════════════════════════════════════════════════════════════╡\n// │ GC info │ -16\n// ├───────────────────────────────────────────────────────────────┤\n// │ GC info │ -12\n// ├───────────────────────────────────────────────────────────────┤\n// │ RT id │ -8\n// ├───────────────────────────────────────────────────────────────┤\n// │ RT size │ -4\n// ╞>ptr═══════════════════════════════════════════════════════════╡\n// │ ... │\n@unmanaged export class OBJECT extends BLOCK {\n /** Garbage collector info. */\n gcInfo: u32;\n /** Garbage collector info. */\n gcInfo2: u32;\n /** Runtime class id. */\n rtId: u32;\n /** Runtime object size. */\n rtSize: u32;\n}\n\n/** Overhead of a garbage collector object. Excludes memory manager block overhead. */\n// @ts-ignore: decorator\n@inline export const OBJECT_OVERHEAD: usize = (offsetof() - BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK;\n\n/** Maximum size of a garbage collector object's payload. */\n// @ts-ignore: decorator\n@inline export const OBJECT_MAXSIZE: usize = BLOCK_MAXSIZE - OBJECT_OVERHEAD;\n\n/** Total of memory manager and garbage collector overhead. */\n// @ts-ignore: decorator\n@inline export const TOTAL_OVERHEAD: usize = BLOCK_OVERHEAD + OBJECT_OVERHEAD;\n","/**\n * as-warduino - WARDuino primitives library\n *\n *
\n *\n * WARDuino is a dynamic WebAssembly runtime for embedded devices, that\n * provides primitives to access hardware and IoT specific functionality.\n *\n * The `as-warduino` package allows using these primitives from AssemblyScript.\n *\n *
\n *\n * # Usage\n *\n * ```ts\n * import {pinMode, PinMode, PinVoltage, digitalWrite, delay} from \"as-warduino\";\n * \n * export function main(): void {\n * let led = 26;\n * pinMode(led, PinMode.OUTPUT);\n * \n * let pause: u32 = 1000;\n * while (true) {\n * digitalWrite(led, PinVoltage.HIGH);\n * delay(pause);\n * digitalWrite(led, PinVoltage.LOW);\n * delay(pause);\n * }\n * }\n * ```\n */\n\nimport * as ward from \"./warduino\";\n\n/** Returns the number of milliseconds passed since the current program started to run. */\nexport function millis(): u32 {\n return ward._millis();\n}\n/** Pauses the program for the amount of time (in milliseconds). */\nexport function delay(ms: u32): void {\n ward._delay(ms);\n}\n\n/** Pauses the program for the amount of time (in seconds). */\nexport function sleep(s: u32): void {\n ward._delay(s * 1000);\n}\n\n/** Reads the value from the specified analog pin. */\nexport function analogRead(pin: u32): i32 {\n return ward._analog_read(pin);\n}\n\n/** Write the value to the specified analog pin. */\nexport function analogWrite(pin: u32, signal: u32): void {\n ward._analog_write(pin, signal);\n}\n\nexport function analogSetup(channel: u32, frequency: u32, timer: u32): void {\n ward._analog_setup(channel, frequency, timer);\n}\n\nexport function analogAttach(pin: u32, channel: u32): void {\n ward._analog_attach(pin, channel);\n}\n\nexport function analogDuty(channel: u32, value: i32, max: u32): void {\n ward._analog_duty(channel, value, max);\n}\n\n/** The voltage of a digital pin. */\nexport enum PinVoltage {\n /** Low voltage on a digital I/O pin */\n LOW = 0,\n /** High voltage on a digital I/O pin */\n HIGH = 1,\n}\n\n/** The mode of a pin interrupt. */\nexport enum InterruptMode {\n /** Changing edge on a digital I/O pin */\n CHANGED = 1,\n /** Falling edge on a digital I/O pin */\n FALLING = 2,\n /** Rising edge on a digital I/O pin */\n RISING = 3,\n}\n\n/** The mode of a digital I/O pin. */\nexport enum PinMode {\n /** Input mode for digital pins */\n INPUT = 0x0,\n /** Output mode for digital pins */\n OUTPUT = 0x2,\n}\n\n/** Configures the [PinMode] of the specified pin. */\nexport function pinMode(pin: u32, mode: PinMode): void {\n ward._pin_mode(pin, mode);\n}\n\n/** Write the voltage to a specified digital pin, either [HIGH](PinVoltage) or [LOW](PinVoltage). */\nexport function digitalWrite(pin: u32, value: PinVoltage): void {\n ward._digital_write(pin, value);\n}\n\n/** Reads the value from a specified digital pin, either [HIGH](PinVoltage) or [LOW](PinVoltage). */\nexport function digitalRead(pin: u32): PinVoltage {\n return ward._digital_read(pin);\n}\n\n/** Subscribe a callback function to an interrupt on the given pin. */\nexport function interruptOn(pin: u32, mode: InterruptMode, fn: (topic: string, payload: string) => void): void {\n ward._subscribe_interrupt(pin, fn, mode);\n}\n\n/** Print a string to the serial port. */\nexport function print(text: string): void {\n ward._print(String.UTF8.encode(text, true), String.UTF8.byteLength(text, true));\n}\n\nexport namespace WiFi {\n export enum Status {\n /** No Wi-Fi hardware found */\n NoShield = 255,\n /** Wi-Fi is in process of changing between statuses */\n Idle = 0,\n /** Configured SSID cannot be reached */\n SsidUnavailable = 1,\n /** */\n ScanCompleted = 2,\n /** Successful connection is established */\n Connected = 3,\n /** Failed to connect */\n ConnectFailed = 4,\n /** No longer connected */\n ConnectionLost = 5,\n /** Module is not configured in station mode */\n Disconnected = 6,\n }\n\n /** Connect to Wi-Fi network with SSID and password. */\n function connect(ssid: string, password: string): void {\n ward._wifi_connect(String.UTF8.encode(ssid, true), String.UTF8.byteLength(ssid, true),\n String.UTF8.encode(password, true), String.UTF8.byteLength(password, true));\n }\n\n /** Returns the status of the Wi-Fi connection of the board. */\n function status(): Status {\n return ward._wifi_status();\n }\n\n /** Returns whether the board si still connected to Wi-Fi. */\n function connected(): bool {\n return status() === Status.Connected;\n }\n\n /** Returns the local IP address of the board. */\n function localip(): string {\n let localip = new ArrayBuffer(20);\n ward._wifi_localip(localip, localip.byteLength);\n return String.UTF8.decode(localip, true);\n }\n}\n\nexport namespace MQTT {\n export enum Status {\n /** The server didn't respond within the keepalive time */\n ConnectionTimeout = -4,\n /** The network connection was broken */\n ConnectionLost = -3,\n /** The network connection failed */\n ConnectFailed = -2,\n /** The client is disconnected cleanly */\n Disconnected = -1,\n /** The client is connected */\n Connected = 0,\n /** the server doesn't support the requested version of MQTT */\n ConnectBadProtocol = 1,\n /** The server rejected the client identifier */\n ConnectBadClientId = 2,\n /** The server was unable to accept the connection */\n ConnectUnavailable = 3,\n /** The username/password were rejected */\n ConnectBadCredentials = 4,\n /** The client was not authorized to connect */\n ConnectUnauthorized = 5,\n }\n\n /** Configure an MQTT broker. */\n function configureBroker(server: string, port: u32): void {\n ward._mqtt_init(String.UTF8.encode(server, true), String.UTF8.byteLength(server, true), port);\n }\n\n /** Connect to the Configured MQTT broker with client_id. */\n function connect(client_id: string): i32 {\n return ward._mqtt_connect(String.UTF8.encode(client_id, true), String.UTF8.byteLength(client_id, true));\n }\n\n /** Returns whether the board is still connected to the MQTT broker. */\n function connected(): bool {\n return status() === Status.Connected;\n }\n\n /** Returns the status of the connection to the MQTT broker. */\n function status(): Status {\n return ward._mqtt_state();\n }\n\n /** Publish a message on an MQTT topic. */\n function publish(topic: string, payload: string): i32 {\n return ward._mqtt_publish(String.UTF8.encode(topic, true), String.UTF8.byteLength(topic, true), String.UTF8.encode(payload, true), String.UTF8.byteLength(payload, true));\n }\n\n /** Subscribe a callback function to an MQTT topic. */\n function subscribe(topic: string, fn: (topic: string, payload: string) => void): i32 {\n return ward._mqtt_subscribe(topic, fn);\n }\n\n /** Unsubscribe a callback function from an MQTT topic. */\n function unsubscribe(topic: string, fn: (topic: string, payload: string) => void): i32 {\n return ward._mqtt_unsubscribe(topic, fn);\n }\n\n /** Check for messages from the MQTT broker. */\n function loop(): i32 {\n return ward._mqtt_loop();\n }\n}\n\nconst buffersizeMaximum: u32 = 1000;\n\nexport namespace HTTP {\n class PostOptions {\n url: string;\n body: string;\n content_type: string;\n authorization: string;\n\n constructor(url: string, body: string, content_type: string, authorization: string) {\n this.url = url; this.body = body; this.content_type = content_type; this.authorization = authorization;\n }\n }\n\n /** Send an HTTP GET request. The response is written to an ArrayBuffer. */\n function get(url: string): string {\n const response: ArrayBuffer = new ArrayBuffer(buffersizeMaximum);\n ward._http_get(String.UTF8.encode(url, true), String.UTF8.byteLength(url, true), response, response.byteLength);\n return String.UTF8.decode(response);\n }\n\n /** Send an HTTP POST request. The response is written to an ArrayBuffer. */\n function post(options: PostOptions): string {\n const response: ArrayBuffer = new ArrayBuffer(buffersizeMaximum);\n ward._http_post(String.UTF8.encode(options.url, true), String.UTF8.byteLength(options.url, true),\n String.UTF8.encode(options.body, true), String.UTF8.byteLength(options.body, true),\n String.UTF8.encode(options.content_type, true), String.UTF8.byteLength(options.content_type, true),\n String.UTF8.encode(options.authorization, true), String.UTF8.byteLength(options.authorization, true),\n response, response.byteLength);\n return String.UTF8.decode(response);\n }\n}\n","import {print} from \"as-warduino/assembly\";\n\nexport function main(): void {\n print(\"ASCII Table ~ Character Map\\n\");\n let byte: i32 = 33;\n\n while (byte !== 126) {\n print(String.fromCharCode(byte));\n\n print(\", dec: \" + byte.toString());\n print(\", hex: \" + byte.toString(16));\n print(\", oct: \" + byte.toString(8));\n print(\", bin: \" + byte.toString(2) + \"\\n\");\n\n if (byte == 126) {\n while (true) {\n continue;\n }\n }\n\n byte++;\n }\n}\n","/// \n\nimport { idof } from \"../builtins\";\nimport { CharCode } from \"./string\";\n\n// @ts-ignore: decorator\n@inline\nexport const MAX_DOUBLE_LENGTH = 28;\n\n// @ts-ignore: decorator\n@lazy @inline const POWERS10 = memory.data([\n 1,\n 10,\n 100,\n 1000,\n 10000,\n 100000,\n 1000000,\n 10000000,\n 100000000,\n 1000000000\n]);\n\n/*\n Lookup table for pairwise char codes in range [0-99]\n\n \"00\", \"01\", \"02\", \"03\", \"04\", \"05\", \"06\", \"07\", \"08\", \"09\",\n \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\",\n \"20\", \"21\", \"22\", \"23\", \"24\", \"25\", \"26\", \"27\", \"28\", \"29\",\n \"30\", \"31\", \"32\", \"33\", \"34\", \"35\", \"36\", \"37\", \"38\", \"39\",\n \"40\", \"41\", \"42\", \"43\", \"44\", \"45\", \"46\", \"47\", \"48\", \"49\",\n \"50\", \"51\", \"52\", \"53\", \"54\", \"55\", \"56\", \"57\", \"58\", \"59\",\n \"60\", \"61\", \"62\", \"63\", \"64\", \"65\", \"66\", \"67\", \"68\", \"69\",\n \"70\", \"71\", \"72\", \"73\", \"74\", \"75\", \"76\", \"77\", \"78\", \"79\",\n \"80\", \"81\", \"82\", \"83\", \"84\", \"85\", \"86\", \"87\", \"88\", \"89\",\n \"90\", \"91\", \"92\", \"93\", \"94\", \"95\", \"96\", \"97\", \"98\", \"99\"\n*/\n// @ts-ignore: decorator\n@lazy @inline const DIGITS = memory.data([\n 0x00300030, 0x00310030, 0x00320030, 0x00330030, 0x00340030,\n 0x00350030, 0x00360030, 0x00370030, 0x00380030, 0x00390030,\n 0x00300031, 0x00310031, 0x00320031, 0x00330031, 0x00340031,\n 0x00350031, 0x00360031, 0x00370031, 0x00380031, 0x00390031,\n 0x00300032, 0x00310032, 0x00320032, 0x00330032, 0x00340032,\n 0x00350032, 0x00360032, 0x00370032, 0x00380032, 0x00390032,\n 0x00300033, 0x00310033, 0x00320033, 0x00330033, 0x00340033,\n 0x00350033, 0x00360033, 0x00370033, 0x00380033, 0x00390033,\n 0x00300034, 0x00310034, 0x00320034, 0x00330034, 0x00340034,\n 0x00350034, 0x00360034, 0x00370034, 0x00380034, 0x00390034,\n 0x00300035, 0x00310035, 0x00320035, 0x00330035, 0x00340035,\n 0x00350035, 0x00360035, 0x00370035, 0x00380035, 0x00390035,\n 0x00300036, 0x00310036, 0x00320036, 0x00330036, 0x00340036,\n 0x00350036, 0x00360036, 0x00370036, 0x00380036, 0x00390036,\n 0x00300037, 0x00310037, 0x00320037, 0x00330037, 0x00340037,\n 0x00350037, 0x00360037, 0x00370037, 0x00380037, 0x00390037,\n 0x00300038, 0x00310038, 0x00320038, 0x00330038, 0x00340038,\n 0x00350038, 0x00360038, 0x00370038, 0x00380038, 0x00390038,\n 0x00300039, 0x00310039, 0x00320039, 0x00330039, 0x00340039,\n 0x00350039, 0x00360039, 0x00370039, 0x00380039, 0x00390039\n]);\n\n// Lookup table for pairwise char codes in range [0x00-0xFF]\n// @ts-ignore: decorator\n@lazy @inline const HEX_DIGITS =\n\"000102030405060708090a0b0c0d0e0f\\\n101112131415161718191a1b1c1d1e1f\\\n202122232425262728292a2b2c2d2e2f\\\n303132333435363738393a3b3c3d3e3f\\\n404142434445464748494a4b4c4d4e4f\\\n505152535455565758595a5b5c5d5e5f\\\n606162636465666768696a6b6c6d6e6f\\\n707172737475767778797a7b7c7d7e7f\\\n808182838485868788898a8b8c8d8e8f\\\n909192939495969798999a9b9c9d9e9f\\\na0a1a2a3a4a5a6a7a8a9aaabacadaeaf\\\nb0b1b2b3b4b5b6b7b8b9babbbcbdbebf\\\nc0c1c2c3c4c5c6c7c8c9cacbcccdcecf\\\nd0d1d2d3d4d5d6d7d8d9dadbdcdddedf\\\ne0e1e2e3e4e5e6e7e8e9eaebecedeeef\\\nf0f1f2f3f4f5f6f7f8f9fafbfcfdfeff\";\n\n// @ts-ignore: decorator\n@lazy @inline const ANY_DIGITS = \"0123456789abcdefghijklmnopqrstuvwxyz\";\n\n// @ts-ignore: decorator\n@lazy @inline const EXP_POWERS = memory.data([/* eslint-disable indent */\n -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980,\n -954, -927, -901, -874, -847, -821, -794, -768, -741, -715,\n -688, -661, -635, -608, -582, -555, -529, -502, -475, -449,\n -422, -396, -369, -343, -316, -289, -263, -236, -210, -183,\n -157, -130, -103, -77, -50, -24, 3, 30, 56, 83,\n 109, 136, 162, 189, 216, 242, 269, 295, 322, 348,\n 375, 402, 428, 455, 481, 508, 534, 561, 588, 614,\n 641, 667, 694, 720, 747, 774, 800, 827, 853, 880,\n 907, 933, 960, 986, 1013, 1039, 1066\n/* eslint-enable indent */]);\n\n// 1e-348, 1e-340, ..., 1e340\n// @ts-ignore: decorator\n@lazy @inline const FRC_POWERS = memory.data([\n 0xFA8FD5A0081C0288, 0xBAAEE17FA23EBF76, 0x8B16FB203055AC76, 0xCF42894A5DCE35EA,\n 0x9A6BB0AA55653B2D, 0xE61ACF033D1A45DF, 0xAB70FE17C79AC6CA, 0xFF77B1FCBEBCDC4F,\n 0xBE5691EF416BD60C, 0x8DD01FAD907FFC3C, 0xD3515C2831559A83, 0x9D71AC8FADA6C9B5,\n 0xEA9C227723EE8BCB, 0xAECC49914078536D, 0x823C12795DB6CE57, 0xC21094364DFB5637,\n 0x9096EA6F3848984F, 0xD77485CB25823AC7, 0xA086CFCD97BF97F4, 0xEF340A98172AACE5,\n 0xB23867FB2A35B28E, 0x84C8D4DFD2C63F3B, 0xC5DD44271AD3CDBA, 0x936B9FCEBB25C996,\n 0xDBAC6C247D62A584, 0xA3AB66580D5FDAF6, 0xF3E2F893DEC3F126, 0xB5B5ADA8AAFF80B8,\n 0x87625F056C7C4A8B, 0xC9BCFF6034C13053, 0x964E858C91BA2655, 0xDFF9772470297EBD,\n 0xA6DFBD9FB8E5B88F, 0xF8A95FCF88747D94, 0xB94470938FA89BCF, 0x8A08F0F8BF0F156B,\n 0xCDB02555653131B6, 0x993FE2C6D07B7FAC, 0xE45C10C42A2B3B06, 0xAA242499697392D3,\n 0xFD87B5F28300CA0E, 0xBCE5086492111AEB, 0x8CBCCC096F5088CC, 0xD1B71758E219652C,\n 0x9C40000000000000, 0xE8D4A51000000000, 0xAD78EBC5AC620000, 0x813F3978F8940984,\n 0xC097CE7BC90715B3, 0x8F7E32CE7BEA5C70, 0xD5D238A4ABE98068, 0x9F4F2726179A2245,\n 0xED63A231D4C4FB27, 0xB0DE65388CC8ADA8, 0x83C7088E1AAB65DB, 0xC45D1DF942711D9A,\n 0x924D692CA61BE758, 0xDA01EE641A708DEA, 0xA26DA3999AEF774A, 0xF209787BB47D6B85,\n 0xB454E4A179DD1877, 0x865B86925B9BC5C2, 0xC83553C5C8965D3D, 0x952AB45CFA97A0B3,\n 0xDE469FBD99A05FE3, 0xA59BC234DB398C25, 0xF6C69A72A3989F5C, 0xB7DCBF5354E9BECE,\n 0x88FCF317F22241E2, 0xCC20CE9BD35C78A5, 0x98165AF37B2153DF, 0xE2A0B5DC971F303A,\n 0xA8D9D1535CE3B396, 0xFB9B7CD9A4A7443C, 0xBB764C4CA7A44410, 0x8BAB8EEFB6409C1A,\n 0xD01FEF10A657842C, 0x9B10A4E5E9913129, 0xE7109BFBA19C0C9D, 0xAC2820D9623BF429,\n 0x80444B5E7AA7CF85, 0xBF21E44003ACDD2D, 0x8E679C2F5E44FF8F, 0xD433179D9C8CB841,\n 0x9E19DB92B4E31BA9, 0xEB96BF6EBADF77D9, 0xAF87023B9BF0EE6B\n]);\n\n// @ts-ignore: decorator\n@inline\nexport function isPowerOf2(value: T): bool {\n return popcnt(value) == 1;\n}\n\n// Count number of decimals for u32 values\n// In our case input value always non-zero so we can simplify some parts\nexport function decimalCount32(value: u32): u32 {\n if (value < 100000) {\n if (value < 100) {\n return 1 + u32(value >= 10);\n } else {\n return 3 + u32(value >= 10000) + u32(value >= 1000);\n }\n } else {\n if (value < 10000000) {\n return 6 + u32(value >= 1000000);\n } else {\n return 8 + u32(value >= 1000000000) + u32(value >= 100000000);\n }\n }\n}\n\n// Count number of decimals for u64 values\n// In our case input value always greater than 2^32-1 so we can skip some parts\nexport function decimalCount64High(value: u64): u32 {\n if (value < 1000000000000000) {\n if (value < 1000000000000) {\n return 10 + u32(value >= 100000000000) + u32(value >= 10000000000);\n } else {\n return 13 + u32(value >= 100000000000000) + u32(value >= 10000000000000);\n }\n } else {\n if (value < 100000000000000000) {\n return 16 + u32(value >= 10000000000000000);\n } else {\n return 18 + u32(value >= 10000000000000000000) + u32(value >= 1000000000000000000);\n }\n }\n}\n\nfunction ulog_base(num: u64, base: i32): u32 {\n if (isPowerOf2(base)) {\n return (63 - clz(num)) / (31 - clz(base)) + 1;\n }\n let b64 = u64(base), b = b64, e: u32 = 1;\n while (num >= b) {\n num /= b;\n b *= b;\n e <<= 1;\n }\n while (num >= 1) {\n num /= b64;\n e++;\n }\n return e - 1;\n}\n\nfunction utoa32_dec_lut(buffer: usize, num: u32, offset: usize): void {\n while (num >= 10000) {\n // in most VMs i32/u32 div and modulo by constant can be shared and simplificate\n let t = num / 10000;\n let r = num % 10000;\n num = t;\n\n let d1 = r / 100;\n let d2 = r % 100;\n\n let digits1 = load(DIGITS + (d1 << alignof()));\n let digits2 = load(DIGITS + (d2 << alignof()));\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32));\n }\n\n if (num >= 100) {\n let t = num / 100;\n let d1 = num % 100;\n num = t;\n offset -= 2;\n let digits = load(DIGITS + (d1 << alignof()));\n store(buffer + (offset << 1), digits);\n }\n\n if (num >= 10) {\n offset -= 2;\n let digits = load(DIGITS + (num << alignof()));\n store(buffer + (offset << 1), digits);\n } else {\n offset -= 1;\n let digit = CharCode._0 + num;\n store(buffer + (offset << 1), digit);\n }\n}\n\nfunction utoa64_dec_lut(buffer: usize, num: u64, offset: usize): void {\n while (num >= 100000000) {\n let t = num / 100000000;\n let r = (num - t * 100000000);\n num = t;\n\n let b = r / 10000;\n let c = r % 10000;\n\n let b1 = b / 100;\n let b2 = b % 100;\n let c1 = c / 100;\n let c2 = c % 100;\n\n let digits1 = load(DIGITS + (c1 << alignof()));\n let digits2 = load(DIGITS + (c2 << alignof()));\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32));\n\n digits1 = load(DIGITS + (b1 << alignof()));\n digits2 = load(DIGITS + (b2 << alignof()));\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32));\n }\n\n utoa32_dec_lut(buffer, num, offset);\n}\n\nfunction utoa_hex_lut(buffer: usize, num: u64, offset: usize): void {\n const lut = changetype(HEX_DIGITS);\n while (offset >= 2) {\n offset -= 2;\n store(\n buffer + (offset << 1),\n load(lut + ((num & 0xFF) << alignof()))\n );\n num >>= 8;\n }\n if (offset & 1) {\n store(buffer, load(lut + (num << 6)));\n }\n}\n\nfunction utoa_dec_simple(buffer: usize, num: T, offset: usize): void {\n do {\n let t = num / 10;\n let r = (num % 10);\n num = changetype(t);\n offset--;\n store(buffer + (offset << 1), CharCode._0 + r);\n } while (num);\n}\n\nfunction utoa_hex_simple(buffer: usize, num: T, offset: usize): void {\n do {\n let d = num & 0x0F | CharCode._0;\n d += select(0x27, 0, d > CharCode._9);\n offset--;\n store(buffer + (offset << 1), d);\n // @ts-ignore: type\n num >>= 4;\n } while (num);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function utoa32_dec_core(buffer: usize, num: u32, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_dec_simple(buffer, num, offset);\n } else {\n utoa32_dec_lut(buffer, num, offset);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction utoa32_hex_core(buffer: usize, num: u32, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_hex_simple(buffer, num, offset);\n } else {\n utoa_hex_lut(buffer, num, offset);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction utoa64_dec_core(buffer: usize, num: u64, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_dec_simple(buffer, num, offset);\n } else {\n utoa64_dec_lut(buffer, num, offset);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction utoa64_hex_core(buffer: usize, num: u64, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_hex_simple(buffer, num, offset);\n } else {\n utoa_hex_lut(buffer, num, offset);\n }\n}\n\nfunction utoa64_any_core(buffer: usize, num: u64, offset: usize, radix: i32): void {\n const lut = changetype(ANY_DIGITS);\n let base = u64(radix);\n if ((radix & (radix - 1)) == 0) { // for radix which pow of two\n let shift = u64(ctz(radix) & 7);\n let mask = base - 1;\n do {\n offset--;\n store(buffer + (offset << 1), load(lut + (usize(num & mask) << 1)));\n num >>= shift;\n } while (num);\n } else {\n do {\n offset--;\n let q = num / base;\n store(buffer + (offset << 1), load(lut + (usize(num - q * base) << 1)));\n num = q;\n } while (num);\n }\n}\n\nexport function utoa32(value: u32, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n let out: String;\n\n if (radix == 10) {\n let decimals = decimalCount32(value);\n out = changetype(__new(decimals << 1, idof()));\n utoa32_dec_core(changetype(out), value, decimals);\n } else if (radix == 16) {\n let decimals = (31 - clz(value) >> 2) + 1;\n out = changetype(__new(decimals << 1, idof()));\n utoa32_hex_core(changetype(out), value, decimals);\n } else {\n let decimals = ulog_base(value, radix);\n out = changetype(__new(decimals << 1, idof()));\n utoa64_any_core(changetype(out), value, decimals, radix);\n }\n return out;\n}\n\nexport function itoa32(value: i32, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n\n let sign = (value >>> 31) << 1;\n if (sign) value = -value;\n let out: String;\n\n if (radix == 10) {\n let decimals = decimalCount32(value);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa32_dec_core(changetype(out) + sign, value, decimals);\n } else if (radix == 16) {\n let decimals = (31 - clz(value) >> 2) + 1;\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa32_hex_core(changetype(out) + sign, value, decimals);\n } else {\n let val32 = u32(value);\n let decimals = ulog_base(val32, radix);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_any_core(changetype(out) + sign, val32, decimals, radix);\n }\n if (sign) store(changetype(out), CharCode.MINUS);\n return out;\n}\n\nexport function utoa64(value: u64, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n let out: String;\n\n if (radix == 10) {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n let decimals = decimalCount32(val32);\n out = changetype(__new(decimals << 1, idof()));\n utoa32_dec_core(changetype(out), val32, decimals);\n } else {\n let decimals = decimalCount64High(value);\n out = changetype(__new(decimals << 1, idof()));\n utoa64_dec_core(changetype(out), value, decimals);\n }\n } else if (radix == 16) {\n let decimals = (63 - u32(clz(value)) >> 2) + 1;\n out = changetype(__new(decimals << 1, idof()));\n utoa64_hex_core(changetype(out), value, decimals);\n } else {\n let decimals = ulog_base(value, radix);\n out = changetype(__new(decimals << 1, idof()));\n utoa64_any_core(changetype(out), value, decimals, radix);\n }\n return out;\n}\n\nexport function itoa64(value: i64, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n\n let sign = u32(value >>> 63) << 1;\n if (sign) value = -value;\n let out: String;\n\n if (radix == 10) {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n let decimals = decimalCount32(val32);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa32_dec_core(changetype(out) + sign, val32, decimals);\n } else {\n let decimals = decimalCount64High(value);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_dec_core(changetype(out) + sign, value, decimals);\n }\n } else if (radix == 16) {\n let decimals = (63 - u32(clz(value)) >> 2) + 1;\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_hex_core(changetype(out) + sign, value, decimals);\n } else {\n let decimals = ulog_base(value, radix);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_any_core(changetype(out) + sign, value, decimals, radix);\n }\n if (sign) store(changetype(out), CharCode.MINUS);\n return out;\n}\n\n// @ts-ignore: decorator\n@lazy let _K: i32 = 0;\n\n// // @ts-ignore: decorator\n// @lazy\n// let _frc: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy let _exp: i32 = 0;\n\n// @ts-ignore: decorator\n@lazy let _frc_minus: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy let _frc_plus: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy let _frc_pow: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy let _exp_pow: i32 = 0;\n\n// @ts-ignore: decorator\n@inline\nfunction umul64f(u: u64, v: u64): u64 {\n let u0 = u & 0xFFFFFFFF;\n let v0 = v & 0xFFFFFFFF;\n\n let u1 = u >> 32;\n let v1 = v >> 32;\n\n let l = u0 * v0;\n let t = u1 * v0 + (l >> 32);\n let w = u0 * v1 + (t & 0xFFFFFFFF);\n\n w += 0x7FFFFFFF; // rounding\n\n t >>= 32;\n w >>= 32;\n\n return u1 * v1 + t + w;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction umul64e(e1: i32, e2: i32): i32 {\n return e1 + e2 + 64; // where 64 is significand size\n}\n\n// @ts-ignore: decorator\n@inline\nfunction normalizedBoundaries(f: u64, e: i32): void {\n let frc = (f << 1) + 1;\n let exp = e - 1;\n let off = clz(frc);\n frc <<= off;\n exp -= off;\n\n let m = 1 + i32(f == 0x0010000000000000);\n\n _frc_plus = frc;\n _frc_minus = ((f << m) - 1) << e - m - exp;\n _exp = exp;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction grisuRound(buffer: usize, len: i32, delta: u64, rest: u64, ten_kappa: u64, wp_w: u64): void {\n let lastp = buffer + ((len - 1) << 1);\n let digit = load(lastp);\n while (\n rest < wp_w &&\n delta - rest >= ten_kappa && (\n rest + ten_kappa < wp_w ||\n wp_w - rest > rest + ten_kappa - wp_w\n )\n ) {\n --digit;\n rest += ten_kappa;\n }\n store(lastp, digit);\n}\n\n// @ts-ignore: decorator\n@inline\nfunction getCachedPower(minExp: i32): void {\n const c = reinterpret(0x3FD34413509F79FE); // 1 / lg(10) = 0.30102999566398114\n let dk = (-61 - minExp) * c + 347;\t // dk must be positive, so can do ceiling in positive\n let k = dk;\n k += i32(k != dk); // conversion with ceil\n\n let index = (k >> 3) + 1;\n _K = 348 - (index << 3);\t// decimal exponent no need lookup table\n _frc_pow = load(FRC_POWERS + (index << alignof()));\n _exp_pow = load(EXP_POWERS + (index << alignof()));\n}\n\n// @ts-ignore: decorator\n@inline\nfunction grisu2(value: f64, buffer: usize, sign: i32): i32 {\n\n // frexp routine\n let uv = reinterpret(value);\n let exp = i32((uv & 0x7FF0000000000000) >>> 52);\n let sid = uv & 0x000FFFFFFFFFFFFF;\n let frc = (u64(exp != 0) << 52) + sid;\n exp = select(exp, 1, exp) - (0x3FF + 52);\n\n normalizedBoundaries(frc, exp);\n getCachedPower(_exp);\n\n // normalize\n let off = clz(frc);\n frc <<= off;\n exp -= off;\n\n let frc_pow = _frc_pow;\n let exp_pow = _exp_pow;\n\n let w_frc = umul64f(frc, frc_pow);\n let w_exp = umul64e(exp, exp_pow);\n\n let wp_frc = umul64f(_frc_plus, frc_pow) - 1;\n let wp_exp = umul64e(_exp, exp_pow);\n\n let wm_frc = umul64f(_frc_minus, frc_pow) + 1;\n let delta = wp_frc - wm_frc;\n\n return genDigits(buffer, w_frc, w_exp, wp_frc, wp_exp, delta, sign);\n}\n\nfunction genDigits(buffer: usize, w_frc: u64, w_exp: i32, mp_frc: u64, mp_exp: i32, delta: u64, sign: i32): i32 {\n let one_exp = -mp_exp;\n let one_frc = (1) << one_exp;\n let mask = one_frc - 1;\n\n let wp_w_frc = mp_frc - w_frc;\n\n let p1 = u32(mp_frc >> one_exp);\n let p2 = mp_frc & mask;\n\n let kappa = decimalCount32(p1);\n let len = sign;\n\n while (kappa > 0) {\n let d: u32;\n switch (kappa) {\n case 10: { d = p1 / 1000000000; p1 %= 1000000000; break; }\n case 9: { d = p1 / 100000000; p1 %= 100000000; break; }\n case 8: { d = p1 / 10000000; p1 %= 10000000; break; }\n case 7: { d = p1 / 1000000; p1 %= 1000000; break; }\n case 6: { d = p1 / 100000; p1 %= 100000; break; }\n case 5: { d = p1 / 10000; p1 %= 10000; break; }\n case 4: { d = p1 / 1000; p1 %= 1000; break; }\n case 3: { d = p1 / 100; p1 %= 100; break; }\n case 2: { d = p1 / 10; p1 %= 10; break; }\n case 1: { d = p1; p1 = 0; break; }\n default: { d = 0; break; }\n }\n\n if (d | len) store(buffer + (len++ << 1), CharCode._0 + d);\n\n --kappa;\n let tmp = ((p1) << one_exp) + p2;\n if (tmp <= delta) {\n _K += kappa;\n grisuRound(buffer, len, delta, tmp, load(POWERS10 + (kappa << alignof())) << one_exp, wp_w_frc);\n return len;\n }\n }\n\n while (true) {\n p2 *= 10;\n delta *= 10;\n\n let d = p2 >> one_exp;\n if (d | len) store(buffer + (len++ << 1), CharCode._0 + d);\n\n p2 &= mask;\n --kappa;\n if (p2 < delta) {\n _K += kappa;\n wp_w_frc *= load(POWERS10 + (-kappa << alignof()));\n grisuRound(buffer, len, delta, p2, one_frc, wp_w_frc);\n return len;\n }\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction genExponent(buffer: usize, k: i32): i32 {\n let sign = k < 0;\n if (sign) k = -k;\n let decimals = decimalCount32(k) + 1;\n utoa32_dec_core(buffer, k, decimals);\n store(buffer, select(CharCode.MINUS, CharCode.PLUS, sign));\n return decimals;\n}\n\nfunction prettify(buffer: usize, length: i32, k: i32): i32 {\n if (!k) {\n store(buffer + (length << 1), CharCode.DOT | (CharCode._0 << 16));\n return length + 2;\n }\n\n let kk = length + k;\n if (length <= kk && kk <= 21) {\n // 1234e7 -> 12340000000\n for (let i = length; i < kk; ++i) {\n store(buffer + (i << 1), CharCode._0);\n }\n store(buffer + (kk << 1), CharCode.DOT | (CharCode._0 << 16));\n return kk + 2;\n } else if (kk > 0 && kk <= 21) {\n // 1234e-2 -> 12.34\n let ptr = buffer + (kk << 1);\n memory.copy(\n ptr + 2,\n ptr,\n -k << 1\n );\n store(buffer + (kk << 1), CharCode.DOT);\n return length + 1;\n } else if (-6 < kk && kk <= 0) {\n // 1234e-6 -> 0.001234\n let offset = 2 - kk;\n memory.copy(\n buffer + (offset << 1),\n buffer,\n length << 1\n );\n store(buffer, CharCode._0 | (CharCode.DOT << 16));\n for (let i = 2; i < offset; ++i) {\n store(buffer + (i << 1), CharCode._0);\n }\n return length + offset;\n } else if (length == 1) {\n // 1e30\n store(buffer, CharCode.e, 2);\n length = genExponent(buffer + 4, kk - 1);\n return length + 2;\n } else {\n let len = length << 1;\n memory.copy(\n buffer + 4,\n buffer + 2,\n len - 2\n );\n store(buffer, CharCode.DOT, 2);\n store(buffer + len, CharCode.e, 2);\n length += genExponent(buffer + len + 4, kk - 1);\n return length + 2;\n }\n}\n\nfunction dtoa_core(buffer: usize, value: f64): i32 {\n let sign = i32(value < 0);\n if (sign) {\n value = -value;\n store(buffer, CharCode.MINUS);\n }\n // assert(value > 0 && value <= 1.7976931348623157e308);\n let len = grisu2(value, buffer, sign);\n len = prettify(buffer + (sign << 1), len - sign, _K);\n return len + sign;\n}\n\n// @ts-ignore: decorator\n@lazy @inline const dtoa_buf = memory.data(MAX_DOUBLE_LENGTH << 1);\n\nexport function dtoa(value: f64): String {\n if (value == 0) return \"0.0\";\n if (!isFinite(value)) {\n if (isNaN(value)) return \"NaN\";\n return select(\"-Infinity\", \"Infinity\", value < 0);\n }\n let size = dtoa_core(dtoa_buf, value) << 1;\n let result = changetype(__new(size, idof()));\n memory.copy(changetype(result), dtoa_buf, size);\n return result;\n}\n\nexport function itoa_buffered(buffer: usize, value: T): u32 {\n let sign: u32 = 0;\n if (isSigned()) {\n sign = u32(value < 0);\n if (sign) {\n if (sizeof() == 1) {\n if (value == -0x80) {\n // -0x80 -> -128\n store(buffer,\n CharCode.MINUS |\n (CharCode._0 + 1) << 16 |\n (CharCode._0 + 2) << 32 |\n (CharCode._0 + 8) << 48\n );\n return 4;\n }\n }\n if (sizeof() == 2) {\n if (value == -0x8000) {\n // -0x8000 -> -32768\n store(buffer,\n CharCode.MINUS |\n (CharCode._0 + 3) << 16 |\n (CharCode._0 + 2) << 32 |\n (CharCode._0 + 7) << 48\n ); // -327\n store(buffer + 8,\n (CharCode._0 + 6) << 0 |\n (CharCode._0 + 8) << 16\n ); // 68\n return 6;\n }\n }\n store(buffer, CharCode.MINUS);\n // @ts-ignore\n value = -value;\n }\n }\n let dest = buffer + (sign << 1);\n if (ASC_SHRINK_LEVEL <= 1) {\n if (isSigned()) {\n if (sizeof() <= 4) {\n if (value < 10) {\n store(dest, value | CharCode._0);\n return 1 + sign;\n }\n } else {\n if (value < 10) {\n store(dest, value | CharCode._0);\n return 1 + sign;\n }\n }\n } else {\n if (value < 10) {\n store(buffer, value | CharCode._0);\n return 1;\n }\n }\n }\n let decimals: u32 = 0;\n if (sizeof() <= 4) {\n let val32 = value;\n decimals = decimalCount32(val32);\n utoa32_dec_core(dest, val32, decimals);\n } else {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n decimals = decimalCount32(val32);\n utoa32_dec_core(dest, val32, decimals);\n } else {\n let val64 = value;\n decimals = decimalCount64High(val64);\n utoa64_dec_core(dest, val64, decimals);\n }\n }\n return sign + decimals;\n}\n\nexport function dtoa_buffered(buffer: usize, value: f64): u32 {\n if (value == 0) {\n store(buffer, CharCode._0);\n store(buffer, CharCode.DOT, 2);\n store(buffer, CharCode._0, 4);\n return 3;\n }\n if (!isFinite(value)) {\n if (isNaN(value)) {\n store(buffer, CharCode.N);\n store(buffer, CharCode.a, 2);\n store(buffer, CharCode.N, 4);\n return 3;\n } else {\n let sign = value < 0;\n if (sign) {\n store(buffer, CharCode.MINUS); // -\n buffer += 2;\n }\n store(buffer, 0x690066006E0049, 0); // ifnI\n store(buffer, 0x7900740069006E, 8); // ytin\n return 8 + u32(sign);\n }\n }\n return dtoa_core(buffer, value);\n}\n","//\n// Lookup data for exp2f\n//\n\n// @ts-ignore: decorator\n@inline const EXP2F_TABLE_BITS = 5;\n\n// @ts-ignore: decorator\n@lazy @inline const EXP2F_DATA_TAB = memory.data([\n // exp2f_data_tab[i] = uint(2^(i/N)) - (i << 52-BITS)\n // used for computing 2^(k/N) for an int |k| < 150 N as\n // double(tab[k%N] + (k << 52-BITS))\n 0x3FF0000000000000, 0x3FEFD9B0D3158574, 0x3FEFB5586CF9890F, 0x3FEF9301D0125B51,\n 0x3FEF72B83C7D517B, 0x3FEF54873168B9AA, 0x3FEF387A6E756238, 0x3FEF1E9DF51FDEE1,\n 0x3FEF06FE0A31B715, 0x3FEEF1A7373AA9CB, 0x3FEEDEA64C123422, 0x3FEECE086061892D,\n 0x3FEEBFDAD5362A27, 0x3FEEB42B569D4F82, 0x3FEEAB07DD485429, 0x3FEEA47EB03A5585,\n 0x3FEEA09E667F3BCD, 0x3FEE9F75E8EC5F74, 0x3FEEA11473EB0187, 0x3FEEA589994CCE13,\n 0x3FEEACE5422AA0DB, 0x3FEEB737B0CDC5E5, 0x3FEEC49182A3F090, 0x3FEED503B23E255D,\n 0x3FEEE89F995AD3AD, 0x3FEEFF76F2FB5E47, 0x3FEF199BDD85529C, 0x3FEF3720DCEF9069,\n 0x3FEF5818DCFBA487, 0x3FEF7C97337B9B5F, 0x3FEFA4AFA2A490DA, 0x3FEFD0765B6E4540\n]);\n\n// ULP error: 0.502 (nearest rounding.)\n// Relative error: 1.69 * 2^-34 in [-1/64, 1/64] (before rounding.)\n// Wrong count: 168353 (all nearest rounding wrong results with fma.)\n// @ts-ignore: decorator\n@inline\nexport function exp2f_lut(x: f32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000) / N, // 0x1.8p+52\n Ox127f = reinterpret(0x7F000000);\n\n const\n C0 = reinterpret(0x3FAC6AF84B912394), // 0x1.c6af84b912394p-5\n C1 = reinterpret(0x3FCEBFCE50FAC4F3), // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret(0x3FE62E42FF0C52D6); // 0x1.62e42ff0c52d6p-1\n\n let xd = x;\n let ix = reinterpret(x);\n let ux = ix >> 20 & 0x7FF;\n if (ux >= 0x430) {\n // |x| >= 128 or x is nan.\n if (ix == 0xFF800000) return 0; // x == -Inf -> 0\n if (ux >= 0x7F8) return x + x; // x == Inf/NaN -> Inf/NaN\n if (x > 0) return x * Ox127f; // x > 0 -> HugeVal (Owerflow)\n if (x <= -150) return 0; // x <= -150 -> 0 (Underflow)\n }\n\n // x = k/N + r with r in [-1/(2N), 1/(2N)] and int k.\n let kd = xd + shift;\n let ki = reinterpret(kd);\n let r = xd - (kd - shift);\n let t: u64, y: f64, s: f64;\n\n // exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load(EXP2F_DATA_TAB + ((ki & N_MASK) << alignof()));\n t += ki << (52 - EXP2F_TABLE_BITS);\n s = reinterpret(t);\n y = C2 * r + 1;\n y += (C0 * r + C1) * (r * r);\n y *= s;\n\n return y;\n}\n\n// ULP error: 0.502 (nearest rounding.)\n// Relative error: 1.69 * 2^-34 in [-ln2/64, ln2/64] (before rounding.)\n// Wrong count: 170635 (all nearest rounding wrong results with fma.)\n// @ts-ignore: decorator\n@inline\nexport function expf_lut(x: f32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000), // 0x1.8p+52\n InvLn2N = reinterpret(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep+0\n Ox1p127f = reinterpret(0x7F000000);\n\n const\n C0 = reinterpret(0x3FAC6AF84B912394) / N / N / N, // 0x1.c6af84b912394p-5\n C1 = reinterpret(0x3FCEBFCE50FAC4F3) / N / N, // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret(0x3FE62E42FF0C52D6) / N; // 0x1.62e42ff0c52d6p-1\n\n let xd = x;\n let ix = reinterpret(x);\n let ux = ix >> 20 & 0x7FF;\n if (ux >= 0x42B) {\n // |x| >= 88 or x is nan.\n if (ix == 0xFF800000) return 0; // x == -Inf -> 0\n if (ux >= 0x7F8) return x + x; // x == Inf/NaN -> Inf/NaN\n if (x > reinterpret(0x42B17217)) return x * Ox1p127f; // x > log(0x1p128) ~= 88.72 -> HugeVal (Owerflow)\n if (x < reinterpret(0xC2CFF1B4)) return 0; // x < log(0x1p-150) ~= -103.97 -> 0 (Underflow)\n }\n\n // x*N/Ln2 = k + r with r in [-1/2, 1/2] and int k.\n let z = InvLn2N * xd;\n\n // Round and convert z to int, the result is in [-150*N, 128*N] and\n // ideally ties-to-even rule is used, otherwise the magnitude of r\n // can be bigger which gives larger approximation error.\n let kd = (z + shift);\n let ki = reinterpret(kd);\n let r = z - (kd - shift);\n let s: f64, y: f64, t: u64;\n\n // exp(x) = 2^(k/N) * 2^(r/N) ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load(EXP2F_DATA_TAB + ((ki & N_MASK) << alignof()));\n t += ki << (52 - EXP2F_TABLE_BITS);\n s = reinterpret(t);\n z = C0 * r + C1;\n y = C2 * r + 1;\n y += z * (r * r);\n y *= s;\n\n return y;\n}\n\n//\n// Lookup data for log2f\n//\n\n// @ts-ignore: decorator\n@inline const LOG2F_TABLE_BITS = 4;\n\n// @ts-ignore: decorator\n@lazy @inline const LOG2F_DATA_TAB = memory.data([\n 0x3FF661EC79F8F3BE, 0xBFDEFEC65B963019, // 0x1.661ec79f8f3bep+0, -0x1.efec65b963019p-2,\n 0x3FF571ED4AAF883D, 0xBFDB0B6832D4FCA4, // 0x1.571ed4aaf883dp+0, -0x1.b0b6832d4fca4p-2,\n 0x3FF49539F0F010B0, 0xBFD7418B0A1FB77B, // 0x1.49539f0f010bp+0 , -0x1.7418b0a1fb77bp-2,\n 0x3FF3C995B0B80385, 0xBFD39DE91A6DCF7B, // 0x1.3c995b0b80385p+0, -0x1.39de91a6dcf7bp-2,\n 0x3FF30D190C8864A5, 0xBFD01D9BF3F2B631, // 0x1.30d190c8864a5p+0, -0x1.01d9bf3f2b631p-2,\n 0x3FF25E227B0B8EA0, 0xBFC97C1D1B3B7AF0, // 0x1.25e227b0b8eap+0 , -0x1.97c1d1b3b7afp-3 ,\n 0x3FF1BB4A4A1A343F, 0xBFC2F9E393AF3C9F, // 0x1.1bb4a4a1a343fp+0, -0x1.2f9e393af3c9fp-3,\n 0x3FF12358F08AE5BA, 0xBFB960CBBF788D5C, // 0x1.12358f08ae5bap+0, -0x1.960cbbf788d5cp-4,\n 0x3FF0953F419900A7, 0xBFAA6F9DB6475FCE, // 0x1.0953f419900a7p+0, -0x1.a6f9db6475fcep-5,\n 0x3FF0000000000000, 0, // 0x1p+0, 0x0,\n 0x3FEE608CFD9A47AC, 0x3FB338CA9F24F53D, // 0x1.e608cfd9a47acp-1, 0x1.338ca9f24f53dp-4,\n 0x3FECA4B31F026AA0, 0x3FC476A9543891BA, // 0x1.ca4b31f026aap-1 , 0x1.476a9543891bap-3,\n 0x3FEB2036576AFCE6, 0x3FCE840B4AC4E4D2, // 0x1.b2036576afce6p-1, 0x1.e840b4ac4e4d2p-3,\n 0x3FE9C2D163A1AA2D, 0x3FD40645F0C6651C, // 0x1.9c2d163a1aa2dp-1, 0x1.40645f0c6651cp-2,\n 0x3FE886E6037841ED, 0x3FD88E9C2C1B9FF8, // 0x1.886e6037841edp-1, 0x1.88e9c2c1b9ff8p-2,\n 0x3FE767DCF5534862, 0x3FDCE0A44EB17BCC // 0x1.767dcf5534862p-1, 0x1.ce0a44eb17bccp-2\n]);\n\n// ULP error: 0.752 (nearest rounding.)\n// Relative error: 1.9 * 2^-26 (before rounding.)\n// @ts-ignore: decorator\n@inline\nexport function log2f_lut(x: f32): f32 {\n const\n N_MASK = (1 << LOG2F_TABLE_BITS) - 1,\n Ox1p23f = reinterpret(0x4B000000); // 0x1p23f\n\n const\n A0 = reinterpret(0xBFD712B6F70A7E4D), // -0x1.712b6f70a7e4dp-2\n A1 = reinterpret(0x3FDECABF496832E0), // 0x1.ecabf496832ep-2\n A2 = reinterpret(0xBFE715479FFAE3DE), // -0x1.715479ffae3dep-1\n A3 = reinterpret(0x3FF715475F35C8B8); // 0x1.715475f35c8b8p0\n\n let ux = reinterpret(x);\n // Fix sign of zero with downward rounding when x==1.\n // if (WANT_ROUNDING && predict_false(ix == 0x3f800000)) return 0;\n if (ux - 0x00800000 >= 0x7F800000 - 0x00800000) {\n // x < 0x1p-126 or inf or nan.\n if (ux * 2 == 0) return -Infinity;\n if (ux == 0x7F800000) return x; // log2(inf) == inf.\n if ((ux >> 31) || ux * 2 >= 0xFF000000) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ux = reinterpret(x * Ox1p23f);\n ux -= 23 << 23;\n }\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n let tmp = ux - 0x3F330000;\n let i = (tmp >> (23 - LOG2F_TABLE_BITS)) & N_MASK;\n let top = tmp & 0xFF800000;\n let iz = ux - top;\n let k = tmp >> 23;\n\n let invc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 0 << alignof());\n let logc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 1 << alignof());\n let z = reinterpret(iz);\n\n // log2(x) = log1p(z/c-1)/ln2 + log2(c) + k\n let r = z * invc - 1;\n let y0 = logc + k;\n\n // Pipelined polynomial evaluation to approximate log1p(r)/ln2.\n let y = A1 * r + A2;\n let p = A3 * r + y0;\n let r2 = r * r;\n y += A0 * r2;\n y = y * r2 + p;\n\n return y;\n}\n\n//\n// Lookup data for logf. See: https://git.musl-libc.org/cgit/musl/tree/src/math/logf.c\n//\n\n// @ts-ignore: decorator\n@inline const LOGF_TABLE_BITS = 4;\n\n// @ts-ignore: decorator\n@lazy @inline const LOGF_DATA_TAB = memory.data([\n 0x3FF661EC79F8F3BE, 0xBFD57BF7808CAADE, // 0x1.661ec79f8f3bep+0, -0x1.57bf7808caadep-2,\n 0x3FF571ED4AAF883D, 0xBFD2BEF0A7C06DDB, // 0x1.571ed4aaf883dp+0, -0x1.2bef0a7c06ddbp-2,\n 0x3FF49539F0F010B0, 0xBFD01EAE7F513A67, // 0x1.49539f0f010bp+0 , -0x1.01eae7f513a67p-2,\n 0x3FF3C995B0B80385, 0xBFCB31D8A68224E9, // 0x1.3c995b0b80385p+0, -0x1.b31d8a68224e9p-3,\n 0x3FF30D190C8864A5, 0xBFC6574F0AC07758, // 0x1.30d190c8864a5p+0, -0x1.6574f0ac07758p-3,\n 0x3FF25E227B0B8EA0, 0xBFC1AA2BC79C8100, // 0x1.25e227b0b8eap+0 , -0x1.1aa2bc79c81p-3 ,\n 0x3FF1BB4A4A1A343F, 0xBFBA4E76CE8C0E5E, // 0x1.1bb4a4a1a343fp+0, -0x1.a4e76ce8c0e5ep-4,\n 0x3FF12358F08AE5BA, 0xBFB1973C5A611CCC, // 0x1.12358f08ae5bap+0, -0x1.1973c5a611cccp-4,\n 0x3FF0953F419900A7, 0xBFA252F438E10C1E, // 0x1.0953f419900a7p+0, -0x1.252f438e10c1ep-5,\n 0x3FF0000000000000, 0, // 0x1p+0, 0,\n 0x3FEE608CFD9A47AC, 0x3FAAA5AA5DF25984, // 0x1.e608cfd9a47acp-1, 0x1.aa5aa5df25984p-5,\n 0x3FECA4B31F026AA0, 0x3FBC5E53AA362EB4, // 0x1.ca4b31f026aap-1 , 0x1.c5e53aa362eb4p-4,\n 0x3FEB2036576AFCE6, 0x3FC526E57720DB08, // 0x1.b2036576afce6p-1, 0x1.526e57720db08p-3,\n 0x3FE9C2D163A1AA2D, 0x3FCBC2860D224770, // 0x1.9c2d163a1aa2dp-1, 0x1.bc2860d22477p-3 ,\n 0x3FE886E6037841ED, 0x3FD1058BC8A07EE1, // 0x1.886e6037841edp-1, 0x1.1058bc8a07ee1p-2,\n 0x3FE767DCF5534862, 0x3FD4043057B6EE09 // 0x1.767dcf5534862p-1, 0x1.4043057b6ee09p-2\n]);\n\n// ULP error: 0.818 (nearest rounding.)\n// Relative error: 1.957 * 2^-26 (before rounding.)\n// @ts-ignore: decorator\n@inline\nexport function logf_lut(x: f32): f32 {\n const\n N_MASK = (1 << LOGF_TABLE_BITS) - 1,\n Ox1p23f = reinterpret(0x4B000000); // 0x1p23f\n\n const\n Ln2 = reinterpret(0x3FE62E42FEFA39EF), // 0x1.62e42fefa39efp-1;\n A0 = reinterpret(0xBFD00EA348B88334), // -0x1.00ea348b88334p-2\n A1 = reinterpret(0x3FD5575B0BE00B6A), // 0x1.5575b0be00b6ap-2\n A2 = reinterpret(0xBFDFFFFEF20A4123); // -0x1.ffffef20a4123p-2\n\n let ux = reinterpret(x);\n // Fix sign of zero with downward rounding when x==1.\n // if (WANT_ROUNDING && ux == 0x3f800000) return 0;\n if (ux - 0x00800000 >= 0x7F800000 - 0x00800000) {\n // x < 0x1p-126 or inf or nan.\n if ((ux << 1) == 0) return -Infinity;\n if (ux == 0x7F800000) return x; // log(inf) == inf.\n if ((ux >> 31) || (ux << 1) >= 0xFF000000) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ux = reinterpret(x * Ox1p23f);\n ux -= 23 << 23;\n }\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n let tmp = ux - 0x3F330000;\n let i = (tmp >> (23 - LOGF_TABLE_BITS)) & N_MASK;\n let k = tmp >> 23;\n let iz = ux - (tmp & 0x1FF << 23);\n\n let invc = load(LOGF_DATA_TAB + (i << (1 + alignof())), 0 << alignof());\n let logc = load(LOGF_DATA_TAB + (i << (1 + alignof())), 1 << alignof());\n\n let z = reinterpret(iz);\n\n // log(x) = log1p(z/c-1) + log(c) + k*Ln2\n let r = z * invc - 1;\n let y0 = logc + k * Ln2;\n\n // Pipelined polynomial evaluation to approximate log1p(r).\n let r2 = r * r;\n let y = A1 * r + A2;\n y += A0 * r2;\n y = y * r2 + (y0 + r);\n\n return y;\n}\n\n//\n// Lookup data for powf. See: https://git.musl-libc.org/cgit/musl/tree/src/math/powf.c\n//\n\n// @ts-ignore: decorator\n@inline\nfunction zeroinfnanf(ux: u32): bool {\n return (ux << 1) - 1 >= (0x7f800000 << 1) - 1;\n}\n\n// Returns 0 if not int, 1 if odd int, 2 if even int. The argument is\n// the bit representation of a non-zero finite floating-point value.\n// @ts-ignore: decorator\n@inline\nfunction checkintf(iy: u32): i32 {\n let e = iy >> 23 & 0xFF;\n if (e < 0x7F ) return 0;\n if (e > 0x7F + 23) return 2;\n e = 1 << (0x7F + 23 - e);\n if (iy & (e - 1)) return 0;\n if (iy & e ) return 1;\n return 2;\n}\n\n// Subnormal input is normalized so ix has negative biased exponent.\n// Output is multiplied by N (POWF_SCALE) if TOINT_INTRINICS is set.\n// @ts-ignore: decorator\n@inline\nfunction log2f_inline(ux: u32): f64 {\n const N_MASK = (1 << LOG2F_TABLE_BITS) - 1;\n\n const\n A0 = reinterpret(0x3FD27616C9496E0B), // 0x1.27616c9496e0bp-2\n A1 = reinterpret(0xBFD71969A075C67A), // -0x1.71969a075c67ap-2\n A2 = reinterpret(0x3FDEC70A6CA7BADD), // 0x1.ec70a6ca7baddp-2\n A3 = reinterpret(0xBFE7154748BEF6C8), // -0x1.7154748bef6c8p-1\n A4 = reinterpret(0x3FF71547652AB82B); // 0x1.71547652ab82bp+0\n\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n let tmp = ux - 0x3F330000;\n let i = usize((tmp >> (23 - LOG2F_TABLE_BITS)) & N_MASK);\n let top = tmp & 0xFF800000;\n let uz = ux - top;\n let k = top >> 23;\n\n let invc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 0 << alignof());\n let logc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 1 << alignof());\n let z = reinterpret(uz);\n\n // log2(x) = log1p(z/c-1)/ln2 + log2(c) + k\n let r = z * invc - 1;\n let y0 = logc + k;\n\n // Pipelined polynomial evaluation to approximate log1p(r)/ln2.\n let y = A0 * r + A1;\n let p = A2 * r + A3;\n let q = A4 * r + y0;\n\n r *= r;\n q += p * r;\n y = y * (r * r) + q;\n\n return y;\n}\n\n// The output of log2 and thus the input of exp2 is either scaled by N\n// (in case of fast toint intrinsics) or not. The unscaled xd must be\n// in [-1021,1023], sign_bias sets the sign of the result.\n// @ts-ignore: decorator\n@inline\nfunction exp2f_inline(xd: f64, signBias: u32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000) / N; // 0x1.8p+52\n\n const\n C0 = reinterpret(0x3FAC6AF84B912394), // 0x1.c6af84b912394p-5\n C1 = reinterpret(0x3FCEBFCE50FAC4F3), // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret(0x3FE62E42FF0C52D6); // 0x1.62e42ff0c52d6p-1\n\n // x = k/N + r with r in [-1/(2N), 1/(2N)]\n let kd = (xd + shift);\n let ki = reinterpret(kd);\n let r = xd - (kd - shift);\n let t: u64, z: f64, y: f64, s: f64;\n\n // exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load(EXP2F_DATA_TAB + ((ki & N_MASK) << alignof()));\n t += (ki + signBias) << (52 - EXP2F_TABLE_BITS);\n s = reinterpret(t);\n z = C0 * r + C1;\n y = C2 * r + 1;\n y += z * (r * r);\n y *= s;\n return y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction xflowf(sign: u32, y: f32): f32 {\n return select(-y, y, sign) * y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction oflowf(sign: u32): f32 {\n return xflowf(sign, reinterpret(0x70000000)); // 0x1p97f\n}\n\n// @ts-ignore: decorator\n@inline\nfunction uflowf(sign: u32): f32 {\n return xflowf(sign, reinterpret(0x10000000)); // 0x1p-95f\n}\n\n// @ts-ignore: decorator\n@inline\nexport function powf_lut(x: f32, y: f32): f32 {\n const\n Ox1p23f = reinterpret(0x4B000000), // 0x1p23f\n UPPER_LIMIT = reinterpret(0x405FFFFFFFD1D571), // 0x1.fffffffd1d571p+6\n LOWER_LIMIT = -150.0,\n SIGN_BIAS = 1 << (EXP2F_TABLE_BITS + 11);\n\n let signBias: u32 = 0;\n let ix = reinterpret(x);\n let iy = reinterpret(y);\n let ny = 0;\n\n if (i32(ix - 0x00800000 >= 0x7f800000 - 0x00800000) | (ny = i32(zeroinfnanf(iy)))) {\n // Either (x < 0x1p-126 or inf or nan) or (y is 0 or inf or nan).\n if (ny) {\n if ((iy << 1) == 0) return 1.0;\n if (ix == 0x3F800000) return NaN; // original: 1.0\n if ((ix << 1) > (0x7F800000 << 1) || (iy << 1) > (0x7F800000 << 1)) return x + y;\n if ((ix << 1) == (0x3F800000 << 1)) return NaN; // original: 1.0\n if (((ix << 1) < (0x3F800000 << 1)) == !(iy >> 31)) return 0; // |x| < 1 && y==inf or |x| > 1 && y==-inf.\n return y * y;\n }\n if (zeroinfnanf(ix)) {\n let x2 = x * x;\n if ((ix >> 31) && checkintf(iy) == 1) x2 = -x2;\n return iy < 0 ? 1 / x2 : x2;\n }\n // x and y are non-zero finite.\n if (ix < 0) {\n // Finite x < 0.\n let yint = checkintf(iy);\n if (yint == 0) return (x - x) / (x - x);\n if (yint == 1) signBias = SIGN_BIAS;\n ix &= 0x7FFFFFFF;\n }\n if (ix < 0x00800000) {\n // Normalize subnormal x so exponent becomes negative.\n ix = reinterpret(x * Ox1p23f);\n ix &= 0x7FFFFFFF;\n ix -= 23 << 23;\n }\n }\n let logx = log2f_inline(ix);\n let ylogx = y * logx; // cannot overflow, y is single prec.\n if ((reinterpret(ylogx) >> 47 & 0xFFFF) >= 0x80BF) { // reinterpret(126.0) >> 47\n // |y * log(x)| >= 126\n if (ylogx > UPPER_LIMIT) return oflowf(signBias); // overflow\n if (ylogx <= LOWER_LIMIT) return uflowf(signBias); // underflow\n }\n return exp2f_inline(ylogx, signBias);\n}\n\n//\n// Lookup data for exp. See: https://git.musl-libc.org/cgit/musl/tree/src/math/exp.c\n//\n\n// @ts-ignore: decorator\n@inline const EXP_TABLE_BITS = 7;\n\n// @ts-ignore: decorator\n@lazy @inline const EXP_DATA_TAB = memory.data([\n 0x0000000000000000, 0x3FF0000000000000,\n 0x3C9B3B4F1A88BF6E, 0x3FEFF63DA9FB3335,\n 0xBC7160139CD8DC5D, 0x3FEFEC9A3E778061,\n 0xBC905E7A108766D1, 0x3FEFE315E86E7F85,\n 0x3C8CD2523567F613, 0x3FEFD9B0D3158574,\n 0xBC8BCE8023F98EFA, 0x3FEFD06B29DDF6DE,\n 0x3C60F74E61E6C861, 0x3FEFC74518759BC8,\n 0x3C90A3E45B33D399, 0x3FEFBE3ECAC6F383,\n 0x3C979AA65D837B6D, 0x3FEFB5586CF9890F,\n 0x3C8EB51A92FDEFFC, 0x3FEFAC922B7247F7,\n 0x3C3EBE3D702F9CD1, 0x3FEFA3EC32D3D1A2,\n 0xBC6A033489906E0B, 0x3FEF9B66AFFED31B,\n 0xBC9556522A2FBD0E, 0x3FEF9301D0125B51,\n 0xBC5080EF8C4EEA55, 0x3FEF8ABDC06C31CC,\n 0xBC91C923B9D5F416, 0x3FEF829AAEA92DE0,\n 0x3C80D3E3E95C55AF, 0x3FEF7A98C8A58E51,\n 0xBC801B15EAA59348, 0x3FEF72B83C7D517B,\n 0xBC8F1FF055DE323D, 0x3FEF6AF9388C8DEA,\n 0x3C8B898C3F1353BF, 0x3FEF635BEB6FCB75,\n 0xBC96D99C7611EB26, 0x3FEF5BE084045CD4,\n 0x3C9AECF73E3A2F60, 0x3FEF54873168B9AA,\n 0xBC8FE782CB86389D, 0x3FEF4D5022FCD91D,\n 0x3C8A6F4144A6C38D, 0x3FEF463B88628CD6,\n 0x3C807A05B0E4047D, 0x3FEF3F49917DDC96,\n 0x3C968EFDE3A8A894, 0x3FEF387A6E756238,\n 0x3C875E18F274487D, 0x3FEF31CE4FB2A63F,\n 0x3C80472B981FE7F2, 0x3FEF2B4565E27CDD,\n 0xBC96B87B3F71085E, 0x3FEF24DFE1F56381,\n 0x3C82F7E16D09AB31, 0x3FEF1E9DF51FDEE1,\n 0xBC3D219B1A6FBFFA, 0x3FEF187FD0DAD990,\n 0x3C8B3782720C0AB4, 0x3FEF1285A6E4030B,\n 0x3C6E149289CECB8F, 0x3FEF0CAFA93E2F56,\n 0x3C834D754DB0ABB6, 0x3FEF06FE0A31B715,\n 0x3C864201E2AC744C, 0x3FEF0170FC4CD831,\n 0x3C8FDD395DD3F84A, 0x3FEEFC08B26416FF,\n 0xBC86A3803B8E5B04, 0x3FEEF6C55F929FF1,\n 0xBC924AEDCC4B5068, 0x3FEEF1A7373AA9CB,\n 0xBC9907F81B512D8E, 0x3FEEECAE6D05D866,\n 0xBC71D1E83E9436D2, 0x3FEEE7DB34E59FF7,\n 0xBC991919B3CE1B15, 0x3FEEE32DC313A8E5,\n 0x3C859F48A72A4C6D, 0x3FEEDEA64C123422,\n 0xBC9312607A28698A, 0x3FEEDA4504AC801C,\n 0xBC58A78F4817895B, 0x3FEED60A21F72E2A,\n 0xBC7C2C9B67499A1B, 0x3FEED1F5D950A897,\n 0x3C4363ED60C2AC11, 0x3FEECE086061892D,\n 0x3C9666093B0664EF, 0x3FEECA41ED1D0057,\n 0x3C6ECCE1DAA10379, 0x3FEEC6A2B5C13CD0,\n 0x3C93FF8E3F0F1230, 0x3FEEC32AF0D7D3DE,\n 0x3C7690CEBB7AAFB0, 0x3FEEBFDAD5362A27,\n 0x3C931DBDEB54E077, 0x3FEEBCB299FDDD0D,\n 0xBC8F94340071A38E, 0x3FEEB9B2769D2CA7,\n 0xBC87DECCDC93A349, 0x3FEEB6DAA2CF6642,\n 0xBC78DEC6BD0F385F, 0x3FEEB42B569D4F82,\n 0xBC861246EC7B5CF6, 0x3FEEB1A4CA5D920F,\n 0x3C93350518FDD78E, 0x3FEEAF4736B527DA,\n 0x3C7B98B72F8A9B05, 0x3FEEAD12D497C7FD,\n 0x3C9063E1E21C5409, 0x3FEEAB07DD485429,\n 0x3C34C7855019C6EA, 0x3FEEA9268A5946B7,\n 0x3C9432E62B64C035, 0x3FEEA76F15AD2148,\n 0xBC8CE44A6199769F, 0x3FEEA5E1B976DC09,\n 0xBC8C33C53BEF4DA8, 0x3FEEA47EB03A5585,\n 0xBC845378892BE9AE, 0x3FEEA34634CCC320,\n 0xBC93CEDD78565858, 0x3FEEA23882552225,\n 0x3C5710AA807E1964, 0x3FEEA155D44CA973,\n 0xBC93B3EFBF5E2228, 0x3FEEA09E667F3BCD,\n 0xBC6A12AD8734B982, 0x3FEEA012750BDABF,\n 0xBC6367EFB86DA9EE, 0x3FEE9FB23C651A2F,\n 0xBC80DC3D54E08851, 0x3FEE9F7DF9519484,\n 0xBC781F647E5A3ECF, 0x3FEE9F75E8EC5F74,\n 0xBC86EE4AC08B7DB0, 0x3FEE9F9A48A58174,\n 0xBC8619321E55E68A, 0x3FEE9FEB564267C9,\n 0x3C909CCB5E09D4D3, 0x3FEEA0694FDE5D3F,\n 0xBC7B32DCB94DA51D, 0x3FEEA11473EB0187,\n 0x3C94ECFD5467C06B, 0x3FEEA1ED0130C132,\n 0x3C65EBE1ABD66C55, 0x3FEEA2F336CF4E62,\n 0xBC88A1C52FB3CF42, 0x3FEEA427543E1A12,\n 0xBC9369B6F13B3734, 0x3FEEA589994CCE13,\n 0xBC805E843A19FF1E, 0x3FEEA71A4623C7AD,\n 0xBC94D450D872576E, 0x3FEEA8D99B4492ED,\n 0x3C90AD675B0E8A00, 0x3FEEAAC7D98A6699,\n 0x3C8DB72FC1F0EAB4, 0x3FEEACE5422AA0DB,\n 0xBC65B6609CC5E7FF, 0x3FEEAF3216B5448C,\n 0x3C7BF68359F35F44, 0x3FEEB1AE99157736,\n 0xBC93091FA71E3D83, 0x3FEEB45B0B91FFC6,\n 0xBC5DA9B88B6C1E29, 0x3FEEB737B0CDC5E5,\n 0xBC6C23F97C90B959, 0x3FEEBA44CBC8520F,\n 0xBC92434322F4F9AA, 0x3FEEBD829FDE4E50,\n 0xBC85CA6CD7668E4B, 0x3FEEC0F170CA07BA,\n 0x3C71AFFC2B91CE27, 0x3FEEC49182A3F090,\n 0x3C6DD235E10A73BB, 0x3FEEC86319E32323,\n 0xBC87C50422622263, 0x3FEECC667B5DE565,\n 0x3C8B1C86E3E231D5, 0x3FEED09BEC4A2D33,\n 0xBC91BBD1D3BCBB15, 0x3FEED503B23E255D,\n 0x3C90CC319CEE31D2, 0x3FEED99E1330B358,\n 0x3C8469846E735AB3, 0x3FEEDE6B5579FDBF,\n 0xBC82DFCD978E9DB4, 0x3FEEE36BBFD3F37A,\n 0x3C8C1A7792CB3387, 0x3FEEE89F995AD3AD,\n 0xBC907B8F4AD1D9FA, 0x3FEEEE07298DB666,\n 0xBC55C3D956DCAEBA, 0x3FEEF3A2B84F15FB,\n 0xBC90A40E3DA6F640, 0x3FEEF9728DE5593A,\n 0xBC68D6F438AD9334, 0x3FEEFF76F2FB5E47,\n 0xBC91EEE26B588A35, 0x3FEF05B030A1064A,\n 0x3C74FFD70A5FDDCD, 0x3FEF0C1E904BC1D2,\n 0xBC91BDFBFA9298AC, 0x3FEF12C25BD71E09,\n 0x3C736EAE30AF0CB3, 0x3FEF199BDD85529C,\n 0x3C8EE3325C9FFD94, 0x3FEF20AB5FFFD07A,\n 0x3C84E08FD10959AC, 0x3FEF27F12E57D14B,\n 0x3C63CDAF384E1A67, 0x3FEF2F6D9406E7B5,\n 0x3C676B2C6C921968, 0x3FEF3720DCEF9069,\n 0xBC808A1883CCB5D2, 0x3FEF3F0B555DC3FA,\n 0xBC8FAD5D3FFFFA6F, 0x3FEF472D4A07897C,\n 0xBC900DAE3875A949, 0x3FEF4F87080D89F2,\n 0x3C74A385A63D07A7, 0x3FEF5818DCFBA487,\n 0xBC82919E2040220F, 0x3FEF60E316C98398,\n 0x3C8E5A50D5C192AC, 0x3FEF69E603DB3285,\n 0x3C843A59AC016B4B, 0x3FEF7321F301B460,\n 0xBC82D52107B43E1F, 0x3FEF7C97337B9B5F,\n 0xBC892AB93B470DC9, 0x3FEF864614F5A129,\n 0x3C74B604603A88D3, 0x3FEF902EE78B3FF6,\n 0x3C83C5EC519D7271, 0x3FEF9A51FBC74C83,\n 0xBC8FF7128FD391F0, 0x3FEFA4AFA2A490DA,\n 0xBC8DAE98E223747D, 0x3FEFAF482D8E67F1,\n 0x3C8EC3BC41AA2008, 0x3FEFBA1BEE615A27,\n 0x3C842B94C3A9EB32, 0x3FEFC52B376BBA97,\n 0x3C8A64A931D185EE, 0x3FEFD0765B6E4540,\n 0xBC8E37BAE43BE3ED, 0x3FEFDBFDAD9CBE14,\n 0x3C77893B4D91CD9D, 0x3FEFE7C1819E90D8,\n 0x3C5305C14160CC89, 0x3FEFF3C22B8F71F1\n]);\n\n// Handle cases that may overflow or underflow when computing the result that\n// is scale*(1+TMP) without intermediate rounding. The bit representation of\n// scale is in SBITS, however it has a computed exponent that may have\n// overflown into the sign bit so that needs to be adjusted before using it as\n// a double. (int32_t)KI is the k used in the argument reduction and exponent\n// adjustment of scale, positive k here means the result may overflow and\n// negative k means the result may underflow.\n// @ts-ignore: decorator\n@inline\nfunction specialcase(tmp: f64, sbits: u64, ki: u64): f64 {\n const\n Ox1p_1022 = reinterpret(0x0010000000000000), // 0x1p-1022\n Ox1p1009 = reinterpret(0x7F00000000000000); // 0x1p1009\n\n let scale: f64;\n if (!(ki & 0x80000000)) {\n // k > 0, the exponent of scale might have overflowed by <= 460.\n sbits -= u64(1009) << 52;\n scale = reinterpret(sbits);\n return Ox1p1009 * (scale + scale * tmp); // 0x1p1009\n }\n // k < 0, need special care in the subnormal range.\n sbits += u64(1022) << 52;\n // Note: sbits is signed scale.\n scale = reinterpret(sbits);\n let y = scale + scale * tmp;\n if (abs(y) < 1.0) {\n // Round y to the right precision before scaling it into the subnormal\n // range to avoid double rounding that can cause 0.5+E/2 ulp error where\n // E is the worst-case ulp error outside the subnormal range. So this\n // is only useful if the goal is better than 1 ulp worst-case error.\n let one = copysign(1.0, y);\n let lo = scale - y + scale * tmp;\n let hi = one + y;\n lo = one - hi + y + lo;\n y = (hi + lo) - one;\n // Fix the sign of 0.\n if (y == 0.0) y = reinterpret(sbits & 0x8000000000000000);\n }\n return y * Ox1p_1022;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function exp_lut(x: f64): f64 {\n const\n N = 1 << EXP_TABLE_BITS,\n N_MASK = N - 1;\n\n const\n InvLn2N = reinterpret(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep0\n NegLn2hiN = reinterpret(0xBF762E42FEFA0000), // -0x1.62e42fefa0000p-8\n NegLn2loN = reinterpret(0xBD0CF79ABC9E3B3A), // -0x1.cf79abc9e3b3ap-47\n shift = reinterpret(0x4338000000000000); // 0x1.8p52;\n\n const\n C2 = reinterpret(0x3FDFFFFFFFFFFDBD), // __exp_data.poly[0] (0x1.ffffffffffdbdp-2)\n C3 = reinterpret(0x3FC555555555543C), // __exp_data.poly[1] (0x1.555555555543cp-3)\n C4 = reinterpret(0x3FA55555CF172B91), // __exp_data.poly[2] (0x1.55555cf172b91p-5)\n C5 = reinterpret(0x3F81111167A4D017); // __exp_data.poly[3] (0x1.1111167a4d017p-7)\n\n let ux = reinterpret(x);\n let abstop = u32(ux >> 52) & 0x7FF;\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) return 1;\n if (abstop >= 0x409) {\n if (ux == 0xFFF0000000000000) return 0;\n if (abstop >= 0x7FF) {\n return 1.0 + x;\n } else {\n return select(0, Infinity, ux < 0);\n }\n }\n // Large x is special cased below.\n abstop = 0;\n }\n\n // exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)]\n // x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N]\n let z = InvLn2N * x;\n // #if TOINT_INTRINSICS\n // \tkd = roundtoint(z);\n // \tki = converttoint(z);\n // #elif EXP_USE_TOINT_NARROW\n // \t// z - kd is in [-0.5-2^-16, 0.5] in all rounding modes.\n // let kd = z + shift;\n // let ki = reinterpret(kd) >> 16;\n // let kd = ki;\n // #else\n // z - kd is in [-1, 1] in non-nearest rounding modes.\n let kd = z + shift;\n let ki = reinterpret(kd);\n kd -= shift;\n // #endif\n let r = x + kd * NegLn2hiN + kd * NegLn2loN;\n // 2^(k/N) ~= scale * (1 + tail).\n let idx = usize((ki & N_MASK) << 1);\n let top = ki << (52 - EXP_TABLE_BITS);\n\n let tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof()))); // T[idx]\n // This is only a valid scale when -1023*N < k < 1024*N\n let sbits = load(EXP_DATA_TAB + (idx << alignof()), 1 << alignof()) + top; // T[idx + 1]\n // exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1).\n // Evaluation is optimized assuming superscalar pipelined execution.\n let r2 = r * r;\n // Without fma the worst case error is 0.25/N ulp larger.\n // Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp.\n let tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase(tmp, sbits, ki);\n let scale = reinterpret(sbits);\n // Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there\n // is no spurious underflow here even without fma.\n return scale + scale * tmp;\n}\n\n//\n// Lookup data for exp2. See: https://git.musl-libc.org/cgit/musl/tree/src/math/exp2.c\n//\n\n// Handle cases that may overflow or underflow when computing the result that\n// is scale*(1+TMP) without intermediate rounding. The bit representation of\n// scale is in SBITS, however it has a computed exponent that may have\n// overflown into the sign bit so that needs to be adjusted before using it as\n// a double. (int32_t)KI is the k used in the argument reduction and exponent\n// adjustment of scale, positive k here means the result may overflow and\n// negative k means the result may underflow.\n// @ts-ignore: decorator\n@inline\nfunction specialcase2(tmp: f64, sbits: u64, ki: u64): f64 {\n const Ox1p_1022 = reinterpret(0x10000000000000); // 0x1p-1022\n let scale: f64;\n if ((ki & 0x80000000) == 0) {\n // k > 0, the exponent of scale might have overflowed by 1\n sbits -= u64(1) << 52;\n scale = reinterpret(sbits);\n return 2 * (scale * tmp + scale);\n }\n // k < 0, need special care in the subnormal range\n sbits += u64(1022) << 52;\n scale = reinterpret(sbits);\n let y = scale * tmp + scale;\n if (y < 1.0) {\n // Round y to the right precision before scaling it into the subnormal\n // range to avoid double rounding that can cause 0.5+E/2 ulp error where\n // E is the worst-case ulp error outside the subnormal range. So this\n // is only useful if the goal is better than 1 ulp worst-case error.\n let hi: f64, lo: f64;\n lo = scale - y + scale * tmp;\n hi = 1.0 + y;\n lo = 1.0 - hi + y + lo;\n y = (hi + lo) - 1.0;\n }\n return y * Ox1p_1022;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function exp2_lut(x: f64): f64 {\n const\n N = 1 << EXP_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000) / N; // 0x1.8p52\n\n const\n C1 = reinterpret(0x3FE62E42FEFA39EF), // 0x1.62e42fefa39efp-1\n C2 = reinterpret(0x3FCEBFBDFF82C424), // 0x1.ebfbdff82c424p-3\n C3 = reinterpret(0x3FAC6B08D70CF4B5), // 0x1.c6b08d70cf4b5p-5\n C4 = reinterpret(0x3F83B2ABD24650CC), // 0x1.3b2abd24650ccp-7\n C5 = reinterpret(0x3F55D7E09B4E3A84); // 0x1.5d7e09b4e3a84p-10\n\n let ux = reinterpret(x);\n let abstop = u32(ux >> 52) & 0x7ff;\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) return 1.0;\n if (abstop >= 0x409) {\n if (ux == 0xFFF0000000000000) return 0;\n if (abstop >= 0x7FF) return 1.0 + x;\n if (ux >= 0) return Infinity;\n else if (ux >= 0xC090CC0000000000) return 0;\n }\n if ((ux << 1) > 0x811A000000000000) abstop = 0; // Large x is special cased below.\n }\n\n // exp2(x) = 2^(k/N) * 2^r, with 2^r in [2^(-1/2N),2^(1/2N)].\n // x = k/N + r, with int k and r in [-1/2N, 1/2N]\n let kd = x + shift;\n let ki = reinterpret(kd);\n kd -= shift; // k/N for int k\n let r = x - kd;\n // 2^(k/N) ~= scale * (1 + tail)\n let idx = usize((ki & N_MASK) << 1);\n let top = ki << (52 - EXP_TABLE_BITS);\n\n let tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof()), 0 << alignof())); // T[idx])\n // This is only a valid scale when -1023*N < k < 1024*N\n let sbits = load(EXP_DATA_TAB + (idx << alignof()), 1 << alignof()) + top; // T[idx + 1]\n // exp2(x) = 2^(k/N) * 2^r ~= scale + scale * (tail + 2^r - 1).\n // Evaluation is optimized assuming superscalar pipelined execution\n let r2 = r * r;\n // Without fma the worst case error is 0.5/N ulp larger.\n // Worst case error is less than 0.5+0.86/N+(abs poly error * 2^53) ulp.\n let tmp = tail + r * C1 + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase2(tmp, sbits, ki);\n let scale = reinterpret(sbits);\n // Note: tmp == 0 or |tmp| > 2^-65 and scale > 2^-928, so there\n // is no spurious underflow here even without fma.\n return scale * tmp + scale;\n}\n\n//\n// Lookup data for log2. See: https://git.musl-libc.org/cgit/musl/tree/src/math/log2.c\n//\n\n// @ts-ignore: decorator\n@inline const LOG2_TABLE_BITS = 6;\n\n/* Algorithm:\n\n x = 2^k z\n log2(x) = k + log2(c) + log2(z/c)\n log2(z/c) = poly(z/c - 1)\n\nwhere z is in [1.6p-1; 1.6p0] which is split into N subintervals and z falls\ninto the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = (double)log2(c)\n tab2[i].chi = (double)c\n tab2[i].clo = (double)(c - (double)c)\n\nwhere c is near the center of the subinterval and is chosen by trying +-2^29\nfloating point invc candidates around 1/center and selecting one for which\n\n 1) the rounding error in 0x1.8p10 + logc is 0,\n 2) the rounding error in z - chi - clo is < 0x1p-64 and\n 3) the rounding error in (double)log2(c) is minimized (< 0x1p-68).\n\nNote: 1) ensures that k + logc can be computed without rounding error, 2)\nensures that z/c - 1 can be computed as (z - chi - clo)*invc with close to a\nsingle rounding error when there is no fast fma for z*invc - 1, 3) ensures\nthat logc + poly(z/c - 1) has small error, however near x == 1 when\n|log2(x)| < 0x1p-4, this is not enough so that is special cased. */\n\n// @ts-ignore: decorator\n@lazy @inline const LOG2_DATA_TAB1 = memory.data([\n // invc , logc\n 0x3FF724286BB1ACF8, 0xBFE1095FEECDB000,\n 0x3FF6E1F766D2CCA1, 0xBFE08494BD76D000,\n 0x3FF6A13D0E30D48A, 0xBFE00143AEE8F800,\n 0x3FF661EC32D06C85, 0xBFDEFEC5360B4000,\n 0x3FF623FA951198F8, 0xBFDDFDD91AB7E000,\n 0x3FF5E75BA4CF026C, 0xBFDCFFAE0CC79000,\n 0x3FF5AC055A214FB8, 0xBFDC043811FDA000,\n 0x3FF571ED0F166E1E, 0xBFDB0B67323AE000,\n 0x3FF53909590BF835, 0xBFDA152F5A2DB000,\n 0x3FF5014FED61ADDD, 0xBFD9217F5AF86000,\n 0x3FF4CAB88E487BD0, 0xBFD8304DB0719000,\n 0x3FF49539B4334FEE, 0xBFD74189F9A9E000,\n 0x3FF460CBDFAFD569, 0xBFD6552BB5199000,\n 0x3FF42D664EE4B953, 0xBFD56B23A29B1000,\n 0x3FF3FB01111DD8A6, 0xBFD483650F5FA000,\n 0x3FF3C995B70C5836, 0xBFD39DE937F6A000,\n 0x3FF3991C4AB6FD4A, 0xBFD2BAA1538D6000,\n 0x3FF3698E0CE099B5, 0xBFD1D98340CA4000,\n 0x3FF33AE48213E7B2, 0xBFD0FA853A40E000,\n 0x3FF30D191985BDB1, 0xBFD01D9C32E73000,\n 0x3FF2E025CAB271D7, 0xBFCE857DA2FA6000,\n 0x3FF2B404CF13CD82, 0xBFCCD3C8633D8000,\n 0x3FF288B02C7CCB50, 0xBFCB26034C14A000,\n 0x3FF25E2263944DE5, 0xBFC97C1C2F4FE000,\n 0x3FF234563D8615B1, 0xBFC7D6023F800000,\n 0x3FF20B46E33EAF38, 0xBFC633A71A05E000,\n 0x3FF1E2EEFDCDA3DD, 0xBFC494F5E9570000,\n 0x3FF1BB4A580B3930, 0xBFC2F9E424E0A000,\n 0x3FF19453847F2200, 0xBFC162595AFDC000,\n 0x3FF16E06C0D5D73C, 0xBFBF9C9A75BD8000,\n 0x3FF1485F47B7E4C2, 0xBFBC7B575BF9C000,\n 0x3FF12358AD0085D1, 0xBFB960C60FF48000,\n 0x3FF0FEF00F532227, 0xBFB64CE247B60000,\n 0x3FF0DB2077D03A8F, 0xBFB33F78B2014000,\n 0x3FF0B7E6D65980D9, 0xBFB0387D1A42C000,\n 0x3FF0953EFE7B408D, 0xBFAA6F9208B50000,\n 0x3FF07325CAC53B83, 0xBFA47A954F770000,\n 0x3FF05197E40D1B5C, 0xBF9D23A8C50C0000,\n 0x3FF03091C1208EA2, 0xBF916A2629780000,\n 0x3FF0101025B37E21, 0xBF7720F8D8E80000,\n 0x3FEFC07EF9CAA76B, 0x3F86FE53B1500000,\n 0x3FEF4465D3F6F184, 0x3FA11CCCE10F8000,\n 0x3FEECC079F84107F, 0x3FAC4DFC8C8B8000,\n 0x3FEE573A99975AE8, 0x3FB3AA321E574000,\n 0x3FEDE5D6F0BD3DE6, 0x3FB918A0D08B8000,\n 0x3FED77B681FF38B3, 0x3FBE72E9DA044000,\n 0x3FED0CB5724DE943, 0x3FC1DCD2507F6000,\n 0x3FECA4B2DC0E7563, 0x3FC476AB03DEA000,\n 0x3FEC3F8EE8D6CB51, 0x3FC7074377E22000,\n 0x3FEBDD2B4F020C4C, 0x3FC98EDE8BA94000,\n 0x3FEB7D6C006015CA, 0x3FCC0DB86AD2E000,\n 0x3FEB20366E2E338F, 0x3FCE840AAFCEE000,\n 0x3FEAC57026295039, 0x3FD0790AB4678000,\n 0x3FEA6D01BC2731DD, 0x3FD1AC056801C000,\n 0x3FEA16D3BC3FF18B, 0x3FD2DB11D4FEE000,\n 0x3FE9C2D14967FEAD, 0x3FD406464EC58000,\n 0x3FE970E4F47C9902, 0x3FD52DBE093AF000,\n 0x3FE920FB3982BCF2, 0x3FD651902050D000,\n 0x3FE8D30187F759F1, 0x3FD771D2CDEAF000,\n 0x3FE886E5EBB9F66D, 0x3FD88E9C857D9000,\n 0x3FE83C97B658B994, 0x3FD9A80155E16000,\n 0x3FE7F405FFC61022, 0x3FDABE186ED3D000,\n 0x3FE7AD22181415CA, 0x3FDBD0F2AEA0E000,\n 0x3FE767DCF99EFF8C, 0x3FDCE0A43DBF4000\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const LOG2_DATA_TAB2 = memory.data([\n // chi , clo\n 0x3FE6200012B90A8E, 0x3C8904AB0644B605,\n 0x3FE66000045734A6, 0x3C61FF9BEA62F7A9,\n 0x3FE69FFFC325F2C5, 0x3C827ECFCB3C90BA,\n 0x3FE6E00038B95A04, 0x3C88FF8856739326,\n 0x3FE71FFFE09994E3, 0x3C8AFD40275F82B1,\n 0x3FE7600015590E10, 0xBC72FD75B4238341,\n 0x3FE7A00012655BD5, 0x3C7808E67C242B76,\n 0x3FE7E0003259E9A6, 0xBC6208E426F622B7,\n 0x3FE81FFFEDB4B2D2, 0xBC8402461EA5C92F,\n 0x3FE860002DFAFCC3, 0x3C6DF7F4A2F29A1F,\n 0x3FE89FFFF78C6B50, 0xBC8E0453094995FD,\n 0x3FE8E00039671566, 0xBC8A04F3BEC77B45,\n 0x3FE91FFFE2BF1745, 0xBC77FA34400E203C,\n 0x3FE95FFFCC5C9FD1, 0xBC76FF8005A0695D,\n 0x3FE9A0003BBA4767, 0x3C70F8C4C4EC7E03,\n 0x3FE9DFFFE7B92DA5, 0x3C8E7FD9478C4602,\n 0x3FEA1FFFD72EFDAF, 0xBC6A0C554DCDAE7E,\n 0x3FEA5FFFDE04FF95, 0x3C867DA98CE9B26B,\n 0x3FEA9FFFCA5E8D2B, 0xBC8284C9B54C13DE,\n 0x3FEADFFFDDAD03EA, 0x3C5812C8EA602E3C,\n 0x3FEB1FFFF10D3D4D, 0xBC8EFADDAD27789C,\n 0x3FEB5FFFCE21165A, 0x3C53CB1719C61237,\n 0x3FEB9FFFD950E674, 0x3C73F7D94194CE00,\n 0x3FEBE000139CA8AF, 0x3C750AC4215D9BC0,\n 0x3FEC20005B46DF99, 0x3C6BEEA653E9C1C9,\n 0x3FEC600040B9F7AE, 0xBC7C079F274A70D6,\n 0x3FECA0006255FD8A, 0xBC7A0B4076E84C1F,\n 0x3FECDFFFD94C095D, 0x3C88F933F99AB5D7,\n 0x3FED1FFFF975D6CF, 0xBC582C08665FE1BE,\n 0x3FED5FFFA2561C93, 0xBC7B04289BD295F3,\n 0x3FED9FFF9D228B0C, 0x3C870251340FA236,\n 0x3FEDE00065BC7E16, 0xBC75011E16A4D80C,\n 0x3FEE200002F64791, 0x3C89802F09EF62E0,\n 0x3FEE600057D7A6D8, 0xBC7E0B75580CF7FA,\n 0x3FEEA00027EDC00C, 0xBC8C848309459811,\n 0x3FEEE0006CF5CB7C, 0xBC8F8027951576F4,\n 0x3FEF2000782B7DCC, 0xBC8F81D97274538F,\n 0x3FEF6000260C450A, 0xBC4071002727FFDC,\n 0x3FEF9FFFE88CD533, 0xBC581BDCE1FDA8B0,\n 0x3FEFDFFFD50F8689, 0x3C87F91ACB918E6E,\n 0x3FF0200004292367, 0x3C9B7FF365324681,\n 0x3FF05FFFE3E3D668, 0x3C86FA08DDAE957B,\n 0x3FF0A0000A85A757, 0xBC57E2DE80D3FB91,\n 0x3FF0E0001A5F3FCC, 0xBC91823305C5F014,\n 0x3FF11FFFF8AFBAF5, 0xBC8BFABB6680BAC2,\n 0x3FF15FFFE54D91AD, 0xBC9D7F121737E7EF,\n 0x3FF1A00011AC36E1, 0x3C9C000A0516F5FF,\n 0x3FF1E00019C84248, 0xBC9082FBE4DA5DA0,\n 0x3FF220000FFE5E6E, 0xBC88FDD04C9CFB43,\n 0x3FF26000269FD891, 0x3C8CFE2A7994D182,\n 0x3FF2A00029A6E6DA, 0xBC700273715E8BC5,\n 0x3FF2DFFFE0293E39, 0x3C9B7C39DAB2A6F9,\n 0x3FF31FFFF7DCF082, 0x3C7DF1336EDC5254,\n 0x3FF35FFFF05A8B60, 0xBC9E03564CCD31EB,\n 0x3FF3A0002E0EAECC, 0x3C75F0E74BD3A477,\n 0x3FF3E000043BB236, 0x3C9C7DCB149D8833,\n 0x3FF4200002D187FF, 0x3C7E08AFCF2D3D28,\n 0x3FF460000D387CB1, 0x3C820837856599A6,\n 0x3FF4A00004569F89, 0xBC89FA5C904FBCD2,\n 0x3FF4E000043543F3, 0xBC781125ED175329,\n 0x3FF51FFFCC027F0F, 0x3C9883D8847754DC,\n 0x3FF55FFFFD87B36F, 0xBC8709E731D02807,\n 0x3FF59FFFF21DF7BA, 0x3C87F79F68727B02,\n 0x3FF5DFFFEBFC3481, 0xBC9180902E30E93E\n]);\n\n// @ts-ignore: decorator\n@inline\nexport function log2_lut(x: f64): f64 {\n const N_MASK = (1 << LOG2_TABLE_BITS) - 1;\n\n const\n LO: u64 = 0x3FEEA4AF00000000, // reinterpret(1.0 - 0x1.5b51p-5)\n HI: u64 = 0x3FF0B55900000000; // reinterpret(1.0 + 0x1.6ab2p-5)\n\n const\n InvLn2hi = reinterpret(0x3FF7154765200000), // 0x1.7154765200000p+0\n InvLn2lo = reinterpret(0x3DE705FC2EEFA200), // 0x1.705fc2eefa200p-33\n Ox1p52 = reinterpret(0x4330000000000000); // 0x1p52\n\n const\n B0 = reinterpret(0xBFE71547652B82FE), // -0x1.71547652b82fep-1\n B1 = reinterpret(0x3FDEC709DC3A03F7), // 0x1.ec709dc3a03f7p-2\n B2 = reinterpret(0xBFD71547652B7C3F), // -0x1.71547652b7c3fp-2\n B3 = reinterpret(0x3FD2776C50F05BE4), // 0x1.2776c50f05be4p-2\n B4 = reinterpret(0xBFCEC709DD768FE5), // -0x1.ec709dd768fe5p-3\n B5 = reinterpret(0x3FCA61761EC4E736), // 0x1.a61761ec4e736p-3\n B6 = reinterpret(0xBFC7153FBC64A79B), // -0x1.7153fbc64a79bp-3\n B7 = reinterpret(0x3FC484D154F01B4A), // 0x1.484d154f01b4ap-3\n B8 = reinterpret(0xBFC289E4A72C383C), // -0x1.289e4a72c383cp-3\n B9 = reinterpret(0x3FC0B32F285AEE66); // 0x1.0b32f285aee66p-3\n\n const\n A0 = reinterpret(0xBFE71547652B8339), // -0x1.71547652b8339p-1\n A1 = reinterpret(0x3FDEC709DC3A04BE), // 0x1.ec709dc3a04bep-2\n A2 = reinterpret(0xBFD7154764702FFB), // -0x1.7154764702ffbp-2\n A3 = reinterpret(0x3FD2776C50034C48), // 0x1.2776c50034c48p-2\n A4 = reinterpret(0xBFCEC7B328EA92BC), // -0x1.ec7b328ea92bcp-3\n A5 = reinterpret(0x3FCA6225E117F92E); // 0x1.a6225e117f92ep-3\n\n let ix = reinterpret(x);\n if (ix - LO < HI - LO) {\n let r = x - 1.0;\n // #if __FP_FAST_FMA\n // hi = r * InvLn2hi;\n // lo = r * InvLn2lo + __builtin_fma(r, InvLn2hi, -hi);\n // #else\n let rhi = reinterpret(reinterpret(r) & 0xFFFFFFFF00000000);\n let rlo = r - rhi;\n let hi = rhi * InvLn2hi;\n let lo = rlo * InvLn2hi + r * InvLn2lo;\n // #endif\n let r2 = r * r; // rounding error: 0x1p-62\n let r4 = r2 * r2;\n // Worst-case error is less than 0.54 ULP (0.55 ULP without fma)\n let p = r2 * (B0 + r * B1);\n let y = hi + p;\n lo += hi - y + p;\n lo += r4 * (B2 + r * B3 + r2 * (B4 + r * B5) +\n r4 * (B6 + r * B7 + r2 * (B8 + r * B9)));\n return y + lo;\n }\n let top = u32(ix >> 48);\n if (top - 0x0010 >= 0x7ff0 - 0x0010) {\n // x < 0x1p-1022 or inf or nan.\n if ((ix << 1) == 0) return -1.0 / (x * x);\n if (ix == 0x7FF0000000000000) return x; // log(inf) == inf\n if ((top & 0x8000) || (top & 0x7FF0) == 0x7FF0) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ix = reinterpret(x * Ox1p52);\n ix -= u64(52) << 52;\n }\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n let tmp = ix - 0x3FE6000000000000;\n let i = ((tmp >> (52 - LOG2_TABLE_BITS)) & N_MASK);\n let k = tmp >> 52;\n let iz = ix - (tmp & 0xFFF0000000000000);\n\n let invc = load(LOG2_DATA_TAB1 + (i << (1 + alignof())), 0 << alignof()); // T[i].invc;\n let logc = load(LOG2_DATA_TAB1 + (i << (1 + alignof())), 1 << alignof()); // T[i].logc;\n let z = reinterpret(iz);\n let kd = k;\n\n // log2(x) = log2(z/c) + log2(c) + k.\n // r ~= z/c - 1, |r| < 1/(2*N).\n // #if __FP_FAST_FMA\n // \t// rounding error: 0x1p-55/N.\n // \tr = __builtin_fma(z, invc, -1.0);\n // \tt1 = r * InvLn2hi;\n // \tt2 = r * InvLn2lo + __builtin_fma(r, InvLn2hi, -t1);\n // #else\n // rounding error: 0x1p-55/N + 0x1p-65.\n let chi = load(LOG2_DATA_TAB2 + (i << (1 + alignof())), 0 << alignof()); // T[i].chi;\n let clo = load(LOG2_DATA_TAB2 + (i << (1 + alignof())), 1 << alignof()); // T[i].clo;\n\n let r = (z - chi - clo) * invc;\n let rhi = reinterpret(reinterpret(r) & 0xFFFFFFFF00000000);\n let rlo = r - rhi;\n let t1 = rhi * InvLn2hi;\n let t2 = rlo * InvLn2hi + r * InvLn2lo;\n // #endif\n\n // hi + lo = r/ln2 + log2(c) + k\n let t3 = kd + logc;\n let hi = t3 + t1;\n let lo = t3 - hi + t1 + t2;\n\n // log2(r+1) = r/ln2 + r^2*poly(r)\n // Evaluation is optimized assuming superscalar pipelined execution\n let r2 = r * r; // rounding error: 0x1p-54/N^2\n // Worst-case error if |y| > 0x1p-4: 0.547 ULP (0.550 ULP without fma).\n // ~ 0.5 + 2/N/ln2 + abs-poly-error*0x1p56 ULP (+ 0.003 ULP without fma).\n let p = A0 + r * A1 + r2 * (A2 + r * A3) + (r2 * r2) * (A4 + r * A5);\n return lo + r2 * p + hi;\n}\n\n//\n// Lookup data for log. See: https://git.musl-libc.org/cgit/musl/tree/src/math/log.c\n//\n\n// @ts-ignore: decorator\n@inline const LOG_TABLE_BITS = 7;\n\n/* Algorithm:\n\n x = 2^k z\n log(x) = k ln2 + log(c) + log(z/c)\n log(z/c) = poly(z/c - 1)\n\nwhere z is in [1.6p-1; 1.6p0] which is split into N subintervals and z falls\ninto the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = (double)log(c)\n tab2[i].chi = (double)c\n tab2[i].clo = (double)(c - (double)c)\n\nwhere c is near the center of the subinterval and is chosen by trying +-2^29\nfloating point invc candidates around 1/center and selecting one for which\n\n 1) the rounding error in 0x1.8p9 + logc is 0,\n 2) the rounding error in z - chi - clo is < 0x1p-66 and\n 3) the rounding error in (double)log(c) is minimized (< 0x1p-66).\n\nNote: 1) ensures that k*ln2hi + logc can be computed without rounding error,\n2) ensures that z/c - 1 can be computed as (z - chi - clo)*invc with close to\na single rounding error when there is no fast fma for z*invc - 1, 3) ensures\nthat logc + poly(z/c - 1) has small error, however near x == 1 when\n|log(x)| < 0x1p-4, this is not enough so that is special cased.*/\n\n// @ts-ignore: decorator\n@lazy @inline const LOG_DATA_TAB1 = memory.data([\n // invc , logc\n 0x3FF734F0C3E0DE9F, 0xBFD7CC7F79E69000,\n 0x3FF713786A2CE91F, 0xBFD76FEEC20D0000,\n 0x3FF6F26008FAB5A0, 0xBFD713E31351E000,\n 0x3FF6D1A61F138C7D, 0xBFD6B85B38287800,\n 0x3FF6B1490BC5B4D1, 0xBFD65D5590807800,\n 0x3FF69147332F0CBA, 0xBFD602D076180000,\n 0x3FF6719F18224223, 0xBFD5A8CA86909000,\n 0x3FF6524F99A51ED9, 0xBFD54F4356035000,\n 0x3FF63356AA8F24C4, 0xBFD4F637C36B4000,\n 0x3FF614B36B9DDC14, 0xBFD49DA7FDA85000,\n 0x3FF5F66452C65C4C, 0xBFD445923989A800,\n 0x3FF5D867B5912C4F, 0xBFD3EDF439B0B800,\n 0x3FF5BABCCB5B90DE, 0xBFD396CE448F7000,\n 0x3FF59D61F2D91A78, 0xBFD3401E17BDA000,\n 0x3FF5805612465687, 0xBFD2E9E2EF468000,\n 0x3FF56397CEE76BD3, 0xBFD2941B3830E000,\n 0x3FF54725E2A77F93, 0xBFD23EC58CDA8800,\n 0x3FF52AFF42064583, 0xBFD1E9E129279000,\n 0x3FF50F22DBB2BDDF, 0xBFD1956D2B48F800,\n 0x3FF4F38F4734DED7, 0xBFD141679AB9F800,\n 0x3FF4D843CFDE2840, 0xBFD0EDD094EF9800,\n 0x3FF4BD3EC078A3C8, 0xBFD09AA518DB1000,\n 0x3FF4A27FC3E0258A, 0xBFD047E65263B800,\n 0x3FF4880524D48434, 0xBFCFEB224586F000,\n 0x3FF46DCE1B192D0B, 0xBFCF474A7517B000,\n 0x3FF453D9D3391854, 0xBFCEA4443D103000,\n 0x3FF43A2744B4845A, 0xBFCE020D44E9B000,\n 0x3FF420B54115F8FB, 0xBFCD60A22977F000,\n 0x3FF40782DA3EF4B1, 0xBFCCC00104959000,\n 0x3FF3EE8F5D57FE8F, 0xBFCC202956891000,\n 0x3FF3D5D9A00B4CE9, 0xBFCB81178D811000,\n 0x3FF3BD60C010C12B, 0xBFCAE2C9CCD3D000,\n 0x3FF3A5242B75DAB8, 0xBFCA45402E129000,\n 0x3FF38D22CD9FD002, 0xBFC9A877681DF000,\n 0x3FF3755BC5847A1C, 0xBFC90C6D69483000,\n 0x3FF35DCE49AD36E2, 0xBFC87120A645C000,\n 0x3FF34679984DD440, 0xBFC7D68FB4143000,\n 0x3FF32F5CCEFFCB24, 0xBFC73CB83C627000,\n 0x3FF3187775A10D49, 0xBFC6A39A9B376000,\n 0x3FF301C8373E3990, 0xBFC60B3154B7A000,\n 0x3FF2EB4EBB95F841, 0xBFC5737D76243000,\n 0x3FF2D50A0219A9D1, 0xBFC4DC7B8FC23000,\n 0x3FF2BEF9A8B7FD2A, 0xBFC4462C51D20000,\n 0x3FF2A91C7A0C1BAB, 0xBFC3B08ABC830000,\n 0x3FF293726014B530, 0xBFC31B996B490000,\n 0x3FF27DFA5757A1F5, 0xBFC2875490A44000,\n 0x3FF268B39B1D3BBF, 0xBFC1F3B9F879A000,\n 0x3FF2539D838FF5BD, 0xBFC160C8252CA000,\n 0x3FF23EB7AAC9083B, 0xBFC0CE7F57F72000,\n 0x3FF22A012BA940B6, 0xBFC03CDC49FEA000,\n 0x3FF2157996CC4132, 0xBFBF57BDBC4B8000,\n 0x3FF201201DD2FC9B, 0xBFBE370896404000,\n 0x3FF1ECF4494D480B, 0xBFBD17983EF94000,\n 0x3FF1D8F5528F6569, 0xBFBBF9674ED8A000,\n 0x3FF1C52311577E7C, 0xBFBADC79202F6000,\n 0x3FF1B17C74CB26E9, 0xBFB9C0C3E7288000,\n 0x3FF19E010C2C1AB6, 0xBFB8A646B372C000,\n 0x3FF18AB07BB670BD, 0xBFB78D01B3AC0000,\n 0x3FF1778A25EFBCB6, 0xBFB674F145380000,\n 0x3FF1648D354C31DA, 0xBFB55E0E6D878000,\n 0x3FF151B990275FDD, 0xBFB4485CDEA1E000,\n 0x3FF13F0EA432D24C, 0xBFB333D94D6AA000,\n 0x3FF12C8B7210F9DA, 0xBFB22079F8C56000,\n 0x3FF11A3028ECB531, 0xBFB10E4698622000,\n 0x3FF107FBDA8434AF, 0xBFAFFA6C6AD20000,\n 0x3FF0F5EE0F4E6BB3, 0xBFADDA8D4A774000,\n 0x3FF0E4065D2A9FCE, 0xBFABBCECE4850000,\n 0x3FF0D244632CA521, 0xBFA9A1894012C000,\n 0x3FF0C0A77CE2981A, 0xBFA788583302C000,\n 0x3FF0AF2F83C636D1, 0xBFA5715E67D68000,\n 0x3FF09DDB98A01339, 0xBFA35C8A49658000,\n 0x3FF08CABAF52E7DF, 0xBFA149E364154000,\n 0x3FF07B9F2F4E28FB, 0xBF9E72C082EB8000,\n 0x3FF06AB58C358F19, 0xBF9A55F152528000,\n 0x3FF059EEA5ECF92C, 0xBF963D62CF818000,\n 0x3FF04949CDD12C90, 0xBF9228FB8CAA0000,\n 0x3FF038C6C6F0ADA9, 0xBF8C317B20F90000,\n 0x3FF02865137932A9, 0xBF8419355DAA0000,\n 0x3FF0182427EA7348, 0xBF781203C2EC0000,\n 0x3FF008040614B195, 0xBF60040979240000,\n 0x3FEFE01FF726FA1A, 0x3F6FEFF384900000,\n 0x3FEFA11CC261EA74, 0x3F87DC41353D0000,\n 0x3FEF6310B081992E, 0x3F93CEA3C4C28000,\n 0x3FEF25F63CEEADCD, 0x3F9B9FC114890000,\n 0x3FEEE9C8039113E7, 0x3FA1B0D8CE110000,\n 0x3FEEAE8078CBB1AB, 0x3FA58A5BD001C000,\n 0x3FEE741AA29D0C9B, 0x3FA95C8340D88000,\n 0x3FEE3A91830A99B5, 0x3FAD276AEF578000,\n 0x3FEE01E009609A56, 0x3FB07598E598C000,\n 0x3FEDCA01E577BB98, 0x3FB253F5E30D2000,\n 0x3FED92F20B7C9103, 0x3FB42EDD8B380000,\n 0x3FED5CAC66FB5CCE, 0x3FB606598757C000,\n 0x3FED272CAA5EDE9D, 0x3FB7DA76356A0000,\n 0x3FECF26E3E6B2CCD, 0x3FB9AB434E1C6000,\n 0x3FECBE6DA2A77902, 0x3FBB78C7BB0D6000,\n 0x3FEC8B266D37086D, 0x3FBD431332E72000,\n 0x3FEC5894BD5D5804, 0x3FBF0A3171DE6000,\n 0x3FEC26B533BB9F8C, 0x3FC067152B914000,\n 0x3FEBF583EEECE73F, 0x3FC147858292B000,\n 0x3FEBC4FD75DB96C1, 0x3FC2266ECDCA3000,\n 0x3FEB951E0C864A28, 0x3FC303D7A6C55000,\n 0x3FEB65E2C5EF3E2C, 0x3FC3DFC33C331000,\n 0x3FEB374867C9888B, 0x3FC4BA366B7A8000,\n 0x3FEB094B211D304A, 0x3FC5933928D1F000,\n 0x3FEADBE885F2EF7E, 0x3FC66ACD2418F000,\n 0x3FEAAF1D31603DA2, 0x3FC740F8EC669000,\n 0x3FEA82E63FD358A7, 0x3FC815C0F51AF000,\n 0x3FEA5740EF09738B, 0x3FC8E92954F68000,\n 0x3FEA2C2A90AB4B27, 0x3FC9BB3602F84000,\n 0x3FEA01A01393F2D1, 0x3FCA8BED1C2C0000,\n 0x3FE9D79F24DB3C1B, 0x3FCB5B515C01D000,\n 0x3FE9AE2505C7B190, 0x3FCC2967CCBCC000,\n 0x3FE9852EF297CE2F, 0x3FCCF635D5486000,\n 0x3FE95CBAEEA44B75, 0x3FCDC1BD3446C000,\n 0x3FE934C69DE74838, 0x3FCE8C01B8CFE000,\n 0x3FE90D4F2F6752E6, 0x3FCF5509C0179000,\n 0x3FE8E6528EFFD79D, 0x3FD00E6C121FB800,\n 0x3FE8BFCE9FCC007C, 0x3FD071B80E93D000,\n 0x3FE899C0DABEC30E, 0x3FD0D46B9E867000,\n 0x3FE87427AA2317FB, 0x3FD13687334BD000,\n 0x3FE84F00ACB39A08, 0x3FD1980D67234800,\n 0x3FE82A49E8653E55, 0x3FD1F8FFE0CC8000,\n 0x3FE8060195F40260, 0x3FD2595FD7636800,\n 0x3FE7E22563E0A329, 0x3FD2B9300914A800,\n 0x3FE7BEB377DCB5AD, 0x3FD3187210436000,\n 0x3FE79BAA679725C2, 0x3FD377266DEC1800,\n 0x3FE77907F2170657, 0x3FD3D54FFBAF3000,\n 0x3FE756CADBD6130C, 0x3FD432EEE32FE000\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const LOG_DATA_TAB2 = memory.data([\n // chi , clo\n 0x3FE61000014FB66B, 0x3C7E026C91425B3C,\n 0x3FE63000034DB495, 0x3C8DBFEA48005D41,\n 0x3FE650000D94D478, 0x3C8E7FA786D6A5B7,\n 0x3FE67000074E6FAD, 0x3C61FCEA6B54254C,\n 0x3FE68FFFFEDF0FAE, 0xBC7C7E274C590EFD,\n 0x3FE6B0000763C5BC, 0xBC8AC16848DCDA01,\n 0x3FE6D0001E5CC1F6, 0x3C833F1C9D499311,\n 0x3FE6EFFFEB05F63E, 0xBC7E80041AE22D53,\n 0x3FE710000E869780, 0x3C7BFF6671097952,\n 0x3FE72FFFFC67E912, 0x3C8C00E226BD8724,\n 0x3FE74FFFDF81116A, 0xBC6E02916EF101D2,\n 0x3FE770000F679C90, 0xBC67FC71CD549C74,\n 0x3FE78FFFFA7EC835, 0x3C81BEC19EF50483,\n 0x3FE7AFFFFE20C2E6, 0xBC707E1729CC6465,\n 0x3FE7CFFFED3FC900, 0xBC808072087B8B1C,\n 0x3FE7EFFFE9261A76, 0x3C8DC0286D9DF9AE,\n 0x3FE81000049CA3E8, 0x3C897FD251E54C33,\n 0x3FE8300017932C8F, 0xBC8AFEE9B630F381,\n 0x3FE850000633739C, 0x3C89BFBF6B6535BC,\n 0x3FE87000204289C6, 0xBC8BBF65F3117B75,\n 0x3FE88FFFEBF57904, 0xBC89006EA23DCB57,\n 0x3FE8B00022BC04DF, 0xBC7D00DF38E04B0A,\n 0x3FE8CFFFE50C1B8A, 0xBC88007146FF9F05,\n 0x3FE8EFFFFC918E43, 0x3C83817BD07A7038,\n 0x3FE910001EFA5FC7, 0x3C893E9176DFB403,\n 0x3FE9300013467BB9, 0x3C7F804E4B980276,\n 0x3FE94FFFE6EE076F, 0xBC8F7EF0D9FF622E,\n 0x3FE96FFFDE3C12D1, 0xBC7082AA962638BA,\n 0x3FE98FFFF4458A0D, 0xBC87801B9164A8EF,\n 0x3FE9AFFFDD982E3E, 0xBC8740E08A5A9337,\n 0x3FE9CFFFED49FB66, 0x3C3FCE08C19BE000,\n 0x3FE9F00020F19C51, 0xBC8A3FAA27885B0A,\n 0x3FEA10001145B006, 0x3C74FF489958DA56,\n 0x3FEA300007BBF6FA, 0x3C8CBEAB8A2B6D18,\n 0x3FEA500010971D79, 0x3C88FECADD787930,\n 0x3FEA70001DF52E48, 0xBC8F41763DD8ABDB,\n 0x3FEA90001C593352, 0xBC8EBF0284C27612,\n 0x3FEAB0002A4F3E4B, 0xBC69FD043CFF3F5F,\n 0x3FEACFFFD7AE1ED1, 0xBC823EE7129070B4,\n 0x3FEAEFFFEE510478, 0x3C6A063EE00EDEA3,\n 0x3FEB0FFFDB650D5B, 0x3C5A06C8381F0AB9,\n 0x3FEB2FFFFEAACA57, 0xBC79011E74233C1D,\n 0x3FEB4FFFD995BADC, 0xBC79FF1068862A9F,\n 0x3FEB7000249E659C, 0x3C8AFF45D0864F3E,\n 0x3FEB8FFFF9871640, 0x3C7CFE7796C2C3F9,\n 0x3FEBAFFFD204CB4F, 0xBC63FF27EEF22BC4,\n 0x3FEBCFFFD2415C45, 0xBC6CFFB7EE3BEA21,\n 0x3FEBEFFFF86309DF, 0xBC814103972E0B5C,\n 0x3FEC0FFFE1B57653, 0x3C8BC16494B76A19,\n 0x3FEC2FFFF1FA57E3, 0xBC64FEEF8D30C6ED,\n 0x3FEC4FFFDCBFE424, 0xBC843F68BCEC4775,\n 0x3FEC6FFFED54B9F7, 0x3C847EA3F053E0EC,\n 0x3FEC8FFFEB998FD5, 0x3C7383068DF992F1,\n 0x3FECB0002125219A, 0xBC68FD8E64180E04,\n 0x3FECCFFFDD94469C, 0x3C8E7EBE1CC7EA72,\n 0x3FECEFFFEAFDC476, 0x3C8EBE39AD9F88FE,\n 0x3FED1000169AF82B, 0x3C757D91A8B95A71,\n 0x3FED30000D0FF71D, 0x3C89C1906970C7DA,\n 0x3FED4FFFEA790FC4, 0xBC580E37C558FE0C,\n 0x3FED70002EDC87E5, 0xBC7F80D64DC10F44,\n 0x3FED900021DC82AA, 0xBC747C8F94FD5C5C,\n 0x3FEDAFFFD86B0283, 0x3C8C7F1DC521617E,\n 0x3FEDD000296C4739, 0x3C88019EB2FFB153,\n 0x3FEDEFFFE54490F5, 0x3C6E00D2C652CC89,\n 0x3FEE0FFFCDABF694, 0xBC7F8340202D69D2,\n 0x3FEE2FFFDB52C8DD, 0x3C7B00C1CA1B0864,\n 0x3FEE4FFFF24216EF, 0x3C72FFA8B094AB51,\n 0x3FEE6FFFE88A5E11, 0xBC57F673B1EFBE59,\n 0x3FEE9000119EFF0D, 0xBC84808D5E0BC801,\n 0x3FEEAFFFDFA51744, 0x3C780006D54320B5,\n 0x3FEED0001A127FA1, 0xBC5002F860565C92,\n 0x3FEEF00007BABCC4, 0xBC8540445D35E611,\n 0x3FEF0FFFF57A8D02, 0xBC4FFB3139EF9105,\n 0x3FEF30001EE58AC7, 0x3C8A81ACF2731155,\n 0x3FEF4FFFF5823494, 0x3C8A3F41D4D7C743,\n 0x3FEF6FFFFCA94C6B, 0xBC6202F41C987875,\n 0x3FEF8FFFE1F9C441, 0x3C777DD1F477E74B,\n 0x3FEFAFFFD2E0E37E, 0xBC6F01199A7CA331,\n 0x3FEFD0001C77E49E, 0x3C7181EE4BCEACB1,\n 0x3FEFEFFFF7E0C331, 0xBC6E05370170875A,\n 0x3FF00FFFF465606E, 0xBC8A7EAD491C0ADA,\n 0x3FF02FFFF3867A58, 0xBC977F69C3FCB2E0,\n 0x3FF04FFFFDFC0D17, 0x3C97BFFE34CB945B,\n 0x3FF0700003CD4D82, 0x3C820083C0E456CB,\n 0x3FF08FFFF9F2CBE8, 0xBC6DFFDFBE37751A,\n 0x3FF0B000010CDA65, 0xBC913F7FAEE626EB,\n 0x3FF0D00001A4D338, 0x3C807DFA79489FF7,\n 0x3FF0EFFFFADAFDFD, 0xBC77040570D66BC0,\n 0x3FF110000BBAFD96, 0x3C8E80D4846D0B62,\n 0x3FF12FFFFAE5F45D, 0x3C9DBFFA64FD36EF,\n 0x3FF150000DD59AD9, 0x3C9A0077701250AE,\n 0x3FF170000F21559A, 0x3C8DFDF9E2E3DEEE,\n 0x3FF18FFFFC275426, 0x3C910030DC3B7273,\n 0x3FF1B000123D3C59, 0x3C997F7980030188,\n 0x3FF1CFFFF8299EB7, 0xBC65F932AB9F8C67,\n 0x3FF1EFFFF48AD400, 0x3C937FBF9DA75BEB,\n 0x3FF210000C8B86A4, 0x3C9F806B91FD5B22,\n 0x3FF2300003854303, 0x3C93FFC2EB9FBF33,\n 0x3FF24FFFFFBCF684, 0x3C7601E77E2E2E72,\n 0x3FF26FFFF52921D9, 0x3C7FFCBB767F0C61,\n 0x3FF2900014933A3C, 0xBC7202CA3C02412B,\n 0x3FF2B00014556313, 0xBC92808233F21F02,\n 0x3FF2CFFFEBFE523B, 0xBC88FF7E384FDCF2,\n 0x3FF2F0000BB8AD96, 0xBC85FF51503041C5,\n 0x3FF30FFFFB7AE2AF, 0xBC810071885E289D,\n 0x3FF32FFFFEAC5F7F, 0xBC91FF5D3FB7B715,\n 0x3FF350000CA66756, 0x3C957F82228B82BD,\n 0x3FF3700011FBF721, 0x3C8000BAC40DD5CC,\n 0x3FF38FFFF9592FB9, 0xBC943F9D2DB2A751,\n 0x3FF3B00004DDD242, 0x3C857F6B707638E1,\n 0x3FF3CFFFF5B2C957, 0x3C7A023A10BF1231,\n 0x3FF3EFFFEAB0B418, 0x3C987F6D66B152B0,\n 0x3FF410001532AFF4, 0x3C67F8375F198524,\n 0x3FF4300017478B29, 0x3C8301E672DC5143,\n 0x3FF44FFFE795B463, 0x3C89FF69B8B2895A,\n 0x3FF46FFFE80475E0, 0xBC95C0B19BC2F254,\n 0x3FF48FFFEF6FC1E7, 0x3C9B4009F23A2A72,\n 0x3FF4AFFFE5BEA704, 0xBC94FFB7BF0D7D45,\n 0x3FF4D000171027DE, 0xBC99C06471DC6A3D,\n 0x3FF4F0000FF03EE2, 0x3C977F890B85531C,\n 0x3FF5100012DC4BD1, 0x3C6004657166A436,\n 0x3FF530001605277A, 0xBC96BFCECE233209,\n 0x3FF54FFFECDB704C, 0xBC8902720505A1D7,\n 0x3FF56FFFEF5F54A9, 0x3C9BBFE60EC96412,\n 0x3FF5900017E61012, 0x3C887EC581AFEF90,\n 0x3FF5B00003C93E92, 0xBC9F41080ABF0CC0,\n 0x3FF5D0001D4919BC, 0xBC98812AFB254729,\n 0x3FF5EFFFE7B87A89, 0xBC947EB780ED6904\n]);\n\n// @ts-ignore: decorator\n@inline\nexport function log_lut(x: f64): f64 {\n const N_MASK = (1 << LOG_TABLE_BITS) - 1;\n\n const\n B0 = reinterpret(0xBFE0000000000000), // -0x1p-1\n B1 = reinterpret(0x3FD5555555555577), // 0x1.5555555555577p-2\n B2 = reinterpret(0xBFCFFFFFFFFFFDCB), // -0x1.ffffffffffdcbp-3\n B3 = reinterpret(0x3FC999999995DD0C), // 0x1.999999995dd0cp-3\n B4 = reinterpret(0xBFC55555556745A7), // -0x1.55555556745a7p-3\n B5 = reinterpret(0x3FC24924A344DE30), // 0x1.24924a344de3p-3\n B6 = reinterpret(0xBFBFFFFFA4423D65), // -0x1.fffffa4423d65p-4\n B7 = reinterpret(0x3FBC7184282AD6CA), // 0x1.c7184282ad6cap-4\n B8 = reinterpret(0xBFB999EB43B068FF), // -0x1.999eb43b068ffp-4\n B9 = reinterpret(0x3FB78182F7AFD085), // 0x1.78182f7afd085p-4\n B10 = reinterpret(0xBFB5521375D145CD); // -0x1.5521375d145cdp-4\n\n const\n A0 = reinterpret(0xBFE0000000000001), // -0x1.0000000000001p-1\n A1 = reinterpret(0x3FD555555551305B), // 0x1.555555551305bp-2\n A2 = reinterpret(0xBFCFFFFFFFEB4590), // -0x1.fffffffeb459p-3\n A3 = reinterpret(0x3FC999B324F10111), // 0x1.999b324f10111p-3\n A4 = reinterpret(0xBFC55575E506C89F); // -0x1.55575e506c89fp-3\n\n const\n LO: u64 = 0x3FEE000000000000,\n HI: u64 = 0x3FF1090000000000;\n\n const\n Ln2hi = reinterpret(0x3FE62E42FEFA3800), // 0x1.62e42fefa3800p-1\n Ln2lo = reinterpret(0x3D2EF35793C76730), // 0x1.ef35793c76730p-45\n Ox1p27 = reinterpret(0x41A0000000000000), // 0x1p27\n Ox1p52 = reinterpret(0x4330000000000000); // 0x1p52\n\n let ix = reinterpret(x);\n if (ix - LO < HI - LO) {\n let r = x - 1.0;\n let r2 = r * r;\n let r3 = r2 * r;\n let y =\n r3 * (B1 + r * B2 + r2 * B3 +\n r3 * (B4 + r * B5 + r2 * B6 +\n r3 * (B7 + r * B8 + r2 * B9 + r3 * B10)));\n // Worst-case error is around 0.507 ULP\n let w = r * Ox1p27;\n let rhi = r + w - w;\n let rlo = r - rhi;\n w = rhi * rhi * B0; // B[0] == -0.5\n let hi = r + w;\n let lo = r - hi + w;\n lo += B0 * rlo * (rhi + r);\n return y + lo + hi;\n }\n let top = u32(ix >> 48);\n if (top - 0x0010 >= 0x7FF0 - 0x0010) {\n // x < 0x1p-1022 or inf or nan\n if ((ix << 1) == 0) return -1.0 / (x * x);\n if (ix == reinterpret(Infinity)) return x; // log(inf) == inf\n if ((top & 0x8000) || (top & 0x7FF0) == 0x7FF0) return (x - x) / (x - x);\n // x is subnormal, normalize it\n ix = reinterpret(x * Ox1p52);\n ix -= u64(52) << 52;\n }\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n let tmp = ix - 0x3FE6000000000000;\n let i = ((tmp >> (52 - LOG_TABLE_BITS)) & N_MASK);\n let k = tmp >> 52;\n let iz = ix - (tmp & (u64(0xFFF) << 52));\n\n let invc = load(LOG_DATA_TAB1 + (i << (1 + alignof())), 0 << alignof()); // T[i].invc;\n let logc = load(LOG_DATA_TAB1 + (i << (1 + alignof())), 1 << alignof()); // T[i].logc;\n let z = reinterpret(iz);\n\n // log(x) = log1p(z/c-1) + log(c) + k*Ln2.\n // r ~= z/c - 1, |r| < 1/(2*N)\n // #if __FP_FAST_FMA\n // \t// rounding error: 0x1p-55/N\n // \tr = __builtin_fma(z, invc, -1.0);\n // #else\n // rounding error: 0x1p-55/N + 0x1p-66\n const chi = load(LOG_DATA_TAB2 + (i << (1 + alignof())), 0 << alignof()); // T2[i].chi\n const clo = load(LOG_DATA_TAB2 + (i << (1 + alignof())), 1 << alignof()); // T2[i].clo\n let r = (z - chi - clo) * invc;\n // #endif\n let kd = k;\n\n // hi + lo = r + log(c) + k*Ln2\n let w = kd * Ln2hi + logc;\n let hi = w + r;\n let lo = w - hi + r + kd * Ln2lo;\n\n // log(x) = lo + (log1p(r) - r) + hi\n let r2 = r * r; // rounding error: 0x1p-54/N^2\n // Worst case error if |y| > 0x1p-5:\n // 0.5 + 4.13/N + abs-poly-error*2^57 ULP (+ 0.002 ULP without fma)\n // Worst case error if |y| > 0x1p-4:\n // 0.5 + 2.06/N + abs-poly-error*2^56 ULP (+ 0.001 ULP without fma).\n return lo + r2 * A0 + r * r2 * (A1 + r * A2 + r2 * (A3 + r * A4)) + hi;\n}\n\n//\n// Lookup data for pow. See: https://git.musl-libc.org/cgit/musl/tree/src/math/pow.c\n//\n\n// @ts-ignore: decorator\n@inline const POW_LOG_TABLE_BITS = 7;\n\n/* Algorithm:\n\n x = 2^k z\n log(x) = k ln2 + log(c) + log(z/c)\n log(z/c) = poly(z/c - 1)\n\nwhere z is in [0x1.69555p-1; 0x1.69555p0] which is split into N subintervals\nand z falls into the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = round(0x1p43*log(c))/0x1p43\n tab[i].logctail = (double)(log(c) - logc)\n\nwhere c is chosen near the center of the subinterval such that 1/c has only a\nfew precision bits so z/c - 1 is exactly representible as double:\n\n 1/c = center < 1 ? round(N/center)/N : round(2*N/center)/N/2\n\nNote: |z/c - 1| < 1/N for the chosen c, |log(c) - logc - logctail| < 0x1p-97,\nthe last few bits of logc are rounded away so k*ln2hi + logc has no rounding\nerror and the interval for z is selected such that near x == 1, where log(x)\nis tiny, large cancellation error is avoided in logc + poly(z/c - 1). */\n\n// @ts-ignore: decorator\n@lazy @inline const POW_LOG_DATA_TAB = memory.data([\n // invc ,pad, logc , logctail\n 0x3FF6A00000000000, 0, 0xBFD62C82F2B9C800, 0x3CFAB42428375680,\n 0x3FF6800000000000, 0, 0xBFD5D1BDBF580800, 0xBD1CA508D8E0F720,\n 0x3FF6600000000000, 0, 0xBFD5767717455800, 0xBD2362A4D5B6506D,\n 0x3FF6400000000000, 0, 0xBFD51AAD872DF800, 0xBCE684E49EB067D5,\n 0x3FF6200000000000, 0, 0xBFD4BE5F95777800, 0xBD041B6993293EE0,\n 0x3FF6000000000000, 0, 0xBFD4618BC21C6000, 0x3D13D82F484C84CC,\n 0x3FF5E00000000000, 0, 0xBFD404308686A800, 0x3CDC42F3ED820B3A,\n 0x3FF5C00000000000, 0, 0xBFD3A64C55694800, 0x3D20B1C686519460,\n 0x3FF5A00000000000, 0, 0xBFD347DD9A988000, 0x3D25594DD4C58092,\n 0x3FF5800000000000, 0, 0xBFD2E8E2BAE12000, 0x3D267B1E99B72BD8,\n 0x3FF5600000000000, 0, 0xBFD2895A13DE8800, 0x3D15CA14B6CFB03F,\n 0x3FF5600000000000, 0, 0xBFD2895A13DE8800, 0x3D15CA14B6CFB03F,\n 0x3FF5400000000000, 0, 0xBFD22941FBCF7800, 0xBD165A242853DA76,\n 0x3FF5200000000000, 0, 0xBFD1C898C1699800, 0xBD1FAFBC68E75404,\n 0x3FF5000000000000, 0, 0xBFD1675CABABA800, 0x3D1F1FC63382A8F0,\n 0x3FF4E00000000000, 0, 0xBFD1058BF9AE4800, 0xBD26A8C4FD055A66,\n 0x3FF4C00000000000, 0, 0xBFD0A324E2739000, 0xBD0C6BEE7EF4030E,\n 0x3FF4A00000000000, 0, 0xBFD0402594B4D000, 0xBCF036B89EF42D7F,\n 0x3FF4A00000000000, 0, 0xBFD0402594B4D000, 0xBCF036B89EF42D7F,\n 0x3FF4800000000000, 0, 0xBFCFB9186D5E4000, 0x3D0D572AAB993C87,\n 0x3FF4600000000000, 0, 0xBFCEF0ADCBDC6000, 0x3D2B26B79C86AF24,\n 0x3FF4400000000000, 0, 0xBFCE27076E2AF000, 0xBD172F4F543FFF10,\n 0x3FF4200000000000, 0, 0xBFCD5C216B4FC000, 0x3D21BA91BBCA681B,\n 0x3FF4000000000000, 0, 0xBFCC8FF7C79AA000, 0x3D27794F689F8434,\n 0x3FF4000000000000, 0, 0xBFCC8FF7C79AA000, 0x3D27794F689F8434,\n 0x3FF3E00000000000, 0, 0xBFCBC286742D9000, 0x3D194EB0318BB78F,\n 0x3FF3C00000000000, 0, 0xBFCAF3C94E80C000, 0x3CBA4E633FCD9066,\n 0x3FF3A00000000000, 0, 0xBFCA23BC1FE2B000, 0xBD258C64DC46C1EA,\n 0x3FF3A00000000000, 0, 0xBFCA23BC1FE2B000, 0xBD258C64DC46C1EA,\n 0x3FF3800000000000, 0, 0xBFC9525A9CF45000, 0xBD2AD1D904C1D4E3,\n 0x3FF3600000000000, 0, 0xBFC87FA06520D000, 0x3D2BBDBF7FDBFA09,\n 0x3FF3400000000000, 0, 0xBFC7AB890210E000, 0x3D2BDB9072534A58,\n 0x3FF3400000000000, 0, 0xBFC7AB890210E000, 0x3D2BDB9072534A58,\n 0x3FF3200000000000, 0, 0xBFC6D60FE719D000, 0xBD10E46AA3B2E266,\n 0x3FF3000000000000, 0, 0xBFC5FF3070A79000, 0xBD1E9E439F105039,\n 0x3FF3000000000000, 0, 0xBFC5FF3070A79000, 0xBD1E9E439F105039,\n 0x3FF2E00000000000, 0, 0xBFC526E5E3A1B000, 0xBD20DE8B90075B8F,\n 0x3FF2C00000000000, 0, 0xBFC44D2B6CCB8000, 0x3D170CC16135783C,\n 0x3FF2C00000000000, 0, 0xBFC44D2B6CCB8000, 0x3D170CC16135783C,\n 0x3FF2A00000000000, 0, 0xBFC371FC201E9000, 0x3CF178864D27543A,\n 0x3FF2800000000000, 0, 0xBFC29552F81FF000, 0xBD248D301771C408,\n 0x3FF2600000000000, 0, 0xBFC1B72AD52F6000, 0xBD2E80A41811A396,\n 0x3FF2600000000000, 0, 0xBFC1B72AD52F6000, 0xBD2E80A41811A396,\n 0x3FF2400000000000, 0, 0xBFC0D77E7CD09000, 0x3D0A699688E85BF4,\n 0x3FF2400000000000, 0, 0xBFC0D77E7CD09000, 0x3D0A699688E85BF4,\n 0x3FF2200000000000, 0, 0xBFBFEC9131DBE000, 0xBD2575545CA333F2,\n 0x3FF2000000000000, 0, 0xBFBE27076E2B0000, 0x3D2A342C2AF0003C,\n 0x3FF2000000000000, 0, 0xBFBE27076E2B0000, 0x3D2A342C2AF0003C,\n 0x3FF1E00000000000, 0, 0xBFBC5E548F5BC000, 0xBD1D0C57585FBE06,\n 0x3FF1C00000000000, 0, 0xBFBA926D3A4AE000, 0x3D253935E85BAAC8,\n 0x3FF1C00000000000, 0, 0xBFBA926D3A4AE000, 0x3D253935E85BAAC8,\n 0x3FF1A00000000000, 0, 0xBFB8C345D631A000, 0x3D137C294D2F5668,\n 0x3FF1A00000000000, 0, 0xBFB8C345D631A000, 0x3D137C294D2F5668,\n 0x3FF1800000000000, 0, 0xBFB6F0D28AE56000, 0xBD269737C93373DA,\n 0x3FF1600000000000, 0, 0xBFB51B073F062000, 0x3D1F025B61C65E57,\n 0x3FF1600000000000, 0, 0xBFB51B073F062000, 0x3D1F025B61C65E57,\n 0x3FF1400000000000, 0, 0xBFB341D7961BE000, 0x3D2C5EDACCF913DF,\n 0x3FF1400000000000, 0, 0xBFB341D7961BE000, 0x3D2C5EDACCF913DF,\n 0x3FF1200000000000, 0, 0xBFB16536EEA38000, 0x3D147C5E768FA309,\n 0x3FF1000000000000, 0, 0xBFAF0A30C0118000, 0x3D2D599E83368E91,\n 0x3FF1000000000000, 0, 0xBFAF0A30C0118000, 0x3D2D599E83368E91,\n 0x3FF0E00000000000, 0, 0xBFAB42DD71198000, 0x3D1C827AE5D6704C,\n 0x3FF0E00000000000, 0, 0xBFAB42DD71198000, 0x3D1C827AE5D6704C,\n 0x3FF0C00000000000, 0, 0xBFA77458F632C000, 0xBD2CFC4634F2A1EE,\n 0x3FF0C00000000000, 0, 0xBFA77458F632C000, 0xBD2CFC4634F2A1EE,\n 0x3FF0A00000000000, 0, 0xBFA39E87B9FEC000, 0x3CF502B7F526FEAA,\n 0x3FF0A00000000000, 0, 0xBFA39E87B9FEC000, 0x3CF502B7F526FEAA,\n 0x3FF0800000000000, 0, 0xBF9F829B0E780000, 0xBD2980267C7E09E4,\n 0x3FF0800000000000, 0, 0xBF9F829B0E780000, 0xBD2980267C7E09E4,\n 0x3FF0600000000000, 0, 0xBF97B91B07D58000, 0xBD288D5493FAA639,\n 0x3FF0400000000000, 0, 0xBF8FC0A8B0FC0000, 0xBCDF1E7CF6D3A69C,\n 0x3FF0400000000000, 0, 0xBF8FC0A8B0FC0000, 0xBCDF1E7CF6D3A69C,\n 0x3FF0200000000000, 0, 0xBF7FE02A6B100000, 0xBD19E23F0DDA40E4,\n 0x3FF0200000000000, 0, 0xBF7FE02A6B100000, 0xBD19E23F0DDA40E4,\n 0x3FF0000000000000, 0, 0, 0,\n 0x3FF0000000000000, 0, 0, 0,\n 0x3FEFC00000000000, 0, 0x3F80101575890000, 0xBD10C76B999D2BE8,\n 0x3FEF800000000000, 0, 0x3F90205658938000, 0xBD23DC5B06E2F7D2,\n 0x3FEF400000000000, 0, 0x3F98492528C90000, 0xBD2AA0BA325A0C34,\n 0x3FEF000000000000, 0, 0x3FA0415D89E74000, 0x3D0111C05CF1D753,\n 0x3FEEC00000000000, 0, 0x3FA466AED42E0000, 0xBD2C167375BDFD28,\n 0x3FEE800000000000, 0, 0x3FA894AA149FC000, 0xBD197995D05A267D,\n 0x3FEE400000000000, 0, 0x3FACCB73CDDDC000, 0xBD1A68F247D82807,\n 0x3FEE200000000000, 0, 0x3FAEEA31C006C000, 0xBD0E113E4FC93B7B,\n 0x3FEDE00000000000, 0, 0x3FB1973BD1466000, 0xBD25325D560D9E9B,\n 0x3FEDA00000000000, 0, 0x3FB3BDF5A7D1E000, 0x3D2CC85EA5DB4ED7,\n 0x3FED600000000000, 0, 0x3FB5E95A4D97A000, 0xBD2C69063C5D1D1E,\n 0x3FED400000000000, 0, 0x3FB700D30AEAC000, 0x3CEC1E8DA99DED32,\n 0x3FED000000000000, 0, 0x3FB9335E5D594000, 0x3D23115C3ABD47DA,\n 0x3FECC00000000000, 0, 0x3FBB6AC88DAD6000, 0xBD1390802BF768E5,\n 0x3FECA00000000000, 0, 0x3FBC885801BC4000, 0x3D2646D1C65AACD3,\n 0x3FEC600000000000, 0, 0x3FBEC739830A2000, 0xBD2DC068AFE645E0,\n 0x3FEC400000000000, 0, 0x3FBFE89139DBE000, 0xBD2534D64FA10AFD,\n 0x3FEC000000000000, 0, 0x3FC1178E8227E000, 0x3D21EF78CE2D07F2,\n 0x3FEBE00000000000, 0, 0x3FC1AA2B7E23F000, 0x3D2CA78E44389934,\n 0x3FEBA00000000000, 0, 0x3FC2D1610C868000, 0x3D039D6CCB81B4A1,\n 0x3FEB800000000000, 0, 0x3FC365FCB0159000, 0x3CC62FA8234B7289,\n 0x3FEB400000000000, 0, 0x3FC4913D8333B000, 0x3D25837954FDB678,\n 0x3FEB200000000000, 0, 0x3FC527E5E4A1B000, 0x3D2633E8E5697DC7,\n 0x3FEAE00000000000, 0, 0x3FC6574EBE8C1000, 0x3D19CF8B2C3C2E78,\n 0x3FEAC00000000000, 0, 0x3FC6F0128B757000, 0xBD25118DE59C21E1,\n 0x3FEAA00000000000, 0, 0x3FC7898D85445000, 0xBD1C661070914305,\n 0x3FEA600000000000, 0, 0x3FC8BEAFEB390000, 0xBD073D54AAE92CD1,\n 0x3FEA400000000000, 0, 0x3FC95A5ADCF70000, 0x3D07F22858A0FF6F,\n 0x3FEA000000000000, 0, 0x3FCA93ED3C8AE000, 0xBD28724350562169,\n 0x3FE9E00000000000, 0, 0x3FCB31D8575BD000, 0xBD0C358D4EACE1AA,\n 0x3FE9C00000000000, 0, 0x3FCBD087383BE000, 0xBD2D4BC4595412B6,\n 0x3FE9A00000000000, 0, 0x3FCC6FFBC6F01000, 0xBCF1EC72C5962BD2,\n 0x3FE9600000000000, 0, 0x3FCDB13DB0D49000, 0xBD2AFF2AF715B035,\n 0x3FE9400000000000, 0, 0x3FCE530EFFE71000, 0x3CC212276041F430,\n 0x3FE9200000000000, 0, 0x3FCEF5ADE4DD0000, 0xBCCA211565BB8E11,\n 0x3FE9000000000000, 0, 0x3FCF991C6CB3B000, 0x3D1BCBECCA0CDF30,\n 0x3FE8C00000000000, 0, 0x3FD07138604D5800, 0x3CF89CDB16ED4E91,\n 0x3FE8A00000000000, 0, 0x3FD0C42D67616000, 0x3D27188B163CEAE9,\n 0x3FE8800000000000, 0, 0x3FD1178E8227E800, 0xBD2C210E63A5F01C,\n 0x3FE8600000000000, 0, 0x3FD16B5CCBACF800, 0x3D2B9ACDF7A51681,\n 0x3FE8400000000000, 0, 0x3FD1BF99635A6800, 0x3D2CA6ED5147BDB7,\n 0x3FE8200000000000, 0, 0x3FD214456D0EB800, 0x3D0A87DEBA46BAEA,\n 0x3FE7E00000000000, 0, 0x3FD2BEF07CDC9000, 0x3D2A9CFA4A5004F4,\n 0x3FE7C00000000000, 0, 0x3FD314F1E1D36000, 0xBD28E27AD3213CB8,\n 0x3FE7A00000000000, 0, 0x3FD36B6776BE1000, 0x3D116ECDB0F177C8,\n 0x3FE7800000000000, 0, 0x3FD3C25277333000, 0x3D183B54B606BD5C,\n 0x3FE7600000000000, 0, 0x3FD419B423D5E800, 0x3D08E436EC90E09D,\n 0x3FE7400000000000, 0, 0x3FD4718DC271C800, 0xBD2F27CE0967D675,\n 0x3FE7200000000000, 0, 0x3FD4C9E09E173000, 0xBD2E20891B0AD8A4,\n 0x3FE7000000000000, 0, 0x3FD522AE0738A000, 0x3D2EBE708164C759,\n 0x3FE6E00000000000, 0, 0x3FD57BF753C8D000, 0x3D1FADEDEE5D40EF,\n 0x3FE6C00000000000, 0, 0x3FD5D5BDDF596000, 0xBD0A0B2A08A465DC\n]);\n\n// Returns 0 if not int, 1 if odd int, 2 if even int. The argument is\n// the bit representation of a non-zero finite floating-point value.\n// @ts-ignore: decorator\n@inline\nfunction checkint(iy: u64): i32 {\n let e = iy >> 52 & 0x7FF;\n if (e < 0x3FF ) return 0;\n if (e > 0x3FF + 52) return 2;\n e = u64(1) << (0x3FF + 52 - e);\n if (iy & (e - 1)) return 0;\n if (iy & e ) return 1;\n return 2;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction xflow(sign: u32, y: f64): f64 {\n return select(-y, y, sign) * y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction uflow(sign: u32): f64 {\n return xflow(sign, reinterpret(0x1000000000000000)); // 0x1p-767\n}\n\n// @ts-ignore: decorator\n@inline\nfunction oflow(sign: u32): f64 {\n return xflow(sign, reinterpret(0x7000000000000000)); // 0x1p769\n}\n\n// Returns 1 if input is the bit representation of 0, infinity or nan.\n// @ts-ignore: decorator\n@inline\nfunction zeroinfnan(u: u64): bool {\n return (u << 1) - 1 >= 0xFFE0000000000000 - 1;\n}\n\n// @ts-ignore: decorator\n@lazy let log_tail: f64 = 0;\n\n// Compute y+TAIL = log(x) where the rounded result is y and TAIL has about\n// additional 15 bits precision. IX is the bit representation of x, but\n// normalized in the subnormal range using the sign bit for the exponent.\n// @ts-ignore: decorator\n@inline\nfunction log_inline(ix: u64): f64 {\n const N = 1 << POW_LOG_TABLE_BITS;\n const N_MASK = N - 1;\n\n const\n Ln2hi = reinterpret(0x3FE62E42FEFA3800),\n Ln2lo = reinterpret(0x3D2EF35793C76730);\n\n const\n A0 = reinterpret(0xBFE0000000000000),\n A1 = reinterpret(0xBFE5555555555560),\n A2 = reinterpret(0x3FE0000000000006),\n A3 = reinterpret(0x3FE999999959554E),\n A4 = reinterpret(0xBFE555555529A47A),\n A5 = reinterpret(0xBFF2495B9B4845E9),\n A6 = reinterpret(0x3FF0002B8B263FC3);\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n let tmp = ix - 0x3fE6955500000000;\n let i = usize((tmp >> (52 - POW_LOG_TABLE_BITS)) & N_MASK);\n let k = tmp >> 52;\n let iz = ix - (tmp & u64(0xFFF) << 52);\n let z = reinterpret(iz);\n let kd = k;\n\n // log(x) = k*Ln2 + log(c) + log1p(z/c-1).\n let invc = load(POW_LOG_DATA_TAB + (i << (2 + alignof())), 0 << alignof()); // tab[i].invc\n let logc = load(POW_LOG_DATA_TAB + (i << (2 + alignof())), 2 << alignof()); // tab[i].logc\n let logctail = load(POW_LOG_DATA_TAB + (i << (2 + alignof())), 3 << alignof()); // tab[i].logctail\n\n // Note: 1/c is j/N or j/N/2 where j is an integer in [N,2N) and\n // |z/c - 1| < 1/N, so r = z/c - 1 is exactly representible.\n // Split z such that rhi, rlo and rhi*rhi are exact and |rlo| <= |r|.\n let zhi = reinterpret((iz + u64(0x80000000)) & 0xFFFFFFFF00000000);\n let zlo = z - zhi;\n let rhi = zhi * invc - 1.0;\n let rlo = zlo * invc;\n let r = rhi + rlo;\n\n // k * Ln2 + log(c) + r.\n let t1 = kd * Ln2hi + logc;\n let t2 = t1 + r;\n let lo1 = kd * Ln2lo + logctail;\n let lo2 = t1 - t2 + r;\n\n // Evaluation is optimized assuming superscalar pipelined execution.\n let ar = A0 * r; // A[0] = -0.5\n let ar2 = r * ar;\n let ar3 = r * ar2;\n // k * Ln2 + log(c) + r + A[0] * r * r.\n let arhi = A0 * rhi;\n let arhi2 = rhi * arhi;\n let hi = t2 + arhi2;\n let lo3 = rlo * (ar + arhi);\n let lo4 = t2 - hi + arhi2;\n\n // p = log1p(r) - r - A[0] * r * r.\n let p = ar3 * (A1 + r * A2 + ar2 * (A3 + r * A4 + ar2 * (A5 + r * A6)));\n let lo = lo1 + lo2 + lo3 + lo4 + p;\n let y = hi + lo;\n log_tail = hi - y + lo;\n\n return y;\n}\n\n// @ts-ignore: decorator\n@inline const SIGN_BIAS = 0x800 << EXP_TABLE_BITS;\n\n// Computes sign*exp(x+xtail) where |xtail| < 2^-8/N and |xtail| <= |x|.\n// The sign_bias argument is SIGN_BIAS or 0 and sets the sign to -1 or 1.\n// @ts-ignore: decorator\n@inline\nfunction exp_inline(x: f64, xtail: f64, sign_bias: u32): f64 {\n const N = 1 << EXP_TABLE_BITS;\n const N_MASK = N - 1;\n\n const\n InvLn2N = reinterpret(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep0\n NegLn2hiN = reinterpret(0xBF762E42FEFA0000), // -0x1.62e42fefa0000p-8\n NegLn2loN = reinterpret(0xBD0CF79ABC9E3B3A), // -0x1.cf79abc9e3b3ap-47\n shift = reinterpret(0x4338000000000000); // 0x1.8p52\n\n const\n C2 = reinterpret(0x3FDFFFFFFFFFFDBD), // __exp_data.poly[0] (0x1.ffffffffffdbdp-2)\n C3 = reinterpret(0x3FC555555555543C), // __exp_data.poly[1] (0x1.555555555543cp-3)\n C4 = reinterpret(0x3FA55555CF172B91), // __exp_data.poly[2] (0x1.55555cf172b91p-5)\n C5 = reinterpret(0x3F81111167A4D017); // __exp_data.poly[3] (0x1.1111167a4d017p-7)\n\n let abstop: u32;\n let ki: u64, top: u64, sbits: u64;\n let idx: usize;\n // double_t for better performance on targets with FLT_EVAL_METHOD==2.\n let kd: f64, z: f64, r: f64, r2: f64, scale: f64, tail: f64, tmp: f64;\n\n let ux = reinterpret(x);\n abstop = u32(ux >> 52) & 0x7FF;\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) {\n // Avoid spurious underflow for tiny x.\n // Note: 0 is common input.\n return select(-1.0, 1.0, sign_bias);\n }\n if (abstop >= 0x409) { // top12(1024.0)\n // Note: inf and nan are already handled.\n return ux < 0\n ? uflow(sign_bias)\n : oflow(sign_bias);\n }\n // Large x is special cased below.\n abstop = 0;\n }\n\n // exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)].\n // x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N].\n z = InvLn2N * x;\n\n // #if TOINT_INTRINSICS\n // kd = roundtoint(z);\n // ki = converttoint(z);\n // #elif EXP_USE_TOINT_NARROW\n // // z - kd is in [-0.5-2^-16, 0.5] in all rounding modes.\n // kd = eval_as_double(z + shift);\n // ki = asuint64(kd) >> 16;\n // kd = (double_t)(int32_t)ki;\n // #else\n // z - kd is in [-1, 1] in non-nearest rounding modes\n kd = z + shift;\n ki = reinterpret(kd);\n kd -= shift;\n // #endif\n r = x + kd * NegLn2hiN + kd * NegLn2loN;\n // The code assumes 2^-200 < |xtail| < 2^-8/N\n r += xtail;\n // 2^(k/N) ~= scale * (1 + tail)\n idx = usize((ki & N_MASK) << 1);\n top = (ki + sign_bias) << (52 - EXP_TABLE_BITS);\n\n tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof())));\n // This is only a valid scale when -1023*N < k < 1024*N\n sbits = load(EXP_DATA_TAB + (idx << alignof()), 1 << alignof()) + top;\n // exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1).\n // Evaluation is optimized assuming superscalar pipelined execution.\n r2 = r * r;\n // Without fma the worst case error is 0.25/N ulp larger.\n // Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp\n tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase(tmp, sbits, ki);\n scale = reinterpret(sbits);\n // Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there\n // is no spurious underflow here even without fma.\n return scale + scale * tmp;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function pow_lut(x: f64, y: f64): f64 {\n const Ox1p52 = reinterpret(0x4330000000000000); // 0x1p52\n\n let sign_bias: u32 = 0;\n let ix = reinterpret(x);\n let iy = reinterpret(y);\n let topx = ix >> 52;\n let topy = iy >> 52;\n\n if (topx - 0x001 >= 0x7FF - 0x001 || (topy & 0x7FF) - 0x3BE >= 0x43e - 0x3BE) {\n // Note: if |y| > 1075 * ln2 * 2^53 ~= 0x1.749p62 then pow(x,y) = inf/0\n // and if |y| < 2^-54 / 1075 ~= 0x1.e7b6p-65 then pow(x,y) = +-1.\n // Special cases: (x < 0x1p-126 or inf or nan) or\n // (|y| < 0x1p-65 or |y| >= 0x1p63 or nan).\n if (zeroinfnan(iy)) {\n if ((iy << 1) == 0) return 1.0;\n if (ix == 0x3FF0000000000000) return NaN; // original: 1.0\n if ((ix << 1) > 0xFFE0000000000000 || (iy << 1) > 0xFFE0000000000000) return x + y;\n if ((ix << 1) == 0x7FE0000000000000) return NaN; // original: 1.0\n if (((ix << 1) < 0x7FE0000000000000) == !(iy >> 63)) return 0; // |x|<1 && y==inf or |x|>1 && y==-inf.\n return y * y;\n }\n if (zeroinfnan(ix)) {\n let x2 = x * x;\n if (i32(ix >> 63) && checkint(iy) == 1) x2 = -x2;\n return iy < 0 ? 1 / x2 : x2;\n }\n // Here x and y are non-zero finite\n if (ix < 0) {\n // Finite x < 0\n let yint = checkint(iy);\n if (yint == 0) return (x - x) / (x - x);\n if (yint == 1) sign_bias = SIGN_BIAS;\n ix &= 0x7FFFFFFFFFFFFFFF;\n topx &= 0x7FF;\n }\n if ((topy & 0x7FF) - 0x3BE >= 0x43E - 0x3BE) {\n // Note: sign_bias == 0 here because y is not odd.\n if (ix == 0x3FF0000000000000) return 1;\n if ((topy & 0x7FF) < 0x3BE) return 1; // |y| < 2^-65, x^y ~= 1 + y*log(x).\n return (ix > 0x3FF0000000000000) == (topy < 0x800) ? Infinity : 0;\n }\n if (topx == 0) {\n // Normalize subnormal x so exponent becomes negative.\n ix = reinterpret(x * Ox1p52);\n ix &= 0x7FFFFFFFFFFFFFFF;\n ix -= u64(52) << 52;\n }\n }\n\n let hi = log_inline(ix);\n let lo = log_tail;\n let ehi: f64, elo: f64;\n // #if __FP_FAST_FMA\n // ehi = y * hi;\n // elo = y * lo + __builtin_fma(y, hi, -ehi);\n // #else\n let yhi = reinterpret(iy & 0xFFFFFFFFF8000000);\n let ylo = y - yhi;\n let lhi = reinterpret(reinterpret(hi) & 0xFFFFFFFFF8000000);\n let llo = hi - lhi + lo;\n ehi = yhi * lhi;\n elo = ylo * lhi + y * llo; // |elo| < |ehi| * 2^-25.\n // #endif\n return exp_inline(ehi, elo, sign_bias);\n}\n","import {\n itoa32,\n utoa32,\n itoa64,\n utoa64,\n dtoa,\n itoa_buffered,\n dtoa_buffered,\n MAX_DOUBLE_LENGTH\n} from \"./number\";\n\nimport {\n ipow32\n} from \"../math\";\n\n// All tables are stored as two staged lookup tables (static tries)\n// because the full range of Unicode symbols can't be efficiently\n// represented as-is in memory (see Unicode spec ch 5, p.196):\n// https://www.unicode.org/versions/Unicode12.0.0/ch05.pdf\n// Tables have been generated using these forked musl tools:\n// https://github.com/MaxGraey/musl-chartable-tools/tree/case-ignorable\n\n// Lookup table to check if a character is alphanumeric or not\n// See: https://git.musl-libc.org/cgit/musl/tree/src/ctype/alpha.h\n// size: 3904 bytes\n// @ts-ignore\n@inline @lazy const ALPHA_TABLE = memory.data([\n 18,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,17,34,35,36,17,37,38,39,40,\n 41,42,43,44,17,45,46,47,16,16,48,16,16,16,16,16,16,16,49,50,51,16,52,53,16,16,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,54,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,55,17,17,17,17,56,17,57,58,59,60,61,62,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,63,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,64,65,17,66,67,\n 68,69,70,71,72,73,74,17,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,\n 93,94,16,95,96,97,98,17,17,17,99,100,101,16,16,16,16,16,16,16,16,16,16,17,17,\n 17,17,102,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,103,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,17,17,104,105,16,16,106,107,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,108,17,17,17,17,109,110,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 17,111,112,16,16,16,16,16,16,16,16,16,113,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,114,115,116,117,16,16,16,16,16,16,16,16,118,\n 119,120,16,16,16,16,16,121,122,16,16,16,16,123,16,16,124,16,16,16,16,16,16,16,\n 16,16,125,16,16,16,\n 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,254,255,255,7,254,\n 255,255,7,0,0,0,0,0,4,32,4,255,255,127,255,255,255,127,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,195,255,3,0,31,80,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,223,188,64,215,255,255,\n 251,255,255,255,255,255,255,255,255,255,191,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,3,252,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,254,255,255,255,127,2,255,255,255,\n 255,255,1,0,0,0,0,255,191,182,0,255,255,255,135,7,0,0,0,255,7,255,255,255,255,\n 255,255,255,254,255,195,255,255,255,255,255,255,255,255,255,255,255,255,239,\n 31,254,225,255,\n 159,0,0,255,255,255,255,255,255,0,224,255,255,255,255,255,255,255,255,255,255,\n 255,255,3,0,255,255,255,255,255,7,48,4,255,255,255,252,255,31,0,0,255,255,255,\n 1,255,7,0,0,0,0,0,0,255,255,223,255,255,0,240,255,248,3,255,255,255,255,255,\n 255,255,255,255,239,255,223,225,255,207,255,254,255,239,159,249,255,255,253,\n 197,227,159,89,128,176,207,255,3,16,238,135,249,255,255,253,109,195,135,25,2,\n 94,192,255,63,0,238,191,251,255,255,253,237,227,191,27,1,0,207,255,0,30,238,\n 159,249,255,255,253,237,227,159,25,192,176,207,255,2,0,236,199,61,214,24,199,\n 255,195,199,29,129,0,192,255,0,0,239,223,253,255,255,253,255,227,223,29,96,7,\n 207,255,0,0,239,223,253,255,255,253,239,227,223,29,96,64,207,255,6,0,255,223,\n 253,255,255,255,255,231,223,93,240,128,207,255,0,252,238,255,127,252,255,255,\n 251,47,127,128,95,255,192,255,12,0,254,255,255,255,255,127,255,7,63,32,255,3,\n 0,0,0,0,214,247,255,255,175,255,255,59,95,32,255,243,0,0,0,\n 0,1,0,0,0,255,3,0,0,255,254,255,255,255,31,254,255,3,255,255,254,255,255,255,\n 31,0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,249,255,3,255,255,255,255,255,\n 255,255,255,255,63,255,255,255,255,191,32,255,255,255,255,255,247,255,255,255,\n 255,255,255,255,255,255,61,127,61,255,255,255,255,255,61,255,255,255,255,61,\n 127,61,255,127,255,255,255,255,255,255,255,61,255,255,255,255,255,255,255,255,\n 7,0,0,0,0,255,255,0,0,255,255,255,255,255,255,255,255,255,255,63,63,254,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,159,255,255,254,255,255,7,255,255,255,255,255,255,255,255,\n 255,199,255,1,255,223,15,0,255,255,15,0,255,255,15,0,255,223,13,0,255,255,255,\n 255,255,255,207,255,255,1,128,16,255,3,0,0,0,0,255,3,255,255,255,255,255,255,\n 255,255,255,255,255,1,255,255,255,255,255,7,255,255,255,255,255,255,255,255,\n 63,\n 0,255,255,255,127,255,15,255,1,192,255,255,255,255,63,31,0,255,255,255,255,\n 255,15,255,255,255,3,255,3,0,0,0,0,255,255,255,15,255,255,255,255,255,255,255,\n 127,254,255,31,0,255,3,255,3,128,0,0,128,1,0,0,0,0,0,0,0,255,255,255,255,255,\n 255,239,255,239,15,255,3,0,0,0,0,255,255,255,255,255,243,255,255,255,255,255,\n 255,191,255,3,0,255,255,255,255,255,255,127,0,255,227,255,255,255,255,255,63,\n 255,1,255,255,255,255,255,231,0,0,0,0,0,222,111,4,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,\n 128,255,31,0,255,255,63,63,255,255,255,255,63,63,255,170,255,255,255,63,255,\n 255,255,255,255,255,223,95,220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,2,128,0,0,255,31,0,0,0,0,0,0,0,0,0,0,0,0,132,252,47,62,80,189,255,243,\n 224,67,0,0,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,255,255,255,255,255,255,3,0,\n 0,255,255,255,255,255,127,255,255,255,255,255,127,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,31,120,12,0,255,255,255,255,191,32,255,\n 255,255,255,255,255,255,128,0,0,255,255,127,0,127,127,127,127,127,127,127,127,\n 255,255,255,255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,224,0,0,0,254,3,62,31,254,255,255,255,255,255,255,255,255,255,127,224,254,\n 255,255,255,255,255,255,255,255,255,255,247,224,255,255,255,255,255,254,255,\n 255,255,255,255,255,255,255,255,255,127,0,0,255,255,255,255,0,0,0,0,0,0,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,\n 31,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,\n 0,0,0,0,0,0,255,255,255,255,255,63,255,31,255,255,255,15,0,0,255,255,255,255,\n 255,127,240,143,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,\n 0,128,255,252,255,255,255,255,255,255,255,255,255,255,255,255,249,255,255,255,\n 255,255,255,252,7,0,0,0,0,224,255,191,255,255,255,255,0,0,0,255,255,255,255,\n 255,255,15,0,255,255,255,255,255,255,255,255,47,0,255,3,0,0,252,232,255,255,\n 255,255,255,7,255,255,255,255,7,0,255,255,255,31,255,255,255,255,255,255,247,\n 255,0,128,255,3,255,255,255,127,255,255,255,255,255,255,127,0,255,63,255,3,\n 255,255,127,252,255,255,255,255,255,255,255,127,5,0,0,56,255,255,60,0,126,126,\n 126,0,127,127,255,255,255,255,255,247,255,3,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,7,255,3,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,15,0,255,255,127,248,255,255,255,255,\n 255,\n 15,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,3,0,0,0,0,127,0,248,224,255,253,127,95,219,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,3,0,0,0,248,255,255,255,\n 255,255,255,255,255,255,255,255,255,63,0,0,255,255,255,255,255,255,255,255,\n 252,255,255,255,255,255,255,0,0,0,0,0,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,223,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,255,3,\n 254,255,255,7,254,255,255,7,192,255,255,255,255,255,255,255,255,255,255,127,\n 252,252,252,28,0,0,0,0,255,239,255,255,127,255,255,183,255,63,255,63,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,31,255,255,255,255,255,255,1,0,0,0,0,\n 0,255,255,255,255,0,224,255,255,255,7,255,255,255,255,255,7,255,255,255,63,\n 255,255,255,255,15,255,62,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,63,255,3,255,255,255,255,15,255,255,255,\n 255,15,255,255,255,255,255,0,255,255,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,0,255,255,63,0,255,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,63,253,255,255,255,255,191,145,255,255,63,0,255,255,\n 127,0,255,255,255,127,0,0,0,0,0,0,0,0,255,255,55,0,255,255,63,0,255,255,255,3,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,192,0,0,0,0,0,0,0,0,111,240,239,\n 254,255,255,63,0,0,0,0,0,255,255,255,31,255,255,255,31,0,0,0,0,255,254,255,\n 255,31,0,0,0,255,255,255,255,255,255,63,0,255,255,63,0,255,255,7,0,255,255,3,\n 0,0,0,0,0,0,0,0,0,0,0,0,\n 0,255,255,255,255,255,255,255,255,255,1,0,0,0,0,0,0,255,255,255,255,255,255,7,\n 0,255,255,255,255,255,255,7,0,255,255,255,255,255,0,255,3,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,\n 255,27,3,0,0,0,0,0,0,0,0,0,255,255,255,31,128,0,255,255,63,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,255,31,0,0,0,255,255,127,0,255,255,255,255,255,255,255,255,63,0,0,\n 0,192,255,0,0,252,255,255,255,255,255,255,1,0,0,255,255,255,1,255,3,255,255,\n 255,255,255,255,199,255,240,0,255,255,255,255,71,0,255,255,255,255,255,255,\n 255,255,30,192,255,23,0,0,0,0,255,255,251,255,255,255,159,64,0,0,0,0,0,0,0,0,\n 127,189,255,191,255,1,255,255,255,255,255,255,255,1,255,3,239,159,249,255,255,\n 253,237,227,159,25,129,224,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,255,255,255,255,255,255,255,255,187,7,255,131,3,0,0,0,255,255,255,255,255,\n 255,255,255,179,0,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,\n 255,255,255,63,127,0,0,0,63,0,0,0,0,255,255,255,255,255,255,255,127,17,0,255,\n 3,0,0,0,0,255,255,255,255,255,255,63,1,255,3,0,0,0,0,0,0,255,255,255,231,255,\n 7,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,\n 255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,3,0,128,\n 127,242,111,255,255,255,191,153,7,0,255,3,0,0,0,0,0,0,0,0,255,252,255,255,255,\n 255,255,252,26,0,0,0,255,255,255,255,255,255,231,127,0,0,255,255,255,255,255,\n 255,255,255,255,32,0,0,0,0,255,255,255,255,255,255,255,1,255,253,255,255,255,\n 255,127,127,1,0,255,3,0,0,252,255,255,255,252,255,255,254,127,0,0,0,0,0,0,0,0,\n 0,127,251,255,255,255,255,127,180,203,0,255,3,191,253,255,255,255,127,123,1,\n 255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,\n 0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,3,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,127,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,255,255,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,\n 0,255,255,255,255,255,255,255,1,255,255,255,127,255,3,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,63,0,0,255,255,255,255,255,255,0,0,15,0,255,3,248,255,255,224,255,\n 255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,\n 255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,135,\n 255,255,255,255,255,255,255,128,255,255,0,0,0,0,0,0,0,0,11,0,3,0,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,0,0,0,0,0,\n 255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,\n 127,0,0,0,0,0,0,7,0,240,0,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,15,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,7,255,31,255,1,255,67,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,223,255,255,255,255,255,255,255,255,\n 223,100,222,255,235,239,255,255,255,255,255,255,255,191,231,223,223,255,255,\n 255,123,95,252,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,63,255,255,255,253,255,255,247,255,255,255,\n 247,255,255,223,255,255,255,223,255,255,127,255,255,255,127,255,255,255,253,\n 255,255,255,253,255,255,247,207,255,255,255,255,255,255,127,255,255,249,219,7,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,31,\n 128,63,255,67,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,15,255,\n 3,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,31,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,143,8,\n 255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,239,255,255,255,150,254,247,10,\n 132,234,150,170,150,247,247,94,255,251,255,15,238,251,255,15,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,255,255,255,3,255,255,255,3,255,255,255,3,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,3\n]);\n\n// size: 1568 bytes (compressed to ~1380 bytes after binaryen)\n// @ts-ignore: decorator\n@lazy @inline const CASED = memory.data([\n 18,19,20,21,22,23,16,16,16,16,16,16,16,16,16,16,\n 24,16,16,25,16,16,16,16,16,16,16,16,26,27,17,28,\n 29,30,16,16,31,16,16,16,16,16,16,16,32,33,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,34,35,16,16,16,36,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,37,16,16,16,38,\n 16,16,16,16,39,16,16,16,16,16,16,16,40,16,16,16,\n 16,16,16,16,16,16,16,16,41,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,42,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,43,44,45,46,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,47,16,16,16,16,16,16,\n 16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,254,255,255,7,254,255,255,7,0,0,0,0,0,4,32,4,\n 255,255,127,255,255,255,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,247,240,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,239,255,255,255,255,1,3,0,0,0,31,0,0,0,\n 0,0,0,0,0,0,0,0,32,0,0,0,0,0,207,188,64,215,255,255,251,255,255,255,\n 255,255,255,255,255,255,191,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 3,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,255,\n 255,255,127,0,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,\n 191,32,255,255,255,255,255,231,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,255,255,255,255,255,255,255,255,255,63,63,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,1,255,255,255,255,255,231,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,255,255,63,63,255,255,255,255,63,63,255,170,255,255,255,63,\n 255,255,255,255,255,255,223,95,220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,2,128,0,0,255,31,0,0,0,0,0,0,0,0,0,0,0,0,\n 132,252,47,62,80,189,31,242,224,67,0,0,255,255,255,255,24,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,192,255,255,255,255,255,255,3,0,0,255,255,255,255,255,127,255,255,\n 255,255,255,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,120,12,0,\n 255,255,255,255,191,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,63,0,0,\n 255,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,255,255,255,\n 255,255,255,255,255,255,255,255,255,120,255,255,255,255,255,255,252,7,0,0,0,0,96,7,\n 0,0,0,0,0,0,255,255,255,255,255,247,255,1,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,127,0,248,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254,255,255,7,\n 254,255,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,255,255,\n 255,255,15,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,7,0,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,223,255,255,255,255,255,\n 255,255,255,223,100,222,255,235,239,255,255,255,255,255,255,255,191,231,223,223,255,255,255,123,\n 95,252,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,\n 253,255,255,247,255,255,255,247,255,255,223,255,255,255,223,255,255,127,255,255,255,127,255,255,\n 255,253,255,255,255,253,255,255,247,15,0,0,0,0,0,0,255,255,255,255,255,255,255,255,\n 15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,255,255,255,3,255,255,255,3,255,255,255,3,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0\n]);\n\n// size: 2976 bytes (compressed to ~2050 bytes after binaryen)\n// @ts-ignore: decorator\n@lazy @inline const CASE_IGNORABLES = memory.data([\n 18,16,19,20,21,22,23,24,25,26,27,28,29,30,31,32,\n 33,16,16,34,16,16,16,35,36,37,38,39,40,41,16,42,\n 43,16,16,16,16,16,16,16,16,16,16,16,44,45,46,16,\n 47,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 48,16,16,16,49,16,50,51,52,53,54,55,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,56,16,16,57,58,\n 16,59,60,61,16,16,16,16,16,16,62,16,16,63,64,65,\n 66,67,68,69,70,71,72,73,74,75,76,16,77,78,79,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,80,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,81,82,16,16,16,83,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,84,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,85,86,16,16,16,16,16,16,16,87,16,16,16,16,16,\n 88,89,90,16,16,16,16,16,91,92,16,16,16,16,16,16,\n 16,16,16,93,16,16,16,16,16,16,16,16,16,16,16,16,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,128,64,0,4,0,0,0,64,1,0,0,0,0,0,0,0,0,161,144,1,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,48,4,176,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,3,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,130,0,0,0,0,\n 0,0,254,255,255,255,255,191,182,0,0,0,0,0,16,0,63,0,255,23,0,0,0,0,\n 1,248,255,255,0,0,1,0,0,0,0,0,0,0,0,0,0,0,192,191,255,61,0,0,\n 0,128,2,0,0,0,255,255,255,7,0,0,0,0,0,0,0,0,0,0,192,255,1,0,\n 0,0,0,0,0,248,63,36,0,0,192,255,255,63,0,0,0,0,0,14,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,248,255,255,255,255,255,7,0,0,0,0,0,0,20,\n 254,33,254,0,12,0,2,0,2,0,0,0,0,0,0,16,30,32,0,0,12,0,0,64,\n 6,0,0,0,0,0,0,16,134,57,2,0,0,0,35,0,6,0,0,0,0,0,0,16,\n 190,33,0,0,12,0,0,252,2,0,0,0,0,0,0,144,30,32,96,0,12,0,0,0,\n 4,0,0,0,0,0,0,0,1,32,0,0,0,0,0,0,17,0,0,0,0,0,0,192,\n 193,61,96,0,12,0,0,0,2,0,0,0,0,0,0,144,64,48,0,0,12,0,0,0,\n 3,0,0,0,0,0,0,24,30,32,0,0,12,0,0,0,2,0,0,0,0,0,0,0,\n 0,4,92,0,0,0,0,0,0,0,0,0,0,0,242,7,192,127,0,0,0,0,0,0,\n 0,0,0,0,0,0,242,31,64,63,0,0,0,0,0,0,0,0,0,3,0,0,160,2,\n 0,0,0,0,0,0,254,127,223,224,255,254,255,255,255,31,64,0,0,0,0,0,0,0,\n 0,0,0,0,0,224,253,102,0,0,0,195,1,0,30,0,100,32,0,32,0,0,0,0,\n 0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0,0,0,28,0,\n 0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,143,32,0,0,0,0,\n 0,120,0,0,0,0,0,0,8,0,0,0,0,0,0,0,96,0,0,0,0,2,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,135,1,4,14,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,9,0,0,0,0,\n 0,0,64,127,229,31,248,159,0,0,0,0,128,0,255,255,1,0,0,0,0,0,0,0,\n 15,0,0,0,0,0,208,23,4,0,0,0,0,248,15,0,3,0,0,0,60,59,0,0,\n 0,0,0,0,64,163,3,0,0,0,0,0,0,240,207,0,0,0,0,0,0,0,0,63,\n 0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,3,0,0,0,0,0,240,255,255,\n 255,255,255,255,255,7,0,1,0,0,0,248,255,255,255,255,255,255,255,255,255,255,255,251,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,160,\n 3,224,0,224,0,224,0,96,0,248,0,3,144,124,0,0,0,0,0,0,223,255,2,128,\n 0,0,255,31,0,0,0,0,0,0,255,255,255,255,1,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,48,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,128,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,255,255,255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,60,62,8,\n 0,0,0,0,0,0,0,0,0,0,0,126,0,0,0,0,0,0,0,0,0,0,0,112,\n 0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,63,0,16,0,0,0,0,0,0,\n 0,0,0,0,0,128,247,191,0,0,0,240,0,0,0,0,0,0,0,0,0,0,3,0,\n 255,255,255,255,3,0,0,0,0,0,0,0,0,0,1,0,0,7,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,3,68,8,0,0,96,16,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,48,0,0,0,255,255,3,128,0,0,0,0,192,63,0,0,\n 128,255,3,0,0,0,0,0,7,0,0,0,0,0,200,51,0,128,0,0,96,0,0,0,\n 0,0,0,0,0,126,102,0,8,16,0,0,0,0,1,16,0,0,0,0,0,0,157,193,\n 2,0,0,32,0,48,88,0,0,0,0,0,0,0,0,0,0,0,0,248,0,14,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,32,33,0,0,0,0,0,64,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,255,3,0,0,0,0,0,0,0,\n 255,255,8,0,255,255,0,0,0,0,36,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,128,128,64,0,4,0,0,0,64,1,0,0,0,0,0,1,0,\n 0,0,0,192,0,0,0,0,0,0,0,0,8,0,0,14,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,7,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,110,240,0,0,0,0,0,135,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,\n 0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 192,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 2,0,0,0,0,0,0,255,127,0,0,0,0,0,0,128,3,0,0,0,0,0,120,38,\n 0,32,0,0,0,0,0,0,7,0,0,0,128,239,31,0,0,0,0,0,0,0,8,0,\n 3,0,0,0,0,0,192,127,0,158,0,0,0,0,0,0,0,0,0,0,0,128,211,64,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,248,7,0,0,\n 3,0,0,0,0,0,0,24,1,0,0,0,192,31,31,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,92,0,0,64,0,0,0,0,\n 0,0,0,0,0,0,248,133,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,60,176,1,0,0,48,0,0,0,0,\n 0,0,0,0,0,0,248,167,1,0,0,0,0,0,0,0,0,0,0,0,0,40,191,0,\n 0,0,0,0,0,0,0,0,0,0,0,224,188,15,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,255,6,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,88,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,240,12,1,0,0,0,254,7,0,0,0,0,248,121,128,0,126,14,0,0,0,0,\n 0,252,127,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,191,\n 0,0,0,0,0,0,0,0,0,0,252,255,255,252,109,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,126,180,191,0,0,0,0,0,0,0,0,0,163,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,0,0,0,0,0,0,255,1,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,31,0,0,0,0,0,0,0,127,0,15,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,128,0,0,0,0,0,0,0,128,255,255,0,0,0,0,0,0,0,0,27,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,15,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,248,255,\n 231,15,0,0,0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,127,248,255,255,255,255,255,31,32,0,16,0,0,248,254,255,0,0,\n 0,0,0,0,0,0,0,0,127,255,255,249,219,7,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,63,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 240,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,248\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const LOWER127 = memory.data([\n 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,\n 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,\n 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,\n 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,\n 64,\n 97,98,99,100,101,102,103,104,105,106,107,108,109,\n 110,111,112,113,114,115,116,117,118,119,120,121,122,\n 91,92,93,94,95,96,\n 97,98,99,100,101,102,103,104,105,106,107,108,109,\n 110,111,112,113,114,115,116,117,118,119,120,121,122,\n 123,124,125,126,127\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const UPPER127 = memory.data([\n 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,\n 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,\n 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,\n 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,\n 64,\n 65,66,67,68,69,70,71,72,73,74,75,76,77,\n 78,79,80,81,82,83,84,85,86,87,88,89,90,\n 91,92,93,94,95,96,\n 65,66,67,68,69,70,71,72,73,74,75,76,77,\n 78,79,80,81,82,83,84,85,86,87,88,89,90,\n 123,124,125,126,127\n]);\n\n// 23 * 8 = 184 bytes\n// @ts-ignore: decorator\n@lazy @inline const POWERS10 = memory.data([\n 1e00, 1e01, 1e02, 1e03, 1e04, 1e05, 1e06, 1e07, 1e08, 1e09,\n 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,\n 1e20, 1e21, 1e22\n]);\n\n// @ts-ignore: decorator\n@inline\nexport const enum CharCode {\n PERCENT = 0x25,\n PLUS = 0x2B,\n MINUS = 0x2D,\n DOT = 0x2E,\n _0 = 0x30,\n _1 = 0x31,\n _2 = 0x32,\n _3 = 0x33,\n _4 = 0x34,\n _5 = 0x35,\n _6 = 0x36,\n _7 = 0x37,\n _8 = 0x38,\n _9 = 0x39,\n A = 0x41,\n B = 0x42,\n E = 0x45,\n I = 0x49,\n N = 0x4E,\n O = 0x4F,\n X = 0x58,\n Z = 0x5A,\n a = 0x61,\n b = 0x62,\n e = 0x65,\n n = 0x6E,\n o = 0x6F,\n u = 0x75,\n x = 0x78,\n z = 0x7A\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isAscii(c: u32): bool {\n return !(c >> 7);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isLower8(c: u32): bool {\n return c - CharCode.a < 26;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isUpper8(c: u32): bool {\n return c - CharCode.A < 26;\n}\n\nexport function isSpace(c: u32): bool {\n if (c < 0x1680) { // < (1)\n // , , , , , and \n // (c == 0x20 || c == 0xA0) was optimized to (c | 0x80) == 0xA0\n return ((c | 0x80) == 0xA0) || (c - 0x09 <= 0x0D - 0x09);\n }\n if (c - 0x2000 <= 0x200A - 0x2000) return true;\n switch (c) {\n case 0x1680: // (1)\n case 0x2028: // (2)\n case 0x2029: // \n case 0x202F: // \n case 0x205F: // \n case 0x3000: // \n case 0xFEFF: return true; // \n }\n return false;\n}\n\nexport function isAlpha(c: u32): bool {\n if (isAscii(c)) return (c | 32) - CharCode.a < 26;\n if (c < 0x20000) {\n // @ts-ignore: cast\n return stagedBinaryLookup(ALPHA_TABLE, c);\n }\n return c < 0x2FFFE;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isCased(c: u32): bool {\n // @ts-ignore: cast\n return c < 0x1F18A && stagedBinaryLookup(CASED, c);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isCaseIgnorable(c: u32): bool {\n // @ts-ignore: cast\n return c < 0xE01F0 && stagedBinaryLookup(CASE_IGNORABLES, c);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isFinalSigma(buffer: usize, index: isize, len: isize): bool {\n const lookaheadLimit = 30; // max lookahead limit\n let found = false;\n let pos = index;\n let minPos = max(0, pos - lookaheadLimit);\n while (pos > minPos) {\n let c = codePointBefore(buffer, pos);\n if (!isCaseIgnorable(c)) {\n if (isCased(c)) {\n found = true;\n } else {\n return false;\n }\n }\n pos -= isize(c >= 0x10000) + 1;\n }\n if (!found) return false;\n pos = index + 1;\n let maxPos = min(pos + lookaheadLimit, len);\n while (pos < maxPos) {\n let c = load(buffer + (pos << 1));\n if (u32((c & 0xFC00) == 0xD800) & u32(pos + 1 != len)) {\n let c1 = load(buffer + (pos << 1), 2);\n if ((c1 & 0xFC00) == 0xDC00) {\n c = (c - 0xD800 << 10) + (c1 - 0xDC00) + 0x10000;\n }\n }\n if (!isCaseIgnorable(c)) {\n return !isCased(c);\n }\n pos += isize(c >= 0x10000) + 1;\n }\n return true;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction codePointBefore(buffer: usize, index: isize): i32 {\n if (index <= 0) return -1;\n let c = load(buffer + (index - 1 << 1));\n if (u32((c & 0xFC00) == 0xDC00) & u32(index - 2 >= 0)) {\n let c1 = load(buffer + (index - 2 << 1));\n if ((c1 & 0xFC00) == 0xD800) {\n return ((c1 & 0x3FF) << 10) + (c & 0x3FF) + 0x10000;\n }\n }\n return (c & 0xF800) == 0xD800 ? 0xFFFD : c;\n}\n\n// Search routine for two-staged lookup tables\nfunction stagedBinaryLookup(table: usize, c: u32): bool {\n return ((load(table + (load(table + (c >>> 8)) << 5) + ((c & 255) >> 3)) >>> (c & 7)) & 1);\n}\n\nexport function compareImpl(str1: string, index1: usize, str2: string, index2: usize, len: usize): i32 {\n let ptr1 = changetype(str1) + (index1 << 1);\n let ptr2 = changetype(str2) + (index2 << 1);\n if (ASC_SHRINK_LEVEL < 2) {\n if (len >= 4 && !((ptr1 & 7) | (ptr2 & 7))) {\n do {\n if (load(ptr1) != load(ptr2)) break;\n ptr1 += 8;\n ptr2 += 8;\n len -= 4;\n } while (len >= 4);\n }\n }\n while (len--) {\n let a = load(ptr1);\n let b = load(ptr2);\n if (a != b) return a - b;\n ptr1 += 2;\n ptr2 += 2;\n }\n return 0;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function toLower8(c: u32): u32 {\n if (ASC_SHRINK_LEVEL > 0) {\n return c | u32(isUpper8(c)) << 5;\n } else {\n return load(LOWER127 + c);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function toUpper8(c: u32): u32 {\n if (ASC_SHRINK_LEVEL > 0) {\n return c & ~(u32(isLower8(c)) << 5);\n } else {\n return load(UPPER127 + c);\n }\n}\n\n/** Parses a string to an integer (usually), using the specified radix. */\nexport function strtol(str: string, radix: i32 = 0): T {\n let len = str.length;\n if (!len) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n\n let ptr = changetype(str) /* + HEAD -> offset */;\n let code = load(ptr);\n\n // trim white spaces\n while (isSpace(code)) {\n code = load(ptr += 2);\n --len;\n }\n // determine sign\n // @ts-ignore\n let sign: T = 1;\n if (code == CharCode.MINUS || code == CharCode.PLUS) {\n if (!--len) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n if (code == CharCode.MINUS) {\n // @ts-ignore: type\n sign = -1;\n }\n code = load(ptr += 2);\n }\n\n // See https://tc39.es/ecma262/#sec-parseint-string-radix\n if (radix) {\n if (radix < 2 || radix > 36) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n // handle case as parseInt(\"0xFF\", 16) by spec\n if (radix == 16) {\n if (\n len > 2 &&\n code == CharCode._0 &&\n (load(ptr, 2) | 32) == CharCode.x\n ) {\n ptr += 4; len -= 2;\n }\n }\n } else {\n // determine radix by literal prefix\n if (code == CharCode._0 && len > 2) {\n switch (load(ptr, 2) | 32) {\n case CharCode.b: {\n ptr += 4; len -= 2;\n radix = 2;\n break;\n }\n case CharCode.o: {\n ptr += 4; len -= 2;\n radix = 8;\n break;\n }\n case CharCode.x: {\n ptr += 4; len -= 2;\n radix = 16;\n break;\n }\n }\n }\n if (!radix) radix = 10;\n }\n\n // calculate value\n // @ts-ignore: type\n let num: T = 0;\n let initial = len - 1;\n while (len--) {\n code = load(ptr);\n if (code - CharCode._0 < 10) {\n code -= CharCode._0;\n } else if (code - CharCode.A <= (CharCode.Z - CharCode.A)) {\n code -= CharCode.A - 10;\n } else if (code - CharCode.a <= (CharCode.z - CharCode.a)) {\n code -= CharCode.a - 10;\n }\n if (code >= radix) {\n if (initial == len) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n break;\n }\n // @ts-ignore: type\n num = num * radix + code;\n ptr += 2;\n }\n // @ts-ignore: type\n return sign * num;\n}\n\nexport function strtod(str: string): f64 {\n let len = str.length;\n if (!len) return NaN;\n\n let ptr = changetype(str);\n let code = load(ptr);\n\n let sign = 1.0;\n // skip white spaces\n while (len && isSpace(code)) {\n code = load(ptr += 2);\n --len;\n }\n if (!len) return NaN;\n\n // try parse '-' or '+'\n if (code == CharCode.MINUS) {\n if (!--len) return NaN;\n code = load(ptr += 2);\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) return NaN;\n code = load(ptr += 2);\n }\n\n // try parse Infinity\n if (len >= 8 && code == CharCode.I) {\n if (\n load(ptr, 0) == 0x690066006E0049 && // ifnI\n load(ptr, 8) == 0x7900740069006E // ytin\n ) {\n return Infinity * sign;\n }\n return NaN;\n }\n // validate next symbol\n if (code != CharCode.DOT && (code - CharCode._0) >= 10) {\n return NaN;\n }\n let savedPtr = ptr;\n // skip zeros\n while (code == CharCode._0) {\n code = load(ptr += 2);\n --len;\n }\n if (len <= 0) return 0.0 * sign;\n const capacity = 19; // int(64 * 0.3010)\n let pointed = false;\n let consumed = 0;\n let position = 0;\n let x: u64 = 0;\n if (code == CharCode.DOT) {\n let noDigits = !(savedPtr - ptr);\n ptr += 2; --len;\n if (!len && noDigits) return NaN;\n for (pointed = true; (code = load(ptr)) == CharCode._0; --position, ptr += 2) --len;\n if (len <= 0) return 0.0 * sign;\n if (!position && noDigits && code - CharCode._0 >= 10) return NaN;\n }\n for (let digit = code - CharCode._0; digit < 10 || (code == CharCode.DOT && !pointed); digit = code - CharCode._0) {\n if (digit < 10) {\n x = consumed < capacity ? 10 * x + digit : x | u64(!!digit);\n ++consumed;\n } else {\n position = consumed;\n pointed = true;\n }\n if (!--len) break;\n code = load(ptr += 2);\n }\n\n if (!pointed) position = consumed;\n return copysign(scientific(x, position - min(capacity, consumed) + parseExp(ptr, len)), sign);\n}\n\nexport function strtob(str: string): bool {\n let size: usize = str.length << 1;\n let offset: usize = 0;\n if (size > 8) {\n // try trim end whitespaces first\n while (size && isSpace(load(changetype(str) + size - 2))) size -= 2;\n if (size > 8) {\n // trim start whitespaces\n while (offset < size && isSpace(load(changetype(str) + offset))) offset += 2;\n size -= offset;\n }\n }\n if (size != 8) return false;\n // \"true\" represents as \\00\\e\\00\\u\\00\\e\\00\\t (00 65 00 75 00 72 00 74)\n return load(changetype(str) + offset) == 0x0065_0075_0072_0074;\n}\n\nexport function joinBooleanArray(dataStart: usize, length: i32, separator: string): string {\n let lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) return select(\"true\", \"false\", load(dataStart));\n\n let sepLen = separator.length;\n let valueLen = 5; // max possible length of element len(\"false\")\n let estLen = (valueLen + sepLen) * lastIndex + valueLen;\n let result = changetype(__new(estLen << 1, idof()));\n let offset = 0;\n let value: bool;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + i);\n valueLen = 4 + i32(!value);\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(select(\"true\", \"false\", value)),\n valueLen << 1\n );\n offset += valueLen;\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + lastIndex);\n valueLen = 4 + i32(!value);\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(select(\"true\", \"false\", value)),\n valueLen << 1\n );\n offset += valueLen;\n\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinIntegerArray(dataStart: usize, length: i32, separator: string): string {\n let lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) {\n let value = load(dataStart);\n if (isSigned()) {\n if (sizeof() <= 4) {\n // @ts-ignore: type\n return changetype(itoa32(value, 10));\n } else {\n // @ts-ignore: type\n return changetype(itoa64(value, 10));\n }\n } else {\n if (sizeof() <= 4) {\n // @ts-ignore: type\n return changetype(utoa32(value, 10));\n } else {\n // @ts-ignore: type\n return changetype(utoa64(value, 10));\n }\n }\n }\n\n let sepLen = separator.length;\n const valueLen = (sizeof() <= 4 ? 10 : 20) + i32(isSigned());\n let estLen = (valueLen + sepLen) * lastIndex + valueLen;\n let result = changetype(__new(estLen << 1, idof()));\n let offset = 0;\n let value: T;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n // @ts-ignore: type\n offset += itoa_buffered(changetype(result) + (offset << 1), value);\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + (lastIndex << alignof()));\n // @ts-ignore: type\n offset += itoa_buffered(changetype(result) + (offset << 1), value);\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinFloatArray(dataStart: usize, length: i32, separator: string): string {\n let lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) {\n return changetype(dtoa(\n // @ts-ignore: type\n load(dataStart))\n );\n }\n\n const valueLen = MAX_DOUBLE_LENGTH;\n let sepLen = separator.length;\n let estLen = (valueLen + sepLen) * lastIndex + valueLen;\n let result = changetype(__new(estLen << 1, idof()));\n let offset = 0;\n let value: T;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n // @ts-ignore: type\n offset += dtoa_buffered(changetype(result) + (offset << 1), value);\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + (lastIndex << alignof()));\n // @ts-ignore: type\n offset += dtoa_buffered(changetype(result) + (offset << 1), value);\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinStringArray(dataStart: usize, length: i32, separator: string): string {\n let lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) {\n // @ts-ignore: type\n return load(dataStart) || \"\";\n }\n let estLen = 0;\n let value: string;\n for (let i = 0; i < length; ++i) {\n value = load(dataStart + (i << alignof()));\n if (changetype(value) != 0) estLen += value.length;\n }\n let offset = 0;\n let sepLen = separator.length;\n let result = changetype(__new((estLen + sepLen * lastIndex) << 1, idof()));\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n if (changetype(value) != 0) {\n let valueLen = value.length;\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(value),\n valueLen << 1\n );\n offset += valueLen;\n }\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + (lastIndex << alignof()));\n if (changetype(value) != 0) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(value),\n value.length << 1\n );\n }\n return result;\n}\n\nexport function joinReferenceArray(dataStart: usize, length: i32, separator: string): string {\n let lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n let value: T;\n if (!lastIndex) {\n value = load(dataStart);\n // @ts-ignore: type\n return value != null ? value.toString() : \"\";\n }\n let result = \"\";\n let sepLen = separator.length;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n // @ts-ignore: type\n if (value != null) result += value.toString();\n if (sepLen) result += separator;\n }\n value = load(dataStart + (lastIndex << alignof()));\n // @ts-ignore: type\n if (value != null) result += value.toString();\n return result;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction scientific(significand: u64, exp: i32): f64 {\n if (!significand || exp < -342) return 0;\n if (exp > 308) return Infinity;\n // Try use fast path\n // Use fast path for string-to-double conversion if possible\n // see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion\n // Simple integer\n let significandf = significand;\n if (!exp) return significandf;\n if (exp > 22 && exp <= 22 + 15) {\n significandf *= pow10(exp - 22);\n exp = 22;\n }\n if (significand <= 9007199254740991 && abs(exp) <= 22) {\n if (exp > 0) return significandf * pow10(exp);\n return significandf / pow10(-exp);\n } else if (exp < 0) {\n return scaledown(significand, exp);\n } else {\n return scaleup(significand, exp);\n }\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction scaledown(significand: u64, exp: i32): f64 {\n const denom: u64 = 6103515625; // 1e14 * 0x1p-14\n const scale = reinterpret(0x3F06849B86A12B9B); // 1e-14 * 0x1p32\n\n let shift = clz(significand);\n significand <<= shift;\n shift = exp - shift;\n\n for (; exp <= -14; exp += 14) {\n let q = significand / denom;\n let r = significand % denom;\n let s = clz(q);\n significand = (q << s) + nearest(scale * (r << (s - 18)));\n shift -= s;\n }\n let b = ipow32(5, -exp);\n let q = significand / b;\n let r = significand % b;\n let s = clz(q);\n significand = (q << s) + (reinterpret(reinterpret(r) + (s << 52)) / b);\n shift -= s;\n\n return NativeMath.scalbn(significand, shift);\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction scaleup(significand: u64, exp: i32): f64 {\n const coeff: u32 = 1220703125; // 1e13 * 0x1p-13;\n let shift = ctz(significand);\n significand >>= shift;\n shift += exp;\n\n __fixmulShift = shift;\n for (; exp >= 13; exp -= 13) {\n significand = fixmul(significand, coeff);\n }\n significand = fixmul(significand, ipow32(5, exp));\n shift = __fixmulShift;\n return NativeMath.scalbn(significand, shift);\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction parseExp(ptr: usize, len: i32): i32 {\n let sign = 1, magnitude = 0;\n let code = load(ptr);\n // check code is 'e' or 'E'\n if ((code | 32) != CharCode.e) return 0;\n\n if (!--len) return 0;\n code = load(ptr += 2);\n if (code == CharCode.MINUS) {\n if (!--len) return 0;\n code = load(ptr += 2);\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) return 0;\n code = load(ptr += 2);\n }\n // skip zeros\n while (code == CharCode._0) {\n if (!--len) return 0;\n code = load(ptr += 2);\n }\n for (let digit: u32 = code - CharCode._0; len && digit < 10; digit = code - CharCode._0) {\n if (magnitude >= 3200) return sign * 3200;\n magnitude = 10 * magnitude + digit;\n code = load(ptr += 2);\n --len;\n }\n return sign * magnitude;\n}\n\n// @ts-ignore: decorator\n@lazy let __fixmulShift: u64 = 0;\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction fixmul(a: u64, b: u32): u64 {\n let low = (a & 0xFFFFFFFF) * b;\n let high = (a >> 32) * b + (low >> 32);\n let overflow = (high >> 32);\n let space = clz(overflow);\n let revspace: u64 = 32 - space;\n __fixmulShift += revspace;\n return (high << space | (low & 0xFFFFFFFF) >> revspace) + (low << space >> 31 & 1);\n}\n\n// @ts-ignore: decorator\n@inline\nfunction pow10(n: i32): f64 {\n // argument `n` should bounds in [0, 22] range\n return load(POWERS10 + (n << alignof()));\n}\n","// This file is shared with the compiler and must remain portable\n\n/** Runtime types. */\nexport enum Runtime {\n /** Simple bump allocator without GC. */\n Stub = 0,\n /** Stop the world semi-automatic GC. */\n Minimal = 1,\n /** incremental GC. */\n Incremental = 2,\n}\n","import { compareImpl } from \"./string\";\n\ntype Comparator = (a: T, b: T) => i32;\n\n// @ts-ignore: decorator\n@lazy @inline const EMPTY = u32.MAX_VALUE;\n// @ts-ignore: decorator\n@inline const INSERTION_SORT_THRESHOLD = 48;\n// @ts-ignore: decorator\n@inline const MIN_RUN_LENGTH = 32;\n\n// @ts-ignore: decorator\n@inline\nfunction log2u(n: u32): u32 {\n return 31 - clz(n);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function COMPARATOR(): Comparator {\n if (isInteger()) {\n if (isSigned() && sizeof() <= 4) {\n return (a, b) => i32(a) - i32(b);\n } else {\n return (a, b) => i32(a > b) - i32(a < b);\n }\n } else if (isFloat()) {\n if (sizeof() == 4) {\n return (a, b) => {\n let ia = reinterpret(f32(a));\n let ib = reinterpret(f32(b));\n ia ^= ia >> 31 >>> 1;\n ib ^= ib >> 31 >>> 1;\n return i32(ia > ib) - i32(ia < ib);\n };\n } else {\n return (a, b) => {\n let ia = reinterpret(f64(a));\n let ib = reinterpret(f64(b));\n ia ^= ia >> 63 >>> 1;\n ib ^= ib >> 63 >>> 1;\n return i32(ia > ib) - i32(ia < ib);\n };\n }\n } else if (isString()) {\n return (a, b) => {\n if (\n changetype(a) == changetype(b) ||\n changetype(a) == 0 ||\n changetype(b) == 0\n ) return 0;\n let alen = changetype(a).length;\n let blen = changetype(b).length;\n if (!(alen | blen)) return 0;\n if (!alen) return -1;\n if (!blen) return 1;\n let res = compareImpl(\n changetype(a), 0,\n changetype(b), 0,\n min(alen, blen)\n );\n return res ? res : alen - blen;\n };\n } else {\n return (a, b) => i32(a > b) - i32(a < b);\n }\n}\n\n// Power Sort implementation (stable) from paper \"Nearly-Optimal Mergesorts\"\n// https://arxiv.org/pdf/1805.04154.pdf\n// This method usually outperform TimSort.\n// TODO: refactor c >>> 31 to c < 0 when binaryen will support this opt\nexport function SORT(\n ptr: usize,\n len: i32,\n comparator: Comparator\n): void {\n if (len <= INSERTION_SORT_THRESHOLD) {\n if (len <= 1) return;\n if (ASC_SHRINK_LEVEL < 1) {\n switch (len) {\n case 3: {\n let a = load(ptr, 0);\n let b = load(ptr, 1 << alignof());\n let c = comparator(a, b) > 0;\n store(ptr, select(b, a, c), 0);\n a = select(a, b, c);\n b = load(ptr, 2 << alignof());\n c = comparator(a, b) > 0;\n store(ptr, select(b, a, c), 1 << alignof());\n store(ptr, select(a, b, c), 2 << alignof());\n }\n case 2: {\n let a = load(ptr, 0);\n let b = load(ptr, 1 << alignof());\n let c = comparator(a, b) > 0;\n store(ptr, select(b, a, c), 0);\n store(ptr, select(a, b, c), 1 << alignof());\n return;\n }\n }\n }\n insertionSort(ptr, 0, len - 1, 0, comparator);\n return;\n }\n\n let lgPlus2 = log2u(len) + 2;\n let lgPlus2Size = lgPlus2 << alignof();\n let leftRunStartBuf = __alloc(lgPlus2Size << 1);\n let leftRunEndBuf = leftRunStartBuf + lgPlus2Size;\n\n for (let i: u32 = 0; i < lgPlus2; ++i) {\n store(leftRunStartBuf + (i << alignof()), EMPTY);\n }\n\n let buffer = __alloc(len << alignof());\n\n let hi = len - 1;\n let endA = extendRunRight(ptr, 0, hi, comparator);\n let lenA = endA + 1;\n\n if (lenA < MIN_RUN_LENGTH) {\n endA = min(hi, MIN_RUN_LENGTH - 1);\n insertionSort(ptr, 0, endA, lenA, comparator);\n }\n\n let top: u32 = 0, startA = 0;\n while (endA < hi) {\n let startB = endA + 1;\n let endB = extendRunRight(ptr, startB, hi, comparator);\n let lenB = endB - startB + 1;\n\n if (lenB < MIN_RUN_LENGTH) {\n endB = min(hi, startB + MIN_RUN_LENGTH - 1);\n insertionSort(ptr, startB, endB, lenB, comparator);\n }\n\n let k = nodePower(0, hi, startA, startB, endB);\n\n for (let i = top; i > k; --i) {\n let start = load(leftRunStartBuf + (i << alignof()));\n if (start != EMPTY) {\n mergeRuns(\n ptr,\n start,\n load(leftRunEndBuf + (i << alignof())) + 1,\n endA,\n buffer,\n comparator\n );\n startA = start;\n store(leftRunStartBuf + (i << alignof()), EMPTY);\n }\n }\n\n store(leftRunStartBuf + (k << alignof()), startA);\n store(leftRunEndBuf + (k << alignof()), endA);\n startA = startB;\n endA = endB;\n top = k;\n }\n\n for (let i = top; i != 0; --i) {\n let start = load(leftRunStartBuf + (i << alignof()));\n if (start != EMPTY) {\n mergeRuns(\n ptr,\n start,\n load(leftRunEndBuf + (i << alignof())) + 1,\n hi,\n buffer,\n comparator\n );\n }\n }\n // dealloc aux buffers\n __free(buffer);\n __free(leftRunStartBuf);\n}\n\nfunction insertionSort(\n ptr: usize,\n left: i32,\n right: i32,\n presorted: i32,\n comparator: Comparator\n): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n // slightly improved original insertion sort\n for (let i = left + presorted; i <= right; ++i) {\n let j = i - 1;\n let a = load(ptr + (i << alignof()));\n while (j >= left) {\n let b = load(ptr + (j << alignof()));\n if (comparator(a, b) < 0) {\n store(ptr + (j << alignof()), b, 1 << alignof()); --j;\n } else break;\n }\n store(ptr + (j << alignof()), a, 1 << alignof());\n }\n } else {\n // even-odd two-way insertion sort which allow increase minRunLen\n let range = right - left + 1;\n let i = left + select(range & 1, presorted - ((range - presorted) & 1), presorted == 0);\n for (; i <= right; i += 2) {\n let a = load(ptr + (i << alignof()), 0);\n let b = load(ptr + (i << alignof()), 1 << alignof());\n let min = b, max = a;\n if (comparator(a, b) <= 0) {\n min = a, max = b;\n }\n let j = i - 1;\n while (j >= left) {\n a = load(ptr + (j << alignof()));\n if (comparator(a, max) > 0) {\n store(ptr + (j << alignof()), a, 2 << alignof()); --j;\n } else break;\n }\n store(ptr + (j << alignof()), max, 2 << alignof());\n while (j >= left) {\n a = load(ptr + (j << alignof()));\n if (comparator(a, min) > 0) {\n store(ptr + (j << alignof()), a, 1 << alignof()); --j;\n } else break;\n }\n store(ptr + (j << alignof()), min, 1 << alignof());\n }\n }\n}\n\nfunction nodePower(left: u32, right: u32, startA: u32, startB: u32, endB: u32): u32 {\n let n: u64 = right - left + 1;\n let s = startB - (left << 1);\n let l = startA + s;\n let r = endB + s + 1;\n let a = (l << 30) / n;\n let b = (r << 30) / n;\n return clz((a ^ b));\n}\n\nfunction extendRunRight(\n ptr: usize,\n i: i32,\n right: i32,\n comparator: Comparator\n): i32 {\n if (i == right) return i;\n let j = i;\n if (comparator(\n load(ptr + ( j << alignof())),\n load(ptr + (++j << alignof()))\n ) > 0) {\n while (\n j < right &&\n (comparator(\n load(ptr + (j << alignof()), 1 << alignof()),\n load(ptr + (j << alignof()))\n ) >>> 31) // < 0\n ) ++j;\n // reverse\n let k = j;\n while (i < k) {\n let tmp = load(ptr + (i << alignof()));\n store(ptr + (i << alignof()), load(ptr + (k << alignof()))); ++i;\n store(ptr + (k << alignof()), tmp); --k;\n }\n } else {\n while (\n j < right &&\n comparator(\n load(ptr + (j << alignof()), 1 << alignof()),\n load(ptr + (j << alignof()))\n ) >= 0\n ) ++j;\n }\n return j;\n}\n\n// Merges arr[l..m - 1] and arr[m..r]\nfunction mergeRuns(\n ptr: usize,\n l: i32,\n m: i32,\n r: i32,\n buffer: usize,\n comparator: Comparator\n): void {\n --m;\n let i: i32, j: i32, t = r + m;\n for (i = m + 1; i > l; --i) {\n store(\n buffer + ((i - 1) << alignof()),\n load(ptr + ((i - 1) << alignof()))\n );\n }\n for (j = m; j < r; ++j) {\n store(\n buffer + ((t - j) << alignof()),\n load(ptr + (j << alignof()), 1 << alignof())\n );\n }\n for (let k = l; k <= r; ++k) {\n let a = load(buffer + (j << alignof()));\n let b = load(buffer + (i << alignof()));\n if (comparator(a, b) < 0) {\n store(ptr + (k << alignof()), a);\n --j;\n } else {\n store(ptr + (k << alignof()), b);\n ++i;\n }\n }\n}\n","/// \n\nimport { OBJECT, BLOCK_MAXSIZE, TOTAL_OVERHEAD } from \"./rt/common\";\nimport { compareImpl, strtol, strtod, isSpace, isAscii, isFinalSigma, toLower8, toUpper8 } from \"./util/string\";\nimport { SPECIALS_UPPER, casemap, bsearch } from \"./util/casemap\";\nimport { E_INDEXOUTOFRANGE, E_INVALIDLENGTH, E_UNPAIRED_SURROGATE } from \"./util/error\";\nimport { idof } from \"./builtins\";\nimport { Array } from \"./array\";\n\n@final export abstract class String {\n\n @lazy static readonly MAX_LENGTH: i32 = (BLOCK_MAXSIZE >>> alignof());\n\n static fromCharCode(unit: i32, surr: i32 = -1): String {\n let hasSur = surr > 0;\n let out = changetype(__new(2 << i32(hasSur), idof()));\n store(changetype(out), unit);\n if (hasSur) store(changetype(out), surr, 2);\n return out;\n }\n\n static fromCharCodes(units: Array): String {\n let length = units.length;\n let out = changetype(__new(length << 1, idof()));\n let ptr = units.dataStart;\n for (let i = 0; i < length; ++i) {\n store(changetype(out) + (i << 1), load(ptr + (i << 2)));\n }\n return out;\n }\n\n static fromCodePoint(code: i32): String {\n let hasSur = code > 0xFFFF;\n let out = changetype(__new(2 << i32(hasSur), idof()));\n if (!hasSur) {\n store(changetype(out), code);\n } else {\n // Checks valid code point range\n assert(code <= 0x10FFFF);\n code -= 0x10000;\n let hi = (code & 0x03FF) | 0xDC00;\n let lo = code >>> 10 | 0xD800;\n store(changetype(out), lo | hi << 16);\n }\n return out;\n }\n\n @builtin static raw(parts: TemplateStringsArray, ...args: unknown[]): string { return unreachable(); }\n\n get length(): i32 {\n return changetype(changetype(this) - TOTAL_OVERHEAD).rtSize >> 1;\n }\n\n at(pos: i32): String {\n let len = this.length;\n pos += select(0, len, pos >= 0);\n if (pos >= len) throw new RangeError(E_INDEXOUTOFRANGE);\n let out = __new(2, idof());\n store(out, load(changetype(this) + (pos << 1)));\n return changetype(out); // retains\n }\n\n @operator(\"[]\") charAt(pos: i32): String {\n if (pos >= this.length) return changetype(\"\");\n let out = changetype(__new(2, idof()));\n store(changetype(out), load(changetype(this) + (pos << 1)));\n return out;\n }\n\n charCodeAt(pos: i32): i32 {\n if (pos >= this.length) return -1; // (NaN)\n return load(changetype(this) + (pos << 1));\n }\n\n codePointAt(pos: i32): i32 {\n let len = this.length;\n if (pos >= len) return -1; // (undefined)\n let first = load(changetype(this) + (pos << 1));\n if ((first & 0xFC00) != 0xD800 || pos + 1 == len) return first;\n let second = load(changetype(this) + (pos << 1), 2);\n if ((second & 0xFC00) != 0xDC00) return first;\n return (first - 0xD800 << 10) + (second - 0xDC00) + 0x10000;\n }\n\n @operator(\"+\") private static __concat(left: String, right: String): String {\n return left.concat(right);\n }\n\n concat(other: String): String {\n let thisSize: isize = this.length << 1;\n let otherSize: isize = other.length << 1;\n let outSize: usize = thisSize + otherSize;\n if (outSize == 0) return changetype(\"\");\n let out = changetype(__new(outSize, idof()));\n memory.copy(changetype(out), changetype(this), thisSize);\n memory.copy(changetype(out) + thisSize, changetype(other), otherSize);\n return out;\n }\n\n endsWith(search: String, end: i32 = String.MAX_LENGTH): bool {\n end = min(max(end, 0), this.length);\n let searchLength = search.length;\n let searchStart = end - searchLength;\n if (searchStart < 0) return false;\n // @ts-ignore: string <-> String\n return !compareImpl(this, searchStart, search, 0, searchLength);\n }\n\n @operator(\"==\") private static __eq(left: String | null, right: String | null): bool {\n if (changetype(left) == changetype(right)) return true;\n if (changetype(left) == 0 || changetype(right) == 0) return false;\n let leftLength = changetype(left).length;\n if (leftLength != changetype(right).length) return false;\n // @ts-ignore: string <-> String\n return !compareImpl(left, 0, right, 0, leftLength);\n }\n\n @operator.prefix(\"!\")\n private static __not(str: String | null): bool {\n return changetype(str) == 0 || !changetype(str).length;\n }\n\n @operator(\"!=\")\n private static __ne(left: String | null, right: String | null): bool {\n return !this.__eq(left, right);\n }\n\n @operator(\">\") private static __gt(left: String, right: String): bool {\n if (changetype(left) == changetype(right)) return false;\n let leftLength = left.length;\n if (!leftLength) return false;\n let rightLength = right.length;\n if (!rightLength) return true;\n // @ts-ignore: string <-> String\n let res = compareImpl(left, 0, right, 0, min(leftLength, rightLength));\n return res ? res > 0 : leftLength > rightLength;\n }\n\n @operator(\">=\") private static __gte(left: String, right: String): bool {\n return !this.__lt(left, right);\n }\n\n @operator(\"<\") private static __lt(left: String, right: String): bool {\n if (changetype(left) == changetype(right)) return false;\n let rightLength = right.length;\n if (!rightLength) return false;\n let leftLength = left.length;\n if (!leftLength) return true;\n // @ts-ignore: string <-> String\n let res = compareImpl(left, 0, right, 0, min(leftLength, rightLength));\n return res ? res < 0 : leftLength < rightLength;\n }\n\n @operator(\"<=\") private static __lte(left: String, right: String): bool {\n return !this.__gt(left, right);\n }\n\n includes(search: String, start: i32 = 0): bool {\n return this.indexOf(search, start) != -1;\n }\n\n indexOf(search: String, start: i32 = 0): i32 {\n let searchLen = search.length;\n if (!searchLen) return 0;\n let len = this.length;\n if (!len) return -1;\n let searchStart = min(max(start, 0), len);\n for (len -= searchLen; searchStart <= len; ++searchStart) {\n // @ts-ignore: string <-> String\n if (!compareImpl(this, searchStart, search, 0, searchLen)) return searchStart;\n }\n return -1;\n }\n\n lastIndexOf(search: String, start: i32 = i32.MAX_VALUE): i32 {\n let searchLen = search.length;\n if (!searchLen) return this.length;\n let len = this.length;\n if (!len) return -1;\n let searchStart = min(max(start, 0), len - searchLen);\n for (; searchStart >= 0; --searchStart) {\n // @ts-ignore: string <-> String\n if (!compareImpl(this, searchStart, search, 0, searchLen)) return searchStart;\n }\n return -1;\n }\n\n // TODO: implement full locale comparison with locales and Collator options\n localeCompare(other: String): i32 {\n if (changetype(other) == changetype(this)) return 0;\n let alen = this.length;\n let blen = other.length;\n // @ts-ignore: string <-> String\n let res = compareImpl(this, 0, other, 0, min(alen, blen));\n res = res ? res : alen - blen;\n // normalize to [-1, 1] range\n return i32(res > 0) - i32(res < 0);\n }\n\n startsWith(search: String, start: i32 = 0): bool {\n let len = this.length;\n let searchStart = min(max(start, 0), len);\n let searchLength = search.length;\n if (searchLength + searchStart > len) return false;\n // @ts-ignore: string <-> String\n return !compareImpl(this, searchStart, search, 0, searchLength);\n }\n\n substr(start: i32, length: i32 = i32.MAX_VALUE): String { // legacy\n let intStart: isize = start;\n let end: isize = length;\n let len: isize = this.length;\n if (intStart < 0) intStart = max(len + intStart, 0);\n let size = min(max(end, 0), len - intStart) << 1;\n if (size <= 0) return changetype(\"\");\n let out = changetype(__new(size, idof()));\n memory.copy(changetype(out), changetype(this) + (intStart << 1), size);\n return out;\n }\n\n substring(start: i32, end: i32 = i32.MAX_VALUE): String {\n let len: isize = this.length;\n let finalStart = min(max(start, 0), len);\n let finalEnd = min(max(end, 0), len);\n let fromPos = min(finalStart, finalEnd) << 1;\n let toPos = max(finalStart, finalEnd) << 1;\n let size = toPos - fromPos;\n if (!size) return changetype(\"\");\n if (!fromPos && toPos == len << 1) return this;\n let out = changetype(__new(size, idof()));\n memory.copy(changetype(out), changetype(this) + fromPos, size);\n return out;\n }\n\n trim(): String {\n let len = this.length;\n let size: usize = len << 1;\n while (size && isSpace(load(changetype(this) + size - 2))) {\n size -= 2;\n }\n let offset: usize = 0;\n while (offset < size && isSpace(load(changetype(this) + offset))) {\n offset += 2; size -= 2;\n }\n if (!size) return changetype(\"\");\n if (!offset && size == len << 1) return this;\n let out = changetype(__new(size, idof()));\n memory.copy(changetype(out), changetype(this) + offset, size);\n return out;\n }\n\n @inline\n trimLeft(): String {\n return this.trimStart();\n }\n\n @inline\n trimRight(): String {\n return this.trimEnd();\n }\n\n trimStart(): String {\n let size = this.length << 1;\n let offset: usize = 0;\n while (offset < size && isSpace(load(changetype(this) + offset))) {\n offset += 2;\n }\n if (!offset) return this;\n size -= offset;\n if (!size) return changetype(\"\");\n let out = changetype(__new(size, idof()));\n memory.copy(changetype(out), changetype(this) + offset, size);\n return out;\n }\n\n trimEnd(): String {\n let originalSize = this.length << 1;\n let size = originalSize;\n while (size && isSpace(load(changetype(this) + size - 2))) {\n size -= 2;\n }\n if (!size) return changetype(\"\");\n if (size == originalSize) return this;\n let out = changetype(__new(size, idof()));\n memory.copy(changetype(out), changetype(this), size);\n return out;\n }\n\n padStart(length: i32, pad: string = \" \"): String {\n let thisSize = this.length << 1;\n let targetSize = length << 1;\n let padSize = pad.length << 1;\n if (targetSize < thisSize || !padSize) return this;\n let prependSize = targetSize - thisSize;\n let out = changetype(__new(targetSize, idof()));\n if (prependSize > padSize) {\n let repeatCount = (prependSize - 2) / padSize;\n let restBase = repeatCount * padSize;\n let restSize = prependSize - restBase;\n memory.repeat(changetype(out), changetype(pad), padSize, repeatCount);\n memory.copy(changetype(out) + restBase, changetype(pad), restSize);\n } else {\n memory.copy(changetype(out), changetype(pad), prependSize);\n }\n memory.copy(changetype(out) + prependSize, changetype(this), thisSize);\n return out;\n }\n\n padEnd(length: i32, pad: string = \" \"): String {\n let thisSize = this.length << 1;\n let targetSize = length << 1;\n let padSize = pad.length << 1;\n if (targetSize < thisSize || !padSize) return this;\n let appendSize = targetSize - thisSize;\n let out = changetype(__new(targetSize, idof()));\n memory.copy(changetype(out), changetype(this), thisSize);\n if (appendSize > padSize) {\n let repeatCount = (appendSize - 2) / padSize;\n let restBase = repeatCount * padSize;\n let restSize = appendSize - restBase;\n memory.repeat(changetype(out) + thisSize, changetype(pad), padSize, repeatCount);\n memory.copy(changetype(out) + thisSize + restBase, changetype(pad), restSize);\n } else {\n memory.copy(changetype(out) + thisSize, changetype(pad), appendSize);\n }\n return out;\n }\n\n repeat(count: i32 = 0): String {\n let length = this.length;\n\n // Most browsers can't handle strings 1 << 28 chars or longer\n if (count < 0 || length * count > (1 << 28)) {\n throw new RangeError(E_INVALIDLENGTH);\n }\n\n if (count == 0 || !length) return changetype(\"\");\n if (count == 1) return this;\n let out = changetype(__new((length * count) << 1, idof()));\n memory.repeat(changetype(out), changetype(this), length << 1, count);\n return out;\n }\n\n replace(search: String, replacement: String): String {\n let len: usize = this.length;\n let slen: usize = search.length;\n if (len <= slen) {\n return len < slen ? this : select(replacement, this, search == this);\n }\n let index: isize = this.indexOf(search);\n if (~index) {\n let rlen: usize = replacement.length;\n len -= slen;\n let olen = len + rlen;\n if (olen) {\n let out = changetype(__new(olen << 1, idof()));\n memory.copy(changetype(out), changetype(this), index << 1);\n memory.copy(\n changetype(out) + (index << 1),\n changetype(replacement),\n rlen << 1\n );\n memory.copy(\n changetype(out) + ((index + rlen) << 1),\n changetype(this) + ((index + slen) << 1),\n (len - index) << 1\n );\n return out;\n }\n }\n return this;\n }\n\n replaceAll(search: String, replacement: String): String {\n let thisLen: usize = this.length;\n let searchLen: usize = search.length;\n if (thisLen <= searchLen) {\n return thisLen < searchLen\n ? this\n : select(replacement, this, search == this);\n }\n let replaceLen: usize = replacement.length;\n if (!searchLen) {\n if (!replaceLen) return this;\n // Special case: 'abc'.replaceAll('', '-') -> '-a-b-c-'\n let out = changetype(__new((thisLen + (thisLen + 1) * replaceLen) << 1, idof()));\n memory.copy(changetype(out), changetype(replacement), replaceLen << 1);\n let offset = replaceLen;\n for (let i: usize = 0; i < thisLen; ++i) {\n store(\n changetype(out) + (offset++ << 1),\n load(changetype(this) + (i << 1))\n );\n memory.copy(\n changetype(out) + (offset << 1),\n changetype(replacement),\n replaceLen << 1\n );\n offset += replaceLen;\n }\n return out;\n }\n let prev: isize = 0, next: isize = 0;\n if (searchLen == replaceLen) {\n // Fast path when search and replacement have same length\n let outSize = thisLen << 1;\n let out = changetype(__new(outSize, idof()));\n memory.copy(changetype(out), changetype(this), outSize);\n while (~(next = this.indexOf(search, prev))) {\n memory.copy(changetype(out) + (next << 1), changetype(replacement), replaceLen << 1);\n prev = next + searchLen;\n }\n return out;\n }\n let out: String | null = null, offset: usize = 0, outSize = thisLen;\n while (~(next = this.indexOf(search, prev))) {\n if (!out) out = changetype(__new(thisLen << 1, idof()));\n let chunk = next - prev;\n if (offset + chunk + replaceLen > outSize) {\n outSize <<= 1;\n out = changetype(__renew(changetype(out), outSize << 1));\n }\n memory.copy(\n changetype(out) + (offset << 1),\n changetype(this) + (prev << 1),\n chunk << 1\n );\n offset += chunk;\n memory.copy(\n changetype(out) + (offset << 1),\n changetype(replacement),\n replaceLen << 1\n );\n offset += replaceLen;\n prev = next + searchLen;\n }\n if (out) {\n let rest = thisLen - prev;\n if (offset + rest > outSize) {\n outSize <<= 1;\n out = changetype(__renew(changetype(out), outSize << 1));\n }\n if (rest) {\n memory.copy(\n changetype(out) + (offset << 1),\n changetype(this) + (prev << 1),\n rest << 1\n );\n }\n rest += offset;\n if (outSize > rest) {\n out = changetype(__renew(changetype(out), rest << 1));\n }\n return out;\n }\n return this;\n }\n\n slice(start: i32, end: i32 = i32.MAX_VALUE): String {\n let len = this.length;\n start = start < 0 ? max(start + len, 0) : min(start, len);\n end = end < 0 ? max(end + len, 0) : min(end, len);\n len = end - start;\n if (len <= 0) return changetype(\"\");\n let out = changetype(__new(len << 1, idof()));\n memory.copy(changetype(out), changetype(this) + (start << 1), len << 1);\n return out;\n }\n\n split(separator: String | null = null, limit: i32 = i32.MAX_VALUE): String[] {\n if (!limit) return changetype(__newArray(0, alignof(), idof>()));\n if (changetype(separator) == 0) return [ this ];\n let length: isize = this.length;\n let sepLen = changetype(separator).length;\n if (limit < 0) limit = i32.MAX_VALUE;\n if (!sepLen) {\n if (!length) return changetype(__newArray(0, alignof(), idof>()));\n // split by chars\n length = min(length, limit);\n let result = changetype(__newArray(length, alignof(), idof>()));\n // @ts-ignore: cast\n let resultStart = result.dataStart as usize;\n for (let i: isize = 0; i < length; ++i) {\n let charStr = changetype(__new(2, idof()));\n store(changetype(charStr), load(changetype(this) + (i << 1)));\n store(resultStart + (i << alignof()), changetype(charStr)); // result[i] = charStr\n __link(changetype(result), changetype(charStr), true);\n }\n return result;\n } else if (!length) {\n let result = changetype(__newArray(1, alignof(), idof>()));\n // @ts-ignore: cast\n store(result.dataStart as usize, changetype(\"\")); // static \"\"\n return result;\n }\n let result = changetype(__newArray(0, alignof(), idof>()));\n let end = 0, start = 0, i = 0;\n while (~(end = this.indexOf(changetype(separator), start))) {\n let len = end - start;\n if (len > 0) {\n let out = changetype(__new(len << 1, idof()));\n memory.copy(changetype(out), changetype(this) + (start << 1), len << 1);\n result.push(out);\n } else {\n result.push(changetype(\"\"));\n }\n if (++i == limit) return result;\n start = end + sepLen;\n }\n if (!start) { // also means: loop above didn't do anything\n result.push(this);\n return result;\n }\n let len = length - start;\n if (len > 0) {\n let out = changetype(__new(len << 1, idof()));\n memory.copy(changetype(out), changetype(this) + (start << 1), len << 1);\n result.push(out);\n } else {\n result.push(changetype(\"\")); // static \"\"\n }\n return result;\n }\n\n toLowerCase(): String {\n let len = this.length;\n if (!len) return this;\n let codes = changetype(__new(len * 2 * 2, idof()));\n let j: usize = 0;\n for (let i: usize = 0; i < len; ++i, ++j) {\n let c = load(changetype(this) + (i << 1));\n if (isAscii(c)) {\n store(changetype(codes) + (j << 1), toLower8(c));\n } else {\n // check and read surrogate pair\n if ((c - 0xD7FF < 0xDC00 - 0xD7FF) && i < len - 1) {\n let c1 = load(changetype(this) + (i << 1), 2);\n if (c1 - 0xDBFF < 0xE000 - 0xDBFF) {\n let c0 = c;\n c = (((c & 0x03FF) << 10) | (c1 & 0x03FF)) + 0x10000;\n ++i;\n if (c >= 0x20000) {\n store(changetype(codes) + (j << 1), c0 | (c1 << 16));\n ++j;\n continue;\n }\n }\n }\n // check special casing for lower table. It has one ently so instead lookup we just inline this.\n if (c == 0x0130) {\n // 0x0130 -> [0x0069, 0x0307]\n store(changetype(codes) + (j << 1), (0x0307 << 16) | 0x0069);\n ++j;\n } else if (c == 0x03A3) { // 'Σ'\n // Σ maps to σ but except at the end of a word where it maps to ς\n let sigma = 0x03C3; // σ\n if (len > 1 && isFinalSigma(changetype(this), i, len)) {\n sigma = 0x03C2; // ς\n }\n store(changetype(codes) + (j << 1), sigma);\n } else if (c - 0x24B6 <= 0x24CF - 0x24B6) {\n // Range 0x24B6 <= c <= 0x24CF not covered by casemap and require special early handling\n store(changetype(codes) + (j << 1), c + 26);\n } else {\n let code = casemap(c, 0) & 0x1FFFFF;\n if (code < 0x10000) {\n store(changetype(codes) + (j << 1), code);\n } else {\n // store as surrogare pair\n code -= 0x10000;\n let lo = (code >>> 10) | 0xD800;\n let hi = (code & 0x03FF) | 0xDC00;\n store(changetype(codes) + (j << 1), lo | (hi << 16));\n ++j;\n }\n }\n }\n }\n return changetype(__renew(changetype(codes), j << 1));\n }\n\n toUpperCase(): String {\n let len = this.length;\n if (!len) return this;\n let codes = changetype(__new(len * 3 * 2, idof()));\n let specialsPtr = changetype(SPECIALS_UPPER);\n let specialsLen = SPECIALS_UPPER.length;\n let j: usize = 0;\n for (let i: usize = 0; i < len; ++i, ++j) {\n let c = load(changetype(this) + (i << 1));\n if (isAscii(c)) {\n store(changetype(codes) + (j << 1), toUpper8(c));\n } else {\n // check and read surrogate pair\n if ((c - 0xD7FF < 0xDC00 - 0xD7FF) && i < len - 1) {\n let c1 = load(changetype(this) + (i << 1), 2);\n if (c1 - 0xDBFF < 0xE000 - 0xDBFF) {\n let c0 = c;\n c = (((c & 0x03FF) << 10) | (c1 & 0x03FF)) + 0x10000;\n ++i;\n if (c >= 0x20000) {\n store(changetype(codes) + (j << 1), c0 | (c1 << 16));\n ++j;\n continue;\n }\n }\n }\n // Range 0x24D0 <= c <= 0x24E9 not covered by casemap and require special early handling\n if (c - 0x24D0 <= 0x24E9 - 0x24D0) {\n // monkey patch\n store(changetype(codes) + (j << 1), c - 26);\n } else {\n let index: usize = -1;\n // Fast range check. See first and last rows in specialsUpper table\n if (c - 0x00DF <= 0xFB17 - 0x00DF) {\n index = bsearch(c, specialsPtr, specialsLen);\n }\n if (~index) {\n // load next 3 code points from row with `index` offset for specialsUpper table\n let ab = load(specialsPtr + (index << 1), 2);\n let cc = load(specialsPtr + (index << 1), 6);\n store(changetype(codes) + (j << 1), ab, 0);\n store(changetype(codes) + (j << 1), cc, 4);\n j += 1 + usize(cc != 0);\n } else {\n let code = casemap(c, 1) & 0x1FFFFF;\n if (code < 0x10000) {\n store(changetype(codes) + (j << 1), code);\n } else {\n // store as surrogare pair\n code -= 0x10000;\n let lo = (code >>> 10) | 0xD800;\n let hi = (code & 0x03FF) | 0xDC00;\n store(changetype(codes) + (j << 1), lo | (hi << 16));\n ++j;\n }\n }\n }\n }\n }\n return changetype(__renew(changetype(codes), j << 1));\n }\n\n toString(): String {\n return this;\n }\n}\n\n// @ts-ignore: nolib\nexport type string = String;\n\nexport function parseInt(str: string, radix: i32 = 0): f64 {\n return strtol(str, radix);\n}\n\nexport function parseFloat(str: string): f64 {\n return strtod(str);\n}\n\n// Encoding helpers\nexport namespace String {\n\n export namespace UTF8 {\n\n export const enum ErrorMode {\n WTF8,\n REPLACE,\n ERROR\n }\n\n export function byteLength(str: string, nullTerminated: bool = false): i32 {\n let strOff = changetype(str);\n let strEnd = strOff + changetype(changetype(str) - TOTAL_OVERHEAD).rtSize;\n let bufLen = i32(nullTerminated);\n while (strOff < strEnd) {\n let c1 = load(strOff);\n if (c1 < 128) {\n // @ts-ignore: cast\n if (nullTerminated & !c1) break;\n bufLen += 1;\n } else if (c1 < 2048) {\n bufLen += 2;\n } else {\n if ((c1 & 0xFC00) == 0xD800 && strOff + 2 < strEnd) {\n if ((load(strOff, 2) & 0xFC00) == 0xDC00) {\n bufLen += 4; strOff += 4;\n continue;\n }\n }\n bufLen += 3;\n }\n strOff += 2;\n }\n return bufLen;\n }\n\n export function encode(str: string, nullTerminated: bool = false, errorMode: ErrorMode = ErrorMode.WTF8): ArrayBuffer {\n let buf = changetype(__new(byteLength(str, nullTerminated), idof()));\n encodeUnsafe(changetype(str), str.length, changetype(buf), nullTerminated, errorMode);\n return buf;\n }\n\n // @ts-ignore: decorator\n @unsafe\n export function encodeUnsafe(str: usize, len: i32, buf: usize, nullTerminated: bool = false, errorMode: ErrorMode = ErrorMode.WTF8): usize {\n let strEnd = str + (len << 1);\n let bufOff = buf;\n while (str < strEnd) {\n let c1 = load(str);\n if (c1 < 128) {\n store(bufOff, c1);\n bufOff++;\n // @ts-ignore: cast\n if (nullTerminated & !c1) return bufOff - buf;\n } else if (c1 < 2048) {\n let b0 = c1 >> 6 | 192;\n let b1 = c1 & 63 | 128;\n store(bufOff, b1 << 8 | b0);\n bufOff += 2;\n } else {\n // D800: 11011 0 0000000000 Lead\n // DBFF: 11011 0 1111111111\n // DC00: 11011 1 0000000000 Trail\n // DFFF: 11011 1 1111111111\n // F800: 11111 0 0000000000 Mask\n // FC00: 11111 1 0000000000\n if ((c1 & 0xF800) == 0xD800) {\n if (c1 < 0xDC00 && str + 2 < strEnd) {\n let c2 = load(str, 2);\n if ((c2 & 0xFC00) == 0xDC00) {\n c1 = 0x10000 + ((c1 & 0x03FF) << 10) | (c2 & 0x03FF);\n let b0 = c1 >> 18 | 240;\n let b1 = c1 >> 12 & 63 | 128;\n let b2 = c1 >> 6 & 63 | 128;\n let b3 = c1 & 63 | 128;\n store(bufOff, b3 << 24 | b2 << 16 | b1 << 8 | b0);\n bufOff += 4; str += 4;\n continue;\n }\n }\n if (errorMode != ErrorMode.WTF8) { // unlikely\n if (errorMode == ErrorMode.ERROR) throw new Error(E_UNPAIRED_SURROGATE);\n c1 = 0xFFFD;\n }\n }\n let b0 = c1 >> 12 | 224;\n let b1 = c1 >> 6 & 63 | 128;\n let b2 = c1 & 63 | 128;\n store(bufOff, b1 << 8 | b0);\n store(bufOff, b2, 2);\n bufOff += 3;\n }\n str += 2;\n }\n if (nullTerminated) {\n store(bufOff++, 0);\n }\n return bufOff - buf;\n }\n\n export function decode(buf: ArrayBuffer, nullTerminated: bool = false): String {\n return decodeUnsafe(changetype(buf), buf.byteLength, nullTerminated);\n }\n\n // @ts-ignore: decorator\n @unsafe\n export function decodeUnsafe(buf: usize, len: usize, nullTerminated: bool = false): String {\n let bufOff = buf;\n let bufEnd = buf + len;\n assert(bufEnd >= bufOff); // guard wraparound\n let str = changetype(__new(len << 1, idof())); // max is one u16 char per u8 byte\n let strOff = changetype(str);\n while (bufOff < bufEnd) {\n let u0 = load(bufOff); ++bufOff;\n if (!(u0 & 128)) {\n // @ts-ignore: cast\n if (nullTerminated & !u0) break;\n store(strOff, u0);\n } else {\n if (bufEnd == bufOff) break;\n let u1 = load(bufOff) & 63; ++bufOff;\n if ((u0 & 224) == 192) {\n store(strOff, (u0 & 31) << 6 | u1);\n } else {\n if (bufEnd == bufOff) break;\n let u2 = load(bufOff) & 63; ++bufOff;\n if ((u0 & 240) == 224) {\n u0 = (u0 & 15) << 12 | u1 << 6 | u2;\n } else {\n if (bufEnd == bufOff) break;\n u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | load(bufOff) & 63;\n ++bufOff;\n }\n if (u0 < 0x10000) {\n store(strOff, u0);\n } else {\n u0 -= 0x10000;\n let lo = u0 >> 10 | 0xD800;\n let hi = (u0 & 0x03FF) | 0xDC00;\n store(strOff, lo | (hi << 16));\n strOff += 2;\n }\n }\n }\n strOff += 2;\n }\n return changetype(__renew(changetype(str), strOff - changetype(str)));\n }\n }\n\n export namespace UTF16 {\n\n export function byteLength(str: string): i32 {\n return changetype(changetype(str) - TOTAL_OVERHEAD).rtSize;\n }\n\n export function encode(str: string): ArrayBuffer {\n let buf = changetype(__new(byteLength(str), idof()));\n encodeUnsafe(changetype(str), str.length, changetype(buf));\n return buf;\n }\n\n // @ts-ignore: decorator\n @unsafe\n export function encodeUnsafe(str: usize, len: i32, buf: usize): usize {\n let size = len << 1;\n memory.copy(buf, changetype(str), size);\n return size;\n }\n\n export function decode(buf: ArrayBuffer): String {\n return decodeUnsafe(changetype(buf), buf.byteLength);\n }\n\n // @ts-ignore: decorator\n @unsafe\n export function decodeUnsafe(buf: usize, len: usize): String {\n let str = changetype(__new(len &= ~1, idof()));\n memory.copy(changetype(str), buf, len);\n return str;\n }\n }\n}\n\nexport class TemplateStringsArray extends Array {\n readonly raw: string[];\n}\n","import { AL_MASK, OBJECT, OBJECT_OVERHEAD, BLOCK_MAXSIZE, BLOCK_OVERHEAD, BLOCK, OBJECT_MAXSIZE } from \"./common\";\nimport { E_ALLOCATION_TOO_LARGE } from \"../util/error\";\n\n// === A minimal runtime stub ===\n\n// @ts-ignore: decorator\n@lazy let startOffset: usize = ((__heap_base + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD;\n// @ts-ignore: decorator\n@lazy let offset: usize = startOffset;\n\nfunction maybeGrowMemory(newOffset: usize): void {\n // assumes newOffset is aligned\n let pagesBefore = memory.size();\n let maxOffset = ((pagesBefore << 16) + AL_MASK) & ~AL_MASK;\n if (newOffset > maxOffset) {\n let pagesNeeded = (((newOffset - maxOffset + 0xffff) & ~0xffff) >>> 16);\n let pagesWanted = max(pagesBefore, pagesNeeded); // double memory\n if (memory.grow(pagesWanted) < 0) {\n if (memory.grow(pagesNeeded) < 0) unreachable(); // out of memory\n }\n }\n offset = newOffset;\n}\n\n// @ts-ignore: decorator\n@inline function computeSize(size: usize): usize {\n return ((size + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD;\n}\n\n// @ts-ignore: decorator\n@unsafe @global\nexport function __alloc(size: usize): usize {\n if (size > BLOCK_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);\n let block = changetype(offset);\n let ptr = offset + BLOCK_OVERHEAD;\n let payloadSize = computeSize(size);\n maybeGrowMemory(ptr + payloadSize);\n block.mmInfo = payloadSize;\n return ptr;\n}\n\n// @ts-ignore: decorator\n@unsafe @global\nexport function __realloc(ptr: usize, size: usize): usize {\n assert(ptr != 0 && !(ptr & AL_MASK)); // must exist and be aligned\n let block = changetype(ptr - BLOCK_OVERHEAD);\n let actualSize = block.mmInfo;\n let isLast = ptr + actualSize == offset;\n let payloadSize = computeSize(size);\n if (size > actualSize) {\n if (isLast) { // last block: grow\n if (size > BLOCK_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);\n maybeGrowMemory(ptr + payloadSize);\n block.mmInfo = payloadSize;\n } else { // copy to new block at least double the size\n let newPtr = __alloc(max(payloadSize, actualSize << 1));\n memory.copy(newPtr, ptr, actualSize);\n block = changetype((ptr = newPtr) - BLOCK_OVERHEAD);\n }\n } else if (isLast) { // last block: shrink\n offset = ptr + payloadSize;\n block.mmInfo = payloadSize;\n }\n return ptr;\n}\n\n// @ts-ignore: decorator\n@unsafe @global\nexport function __free(ptr: usize): void {\n assert(ptr != 0 && !(ptr & AL_MASK)); // must exist and be aligned\n let block = changetype(ptr - BLOCK_OVERHEAD);\n if (ptr + block.mmInfo == offset) { // last block: discard\n offset = changetype(block);\n }\n}\n\n// @ts-ignore: decorator\n@unsafe @global\nexport function __reset(): void { // special\n offset = startOffset;\n}\n\n// @ts-ignore: decorator\n@unsafe @global\nexport function __new(size: usize, id: u32): usize {\n if (size > OBJECT_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);\n let ptr = __alloc(OBJECT_OVERHEAD + size);\n let object = changetype(ptr - BLOCK_OVERHEAD);\n object.gcInfo = 0;\n object.gcInfo2 = 0;\n object.rtId = id;\n object.rtSize = size;\n return ptr + OBJECT_OVERHEAD;\n}\n\n// @ts-ignore: decorator\n@unsafe @global\nexport function __renew(oldPtr: usize, size: usize): usize {\n if (size > OBJECT_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);\n let newPtr = __realloc(oldPtr - OBJECT_OVERHEAD, OBJECT_OVERHEAD + size);\n changetype(newPtr - BLOCK_OVERHEAD).rtSize = size;\n return newPtr + OBJECT_OVERHEAD;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __link(parentPtr: usize, childPtr: usize, expectMultiple: bool): void {\n // nop\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __pin(ptr: usize): usize {\n return ptr;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __unpin(ptr: usize): void {\n // nop\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nfunction __visit(ptr: usize, cookie: u32): void { // eslint-disable-line @typescript-eslint/no-unused-vars\n // nop\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __collect(): void {\n // nop\n}\n","// Common error messages for use across the standard library. Keeping error messages compact\n// and reusing them where possible ensures minimal static data in binaries.\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_INDEXOUTOFRANGE: string = \"Index out of range\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_VALUEOUTOFRANGE: string = \"Value out of range\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_INVALIDLENGTH: string = \"Invalid length\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_EMPTYARRAY: string = \"Array is empty\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_HOLEYARRAY: string = \"Element type must be nullable if array is holey\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_NOTIMPLEMENTED: string = \"Not implemented\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_KEYNOTFOUND: string = \"Key does not exist\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_ALLOCATION_TOO_LARGE: string = \"Allocation too large\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_ALREADY_PINNED: string = \"Object already pinned\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_NOT_PINNED: string = \"Object is not pinned\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_URI_MALFORMED: string = \"URI malformed\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_INVALIDDATE: string = \"Invalid Date\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_UNPAIRED_SURROGATE: string = \"Unpaired surrogate\";\n","import { itoa32, utoa32, itoa64, utoa64, dtoa } from \"./util/number\";\nimport { strtol, strtod } from \"./util/string\";\n\n// @ts-ignore: decorator\n@builtin @inline\nexport const NaN: f64 = 0 / 0; // context-aware\n\n// @ts-ignore: decorator\n@builtin @inline\nexport const Infinity: f64 = 1 / 0; // context-aware\n\n// @ts-ignore: decorator\n@builtin\nexport declare function isNaN(value: T): bool;\n\n// @ts-ignore: decorator\n@builtin\nexport declare function isFinite(value: T): bool;\n\n@final @unmanaged\nexport abstract class I8 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: i8 = i8.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: i8 = i8.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): i8 {\n return strtol(value, radix);\n }\n\n toString(this: i8, radix: i32 = 10): String {\n return itoa32(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class I16 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: i16 = i16.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: i16 = i16.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): i16 {\n return strtol(value, radix);\n }\n\n toString(this: i16, radix: i32 = 10): String {\n return itoa32(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class I32 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: i32 = i32.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: i32 = i32.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): i32 {\n return strtol(value, radix);\n }\n\n toString(this: i32, radix: i32 = 10): String {\n return itoa32(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class I64 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: i64 = i64.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: i64 = i64.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): i64 {\n return strtol(value, radix);\n }\n\n toString(this: i64, radix: i32 = 10): String {\n return itoa64(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class Isize {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: isize = isize.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: isize = isize.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): isize {\n return strtol(value, radix);\n }\n\n toString(this: isize, radix: i32 = 10): String {\n if (sizeof() == 4) {\n return itoa32(this, radix);\n } else {\n return itoa64(this, radix);\n }\n }\n}\n\n@final @unmanaged\nexport abstract class U8 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: u8 = u8.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: u8 = u8.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): u8 {\n return strtol(value, radix);\n }\n\n toString(this: u8, radix: i32 = 10): String {\n return utoa32(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class U16 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: u16 = u16.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: u16 = u16.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): u16 {\n return strtol(value, radix);\n }\n\n toString(this: u16, radix: i32 = 10): String {\n return utoa32(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class U32 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: u32 = u32.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: u32 = u32.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): u32 {\n return strtol(value, radix);\n }\n\n toString(this: u32, radix: i32 = 10): String {\n return utoa32(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class U64 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: u64 = u64.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: u64 = u64.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): u64 {\n return strtol(value, radix);\n }\n\n toString(this: u64, radix: i32 = 10): String {\n return utoa64(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class Usize {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: usize = usize.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: usize = usize.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): usize {\n return strtol(value, radix);\n }\n\n toString(this: usize, radix: i32 = 10): String {\n if (sizeof() == 4) {\n return utoa32(this, radix);\n } else {\n return utoa64(this, radix);\n }\n }\n}\n\n@final @unmanaged\nexport abstract class Bool {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: bool = bool.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: bool = bool.MAX_VALUE;\n\n toString(this: bool, radix: i32 = 0): String {\n return this ? \"true\" : \"false\";\n }\n}\n\nexport { Bool as Boolean };\n\n@final @unmanaged\nexport abstract class F32 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly EPSILON: f32 = f32.EPSILON;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: f32 = f32.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: f32 = f32.MAX_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_SAFE_INTEGER: f32 = f32.MIN_SAFE_INTEGER;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_SAFE_INTEGER: f32 = f32.MAX_SAFE_INTEGER;\n\n // @ts-ignore: decorator\n @lazy\n static readonly POSITIVE_INFINITY: f32 = f32.POSITIVE_INFINITY;\n\n // @ts-ignore: decorator\n @lazy\n static readonly NEGATIVE_INFINITY: f32 = f32.NEGATIVE_INFINITY;\n\n // @ts-ignore: decorator\n @lazy\n static readonly NaN: f32 = f32.NaN;\n\n static isNaN(value: f32): bool {\n return isNaN(value);\n }\n\n static isFinite(value: f32): bool {\n return isFinite(value);\n }\n\n static isSafeInteger(value: f32): bool {\n return abs(value) <= f32.MAX_SAFE_INTEGER && trunc(value) == value;\n }\n\n static isInteger(value: f32): bool {\n return isFinite(value) && trunc(value) == value;\n }\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): f32 {\n return strtol(value, radix);\n }\n\n /** @deprecated */\n static parseFloat(value: string): f32 {\n return strtod(value);\n }\n\n toString(this: f32, radix: i32 = 0): String {\n return dtoa(this);\n }\n}\n\n@final @unmanaged\nexport abstract class F64 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly EPSILON: f64 = f64.EPSILON;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: f64 = f64.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: f64 = f64.MAX_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_SAFE_INTEGER: f64 = f64.MIN_SAFE_INTEGER;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_SAFE_INTEGER: f64 = f64.MAX_SAFE_INTEGER;\n\n // @ts-ignore: decorator\n @lazy\n static readonly POSITIVE_INFINITY: f64 = f64.POSITIVE_INFINITY;\n\n // @ts-ignore: decorator\n @lazy\n static readonly NEGATIVE_INFINITY: f64 = f64.NEGATIVE_INFINITY;\n\n // @ts-ignore: decorator\n @lazy\n static readonly NaN: f64 = f64.NaN;\n\n static isNaN(value: f64): bool {\n return isNaN(value);\n }\n\n static isFinite(value: f64): bool {\n return isFinite(value);\n }\n\n static isSafeInteger(value: f64): bool {\n return abs(value) <= f64.MAX_SAFE_INTEGER && trunc(value) == value;\n }\n\n static isInteger(value: f64): bool {\n return isFinite(value) && trunc(value) == value;\n }\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): f64 {\n return strtol(value, radix);\n }\n\n /** @deprecated */\n static parseFloat(value: string): f64 {\n return strtod(value);\n }\n\n toString(this: f64, radix: i32 = 0): String {\n return dtoa(this);\n }\n}\n\nexport { F64 as Number };\n","import { memcmp, memmove, memset } from \"./util/memory\";\nimport { E_NOTIMPLEMENTED } from \"./util/error\";\n\n/** Memory manager interface. */\nexport namespace memory {\n\n /** Gets the size of the memory in pages. */\n // @ts-ignore: decorator\n @builtin\n export declare function size(): i32;\n\n /** Grows the memory by the given size in pages and returns the previous size in pages. */\n // @ts-ignore: decorator\n @unsafe @builtin\n export declare function grow(pages: i32): i32;\n\n /** Fills a section in memory with the specified byte value. */\n // @ts-ignore: decorator\n @unsafe @builtin\n export function fill(dst: usize, c: u8, n: usize): void {\n memset(dst, c, n); // fallback if \"bulk-memory\" isn't enabled\n }\n\n /** Copies a section of memory to another. Has move semantics. */\n // @ts-ignore: decorator\n @unsafe @builtin\n export function copy(dst: usize, src: usize, n: usize): void {\n memmove(dst, src, n); // fallback if \"bulk-memory\" isn't enabled\n }\n\n export namespace atomic {\n\n // @ts-ignore: decorator\n @unsafe @builtin\n export declare function wait32(ptr: usize, expected: i32, timeout: i64): AtomicWaitResult;\n\n // @ts-ignore: decorator\n @unsafe @builtin\n export declare function wait64(ptr: usize, expected: i64, timeout: i64): AtomicWaitResult;\n }\n\n /** Initializes a memory segment. */\n // @ts-ignore: decorator\n @unsafe\n export function init(segmentIndex: u32, srcOffset: usize, dstOffset: usize, n: usize): void {\n throw new Error(E_NOTIMPLEMENTED);\n }\n\n /** Drops a memory segment. */\n // @ts-ignore: decorator\n @unsafe\n export function drop(segmentIndex: u32): void {\n throw new Error(E_NOTIMPLEMENTED);\n }\n\n /** Repeats a section of memory at a specific address. */\n // @ts-ignore: decorator\n @unsafe\n export function repeat(dst: usize, src: usize, srcLength: usize, count: usize): void {\n let index: usize = 0;\n let total = srcLength * count;\n while (index < total) {\n memory.copy(dst + index, src, srcLength);\n index += srcLength;\n }\n }\n\n /** Compares a section of memory to another. */\n // @ts-ignore: decorator\n @inline\n export function compare(vl: usize, vr: usize, n: usize): i32 {\n return memcmp(vl, vr, n);\n }\n\n /** Gets a pointer to a static chunk of memory of the given size. */\n // @ts-ignore: decorator\n @builtin\n export declare function data(size: T, align?: i32): usize;\n}\n\n// @ts-ignore: decorator\n@builtin\nexport declare const __data_end: usize;\n\n// @ts-ignore: decorator\n@builtin\nexport declare let __stack_pointer: usize;\n\n// @ts-ignore: decorator\n@builtin\nexport declare const __heap_base: usize;\n\n/** Heap memory interface. */\nexport namespace heap {\n\n /** Allocates a chunk of memory of at least the specified size. */\n // @ts-ignore: decorator\n @unsafe export function alloc(size: usize): usize {\n return __alloc(size);\n }\n\n /** Reallocates a chunk of memory to have at least the specified size. */\n // @ts-ignore: decorator\n @unsafe export function realloc(ptr: usize, size: usize): usize {\n return __realloc(ptr, size);\n }\n\n /** Frees a chunk of memory. Does hardly anything (most recent block only) with the stub runtime. */\n // @ts-ignore: decorator\n @unsafe export function free(ptr: usize): void {\n __free(ptr);\n }\n\n /** Dangerously resets the entire heap. Specific to the stub runtime. */\n // @ts-ignore: decorator\n @unsafe export function reset(): void {\n if (isDefined(__reset)) {\n __reset();\n } else {\n throw new Error(E_NOTIMPLEMENTED);\n }\n }\n}\n","export function memcpy(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memcpy.c\n let w: u32, x: u32;\n\n // copy 1 byte each until src is aligned to 4 bytes\n while (n && (src & 3)) {\n store(dest++, load(src++));\n n--;\n }\n\n // if dst is aligned to 4 bytes as well, copy 4 bytes each\n if ((dest & 3) == 0) {\n while (n >= 16) {\n store(dest , load(src ));\n store(dest + 4, load(src + 4));\n store(dest + 8, load(src + 8));\n store(dest + 12, load(src + 12));\n src += 16; dest += 16; n -= 16;\n }\n if (n & 8) {\n store(dest , load(src ));\n store(dest + 4, load(src + 4));\n dest += 8; src += 8;\n }\n if (n & 4) {\n store(dest, load(src));\n dest += 4; src += 4;\n }\n if (n & 2) { // drop to 2 bytes each\n store(dest, load(src));\n dest += 2; src += 2;\n }\n if (n & 1) { // drop to 1 byte\n store(dest++, load(src++));\n }\n return;\n }\n\n // if dst is not aligned to 4 bytes, use alternating shifts to copy 4 bytes each\n // doing shifts if faster when copying enough bytes (here: 32 or more)\n if (n >= 32) {\n switch (dest & 3) {\n // known to be != 0\n case 1: {\n w = load(src);\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n n -= 3;\n while (n >= 17) {\n x = load(src + 1);\n store(dest, w >> 24 | x << 8);\n w = load(src + 5);\n store(dest + 4, x >> 24 | w << 8);\n x = load(src + 9);\n store(dest + 8, w >> 24 | x << 8);\n w = load(src + 13);\n store(dest + 12, x >> 24 | w << 8);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n case 2: {\n w = load(src);\n store(dest++, load(src++));\n store(dest++, load(src++));\n n -= 2;\n while (n >= 18) {\n x = load(src + 2);\n store(dest, w >> 16 | x << 16);\n w = load(src + 6);\n store(dest + 4, x >> 16 | w << 16);\n x = load(src + 10);\n store(dest + 8, w >> 16 | x << 16);\n w = load(src + 14);\n store(dest + 12, x >> 16 | w << 16);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n case 3: {\n w = load(src);\n store(dest++, load(src++));\n n -= 1;\n while (n >= 19) {\n x = load(src + 3);\n store(dest, w >> 8 | x << 24);\n w = load(src + 7);\n store(dest + 4, x >> 8 | w << 24);\n x = load(src + 11);\n store(dest + 8, w >> 8 | x << 24);\n w = load(src + 15);\n store(dest + 12, x >> 8 | w << 24);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n }\n }\n\n // copy remaining bytes one by one\n if (n & 16) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 8) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 4) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 2) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 1) {\n store(dest++, load(src++));\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function memmove(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c\n if (dest == src) return;\n if (ASC_SHRINK_LEVEL < 1) {\n if (src - dest - n <= -(n << 1)) {\n memcpy(dest, src, n);\n return;\n }\n }\n if (dest < src) {\n if (ASC_SHRINK_LEVEL < 2) {\n if ((src & 7) == (dest & 7)) {\n while (dest & 7) {\n if (!n) return;\n --n;\n store(dest++, load(src++));\n }\n while (n >= 8) {\n store(dest, load(src));\n n -= 8;\n dest += 8;\n src += 8;\n }\n }\n }\n while (n) {\n store(dest++, load(src++));\n --n;\n }\n } else {\n if (ASC_SHRINK_LEVEL < 2) {\n if ((src & 7) == (dest & 7)) {\n while ((dest + n) & 7) {\n if (!n) return;\n store(dest + --n, load(src + n));\n }\n while (n >= 8) {\n n -= 8;\n store(dest + n, load(src + n));\n }\n }\n }\n while (n) {\n store(dest + --n, load(src + n));\n }\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function memset(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset\n if (ASC_SHRINK_LEVEL > 1) {\n while (n) {\n store(dest++, c);\n --n;\n }\n } else {\n // fill head and tail with minimal branching\n if (!n) return;\n let dend = dest + n;\n store(dest, c);\n store(dend - 1, c);\n if (n <= 2) return;\n store(dest, c, 1);\n store(dest, c, 2);\n store(dend - 2, c);\n store(dend - 3, c);\n if (n <= 6) return;\n store(dest, c, 3);\n store(dend - 4, c);\n if (n <= 8) return;\n\n // advance pointer to align it at 4-byte boundary\n let k: usize = -dest & 3;\n dest += k;\n n -= k;\n n &= -4;\n\n let c32: u32 = -1 / 255 * c;\n\n // fill head/tail up to 28 bytes each in preparation\n dend = dest + n;\n store(dest, c32);\n store(dend - 4, c32);\n if (n <= 8) return;\n store(dest, c32, 4);\n store(dest, c32, 8);\n store(dend - 12, c32);\n store(dend - 8, c32);\n if (n <= 24) return;\n store(dest, c32, 12);\n store(dest, c32, 16);\n store(dest, c32, 20);\n store(dest, c32, 24);\n store(dend - 28, c32);\n store(dend - 24, c32);\n store(dend - 20, c32);\n store(dend - 16, c32);\n\n // align to a multiple of 8\n k = 24 + (dest & 4);\n dest += k;\n n -= k;\n\n // copy 32 bytes each\n let c64: u64 = c32 | (c32 << 32);\n while (n >= 32) {\n store(dest, c64);\n store(dest, c64, 8);\n store(dest, c64, 16);\n store(dest, c64, 24);\n n -= 32;\n dest += 32;\n }\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function memcmp(vl: usize, vr: usize, n: usize): i32 {\n if (vl == vr) return 0;\n if (ASC_SHRINK_LEVEL < 2) {\n if ((vl & 7) == (vr & 7)) {\n while (vl & 7) {\n if (!n) return 0;\n let a = load(vl);\n let b = load(vr);\n if (a != b) return a - b;\n n--; vl++; vr++;\n }\n while (n >= 8) {\n if (load(vl) != load(vr)) break;\n vl += 8;\n vr += 8;\n n -= 8;\n }\n }\n }\n while (n--) {\n let a = load(vl);\n let b = load(vr);\n if (a != b) return a - b;\n vl++; vr++;\n }\n return 0;\n}\n"]} \ No newline at end of file diff --git a/tutorials/assemblyscript/bin/main.debug.wast b/tutorials/assemblyscript/bin/main.debug.wast new file mode 100644 index 000000000..d086f79a0 --- /dev/null +++ b/tutorials/assemblyscript/bin/main.debug.wast @@ -0,0 +1,5391 @@ +(module + (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) + (type $i32_i32_=>_none (func (param i32 i32))) + (type $i32_=>_i32 (func (param i32) (result i32))) + (type $i32_i32_i32_=>_none (func (param i32 i32 i32))) + (type $i32_=>_none (func (param i32))) + (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) + (type $none_=>_none (func)) + (type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32))) + (type $i32_i32_i32_i32_i32_=>_i32 (func (param i32 i32 i32 i32 i32) (result i32))) + (type $i32_i64_i32_=>_none (func (param i32 i64 i32))) + (type $i64_i32_=>_i32 (func (param i64 i32) (result i32))) + (type $i32_i64_i32_i32_=>_none (func (param i32 i64 i32 i32))) + (import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32))) + (import "env" "print_string" (func $~lib/as-warduino/assembly/warduino/_print (param i32 i32))) + (global $~lib/as-warduino/assembly/index/PinVoltage.LOW i32 (i32.const 0)) + (global $~lib/as-warduino/assembly/index/PinVoltage.HIGH i32 (i32.const 1)) + (global $~lib/as-warduino/assembly/index/InterruptMode.CHANGED i32 (i32.const 1)) + (global $~lib/as-warduino/assembly/index/InterruptMode.FALLING i32 (i32.const 2)) + (global $~lib/as-warduino/assembly/index/InterruptMode.RISING i32 (i32.const 3)) + (global $~lib/as-warduino/assembly/index/PinMode.INPUT i32 (i32.const 0)) + (global $~lib/as-warduino/assembly/index/PinMode.OUTPUT i32 (i32.const 2)) + (global $~lib/as-warduino/assembly/index/WiFi.Status.NoShield i32 (i32.const 255)) + (global $~lib/as-warduino/assembly/index/WiFi.Status.Idle i32 (i32.const 0)) + (global $~lib/as-warduino/assembly/index/WiFi.Status.SsidUnavailable i32 (i32.const 1)) + (global $~lib/as-warduino/assembly/index/WiFi.Status.ScanCompleted i32 (i32.const 2)) + (global $~lib/as-warduino/assembly/index/WiFi.Status.Connected i32 (i32.const 3)) + (global $~lib/as-warduino/assembly/index/WiFi.Status.ConnectFailed i32 (i32.const 4)) + (global $~lib/as-warduino/assembly/index/WiFi.Status.ConnectionLost i32 (i32.const 5)) + (global $~lib/as-warduino/assembly/index/WiFi.Status.Disconnected i32 (i32.const 6)) + (global $~lib/as-warduino/assembly/index/MQTT.Status.ConnectionTimeout i32 (i32.const -4)) + (global $~lib/as-warduino/assembly/index/MQTT.Status.ConnectionLost i32 (i32.const -3)) + (global $~lib/as-warduino/assembly/index/MQTT.Status.ConnectFailed i32 (i32.const -2)) + (global $~lib/as-warduino/assembly/index/MQTT.Status.Disconnected i32 (i32.const -1)) + (global $~lib/as-warduino/assembly/index/MQTT.Status.Connected i32 (i32.const 0)) + (global $~lib/as-warduino/assembly/index/MQTT.Status.ConnectBadProtocol i32 (i32.const 1)) + (global $~lib/as-warduino/assembly/index/MQTT.Status.ConnectBadClientId i32 (i32.const 2)) + (global $~lib/as-warduino/assembly/index/MQTT.Status.ConnectUnavailable i32 (i32.const 3)) + (global $~lib/as-warduino/assembly/index/MQTT.Status.ConnectBadCredentials i32 (i32.const 4)) + (global $~lib/as-warduino/assembly/index/MQTT.Status.ConnectUnauthorized i32 (i32.const 5)) + (global $~lib/as-warduino/assembly/index/buffersizeMaximum i32 (i32.const 1000)) + (global $~lib/shared/runtime/Runtime.Stub i32 (i32.const 0)) + (global $~lib/shared/runtime/Runtime.Minimal i32 (i32.const 1)) + (global $~lib/shared/runtime/Runtime.Incremental i32 (i32.const 2)) + (global $~lib/rt/stub/startOffset (mut i32) (i32.const 0)) + (global $~lib/rt/stub/offset (mut i32) (i32.const 0)) + (global $~argumentsLength (mut i32) (i32.const 0)) + (global $~lib/native/ASC_SHRINK_LEVEL i32 (i32.const 0)) + (global $~lib/memory/__heap_base i32 (i32.const 2364)) + (memory $0 1 2) + (data $0 (i32.const 12) "L\00\00\00\00\00\00\00\00\00\00\00\02\00\00\008\00\00\00A\00S\00C\00I\00I\00 \00T\00a\00b\00l\00e\00 \00~\00 \00C\00h\00a\00r\00a\00c\00t\00e\00r\00 \00M\00a\00p\00\n\00\00\00\00\00") + (data $1 (i32.const 92) "<\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00(\00\00\00A\00l\00l\00o\00c\00a\00t\00i\00o\00n\00 \00t\00o\00o\00 \00l\00a\00r\00g\00e\00\00\00\00\00") + (data $2 (i32.const 156) "<\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00s\00t\00u\00b\00.\00t\00s\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") + (data $3 (i32.const 220) "<\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00$\00\00\00U\00n\00p\00a\00i\00r\00e\00d\00 \00s\00u\00r\00r\00o\00g\00a\00t\00e\00\00\00\00\00\00\00\00\00") + (data $4 (i32.const 284) ",\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\1c\00\00\00~\00l\00i\00b\00/\00s\00t\00r\00i\00n\00g\00.\00t\00s\00") + (data $5 (i32.const 332) ",\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\0e\00\00\00,\00 \00d\00e\00c\00:\00 \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") + (data $6 (i32.const 380) "|\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00d\00\00\00t\00o\00S\00t\00r\00i\00n\00g\00(\00)\00 \00r\00a\00d\00i\00x\00 \00a\00r\00g\00u\00m\00e\00n\00t\00 \00m\00u\00s\00t\00 \00b\00e\00 \00b\00e\00t\00w\00e\00e\00n\00 \002\00 \00a\00n\00d\00 \003\006\00\00\00\00\00\00\00\00\00") + (data $7 (i32.const 508) "<\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00&\00\00\00~\00l\00i\00b\00/\00u\00t\00i\00l\00/\00n\00u\00m\00b\00e\00r\00.\00t\00s\00\00\00\00\00\00\00") + (data $8 (i32.const 572) "\1c\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\02\00\00\000\00\00\00\00\00\00\00\00\00\00\00") + (data $9 (i32.const 604) "0\000\000\001\000\002\000\003\000\004\000\005\000\006\000\007\000\008\000\009\001\000\001\001\001\002\001\003\001\004\001\005\001\006\001\007\001\008\001\009\002\000\002\001\002\002\002\003\002\004\002\005\002\006\002\007\002\008\002\009\003\000\003\001\003\002\003\003\003\004\003\005\003\006\003\007\003\008\003\009\004\000\004\001\004\002\004\003\004\004\004\005\004\006\004\007\004\008\004\009\005\000\005\001\005\002\005\003\005\004\005\005\005\006\005\007\005\008\005\009\006\000\006\001\006\002\006\003\006\004\006\005\006\006\006\007\006\008\006\009\007\000\007\001\007\002\007\003\007\004\007\005\007\006\007\007\007\008\007\009\008\000\008\001\008\002\008\003\008\004\008\005\008\006\008\007\008\008\008\009\009\000\009\001\009\002\009\003\009\004\009\005\009\006\009\007\009\008\009\009\00") + (data $10 (i32.const 1004) "\1c\04\00\00\00\00\00\00\00\00\00\00\02\00\00\00\00\04\00\000\000\000\001\000\002\000\003\000\004\000\005\000\006\000\007\000\008\000\009\000\00a\000\00b\000\00c\000\00d\000\00e\000\00f\001\000\001\001\001\002\001\003\001\004\001\005\001\006\001\007\001\008\001\009\001\00a\001\00b\001\00c\001\00d\001\00e\001\00f\002\000\002\001\002\002\002\003\002\004\002\005\002\006\002\007\002\008\002\009\002\00a\002\00b\002\00c\002\00d\002\00e\002\00f\003\000\003\001\003\002\003\003\003\004\003\005\003\006\003\007\003\008\003\009\003\00a\003\00b\003\00c\003\00d\003\00e\003\00f\004\000\004\001\004\002\004\003\004\004\004\005\004\006\004\007\004\008\004\009\004\00a\004\00b\004\00c\004\00d\004\00e\004\00f\005\000\005\001\005\002\005\003\005\004\005\005\005\006\005\007\005\008\005\009\005\00a\005\00b\005\00c\005\00d\005\00e\005\00f\006\000\006\001\006\002\006\003\006\004\006\005\006\006\006\007\006\008\006\009\006\00a\006\00b\006\00c\006\00d\006\00e\006\00f\007\000\007\001\007\002\007\003\007\004\007\005\007\006\007\007\007\008\007\009\007\00a\007\00b\007\00c\007\00d\007\00e\007\00f\008\000\008\001\008\002\008\003\008\004\008\005\008\006\008\007\008\008\008\009\008\00a\008\00b\008\00c\008\00d\008\00e\008\00f\009\000\009\001\009\002\009\003\009\004\009\005\009\006\009\007\009\008\009\009\009\00a\009\00b\009\00c\009\00d\009\00e\009\00f\00a\000\00a\001\00a\002\00a\003\00a\004\00a\005\00a\006\00a\007\00a\008\00a\009\00a\00a\00a\00b\00a\00c\00a\00d\00a\00e\00a\00f\00b\000\00b\001\00b\002\00b\003\00b\004\00b\005\00b\006\00b\007\00b\008\00b\009\00b\00a\00b\00b\00b\00c\00b\00d\00b\00e\00b\00f\00c\000\00c\001\00c\002\00c\003\00c\004\00c\005\00c\006\00c\007\00c\008\00c\009\00c\00a\00c\00b\00c\00c\00c\00d\00c\00e\00c\00f\00d\000\00d\001\00d\002\00d\003\00d\004\00d\005\00d\006\00d\007\00d\008\00d\009\00d\00a\00d\00b\00d\00c\00d\00d\00d\00e\00d\00f\00e\000\00e\001\00e\002\00e\003\00e\004\00e\005\00e\006\00e\007\00e\008\00e\009\00e\00a\00e\00b\00e\00c\00e\00d\00e\00e\00e\00f\00f\000\00f\001\00f\002\00f\003\00f\004\00f\005\00f\006\00f\007\00f\008\00f\009\00f\00a\00f\00b\00f\00c\00f\00d\00f\00e\00f\00f\00\00\00\00\00\00\00\00\00\00\00\00\00") + (data $11 (i32.const 2060) "\\\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00H\00\00\000\001\002\003\004\005\006\007\008\009\00a\00b\00c\00d\00e\00f\00g\00h\00i\00j\00k\00l\00m\00n\00o\00p\00q\00r\00s\00t\00u\00v\00w\00x\00y\00z\00\00\00\00\00") + (data $12 (i32.const 2156) "\1c\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") + (data $13 (i32.const 2188) ",\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\0e\00\00\00,\00 \00h\00e\00x\00:\00 \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") + (data $14 (i32.const 2236) ",\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\0e\00\00\00,\00 \00o\00c\00t\00:\00 \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") + (data $15 (i32.const 2284) ",\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\0e\00\00\00,\00 \00b\00i\00n\00:\00 \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") + (data $16 (i32.const 2332) "\1c\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\02\00\00\00\n\00\00\00\00\00\00\00\00\00\00\00") + (table $0 1 funcref) + (elem $0 (i32.const 1)) + (export "main" (func $main/ascii/main)) + (export "memory" (memory $0)) + (export "table" (table $0)) + (start $~start) + (func $~lib/rt/common/OBJECT#get:rtSize (param $this i32) (result i32) + (i32.load offset=16 + (local.get $this) + ) + ) + (func $~lib/string/String.UTF8.byteLength (param $str i32) (param $nullTerminated i32) (result i32) + (local $strOff i32) + (local $strEnd i32) + (local $bufLen i32) + (local $c1 i32) + ;;@ ~lib/string.ts:672:6 + (local.set $strOff + ;;@ ~lib/string.ts:672:19 + (local.get $str) + ) + ;;@ ~lib/string.ts:673:6 + (local.set $strEnd + ;;@ ~lib/string.ts:673:19 + (i32.add + (local.get $strOff) + ;;@ ~lib/string.ts:673:28 + (call $~lib/rt/common/OBJECT#get:rtSize + ;;@ ~lib/string.ts:673:35 + (i32.sub + ;;@ ~lib/string.ts:673:54 + (local.get $str) + ;;@ ~lib/string.ts:673:79 + (i32.const 20) + ) + ) + ) + ) + ;;@ ~lib/string.ts:674:6 + (local.set $bufLen + ;;@ ~lib/string.ts:674:19 + (i32.ne + (local.get $nullTerminated) + (i32.const 0) + ) + ) + ;;@ ~lib/string.ts:675:6 + (block $while-break|0 + (loop $while-continue|0 + (if + ;;@ ~lib/string.ts:675:13 + (i32.lt_u + (local.get $strOff) + ;;@ ~lib/string.ts:675:22 + (local.get $strEnd) + ) + (block + ;;@ ~lib/string.ts:676:8 + (local.set $c1 + ;;@ ~lib/string.ts:676:17 + (i32.load16_u + ;;@ ~lib/string.ts:676:32 + (local.get $strOff) + ) + ) + ;;@ ~lib/string.ts:677:8 + (if + ;;@ ~lib/string.ts:677:12 + (i32.lt_u + (local.get $c1) + ;;@ ~lib/string.ts:677:17 + (i32.const 128) + ) + (block + ;;@ ~lib/string.ts:679:10 + (if + ;;@ ~lib/string.ts:679:14 + (i32.and + (local.get $nullTerminated) + ;;@ ~lib/string.ts:679:31 + (i32.eqz + ;;@ ~lib/string.ts:679:32 + (local.get $c1) + ) + ) + ;;@ ~lib/string.ts:679:36 + (br $while-break|0) + ) + ;;@ ~lib/string.ts:680:10 + (local.set $bufLen + (i32.add + (local.get $bufLen) + ;;@ ~lib/string.ts:680:20 + (i32.const 1) + ) + ) + ) + ;;@ ~lib/string.ts:681:15 + (if + ;;@ ~lib/string.ts:681:19 + (i32.lt_u + (local.get $c1) + ;;@ ~lib/string.ts:681:24 + (i32.const 2048) + ) + ;;@ ~lib/string.ts:682:10 + (local.set $bufLen + (i32.add + (local.get $bufLen) + ;;@ ~lib/string.ts:682:20 + (i32.const 2) + ) + ) + (block + ;;@ ~lib/string.ts:684:10 + (if + ;;@ ~lib/string.ts:684:14 + (if (result i32) + (i32.eq + ;;@ ~lib/string.ts:684:15 + (i32.and + (local.get $c1) + ;;@ ~lib/string.ts:684:20 + (i32.const 64512) + ) + ;;@ ~lib/string.ts:684:31 + (i32.const 55296) + ) + ;;@ ~lib/string.ts:684:41 + (i32.lt_u + (i32.add + (local.get $strOff) + ;;@ ~lib/string.ts:684:50 + (i32.const 2) + ) + ;;@ ~lib/string.ts:684:54 + (local.get $strEnd) + ) + (i32.const 0) + ) + ;;@ ~lib/string.ts:685:12 + (if + ;;@ ~lib/string.ts:685:16 + (i32.eq + ;;@ ~lib/string.ts:685:17 + (i32.and + (i32.load16_u offset=2 + ;;@ ~lib/string.ts:685:32 + (local.get $strOff) + ) + ;;@ ~lib/string.ts:685:45 + (i32.const 64512) + ) + ;;@ ~lib/string.ts:685:56 + (i32.const 56320) + ) + (block + ;;@ ~lib/string.ts:686:14 + (local.set $bufLen + (i32.add + (local.get $bufLen) + ;;@ ~lib/string.ts:686:24 + (i32.const 4) + ) + ) + ;;@ ~lib/string.ts:686:27 + (local.set $strOff + (i32.add + (local.get $strOff) + ;;@ ~lib/string.ts:686:37 + (i32.const 4) + ) + ) + ;;@ ~lib/string.ts:687:14 + (br $while-continue|0) + ) + ) + ) + ;;@ ~lib/string.ts:690:10 + (local.set $bufLen + (i32.add + (local.get $bufLen) + ;;@ ~lib/string.ts:690:20 + (i32.const 3) + ) + ) + ) + ) + ) + ;;@ ~lib/string.ts:692:8 + (local.set $strOff + (i32.add + (local.get $strOff) + ;;@ ~lib/string.ts:692:18 + (i32.const 2) + ) + ) + (br $while-continue|0) + ) + ) + ) + ) + ;;@ ~lib/string.ts:694:6 + (return + ;;@ ~lib/string.ts:694:13 + (local.get $bufLen) + ) + ) + (func $~lib/rt/stub/maybeGrowMemory (param $newOffset i32) + (local $pagesBefore i32) + (local $maxOffset i32) + (local $pagesNeeded i32) + (local $4 i32) + (local $5 i32) + (local $pagesWanted i32) + ;;@ ~lib/rt/stub.ts:13:2 + (local.set $pagesBefore + ;;@ ~lib/rt/stub.ts:13:20 + (memory.size) + ) + ;;@ ~lib/rt/stub.ts:14:2 + (local.set $maxOffset + ;;@ ~lib/rt/stub.ts:14:18 + (i32.and + ;;@ ~lib/rt/stub.ts:14:19 + (i32.add + ;;@ ~lib/rt/stub.ts:14:20 + (i32.shl + (local.get $pagesBefore) + ;;@ ~lib/rt/stub.ts:14:42 + (i32.const 16) + ) + ;;@ ~lib/rt/stub.ts:14:48 + (i32.const 15) + ) + ;;@ ~lib/rt/stub.ts:14:59 + (i32.xor + ;;@ ~lib/rt/stub.ts:14:60 + (i32.const 15) + (i32.const -1) + ) + ) + ) + ;;@ ~lib/rt/stub.ts:15:2 + (if + ;;@ ~lib/rt/stub.ts:15:6 + (i32.gt_u + (local.get $newOffset) + ;;@ ~lib/rt/stub.ts:15:18 + (local.get $maxOffset) + ) + (block + ;;@ ~lib/rt/stub.ts:16:4 + (local.set $pagesNeeded + ;;@ ~lib/rt/stub.ts:16:22 + (i32.shr_u + ;;@ ~lib/rt/stub.ts:16:29 + (i32.and + ;;@ ~lib/rt/stub.ts:16:30 + (i32.add + (i32.sub + (local.get $newOffset) + ;;@ ~lib/rt/stub.ts:16:42 + (local.get $maxOffset) + ) + ;;@ ~lib/rt/stub.ts:16:54 + (i32.const 65535) + ) + ;;@ ~lib/rt/stub.ts:16:64 + (i32.xor + ;;@ ~lib/rt/stub.ts:16:65 + (i32.const 65535) + (i32.const -1) + ) + ) + ;;@ ~lib/rt/stub.ts:16:77 + (i32.const 16) + ) + ) + ;;@ ~lib/rt/stub.ts:17:4 + (local.set $pagesWanted + ;;@ ~lib/rt/stub.ts:17:22 + (select + (local.tee $4 + ;;@ ~lib/rt/stub.ts:17:26 + (local.get $pagesBefore) + ) + (local.tee $5 + ;;@ ~lib/rt/stub.ts:17:39 + (local.get $pagesNeeded) + ) + (i32.gt_s + (local.get $4) + (local.get $5) + ) + ) + ) + ;;@ ~lib/rt/stub.ts:18:4 + (if + ;;@ ~lib/rt/stub.ts:18:8 + (i32.lt_s + (memory.grow + ;;@ ~lib/rt/stub.ts:18:20 + (local.get $pagesWanted) + ) + ;;@ ~lib/rt/stub.ts:18:35 + (i32.const 0) + ) + ;;@ ~lib/rt/stub.ts:19:6 + (if + ;;@ ~lib/rt/stub.ts:19:10 + (i32.lt_s + (memory.grow + ;;@ ~lib/rt/stub.ts:19:22 + (local.get $pagesNeeded) + ) + ;;@ ~lib/rt/stub.ts:19:37 + (i32.const 0) + ) + ;;@ ~lib/rt/stub.ts:19:40 + (unreachable) + ) + ) + ) + ) + ;;@ ~lib/rt/stub.ts:22:2 + (global.set $~lib/rt/stub/offset + ;;@ ~lib/rt/stub.ts:22:11 + (local.get $newOffset) + ) + ) + (func $~lib/rt/common/BLOCK#set:mmInfo (param $this i32) (param $mmInfo i32) + (i32.store + (local.get $this) + (local.get $mmInfo) + ) + ) + (func $~lib/rt/stub/__alloc (param $size i32) (result i32) + (local $block i32) + (local $ptr i32) + (local $size|3 i32) + (local $payloadSize i32) + ;;@ ~lib/rt/stub.ts:33:2 + (if + ;;@ ~lib/rt/stub.ts:33:6 + (i32.gt_u + (local.get $size) + ;;@ ~lib/rt/stub.ts:33:13 + (i32.const 1073741820) + ) + ;;@ ~lib/rt/stub.ts:33:28 + (block + (call $~lib/builtins/abort + ;;@ ~lib/rt/stub.ts:33:44 + (i32.const 112) + (i32.const 176) + (i32.const 33) + (i32.const 29) + ) + (unreachable) + ) + ) + ;;@ ~lib/rt/stub.ts:34:2 + (local.set $block + ;;@ ~lib/rt/stub.ts:34:14 + (global.get $~lib/rt/stub/offset) + ) + ;;@ ~lib/rt/stub.ts:35:2 + (local.set $ptr + ;;@ ~lib/rt/stub.ts:35:12 + (i32.add + (global.get $~lib/rt/stub/offset) + ;;@ ~lib/rt/stub.ts:35:21 + (i32.const 4) + ) + ) + ;;@ ~lib/rt/stub.ts:36:2 + (local.set $payloadSize + ;;@ ~lib/rt/stub.ts:36:20 + (block $~lib/rt/stub/computeSize|inlined.0 (result i32) + (local.set $size|3 + ;;@ ~lib/rt/stub.ts:36:32 + (local.get $size) + ) + ;;@ ~lib/rt/stub.ts:27:2 + (br $~lib/rt/stub/computeSize|inlined.0 + ;;@ ~lib/rt/stub.ts:27:9 + (i32.sub + ;;@ ~lib/rt/stub.ts:27:10 + (i32.and + ;;@ ~lib/rt/stub.ts:27:11 + (i32.add + (i32.add + (local.get $size|3) + ;;@ ~lib/rt/stub.ts:27:18 + (i32.const 4) + ) + ;;@ ~lib/rt/stub.ts:27:35 + (i32.const 15) + ) + ;;@ ~lib/rt/stub.ts:27:46 + (i32.xor + ;;@ ~lib/rt/stub.ts:27:47 + (i32.const 15) + (i32.const -1) + ) + ) + ;;@ ~lib/rt/stub.ts:27:58 + (i32.const 4) + ) + ) + ) + ) + ;;@ ~lib/rt/stub.ts:37:2 + (call $~lib/rt/stub/maybeGrowMemory + ;;@ ~lib/rt/stub.ts:37:18 + (i32.add + (local.get $ptr) + ;;@ ~lib/rt/stub.ts:37:24 + (local.get $payloadSize) + ) + ) + ;;@ ~lib/rt/stub.ts:38:2 + (call $~lib/rt/common/BLOCK#set:mmInfo + (local.get $block) + ;;@ ~lib/rt/stub.ts:38:17 + (local.get $payloadSize) + ) + ;;@ ~lib/rt/stub.ts:39:2 + (return + ;;@ ~lib/rt/stub.ts:39:9 + (local.get $ptr) + ) + ) + (func $~lib/rt/common/OBJECT#set:gcInfo (param $this i32) (param $gcInfo i32) + (i32.store offset=4 + (local.get $this) + (local.get $gcInfo) + ) + ) + (func $~lib/rt/common/OBJECT#set:gcInfo2 (param $this i32) (param $gcInfo2 i32) + (i32.store offset=8 + (local.get $this) + (local.get $gcInfo2) + ) + ) + (func $~lib/rt/common/OBJECT#set:rtId (param $this i32) (param $rtId i32) + (i32.store offset=12 + (local.get $this) + (local.get $rtId) + ) + ) + (func $~lib/rt/common/OBJECT#set:rtSize (param $this i32) (param $rtSize i32) + (i32.store offset=16 + (local.get $this) + (local.get $rtSize) + ) + ) + (func $~lib/rt/stub/__new (param $size i32) (param $id i32) (result i32) + (local $ptr i32) + (local $object i32) + ;;@ ~lib/rt/stub.ts:86:2 + (if + ;;@ ~lib/rt/stub.ts:86:6 + (i32.gt_u + (local.get $size) + ;;@ ~lib/rt/stub.ts:86:13 + (i32.const 1073741804) + ) + ;;@ ~lib/rt/stub.ts:86:29 + (block + (call $~lib/builtins/abort + ;;@ ~lib/rt/stub.ts:86:45 + (i32.const 112) + (i32.const 176) + (i32.const 86) + (i32.const 30) + ) + (unreachable) + ) + ) + ;;@ ~lib/rt/stub.ts:87:2 + (local.set $ptr + ;;@ ~lib/rt/stub.ts:87:12 + (call $~lib/rt/stub/__alloc + ;;@ ~lib/rt/stub.ts:87:20 + (i32.add + (i32.const 16) + ;;@ ~lib/rt/stub.ts:87:38 + (local.get $size) + ) + ) + ) + ;;@ ~lib/rt/stub.ts:88:2 + (local.set $object + ;;@ ~lib/rt/stub.ts:88:15 + (i32.sub + ;;@ ~lib/rt/stub.ts:88:34 + (local.get $ptr) + ;;@ ~lib/rt/stub.ts:88:40 + (i32.const 4) + ) + ) + ;;@ ~lib/rt/stub.ts:89:2 + (call $~lib/rt/common/OBJECT#set:gcInfo + (local.get $object) + ;;@ ~lib/rt/stub.ts:89:18 + (i32.const 0) + ) + ;;@ ~lib/rt/stub.ts:90:2 + (call $~lib/rt/common/OBJECT#set:gcInfo2 + (local.get $object) + ;;@ ~lib/rt/stub.ts:90:19 + (i32.const 0) + ) + ;;@ ~lib/rt/stub.ts:91:2 + (call $~lib/rt/common/OBJECT#set:rtId + (local.get $object) + ;;@ ~lib/rt/stub.ts:91:16 + (local.get $id) + ) + ;;@ ~lib/rt/stub.ts:92:2 + (call $~lib/rt/common/OBJECT#set:rtSize + (local.get $object) + ;;@ ~lib/rt/stub.ts:92:18 + (local.get $size) + ) + ;;@ ~lib/rt/stub.ts:93:2 + (return + ;;@ ~lib/rt/stub.ts:93:9 + (i32.add + (local.get $ptr) + ;;@ ~lib/rt/stub.ts:93:15 + (i32.const 16) + ) + ) + ) + (func $~lib/string/String#get:length (param $this i32) (result i32) + ;;@ ~lib/string.ts:51:4 + (return + ;;@ ~lib/string.ts:51:11 + (i32.shr_u + (call $~lib/rt/common/OBJECT#get:rtSize + (i32.sub + ;;@ ~lib/string.ts:51:30 + (local.get $this) + ;;@ ~lib/string.ts:51:56 + (i32.const 20) + ) + ) + ;;@ ~lib/string.ts:51:82 + (i32.const 1) + ) + ) + ) + (func $~lib/string/String.UTF8.encodeUnsafe (param $str i32) (param $len i32) (param $buf i32) (param $nullTerminated i32) (param $errorMode i32) (result i32) + (local $strEnd i32) + (local $bufOff i32) + (local $c1 i32) + (local $b0 i32) + (local $b1 i32) + (local $c2 i32) + (local $b0|11 i32) + (local $b1|12 i32) + (local $b2 i32) + (local $b3 i32) + (local $b0|15 i32) + (local $b1|16 i32) + (local $b2|17 i32) + (local $18 i32) + ;;@ ~lib/string.ts:706:6 + (local.set $strEnd + ;;@ ~lib/string.ts:706:19 + (i32.add + (local.get $str) + ;;@ ~lib/string.ts:706:26 + (i32.shl + (local.get $len) + ;;@ ~lib/string.ts:706:40 + (i32.const 1) + ) + ) + ) + ;;@ ~lib/string.ts:707:6 + (local.set $bufOff + ;;@ ~lib/string.ts:707:19 + (local.get $buf) + ) + ;;@ ~lib/string.ts:708:6 + (block $while-break|0 + (loop $while-continue|0 + (if + ;;@ ~lib/string.ts:708:13 + (i32.lt_u + (local.get $str) + ;;@ ~lib/string.ts:708:19 + (local.get $strEnd) + ) + (block + ;;@ ~lib/string.ts:709:8 + (local.set $c1 + ;;@ ~lib/string.ts:709:17 + (i32.load16_u + ;;@ ~lib/string.ts:709:32 + (local.get $str) + ) + ) + ;;@ ~lib/string.ts:710:8 + (if + ;;@ ~lib/string.ts:710:12 + (i32.lt_u + (local.get $c1) + ;;@ ~lib/string.ts:710:17 + (i32.const 128) + ) + (block + ;;@ ~lib/string.ts:711:10 + (i32.store8 + ;;@ ~lib/string.ts:711:20 + (local.get $bufOff) + ;;@ ~lib/string.ts:711:28 + (local.get $c1) + ) + ;;@ ~lib/string.ts:712:10 + (local.set $bufOff + (i32.add + (local.get $bufOff) + (i32.const 1) + ) + ) + ;;@ ~lib/string.ts:714:10 + (if + ;;@ ~lib/string.ts:714:14 + (i32.and + (local.get $nullTerminated) + ;;@ ~lib/string.ts:714:31 + (i32.eqz + ;;@ ~lib/string.ts:714:32 + (local.get $c1) + ) + ) + ;;@ ~lib/string.ts:714:36 + (return + ;;@ ~lib/string.ts:714:43 + (i32.sub + (local.get $bufOff) + ;;@ ~lib/string.ts:714:52 + (local.get $buf) + ) + ) + ) + ) + ;;@ ~lib/string.ts:715:15 + (if + ;;@ ~lib/string.ts:715:19 + (i32.lt_u + (local.get $c1) + ;;@ ~lib/string.ts:715:24 + (i32.const 2048) + ) + (block + ;;@ ~lib/string.ts:716:10 + (local.set $b0 + ;;@ ~lib/string.ts:716:19 + (i32.or + (i32.shr_u + (local.get $c1) + ;;@ ~lib/string.ts:716:25 + (i32.const 6) + ) + ;;@ ~lib/string.ts:716:29 + (i32.const 192) + ) + ) + ;;@ ~lib/string.ts:717:10 + (local.set $b1 + ;;@ ~lib/string.ts:717:19 + (i32.or + (i32.and + (local.get $c1) + ;;@ ~lib/string.ts:717:24 + (i32.const 63) + ) + ;;@ ~lib/string.ts:717:29 + (i32.const 128) + ) + ) + ;;@ ~lib/string.ts:718:10 + (i32.store16 + ;;@ ~lib/string.ts:718:21 + (local.get $bufOff) + ;;@ ~lib/string.ts:718:29 + (i32.or + (i32.shl + (local.get $b1) + ;;@ ~lib/string.ts:718:35 + (i32.const 8) + ) + ;;@ ~lib/string.ts:718:39 + (local.get $b0) + ) + ) + ;;@ ~lib/string.ts:719:10 + (local.set $bufOff + (i32.add + (local.get $bufOff) + ;;@ ~lib/string.ts:719:20 + (i32.const 2) + ) + ) + ) + (block + ;;@ ~lib/string.ts:727:10 + (if + ;;@ ~lib/string.ts:727:14 + (i32.eq + ;;@ ~lib/string.ts:727:15 + (i32.and + (local.get $c1) + ;;@ ~lib/string.ts:727:20 + (i32.const 63488) + ) + ;;@ ~lib/string.ts:727:31 + (i32.const 55296) + ) + (block + ;;@ ~lib/string.ts:728:12 + (if + ;;@ ~lib/string.ts:728:16 + (if (result i32) + (i32.lt_u + (local.get $c1) + ;;@ ~lib/string.ts:728:21 + (i32.const 56320) + ) + ;;@ ~lib/string.ts:728:31 + (i32.lt_u + (i32.add + (local.get $str) + ;;@ ~lib/string.ts:728:37 + (i32.const 2) + ) + ;;@ ~lib/string.ts:728:41 + (local.get $strEnd) + ) + (i32.const 0) + ) + (block + ;;@ ~lib/string.ts:729:14 + (local.set $c2 + ;;@ ~lib/string.ts:729:23 + (i32.load16_u offset=2 + ;;@ ~lib/string.ts:729:38 + (local.get $str) + ) + ) + ;;@ ~lib/string.ts:730:14 + (if + ;;@ ~lib/string.ts:730:18 + (i32.eq + ;;@ ~lib/string.ts:730:19 + (i32.and + (local.get $c2) + ;;@ ~lib/string.ts:730:24 + (i32.const 64512) + ) + ;;@ ~lib/string.ts:730:35 + (i32.const 56320) + ) + (block + ;;@ ~lib/string.ts:731:16 + (local.set $c1 + ;;@ ~lib/string.ts:731:21 + (i32.or + (i32.add + (i32.const 65536) + ;;@ ~lib/string.ts:731:32 + (i32.shl + ;;@ ~lib/string.ts:731:33 + (i32.and + (local.get $c1) + ;;@ ~lib/string.ts:731:38 + (i32.const 1023) + ) + ;;@ ~lib/string.ts:731:49 + (i32.const 10) + ) + ) + ;;@ ~lib/string.ts:731:56 + (i32.and + (local.get $c2) + ;;@ ~lib/string.ts:731:61 + (i32.const 1023) + ) + ) + ) + ;;@ ~lib/string.ts:732:16 + (local.set $b0|11 + ;;@ ~lib/string.ts:732:25 + (i32.or + (i32.shr_u + (local.get $c1) + ;;@ ~lib/string.ts:732:31 + (i32.const 18) + ) + ;;@ ~lib/string.ts:732:36 + (i32.const 240) + ) + ) + ;;@ ~lib/string.ts:733:16 + (local.set $b1|12 + ;;@ ~lib/string.ts:733:25 + (i32.or + (i32.and + (i32.shr_u + (local.get $c1) + ;;@ ~lib/string.ts:733:31 + (i32.const 12) + ) + ;;@ ~lib/string.ts:733:36 + (i32.const 63) + ) + ;;@ ~lib/string.ts:733:41 + (i32.const 128) + ) + ) + ;;@ ~lib/string.ts:734:16 + (local.set $b2 + ;;@ ~lib/string.ts:734:25 + (i32.or + (i32.and + (i32.shr_u + (local.get $c1) + ;;@ ~lib/string.ts:734:31 + (i32.const 6) + ) + ;;@ ~lib/string.ts:734:36 + (i32.const 63) + ) + ;;@ ~lib/string.ts:734:41 + (i32.const 128) + ) + ) + ;;@ ~lib/string.ts:735:16 + (local.set $b3 + ;;@ ~lib/string.ts:735:25 + (i32.or + (i32.and + (local.get $c1) + ;;@ ~lib/string.ts:735:36 + (i32.const 63) + ) + ;;@ ~lib/string.ts:735:41 + (i32.const 128) + ) + ) + ;;@ ~lib/string.ts:736:16 + (i32.store + ;;@ ~lib/string.ts:736:27 + (local.get $bufOff) + ;;@ ~lib/string.ts:736:35 + (i32.or + (i32.or + (i32.or + (i32.shl + (local.get $b3) + ;;@ ~lib/string.ts:736:41 + (i32.const 24) + ) + ;;@ ~lib/string.ts:736:46 + (i32.shl + (local.get $b2) + ;;@ ~lib/string.ts:736:52 + (i32.const 16) + ) + ) + ;;@ ~lib/string.ts:736:57 + (i32.shl + (local.get $b1|12) + ;;@ ~lib/string.ts:736:63 + (i32.const 8) + ) + ) + ;;@ ~lib/string.ts:736:67 + (local.get $b0|11) + ) + ) + ;;@ ~lib/string.ts:737:16 + (local.set $bufOff + (i32.add + (local.get $bufOff) + ;;@ ~lib/string.ts:737:26 + (i32.const 4) + ) + ) + ;;@ ~lib/string.ts:737:29 + (local.set $str + (i32.add + (local.get $str) + ;;@ ~lib/string.ts:737:36 + (i32.const 4) + ) + ) + ;;@ ~lib/string.ts:738:16 + (br $while-continue|0) + ) + ) + ) + ) + ;;@ ~lib/string.ts:741:12 + (if + ;;@ ~lib/string.ts:741:16 + (i32.ne + (local.get $errorMode) + ;;@ ~lib/string.ts:741:29 + (i32.const 0) + ) + (block + ;;@ ~lib/string.ts:742:14 + (if + ;;@ ~lib/string.ts:742:18 + (i32.eq + (local.get $errorMode) + ;;@ ~lib/string.ts:742:31 + (i32.const 2) + ) + ;;@ ~lib/string.ts:742:48 + (block + (call $~lib/builtins/abort + ;;@ ~lib/string.ts:742:64 + (i32.const 240) + (i32.const 304) + (i32.const 742) + (i32.const 49) + ) + (unreachable) + ) + ) + ;;@ ~lib/string.ts:743:14 + (local.set $c1 + ;;@ ~lib/string.ts:743:19 + (i32.const 65533) + ) + ) + ) + ) + ) + ;;@ ~lib/string.ts:746:10 + (local.set $b0|15 + ;;@ ~lib/string.ts:746:19 + (i32.or + (i32.shr_u + (local.get $c1) + ;;@ ~lib/string.ts:746:25 + (i32.const 12) + ) + ;;@ ~lib/string.ts:746:30 + (i32.const 224) + ) + ) + ;;@ ~lib/string.ts:747:10 + (local.set $b1|16 + ;;@ ~lib/string.ts:747:19 + (i32.or + (i32.and + (i32.shr_u + (local.get $c1) + ;;@ ~lib/string.ts:747:25 + (i32.const 6) + ) + ;;@ ~lib/string.ts:747:30 + (i32.const 63) + ) + ;;@ ~lib/string.ts:747:35 + (i32.const 128) + ) + ) + ;;@ ~lib/string.ts:748:10 + (local.set $b2|17 + ;;@ ~lib/string.ts:748:19 + (i32.or + (i32.and + (local.get $c1) + ;;@ ~lib/string.ts:748:30 + (i32.const 63) + ) + ;;@ ~lib/string.ts:748:35 + (i32.const 128) + ) + ) + ;;@ ~lib/string.ts:749:10 + (i32.store16 + ;;@ ~lib/string.ts:749:21 + (local.get $bufOff) + ;;@ ~lib/string.ts:749:29 + (i32.or + (i32.shl + (local.get $b1|16) + ;;@ ~lib/string.ts:749:35 + (i32.const 8) + ) + ;;@ ~lib/string.ts:749:39 + (local.get $b0|15) + ) + ) + ;;@ ~lib/string.ts:750:10 + (i32.store8 offset=2 + ;;@ ~lib/string.ts:750:20 + (local.get $bufOff) + ;;@ ~lib/string.ts:750:28 + (local.get $b2|17) + ) + ;;@ ~lib/string.ts:751:10 + (local.set $bufOff + (i32.add + (local.get $bufOff) + ;;@ ~lib/string.ts:751:20 + (i32.const 3) + ) + ) + ) + ) + ) + ;;@ ~lib/string.ts:753:8 + (local.set $str + (i32.add + (local.get $str) + ;;@ ~lib/string.ts:753:15 + (i32.const 2) + ) + ) + (br $while-continue|0) + ) + ) + ) + ) + ;;@ ~lib/string.ts:755:6 + (if + ;;@ ~lib/string.ts:755:10 + (local.get $nullTerminated) + ;;@ ~lib/string.ts:756:8 + (i32.store8 + ;;@ ~lib/string.ts:756:18 + (block (result i32) + (local.set $bufOff + (i32.add + (local.tee $18 + (local.get $bufOff) + ) + (i32.const 1) + ) + ) + (local.get $18) + ) + ;;@ ~lib/string.ts:756:28 + (i32.const 0) + ) + ) + ;;@ ~lib/string.ts:758:6 + (return + ;;@ ~lib/string.ts:758:13 + (i32.sub + (local.get $bufOff) + ;;@ ~lib/string.ts:758:22 + (local.get $buf) + ) + ) + ) + (func $~lib/string/String.UTF8.encode (param $str i32) (param $nullTerminated i32) (param $errorMode i32) (result i32) + (local $buf i32) + ;;@ ~lib/string.ts:698:6 + (local.set $buf + ;;@ ~lib/string.ts:698:16 + (call $~lib/rt/stub/__new + ;;@ ~lib/string.ts:698:46 + (call $~lib/string/String.UTF8.byteLength + ;;@ ~lib/string.ts:698:64 + (local.get $str) + ;;@ ~lib/string.ts:698:69 + (local.get $nullTerminated) + ) + ;;@ ~lib/string.ts:698:86 + (i32.const 1) + ) + ) + ;;@ ~lib/string.ts:699:6 + (drop + (call $~lib/string/String.UTF8.encodeUnsafe + ;;@ ~lib/string.ts:699:19 + (local.get $str) + ;;@ ~lib/string.ts:699:43 + (call $~lib/string/String#get:length + (local.get $str) + ) + ;;@ ~lib/string.ts:699:55 + (local.get $buf) + ;;@ ~lib/string.ts:699:79 + (local.get $nullTerminated) + ;;@ ~lib/string.ts:699:95 + (local.get $errorMode) + ) + ) + ;;@ ~lib/string.ts:700:6 + (return + ;;@ ~lib/string.ts:700:13 + (local.get $buf) + ) + ) + (func $~lib/string/String.UTF8.encode@varargs (param $str i32) (param $nullTerminated i32) (param $errorMode i32) (result i32) + (block $2of2 + (block $1of2 + (block $0of2 + (block $outOfRange + (br_table $0of2 $1of2 $2of2 $outOfRange + (i32.sub + (global.get $~argumentsLength) + (i32.const 1) + ) + ) + ) + (unreachable) + ) + (local.set $nullTerminated + ;;@ ~lib/string.ts:697:63 + (i32.const 0) + ) + ) + (local.set $errorMode + ;;@ ~lib/string.ts:697:93 + (i32.const 0) + ) + ) + (call $~lib/string/String.UTF8.encode + (local.get $str) + (local.get $nullTerminated) + (local.get $errorMode) + ) + ) + (func $~lib/as-warduino/assembly/index/print (param $text i32) + ;;@ ~lib/as-warduino/assembly/index.ts:119:4 + (call $~lib/as-warduino/assembly/warduino/_print + ;;@ ~lib/as-warduino/assembly/index.ts:119:16 + (call $~lib/string/String.UTF8.encode@varargs + ;;@ ~lib/as-warduino/assembly/index.ts:119:35 + (local.get $text) + ;;@ ~lib/as-warduino/assembly/index.ts:119:41 + (i32.const 1) + (block (result i32) + (global.set $~argumentsLength + (i32.const 2) + ) + (i32.const 0) + ) + ) + ;;@ ~lib/as-warduino/assembly/index.ts:119:48 + (call $~lib/string/String.UTF8.byteLength + ;;@ ~lib/as-warduino/assembly/index.ts:119:71 + (local.get $text) + ;;@ ~lib/as-warduino/assembly/index.ts:119:77 + (i32.const 1) + ) + ) + ) + (func $~lib/string/String.fromCharCode (param $unit i32) (param $surr i32) (result i32) + (local $hasSur i32) + (local $out i32) + ;;@ ~lib/string.ts:15:4 + (local.set $hasSur + ;;@ ~lib/string.ts:15:17 + (i32.gt_s + (local.get $surr) + ;;@ ~lib/string.ts:15:24 + (i32.const 0) + ) + ) + ;;@ ~lib/string.ts:16:4 + (local.set $out + ;;@ ~lib/string.ts:16:14 + (call $~lib/rt/stub/__new + ;;@ ~lib/string.ts:16:39 + (i32.shl + (i32.const 2) + ;;@ ~lib/string.ts:16:44 + (local.get $hasSur) + ) + ;;@ ~lib/string.ts:16:57 + (i32.const 2) + ) + ) + ;;@ ~lib/string.ts:17:4 + (i32.store16 + ;;@ ~lib/string.ts:17:15 + (local.get $out) + ;;@ ~lib/string.ts:17:39 + (local.get $unit) + ) + ;;@ ~lib/string.ts:18:4 + (if + ;;@ ~lib/string.ts:18:8 + (local.get $hasSur) + ;;@ ~lib/string.ts:18:16 + (i32.store16 offset=2 + ;;@ ~lib/string.ts:18:27 + (local.get $out) + ;;@ ~lib/string.ts:18:51 + (local.get $surr) + ) + ) + ;;@ ~lib/string.ts:19:4 + (return + ;;@ ~lib/string.ts:19:11 + (local.get $out) + ) + ) + (func $~lib/string/String.fromCharCode@varargs (param $unit i32) (param $surr i32) (result i32) + (block $1of1 + (block $0of1 + (block $outOfRange + (br_table $0of1 $1of1 $outOfRange + (i32.sub + (global.get $~argumentsLength) + (i32.const 1) + ) + ) + ) + (unreachable) + ) + (local.set $surr + ;;@ ~lib/string.ts:14:45 + (i32.const -1) + ) + ) + (call $~lib/string/String.fromCharCode + (local.get $unit) + (local.get $surr) + ) + ) + (func $~lib/util/number/decimalCount32 (param $value i32) (result i32) + ;;@ ~lib/util/number.ts:134:2 + (if + ;;@ ~lib/util/number.ts:134:6 + (i32.lt_u + (local.get $value) + ;;@ ~lib/util/number.ts:134:14 + (i32.const 100000) + ) + ;;@ ~lib/util/number.ts:135:4 + (if + ;;@ ~lib/util/number.ts:135:8 + (i32.lt_u + (local.get $value) + ;;@ ~lib/util/number.ts:135:16 + (i32.const 100) + ) + ;;@ ~lib/util/number.ts:136:6 + (return + ;;@ ~lib/util/number.ts:136:13 + (i32.add + (i32.const 1) + ;;@ ~lib/util/number.ts:136:17 + (i32.ge_u + ;;@ ~lib/util/number.ts:136:21 + (local.get $value) + ;;@ ~lib/util/number.ts:136:30 + (i32.const 10) + ) + ) + ) + ;;@ ~lib/util/number.ts:138:6 + (return + ;;@ ~lib/util/number.ts:138:13 + (i32.add + (i32.add + (i32.const 3) + ;;@ ~lib/util/number.ts:138:17 + (i32.ge_u + ;;@ ~lib/util/number.ts:138:21 + (local.get $value) + ;;@ ~lib/util/number.ts:138:30 + (i32.const 10000) + ) + ) + ;;@ ~lib/util/number.ts:138:39 + (i32.ge_u + ;;@ ~lib/util/number.ts:138:43 + (local.get $value) + ;;@ ~lib/util/number.ts:138:52 + (i32.const 1000) + ) + ) + ) + ) + ;;@ ~lib/util/number.ts:141:4 + (if + ;;@ ~lib/util/number.ts:141:8 + (i32.lt_u + (local.get $value) + ;;@ ~lib/util/number.ts:141:16 + (i32.const 10000000) + ) + ;;@ ~lib/util/number.ts:142:6 + (return + ;;@ ~lib/util/number.ts:142:13 + (i32.add + (i32.const 6) + ;;@ ~lib/util/number.ts:142:17 + (i32.ge_u + ;;@ ~lib/util/number.ts:142:21 + (local.get $value) + ;;@ ~lib/util/number.ts:142:30 + (i32.const 1000000) + ) + ) + ) + ;;@ ~lib/util/number.ts:144:6 + (return + ;;@ ~lib/util/number.ts:144:13 + (i32.add + (i32.add + (i32.const 8) + ;;@ ~lib/util/number.ts:144:17 + (i32.ge_u + ;;@ ~lib/util/number.ts:144:21 + (local.get $value) + ;;@ ~lib/util/number.ts:144:30 + (i32.const 1000000000) + ) + ) + ;;@ ~lib/util/number.ts:144:44 + (i32.ge_u + ;;@ ~lib/util/number.ts:144:48 + (local.get $value) + ;;@ ~lib/util/number.ts:144:57 + (i32.const 100000000) + ) + ) + ) + ) + ) + ) + (func $~lib/util/number/utoa32_dec_lut (param $buffer i32) (param $num i32) (param $offset i32) + (local $t i32) + (local $r i32) + (local $d1 i32) + (local $d2 i32) + (local $digits1 i64) + (local $digits2 i64) + (local $t|9 i32) + (local $d1|10 i32) + (local $digits i32) + (local $digits|12 i32) + (local $digit i32) + ;;@ ~lib/util/number.ts:185:2 + (block $while-break|0 + (loop $while-continue|0 + (if + ;;@ ~lib/util/number.ts:185:9 + (i32.ge_u + (local.get $num) + ;;@ ~lib/util/number.ts:185:16 + (i32.const 10000) + ) + (block + ;;@ ~lib/util/number.ts:187:4 + (local.set $t + ;;@ ~lib/util/number.ts:187:12 + (i32.div_u + (local.get $num) + ;;@ ~lib/util/number.ts:187:18 + (i32.const 10000) + ) + ) + ;;@ ~lib/util/number.ts:188:4 + (local.set $r + ;;@ ~lib/util/number.ts:188:12 + (i32.rem_u + (local.get $num) + ;;@ ~lib/util/number.ts:188:18 + (i32.const 10000) + ) + ) + ;;@ ~lib/util/number.ts:189:4 + (local.set $num + ;;@ ~lib/util/number.ts:189:10 + (local.get $t) + ) + ;;@ ~lib/util/number.ts:191:4 + (local.set $d1 + ;;@ ~lib/util/number.ts:191:13 + (i32.div_u + (local.get $r) + ;;@ ~lib/util/number.ts:191:17 + (i32.const 100) + ) + ) + ;;@ ~lib/util/number.ts:192:4 + (local.set $d2 + ;;@ ~lib/util/number.ts:192:13 + (i32.rem_u + (local.get $r) + ;;@ ~lib/util/number.ts:192:17 + (i32.const 100) + ) + ) + ;;@ ~lib/util/number.ts:194:4 + (local.set $digits1 + ;;@ ~lib/util/number.ts:194:18 + (i64.load32_u + ;;@ ~lib/util/number.ts:194:33 + (i32.add + (i32.const 604) + ;;@ ~lib/util/number.ts:194:43 + (i32.shl + (local.get $d1) + ;;@ ~lib/util/number.ts:194:56 + (i32.const 2) + ) + ) + ) + ) + ;;@ ~lib/util/number.ts:195:4 + (local.set $digits2 + ;;@ ~lib/util/number.ts:195:18 + (i64.load32_u + ;;@ ~lib/util/number.ts:195:33 + (i32.add + (i32.const 604) + ;;@ ~lib/util/number.ts:195:43 + (i32.shl + (local.get $d2) + ;;@ ~lib/util/number.ts:195:56 + (i32.const 2) + ) + ) + ) + ) + ;;@ ~lib/util/number.ts:197:4 + (local.set $offset + (i32.sub + (local.get $offset) + ;;@ ~lib/util/number.ts:197:14 + (i32.const 4) + ) + ) + ;;@ ~lib/util/number.ts:198:4 + (i64.store + ;;@ ~lib/util/number.ts:198:15 + (i32.add + (local.get $buffer) + ;;@ ~lib/util/number.ts:198:25 + (i32.shl + (local.get $offset) + ;;@ ~lib/util/number.ts:198:35 + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:198:39 + (i64.or + (local.get $digits1) + ;;@ ~lib/util/number.ts:198:50 + (i64.shl + (local.get $digits2) + ;;@ ~lib/util/number.ts:198:61 + (i64.const 32) + ) + ) + ) + (br $while-continue|0) + ) + ) + ) + ) + ;;@ ~lib/util/number.ts:201:2 + (if + ;;@ ~lib/util/number.ts:201:6 + (i32.ge_u + (local.get $num) + ;;@ ~lib/util/number.ts:201:13 + (i32.const 100) + ) + (block + ;;@ ~lib/util/number.ts:202:4 + (local.set $t|9 + ;;@ ~lib/util/number.ts:202:13 + (i32.div_u + (local.get $num) + ;;@ ~lib/util/number.ts:202:19 + (i32.const 100) + ) + ) + ;;@ ~lib/util/number.ts:203:4 + (local.set $d1|10 + ;;@ ~lib/util/number.ts:203:13 + (i32.rem_u + (local.get $num) + ;;@ ~lib/util/number.ts:203:19 + (i32.const 100) + ) + ) + ;;@ ~lib/util/number.ts:204:4 + (local.set $num + ;;@ ~lib/util/number.ts:204:10 + (local.get $t|9) + ) + ;;@ ~lib/util/number.ts:205:4 + (local.set $offset + (i32.sub + (local.get $offset) + ;;@ ~lib/util/number.ts:205:14 + (i32.const 2) + ) + ) + ;;@ ~lib/util/number.ts:206:4 + (local.set $digits + ;;@ ~lib/util/number.ts:206:17 + (i32.load + ;;@ ~lib/util/number.ts:206:27 + (i32.add + (i32.const 604) + ;;@ ~lib/util/number.ts:206:37 + (i32.shl + (local.get $d1|10) + ;;@ ~lib/util/number.ts:206:50 + (i32.const 2) + ) + ) + ) + ) + ;;@ ~lib/util/number.ts:207:4 + (i32.store + ;;@ ~lib/util/number.ts:207:15 + (i32.add + (local.get $buffer) + ;;@ ~lib/util/number.ts:207:25 + (i32.shl + (local.get $offset) + ;;@ ~lib/util/number.ts:207:35 + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:207:39 + (local.get $digits) + ) + ) + ) + ;;@ ~lib/util/number.ts:210:2 + (if + ;;@ ~lib/util/number.ts:210:6 + (i32.ge_u + (local.get $num) + ;;@ ~lib/util/number.ts:210:13 + (i32.const 10) + ) + (block + ;;@ ~lib/util/number.ts:211:4 + (local.set $offset + (i32.sub + (local.get $offset) + ;;@ ~lib/util/number.ts:211:14 + (i32.const 2) + ) + ) + ;;@ ~lib/util/number.ts:212:4 + (local.set $digits|12 + ;;@ ~lib/util/number.ts:212:17 + (i32.load + ;;@ ~lib/util/number.ts:212:27 + (i32.add + (i32.const 604) + ;;@ ~lib/util/number.ts:212:37 + (i32.shl + (local.get $num) + ;;@ ~lib/util/number.ts:212:51 + (i32.const 2) + ) + ) + ) + ) + ;;@ ~lib/util/number.ts:213:4 + (i32.store + ;;@ ~lib/util/number.ts:213:15 + (i32.add + (local.get $buffer) + ;;@ ~lib/util/number.ts:213:25 + (i32.shl + (local.get $offset) + ;;@ ~lib/util/number.ts:213:35 + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:213:39 + (local.get $digits|12) + ) + ) + (block + ;;@ ~lib/util/number.ts:215:4 + (local.set $offset + (i32.sub + (local.get $offset) + ;;@ ~lib/util/number.ts:215:14 + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:216:4 + (local.set $digit + ;;@ ~lib/util/number.ts:216:16 + (i32.add + (i32.const 48) + ;;@ ~lib/util/number.ts:216:30 + (local.get $num) + ) + ) + ;;@ ~lib/util/number.ts:217:4 + (i32.store16 + ;;@ ~lib/util/number.ts:217:15 + (i32.add + (local.get $buffer) + ;;@ ~lib/util/number.ts:217:25 + (i32.shl + (local.get $offset) + ;;@ ~lib/util/number.ts:217:35 + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:217:39 + (local.get $digit) + ) + ) + ) + ) + (func $~lib/util/number/utoa_hex_lut (param $buffer i32) (param $num i64) (param $offset i32) + ;;@ ~lib/util/number.ts:253:2 + (block $while-break|0 + (loop $while-continue|0 + (if + ;;@ ~lib/util/number.ts:253:9 + (i32.ge_u + (local.get $offset) + ;;@ ~lib/util/number.ts:253:19 + (i32.const 2) + ) + (block + ;;@ ~lib/util/number.ts:254:4 + (local.set $offset + (i32.sub + (local.get $offset) + ;;@ ~lib/util/number.ts:254:14 + (i32.const 2) + ) + ) + ;;@ ~lib/util/number.ts:255:4 + (i32.store + ;;@ ~lib/util/number.ts:256:6 + (i32.add + (local.get $buffer) + ;;@ ~lib/util/number.ts:256:16 + (i32.shl + (local.get $offset) + ;;@ ~lib/util/number.ts:256:26 + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:257:6 + (i32.load + ;;@ ~lib/util/number.ts:257:16 + (i32.add + (i32.const 1024) + ;;@ ~lib/util/number.ts:257:23 + (i32.shl + ;;@ ~lib/util/number.ts:257:24 + (i32.and + (i32.wrap_i64 + (local.get $num) + ) + ;;@ ~lib/util/number.ts:257:37 + (i32.const 255) + ) + ;;@ ~lib/util/number.ts:257:46 + (i32.const 2) + ) + ) + ) + ) + ;;@ ~lib/util/number.ts:259:4 + (local.set $num + (i64.shr_u + (local.get $num) + ;;@ ~lib/util/number.ts:259:12 + (i64.const 8) + ) + ) + (br $while-continue|0) + ) + ) + ) + ) + ;;@ ~lib/util/number.ts:261:2 + (if + ;;@ ~lib/util/number.ts:261:6 + (i32.and + (local.get $offset) + ;;@ ~lib/util/number.ts:261:15 + (i32.const 1) + ) + ;;@ ~lib/util/number.ts:262:4 + (i32.store16 + ;;@ ~lib/util/number.ts:262:15 + (local.get $buffer) + ;;@ ~lib/util/number.ts:262:23 + (i32.load16_u + ;;@ ~lib/util/number.ts:262:33 + (i32.add + (i32.const 1024) + ;;@ ~lib/util/number.ts:262:40 + (i32.shl + (i32.wrap_i64 + (local.get $num) + ) + ;;@ ~lib/util/number.ts:262:54 + (i32.const 6) + ) + ) + ) + ) + ) + ) + (func $~lib/util/number/ulog_base (param $num i64) (param $base i32) (result i32) + (local $value i32) + (local $b64 i64) + (local $b i64) + (local $e i32) + ;;@ ~lib/util/number.ts:168:2 + (if + ;;@ ~lib/util/number.ts:168:6 + (block $~lib/util/number/isPowerOf2|inlined.0 (result i32) + (local.set $value + ;;@ ~lib/util/number.ts:168:17 + (local.get $base) + ) + ;;@ ~lib/util/number.ts:128:2 + (br $~lib/util/number/isPowerOf2|inlined.0 + ;;@ ~lib/util/number.ts:128:9 + (i32.eq + (i32.popcnt + ;;@ ~lib/util/number.ts:128:19 + (local.get $value) + ) + ;;@ ~lib/util/number.ts:128:29 + (i32.const 1) + ) + ) + ) + ;;@ ~lib/util/number.ts:169:4 + (return + ;;@ ~lib/util/number.ts:169:11 + (i32.add + (i32.div_u + ;;@ ~lib/util/number.ts:169:12 + (i32.sub + (i32.const 63) + ;;@ ~lib/util/number.ts:169:17 + (i32.wrap_i64 + (i64.clz + ;;@ ~lib/util/number.ts:169:26 + (local.get $num) + ) + ) + ) + ;;@ ~lib/util/number.ts:169:35 + (i32.sub + (i32.const 31) + ;;@ ~lib/util/number.ts:169:40 + (i32.clz + ;;@ ~lib/util/number.ts:169:49 + (local.get $base) + ) + ) + ) + ;;@ ~lib/util/number.ts:169:58 + (i32.const 1) + ) + ) + ) + (local.set $b64 + ;;@ ~lib/util/number.ts:171:12 + (i64.extend_i32_s + (local.get $base) + ) + ) + (local.set $b + ;;@ ~lib/util/number.ts:171:27 + (local.get $b64) + ) + (local.set $e + ;;@ ~lib/util/number.ts:171:41 + (i32.const 1) + ) + ;;@ ~lib/util/number.ts:172:2 + (block $while-break|0 + (loop $while-continue|0 + (if + ;;@ ~lib/util/number.ts:172:9 + (i64.ge_u + (local.get $num) + ;;@ ~lib/util/number.ts:172:16 + (local.get $b) + ) + (block + ;;@ ~lib/util/number.ts:173:4 + (local.set $num + (i64.div_u + (local.get $num) + ;;@ ~lib/util/number.ts:173:11 + (local.get $b) + ) + ) + ;;@ ~lib/util/number.ts:174:4 + (local.set $b + (i64.mul + (local.get $b) + ;;@ ~lib/util/number.ts:174:9 + (local.get $b) + ) + ) + ;;@ ~lib/util/number.ts:175:4 + (local.set $e + (i32.shl + (local.get $e) + ;;@ ~lib/util/number.ts:175:10 + (i32.const 1) + ) + ) + (br $while-continue|0) + ) + ) + ) + ) + ;;@ ~lib/util/number.ts:177:2 + (block $while-break|1 + (loop $while-continue|1 + (if + ;;@ ~lib/util/number.ts:177:9 + (i64.ge_u + (local.get $num) + ;;@ ~lib/util/number.ts:177:16 + (i64.const 1) + ) + (block + ;;@ ~lib/util/number.ts:178:4 + (local.set $num + (i64.div_u + (local.get $num) + ;;@ ~lib/util/number.ts:178:11 + (local.get $b64) + ) + ) + ;;@ ~lib/util/number.ts:179:4 + (local.set $e + (i32.add + (local.get $e) + (i32.const 1) + ) + ) + (br $while-continue|1) + ) + ) + ) + ) + ;;@ ~lib/util/number.ts:181:2 + (return + ;;@ ~lib/util/number.ts:181:9 + (i32.sub + (local.get $e) + ;;@ ~lib/util/number.ts:181:13 + (i32.const 1) + ) + ) + ) + (func $~lib/util/number/utoa64_any_core (param $buffer i32) (param $num i64) (param $offset i32) (param $radix i32) + (local $base i64) + (local $shift i64) + (local $mask i64) + (local $q i64) + ;;@ ~lib/util/number.ts:329:2 + (local.set $base + ;;@ ~lib/util/number.ts:329:13 + (i64.extend_i32_s + (local.get $radix) + ) + ) + ;;@ ~lib/util/number.ts:330:2 + (if + ;;@ ~lib/util/number.ts:330:6 + (i32.eq + ;;@ ~lib/util/number.ts:330:7 + (i32.and + (local.get $radix) + ;;@ ~lib/util/number.ts:330:16 + (i32.sub + (local.get $radix) + ;;@ ~lib/util/number.ts:330:24 + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:330:31 + (i32.const 0) + ) + (block + ;;@ ~lib/util/number.ts:331:4 + (local.set $shift + ;;@ ~lib/util/number.ts:331:16 + (i64.extend_i32_s + (i32.and + ;;@ ~lib/util/number.ts:331:20 + (i32.ctz + ;;@ ~lib/util/number.ts:331:24 + (local.get $radix) + ) + ;;@ ~lib/util/number.ts:331:33 + (i32.const 7) + ) + ) + ) + ;;@ ~lib/util/number.ts:332:4 + (local.set $mask + ;;@ ~lib/util/number.ts:332:15 + (i64.sub + (local.get $base) + ;;@ ~lib/util/number.ts:332:22 + (i64.const 1) + ) + ) + ;;@ ~lib/util/number.ts:333:4 + (loop $do-loop|0 + ;;@ ~lib/util/number.ts:334:6 + (local.set $offset + (i32.sub + (local.get $offset) + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:335:6 + (i32.store16 + ;;@ ~lib/util/number.ts:335:17 + (i32.add + (local.get $buffer) + ;;@ ~lib/util/number.ts:335:27 + (i32.shl + (local.get $offset) + ;;@ ~lib/util/number.ts:335:37 + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:335:41 + (i32.load16_u + ;;@ ~lib/util/number.ts:335:51 + (i32.add + (i32.const 2080) + ;;@ ~lib/util/number.ts:335:58 + (i32.shl + (i32.wrap_i64 + (i64.and + ;;@ ~lib/util/number.ts:335:64 + (local.get $num) + ;;@ ~lib/util/number.ts:335:70 + (local.get $mask) + ) + ) + ;;@ ~lib/util/number.ts:335:79 + (i32.const 1) + ) + ) + ) + ) + ;;@ ~lib/util/number.ts:336:6 + (local.set $num + (i64.shr_u + (local.get $num) + ;;@ ~lib/util/number.ts:336:14 + (local.get $shift) + ) + ) + (br_if $do-loop|0 + (i64.ne + ;;@ ~lib/util/number.ts:337:13 + (local.get $num) + (i64.const 0) + ) + ) + ) + ) + ;;@ ~lib/util/number.ts:339:4 + (loop $do-loop|1 + ;;@ ~lib/util/number.ts:340:6 + (local.set $offset + (i32.sub + (local.get $offset) + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:341:6 + (local.set $q + ;;@ ~lib/util/number.ts:341:14 + (i64.div_u + (local.get $num) + ;;@ ~lib/util/number.ts:341:20 + (local.get $base) + ) + ) + ;;@ ~lib/util/number.ts:342:6 + (i32.store16 + ;;@ ~lib/util/number.ts:342:17 + (i32.add + (local.get $buffer) + ;;@ ~lib/util/number.ts:342:27 + (i32.shl + (local.get $offset) + ;;@ ~lib/util/number.ts:342:37 + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:342:41 + (i32.load16_u + ;;@ ~lib/util/number.ts:342:51 + (i32.add + (i32.const 2080) + ;;@ ~lib/util/number.ts:342:58 + (i32.shl + (i32.wrap_i64 + (i64.sub + ;;@ ~lib/util/number.ts:342:64 + (local.get $num) + ;;@ ~lib/util/number.ts:342:70 + (i64.mul + (local.get $q) + ;;@ ~lib/util/number.ts:342:74 + (local.get $base) + ) + ) + ) + ;;@ ~lib/util/number.ts:342:83 + (i32.const 1) + ) + ) + ) + ) + ;;@ ~lib/util/number.ts:343:6 + (local.set $num + ;;@ ~lib/util/number.ts:343:12 + (local.get $q) + ) + (br_if $do-loop|1 + (i64.ne + ;;@ ~lib/util/number.ts:344:13 + (local.get $num) + (i64.const 0) + ) + ) + ) + ) + ) + (func $~lib/util/number/itoa32 (param $value i32) (param $radix i32) (result i32) + (local $sign i32) + (local $out i32) + (local $decimals i32) + (local $buffer i32) + (local $num i32) + (local $offset i32) + (local $decimals|8 i32) + (local $buffer|9 i32) + (local $num|10 i32) + (local $offset|11 i32) + (local $val32 i32) + (local $decimals|13 i32) + ;;@ ~lib/util/number.ts:372:2 + (if + ;;@ ~lib/util/number.ts:372:6 + (if (result i32) + (i32.lt_s + (local.get $radix) + ;;@ ~lib/util/number.ts:372:14 + (i32.const 2) + ) + (i32.const 1) + ;;@ ~lib/util/number.ts:372:19 + (i32.gt_s + (local.get $radix) + ;;@ ~lib/util/number.ts:372:27 + (i32.const 36) + ) + ) + (block + (call $~lib/builtins/abort + ;;@ ~lib/util/number.ts:373:25 + (i32.const 400) + (i32.const 528) + (i32.const 373) + (i32.const 5) + ) + (unreachable) + ) + ) + ;;@ ~lib/util/number.ts:375:2 + (if + ;;@ ~lib/util/number.ts:375:6 + (i32.eqz + ;;@ ~lib/util/number.ts:375:7 + (local.get $value) + ) + ;;@ ~lib/util/number.ts:375:14 + (return + ;;@ ~lib/util/number.ts:375:21 + (i32.const 592) + ) + ) + ;;@ ~lib/util/number.ts:377:2 + (local.set $sign + ;;@ ~lib/util/number.ts:377:13 + (i32.shl + ;;@ ~lib/util/number.ts:377:14 + (i32.shr_u + (local.get $value) + ;;@ ~lib/util/number.ts:377:24 + (i32.const 31) + ) + ;;@ ~lib/util/number.ts:377:31 + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:378:2 + (if + ;;@ ~lib/util/number.ts:378:6 + (local.get $sign) + ;;@ ~lib/util/number.ts:378:12 + (local.set $value + ;;@ ~lib/util/number.ts:378:20 + (i32.sub + (i32.const 0) + ;;@ ~lib/util/number.ts:378:21 + (local.get $value) + ) + ) + ) + ;;@ ~lib/util/number.ts:381:2 + (if + ;;@ ~lib/util/number.ts:381:6 + (i32.eq + (local.get $radix) + ;;@ ~lib/util/number.ts:381:15 + (i32.const 10) + ) + (block + ;;@ ~lib/util/number.ts:382:4 + (local.set $decimals + ;;@ ~lib/util/number.ts:382:19 + (call $~lib/util/number/decimalCount32 + ;;@ ~lib/util/number.ts:382:34 + (local.get $value) + ) + ) + ;;@ ~lib/util/number.ts:383:4 + (local.set $out + ;;@ ~lib/util/number.ts:383:10 + (call $~lib/rt/stub/__new + ;;@ ~lib/util/number.ts:383:35 + (i32.add + ;;@ ~lib/util/number.ts:383:36 + (i32.shl + (local.get $decimals) + ;;@ ~lib/util/number.ts:383:48 + (i32.const 1) + ) + ;;@ ~lib/util/number.ts:383:53 + (local.get $sign) + ) + ;;@ ~lib/util/number.ts:383:59 + (i32.const 2) + ) + ) + ;;@ ~lib/util/number.ts:384:4 + (block $~lib/util/number/utoa32_dec_core|inlined.0 + (local.set $buffer + ;;@ ~lib/util/number.ts:384:20 + (i32.add + (local.get $out) + ;;@ ~lib/util/number.ts:384:45 + (local.get $sign) + ) + ) + (local.set $num + ;;@ ~lib/util/number.ts:384:51 + (local.get $value) + ) + (local.set $offset + ;;@ ~lib/util/number.ts:384:58 + (local.get $decimals) + ) + (drop + ;;@ ~lib/util/number.ts:290:6 + (i32.ge_s + (i32.const 0) + ;;@ ~lib/util/number.ts:290:26 + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:292:9 + (call $~lib/util/number/utoa32_dec_lut + ;;@ ~lib/util/number.ts:293:19 + (local.get $buffer) + ;;@ ~lib/util/number.ts:293:27 + (local.get $num) + ;;@ ~lib/util/number.ts:293:32 + (local.get $offset) + ) + ) + ) + ;;@ ~lib/util/number.ts:385:9 + (if + ;;@ ~lib/util/number.ts:385:13 + (i32.eq + (local.get $radix) + ;;@ ~lib/util/number.ts:385:22 + (i32.const 16) + ) + (block + ;;@ ~lib/util/number.ts:386:4 + (local.set $decimals|8 + ;;@ ~lib/util/number.ts:386:19 + (i32.add + ;;@ ~lib/util/number.ts:386:20 + (i32.shr_s + (i32.sub + (i32.const 31) + ;;@ ~lib/util/number.ts:386:25 + (i32.clz + ;;@ ~lib/util/number.ts:386:29 + (local.get $value) + ) + ) + ;;@ ~lib/util/number.ts:386:39 + (i32.const 2) + ) + ;;@ ~lib/util/number.ts:386:44 + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:387:4 + (local.set $out + ;;@ ~lib/util/number.ts:387:10 + (call $~lib/rt/stub/__new + ;;@ ~lib/util/number.ts:387:35 + (i32.add + ;;@ ~lib/util/number.ts:387:36 + (i32.shl + (local.get $decimals|8) + ;;@ ~lib/util/number.ts:387:48 + (i32.const 1) + ) + ;;@ ~lib/util/number.ts:387:53 + (local.get $sign) + ) + ;;@ ~lib/util/number.ts:387:59 + (i32.const 2) + ) + ) + ;;@ ~lib/util/number.ts:388:4 + (block $~lib/util/number/utoa32_hex_core|inlined.0 + (local.set $buffer|9 + ;;@ ~lib/util/number.ts:388:20 + (i32.add + (local.get $out) + ;;@ ~lib/util/number.ts:388:45 + (local.get $sign) + ) + ) + (local.set $num|10 + ;;@ ~lib/util/number.ts:388:51 + (local.get $value) + ) + (local.set $offset|11 + ;;@ ~lib/util/number.ts:388:58 + (local.get $decimals|8) + ) + (drop + ;;@ ~lib/util/number.ts:300:6 + (i32.ge_s + (i32.const 0) + ;;@ ~lib/util/number.ts:300:26 + (i32.const 1) + ) + ) + ;;@ ~lib/util/number.ts:302:9 + (call $~lib/util/number/utoa_hex_lut + ;;@ ~lib/util/number.ts:303:17 + (local.get $buffer|9) + ;;@ ~lib/util/number.ts:303:25 + (i64.extend_i32_u + (local.get $num|10) + ) + ;;@ ~lib/util/number.ts:303:30 + (local.get $offset|11) + ) + ) + ) + (block + ;;@ ~lib/util/number.ts:390:4 + (local.set $val32 + ;;@ ~lib/util/number.ts:390:16 + (local.get $value) + ) + ;;@ ~lib/util/number.ts:391:4 + (local.set $decimals|13 + ;;@ ~lib/util/number.ts:391:19 + (call $~lib/util/number/ulog_base + ;;@ ~lib/util/number.ts:391:29 + (i64.extend_i32_u + (local.get $val32) + ) + ;;@ ~lib/util/number.ts:391:36 + (local.get $radix) + ) + ) + ;;@ ~lib/util/number.ts:392:4 + (local.set $out + ;;@ ~lib/util/number.ts:392:10 + (call $~lib/rt/stub/__new + ;;@ ~lib/util/number.ts:392:35 + (i32.add + ;;@ ~lib/util/number.ts:392:36 + (i32.shl + (local.get $decimals|13) + ;;@ ~lib/util/number.ts:392:48 + (i32.const 1) + ) + ;;@ ~lib/util/number.ts:392:53 + (local.get $sign) + ) + ;;@ ~lib/util/number.ts:392:59 + (i32.const 2) + ) + ) + ;;@ ~lib/util/number.ts:393:4 + (call $~lib/util/number/utoa64_any_core + ;;@ ~lib/util/number.ts:393:20 + (i32.add + (local.get $out) + ;;@ ~lib/util/number.ts:393:45 + (local.get $sign) + ) + ;;@ ~lib/util/number.ts:393:51 + (i64.extend_i32_u + (local.get $val32) + ) + ;;@ ~lib/util/number.ts:393:58 + (local.get $decimals|13) + ;;@ ~lib/util/number.ts:393:68 + (local.get $radix) + ) + ) + ) + ) + ;;@ ~lib/util/number.ts:395:2 + (if + ;;@ ~lib/util/number.ts:395:6 + (local.get $sign) + ;;@ ~lib/util/number.ts:395:12 + (i32.store16 + ;;@ ~lib/util/number.ts:395:23 + (local.get $out) + ;;@ ~lib/util/number.ts:395:47 + (i32.const 45) + ) + ) + ;;@ ~lib/util/number.ts:396:2 + (return + ;;@ ~lib/util/number.ts:396:9 + (local.get $out) + ) + ) + (func $~lib/number/I32#toString (param $this i32) (param $radix i32) (result i32) + ;;@ ~lib/number.ts:79:4 + (return + ;;@ ~lib/number.ts:79:11 + (call $~lib/util/number/itoa32 + ;;@ ~lib/number.ts:79:18 + (local.get $this) + ;;@ ~lib/number.ts:79:24 + (local.get $radix) + ) + ) + ) + (func $~lib/util/memory/memcpy (param $dest i32) (param $src i32) (param $n i32) + (local $w i32) + (local $x i32) + (local $5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + (local $10 i32) + (local $11 i32) + (local $12 i32) + (local $13 i32) + (local $14 i32) + (local $15 i32) + (local $16 i32) + (local $17 i32) + (local $18 i32) + (local $19 i32) + (local $20 i32) + (local $21 i32) + (local $22 i32) + (local $23 i32) + (local $24 i32) + (local $25 i32) + (local $26 i32) + (local $27 i32) + (local $28 i32) + (local $29 i32) + (local $30 i32) + (local $31 i32) + (local $32 i32) + (local $33 i32) + (local $34 i32) + (local $35 i32) + (local $36 i32) + (local $37 i32) + (local $38 i32) + (local $39 i32) + (local $40 i32) + (local $41 i32) + (local $42 i32) + (local $43 i32) + (local $44 i32) + (local $45 i32) + (local $46 i32) + (local $47 i32) + (local $48 i32) + (local $49 i32) + (local $50 i32) + (local $51 i32) + (local $52 i32) + (local $53 i32) + (local $54 i32) + (local $55 i32) + (local $56 i32) + (local $57 i32) + (local $58 i32) + (local $59 i32) + (local $60 i32) + (local $61 i32) + (local $62 i32) + (local $63 i32) + (local $64 i32) + (local $65 i32) + (local $66 i32) + (local $67 i32) + (local $68 i32) + (local $69 i32) + (local $70 i32) + (local $71 i32) + (local $72 i32) + (local $73 i32) + (local $74 i32) + (local $75 i32) + (local $76 i32) + (local $77 i32) + (local $78 i32) + (local $79 i32) + (local $80 i32) + (local $81 i32) + (local $82 i32) + (local $83 i32) + ;;@ ~lib/util/memory.ts:5:2 + (block $while-break|0 + (loop $while-continue|0 + (if + ;;@ ~lib/util/memory.ts:5:9 + (if (result i32) + (local.get $n) + ;;@ ~lib/util/memory.ts:5:15 + (i32.and + (local.get $src) + ;;@ ~lib/util/memory.ts:5:21 + (i32.const 3) + ) + (i32.const 0) + ) + (block + ;;@ ~lib/util/memory.ts:6:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:6:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $5 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $5) + ) + ;;@ ~lib/util/memory.ts:6:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:6:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $6 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $6) + ) + ) + ) + ;;@ ~lib/util/memory.ts:7:4 + (local.set $n + (i32.sub + (local.get $n) + (i32.const 1) + ) + ) + (br $while-continue|0) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:11:2 + (if + ;;@ ~lib/util/memory.ts:11:6 + (i32.eq + ;;@ ~lib/util/memory.ts:11:7 + (i32.and + (local.get $dest) + ;;@ ~lib/util/memory.ts:11:14 + (i32.const 3) + ) + ;;@ ~lib/util/memory.ts:11:20 + (i32.const 0) + ) + (block + ;;@ ~lib/util/memory.ts:12:4 + (block $while-break|1 + (loop $while-continue|1 + (if + ;;@ ~lib/util/memory.ts:12:11 + (i32.ge_u + (local.get $n) + ;;@ ~lib/util/memory.ts:12:16 + (i32.const 16) + ) + (block + ;;@ ~lib/util/memory.ts:13:6 + (i32.store + ;;@ ~lib/util/memory.ts:13:17 + (local.get $dest) + ;;@ ~lib/util/memory.ts:13:28 + (i32.load + ;;@ ~lib/util/memory.ts:13:38 + (local.get $src) + ) + ) + ;;@ ~lib/util/memory.ts:14:6 + (i32.store + ;;@ ~lib/util/memory.ts:14:17 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:14:25 + (i32.const 4) + ) + ;;@ ~lib/util/memory.ts:14:28 + (i32.load + ;;@ ~lib/util/memory.ts:14:38 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:14:45 + (i32.const 4) + ) + ) + ) + ;;@ ~lib/util/memory.ts:15:6 + (i32.store + ;;@ ~lib/util/memory.ts:15:17 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:15:25 + (i32.const 8) + ) + ;;@ ~lib/util/memory.ts:15:28 + (i32.load + ;;@ ~lib/util/memory.ts:15:38 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:15:45 + (i32.const 8) + ) + ) + ) + ;;@ ~lib/util/memory.ts:16:6 + (i32.store + ;;@ ~lib/util/memory.ts:16:17 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:16:24 + (i32.const 12) + ) + ;;@ ~lib/util/memory.ts:16:28 + (i32.load + ;;@ ~lib/util/memory.ts:16:38 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:16:44 + (i32.const 12) + ) + ) + ) + ;;@ ~lib/util/memory.ts:17:6 + (local.set $src + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:17:13 + (i32.const 16) + ) + ) + ;;@ ~lib/util/memory.ts:17:17 + (local.set $dest + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:17:25 + (i32.const 16) + ) + ) + ;;@ ~lib/util/memory.ts:17:29 + (local.set $n + (i32.sub + (local.get $n) + ;;@ ~lib/util/memory.ts:17:34 + (i32.const 16) + ) + ) + (br $while-continue|1) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:19:4 + (if + ;;@ ~lib/util/memory.ts:19:8 + (i32.and + (local.get $n) + ;;@ ~lib/util/memory.ts:19:12 + (i32.const 8) + ) + (block + ;;@ ~lib/util/memory.ts:20:6 + (i32.store + ;;@ ~lib/util/memory.ts:20:17 + (local.get $dest) + ;;@ ~lib/util/memory.ts:20:27 + (i32.load + ;;@ ~lib/util/memory.ts:20:37 + (local.get $src) + ) + ) + ;;@ ~lib/util/memory.ts:21:6 + (i32.store + ;;@ ~lib/util/memory.ts:21:17 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:21:24 + (i32.const 4) + ) + ;;@ ~lib/util/memory.ts:21:27 + (i32.load + ;;@ ~lib/util/memory.ts:21:37 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:21:43 + (i32.const 4) + ) + ) + ) + ;;@ ~lib/util/memory.ts:22:6 + (local.set $dest + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:22:14 + (i32.const 8) + ) + ) + ;;@ ~lib/util/memory.ts:22:17 + (local.set $src + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:22:24 + (i32.const 8) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:24:4 + (if + ;;@ ~lib/util/memory.ts:24:8 + (i32.and + (local.get $n) + ;;@ ~lib/util/memory.ts:24:12 + (i32.const 4) + ) + (block + ;;@ ~lib/util/memory.ts:25:6 + (i32.store + ;;@ ~lib/util/memory.ts:25:17 + (local.get $dest) + ;;@ ~lib/util/memory.ts:25:23 + (i32.load + ;;@ ~lib/util/memory.ts:25:33 + (local.get $src) + ) + ) + ;;@ ~lib/util/memory.ts:26:6 + (local.set $dest + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:26:14 + (i32.const 4) + ) + ) + ;;@ ~lib/util/memory.ts:26:17 + (local.set $src + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:26:24 + (i32.const 4) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:28:4 + (if + ;;@ ~lib/util/memory.ts:28:8 + (i32.and + (local.get $n) + ;;@ ~lib/util/memory.ts:28:12 + (i32.const 2) + ) + (block + ;;@ ~lib/util/memory.ts:29:6 + (i32.store16 + ;;@ ~lib/util/memory.ts:29:17 + (local.get $dest) + ;;@ ~lib/util/memory.ts:29:23 + (i32.load16_u + ;;@ ~lib/util/memory.ts:29:33 + (local.get $src) + ) + ) + ;;@ ~lib/util/memory.ts:30:6 + (local.set $dest + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:30:14 + (i32.const 2) + ) + ) + ;;@ ~lib/util/memory.ts:30:17 + (local.set $src + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:30:24 + (i32.const 2) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:32:4 + (if + ;;@ ~lib/util/memory.ts:32:8 + (i32.and + (local.get $n) + ;;@ ~lib/util/memory.ts:32:12 + (i32.const 1) + ) + ;;@ ~lib/util/memory.ts:33:6 + (i32.store8 + ;;@ ~lib/util/memory.ts:33:16 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $7 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $7) + ) + ;;@ ~lib/util/memory.ts:33:24 + (i32.load8_u + ;;@ ~lib/util/memory.ts:33:33 + (block (result i32) + (local.set $src + (i32.add + (local.tee $8 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $8) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:35:4 + (return) + ) + ) + ;;@ ~lib/util/memory.ts:40:2 + (if + ;;@ ~lib/util/memory.ts:40:6 + (i32.ge_u + (local.get $n) + ;;@ ~lib/util/memory.ts:40:11 + (i32.const 32) + ) + ;;@ ~lib/util/memory.ts:41:4 + (block $break|2 + (block $case2|2 + (block $case1|2 + (block $case0|2 + (local.set $9 + ;;@ ~lib/util/memory.ts:41:12 + (i32.and + (local.get $dest) + ;;@ ~lib/util/memory.ts:41:24 + (i32.const 3) + ) + ) + (br_if $case0|2 + (i32.eq + (local.get $9) + ;;@ ~lib/util/memory.ts:43:11 + (i32.const 1) + ) + ) + (br_if $case1|2 + (i32.eq + (local.get $9) + ;;@ ~lib/util/memory.ts:62:11 + (i32.const 2) + ) + ) + (br_if $case2|2 + (i32.eq + (local.get $9) + ;;@ ~lib/util/memory.ts:80:11 + (i32.const 3) + ) + ) + (br $break|2) + ) + ;;@ ~lib/util/memory.ts:43:14 + (block + ;;@ ~lib/util/memory.ts:44:8 + (local.set $w + ;;@ ~lib/util/memory.ts:44:12 + (i32.load + ;;@ ~lib/util/memory.ts:44:22 + (local.get $src) + ) + ) + ;;@ ~lib/util/memory.ts:45:8 + (i32.store8 + ;;@ ~lib/util/memory.ts:45:18 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $10 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $10) + ) + ;;@ ~lib/util/memory.ts:45:26 + (i32.load8_u + ;;@ ~lib/util/memory.ts:45:35 + (block (result i32) + (local.set $src + (i32.add + (local.tee $11 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $11) + ) + ) + ) + ;;@ ~lib/util/memory.ts:46:8 + (i32.store8 + ;;@ ~lib/util/memory.ts:46:18 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $12 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $12) + ) + ;;@ ~lib/util/memory.ts:46:26 + (i32.load8_u + ;;@ ~lib/util/memory.ts:46:35 + (block (result i32) + (local.set $src + (i32.add + (local.tee $13 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $13) + ) + ) + ) + ;;@ ~lib/util/memory.ts:47:8 + (i32.store8 + ;;@ ~lib/util/memory.ts:47:18 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $14 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $14) + ) + ;;@ ~lib/util/memory.ts:47:26 + (i32.load8_u + ;;@ ~lib/util/memory.ts:47:35 + (block (result i32) + (local.set $src + (i32.add + (local.tee $15 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $15) + ) + ) + ) + ;;@ ~lib/util/memory.ts:48:8 + (local.set $n + (i32.sub + (local.get $n) + ;;@ ~lib/util/memory.ts:48:13 + (i32.const 3) + ) + ) + ;;@ ~lib/util/memory.ts:49:8 + (block $while-break|3 + (loop $while-continue|3 + (if + ;;@ ~lib/util/memory.ts:49:15 + (i32.ge_u + (local.get $n) + ;;@ ~lib/util/memory.ts:49:20 + (i32.const 17) + ) + (block + ;;@ ~lib/util/memory.ts:50:10 + (local.set $x + ;;@ ~lib/util/memory.ts:50:14 + (i32.load + ;;@ ~lib/util/memory.ts:50:24 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:50:30 + (i32.const 1) + ) + ) + ) + ;;@ ~lib/util/memory.ts:51:10 + (i32.store + ;;@ ~lib/util/memory.ts:51:21 + (local.get $dest) + ;;@ ~lib/util/memory.ts:51:27 + (i32.or + (i32.shr_u + (local.get $w) + ;;@ ~lib/util/memory.ts:51:32 + (i32.const 24) + ) + ;;@ ~lib/util/memory.ts:51:37 + (i32.shl + (local.get $x) + ;;@ ~lib/util/memory.ts:51:42 + (i32.const 8) + ) + ) + ) + ;;@ ~lib/util/memory.ts:52:10 + (local.set $w + ;;@ ~lib/util/memory.ts:52:14 + (i32.load + ;;@ ~lib/util/memory.ts:52:24 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:52:30 + (i32.const 5) + ) + ) + ) + ;;@ ~lib/util/memory.ts:53:10 + (i32.store + ;;@ ~lib/util/memory.ts:53:21 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:53:28 + (i32.const 4) + ) + ;;@ ~lib/util/memory.ts:53:31 + (i32.or + (i32.shr_u + (local.get $x) + ;;@ ~lib/util/memory.ts:53:36 + (i32.const 24) + ) + ;;@ ~lib/util/memory.ts:53:41 + (i32.shl + (local.get $w) + ;;@ ~lib/util/memory.ts:53:46 + (i32.const 8) + ) + ) + ) + ;;@ ~lib/util/memory.ts:54:10 + (local.set $x + ;;@ ~lib/util/memory.ts:54:14 + (i32.load + ;;@ ~lib/util/memory.ts:54:24 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:54:30 + (i32.const 9) + ) + ) + ) + ;;@ ~lib/util/memory.ts:55:10 + (i32.store + ;;@ ~lib/util/memory.ts:55:21 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:55:28 + (i32.const 8) + ) + ;;@ ~lib/util/memory.ts:55:31 + (i32.or + (i32.shr_u + (local.get $w) + ;;@ ~lib/util/memory.ts:55:36 + (i32.const 24) + ) + ;;@ ~lib/util/memory.ts:55:41 + (i32.shl + (local.get $x) + ;;@ ~lib/util/memory.ts:55:46 + (i32.const 8) + ) + ) + ) + ;;@ ~lib/util/memory.ts:56:10 + (local.set $w + ;;@ ~lib/util/memory.ts:56:14 + (i32.load + ;;@ ~lib/util/memory.ts:56:24 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:56:30 + (i32.const 13) + ) + ) + ) + ;;@ ~lib/util/memory.ts:57:10 + (i32.store + ;;@ ~lib/util/memory.ts:57:21 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:57:28 + (i32.const 12) + ) + ;;@ ~lib/util/memory.ts:57:32 + (i32.or + (i32.shr_u + (local.get $x) + ;;@ ~lib/util/memory.ts:57:37 + (i32.const 24) + ) + ;;@ ~lib/util/memory.ts:57:42 + (i32.shl + (local.get $w) + ;;@ ~lib/util/memory.ts:57:47 + (i32.const 8) + ) + ) + ) + ;;@ ~lib/util/memory.ts:58:10 + (local.set $src + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:58:17 + (i32.const 16) + ) + ) + ;;@ ~lib/util/memory.ts:58:21 + (local.set $dest + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:58:29 + (i32.const 16) + ) + ) + ;;@ ~lib/util/memory.ts:58:33 + (local.set $n + (i32.sub + (local.get $n) + ;;@ ~lib/util/memory.ts:58:38 + (i32.const 16) + ) + ) + (br $while-continue|3) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:60:8 + (br $break|2) + ) + ) + ;;@ ~lib/util/memory.ts:62:14 + (block + ;;@ ~lib/util/memory.ts:63:8 + (local.set $w + ;;@ ~lib/util/memory.ts:63:12 + (i32.load + ;;@ ~lib/util/memory.ts:63:22 + (local.get $src) + ) + ) + ;;@ ~lib/util/memory.ts:64:8 + (i32.store8 + ;;@ ~lib/util/memory.ts:64:18 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $16 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $16) + ) + ;;@ ~lib/util/memory.ts:64:26 + (i32.load8_u + ;;@ ~lib/util/memory.ts:64:35 + (block (result i32) + (local.set $src + (i32.add + (local.tee $17 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $17) + ) + ) + ) + ;;@ ~lib/util/memory.ts:65:8 + (i32.store8 + ;;@ ~lib/util/memory.ts:65:18 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $18 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $18) + ) + ;;@ ~lib/util/memory.ts:65:26 + (i32.load8_u + ;;@ ~lib/util/memory.ts:65:35 + (block (result i32) + (local.set $src + (i32.add + (local.tee $19 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $19) + ) + ) + ) + ;;@ ~lib/util/memory.ts:66:8 + (local.set $n + (i32.sub + (local.get $n) + ;;@ ~lib/util/memory.ts:66:13 + (i32.const 2) + ) + ) + ;;@ ~lib/util/memory.ts:67:8 + (block $while-break|4 + (loop $while-continue|4 + (if + ;;@ ~lib/util/memory.ts:67:15 + (i32.ge_u + (local.get $n) + ;;@ ~lib/util/memory.ts:67:20 + (i32.const 18) + ) + (block + ;;@ ~lib/util/memory.ts:68:10 + (local.set $x + ;;@ ~lib/util/memory.ts:68:14 + (i32.load + ;;@ ~lib/util/memory.ts:68:24 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:68:30 + (i32.const 2) + ) + ) + ) + ;;@ ~lib/util/memory.ts:69:10 + (i32.store + ;;@ ~lib/util/memory.ts:69:21 + (local.get $dest) + ;;@ ~lib/util/memory.ts:69:27 + (i32.or + (i32.shr_u + (local.get $w) + ;;@ ~lib/util/memory.ts:69:32 + (i32.const 16) + ) + ;;@ ~lib/util/memory.ts:69:37 + (i32.shl + (local.get $x) + ;;@ ~lib/util/memory.ts:69:42 + (i32.const 16) + ) + ) + ) + ;;@ ~lib/util/memory.ts:70:10 + (local.set $w + ;;@ ~lib/util/memory.ts:70:14 + (i32.load + ;;@ ~lib/util/memory.ts:70:24 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:70:30 + (i32.const 6) + ) + ) + ) + ;;@ ~lib/util/memory.ts:71:10 + (i32.store + ;;@ ~lib/util/memory.ts:71:21 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:71:28 + (i32.const 4) + ) + ;;@ ~lib/util/memory.ts:71:31 + (i32.or + (i32.shr_u + (local.get $x) + ;;@ ~lib/util/memory.ts:71:36 + (i32.const 16) + ) + ;;@ ~lib/util/memory.ts:71:41 + (i32.shl + (local.get $w) + ;;@ ~lib/util/memory.ts:71:46 + (i32.const 16) + ) + ) + ) + ;;@ ~lib/util/memory.ts:72:10 + (local.set $x + ;;@ ~lib/util/memory.ts:72:14 + (i32.load + ;;@ ~lib/util/memory.ts:72:24 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:72:30 + (i32.const 10) + ) + ) + ) + ;;@ ~lib/util/memory.ts:73:10 + (i32.store + ;;@ ~lib/util/memory.ts:73:21 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:73:28 + (i32.const 8) + ) + ;;@ ~lib/util/memory.ts:73:31 + (i32.or + (i32.shr_u + (local.get $w) + ;;@ ~lib/util/memory.ts:73:36 + (i32.const 16) + ) + ;;@ ~lib/util/memory.ts:73:41 + (i32.shl + (local.get $x) + ;;@ ~lib/util/memory.ts:73:46 + (i32.const 16) + ) + ) + ) + ;;@ ~lib/util/memory.ts:74:10 + (local.set $w + ;;@ ~lib/util/memory.ts:74:14 + (i32.load + ;;@ ~lib/util/memory.ts:74:24 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:74:30 + (i32.const 14) + ) + ) + ) + ;;@ ~lib/util/memory.ts:75:10 + (i32.store + ;;@ ~lib/util/memory.ts:75:21 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:75:28 + (i32.const 12) + ) + ;;@ ~lib/util/memory.ts:75:32 + (i32.or + (i32.shr_u + (local.get $x) + ;;@ ~lib/util/memory.ts:75:37 + (i32.const 16) + ) + ;;@ ~lib/util/memory.ts:75:42 + (i32.shl + (local.get $w) + ;;@ ~lib/util/memory.ts:75:47 + (i32.const 16) + ) + ) + ) + ;;@ ~lib/util/memory.ts:76:10 + (local.set $src + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:76:17 + (i32.const 16) + ) + ) + ;;@ ~lib/util/memory.ts:76:21 + (local.set $dest + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:76:29 + (i32.const 16) + ) + ) + ;;@ ~lib/util/memory.ts:76:33 + (local.set $n + (i32.sub + (local.get $n) + ;;@ ~lib/util/memory.ts:76:38 + (i32.const 16) + ) + ) + (br $while-continue|4) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:78:8 + (br $break|2) + ) + ) + ;;@ ~lib/util/memory.ts:80:14 + (block + ;;@ ~lib/util/memory.ts:81:8 + (local.set $w + ;;@ ~lib/util/memory.ts:81:12 + (i32.load + ;;@ ~lib/util/memory.ts:81:22 + (local.get $src) + ) + ) + ;;@ ~lib/util/memory.ts:82:8 + (i32.store8 + ;;@ ~lib/util/memory.ts:82:18 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $20 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $20) + ) + ;;@ ~lib/util/memory.ts:82:26 + (i32.load8_u + ;;@ ~lib/util/memory.ts:82:35 + (block (result i32) + (local.set $src + (i32.add + (local.tee $21 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $21) + ) + ) + ) + ;;@ ~lib/util/memory.ts:83:8 + (local.set $n + (i32.sub + (local.get $n) + ;;@ ~lib/util/memory.ts:83:13 + (i32.const 1) + ) + ) + ;;@ ~lib/util/memory.ts:84:8 + (block $while-break|5 + (loop $while-continue|5 + (if + ;;@ ~lib/util/memory.ts:84:15 + (i32.ge_u + (local.get $n) + ;;@ ~lib/util/memory.ts:84:20 + (i32.const 19) + ) + (block + ;;@ ~lib/util/memory.ts:85:10 + (local.set $x + ;;@ ~lib/util/memory.ts:85:14 + (i32.load + ;;@ ~lib/util/memory.ts:85:24 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:85:30 + (i32.const 3) + ) + ) + ) + ;;@ ~lib/util/memory.ts:86:10 + (i32.store + ;;@ ~lib/util/memory.ts:86:21 + (local.get $dest) + ;;@ ~lib/util/memory.ts:86:27 + (i32.or + (i32.shr_u + (local.get $w) + ;;@ ~lib/util/memory.ts:86:32 + (i32.const 8) + ) + ;;@ ~lib/util/memory.ts:86:36 + (i32.shl + (local.get $x) + ;;@ ~lib/util/memory.ts:86:41 + (i32.const 24) + ) + ) + ) + ;;@ ~lib/util/memory.ts:87:10 + (local.set $w + ;;@ ~lib/util/memory.ts:87:14 + (i32.load + ;;@ ~lib/util/memory.ts:87:24 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:87:30 + (i32.const 7) + ) + ) + ) + ;;@ ~lib/util/memory.ts:88:10 + (i32.store + ;;@ ~lib/util/memory.ts:88:21 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:88:28 + (i32.const 4) + ) + ;;@ ~lib/util/memory.ts:88:31 + (i32.or + (i32.shr_u + (local.get $x) + ;;@ ~lib/util/memory.ts:88:36 + (i32.const 8) + ) + ;;@ ~lib/util/memory.ts:88:40 + (i32.shl + (local.get $w) + ;;@ ~lib/util/memory.ts:88:45 + (i32.const 24) + ) + ) + ) + ;;@ ~lib/util/memory.ts:89:10 + (local.set $x + ;;@ ~lib/util/memory.ts:89:14 + (i32.load + ;;@ ~lib/util/memory.ts:89:24 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:89:30 + (i32.const 11) + ) + ) + ) + ;;@ ~lib/util/memory.ts:90:10 + (i32.store + ;;@ ~lib/util/memory.ts:90:21 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:90:28 + (i32.const 8) + ) + ;;@ ~lib/util/memory.ts:90:31 + (i32.or + (i32.shr_u + (local.get $w) + ;;@ ~lib/util/memory.ts:90:36 + (i32.const 8) + ) + ;;@ ~lib/util/memory.ts:90:40 + (i32.shl + (local.get $x) + ;;@ ~lib/util/memory.ts:90:45 + (i32.const 24) + ) + ) + ) + ;;@ ~lib/util/memory.ts:91:10 + (local.set $w + ;;@ ~lib/util/memory.ts:91:14 + (i32.load + ;;@ ~lib/util/memory.ts:91:24 + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:91:30 + (i32.const 15) + ) + ) + ) + ;;@ ~lib/util/memory.ts:92:10 + (i32.store + ;;@ ~lib/util/memory.ts:92:21 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:92:28 + (i32.const 12) + ) + ;;@ ~lib/util/memory.ts:92:32 + (i32.or + (i32.shr_u + (local.get $x) + ;;@ ~lib/util/memory.ts:92:37 + (i32.const 8) + ) + ;;@ ~lib/util/memory.ts:92:41 + (i32.shl + (local.get $w) + ;;@ ~lib/util/memory.ts:92:46 + (i32.const 24) + ) + ) + ) + ;;@ ~lib/util/memory.ts:93:10 + (local.set $src + (i32.add + (local.get $src) + ;;@ ~lib/util/memory.ts:93:17 + (i32.const 16) + ) + ) + ;;@ ~lib/util/memory.ts:93:21 + (local.set $dest + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:93:29 + (i32.const 16) + ) + ) + ;;@ ~lib/util/memory.ts:93:33 + (local.set $n + (i32.sub + (local.get $n) + ;;@ ~lib/util/memory.ts:93:38 + (i32.const 16) + ) + ) + (br $while-continue|5) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:95:8 + (br $break|2) + ) + ) + ) + ;;@ ~lib/util/memory.ts:101:2 + (if + ;;@ ~lib/util/memory.ts:101:6 + (i32.and + (local.get $n) + ;;@ ~lib/util/memory.ts:101:10 + (i32.const 16) + ) + (block + ;;@ ~lib/util/memory.ts:102:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:102:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $22 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $22) + ) + ;;@ ~lib/util/memory.ts:102:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:102:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $23 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $23) + ) + ) + ) + ;;@ ~lib/util/memory.ts:103:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:103:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $24 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $24) + ) + ;;@ ~lib/util/memory.ts:103:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:103:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $25 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $25) + ) + ) + ) + ;;@ ~lib/util/memory.ts:104:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:104:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $26 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $26) + ) + ;;@ ~lib/util/memory.ts:104:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:104:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $27 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $27) + ) + ) + ) + ;;@ ~lib/util/memory.ts:105:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:105:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $28 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $28) + ) + ;;@ ~lib/util/memory.ts:105:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:105:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $29 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $29) + ) + ) + ) + ;;@ ~lib/util/memory.ts:106:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:106:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $30 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $30) + ) + ;;@ ~lib/util/memory.ts:106:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:106:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $31 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $31) + ) + ) + ) + ;;@ ~lib/util/memory.ts:107:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:107:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $32 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $32) + ) + ;;@ ~lib/util/memory.ts:107:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:107:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $33 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $33) + ) + ) + ) + ;;@ ~lib/util/memory.ts:108:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:108:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $34 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $34) + ) + ;;@ ~lib/util/memory.ts:108:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:108:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $35 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $35) + ) + ) + ) + ;;@ ~lib/util/memory.ts:109:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:109:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $36 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $36) + ) + ;;@ ~lib/util/memory.ts:109:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:109:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $37 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $37) + ) + ) + ) + ;;@ ~lib/util/memory.ts:110:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:110:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $38 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $38) + ) + ;;@ ~lib/util/memory.ts:110:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:110:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $39 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $39) + ) + ) + ) + ;;@ ~lib/util/memory.ts:111:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:111:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $40 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $40) + ) + ;;@ ~lib/util/memory.ts:111:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:111:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $41 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $41) + ) + ) + ) + ;;@ ~lib/util/memory.ts:112:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:112:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $42 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $42) + ) + ;;@ ~lib/util/memory.ts:112:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:112:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $43 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $43) + ) + ) + ) + ;;@ ~lib/util/memory.ts:113:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:113:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $44 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $44) + ) + ;;@ ~lib/util/memory.ts:113:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:113:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $45 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $45) + ) + ) + ) + ;;@ ~lib/util/memory.ts:114:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:114:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $46 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $46) + ) + ;;@ ~lib/util/memory.ts:114:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:114:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $47 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $47) + ) + ) + ) + ;;@ ~lib/util/memory.ts:115:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:115:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $48 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $48) + ) + ;;@ ~lib/util/memory.ts:115:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:115:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $49 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $49) + ) + ) + ) + ;;@ ~lib/util/memory.ts:116:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:116:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $50 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $50) + ) + ;;@ ~lib/util/memory.ts:116:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:116:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $51 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $51) + ) + ) + ) + ;;@ ~lib/util/memory.ts:117:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:117:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $52 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $52) + ) + ;;@ ~lib/util/memory.ts:117:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:117:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $53 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $53) + ) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:119:2 + (if + ;;@ ~lib/util/memory.ts:119:6 + (i32.and + (local.get $n) + ;;@ ~lib/util/memory.ts:119:10 + (i32.const 8) + ) + (block + ;;@ ~lib/util/memory.ts:120:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:120:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $54 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $54) + ) + ;;@ ~lib/util/memory.ts:120:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:120:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $55 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $55) + ) + ) + ) + ;;@ ~lib/util/memory.ts:121:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:121:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $56 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $56) + ) + ;;@ ~lib/util/memory.ts:121:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:121:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $57 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $57) + ) + ) + ) + ;;@ ~lib/util/memory.ts:122:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:122:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $58 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $58) + ) + ;;@ ~lib/util/memory.ts:122:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:122:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $59 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $59) + ) + ) + ) + ;;@ ~lib/util/memory.ts:123:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:123:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $60 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $60) + ) + ;;@ ~lib/util/memory.ts:123:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:123:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $61 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $61) + ) + ) + ) + ;;@ ~lib/util/memory.ts:124:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:124:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $62 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $62) + ) + ;;@ ~lib/util/memory.ts:124:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:124:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $63 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $63) + ) + ) + ) + ;;@ ~lib/util/memory.ts:125:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:125:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $64 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $64) + ) + ;;@ ~lib/util/memory.ts:125:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:125:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $65 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $65) + ) + ) + ) + ;;@ ~lib/util/memory.ts:126:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:126:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $66 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $66) + ) + ;;@ ~lib/util/memory.ts:126:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:126:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $67 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $67) + ) + ) + ) + ;;@ ~lib/util/memory.ts:127:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:127:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $68 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $68) + ) + ;;@ ~lib/util/memory.ts:127:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:127:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $69 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $69) + ) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:129:2 + (if + ;;@ ~lib/util/memory.ts:129:6 + (i32.and + (local.get $n) + ;;@ ~lib/util/memory.ts:129:10 + (i32.const 4) + ) + (block + ;;@ ~lib/util/memory.ts:130:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:130:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $70 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $70) + ) + ;;@ ~lib/util/memory.ts:130:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:130:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $71 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $71) + ) + ) + ) + ;;@ ~lib/util/memory.ts:131:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:131:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $72 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $72) + ) + ;;@ ~lib/util/memory.ts:131:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:131:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $73 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $73) + ) + ) + ) + ;;@ ~lib/util/memory.ts:132:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:132:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $74 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $74) + ) + ;;@ ~lib/util/memory.ts:132:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:132:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $75 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $75) + ) + ) + ) + ;;@ ~lib/util/memory.ts:133:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:133:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $76 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $76) + ) + ;;@ ~lib/util/memory.ts:133:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:133:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $77 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $77) + ) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:135:2 + (if + ;;@ ~lib/util/memory.ts:135:6 + (i32.and + (local.get $n) + ;;@ ~lib/util/memory.ts:135:10 + (i32.const 2) + ) + (block + ;;@ ~lib/util/memory.ts:136:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:136:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $78 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $78) + ) + ;;@ ~lib/util/memory.ts:136:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:136:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $79 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $79) + ) + ) + ) + ;;@ ~lib/util/memory.ts:137:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:137:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $80 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $80) + ) + ;;@ ~lib/util/memory.ts:137:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:137:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $81 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $81) + ) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:139:2 + (if + ;;@ ~lib/util/memory.ts:139:6 + (i32.and + (local.get $n) + ;;@ ~lib/util/memory.ts:139:10 + (i32.const 1) + ) + ;;@ ~lib/util/memory.ts:140:4 + (i32.store8 + ;;@ ~lib/util/memory.ts:140:14 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $82 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $82) + ) + ;;@ ~lib/util/memory.ts:140:22 + (i32.load8_u + ;;@ ~lib/util/memory.ts:140:31 + (block (result i32) + (local.set $src + (i32.add + (local.tee $83 + (local.get $src) + ) + (i32.const 1) + ) + ) + (local.get $83) + ) + ) + ) + ) + ) + (func $~lib/memory/memory.copy (param $dst i32) (param $src i32) (param $n i32) + (local $dest i32) + (local $src|4 i32) + (local $n|5 i32) + (local $6 i32) + (local $7 i32) + (local $8 i32) + (local $9 i32) + ;;@ ~lib/memory.ts:28:4 + (block $~lib/util/memory/memmove|inlined.0 + (local.set $dest + ;;@ ~lib/memory.ts:28:12 + (local.get $dst) + ) + (local.set $src|4 + ;;@ ~lib/memory.ts:28:17 + (local.get $src) + ) + (local.set $n|5 + ;;@ ~lib/memory.ts:28:22 + (local.get $n) + ) + ;;@ ~lib/util/memory.ts:147:2 + (if + ;;@ ~lib/util/memory.ts:147:6 + (i32.eq + (local.get $dest) + ;;@ ~lib/util/memory.ts:147:14 + (local.get $src|4) + ) + ;;@ ~lib/util/memory.ts:147:19 + (br $~lib/util/memory/memmove|inlined.0) + ) + (drop + ;;@ ~lib/util/memory.ts:148:6 + (i32.lt_s + (i32.const 0) + ;;@ ~lib/util/memory.ts:148:25 + (i32.const 1) + ) + ) + ;;@ ~lib/util/memory.ts:148:28 + (if + ;;@ ~lib/util/memory.ts:149:8 + (i32.le_u + (i32.sub + (i32.sub + (local.get $src|4) + ;;@ ~lib/util/memory.ts:149:14 + (local.get $dest) + ) + ;;@ ~lib/util/memory.ts:149:21 + (local.get $n|5) + ) + ;;@ ~lib/util/memory.ts:149:26 + (i32.sub + (i32.const 0) + ;;@ ~lib/util/memory.ts:149:28 + (i32.shl + (local.get $n|5) + ;;@ ~lib/util/memory.ts:149:33 + (i32.const 1) + ) + ) + ) + (block + ;;@ ~lib/util/memory.ts:150:6 + (call $~lib/util/memory/memcpy + ;;@ ~lib/util/memory.ts:150:13 + (local.get $dest) + ;;@ ~lib/util/memory.ts:150:19 + (local.get $src|4) + ;;@ ~lib/util/memory.ts:150:24 + (local.get $n|5) + ) + ;;@ ~lib/util/memory.ts:151:6 + (br $~lib/util/memory/memmove|inlined.0) + ) + ) + ;;@ ~lib/util/memory.ts:154:2 + (if + ;;@ ~lib/util/memory.ts:154:6 + (i32.lt_u + (local.get $dest) + ;;@ ~lib/util/memory.ts:154:13 + (local.get $src|4) + ) + (block + (drop + ;;@ ~lib/util/memory.ts:155:8 + (i32.lt_s + (i32.const 0) + ;;@ ~lib/util/memory.ts:155:27 + (i32.const 2) + ) + ) + ;;@ ~lib/util/memory.ts:155:30 + (if + ;;@ ~lib/util/memory.ts:156:10 + (i32.eq + ;;@ ~lib/util/memory.ts:156:11 + (i32.and + (local.get $src|4) + ;;@ ~lib/util/memory.ts:156:17 + (i32.const 7) + ) + ;;@ ~lib/util/memory.ts:156:24 + (i32.and + (local.get $dest) + ;;@ ~lib/util/memory.ts:156:31 + (i32.const 7) + ) + ) + (block + ;;@ ~lib/util/memory.ts:157:8 + (block $while-break|0 + (loop $while-continue|0 + (if + ;;@ ~lib/util/memory.ts:157:15 + (i32.and + (local.get $dest) + ;;@ ~lib/util/memory.ts:157:22 + (i32.const 7) + ) + (block + ;;@ ~lib/util/memory.ts:158:10 + (if + ;;@ ~lib/util/memory.ts:158:14 + (i32.eqz + ;;@ ~lib/util/memory.ts:158:15 + (local.get $n|5) + ) + ;;@ ~lib/util/memory.ts:158:18 + (br $~lib/util/memory/memmove|inlined.0) + ) + ;;@ ~lib/util/memory.ts:159:10 + (local.set $n|5 + (i32.sub + ;;@ ~lib/util/memory.ts:159:12 + (local.get $n|5) + (i32.const 1) + ) + ) + ;;@ ~lib/util/memory.ts:160:10 + (i32.store8 + ;;@ ~lib/util/memory.ts:160:20 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $6 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $6) + ) + ;;@ ~lib/util/memory.ts:160:28 + (i32.load8_u + ;;@ ~lib/util/memory.ts:160:37 + (block (result i32) + (local.set $src|4 + (i32.add + (local.tee $7 + (local.get $src|4) + ) + (i32.const 1) + ) + ) + (local.get $7) + ) + ) + ) + (br $while-continue|0) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:162:8 + (block $while-break|1 + (loop $while-continue|1 + (if + ;;@ ~lib/util/memory.ts:162:15 + (i32.ge_u + (local.get $n|5) + ;;@ ~lib/util/memory.ts:162:20 + (i32.const 8) + ) + (block + ;;@ ~lib/util/memory.ts:163:10 + (i64.store + ;;@ ~lib/util/memory.ts:163:21 + (local.get $dest) + ;;@ ~lib/util/memory.ts:163:27 + (i64.load + ;;@ ~lib/util/memory.ts:163:37 + (local.get $src|4) + ) + ) + ;;@ ~lib/util/memory.ts:164:10 + (local.set $n|5 + (i32.sub + (local.get $n|5) + ;;@ ~lib/util/memory.ts:164:18 + (i32.const 8) + ) + ) + ;;@ ~lib/util/memory.ts:165:10 + (local.set $dest + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:165:18 + (i32.const 8) + ) + ) + ;;@ ~lib/util/memory.ts:166:10 + (local.set $src|4 + (i32.add + (local.get $src|4) + ;;@ ~lib/util/memory.ts:166:18 + (i32.const 8) + ) + ) + (br $while-continue|1) + ) + ) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:170:4 + (block $while-break|2 + (loop $while-continue|2 + (if + ;;@ ~lib/util/memory.ts:170:11 + (local.get $n|5) + (block + ;;@ ~lib/util/memory.ts:171:6 + (i32.store8 + ;;@ ~lib/util/memory.ts:171:16 + (block (result i32) + (local.set $dest + (i32.add + (local.tee $8 + (local.get $dest) + ) + (i32.const 1) + ) + ) + (local.get $8) + ) + ;;@ ~lib/util/memory.ts:171:24 + (i32.load8_u + ;;@ ~lib/util/memory.ts:171:33 + (block (result i32) + (local.set $src|4 + (i32.add + (local.tee $9 + (local.get $src|4) + ) + (i32.const 1) + ) + ) + (local.get $9) + ) + ) + ) + ;;@ ~lib/util/memory.ts:172:6 + (local.set $n|5 + (i32.sub + ;;@ ~lib/util/memory.ts:172:8 + (local.get $n|5) + (i32.const 1) + ) + ) + (br $while-continue|2) + ) + ) + ) + ) + ) + (block + (drop + ;;@ ~lib/util/memory.ts:175:8 + (i32.lt_s + (i32.const 0) + ;;@ ~lib/util/memory.ts:175:27 + (i32.const 2) + ) + ) + ;;@ ~lib/util/memory.ts:175:30 + (if + ;;@ ~lib/util/memory.ts:176:10 + (i32.eq + ;;@ ~lib/util/memory.ts:176:11 + (i32.and + (local.get $src|4) + ;;@ ~lib/util/memory.ts:176:17 + (i32.const 7) + ) + ;;@ ~lib/util/memory.ts:176:24 + (i32.and + (local.get $dest) + ;;@ ~lib/util/memory.ts:176:31 + (i32.const 7) + ) + ) + (block + ;;@ ~lib/util/memory.ts:177:8 + (block $while-break|3 + (loop $while-continue|3 + (if + ;;@ ~lib/util/memory.ts:177:15 + (i32.and + ;;@ ~lib/util/memory.ts:177:16 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:177:23 + (local.get $n|5) + ) + ;;@ ~lib/util/memory.ts:177:28 + (i32.const 7) + ) + (block + ;;@ ~lib/util/memory.ts:178:10 + (if + ;;@ ~lib/util/memory.ts:178:14 + (i32.eqz + ;;@ ~lib/util/memory.ts:178:15 + (local.get $n|5) + ) + ;;@ ~lib/util/memory.ts:178:18 + (br $~lib/util/memory/memmove|inlined.0) + ) + ;;@ ~lib/util/memory.ts:179:10 + (i32.store8 + ;;@ ~lib/util/memory.ts:179:20 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:179:27 + (local.tee $n|5 + (i32.sub + ;;@ ~lib/util/memory.ts:179:29 + (local.get $n|5) + (i32.const 1) + ) + ) + ) + ;;@ ~lib/util/memory.ts:179:32 + (i32.load8_u + ;;@ ~lib/util/memory.ts:179:41 + (i32.add + (local.get $src|4) + ;;@ ~lib/util/memory.ts:179:47 + (local.get $n|5) + ) + ) + ) + (br $while-continue|3) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:181:8 + (block $while-break|4 + (loop $while-continue|4 + (if + ;;@ ~lib/util/memory.ts:181:15 + (i32.ge_u + (local.get $n|5) + ;;@ ~lib/util/memory.ts:181:20 + (i32.const 8) + ) + (block + ;;@ ~lib/util/memory.ts:182:10 + (local.set $n|5 + (i32.sub + (local.get $n|5) + ;;@ ~lib/util/memory.ts:182:15 + (i32.const 8) + ) + ) + ;;@ ~lib/util/memory.ts:183:10 + (i64.store + ;;@ ~lib/util/memory.ts:183:21 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:183:28 + (local.get $n|5) + ) + ;;@ ~lib/util/memory.ts:183:31 + (i64.load + ;;@ ~lib/util/memory.ts:183:41 + (i32.add + (local.get $src|4) + ;;@ ~lib/util/memory.ts:183:47 + (local.get $n|5) + ) + ) + ) + (br $while-continue|4) + ) + ) + ) + ) + ) + ) + ;;@ ~lib/util/memory.ts:187:4 + (block $while-break|5 + (loop $while-continue|5 + (if + ;;@ ~lib/util/memory.ts:187:11 + (local.get $n|5) + (block + ;;@ ~lib/util/memory.ts:188:6 + (i32.store8 + ;;@ ~lib/util/memory.ts:188:16 + (i32.add + (local.get $dest) + ;;@ ~lib/util/memory.ts:188:23 + (local.tee $n|5 + (i32.sub + ;;@ ~lib/util/memory.ts:188:25 + (local.get $n|5) + (i32.const 1) + ) + ) + ) + ;;@ ~lib/util/memory.ts:188:28 + (i32.load8_u + ;;@ ~lib/util/memory.ts:188:37 + (i32.add + (local.get $src|4) + ;;@ ~lib/util/memory.ts:188:43 + (local.get $n|5) + ) + ) + ) + (br $while-continue|5) + ) + ) + ) + ) + ) + ) + ) + ) + (func $~lib/string/String#concat (param $this i32) (param $other i32) (result i32) + (local $thisSize i32) + (local $otherSize i32) + (local $outSize i32) + (local $out i32) + ;;@ ~lib/string.ts:90:4 + (local.set $thisSize + ;;@ ~lib/string.ts:90:26 + (i32.shl + (call $~lib/string/String#get:length + (local.get $this) + ) + ;;@ ~lib/string.ts:90:41 + (i32.const 1) + ) + ) + ;;@ ~lib/string.ts:91:4 + (local.set $otherSize + ;;@ ~lib/string.ts:91:27 + (i32.shl + (call $~lib/string/String#get:length + (local.get $other) + ) + ;;@ ~lib/string.ts:91:43 + (i32.const 1) + ) + ) + ;;@ ~lib/string.ts:92:4 + (local.set $outSize + ;;@ ~lib/string.ts:92:25 + (i32.add + (local.get $thisSize) + ;;@ ~lib/string.ts:92:36 + (local.get $otherSize) + ) + ) + ;;@ ~lib/string.ts:93:4 + (if + ;;@ ~lib/string.ts:93:8 + (i32.eq + (local.get $outSize) + ;;@ ~lib/string.ts:93:19 + (i32.const 0) + ) + ;;@ ~lib/string.ts:93:22 + (return + ;;@ ~lib/string.ts:93:29 + (i32.const 2176) + ) + ) + ;;@ ~lib/string.ts:94:4 + (local.set $out + ;;@ ~lib/string.ts:94:14 + (call $~lib/rt/stub/__new + ;;@ ~lib/string.ts:94:39 + (local.get $outSize) + ;;@ ~lib/string.ts:94:48 + (i32.const 2) + ) + ) + ;;@ ~lib/string.ts:95:4 + (call $~lib/memory/memory.copy + ;;@ ~lib/string.ts:95:16 + (local.get $out) + ;;@ ~lib/string.ts:95:40 + (local.get $this) + ;;@ ~lib/string.ts:95:65 + (local.get $thisSize) + ) + ;;@ ~lib/string.ts:96:4 + (call $~lib/memory/memory.copy + ;;@ ~lib/string.ts:96:16 + (i32.add + (local.get $out) + ;;@ ~lib/string.ts:96:41 + (local.get $thisSize) + ) + ;;@ ~lib/string.ts:96:51 + (local.get $other) + ;;@ ~lib/string.ts:96:77 + (local.get $otherSize) + ) + ;;@ ~lib/string.ts:97:4 + (return + ;;@ ~lib/string.ts:97:11 + (local.get $out) + ) + ) + (func $~lib/string/String.__concat (param $left i32) (param $right i32) (result i32) + ;;@ ~lib/string.ts:86:4 + (return + ;;@ ~lib/string.ts:86:11 + (call $~lib/string/String#concat + (local.get $left) + ;;@ ~lib/string.ts:86:23 + (local.get $right) + ) + ) + ) + (func $main/ascii/main + (local $byte i32) + ;;@ main/ascii.ts:4:4 + (call $~lib/as-warduino/assembly/index/print + ;;@ main/ascii.ts:4:10 + (i32.const 32) + ) + ;;@ main/ascii.ts:5:4 + (local.set $byte + ;;@ main/ascii.ts:5:20 + (i32.const 33) + ) + ;;@ main/ascii.ts:7:4 + (block $while-break|0 + (loop $while-continue|0 + (if + ;;@ main/ascii.ts:7:11 + (i32.ne + (local.get $byte) + ;;@ main/ascii.ts:7:20 + (i32.const 126) + ) + (block + ;;@ main/ascii.ts:8:8 + (call $~lib/as-warduino/assembly/index/print + ;;@ main/ascii.ts:8:14 + (call $~lib/string/String.fromCharCode@varargs + ;;@ main/ascii.ts:8:34 + (local.get $byte) + (block (result i32) + (global.set $~argumentsLength + (i32.const 1) + ) + (i32.const 0) + ) + ) + ) + ;;@ main/ascii.ts:10:8 + (call $~lib/as-warduino/assembly/index/print + ;;@ main/ascii.ts:10:14 + (call $~lib/string/String.__concat + (i32.const 352) + ;;@ main/ascii.ts:10:26 + (call $~lib/number/I32#toString + (local.get $byte) + ;;@ ~lib/number.ts:78:35 + (i32.const 10) + ) + ) + ) + ;;@ main/ascii.ts:11:8 + (call $~lib/as-warduino/assembly/index/print + ;;@ main/ascii.ts:11:14 + (call $~lib/string/String.__concat + (i32.const 2208) + ;;@ main/ascii.ts:11:26 + (call $~lib/number/I32#toString + (local.get $byte) + ;;@ main/ascii.ts:11:40 + (i32.const 16) + ) + ) + ) + ;;@ main/ascii.ts:12:8 + (call $~lib/as-warduino/assembly/index/print + ;;@ main/ascii.ts:12:14 + (call $~lib/string/String.__concat + (i32.const 2256) + ;;@ main/ascii.ts:12:26 + (call $~lib/number/I32#toString + (local.get $byte) + ;;@ main/ascii.ts:12:40 + (i32.const 8) + ) + ) + ) + ;;@ main/ascii.ts:13:8 + (call $~lib/as-warduino/assembly/index/print + ;;@ main/ascii.ts:13:14 + (call $~lib/string/String.__concat + (call $~lib/string/String.__concat + (i32.const 2304) + ;;@ main/ascii.ts:13:26 + (call $~lib/number/I32#toString + (local.get $byte) + ;;@ main/ascii.ts:13:40 + (i32.const 2) + ) + ) + ;;@ main/ascii.ts:13:45 + (i32.const 2352) + ) + ) + ;;@ main/ascii.ts:15:8 + (if + ;;@ main/ascii.ts:15:12 + (i32.eq + (local.get $byte) + ;;@ main/ascii.ts:15:20 + (i32.const 126) + ) + ;;@ main/ascii.ts:16:10 + (block $while-break|1 + (loop $while-continue|1 + (if + ;;@ main/ascii.ts:16:17 + (i32.const 1) + (block + ;;@ main/ascii.ts:17:12 + (br $while-continue|1) + (br $while-continue|1) + ) + ) + ) + (unreachable) + ) + ) + ;;@ main/ascii.ts:21:8 + (local.set $byte + (i32.add + (local.get $byte) + (i32.const 1) + ) + ) + (br $while-continue|0) + ) + ) + ) + ) + ) + (func $~start + (global.set $~lib/rt/stub/startOffset + (i32.sub + (i32.and + (i32.add + (i32.add + (global.get $~lib/memory/__heap_base) + (i32.const 4) + ) + (i32.const 15) + ) + (i32.xor + (i32.const 15) + (i32.const -1) + ) + ) + (i32.const 4) + ) + ) + (global.set $~lib/rt/stub/offset + (global.get $~lib/rt/stub/startOffset) + ) + ) +) diff --git a/tutorials/assemblyscript/bin/main.wasm.map b/tutorials/assemblyscript/bin/main.wasm.map new file mode 100644 index 000000000..1fac310c4 --- /dev/null +++ b/tutorials/assemblyscript/bin/main.wasm.map @@ -0,0 +1 @@ +{"version":3,"sources":["~lib/rt/common.ts","~lib/as-warduino/assembly/index.ts","main/ascii.ts","~lib/util/number.ts","~lib/util/math.ts","~lib/util/string.ts","~lib/shared/runtime.ts","~lib/util/sort.ts","~lib/string.ts","~lib/rt/stub.ts","~lib/util/error.ts","~lib/number.ts","~lib/memory.ts","~lib/util/memory.ts"],"names":[],"mappings":"0JQgqBmB,EADA,EAC4D,EAA5C,OAChB,EAAb,IACO,EAAS,EAAT,GAAP,EAC0B,EAAf,GACL,EAAK,GAAL,GAEoB,EAAlB,CAAJ,EACA,EAAU,IACD,EAAK,GAAL,GACT,EAAU,IAEL,EAAK,IAAL,CAAgB,IAAjB,CAA2B,EAAS,EAAT,CAAa,EAAb,CAA3B,CAAJ,EACsB,EAAf,GAA4B,IAA5B,CAAuC,IAAxC,CAAJ,EACE,EAAU,GAAV,EAAa,EAAU,GAAV,MAIjB,EAAU,OAEZ,EAAU,GAAV,OAEK,QChmBP,EAAO,MAAP,CAAJ,EAA2C,eACP,EAAlB,GAtDd,EAAO,MAAP,CAAJ,EAA0C,cAC9B,EAAZ,EACU,EAAS,EAAT,CAEM,EAVP,KAAmC,EAApC,CAAgD,EAAjD,CAUe,EAAN,CAtBZ,EAFc,EACA,EAAsB,EAAtB,CAA4B,EAA7B,CAAwC,EAAzC,CACA,EAAZ,CAAJ,EAEwB,EADI,EAAY,EAAZ,CAAwB,IAAxB,CAAkC,IAAnC,CAAgD,EAAvD,QAEF,CAAZ,EAA2B,EAA3B,CAAJ,EACkB,EAAZ,EAA2B,EAA3B,CAAJ,MAGK,EAAT,EAgBA,EAAe,KACR,EAiD+B,UAEtC,OACA,EAAc,KACd,EAAgB,KACT,EAAM,EAAN,ID1CqB,EAA0B,EAA7C,IAAuE,EAAvE,OA+oBQ,EAAO,EAAc,EAAd,CAAP,CAAb,EACa,EAAb,EACA,EAAO,EAAM,EAAN,GACmB,EAAf,GACL,EAAK,GAAL,CAAJ,EACY,EAAQ,EAAlB,GACA,OAEsB,EAAlB,CAAJ,KACS,EAAK,GAAL,GAGE,EAFF,EAAM,EAAN,CAAU,GAEU,CADpB,EAAK,EAAL,CAAU,GACA,CAAM,EAAN,EAAnB,GACA,EAAU,IASJ,EAAK,IAAL,CAAe,EAAM,EAAN,CAAU,EAAV,CAAf,CADD,EAAK,IAAL,CAAgB,IAAjB,EAAJ,EAE4B,EAAf,GACJ,EAAK,IAAL,CAAgB,IAAjB,CAAJ,EAMa,EALM,EAAK,GAAL,CAAgB,EAAjB,CAAX,KAAmC,EAAK,GAAL,CAAnC,CAII,EAAW,EAAX,CAAgB,GACN,CAAM,EAAN,CAFV,EAAM,EAAN,CAAW,EAAX,CAAgB,GAEK,CAAM,EAAN,CAAX,CAHV,EAAM,EAAN,CAAW,EAAX,CAAgB,GAGgB,CAAM,EAAN,CAAtB,CAJV,EAAM,EAAN,CAAW,GAI+B,CAAhC,CAAnB,GACA,EAAU,GAAV,EAAa,EAAO,GAAP,MAYR,EAHF,EAAM,EAAN,CAAW,GAGS,CAFpB,EAAM,EAAN,CAAW,EAAX,CAAgB,GAEN,CAAM,EAAN,EAAnB,GACU,EAFD,EAAW,EAAX,CAAgB,GAEP,CAAlB,GACA,EAAU,OAEZ,EAAO,GAAP,QAGoB,EADtB,QP5nB6B,EOmkBW,EAAwC,EAAtE,EAAV,EACa,EAAwB,IAAY,IAC1C,EPrkB0D,EAAvB,YE6P1C,EAAQ,EAAR,CAAa,EAAQ,EAAR,CAAb,CAAJ,EACuB,eAElB,EAAD,CAAJ,SAGmB,EAAD,GADN,EAAU,EAAV,CAAiB,EAAlB,CACP,GAAJ,EAGI,EAAS,EAAT,CAAJ,EACgC,EAtPJ,EAAb,CAAJ,GAEQ,EAAS,IAAb,CAAJ,GAA8B,EAAS,GAAb,CAA1B,CAHL,EAAQ,GAAR,CAAJ,CAOiB,EAAS,IAAb,CAAJ,GAEQ,EAAS,MAAb,CAAJ,GAAmC,EAAS,KAAb,CAA/B,CAHL,EAAQ,KAAR,CAAJ,CAPE,EAAQ,IAAR,CAAJ,CAyPkC,EAAY,EAAZ,CAAiB,EAAlB,CAAwB,EAAjD,EACU,EAAyB,EA7FpB,GAxBvB,EAKa,EADX,KACqB,EAAU,EAAV,CAAV,CAHG,EAAM,EAG6B,CAAd,GAAnC,GAJQ,EAAM,EAER,CAGC,MAgHE,EAAS,EAAT,CAAJ,EACW,EAAS,EAAJ,CAAL,CAAmB,EAAnB,CAAwB,EAAzB,CACiB,EAAY,EAAZ,CAAiB,EAAlB,CAAwB,EAAjD,EACU,EAAyB,EAvFpB,GAxBvB,EAIa,EADX,KACqB,EAAU,EAAV,CAAV,CAFI,EAAS,EADhB,EAAM,EAAN,CAAa,EAAb,CACsB,EAAI,EAAJ,CAAzB,CAAL,EAEmC,CAAnC,GAEA,EAAQ,GACD,QA0GK,EAAZ,EACyB,GAvQV,EAAV,CAAoB,EAApB,GAyCG,EAAc,GAAT,CAAL,CAAuB,EAAc,EAAT,CAAL,CAAxB,CAA+C,EAA/C,MAEC,CAAe,IAAc,IACvC,EAAO,EAAO,EAAP,GACL,EAAO,GAAP,EACA,EAAK,GAAL,EACA,EAAM,GAAN,MAEF,EAAO,EAAO,EAAP,GACL,EAAO,GAAP,EACA,WAEK,EAAI,EAAJ,IAmNuC,EAAZ,CAAiB,EAAlB,CAAwB,EAAjD,EACU,EAAyB,EAAzB,KAA+B,KAhEtC,CAAX,EACK,EAAS,EAAQ,EAAR,CAAT,CAAL,EASE,EAGa,EAFX,KAEqB,EAAU,EAAV,CAAV,GAAyD,EAD5D,EAAM,EAAN,CACwD,IAAZ,CAAyB,EAAzB,CAAP,IAAV,GAAnC,GACM,SAZY,EAAJ,CAAa,GAAjB,CAAZ,EACW,EAAO,EAAP,CAAX,EACA,EAEa,EADX,KACqB,EAAU,EAAV,CAAV,CAA+C,EAAM,GAAZ,CAAqB,EAArB,CAAP,IAAV,GAAnC,GACA,EAAQ,GACD,WA0DP,EAAJ,EAAqB,EAAwB,EAAnC,IACH,KQ7TS,EAAM,EAAb,OCnDP,EAAkB,ICuHhB,EAAQ,EAAR,CAAJ,EAOI,EAAO,EAAP,CAAJ,EAgBE,EAAO,IACK,SAAiB,mBACzB,KAAF,OAeF,EAAO,IACc,KAAF,EAAP,GAAqB,EAAM,EAAN,CAAT,GAAtB,cLtGK,EAIe,IAAe,EAAf,GAGG,KAFF,IAAgB,EAAhB,CACS,EAAX,GACjB,IAC+B,EAAS,EAAlC,EACE,EAAwB,EAAyB,EAA7D,EACY,EAAyB,EAAzB,CAAmC,EAA0B,EAAzE,GAVO,ONlFD,GAAN,EACgB,EAAhB,EAEA,EAAO,EAAS,GAAT,GMS4B,EAAkB,EAA3C,EACC,EAAwB,EAAnC,GAEO,INTG,GAAY,ESoES,ETpET,EAAZ,EAAN,EACM,GAAY,EAAc,EAAd,EAAZ,EAAN,EACM,GAAY,EAAc,EAAd,EAAZ,EAAN,EACM,GAAY,EAAc,EAAd,EAAZ,EAA+B,GAA/B,EAAN,EAEI,EAAQ,GAAR,CAAJ,SAMA","sourceRoot":"./main","sourcesContent":["// Alignment guarantees\n\n// @ts-ignore: decorator\n@inline export const AL_BITS: u32 = 4; // 16 bytes to fit up to v128\n// @ts-ignore: decorator\n@inline export const AL_SIZE: usize = 1 << AL_BITS;\n// @ts-ignore: decorator\n@inline export const AL_MASK: usize = AL_SIZE - 1;\n\n// Extra debugging\n\n// @ts-ignore: decorator\n@inline export const DEBUG = true;\n// @ts-ignore: decorator\n@inline export const TRACE = false;\n// @ts-ignore: decorator\n@inline export const RTRACE = isDefined(ASC_RTRACE);\n// @ts-ignore: decorator\n@inline export const PROFILE = isDefined(ASC_PROFILE);\n\n// Memory manager\n\n// ╒════════════ Memory manager block layout (32-bit) ═════════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤\n// │ MM info │ -4\n// ╞>ptr═══════════════════════════════════════════════════════════╡\n// │ ... │\n@unmanaged export class BLOCK {\n /** Memory manager info. */\n mmInfo: usize;\n}\n\n/** Overhead of a memory manager block. */\n// @ts-ignore: decorator\n@inline export const BLOCK_OVERHEAD: usize = offsetof();\n\n/** Maximum size of a memory manager block's payload. */\n// @ts-ignore: decorator\n@inline export const BLOCK_MAXSIZE: usize = (1 << 30) - BLOCK_OVERHEAD;\n\n// Garbage collector\n\n// ╒══════════ Garbage collector object layout (32-bit) ═══════════╕\n// 3 2 1\n// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 bits\n// ├─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴─┤\n// │ Memory manager block │ -20\n// ╞═══════════════════════════════════════════════════════════════╡\n// │ GC info │ -16\n// ├───────────────────────────────────────────────────────────────┤\n// │ GC info │ -12\n// ├───────────────────────────────────────────────────────────────┤\n// │ RT id │ -8\n// ├───────────────────────────────────────────────────────────────┤\n// │ RT size │ -4\n// ╞>ptr═══════════════════════════════════════════════════════════╡\n// │ ... │\n@unmanaged export class OBJECT extends BLOCK {\n /** Garbage collector info. */\n gcInfo: u32;\n /** Garbage collector info. */\n gcInfo2: u32;\n /** Runtime class id. */\n rtId: u32;\n /** Runtime object size. */\n rtSize: u32;\n}\n\n/** Overhead of a garbage collector object. Excludes memory manager block overhead. */\n// @ts-ignore: decorator\n@inline export const OBJECT_OVERHEAD: usize = (offsetof() - BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK;\n\n/** Maximum size of a garbage collector object's payload. */\n// @ts-ignore: decorator\n@inline export const OBJECT_MAXSIZE: usize = BLOCK_MAXSIZE - OBJECT_OVERHEAD;\n\n/** Total of memory manager and garbage collector overhead. */\n// @ts-ignore: decorator\n@inline export const TOTAL_OVERHEAD: usize = BLOCK_OVERHEAD + OBJECT_OVERHEAD;\n","/**\n * as-warduino - WARDuino primitives library\n *\n *
\n *\n * WARDuino is a dynamic WebAssembly runtime for embedded devices, that\n * provides primitives to access hardware and IoT specific functionality.\n *\n * The `as-warduino` package allows using these primitives from AssemblyScript.\n *\n *
\n *\n * # Usage\n *\n * ```ts\n * import {pinMode, PinMode, PinVoltage, digitalWrite, delay} from \"as-warduino\";\n * \n * export function main(): void {\n * let led = 26;\n * pinMode(led, PinMode.OUTPUT);\n * \n * let pause: u32 = 1000;\n * while (true) {\n * digitalWrite(led, PinVoltage.HIGH);\n * delay(pause);\n * digitalWrite(led, PinVoltage.LOW);\n * delay(pause);\n * }\n * }\n * ```\n */\n\nimport * as ward from \"./warduino\";\n\n/** Returns the number of milliseconds passed since the current program started to run. */\nexport function millis(): u32 {\n return ward._millis();\n}\n/** Pauses the program for the amount of time (in milliseconds). */\nexport function delay(ms: u32): void {\n ward._delay(ms);\n}\n\n/** Pauses the program for the amount of time (in seconds). */\nexport function sleep(s: u32): void {\n ward._delay(s * 1000);\n}\n\n/** Reads the value from the specified analog pin. */\nexport function analogRead(pin: u32): i32 {\n return ward._analog_read(pin);\n}\n\n/** Write the value to the specified analog pin. */\nexport function analogWrite(pin: u32, signal: u32): void {\n ward._analog_write(pin, signal);\n}\n\nexport function analogSetup(channel: u32, frequency: u32, timer: u32): void {\n ward._analog_setup(channel, frequency, timer);\n}\n\nexport function analogAttach(pin: u32, channel: u32): void {\n ward._analog_attach(pin, channel);\n}\n\nexport function analogDuty(channel: u32, value: i32, max: u32): void {\n ward._analog_duty(channel, value, max);\n}\n\n/** The voltage of a digital pin. */\nexport enum PinVoltage {\n /** Low voltage on a digital I/O pin */\n LOW = 0,\n /** High voltage on a digital I/O pin */\n HIGH = 1,\n}\n\n/** The mode of a pin interrupt. */\nexport enum InterruptMode {\n /** Changing edge on a digital I/O pin */\n CHANGED = 1,\n /** Falling edge on a digital I/O pin */\n FALLING = 2,\n /** Rising edge on a digital I/O pin */\n RISING = 3,\n}\n\n/** The mode of a digital I/O pin. */\nexport enum PinMode {\n /** Input mode for digital pins */\n INPUT = 0x0,\n /** Output mode for digital pins */\n OUTPUT = 0x2,\n}\n\n/** Configures the [PinMode] of the specified pin. */\nexport function pinMode(pin: u32, mode: PinMode): void {\n ward._pin_mode(pin, mode);\n}\n\n/** Write the voltage to a specified digital pin, either [HIGH](PinVoltage) or [LOW](PinVoltage). */\nexport function digitalWrite(pin: u32, value: PinVoltage): void {\n ward._digital_write(pin, value);\n}\n\n/** Reads the value from a specified digital pin, either [HIGH](PinVoltage) or [LOW](PinVoltage). */\nexport function digitalRead(pin: u32): PinVoltage {\n return ward._digital_read(pin);\n}\n\n/** Subscribe a callback function to an interrupt on the given pin. */\nexport function interruptOn(pin: u32, mode: InterruptMode, fn: (topic: string, payload: string) => void): void {\n ward._subscribe_interrupt(pin, fn, mode);\n}\n\n/** Print a string to the serial port. */\nexport function print(text: string): void {\n ward._print(String.UTF8.encode(text, true), String.UTF8.byteLength(text, true));\n}\n\nexport namespace WiFi {\n export enum Status {\n /** No Wi-Fi hardware found */\n NoShield = 255,\n /** Wi-Fi is in process of changing between statuses */\n Idle = 0,\n /** Configured SSID cannot be reached */\n SsidUnavailable = 1,\n /** */\n ScanCompleted = 2,\n /** Successful connection is established */\n Connected = 3,\n /** Failed to connect */\n ConnectFailed = 4,\n /** No longer connected */\n ConnectionLost = 5,\n /** Module is not configured in station mode */\n Disconnected = 6,\n }\n\n /** Connect to Wi-Fi network with SSID and password. */\n function connect(ssid: string, password: string): void {\n ward._wifi_connect(String.UTF8.encode(ssid, true), String.UTF8.byteLength(ssid, true),\n String.UTF8.encode(password, true), String.UTF8.byteLength(password, true));\n }\n\n /** Returns the status of the Wi-Fi connection of the board. */\n function status(): Status {\n return ward._wifi_status();\n }\n\n /** Returns whether the board si still connected to Wi-Fi. */\n function connected(): bool {\n return status() === Status.Connected;\n }\n\n /** Returns the local IP address of the board. */\n function localip(): string {\n let localip = new ArrayBuffer(20);\n ward._wifi_localip(localip, localip.byteLength);\n return String.UTF8.decode(localip, true);\n }\n}\n\nexport namespace MQTT {\n export enum Status {\n /** The server didn't respond within the keepalive time */\n ConnectionTimeout = -4,\n /** The network connection was broken */\n ConnectionLost = -3,\n /** The network connection failed */\n ConnectFailed = -2,\n /** The client is disconnected cleanly */\n Disconnected = -1,\n /** The client is connected */\n Connected = 0,\n /** the server doesn't support the requested version of MQTT */\n ConnectBadProtocol = 1,\n /** The server rejected the client identifier */\n ConnectBadClientId = 2,\n /** The server was unable to accept the connection */\n ConnectUnavailable = 3,\n /** The username/password were rejected */\n ConnectBadCredentials = 4,\n /** The client was not authorized to connect */\n ConnectUnauthorized = 5,\n }\n\n /** Configure an MQTT broker. */\n function configureBroker(server: string, port: u32): void {\n ward._mqtt_init(String.UTF8.encode(server, true), String.UTF8.byteLength(server, true), port);\n }\n\n /** Connect to the Configured MQTT broker with client_id. */\n function connect(client_id: string): i32 {\n return ward._mqtt_connect(String.UTF8.encode(client_id, true), String.UTF8.byteLength(client_id, true));\n }\n\n /** Returns whether the board is still connected to the MQTT broker. */\n function connected(): bool {\n return status() === Status.Connected;\n }\n\n /** Returns the status of the connection to the MQTT broker. */\n function status(): Status {\n return ward._mqtt_state();\n }\n\n /** Publish a message on an MQTT topic. */\n function publish(topic: string, payload: string): i32 {\n return ward._mqtt_publish(String.UTF8.encode(topic, true), String.UTF8.byteLength(topic, true), String.UTF8.encode(payload, true), String.UTF8.byteLength(payload, true));\n }\n\n /** Subscribe a callback function to an MQTT topic. */\n function subscribe(topic: string, fn: (topic: string, payload: string) => void): i32 {\n return ward._mqtt_subscribe(topic, fn);\n }\n\n /** Unsubscribe a callback function from an MQTT topic. */\n function unsubscribe(topic: string, fn: (topic: string, payload: string) => void): i32 {\n return ward._mqtt_unsubscribe(topic, fn);\n }\n\n /** Check for messages from the MQTT broker. */\n function loop(): i32 {\n return ward._mqtt_loop();\n }\n}\n\nconst buffersizeMaximum: u32 = 1000;\n\nexport namespace HTTP {\n class PostOptions {\n url: string;\n body: string;\n content_type: string;\n authorization: string;\n\n constructor(url: string, body: string, content_type: string, authorization: string) {\n this.url = url; this.body = body; this.content_type = content_type; this.authorization = authorization;\n }\n }\n\n /** Send an HTTP GET request. The response is written to an ArrayBuffer. */\n function get(url: string): string {\n const response: ArrayBuffer = new ArrayBuffer(buffersizeMaximum);\n ward._http_get(String.UTF8.encode(url, true), String.UTF8.byteLength(url, true), response, response.byteLength);\n return String.UTF8.decode(response);\n }\n\n /** Send an HTTP POST request. The response is written to an ArrayBuffer. */\n function post(options: PostOptions): string {\n const response: ArrayBuffer = new ArrayBuffer(buffersizeMaximum);\n ward._http_post(String.UTF8.encode(options.url, true), String.UTF8.byteLength(options.url, true),\n String.UTF8.encode(options.body, true), String.UTF8.byteLength(options.body, true),\n String.UTF8.encode(options.content_type, true), String.UTF8.byteLength(options.content_type, true),\n String.UTF8.encode(options.authorization, true), String.UTF8.byteLength(options.authorization, true),\n response, response.byteLength);\n return String.UTF8.decode(response);\n }\n}\n","import {print} from \"as-warduino/assembly\";\n\nexport function main(): void {\n print(\"ASCII Table ~ Character Map\\n\");\n let byte: i32 = 33;\n\n while (byte !== 126) {\n print(String.fromCharCode(byte));\n\n print(\", dec: \" + byte.toString());\n print(\", hex: \" + byte.toString(16));\n print(\", oct: \" + byte.toString(8));\n print(\", bin: \" + byte.toString(2) + \"\\n\");\n\n if (byte == 126) {\n while (true) {\n continue;\n }\n }\n\n byte++;\n }\n}\n","/// \n\nimport { idof } from \"../builtins\";\nimport { CharCode } from \"./string\";\n\n// @ts-ignore: decorator\n@inline\nexport const MAX_DOUBLE_LENGTH = 28;\n\n// @ts-ignore: decorator\n@lazy @inline const POWERS10 = memory.data([\n 1,\n 10,\n 100,\n 1000,\n 10000,\n 100000,\n 1000000,\n 10000000,\n 100000000,\n 1000000000\n]);\n\n/*\n Lookup table for pairwise char codes in range [0-99]\n\n \"00\", \"01\", \"02\", \"03\", \"04\", \"05\", \"06\", \"07\", \"08\", \"09\",\n \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\",\n \"20\", \"21\", \"22\", \"23\", \"24\", \"25\", \"26\", \"27\", \"28\", \"29\",\n \"30\", \"31\", \"32\", \"33\", \"34\", \"35\", \"36\", \"37\", \"38\", \"39\",\n \"40\", \"41\", \"42\", \"43\", \"44\", \"45\", \"46\", \"47\", \"48\", \"49\",\n \"50\", \"51\", \"52\", \"53\", \"54\", \"55\", \"56\", \"57\", \"58\", \"59\",\n \"60\", \"61\", \"62\", \"63\", \"64\", \"65\", \"66\", \"67\", \"68\", \"69\",\n \"70\", \"71\", \"72\", \"73\", \"74\", \"75\", \"76\", \"77\", \"78\", \"79\",\n \"80\", \"81\", \"82\", \"83\", \"84\", \"85\", \"86\", \"87\", \"88\", \"89\",\n \"90\", \"91\", \"92\", \"93\", \"94\", \"95\", \"96\", \"97\", \"98\", \"99\"\n*/\n// @ts-ignore: decorator\n@lazy @inline const DIGITS = memory.data([\n 0x00300030, 0x00310030, 0x00320030, 0x00330030, 0x00340030,\n 0x00350030, 0x00360030, 0x00370030, 0x00380030, 0x00390030,\n 0x00300031, 0x00310031, 0x00320031, 0x00330031, 0x00340031,\n 0x00350031, 0x00360031, 0x00370031, 0x00380031, 0x00390031,\n 0x00300032, 0x00310032, 0x00320032, 0x00330032, 0x00340032,\n 0x00350032, 0x00360032, 0x00370032, 0x00380032, 0x00390032,\n 0x00300033, 0x00310033, 0x00320033, 0x00330033, 0x00340033,\n 0x00350033, 0x00360033, 0x00370033, 0x00380033, 0x00390033,\n 0x00300034, 0x00310034, 0x00320034, 0x00330034, 0x00340034,\n 0x00350034, 0x00360034, 0x00370034, 0x00380034, 0x00390034,\n 0x00300035, 0x00310035, 0x00320035, 0x00330035, 0x00340035,\n 0x00350035, 0x00360035, 0x00370035, 0x00380035, 0x00390035,\n 0x00300036, 0x00310036, 0x00320036, 0x00330036, 0x00340036,\n 0x00350036, 0x00360036, 0x00370036, 0x00380036, 0x00390036,\n 0x00300037, 0x00310037, 0x00320037, 0x00330037, 0x00340037,\n 0x00350037, 0x00360037, 0x00370037, 0x00380037, 0x00390037,\n 0x00300038, 0x00310038, 0x00320038, 0x00330038, 0x00340038,\n 0x00350038, 0x00360038, 0x00370038, 0x00380038, 0x00390038,\n 0x00300039, 0x00310039, 0x00320039, 0x00330039, 0x00340039,\n 0x00350039, 0x00360039, 0x00370039, 0x00380039, 0x00390039\n]);\n\n// Lookup table for pairwise char codes in range [0x00-0xFF]\n// @ts-ignore: decorator\n@lazy @inline const HEX_DIGITS =\n\"000102030405060708090a0b0c0d0e0f\\\n101112131415161718191a1b1c1d1e1f\\\n202122232425262728292a2b2c2d2e2f\\\n303132333435363738393a3b3c3d3e3f\\\n404142434445464748494a4b4c4d4e4f\\\n505152535455565758595a5b5c5d5e5f\\\n606162636465666768696a6b6c6d6e6f\\\n707172737475767778797a7b7c7d7e7f\\\n808182838485868788898a8b8c8d8e8f\\\n909192939495969798999a9b9c9d9e9f\\\na0a1a2a3a4a5a6a7a8a9aaabacadaeaf\\\nb0b1b2b3b4b5b6b7b8b9babbbcbdbebf\\\nc0c1c2c3c4c5c6c7c8c9cacbcccdcecf\\\nd0d1d2d3d4d5d6d7d8d9dadbdcdddedf\\\ne0e1e2e3e4e5e6e7e8e9eaebecedeeef\\\nf0f1f2f3f4f5f6f7f8f9fafbfcfdfeff\";\n\n// @ts-ignore: decorator\n@lazy @inline const ANY_DIGITS = \"0123456789abcdefghijklmnopqrstuvwxyz\";\n\n// @ts-ignore: decorator\n@lazy @inline const EXP_POWERS = memory.data([/* eslint-disable indent */\n -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980,\n -954, -927, -901, -874, -847, -821, -794, -768, -741, -715,\n -688, -661, -635, -608, -582, -555, -529, -502, -475, -449,\n -422, -396, -369, -343, -316, -289, -263, -236, -210, -183,\n -157, -130, -103, -77, -50, -24, 3, 30, 56, 83,\n 109, 136, 162, 189, 216, 242, 269, 295, 322, 348,\n 375, 402, 428, 455, 481, 508, 534, 561, 588, 614,\n 641, 667, 694, 720, 747, 774, 800, 827, 853, 880,\n 907, 933, 960, 986, 1013, 1039, 1066\n/* eslint-enable indent */]);\n\n// 1e-348, 1e-340, ..., 1e340\n// @ts-ignore: decorator\n@lazy @inline const FRC_POWERS = memory.data([\n 0xFA8FD5A0081C0288, 0xBAAEE17FA23EBF76, 0x8B16FB203055AC76, 0xCF42894A5DCE35EA,\n 0x9A6BB0AA55653B2D, 0xE61ACF033D1A45DF, 0xAB70FE17C79AC6CA, 0xFF77B1FCBEBCDC4F,\n 0xBE5691EF416BD60C, 0x8DD01FAD907FFC3C, 0xD3515C2831559A83, 0x9D71AC8FADA6C9B5,\n 0xEA9C227723EE8BCB, 0xAECC49914078536D, 0x823C12795DB6CE57, 0xC21094364DFB5637,\n 0x9096EA6F3848984F, 0xD77485CB25823AC7, 0xA086CFCD97BF97F4, 0xEF340A98172AACE5,\n 0xB23867FB2A35B28E, 0x84C8D4DFD2C63F3B, 0xC5DD44271AD3CDBA, 0x936B9FCEBB25C996,\n 0xDBAC6C247D62A584, 0xA3AB66580D5FDAF6, 0xF3E2F893DEC3F126, 0xB5B5ADA8AAFF80B8,\n 0x87625F056C7C4A8B, 0xC9BCFF6034C13053, 0x964E858C91BA2655, 0xDFF9772470297EBD,\n 0xA6DFBD9FB8E5B88F, 0xF8A95FCF88747D94, 0xB94470938FA89BCF, 0x8A08F0F8BF0F156B,\n 0xCDB02555653131B6, 0x993FE2C6D07B7FAC, 0xE45C10C42A2B3B06, 0xAA242499697392D3,\n 0xFD87B5F28300CA0E, 0xBCE5086492111AEB, 0x8CBCCC096F5088CC, 0xD1B71758E219652C,\n 0x9C40000000000000, 0xE8D4A51000000000, 0xAD78EBC5AC620000, 0x813F3978F8940984,\n 0xC097CE7BC90715B3, 0x8F7E32CE7BEA5C70, 0xD5D238A4ABE98068, 0x9F4F2726179A2245,\n 0xED63A231D4C4FB27, 0xB0DE65388CC8ADA8, 0x83C7088E1AAB65DB, 0xC45D1DF942711D9A,\n 0x924D692CA61BE758, 0xDA01EE641A708DEA, 0xA26DA3999AEF774A, 0xF209787BB47D6B85,\n 0xB454E4A179DD1877, 0x865B86925B9BC5C2, 0xC83553C5C8965D3D, 0x952AB45CFA97A0B3,\n 0xDE469FBD99A05FE3, 0xA59BC234DB398C25, 0xF6C69A72A3989F5C, 0xB7DCBF5354E9BECE,\n 0x88FCF317F22241E2, 0xCC20CE9BD35C78A5, 0x98165AF37B2153DF, 0xE2A0B5DC971F303A,\n 0xA8D9D1535CE3B396, 0xFB9B7CD9A4A7443C, 0xBB764C4CA7A44410, 0x8BAB8EEFB6409C1A,\n 0xD01FEF10A657842C, 0x9B10A4E5E9913129, 0xE7109BFBA19C0C9D, 0xAC2820D9623BF429,\n 0x80444B5E7AA7CF85, 0xBF21E44003ACDD2D, 0x8E679C2F5E44FF8F, 0xD433179D9C8CB841,\n 0x9E19DB92B4E31BA9, 0xEB96BF6EBADF77D9, 0xAF87023B9BF0EE6B\n]);\n\n// @ts-ignore: decorator\n@inline\nexport function isPowerOf2(value: T): bool {\n return popcnt(value) == 1;\n}\n\n// Count number of decimals for u32 values\n// In our case input value always non-zero so we can simplify some parts\nexport function decimalCount32(value: u32): u32 {\n if (value < 100000) {\n if (value < 100) {\n return 1 + u32(value >= 10);\n } else {\n return 3 + u32(value >= 10000) + u32(value >= 1000);\n }\n } else {\n if (value < 10000000) {\n return 6 + u32(value >= 1000000);\n } else {\n return 8 + u32(value >= 1000000000) + u32(value >= 100000000);\n }\n }\n}\n\n// Count number of decimals for u64 values\n// In our case input value always greater than 2^32-1 so we can skip some parts\nexport function decimalCount64High(value: u64): u32 {\n if (value < 1000000000000000) {\n if (value < 1000000000000) {\n return 10 + u32(value >= 100000000000) + u32(value >= 10000000000);\n } else {\n return 13 + u32(value >= 100000000000000) + u32(value >= 10000000000000);\n }\n } else {\n if (value < 100000000000000000) {\n return 16 + u32(value >= 10000000000000000);\n } else {\n return 18 + u32(value >= 10000000000000000000) + u32(value >= 1000000000000000000);\n }\n }\n}\n\nfunction ulog_base(num: u64, base: i32): u32 {\n if (isPowerOf2(base)) {\n return (63 - clz(num)) / (31 - clz(base)) + 1;\n }\n let b64 = u64(base), b = b64, e: u32 = 1;\n while (num >= b) {\n num /= b;\n b *= b;\n e <<= 1;\n }\n while (num >= 1) {\n num /= b64;\n e++;\n }\n return e - 1;\n}\n\nfunction utoa32_dec_lut(buffer: usize, num: u32, offset: usize): void {\n while (num >= 10000) {\n // in most VMs i32/u32 div and modulo by constant can be shared and simplificate\n let t = num / 10000;\n let r = num % 10000;\n num = t;\n\n let d1 = r / 100;\n let d2 = r % 100;\n\n let digits1 = load(DIGITS + (d1 << alignof()));\n let digits2 = load(DIGITS + (d2 << alignof()));\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32));\n }\n\n if (num >= 100) {\n let t = num / 100;\n let d1 = num % 100;\n num = t;\n offset -= 2;\n let digits = load(DIGITS + (d1 << alignof()));\n store(buffer + (offset << 1), digits);\n }\n\n if (num >= 10) {\n offset -= 2;\n let digits = load(DIGITS + (num << alignof()));\n store(buffer + (offset << 1), digits);\n } else {\n offset -= 1;\n let digit = CharCode._0 + num;\n store(buffer + (offset << 1), digit);\n }\n}\n\nfunction utoa64_dec_lut(buffer: usize, num: u64, offset: usize): void {\n while (num >= 100000000) {\n let t = num / 100000000;\n let r = (num - t * 100000000);\n num = t;\n\n let b = r / 10000;\n let c = r % 10000;\n\n let b1 = b / 100;\n let b2 = b % 100;\n let c1 = c / 100;\n let c2 = c % 100;\n\n let digits1 = load(DIGITS + (c1 << alignof()));\n let digits2 = load(DIGITS + (c2 << alignof()));\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32));\n\n digits1 = load(DIGITS + (b1 << alignof()));\n digits2 = load(DIGITS + (b2 << alignof()));\n\n offset -= 4;\n store(buffer + (offset << 1), digits1 | (digits2 << 32));\n }\n\n utoa32_dec_lut(buffer, num, offset);\n}\n\nfunction utoa_hex_lut(buffer: usize, num: u64, offset: usize): void {\n const lut = changetype(HEX_DIGITS);\n while (offset >= 2) {\n offset -= 2;\n store(\n buffer + (offset << 1),\n load(lut + ((num & 0xFF) << alignof()))\n );\n num >>= 8;\n }\n if (offset & 1) {\n store(buffer, load(lut + (num << 6)));\n }\n}\n\nfunction utoa_dec_simple(buffer: usize, num: T, offset: usize): void {\n do {\n let t = num / 10;\n let r = (num % 10);\n num = changetype(t);\n offset--;\n store(buffer + (offset << 1), CharCode._0 + r);\n } while (num);\n}\n\nfunction utoa_hex_simple(buffer: usize, num: T, offset: usize): void {\n do {\n let d = num & 0x0F | CharCode._0;\n d += select(0x27, 0, d > CharCode._9);\n offset--;\n store(buffer + (offset << 1), d);\n // @ts-ignore: type\n num >>= 4;\n } while (num);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function utoa32_dec_core(buffer: usize, num: u32, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_dec_simple(buffer, num, offset);\n } else {\n utoa32_dec_lut(buffer, num, offset);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction utoa32_hex_core(buffer: usize, num: u32, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_hex_simple(buffer, num, offset);\n } else {\n utoa_hex_lut(buffer, num, offset);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction utoa64_dec_core(buffer: usize, num: u64, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_dec_simple(buffer, num, offset);\n } else {\n utoa64_dec_lut(buffer, num, offset);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction utoa64_hex_core(buffer: usize, num: u64, offset: usize): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n utoa_hex_simple(buffer, num, offset);\n } else {\n utoa_hex_lut(buffer, num, offset);\n }\n}\n\nfunction utoa64_any_core(buffer: usize, num: u64, offset: usize, radix: i32): void {\n const lut = changetype(ANY_DIGITS);\n let base = u64(radix);\n if ((radix & (radix - 1)) == 0) { // for radix which pow of two\n let shift = u64(ctz(radix) & 7);\n let mask = base - 1;\n do {\n offset--;\n store(buffer + (offset << 1), load(lut + (usize(num & mask) << 1)));\n num >>= shift;\n } while (num);\n } else {\n do {\n offset--;\n let q = num / base;\n store(buffer + (offset << 1), load(lut + (usize(num - q * base) << 1)));\n num = q;\n } while (num);\n }\n}\n\nexport function utoa32(value: u32, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n let out: String;\n\n if (radix == 10) {\n let decimals = decimalCount32(value);\n out = changetype(__new(decimals << 1, idof()));\n utoa32_dec_core(changetype(out), value, decimals);\n } else if (radix == 16) {\n let decimals = (31 - clz(value) >> 2) + 1;\n out = changetype(__new(decimals << 1, idof()));\n utoa32_hex_core(changetype(out), value, decimals);\n } else {\n let decimals = ulog_base(value, radix);\n out = changetype(__new(decimals << 1, idof()));\n utoa64_any_core(changetype(out), value, decimals, radix);\n }\n return out;\n}\n\nexport function itoa32(value: i32, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n\n let sign = (value >>> 31) << 1;\n if (sign) value = -value;\n let out: String;\n\n if (radix == 10) {\n let decimals = decimalCount32(value);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa32_dec_core(changetype(out) + sign, value, decimals);\n } else if (radix == 16) {\n let decimals = (31 - clz(value) >> 2) + 1;\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa32_hex_core(changetype(out) + sign, value, decimals);\n } else {\n let val32 = u32(value);\n let decimals = ulog_base(val32, radix);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_any_core(changetype(out) + sign, val32, decimals, radix);\n }\n if (sign) store(changetype(out), CharCode.MINUS);\n return out;\n}\n\nexport function utoa64(value: u64, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n let out: String;\n\n if (radix == 10) {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n let decimals = decimalCount32(val32);\n out = changetype(__new(decimals << 1, idof()));\n utoa32_dec_core(changetype(out), val32, decimals);\n } else {\n let decimals = decimalCount64High(value);\n out = changetype(__new(decimals << 1, idof()));\n utoa64_dec_core(changetype(out), value, decimals);\n }\n } else if (radix == 16) {\n let decimals = (63 - u32(clz(value)) >> 2) + 1;\n out = changetype(__new(decimals << 1, idof()));\n utoa64_hex_core(changetype(out), value, decimals);\n } else {\n let decimals = ulog_base(value, radix);\n out = changetype(__new(decimals << 1, idof()));\n utoa64_any_core(changetype(out), value, decimals, radix);\n }\n return out;\n}\n\nexport function itoa64(value: i64, radix: i32): String {\n if (radix < 2 || radix > 36) {\n throw new RangeError(\"toString() radix argument must be between 2 and 36\");\n }\n if (!value) return \"0\";\n\n let sign = u32(value >>> 63) << 1;\n if (sign) value = -value;\n let out: String;\n\n if (radix == 10) {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n let decimals = decimalCount32(val32);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa32_dec_core(changetype(out) + sign, val32, decimals);\n } else {\n let decimals = decimalCount64High(value);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_dec_core(changetype(out) + sign, value, decimals);\n }\n } else if (radix == 16) {\n let decimals = (63 - u32(clz(value)) >> 2) + 1;\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_hex_core(changetype(out) + sign, value, decimals);\n } else {\n let decimals = ulog_base(value, radix);\n out = changetype(__new((decimals << 1) + sign, idof()));\n utoa64_any_core(changetype(out) + sign, value, decimals, radix);\n }\n if (sign) store(changetype(out), CharCode.MINUS);\n return out;\n}\n\n// @ts-ignore: decorator\n@lazy let _K: i32 = 0;\n\n// // @ts-ignore: decorator\n// @lazy\n// let _frc: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy let _exp: i32 = 0;\n\n// @ts-ignore: decorator\n@lazy let _frc_minus: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy let _frc_plus: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy let _frc_pow: u64 = 0;\n\n// @ts-ignore: decorator\n@lazy let _exp_pow: i32 = 0;\n\n// @ts-ignore: decorator\n@inline\nfunction umul64f(u: u64, v: u64): u64 {\n let u0 = u & 0xFFFFFFFF;\n let v0 = v & 0xFFFFFFFF;\n\n let u1 = u >> 32;\n let v1 = v >> 32;\n\n let l = u0 * v0;\n let t = u1 * v0 + (l >> 32);\n let w = u0 * v1 + (t & 0xFFFFFFFF);\n\n w += 0x7FFFFFFF; // rounding\n\n t >>= 32;\n w >>= 32;\n\n return u1 * v1 + t + w;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction umul64e(e1: i32, e2: i32): i32 {\n return e1 + e2 + 64; // where 64 is significand size\n}\n\n// @ts-ignore: decorator\n@inline\nfunction normalizedBoundaries(f: u64, e: i32): void {\n let frc = (f << 1) + 1;\n let exp = e - 1;\n let off = clz(frc);\n frc <<= off;\n exp -= off;\n\n let m = 1 + i32(f == 0x0010000000000000);\n\n _frc_plus = frc;\n _frc_minus = ((f << m) - 1) << e - m - exp;\n _exp = exp;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction grisuRound(buffer: usize, len: i32, delta: u64, rest: u64, ten_kappa: u64, wp_w: u64): void {\n let lastp = buffer + ((len - 1) << 1);\n let digit = load(lastp);\n while (\n rest < wp_w &&\n delta - rest >= ten_kappa && (\n rest + ten_kappa < wp_w ||\n wp_w - rest > rest + ten_kappa - wp_w\n )\n ) {\n --digit;\n rest += ten_kappa;\n }\n store(lastp, digit);\n}\n\n// @ts-ignore: decorator\n@inline\nfunction getCachedPower(minExp: i32): void {\n const c = reinterpret(0x3FD34413509F79FE); // 1 / lg(10) = 0.30102999566398114\n let dk = (-61 - minExp) * c + 347;\t // dk must be positive, so can do ceiling in positive\n let k = dk;\n k += i32(k != dk); // conversion with ceil\n\n let index = (k >> 3) + 1;\n _K = 348 - (index << 3);\t// decimal exponent no need lookup table\n _frc_pow = load(FRC_POWERS + (index << alignof()));\n _exp_pow = load(EXP_POWERS + (index << alignof()));\n}\n\n// @ts-ignore: decorator\n@inline\nfunction grisu2(value: f64, buffer: usize, sign: i32): i32 {\n\n // frexp routine\n let uv = reinterpret(value);\n let exp = i32((uv & 0x7FF0000000000000) >>> 52);\n let sid = uv & 0x000FFFFFFFFFFFFF;\n let frc = (u64(exp != 0) << 52) + sid;\n exp = select(exp, 1, exp) - (0x3FF + 52);\n\n normalizedBoundaries(frc, exp);\n getCachedPower(_exp);\n\n // normalize\n let off = clz(frc);\n frc <<= off;\n exp -= off;\n\n let frc_pow = _frc_pow;\n let exp_pow = _exp_pow;\n\n let w_frc = umul64f(frc, frc_pow);\n let w_exp = umul64e(exp, exp_pow);\n\n let wp_frc = umul64f(_frc_plus, frc_pow) - 1;\n let wp_exp = umul64e(_exp, exp_pow);\n\n let wm_frc = umul64f(_frc_minus, frc_pow) + 1;\n let delta = wp_frc - wm_frc;\n\n return genDigits(buffer, w_frc, w_exp, wp_frc, wp_exp, delta, sign);\n}\n\nfunction genDigits(buffer: usize, w_frc: u64, w_exp: i32, mp_frc: u64, mp_exp: i32, delta: u64, sign: i32): i32 {\n let one_exp = -mp_exp;\n let one_frc = (1) << one_exp;\n let mask = one_frc - 1;\n\n let wp_w_frc = mp_frc - w_frc;\n\n let p1 = u32(mp_frc >> one_exp);\n let p2 = mp_frc & mask;\n\n let kappa = decimalCount32(p1);\n let len = sign;\n\n while (kappa > 0) {\n let d: u32;\n switch (kappa) {\n case 10: { d = p1 / 1000000000; p1 %= 1000000000; break; }\n case 9: { d = p1 / 100000000; p1 %= 100000000; break; }\n case 8: { d = p1 / 10000000; p1 %= 10000000; break; }\n case 7: { d = p1 / 1000000; p1 %= 1000000; break; }\n case 6: { d = p1 / 100000; p1 %= 100000; break; }\n case 5: { d = p1 / 10000; p1 %= 10000; break; }\n case 4: { d = p1 / 1000; p1 %= 1000; break; }\n case 3: { d = p1 / 100; p1 %= 100; break; }\n case 2: { d = p1 / 10; p1 %= 10; break; }\n case 1: { d = p1; p1 = 0; break; }\n default: { d = 0; break; }\n }\n\n if (d | len) store(buffer + (len++ << 1), CharCode._0 + d);\n\n --kappa;\n let tmp = ((p1) << one_exp) + p2;\n if (tmp <= delta) {\n _K += kappa;\n grisuRound(buffer, len, delta, tmp, load(POWERS10 + (kappa << alignof())) << one_exp, wp_w_frc);\n return len;\n }\n }\n\n while (true) {\n p2 *= 10;\n delta *= 10;\n\n let d = p2 >> one_exp;\n if (d | len) store(buffer + (len++ << 1), CharCode._0 + d);\n\n p2 &= mask;\n --kappa;\n if (p2 < delta) {\n _K += kappa;\n wp_w_frc *= load(POWERS10 + (-kappa << alignof()));\n grisuRound(buffer, len, delta, p2, one_frc, wp_w_frc);\n return len;\n }\n }\n}\n\n// @ts-ignore: decorator\n@inline\nfunction genExponent(buffer: usize, k: i32): i32 {\n let sign = k < 0;\n if (sign) k = -k;\n let decimals = decimalCount32(k) + 1;\n utoa32_dec_core(buffer, k, decimals);\n store(buffer, select(CharCode.MINUS, CharCode.PLUS, sign));\n return decimals;\n}\n\nfunction prettify(buffer: usize, length: i32, k: i32): i32 {\n if (!k) {\n store(buffer + (length << 1), CharCode.DOT | (CharCode._0 << 16));\n return length + 2;\n }\n\n let kk = length + k;\n if (length <= kk && kk <= 21) {\n // 1234e7 -> 12340000000\n for (let i = length; i < kk; ++i) {\n store(buffer + (i << 1), CharCode._0);\n }\n store(buffer + (kk << 1), CharCode.DOT | (CharCode._0 << 16));\n return kk + 2;\n } else if (kk > 0 && kk <= 21) {\n // 1234e-2 -> 12.34\n let ptr = buffer + (kk << 1);\n memory.copy(\n ptr + 2,\n ptr,\n -k << 1\n );\n store(buffer + (kk << 1), CharCode.DOT);\n return length + 1;\n } else if (-6 < kk && kk <= 0) {\n // 1234e-6 -> 0.001234\n let offset = 2 - kk;\n memory.copy(\n buffer + (offset << 1),\n buffer,\n length << 1\n );\n store(buffer, CharCode._0 | (CharCode.DOT << 16));\n for (let i = 2; i < offset; ++i) {\n store(buffer + (i << 1), CharCode._0);\n }\n return length + offset;\n } else if (length == 1) {\n // 1e30\n store(buffer, CharCode.e, 2);\n length = genExponent(buffer + 4, kk - 1);\n return length + 2;\n } else {\n let len = length << 1;\n memory.copy(\n buffer + 4,\n buffer + 2,\n len - 2\n );\n store(buffer, CharCode.DOT, 2);\n store(buffer + len, CharCode.e, 2);\n length += genExponent(buffer + len + 4, kk - 1);\n return length + 2;\n }\n}\n\nfunction dtoa_core(buffer: usize, value: f64): i32 {\n let sign = i32(value < 0);\n if (sign) {\n value = -value;\n store(buffer, CharCode.MINUS);\n }\n // assert(value > 0 && value <= 1.7976931348623157e308);\n let len = grisu2(value, buffer, sign);\n len = prettify(buffer + (sign << 1), len - sign, _K);\n return len + sign;\n}\n\n// @ts-ignore: decorator\n@lazy @inline const dtoa_buf = memory.data(MAX_DOUBLE_LENGTH << 1);\n\nexport function dtoa(value: f64): String {\n if (value == 0) return \"0.0\";\n if (!isFinite(value)) {\n if (isNaN(value)) return \"NaN\";\n return select(\"-Infinity\", \"Infinity\", value < 0);\n }\n let size = dtoa_core(dtoa_buf, value) << 1;\n let result = changetype(__new(size, idof()));\n memory.copy(changetype(result), dtoa_buf, size);\n return result;\n}\n\nexport function itoa_buffered(buffer: usize, value: T): u32 {\n let sign: u32 = 0;\n if (isSigned()) {\n sign = u32(value < 0);\n if (sign) {\n if (sizeof() == 1) {\n if (value == -0x80) {\n // -0x80 -> -128\n store(buffer,\n CharCode.MINUS |\n (CharCode._0 + 1) << 16 |\n (CharCode._0 + 2) << 32 |\n (CharCode._0 + 8) << 48\n );\n return 4;\n }\n }\n if (sizeof() == 2) {\n if (value == -0x8000) {\n // -0x8000 -> -32768\n store(buffer,\n CharCode.MINUS |\n (CharCode._0 + 3) << 16 |\n (CharCode._0 + 2) << 32 |\n (CharCode._0 + 7) << 48\n ); // -327\n store(buffer + 8,\n (CharCode._0 + 6) << 0 |\n (CharCode._0 + 8) << 16\n ); // 68\n return 6;\n }\n }\n store(buffer, CharCode.MINUS);\n // @ts-ignore\n value = -value;\n }\n }\n let dest = buffer + (sign << 1);\n if (ASC_SHRINK_LEVEL <= 1) {\n if (isSigned()) {\n if (sizeof() <= 4) {\n if (value < 10) {\n store(dest, value | CharCode._0);\n return 1 + sign;\n }\n } else {\n if (value < 10) {\n store(dest, value | CharCode._0);\n return 1 + sign;\n }\n }\n } else {\n if (value < 10) {\n store(buffer, value | CharCode._0);\n return 1;\n }\n }\n }\n let decimals: u32 = 0;\n if (sizeof() <= 4) {\n let val32 = value;\n decimals = decimalCount32(val32);\n utoa32_dec_core(dest, val32, decimals);\n } else {\n if (value <= u32.MAX_VALUE) {\n let val32 = value;\n decimals = decimalCount32(val32);\n utoa32_dec_core(dest, val32, decimals);\n } else {\n let val64 = value;\n decimals = decimalCount64High(val64);\n utoa64_dec_core(dest, val64, decimals);\n }\n }\n return sign + decimals;\n}\n\nexport function dtoa_buffered(buffer: usize, value: f64): u32 {\n if (value == 0) {\n store(buffer, CharCode._0);\n store(buffer, CharCode.DOT, 2);\n store(buffer, CharCode._0, 4);\n return 3;\n }\n if (!isFinite(value)) {\n if (isNaN(value)) {\n store(buffer, CharCode.N);\n store(buffer, CharCode.a, 2);\n store(buffer, CharCode.N, 4);\n return 3;\n } else {\n let sign = value < 0;\n if (sign) {\n store(buffer, CharCode.MINUS); // -\n buffer += 2;\n }\n store(buffer, 0x690066006E0049, 0); // ifnI\n store(buffer, 0x7900740069006E, 8); // ytin\n return 8 + u32(sign);\n }\n }\n return dtoa_core(buffer, value);\n}\n","//\n// Lookup data for exp2f\n//\n\n// @ts-ignore: decorator\n@inline const EXP2F_TABLE_BITS = 5;\n\n// @ts-ignore: decorator\n@lazy @inline const EXP2F_DATA_TAB = memory.data([\n // exp2f_data_tab[i] = uint(2^(i/N)) - (i << 52-BITS)\n // used for computing 2^(k/N) for an int |k| < 150 N as\n // double(tab[k%N] + (k << 52-BITS))\n 0x3FF0000000000000, 0x3FEFD9B0D3158574, 0x3FEFB5586CF9890F, 0x3FEF9301D0125B51,\n 0x3FEF72B83C7D517B, 0x3FEF54873168B9AA, 0x3FEF387A6E756238, 0x3FEF1E9DF51FDEE1,\n 0x3FEF06FE0A31B715, 0x3FEEF1A7373AA9CB, 0x3FEEDEA64C123422, 0x3FEECE086061892D,\n 0x3FEEBFDAD5362A27, 0x3FEEB42B569D4F82, 0x3FEEAB07DD485429, 0x3FEEA47EB03A5585,\n 0x3FEEA09E667F3BCD, 0x3FEE9F75E8EC5F74, 0x3FEEA11473EB0187, 0x3FEEA589994CCE13,\n 0x3FEEACE5422AA0DB, 0x3FEEB737B0CDC5E5, 0x3FEEC49182A3F090, 0x3FEED503B23E255D,\n 0x3FEEE89F995AD3AD, 0x3FEEFF76F2FB5E47, 0x3FEF199BDD85529C, 0x3FEF3720DCEF9069,\n 0x3FEF5818DCFBA487, 0x3FEF7C97337B9B5F, 0x3FEFA4AFA2A490DA, 0x3FEFD0765B6E4540\n]);\n\n// ULP error: 0.502 (nearest rounding.)\n// Relative error: 1.69 * 2^-34 in [-1/64, 1/64] (before rounding.)\n// Wrong count: 168353 (all nearest rounding wrong results with fma.)\n// @ts-ignore: decorator\n@inline\nexport function exp2f_lut(x: f32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000) / N, // 0x1.8p+52\n Ox127f = reinterpret(0x7F000000);\n\n const\n C0 = reinterpret(0x3FAC6AF84B912394), // 0x1.c6af84b912394p-5\n C1 = reinterpret(0x3FCEBFCE50FAC4F3), // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret(0x3FE62E42FF0C52D6); // 0x1.62e42ff0c52d6p-1\n\n let xd = x;\n let ix = reinterpret(x);\n let ux = ix >> 20 & 0x7FF;\n if (ux >= 0x430) {\n // |x| >= 128 or x is nan.\n if (ix == 0xFF800000) return 0; // x == -Inf -> 0\n if (ux >= 0x7F8) return x + x; // x == Inf/NaN -> Inf/NaN\n if (x > 0) return x * Ox127f; // x > 0 -> HugeVal (Owerflow)\n if (x <= -150) return 0; // x <= -150 -> 0 (Underflow)\n }\n\n // x = k/N + r with r in [-1/(2N), 1/(2N)] and int k.\n let kd = xd + shift;\n let ki = reinterpret(kd);\n let r = xd - (kd - shift);\n let t: u64, y: f64, s: f64;\n\n // exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load(EXP2F_DATA_TAB + ((ki & N_MASK) << alignof()));\n t += ki << (52 - EXP2F_TABLE_BITS);\n s = reinterpret(t);\n y = C2 * r + 1;\n y += (C0 * r + C1) * (r * r);\n y *= s;\n\n return y;\n}\n\n// ULP error: 0.502 (nearest rounding.)\n// Relative error: 1.69 * 2^-34 in [-ln2/64, ln2/64] (before rounding.)\n// Wrong count: 170635 (all nearest rounding wrong results with fma.)\n// @ts-ignore: decorator\n@inline\nexport function expf_lut(x: f32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000), // 0x1.8p+52\n InvLn2N = reinterpret(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep+0\n Ox1p127f = reinterpret(0x7F000000);\n\n const\n C0 = reinterpret(0x3FAC6AF84B912394) / N / N / N, // 0x1.c6af84b912394p-5\n C1 = reinterpret(0x3FCEBFCE50FAC4F3) / N / N, // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret(0x3FE62E42FF0C52D6) / N; // 0x1.62e42ff0c52d6p-1\n\n let xd = x;\n let ix = reinterpret(x);\n let ux = ix >> 20 & 0x7FF;\n if (ux >= 0x42B) {\n // |x| >= 88 or x is nan.\n if (ix == 0xFF800000) return 0; // x == -Inf -> 0\n if (ux >= 0x7F8) return x + x; // x == Inf/NaN -> Inf/NaN\n if (x > reinterpret(0x42B17217)) return x * Ox1p127f; // x > log(0x1p128) ~= 88.72 -> HugeVal (Owerflow)\n if (x < reinterpret(0xC2CFF1B4)) return 0; // x < log(0x1p-150) ~= -103.97 -> 0 (Underflow)\n }\n\n // x*N/Ln2 = k + r with r in [-1/2, 1/2] and int k.\n let z = InvLn2N * xd;\n\n // Round and convert z to int, the result is in [-150*N, 128*N] and\n // ideally ties-to-even rule is used, otherwise the magnitude of r\n // can be bigger which gives larger approximation error.\n let kd = (z + shift);\n let ki = reinterpret(kd);\n let r = z - (kd - shift);\n let s: f64, y: f64, t: u64;\n\n // exp(x) = 2^(k/N) * 2^(r/N) ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load(EXP2F_DATA_TAB + ((ki & N_MASK) << alignof()));\n t += ki << (52 - EXP2F_TABLE_BITS);\n s = reinterpret(t);\n z = C0 * r + C1;\n y = C2 * r + 1;\n y += z * (r * r);\n y *= s;\n\n return y;\n}\n\n//\n// Lookup data for log2f\n//\n\n// @ts-ignore: decorator\n@inline const LOG2F_TABLE_BITS = 4;\n\n// @ts-ignore: decorator\n@lazy @inline const LOG2F_DATA_TAB = memory.data([\n 0x3FF661EC79F8F3BE, 0xBFDEFEC65B963019, // 0x1.661ec79f8f3bep+0, -0x1.efec65b963019p-2,\n 0x3FF571ED4AAF883D, 0xBFDB0B6832D4FCA4, // 0x1.571ed4aaf883dp+0, -0x1.b0b6832d4fca4p-2,\n 0x3FF49539F0F010B0, 0xBFD7418B0A1FB77B, // 0x1.49539f0f010bp+0 , -0x1.7418b0a1fb77bp-2,\n 0x3FF3C995B0B80385, 0xBFD39DE91A6DCF7B, // 0x1.3c995b0b80385p+0, -0x1.39de91a6dcf7bp-2,\n 0x3FF30D190C8864A5, 0xBFD01D9BF3F2B631, // 0x1.30d190c8864a5p+0, -0x1.01d9bf3f2b631p-2,\n 0x3FF25E227B0B8EA0, 0xBFC97C1D1B3B7AF0, // 0x1.25e227b0b8eap+0 , -0x1.97c1d1b3b7afp-3 ,\n 0x3FF1BB4A4A1A343F, 0xBFC2F9E393AF3C9F, // 0x1.1bb4a4a1a343fp+0, -0x1.2f9e393af3c9fp-3,\n 0x3FF12358F08AE5BA, 0xBFB960CBBF788D5C, // 0x1.12358f08ae5bap+0, -0x1.960cbbf788d5cp-4,\n 0x3FF0953F419900A7, 0xBFAA6F9DB6475FCE, // 0x1.0953f419900a7p+0, -0x1.a6f9db6475fcep-5,\n 0x3FF0000000000000, 0, // 0x1p+0, 0x0,\n 0x3FEE608CFD9A47AC, 0x3FB338CA9F24F53D, // 0x1.e608cfd9a47acp-1, 0x1.338ca9f24f53dp-4,\n 0x3FECA4B31F026AA0, 0x3FC476A9543891BA, // 0x1.ca4b31f026aap-1 , 0x1.476a9543891bap-3,\n 0x3FEB2036576AFCE6, 0x3FCE840B4AC4E4D2, // 0x1.b2036576afce6p-1, 0x1.e840b4ac4e4d2p-3,\n 0x3FE9C2D163A1AA2D, 0x3FD40645F0C6651C, // 0x1.9c2d163a1aa2dp-1, 0x1.40645f0c6651cp-2,\n 0x3FE886E6037841ED, 0x3FD88E9C2C1B9FF8, // 0x1.886e6037841edp-1, 0x1.88e9c2c1b9ff8p-2,\n 0x3FE767DCF5534862, 0x3FDCE0A44EB17BCC // 0x1.767dcf5534862p-1, 0x1.ce0a44eb17bccp-2\n]);\n\n// ULP error: 0.752 (nearest rounding.)\n// Relative error: 1.9 * 2^-26 (before rounding.)\n// @ts-ignore: decorator\n@inline\nexport function log2f_lut(x: f32): f32 {\n const\n N_MASK = (1 << LOG2F_TABLE_BITS) - 1,\n Ox1p23f = reinterpret(0x4B000000); // 0x1p23f\n\n const\n A0 = reinterpret(0xBFD712B6F70A7E4D), // -0x1.712b6f70a7e4dp-2\n A1 = reinterpret(0x3FDECABF496832E0), // 0x1.ecabf496832ep-2\n A2 = reinterpret(0xBFE715479FFAE3DE), // -0x1.715479ffae3dep-1\n A3 = reinterpret(0x3FF715475F35C8B8); // 0x1.715475f35c8b8p0\n\n let ux = reinterpret(x);\n // Fix sign of zero with downward rounding when x==1.\n // if (WANT_ROUNDING && predict_false(ix == 0x3f800000)) return 0;\n if (ux - 0x00800000 >= 0x7F800000 - 0x00800000) {\n // x < 0x1p-126 or inf or nan.\n if (ux * 2 == 0) return -Infinity;\n if (ux == 0x7F800000) return x; // log2(inf) == inf.\n if ((ux >> 31) || ux * 2 >= 0xFF000000) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ux = reinterpret(x * Ox1p23f);\n ux -= 23 << 23;\n }\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n let tmp = ux - 0x3F330000;\n let i = (tmp >> (23 - LOG2F_TABLE_BITS)) & N_MASK;\n let top = tmp & 0xFF800000;\n let iz = ux - top;\n let k = tmp >> 23;\n\n let invc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 0 << alignof());\n let logc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 1 << alignof());\n let z = reinterpret(iz);\n\n // log2(x) = log1p(z/c-1)/ln2 + log2(c) + k\n let r = z * invc - 1;\n let y0 = logc + k;\n\n // Pipelined polynomial evaluation to approximate log1p(r)/ln2.\n let y = A1 * r + A2;\n let p = A3 * r + y0;\n let r2 = r * r;\n y += A0 * r2;\n y = y * r2 + p;\n\n return y;\n}\n\n//\n// Lookup data for logf. See: https://git.musl-libc.org/cgit/musl/tree/src/math/logf.c\n//\n\n// @ts-ignore: decorator\n@inline const LOGF_TABLE_BITS = 4;\n\n// @ts-ignore: decorator\n@lazy @inline const LOGF_DATA_TAB = memory.data([\n 0x3FF661EC79F8F3BE, 0xBFD57BF7808CAADE, // 0x1.661ec79f8f3bep+0, -0x1.57bf7808caadep-2,\n 0x3FF571ED4AAF883D, 0xBFD2BEF0A7C06DDB, // 0x1.571ed4aaf883dp+0, -0x1.2bef0a7c06ddbp-2,\n 0x3FF49539F0F010B0, 0xBFD01EAE7F513A67, // 0x1.49539f0f010bp+0 , -0x1.01eae7f513a67p-2,\n 0x3FF3C995B0B80385, 0xBFCB31D8A68224E9, // 0x1.3c995b0b80385p+0, -0x1.b31d8a68224e9p-3,\n 0x3FF30D190C8864A5, 0xBFC6574F0AC07758, // 0x1.30d190c8864a5p+0, -0x1.6574f0ac07758p-3,\n 0x3FF25E227B0B8EA0, 0xBFC1AA2BC79C8100, // 0x1.25e227b0b8eap+0 , -0x1.1aa2bc79c81p-3 ,\n 0x3FF1BB4A4A1A343F, 0xBFBA4E76CE8C0E5E, // 0x1.1bb4a4a1a343fp+0, -0x1.a4e76ce8c0e5ep-4,\n 0x3FF12358F08AE5BA, 0xBFB1973C5A611CCC, // 0x1.12358f08ae5bap+0, -0x1.1973c5a611cccp-4,\n 0x3FF0953F419900A7, 0xBFA252F438E10C1E, // 0x1.0953f419900a7p+0, -0x1.252f438e10c1ep-5,\n 0x3FF0000000000000, 0, // 0x1p+0, 0,\n 0x3FEE608CFD9A47AC, 0x3FAAA5AA5DF25984, // 0x1.e608cfd9a47acp-1, 0x1.aa5aa5df25984p-5,\n 0x3FECA4B31F026AA0, 0x3FBC5E53AA362EB4, // 0x1.ca4b31f026aap-1 , 0x1.c5e53aa362eb4p-4,\n 0x3FEB2036576AFCE6, 0x3FC526E57720DB08, // 0x1.b2036576afce6p-1, 0x1.526e57720db08p-3,\n 0x3FE9C2D163A1AA2D, 0x3FCBC2860D224770, // 0x1.9c2d163a1aa2dp-1, 0x1.bc2860d22477p-3 ,\n 0x3FE886E6037841ED, 0x3FD1058BC8A07EE1, // 0x1.886e6037841edp-1, 0x1.1058bc8a07ee1p-2,\n 0x3FE767DCF5534862, 0x3FD4043057B6EE09 // 0x1.767dcf5534862p-1, 0x1.4043057b6ee09p-2\n]);\n\n// ULP error: 0.818 (nearest rounding.)\n// Relative error: 1.957 * 2^-26 (before rounding.)\n// @ts-ignore: decorator\n@inline\nexport function logf_lut(x: f32): f32 {\n const\n N_MASK = (1 << LOGF_TABLE_BITS) - 1,\n Ox1p23f = reinterpret(0x4B000000); // 0x1p23f\n\n const\n Ln2 = reinterpret(0x3FE62E42FEFA39EF), // 0x1.62e42fefa39efp-1;\n A0 = reinterpret(0xBFD00EA348B88334), // -0x1.00ea348b88334p-2\n A1 = reinterpret(0x3FD5575B0BE00B6A), // 0x1.5575b0be00b6ap-2\n A2 = reinterpret(0xBFDFFFFEF20A4123); // -0x1.ffffef20a4123p-2\n\n let ux = reinterpret(x);\n // Fix sign of zero with downward rounding when x==1.\n // if (WANT_ROUNDING && ux == 0x3f800000) return 0;\n if (ux - 0x00800000 >= 0x7F800000 - 0x00800000) {\n // x < 0x1p-126 or inf or nan.\n if ((ux << 1) == 0) return -Infinity;\n if (ux == 0x7F800000) return x; // log(inf) == inf.\n if ((ux >> 31) || (ux << 1) >= 0xFF000000) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ux = reinterpret(x * Ox1p23f);\n ux -= 23 << 23;\n }\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n let tmp = ux - 0x3F330000;\n let i = (tmp >> (23 - LOGF_TABLE_BITS)) & N_MASK;\n let k = tmp >> 23;\n let iz = ux - (tmp & 0x1FF << 23);\n\n let invc = load(LOGF_DATA_TAB + (i << (1 + alignof())), 0 << alignof());\n let logc = load(LOGF_DATA_TAB + (i << (1 + alignof())), 1 << alignof());\n\n let z = reinterpret(iz);\n\n // log(x) = log1p(z/c-1) + log(c) + k*Ln2\n let r = z * invc - 1;\n let y0 = logc + k * Ln2;\n\n // Pipelined polynomial evaluation to approximate log1p(r).\n let r2 = r * r;\n let y = A1 * r + A2;\n y += A0 * r2;\n y = y * r2 + (y0 + r);\n\n return y;\n}\n\n//\n// Lookup data for powf. See: https://git.musl-libc.org/cgit/musl/tree/src/math/powf.c\n//\n\n// @ts-ignore: decorator\n@inline\nfunction zeroinfnanf(ux: u32): bool {\n return (ux << 1) - 1 >= (0x7f800000 << 1) - 1;\n}\n\n// Returns 0 if not int, 1 if odd int, 2 if even int. The argument is\n// the bit representation of a non-zero finite floating-point value.\n// @ts-ignore: decorator\n@inline\nfunction checkintf(iy: u32): i32 {\n let e = iy >> 23 & 0xFF;\n if (e < 0x7F ) return 0;\n if (e > 0x7F + 23) return 2;\n e = 1 << (0x7F + 23 - e);\n if (iy & (e - 1)) return 0;\n if (iy & e ) return 1;\n return 2;\n}\n\n// Subnormal input is normalized so ix has negative biased exponent.\n// Output is multiplied by N (POWF_SCALE) if TOINT_INTRINICS is set.\n// @ts-ignore: decorator\n@inline\nfunction log2f_inline(ux: u32): f64 {\n const N_MASK = (1 << LOG2F_TABLE_BITS) - 1;\n\n const\n A0 = reinterpret(0x3FD27616C9496E0B), // 0x1.27616c9496e0bp-2\n A1 = reinterpret(0xBFD71969A075C67A), // -0x1.71969a075c67ap-2\n A2 = reinterpret(0x3FDEC70A6CA7BADD), // 0x1.ec70a6ca7baddp-2\n A3 = reinterpret(0xBFE7154748BEF6C8), // -0x1.7154748bef6c8p-1\n A4 = reinterpret(0x3FF71547652AB82B); // 0x1.71547652ab82bp+0\n\n // x = 2^k z; where z is in range [OFF,2*OFF] and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n let tmp = ux - 0x3F330000;\n let i = usize((tmp >> (23 - LOG2F_TABLE_BITS)) & N_MASK);\n let top = tmp & 0xFF800000;\n let uz = ux - top;\n let k = top >> 23;\n\n let invc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 0 << alignof());\n let logc = load(LOG2F_DATA_TAB + (i << (1 + alignof())), 1 << alignof());\n let z = reinterpret(uz);\n\n // log2(x) = log1p(z/c-1)/ln2 + log2(c) + k\n let r = z * invc - 1;\n let y0 = logc + k;\n\n // Pipelined polynomial evaluation to approximate log1p(r)/ln2.\n let y = A0 * r + A1;\n let p = A2 * r + A3;\n let q = A4 * r + y0;\n\n r *= r;\n q += p * r;\n y = y * (r * r) + q;\n\n return y;\n}\n\n// The output of log2 and thus the input of exp2 is either scaled by N\n// (in case of fast toint intrinsics) or not. The unscaled xd must be\n// in [-1021,1023], sign_bias sets the sign of the result.\n// @ts-ignore: decorator\n@inline\nfunction exp2f_inline(xd: f64, signBias: u32): f32 {\n const\n N = 1 << EXP2F_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000) / N; // 0x1.8p+52\n\n const\n C0 = reinterpret(0x3FAC6AF84B912394), // 0x1.c6af84b912394p-5\n C1 = reinterpret(0x3FCEBFCE50FAC4F3), // 0x1.ebfce50fac4f3p-3\n C2 = reinterpret(0x3FE62E42FF0C52D6); // 0x1.62e42ff0c52d6p-1\n\n // x = k/N + r with r in [-1/(2N), 1/(2N)]\n let kd = (xd + shift);\n let ki = reinterpret(kd);\n let r = xd - (kd - shift);\n let t: u64, z: f64, y: f64, s: f64;\n\n // exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1)\n t = load(EXP2F_DATA_TAB + ((ki & N_MASK) << alignof()));\n t += (ki + signBias) << (52 - EXP2F_TABLE_BITS);\n s = reinterpret(t);\n z = C0 * r + C1;\n y = C2 * r + 1;\n y += z * (r * r);\n y *= s;\n return y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction xflowf(sign: u32, y: f32): f32 {\n return select(-y, y, sign) * y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction oflowf(sign: u32): f32 {\n return xflowf(sign, reinterpret(0x70000000)); // 0x1p97f\n}\n\n// @ts-ignore: decorator\n@inline\nfunction uflowf(sign: u32): f32 {\n return xflowf(sign, reinterpret(0x10000000)); // 0x1p-95f\n}\n\n// @ts-ignore: decorator\n@inline\nexport function powf_lut(x: f32, y: f32): f32 {\n const\n Ox1p23f = reinterpret(0x4B000000), // 0x1p23f\n UPPER_LIMIT = reinterpret(0x405FFFFFFFD1D571), // 0x1.fffffffd1d571p+6\n LOWER_LIMIT = -150.0,\n SIGN_BIAS = 1 << (EXP2F_TABLE_BITS + 11);\n\n let signBias: u32 = 0;\n let ix = reinterpret(x);\n let iy = reinterpret(y);\n let ny = 0;\n\n if (i32(ix - 0x00800000 >= 0x7f800000 - 0x00800000) | (ny = i32(zeroinfnanf(iy)))) {\n // Either (x < 0x1p-126 or inf or nan) or (y is 0 or inf or nan).\n if (ny) {\n if ((iy << 1) == 0) return 1.0;\n if (ix == 0x3F800000) return NaN; // original: 1.0\n if ((ix << 1) > (0x7F800000 << 1) || (iy << 1) > (0x7F800000 << 1)) return x + y;\n if ((ix << 1) == (0x3F800000 << 1)) return NaN; // original: 1.0\n if (((ix << 1) < (0x3F800000 << 1)) == !(iy >> 31)) return 0; // |x| < 1 && y==inf or |x| > 1 && y==-inf.\n return y * y;\n }\n if (zeroinfnanf(ix)) {\n let x2 = x * x;\n if ((ix >> 31) && checkintf(iy) == 1) x2 = -x2;\n return iy < 0 ? 1 / x2 : x2;\n }\n // x and y are non-zero finite.\n if (ix < 0) {\n // Finite x < 0.\n let yint = checkintf(iy);\n if (yint == 0) return (x - x) / (x - x);\n if (yint == 1) signBias = SIGN_BIAS;\n ix &= 0x7FFFFFFF;\n }\n if (ix < 0x00800000) {\n // Normalize subnormal x so exponent becomes negative.\n ix = reinterpret(x * Ox1p23f);\n ix &= 0x7FFFFFFF;\n ix -= 23 << 23;\n }\n }\n let logx = log2f_inline(ix);\n let ylogx = y * logx; // cannot overflow, y is single prec.\n if ((reinterpret(ylogx) >> 47 & 0xFFFF) >= 0x80BF) { // reinterpret(126.0) >> 47\n // |y * log(x)| >= 126\n if (ylogx > UPPER_LIMIT) return oflowf(signBias); // overflow\n if (ylogx <= LOWER_LIMIT) return uflowf(signBias); // underflow\n }\n return exp2f_inline(ylogx, signBias);\n}\n\n//\n// Lookup data for exp. See: https://git.musl-libc.org/cgit/musl/tree/src/math/exp.c\n//\n\n// @ts-ignore: decorator\n@inline const EXP_TABLE_BITS = 7;\n\n// @ts-ignore: decorator\n@lazy @inline const EXP_DATA_TAB = memory.data([\n 0x0000000000000000, 0x3FF0000000000000,\n 0x3C9B3B4F1A88BF6E, 0x3FEFF63DA9FB3335,\n 0xBC7160139CD8DC5D, 0x3FEFEC9A3E778061,\n 0xBC905E7A108766D1, 0x3FEFE315E86E7F85,\n 0x3C8CD2523567F613, 0x3FEFD9B0D3158574,\n 0xBC8BCE8023F98EFA, 0x3FEFD06B29DDF6DE,\n 0x3C60F74E61E6C861, 0x3FEFC74518759BC8,\n 0x3C90A3E45B33D399, 0x3FEFBE3ECAC6F383,\n 0x3C979AA65D837B6D, 0x3FEFB5586CF9890F,\n 0x3C8EB51A92FDEFFC, 0x3FEFAC922B7247F7,\n 0x3C3EBE3D702F9CD1, 0x3FEFA3EC32D3D1A2,\n 0xBC6A033489906E0B, 0x3FEF9B66AFFED31B,\n 0xBC9556522A2FBD0E, 0x3FEF9301D0125B51,\n 0xBC5080EF8C4EEA55, 0x3FEF8ABDC06C31CC,\n 0xBC91C923B9D5F416, 0x3FEF829AAEA92DE0,\n 0x3C80D3E3E95C55AF, 0x3FEF7A98C8A58E51,\n 0xBC801B15EAA59348, 0x3FEF72B83C7D517B,\n 0xBC8F1FF055DE323D, 0x3FEF6AF9388C8DEA,\n 0x3C8B898C3F1353BF, 0x3FEF635BEB6FCB75,\n 0xBC96D99C7611EB26, 0x3FEF5BE084045CD4,\n 0x3C9AECF73E3A2F60, 0x3FEF54873168B9AA,\n 0xBC8FE782CB86389D, 0x3FEF4D5022FCD91D,\n 0x3C8A6F4144A6C38D, 0x3FEF463B88628CD6,\n 0x3C807A05B0E4047D, 0x3FEF3F49917DDC96,\n 0x3C968EFDE3A8A894, 0x3FEF387A6E756238,\n 0x3C875E18F274487D, 0x3FEF31CE4FB2A63F,\n 0x3C80472B981FE7F2, 0x3FEF2B4565E27CDD,\n 0xBC96B87B3F71085E, 0x3FEF24DFE1F56381,\n 0x3C82F7E16D09AB31, 0x3FEF1E9DF51FDEE1,\n 0xBC3D219B1A6FBFFA, 0x3FEF187FD0DAD990,\n 0x3C8B3782720C0AB4, 0x3FEF1285A6E4030B,\n 0x3C6E149289CECB8F, 0x3FEF0CAFA93E2F56,\n 0x3C834D754DB0ABB6, 0x3FEF06FE0A31B715,\n 0x3C864201E2AC744C, 0x3FEF0170FC4CD831,\n 0x3C8FDD395DD3F84A, 0x3FEEFC08B26416FF,\n 0xBC86A3803B8E5B04, 0x3FEEF6C55F929FF1,\n 0xBC924AEDCC4B5068, 0x3FEEF1A7373AA9CB,\n 0xBC9907F81B512D8E, 0x3FEEECAE6D05D866,\n 0xBC71D1E83E9436D2, 0x3FEEE7DB34E59FF7,\n 0xBC991919B3CE1B15, 0x3FEEE32DC313A8E5,\n 0x3C859F48A72A4C6D, 0x3FEEDEA64C123422,\n 0xBC9312607A28698A, 0x3FEEDA4504AC801C,\n 0xBC58A78F4817895B, 0x3FEED60A21F72E2A,\n 0xBC7C2C9B67499A1B, 0x3FEED1F5D950A897,\n 0x3C4363ED60C2AC11, 0x3FEECE086061892D,\n 0x3C9666093B0664EF, 0x3FEECA41ED1D0057,\n 0x3C6ECCE1DAA10379, 0x3FEEC6A2B5C13CD0,\n 0x3C93FF8E3F0F1230, 0x3FEEC32AF0D7D3DE,\n 0x3C7690CEBB7AAFB0, 0x3FEEBFDAD5362A27,\n 0x3C931DBDEB54E077, 0x3FEEBCB299FDDD0D,\n 0xBC8F94340071A38E, 0x3FEEB9B2769D2CA7,\n 0xBC87DECCDC93A349, 0x3FEEB6DAA2CF6642,\n 0xBC78DEC6BD0F385F, 0x3FEEB42B569D4F82,\n 0xBC861246EC7B5CF6, 0x3FEEB1A4CA5D920F,\n 0x3C93350518FDD78E, 0x3FEEAF4736B527DA,\n 0x3C7B98B72F8A9B05, 0x3FEEAD12D497C7FD,\n 0x3C9063E1E21C5409, 0x3FEEAB07DD485429,\n 0x3C34C7855019C6EA, 0x3FEEA9268A5946B7,\n 0x3C9432E62B64C035, 0x3FEEA76F15AD2148,\n 0xBC8CE44A6199769F, 0x3FEEA5E1B976DC09,\n 0xBC8C33C53BEF4DA8, 0x3FEEA47EB03A5585,\n 0xBC845378892BE9AE, 0x3FEEA34634CCC320,\n 0xBC93CEDD78565858, 0x3FEEA23882552225,\n 0x3C5710AA807E1964, 0x3FEEA155D44CA973,\n 0xBC93B3EFBF5E2228, 0x3FEEA09E667F3BCD,\n 0xBC6A12AD8734B982, 0x3FEEA012750BDABF,\n 0xBC6367EFB86DA9EE, 0x3FEE9FB23C651A2F,\n 0xBC80DC3D54E08851, 0x3FEE9F7DF9519484,\n 0xBC781F647E5A3ECF, 0x3FEE9F75E8EC5F74,\n 0xBC86EE4AC08B7DB0, 0x3FEE9F9A48A58174,\n 0xBC8619321E55E68A, 0x3FEE9FEB564267C9,\n 0x3C909CCB5E09D4D3, 0x3FEEA0694FDE5D3F,\n 0xBC7B32DCB94DA51D, 0x3FEEA11473EB0187,\n 0x3C94ECFD5467C06B, 0x3FEEA1ED0130C132,\n 0x3C65EBE1ABD66C55, 0x3FEEA2F336CF4E62,\n 0xBC88A1C52FB3CF42, 0x3FEEA427543E1A12,\n 0xBC9369B6F13B3734, 0x3FEEA589994CCE13,\n 0xBC805E843A19FF1E, 0x3FEEA71A4623C7AD,\n 0xBC94D450D872576E, 0x3FEEA8D99B4492ED,\n 0x3C90AD675B0E8A00, 0x3FEEAAC7D98A6699,\n 0x3C8DB72FC1F0EAB4, 0x3FEEACE5422AA0DB,\n 0xBC65B6609CC5E7FF, 0x3FEEAF3216B5448C,\n 0x3C7BF68359F35F44, 0x3FEEB1AE99157736,\n 0xBC93091FA71E3D83, 0x3FEEB45B0B91FFC6,\n 0xBC5DA9B88B6C1E29, 0x3FEEB737B0CDC5E5,\n 0xBC6C23F97C90B959, 0x3FEEBA44CBC8520F,\n 0xBC92434322F4F9AA, 0x3FEEBD829FDE4E50,\n 0xBC85CA6CD7668E4B, 0x3FEEC0F170CA07BA,\n 0x3C71AFFC2B91CE27, 0x3FEEC49182A3F090,\n 0x3C6DD235E10A73BB, 0x3FEEC86319E32323,\n 0xBC87C50422622263, 0x3FEECC667B5DE565,\n 0x3C8B1C86E3E231D5, 0x3FEED09BEC4A2D33,\n 0xBC91BBD1D3BCBB15, 0x3FEED503B23E255D,\n 0x3C90CC319CEE31D2, 0x3FEED99E1330B358,\n 0x3C8469846E735AB3, 0x3FEEDE6B5579FDBF,\n 0xBC82DFCD978E9DB4, 0x3FEEE36BBFD3F37A,\n 0x3C8C1A7792CB3387, 0x3FEEE89F995AD3AD,\n 0xBC907B8F4AD1D9FA, 0x3FEEEE07298DB666,\n 0xBC55C3D956DCAEBA, 0x3FEEF3A2B84F15FB,\n 0xBC90A40E3DA6F640, 0x3FEEF9728DE5593A,\n 0xBC68D6F438AD9334, 0x3FEEFF76F2FB5E47,\n 0xBC91EEE26B588A35, 0x3FEF05B030A1064A,\n 0x3C74FFD70A5FDDCD, 0x3FEF0C1E904BC1D2,\n 0xBC91BDFBFA9298AC, 0x3FEF12C25BD71E09,\n 0x3C736EAE30AF0CB3, 0x3FEF199BDD85529C,\n 0x3C8EE3325C9FFD94, 0x3FEF20AB5FFFD07A,\n 0x3C84E08FD10959AC, 0x3FEF27F12E57D14B,\n 0x3C63CDAF384E1A67, 0x3FEF2F6D9406E7B5,\n 0x3C676B2C6C921968, 0x3FEF3720DCEF9069,\n 0xBC808A1883CCB5D2, 0x3FEF3F0B555DC3FA,\n 0xBC8FAD5D3FFFFA6F, 0x3FEF472D4A07897C,\n 0xBC900DAE3875A949, 0x3FEF4F87080D89F2,\n 0x3C74A385A63D07A7, 0x3FEF5818DCFBA487,\n 0xBC82919E2040220F, 0x3FEF60E316C98398,\n 0x3C8E5A50D5C192AC, 0x3FEF69E603DB3285,\n 0x3C843A59AC016B4B, 0x3FEF7321F301B460,\n 0xBC82D52107B43E1F, 0x3FEF7C97337B9B5F,\n 0xBC892AB93B470DC9, 0x3FEF864614F5A129,\n 0x3C74B604603A88D3, 0x3FEF902EE78B3FF6,\n 0x3C83C5EC519D7271, 0x3FEF9A51FBC74C83,\n 0xBC8FF7128FD391F0, 0x3FEFA4AFA2A490DA,\n 0xBC8DAE98E223747D, 0x3FEFAF482D8E67F1,\n 0x3C8EC3BC41AA2008, 0x3FEFBA1BEE615A27,\n 0x3C842B94C3A9EB32, 0x3FEFC52B376BBA97,\n 0x3C8A64A931D185EE, 0x3FEFD0765B6E4540,\n 0xBC8E37BAE43BE3ED, 0x3FEFDBFDAD9CBE14,\n 0x3C77893B4D91CD9D, 0x3FEFE7C1819E90D8,\n 0x3C5305C14160CC89, 0x3FEFF3C22B8F71F1\n]);\n\n// Handle cases that may overflow or underflow when computing the result that\n// is scale*(1+TMP) without intermediate rounding. The bit representation of\n// scale is in SBITS, however it has a computed exponent that may have\n// overflown into the sign bit so that needs to be adjusted before using it as\n// a double. (int32_t)KI is the k used in the argument reduction and exponent\n// adjustment of scale, positive k here means the result may overflow and\n// negative k means the result may underflow.\n// @ts-ignore: decorator\n@inline\nfunction specialcase(tmp: f64, sbits: u64, ki: u64): f64 {\n const\n Ox1p_1022 = reinterpret(0x0010000000000000), // 0x1p-1022\n Ox1p1009 = reinterpret(0x7F00000000000000); // 0x1p1009\n\n let scale: f64;\n if (!(ki & 0x80000000)) {\n // k > 0, the exponent of scale might have overflowed by <= 460.\n sbits -= u64(1009) << 52;\n scale = reinterpret(sbits);\n return Ox1p1009 * (scale + scale * tmp); // 0x1p1009\n }\n // k < 0, need special care in the subnormal range.\n sbits += u64(1022) << 52;\n // Note: sbits is signed scale.\n scale = reinterpret(sbits);\n let y = scale + scale * tmp;\n if (abs(y) < 1.0) {\n // Round y to the right precision before scaling it into the subnormal\n // range to avoid double rounding that can cause 0.5+E/2 ulp error where\n // E is the worst-case ulp error outside the subnormal range. So this\n // is only useful if the goal is better than 1 ulp worst-case error.\n let one = copysign(1.0, y);\n let lo = scale - y + scale * tmp;\n let hi = one + y;\n lo = one - hi + y + lo;\n y = (hi + lo) - one;\n // Fix the sign of 0.\n if (y == 0.0) y = reinterpret(sbits & 0x8000000000000000);\n }\n return y * Ox1p_1022;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function exp_lut(x: f64): f64 {\n const\n N = 1 << EXP_TABLE_BITS,\n N_MASK = N - 1;\n\n const\n InvLn2N = reinterpret(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep0\n NegLn2hiN = reinterpret(0xBF762E42FEFA0000), // -0x1.62e42fefa0000p-8\n NegLn2loN = reinterpret(0xBD0CF79ABC9E3B3A), // -0x1.cf79abc9e3b3ap-47\n shift = reinterpret(0x4338000000000000); // 0x1.8p52;\n\n const\n C2 = reinterpret(0x3FDFFFFFFFFFFDBD), // __exp_data.poly[0] (0x1.ffffffffffdbdp-2)\n C3 = reinterpret(0x3FC555555555543C), // __exp_data.poly[1] (0x1.555555555543cp-3)\n C4 = reinterpret(0x3FA55555CF172B91), // __exp_data.poly[2] (0x1.55555cf172b91p-5)\n C5 = reinterpret(0x3F81111167A4D017); // __exp_data.poly[3] (0x1.1111167a4d017p-7)\n\n let ux = reinterpret(x);\n let abstop = u32(ux >> 52) & 0x7FF;\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) return 1;\n if (abstop >= 0x409) {\n if (ux == 0xFFF0000000000000) return 0;\n if (abstop >= 0x7FF) {\n return 1.0 + x;\n } else {\n return select(0, Infinity, ux < 0);\n }\n }\n // Large x is special cased below.\n abstop = 0;\n }\n\n // exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)]\n // x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N]\n let z = InvLn2N * x;\n // #if TOINT_INTRINSICS\n // \tkd = roundtoint(z);\n // \tki = converttoint(z);\n // #elif EXP_USE_TOINT_NARROW\n // \t// z - kd is in [-0.5-2^-16, 0.5] in all rounding modes.\n // let kd = z + shift;\n // let ki = reinterpret(kd) >> 16;\n // let kd = ki;\n // #else\n // z - kd is in [-1, 1] in non-nearest rounding modes.\n let kd = z + shift;\n let ki = reinterpret(kd);\n kd -= shift;\n // #endif\n let r = x + kd * NegLn2hiN + kd * NegLn2loN;\n // 2^(k/N) ~= scale * (1 + tail).\n let idx = usize((ki & N_MASK) << 1);\n let top = ki << (52 - EXP_TABLE_BITS);\n\n let tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof()))); // T[idx]\n // This is only a valid scale when -1023*N < k < 1024*N\n let sbits = load(EXP_DATA_TAB + (idx << alignof()), 1 << alignof()) + top; // T[idx + 1]\n // exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1).\n // Evaluation is optimized assuming superscalar pipelined execution.\n let r2 = r * r;\n // Without fma the worst case error is 0.25/N ulp larger.\n // Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp.\n let tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase(tmp, sbits, ki);\n let scale = reinterpret(sbits);\n // Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there\n // is no spurious underflow here even without fma.\n return scale + scale * tmp;\n}\n\n//\n// Lookup data for exp2. See: https://git.musl-libc.org/cgit/musl/tree/src/math/exp2.c\n//\n\n// Handle cases that may overflow or underflow when computing the result that\n// is scale*(1+TMP) without intermediate rounding. The bit representation of\n// scale is in SBITS, however it has a computed exponent that may have\n// overflown into the sign bit so that needs to be adjusted before using it as\n// a double. (int32_t)KI is the k used in the argument reduction and exponent\n// adjustment of scale, positive k here means the result may overflow and\n// negative k means the result may underflow.\n// @ts-ignore: decorator\n@inline\nfunction specialcase2(tmp: f64, sbits: u64, ki: u64): f64 {\n const Ox1p_1022 = reinterpret(0x10000000000000); // 0x1p-1022\n let scale: f64;\n if ((ki & 0x80000000) == 0) {\n // k > 0, the exponent of scale might have overflowed by 1\n sbits -= u64(1) << 52;\n scale = reinterpret(sbits);\n return 2 * (scale * tmp + scale);\n }\n // k < 0, need special care in the subnormal range\n sbits += u64(1022) << 52;\n scale = reinterpret(sbits);\n let y = scale * tmp + scale;\n if (y < 1.0) {\n // Round y to the right precision before scaling it into the subnormal\n // range to avoid double rounding that can cause 0.5+E/2 ulp error where\n // E is the worst-case ulp error outside the subnormal range. So this\n // is only useful if the goal is better than 1 ulp worst-case error.\n let hi: f64, lo: f64;\n lo = scale - y + scale * tmp;\n hi = 1.0 + y;\n lo = 1.0 - hi + y + lo;\n y = (hi + lo) - 1.0;\n }\n return y * Ox1p_1022;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function exp2_lut(x: f64): f64 {\n const\n N = 1 << EXP_TABLE_BITS,\n N_MASK = N - 1,\n shift = reinterpret(0x4338000000000000) / N; // 0x1.8p52\n\n const\n C1 = reinterpret(0x3FE62E42FEFA39EF), // 0x1.62e42fefa39efp-1\n C2 = reinterpret(0x3FCEBFBDFF82C424), // 0x1.ebfbdff82c424p-3\n C3 = reinterpret(0x3FAC6B08D70CF4B5), // 0x1.c6b08d70cf4b5p-5\n C4 = reinterpret(0x3F83B2ABD24650CC), // 0x1.3b2abd24650ccp-7\n C5 = reinterpret(0x3F55D7E09B4E3A84); // 0x1.5d7e09b4e3a84p-10\n\n let ux = reinterpret(x);\n let abstop = u32(ux >> 52) & 0x7ff;\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) return 1.0;\n if (abstop >= 0x409) {\n if (ux == 0xFFF0000000000000) return 0;\n if (abstop >= 0x7FF) return 1.0 + x;\n if (ux >= 0) return Infinity;\n else if (ux >= 0xC090CC0000000000) return 0;\n }\n if ((ux << 1) > 0x811A000000000000) abstop = 0; // Large x is special cased below.\n }\n\n // exp2(x) = 2^(k/N) * 2^r, with 2^r in [2^(-1/2N),2^(1/2N)].\n // x = k/N + r, with int k and r in [-1/2N, 1/2N]\n let kd = x + shift;\n let ki = reinterpret(kd);\n kd -= shift; // k/N for int k\n let r = x - kd;\n // 2^(k/N) ~= scale * (1 + tail)\n let idx = usize((ki & N_MASK) << 1);\n let top = ki << (52 - EXP_TABLE_BITS);\n\n let tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof()), 0 << alignof())); // T[idx])\n // This is only a valid scale when -1023*N < k < 1024*N\n let sbits = load(EXP_DATA_TAB + (idx << alignof()), 1 << alignof()) + top; // T[idx + 1]\n // exp2(x) = 2^(k/N) * 2^r ~= scale + scale * (tail + 2^r - 1).\n // Evaluation is optimized assuming superscalar pipelined execution\n let r2 = r * r;\n // Without fma the worst case error is 0.5/N ulp larger.\n // Worst case error is less than 0.5+0.86/N+(abs poly error * 2^53) ulp.\n let tmp = tail + r * C1 + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase2(tmp, sbits, ki);\n let scale = reinterpret(sbits);\n // Note: tmp == 0 or |tmp| > 2^-65 and scale > 2^-928, so there\n // is no spurious underflow here even without fma.\n return scale * tmp + scale;\n}\n\n//\n// Lookup data for log2. See: https://git.musl-libc.org/cgit/musl/tree/src/math/log2.c\n//\n\n// @ts-ignore: decorator\n@inline const LOG2_TABLE_BITS = 6;\n\n/* Algorithm:\n\n x = 2^k z\n log2(x) = k + log2(c) + log2(z/c)\n log2(z/c) = poly(z/c - 1)\n\nwhere z is in [1.6p-1; 1.6p0] which is split into N subintervals and z falls\ninto the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = (double)log2(c)\n tab2[i].chi = (double)c\n tab2[i].clo = (double)(c - (double)c)\n\nwhere c is near the center of the subinterval and is chosen by trying +-2^29\nfloating point invc candidates around 1/center and selecting one for which\n\n 1) the rounding error in 0x1.8p10 + logc is 0,\n 2) the rounding error in z - chi - clo is < 0x1p-64 and\n 3) the rounding error in (double)log2(c) is minimized (< 0x1p-68).\n\nNote: 1) ensures that k + logc can be computed without rounding error, 2)\nensures that z/c - 1 can be computed as (z - chi - clo)*invc with close to a\nsingle rounding error when there is no fast fma for z*invc - 1, 3) ensures\nthat logc + poly(z/c - 1) has small error, however near x == 1 when\n|log2(x)| < 0x1p-4, this is not enough so that is special cased. */\n\n// @ts-ignore: decorator\n@lazy @inline const LOG2_DATA_TAB1 = memory.data([\n // invc , logc\n 0x3FF724286BB1ACF8, 0xBFE1095FEECDB000,\n 0x3FF6E1F766D2CCA1, 0xBFE08494BD76D000,\n 0x3FF6A13D0E30D48A, 0xBFE00143AEE8F800,\n 0x3FF661EC32D06C85, 0xBFDEFEC5360B4000,\n 0x3FF623FA951198F8, 0xBFDDFDD91AB7E000,\n 0x3FF5E75BA4CF026C, 0xBFDCFFAE0CC79000,\n 0x3FF5AC055A214FB8, 0xBFDC043811FDA000,\n 0x3FF571ED0F166E1E, 0xBFDB0B67323AE000,\n 0x3FF53909590BF835, 0xBFDA152F5A2DB000,\n 0x3FF5014FED61ADDD, 0xBFD9217F5AF86000,\n 0x3FF4CAB88E487BD0, 0xBFD8304DB0719000,\n 0x3FF49539B4334FEE, 0xBFD74189F9A9E000,\n 0x3FF460CBDFAFD569, 0xBFD6552BB5199000,\n 0x3FF42D664EE4B953, 0xBFD56B23A29B1000,\n 0x3FF3FB01111DD8A6, 0xBFD483650F5FA000,\n 0x3FF3C995B70C5836, 0xBFD39DE937F6A000,\n 0x3FF3991C4AB6FD4A, 0xBFD2BAA1538D6000,\n 0x3FF3698E0CE099B5, 0xBFD1D98340CA4000,\n 0x3FF33AE48213E7B2, 0xBFD0FA853A40E000,\n 0x3FF30D191985BDB1, 0xBFD01D9C32E73000,\n 0x3FF2E025CAB271D7, 0xBFCE857DA2FA6000,\n 0x3FF2B404CF13CD82, 0xBFCCD3C8633D8000,\n 0x3FF288B02C7CCB50, 0xBFCB26034C14A000,\n 0x3FF25E2263944DE5, 0xBFC97C1C2F4FE000,\n 0x3FF234563D8615B1, 0xBFC7D6023F800000,\n 0x3FF20B46E33EAF38, 0xBFC633A71A05E000,\n 0x3FF1E2EEFDCDA3DD, 0xBFC494F5E9570000,\n 0x3FF1BB4A580B3930, 0xBFC2F9E424E0A000,\n 0x3FF19453847F2200, 0xBFC162595AFDC000,\n 0x3FF16E06C0D5D73C, 0xBFBF9C9A75BD8000,\n 0x3FF1485F47B7E4C2, 0xBFBC7B575BF9C000,\n 0x3FF12358AD0085D1, 0xBFB960C60FF48000,\n 0x3FF0FEF00F532227, 0xBFB64CE247B60000,\n 0x3FF0DB2077D03A8F, 0xBFB33F78B2014000,\n 0x3FF0B7E6D65980D9, 0xBFB0387D1A42C000,\n 0x3FF0953EFE7B408D, 0xBFAA6F9208B50000,\n 0x3FF07325CAC53B83, 0xBFA47A954F770000,\n 0x3FF05197E40D1B5C, 0xBF9D23A8C50C0000,\n 0x3FF03091C1208EA2, 0xBF916A2629780000,\n 0x3FF0101025B37E21, 0xBF7720F8D8E80000,\n 0x3FEFC07EF9CAA76B, 0x3F86FE53B1500000,\n 0x3FEF4465D3F6F184, 0x3FA11CCCE10F8000,\n 0x3FEECC079F84107F, 0x3FAC4DFC8C8B8000,\n 0x3FEE573A99975AE8, 0x3FB3AA321E574000,\n 0x3FEDE5D6F0BD3DE6, 0x3FB918A0D08B8000,\n 0x3FED77B681FF38B3, 0x3FBE72E9DA044000,\n 0x3FED0CB5724DE943, 0x3FC1DCD2507F6000,\n 0x3FECA4B2DC0E7563, 0x3FC476AB03DEA000,\n 0x3FEC3F8EE8D6CB51, 0x3FC7074377E22000,\n 0x3FEBDD2B4F020C4C, 0x3FC98EDE8BA94000,\n 0x3FEB7D6C006015CA, 0x3FCC0DB86AD2E000,\n 0x3FEB20366E2E338F, 0x3FCE840AAFCEE000,\n 0x3FEAC57026295039, 0x3FD0790AB4678000,\n 0x3FEA6D01BC2731DD, 0x3FD1AC056801C000,\n 0x3FEA16D3BC3FF18B, 0x3FD2DB11D4FEE000,\n 0x3FE9C2D14967FEAD, 0x3FD406464EC58000,\n 0x3FE970E4F47C9902, 0x3FD52DBE093AF000,\n 0x3FE920FB3982BCF2, 0x3FD651902050D000,\n 0x3FE8D30187F759F1, 0x3FD771D2CDEAF000,\n 0x3FE886E5EBB9F66D, 0x3FD88E9C857D9000,\n 0x3FE83C97B658B994, 0x3FD9A80155E16000,\n 0x3FE7F405FFC61022, 0x3FDABE186ED3D000,\n 0x3FE7AD22181415CA, 0x3FDBD0F2AEA0E000,\n 0x3FE767DCF99EFF8C, 0x3FDCE0A43DBF4000\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const LOG2_DATA_TAB2 = memory.data([\n // chi , clo\n 0x3FE6200012B90A8E, 0x3C8904AB0644B605,\n 0x3FE66000045734A6, 0x3C61FF9BEA62F7A9,\n 0x3FE69FFFC325F2C5, 0x3C827ECFCB3C90BA,\n 0x3FE6E00038B95A04, 0x3C88FF8856739326,\n 0x3FE71FFFE09994E3, 0x3C8AFD40275F82B1,\n 0x3FE7600015590E10, 0xBC72FD75B4238341,\n 0x3FE7A00012655BD5, 0x3C7808E67C242B76,\n 0x3FE7E0003259E9A6, 0xBC6208E426F622B7,\n 0x3FE81FFFEDB4B2D2, 0xBC8402461EA5C92F,\n 0x3FE860002DFAFCC3, 0x3C6DF7F4A2F29A1F,\n 0x3FE89FFFF78C6B50, 0xBC8E0453094995FD,\n 0x3FE8E00039671566, 0xBC8A04F3BEC77B45,\n 0x3FE91FFFE2BF1745, 0xBC77FA34400E203C,\n 0x3FE95FFFCC5C9FD1, 0xBC76FF8005A0695D,\n 0x3FE9A0003BBA4767, 0x3C70F8C4C4EC7E03,\n 0x3FE9DFFFE7B92DA5, 0x3C8E7FD9478C4602,\n 0x3FEA1FFFD72EFDAF, 0xBC6A0C554DCDAE7E,\n 0x3FEA5FFFDE04FF95, 0x3C867DA98CE9B26B,\n 0x3FEA9FFFCA5E8D2B, 0xBC8284C9B54C13DE,\n 0x3FEADFFFDDAD03EA, 0x3C5812C8EA602E3C,\n 0x3FEB1FFFF10D3D4D, 0xBC8EFADDAD27789C,\n 0x3FEB5FFFCE21165A, 0x3C53CB1719C61237,\n 0x3FEB9FFFD950E674, 0x3C73F7D94194CE00,\n 0x3FEBE000139CA8AF, 0x3C750AC4215D9BC0,\n 0x3FEC20005B46DF99, 0x3C6BEEA653E9C1C9,\n 0x3FEC600040B9F7AE, 0xBC7C079F274A70D6,\n 0x3FECA0006255FD8A, 0xBC7A0B4076E84C1F,\n 0x3FECDFFFD94C095D, 0x3C88F933F99AB5D7,\n 0x3FED1FFFF975D6CF, 0xBC582C08665FE1BE,\n 0x3FED5FFFA2561C93, 0xBC7B04289BD295F3,\n 0x3FED9FFF9D228B0C, 0x3C870251340FA236,\n 0x3FEDE00065BC7E16, 0xBC75011E16A4D80C,\n 0x3FEE200002F64791, 0x3C89802F09EF62E0,\n 0x3FEE600057D7A6D8, 0xBC7E0B75580CF7FA,\n 0x3FEEA00027EDC00C, 0xBC8C848309459811,\n 0x3FEEE0006CF5CB7C, 0xBC8F8027951576F4,\n 0x3FEF2000782B7DCC, 0xBC8F81D97274538F,\n 0x3FEF6000260C450A, 0xBC4071002727FFDC,\n 0x3FEF9FFFE88CD533, 0xBC581BDCE1FDA8B0,\n 0x3FEFDFFFD50F8689, 0x3C87F91ACB918E6E,\n 0x3FF0200004292367, 0x3C9B7FF365324681,\n 0x3FF05FFFE3E3D668, 0x3C86FA08DDAE957B,\n 0x3FF0A0000A85A757, 0xBC57E2DE80D3FB91,\n 0x3FF0E0001A5F3FCC, 0xBC91823305C5F014,\n 0x3FF11FFFF8AFBAF5, 0xBC8BFABB6680BAC2,\n 0x3FF15FFFE54D91AD, 0xBC9D7F121737E7EF,\n 0x3FF1A00011AC36E1, 0x3C9C000A0516F5FF,\n 0x3FF1E00019C84248, 0xBC9082FBE4DA5DA0,\n 0x3FF220000FFE5E6E, 0xBC88FDD04C9CFB43,\n 0x3FF26000269FD891, 0x3C8CFE2A7994D182,\n 0x3FF2A00029A6E6DA, 0xBC700273715E8BC5,\n 0x3FF2DFFFE0293E39, 0x3C9B7C39DAB2A6F9,\n 0x3FF31FFFF7DCF082, 0x3C7DF1336EDC5254,\n 0x3FF35FFFF05A8B60, 0xBC9E03564CCD31EB,\n 0x3FF3A0002E0EAECC, 0x3C75F0E74BD3A477,\n 0x3FF3E000043BB236, 0x3C9C7DCB149D8833,\n 0x3FF4200002D187FF, 0x3C7E08AFCF2D3D28,\n 0x3FF460000D387CB1, 0x3C820837856599A6,\n 0x3FF4A00004569F89, 0xBC89FA5C904FBCD2,\n 0x3FF4E000043543F3, 0xBC781125ED175329,\n 0x3FF51FFFCC027F0F, 0x3C9883D8847754DC,\n 0x3FF55FFFFD87B36F, 0xBC8709E731D02807,\n 0x3FF59FFFF21DF7BA, 0x3C87F79F68727B02,\n 0x3FF5DFFFEBFC3481, 0xBC9180902E30E93E\n]);\n\n// @ts-ignore: decorator\n@inline\nexport function log2_lut(x: f64): f64 {\n const N_MASK = (1 << LOG2_TABLE_BITS) - 1;\n\n const\n LO: u64 = 0x3FEEA4AF00000000, // reinterpret(1.0 - 0x1.5b51p-5)\n HI: u64 = 0x3FF0B55900000000; // reinterpret(1.0 + 0x1.6ab2p-5)\n\n const\n InvLn2hi = reinterpret(0x3FF7154765200000), // 0x1.7154765200000p+0\n InvLn2lo = reinterpret(0x3DE705FC2EEFA200), // 0x1.705fc2eefa200p-33\n Ox1p52 = reinterpret(0x4330000000000000); // 0x1p52\n\n const\n B0 = reinterpret(0xBFE71547652B82FE), // -0x1.71547652b82fep-1\n B1 = reinterpret(0x3FDEC709DC3A03F7), // 0x1.ec709dc3a03f7p-2\n B2 = reinterpret(0xBFD71547652B7C3F), // -0x1.71547652b7c3fp-2\n B3 = reinterpret(0x3FD2776C50F05BE4), // 0x1.2776c50f05be4p-2\n B4 = reinterpret(0xBFCEC709DD768FE5), // -0x1.ec709dd768fe5p-3\n B5 = reinterpret(0x3FCA61761EC4E736), // 0x1.a61761ec4e736p-3\n B6 = reinterpret(0xBFC7153FBC64A79B), // -0x1.7153fbc64a79bp-3\n B7 = reinterpret(0x3FC484D154F01B4A), // 0x1.484d154f01b4ap-3\n B8 = reinterpret(0xBFC289E4A72C383C), // -0x1.289e4a72c383cp-3\n B9 = reinterpret(0x3FC0B32F285AEE66); // 0x1.0b32f285aee66p-3\n\n const\n A0 = reinterpret(0xBFE71547652B8339), // -0x1.71547652b8339p-1\n A1 = reinterpret(0x3FDEC709DC3A04BE), // 0x1.ec709dc3a04bep-2\n A2 = reinterpret(0xBFD7154764702FFB), // -0x1.7154764702ffbp-2\n A3 = reinterpret(0x3FD2776C50034C48), // 0x1.2776c50034c48p-2\n A4 = reinterpret(0xBFCEC7B328EA92BC), // -0x1.ec7b328ea92bcp-3\n A5 = reinterpret(0x3FCA6225E117F92E); // 0x1.a6225e117f92ep-3\n\n let ix = reinterpret(x);\n if (ix - LO < HI - LO) {\n let r = x - 1.0;\n // #if __FP_FAST_FMA\n // hi = r * InvLn2hi;\n // lo = r * InvLn2lo + __builtin_fma(r, InvLn2hi, -hi);\n // #else\n let rhi = reinterpret(reinterpret(r) & 0xFFFFFFFF00000000);\n let rlo = r - rhi;\n let hi = rhi * InvLn2hi;\n let lo = rlo * InvLn2hi + r * InvLn2lo;\n // #endif\n let r2 = r * r; // rounding error: 0x1p-62\n let r4 = r2 * r2;\n // Worst-case error is less than 0.54 ULP (0.55 ULP without fma)\n let p = r2 * (B0 + r * B1);\n let y = hi + p;\n lo += hi - y + p;\n lo += r4 * (B2 + r * B3 + r2 * (B4 + r * B5) +\n r4 * (B6 + r * B7 + r2 * (B8 + r * B9)));\n return y + lo;\n }\n let top = u32(ix >> 48);\n if (top - 0x0010 >= 0x7ff0 - 0x0010) {\n // x < 0x1p-1022 or inf or nan.\n if ((ix << 1) == 0) return -1.0 / (x * x);\n if (ix == 0x7FF0000000000000) return x; // log(inf) == inf\n if ((top & 0x8000) || (top & 0x7FF0) == 0x7FF0) return (x - x) / (x - x);\n // x is subnormal, normalize it.\n ix = reinterpret(x * Ox1p52);\n ix -= u64(52) << 52;\n }\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n let tmp = ix - 0x3FE6000000000000;\n let i = ((tmp >> (52 - LOG2_TABLE_BITS)) & N_MASK);\n let k = tmp >> 52;\n let iz = ix - (tmp & 0xFFF0000000000000);\n\n let invc = load(LOG2_DATA_TAB1 + (i << (1 + alignof())), 0 << alignof()); // T[i].invc;\n let logc = load(LOG2_DATA_TAB1 + (i << (1 + alignof())), 1 << alignof()); // T[i].logc;\n let z = reinterpret(iz);\n let kd = k;\n\n // log2(x) = log2(z/c) + log2(c) + k.\n // r ~= z/c - 1, |r| < 1/(2*N).\n // #if __FP_FAST_FMA\n // \t// rounding error: 0x1p-55/N.\n // \tr = __builtin_fma(z, invc, -1.0);\n // \tt1 = r * InvLn2hi;\n // \tt2 = r * InvLn2lo + __builtin_fma(r, InvLn2hi, -t1);\n // #else\n // rounding error: 0x1p-55/N + 0x1p-65.\n let chi = load(LOG2_DATA_TAB2 + (i << (1 + alignof())), 0 << alignof()); // T[i].chi;\n let clo = load(LOG2_DATA_TAB2 + (i << (1 + alignof())), 1 << alignof()); // T[i].clo;\n\n let r = (z - chi - clo) * invc;\n let rhi = reinterpret(reinterpret(r) & 0xFFFFFFFF00000000);\n let rlo = r - rhi;\n let t1 = rhi * InvLn2hi;\n let t2 = rlo * InvLn2hi + r * InvLn2lo;\n // #endif\n\n // hi + lo = r/ln2 + log2(c) + k\n let t3 = kd + logc;\n let hi = t3 + t1;\n let lo = t3 - hi + t1 + t2;\n\n // log2(r+1) = r/ln2 + r^2*poly(r)\n // Evaluation is optimized assuming superscalar pipelined execution\n let r2 = r * r; // rounding error: 0x1p-54/N^2\n // Worst-case error if |y| > 0x1p-4: 0.547 ULP (0.550 ULP without fma).\n // ~ 0.5 + 2/N/ln2 + abs-poly-error*0x1p56 ULP (+ 0.003 ULP without fma).\n let p = A0 + r * A1 + r2 * (A2 + r * A3) + (r2 * r2) * (A4 + r * A5);\n return lo + r2 * p + hi;\n}\n\n//\n// Lookup data for log. See: https://git.musl-libc.org/cgit/musl/tree/src/math/log.c\n//\n\n// @ts-ignore: decorator\n@inline const LOG_TABLE_BITS = 7;\n\n/* Algorithm:\n\n x = 2^k z\n log(x) = k ln2 + log(c) + log(z/c)\n log(z/c) = poly(z/c - 1)\n\nwhere z is in [1.6p-1; 1.6p0] which is split into N subintervals and z falls\ninto the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = (double)log(c)\n tab2[i].chi = (double)c\n tab2[i].clo = (double)(c - (double)c)\n\nwhere c is near the center of the subinterval and is chosen by trying +-2^29\nfloating point invc candidates around 1/center and selecting one for which\n\n 1) the rounding error in 0x1.8p9 + logc is 0,\n 2) the rounding error in z - chi - clo is < 0x1p-66 and\n 3) the rounding error in (double)log(c) is minimized (< 0x1p-66).\n\nNote: 1) ensures that k*ln2hi + logc can be computed without rounding error,\n2) ensures that z/c - 1 can be computed as (z - chi - clo)*invc with close to\na single rounding error when there is no fast fma for z*invc - 1, 3) ensures\nthat logc + poly(z/c - 1) has small error, however near x == 1 when\n|log(x)| < 0x1p-4, this is not enough so that is special cased.*/\n\n// @ts-ignore: decorator\n@lazy @inline const LOG_DATA_TAB1 = memory.data([\n // invc , logc\n 0x3FF734F0C3E0DE9F, 0xBFD7CC7F79E69000,\n 0x3FF713786A2CE91F, 0xBFD76FEEC20D0000,\n 0x3FF6F26008FAB5A0, 0xBFD713E31351E000,\n 0x3FF6D1A61F138C7D, 0xBFD6B85B38287800,\n 0x3FF6B1490BC5B4D1, 0xBFD65D5590807800,\n 0x3FF69147332F0CBA, 0xBFD602D076180000,\n 0x3FF6719F18224223, 0xBFD5A8CA86909000,\n 0x3FF6524F99A51ED9, 0xBFD54F4356035000,\n 0x3FF63356AA8F24C4, 0xBFD4F637C36B4000,\n 0x3FF614B36B9DDC14, 0xBFD49DA7FDA85000,\n 0x3FF5F66452C65C4C, 0xBFD445923989A800,\n 0x3FF5D867B5912C4F, 0xBFD3EDF439B0B800,\n 0x3FF5BABCCB5B90DE, 0xBFD396CE448F7000,\n 0x3FF59D61F2D91A78, 0xBFD3401E17BDA000,\n 0x3FF5805612465687, 0xBFD2E9E2EF468000,\n 0x3FF56397CEE76BD3, 0xBFD2941B3830E000,\n 0x3FF54725E2A77F93, 0xBFD23EC58CDA8800,\n 0x3FF52AFF42064583, 0xBFD1E9E129279000,\n 0x3FF50F22DBB2BDDF, 0xBFD1956D2B48F800,\n 0x3FF4F38F4734DED7, 0xBFD141679AB9F800,\n 0x3FF4D843CFDE2840, 0xBFD0EDD094EF9800,\n 0x3FF4BD3EC078A3C8, 0xBFD09AA518DB1000,\n 0x3FF4A27FC3E0258A, 0xBFD047E65263B800,\n 0x3FF4880524D48434, 0xBFCFEB224586F000,\n 0x3FF46DCE1B192D0B, 0xBFCF474A7517B000,\n 0x3FF453D9D3391854, 0xBFCEA4443D103000,\n 0x3FF43A2744B4845A, 0xBFCE020D44E9B000,\n 0x3FF420B54115F8FB, 0xBFCD60A22977F000,\n 0x3FF40782DA3EF4B1, 0xBFCCC00104959000,\n 0x3FF3EE8F5D57FE8F, 0xBFCC202956891000,\n 0x3FF3D5D9A00B4CE9, 0xBFCB81178D811000,\n 0x3FF3BD60C010C12B, 0xBFCAE2C9CCD3D000,\n 0x3FF3A5242B75DAB8, 0xBFCA45402E129000,\n 0x3FF38D22CD9FD002, 0xBFC9A877681DF000,\n 0x3FF3755BC5847A1C, 0xBFC90C6D69483000,\n 0x3FF35DCE49AD36E2, 0xBFC87120A645C000,\n 0x3FF34679984DD440, 0xBFC7D68FB4143000,\n 0x3FF32F5CCEFFCB24, 0xBFC73CB83C627000,\n 0x3FF3187775A10D49, 0xBFC6A39A9B376000,\n 0x3FF301C8373E3990, 0xBFC60B3154B7A000,\n 0x3FF2EB4EBB95F841, 0xBFC5737D76243000,\n 0x3FF2D50A0219A9D1, 0xBFC4DC7B8FC23000,\n 0x3FF2BEF9A8B7FD2A, 0xBFC4462C51D20000,\n 0x3FF2A91C7A0C1BAB, 0xBFC3B08ABC830000,\n 0x3FF293726014B530, 0xBFC31B996B490000,\n 0x3FF27DFA5757A1F5, 0xBFC2875490A44000,\n 0x3FF268B39B1D3BBF, 0xBFC1F3B9F879A000,\n 0x3FF2539D838FF5BD, 0xBFC160C8252CA000,\n 0x3FF23EB7AAC9083B, 0xBFC0CE7F57F72000,\n 0x3FF22A012BA940B6, 0xBFC03CDC49FEA000,\n 0x3FF2157996CC4132, 0xBFBF57BDBC4B8000,\n 0x3FF201201DD2FC9B, 0xBFBE370896404000,\n 0x3FF1ECF4494D480B, 0xBFBD17983EF94000,\n 0x3FF1D8F5528F6569, 0xBFBBF9674ED8A000,\n 0x3FF1C52311577E7C, 0xBFBADC79202F6000,\n 0x3FF1B17C74CB26E9, 0xBFB9C0C3E7288000,\n 0x3FF19E010C2C1AB6, 0xBFB8A646B372C000,\n 0x3FF18AB07BB670BD, 0xBFB78D01B3AC0000,\n 0x3FF1778A25EFBCB6, 0xBFB674F145380000,\n 0x3FF1648D354C31DA, 0xBFB55E0E6D878000,\n 0x3FF151B990275FDD, 0xBFB4485CDEA1E000,\n 0x3FF13F0EA432D24C, 0xBFB333D94D6AA000,\n 0x3FF12C8B7210F9DA, 0xBFB22079F8C56000,\n 0x3FF11A3028ECB531, 0xBFB10E4698622000,\n 0x3FF107FBDA8434AF, 0xBFAFFA6C6AD20000,\n 0x3FF0F5EE0F4E6BB3, 0xBFADDA8D4A774000,\n 0x3FF0E4065D2A9FCE, 0xBFABBCECE4850000,\n 0x3FF0D244632CA521, 0xBFA9A1894012C000,\n 0x3FF0C0A77CE2981A, 0xBFA788583302C000,\n 0x3FF0AF2F83C636D1, 0xBFA5715E67D68000,\n 0x3FF09DDB98A01339, 0xBFA35C8A49658000,\n 0x3FF08CABAF52E7DF, 0xBFA149E364154000,\n 0x3FF07B9F2F4E28FB, 0xBF9E72C082EB8000,\n 0x3FF06AB58C358F19, 0xBF9A55F152528000,\n 0x3FF059EEA5ECF92C, 0xBF963D62CF818000,\n 0x3FF04949CDD12C90, 0xBF9228FB8CAA0000,\n 0x3FF038C6C6F0ADA9, 0xBF8C317B20F90000,\n 0x3FF02865137932A9, 0xBF8419355DAA0000,\n 0x3FF0182427EA7348, 0xBF781203C2EC0000,\n 0x3FF008040614B195, 0xBF60040979240000,\n 0x3FEFE01FF726FA1A, 0x3F6FEFF384900000,\n 0x3FEFA11CC261EA74, 0x3F87DC41353D0000,\n 0x3FEF6310B081992E, 0x3F93CEA3C4C28000,\n 0x3FEF25F63CEEADCD, 0x3F9B9FC114890000,\n 0x3FEEE9C8039113E7, 0x3FA1B0D8CE110000,\n 0x3FEEAE8078CBB1AB, 0x3FA58A5BD001C000,\n 0x3FEE741AA29D0C9B, 0x3FA95C8340D88000,\n 0x3FEE3A91830A99B5, 0x3FAD276AEF578000,\n 0x3FEE01E009609A56, 0x3FB07598E598C000,\n 0x3FEDCA01E577BB98, 0x3FB253F5E30D2000,\n 0x3FED92F20B7C9103, 0x3FB42EDD8B380000,\n 0x3FED5CAC66FB5CCE, 0x3FB606598757C000,\n 0x3FED272CAA5EDE9D, 0x3FB7DA76356A0000,\n 0x3FECF26E3E6B2CCD, 0x3FB9AB434E1C6000,\n 0x3FECBE6DA2A77902, 0x3FBB78C7BB0D6000,\n 0x3FEC8B266D37086D, 0x3FBD431332E72000,\n 0x3FEC5894BD5D5804, 0x3FBF0A3171DE6000,\n 0x3FEC26B533BB9F8C, 0x3FC067152B914000,\n 0x3FEBF583EEECE73F, 0x3FC147858292B000,\n 0x3FEBC4FD75DB96C1, 0x3FC2266ECDCA3000,\n 0x3FEB951E0C864A28, 0x3FC303D7A6C55000,\n 0x3FEB65E2C5EF3E2C, 0x3FC3DFC33C331000,\n 0x3FEB374867C9888B, 0x3FC4BA366B7A8000,\n 0x3FEB094B211D304A, 0x3FC5933928D1F000,\n 0x3FEADBE885F2EF7E, 0x3FC66ACD2418F000,\n 0x3FEAAF1D31603DA2, 0x3FC740F8EC669000,\n 0x3FEA82E63FD358A7, 0x3FC815C0F51AF000,\n 0x3FEA5740EF09738B, 0x3FC8E92954F68000,\n 0x3FEA2C2A90AB4B27, 0x3FC9BB3602F84000,\n 0x3FEA01A01393F2D1, 0x3FCA8BED1C2C0000,\n 0x3FE9D79F24DB3C1B, 0x3FCB5B515C01D000,\n 0x3FE9AE2505C7B190, 0x3FCC2967CCBCC000,\n 0x3FE9852EF297CE2F, 0x3FCCF635D5486000,\n 0x3FE95CBAEEA44B75, 0x3FCDC1BD3446C000,\n 0x3FE934C69DE74838, 0x3FCE8C01B8CFE000,\n 0x3FE90D4F2F6752E6, 0x3FCF5509C0179000,\n 0x3FE8E6528EFFD79D, 0x3FD00E6C121FB800,\n 0x3FE8BFCE9FCC007C, 0x3FD071B80E93D000,\n 0x3FE899C0DABEC30E, 0x3FD0D46B9E867000,\n 0x3FE87427AA2317FB, 0x3FD13687334BD000,\n 0x3FE84F00ACB39A08, 0x3FD1980D67234800,\n 0x3FE82A49E8653E55, 0x3FD1F8FFE0CC8000,\n 0x3FE8060195F40260, 0x3FD2595FD7636800,\n 0x3FE7E22563E0A329, 0x3FD2B9300914A800,\n 0x3FE7BEB377DCB5AD, 0x3FD3187210436000,\n 0x3FE79BAA679725C2, 0x3FD377266DEC1800,\n 0x3FE77907F2170657, 0x3FD3D54FFBAF3000,\n 0x3FE756CADBD6130C, 0x3FD432EEE32FE000\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const LOG_DATA_TAB2 = memory.data([\n // chi , clo\n 0x3FE61000014FB66B, 0x3C7E026C91425B3C,\n 0x3FE63000034DB495, 0x3C8DBFEA48005D41,\n 0x3FE650000D94D478, 0x3C8E7FA786D6A5B7,\n 0x3FE67000074E6FAD, 0x3C61FCEA6B54254C,\n 0x3FE68FFFFEDF0FAE, 0xBC7C7E274C590EFD,\n 0x3FE6B0000763C5BC, 0xBC8AC16848DCDA01,\n 0x3FE6D0001E5CC1F6, 0x3C833F1C9D499311,\n 0x3FE6EFFFEB05F63E, 0xBC7E80041AE22D53,\n 0x3FE710000E869780, 0x3C7BFF6671097952,\n 0x3FE72FFFFC67E912, 0x3C8C00E226BD8724,\n 0x3FE74FFFDF81116A, 0xBC6E02916EF101D2,\n 0x3FE770000F679C90, 0xBC67FC71CD549C74,\n 0x3FE78FFFFA7EC835, 0x3C81BEC19EF50483,\n 0x3FE7AFFFFE20C2E6, 0xBC707E1729CC6465,\n 0x3FE7CFFFED3FC900, 0xBC808072087B8B1C,\n 0x3FE7EFFFE9261A76, 0x3C8DC0286D9DF9AE,\n 0x3FE81000049CA3E8, 0x3C897FD251E54C33,\n 0x3FE8300017932C8F, 0xBC8AFEE9B630F381,\n 0x3FE850000633739C, 0x3C89BFBF6B6535BC,\n 0x3FE87000204289C6, 0xBC8BBF65F3117B75,\n 0x3FE88FFFEBF57904, 0xBC89006EA23DCB57,\n 0x3FE8B00022BC04DF, 0xBC7D00DF38E04B0A,\n 0x3FE8CFFFE50C1B8A, 0xBC88007146FF9F05,\n 0x3FE8EFFFFC918E43, 0x3C83817BD07A7038,\n 0x3FE910001EFA5FC7, 0x3C893E9176DFB403,\n 0x3FE9300013467BB9, 0x3C7F804E4B980276,\n 0x3FE94FFFE6EE076F, 0xBC8F7EF0D9FF622E,\n 0x3FE96FFFDE3C12D1, 0xBC7082AA962638BA,\n 0x3FE98FFFF4458A0D, 0xBC87801B9164A8EF,\n 0x3FE9AFFFDD982E3E, 0xBC8740E08A5A9337,\n 0x3FE9CFFFED49FB66, 0x3C3FCE08C19BE000,\n 0x3FE9F00020F19C51, 0xBC8A3FAA27885B0A,\n 0x3FEA10001145B006, 0x3C74FF489958DA56,\n 0x3FEA300007BBF6FA, 0x3C8CBEAB8A2B6D18,\n 0x3FEA500010971D79, 0x3C88FECADD787930,\n 0x3FEA70001DF52E48, 0xBC8F41763DD8ABDB,\n 0x3FEA90001C593352, 0xBC8EBF0284C27612,\n 0x3FEAB0002A4F3E4B, 0xBC69FD043CFF3F5F,\n 0x3FEACFFFD7AE1ED1, 0xBC823EE7129070B4,\n 0x3FEAEFFFEE510478, 0x3C6A063EE00EDEA3,\n 0x3FEB0FFFDB650D5B, 0x3C5A06C8381F0AB9,\n 0x3FEB2FFFFEAACA57, 0xBC79011E74233C1D,\n 0x3FEB4FFFD995BADC, 0xBC79FF1068862A9F,\n 0x3FEB7000249E659C, 0x3C8AFF45D0864F3E,\n 0x3FEB8FFFF9871640, 0x3C7CFE7796C2C3F9,\n 0x3FEBAFFFD204CB4F, 0xBC63FF27EEF22BC4,\n 0x3FEBCFFFD2415C45, 0xBC6CFFB7EE3BEA21,\n 0x3FEBEFFFF86309DF, 0xBC814103972E0B5C,\n 0x3FEC0FFFE1B57653, 0x3C8BC16494B76A19,\n 0x3FEC2FFFF1FA57E3, 0xBC64FEEF8D30C6ED,\n 0x3FEC4FFFDCBFE424, 0xBC843F68BCEC4775,\n 0x3FEC6FFFED54B9F7, 0x3C847EA3F053E0EC,\n 0x3FEC8FFFEB998FD5, 0x3C7383068DF992F1,\n 0x3FECB0002125219A, 0xBC68FD8E64180E04,\n 0x3FECCFFFDD94469C, 0x3C8E7EBE1CC7EA72,\n 0x3FECEFFFEAFDC476, 0x3C8EBE39AD9F88FE,\n 0x3FED1000169AF82B, 0x3C757D91A8B95A71,\n 0x3FED30000D0FF71D, 0x3C89C1906970C7DA,\n 0x3FED4FFFEA790FC4, 0xBC580E37C558FE0C,\n 0x3FED70002EDC87E5, 0xBC7F80D64DC10F44,\n 0x3FED900021DC82AA, 0xBC747C8F94FD5C5C,\n 0x3FEDAFFFD86B0283, 0x3C8C7F1DC521617E,\n 0x3FEDD000296C4739, 0x3C88019EB2FFB153,\n 0x3FEDEFFFE54490F5, 0x3C6E00D2C652CC89,\n 0x3FEE0FFFCDABF694, 0xBC7F8340202D69D2,\n 0x3FEE2FFFDB52C8DD, 0x3C7B00C1CA1B0864,\n 0x3FEE4FFFF24216EF, 0x3C72FFA8B094AB51,\n 0x3FEE6FFFE88A5E11, 0xBC57F673B1EFBE59,\n 0x3FEE9000119EFF0D, 0xBC84808D5E0BC801,\n 0x3FEEAFFFDFA51744, 0x3C780006D54320B5,\n 0x3FEED0001A127FA1, 0xBC5002F860565C92,\n 0x3FEEF00007BABCC4, 0xBC8540445D35E611,\n 0x3FEF0FFFF57A8D02, 0xBC4FFB3139EF9105,\n 0x3FEF30001EE58AC7, 0x3C8A81ACF2731155,\n 0x3FEF4FFFF5823494, 0x3C8A3F41D4D7C743,\n 0x3FEF6FFFFCA94C6B, 0xBC6202F41C987875,\n 0x3FEF8FFFE1F9C441, 0x3C777DD1F477E74B,\n 0x3FEFAFFFD2E0E37E, 0xBC6F01199A7CA331,\n 0x3FEFD0001C77E49E, 0x3C7181EE4BCEACB1,\n 0x3FEFEFFFF7E0C331, 0xBC6E05370170875A,\n 0x3FF00FFFF465606E, 0xBC8A7EAD491C0ADA,\n 0x3FF02FFFF3867A58, 0xBC977F69C3FCB2E0,\n 0x3FF04FFFFDFC0D17, 0x3C97BFFE34CB945B,\n 0x3FF0700003CD4D82, 0x3C820083C0E456CB,\n 0x3FF08FFFF9F2CBE8, 0xBC6DFFDFBE37751A,\n 0x3FF0B000010CDA65, 0xBC913F7FAEE626EB,\n 0x3FF0D00001A4D338, 0x3C807DFA79489FF7,\n 0x3FF0EFFFFADAFDFD, 0xBC77040570D66BC0,\n 0x3FF110000BBAFD96, 0x3C8E80D4846D0B62,\n 0x3FF12FFFFAE5F45D, 0x3C9DBFFA64FD36EF,\n 0x3FF150000DD59AD9, 0x3C9A0077701250AE,\n 0x3FF170000F21559A, 0x3C8DFDF9E2E3DEEE,\n 0x3FF18FFFFC275426, 0x3C910030DC3B7273,\n 0x3FF1B000123D3C59, 0x3C997F7980030188,\n 0x3FF1CFFFF8299EB7, 0xBC65F932AB9F8C67,\n 0x3FF1EFFFF48AD400, 0x3C937FBF9DA75BEB,\n 0x3FF210000C8B86A4, 0x3C9F806B91FD5B22,\n 0x3FF2300003854303, 0x3C93FFC2EB9FBF33,\n 0x3FF24FFFFFBCF684, 0x3C7601E77E2E2E72,\n 0x3FF26FFFF52921D9, 0x3C7FFCBB767F0C61,\n 0x3FF2900014933A3C, 0xBC7202CA3C02412B,\n 0x3FF2B00014556313, 0xBC92808233F21F02,\n 0x3FF2CFFFEBFE523B, 0xBC88FF7E384FDCF2,\n 0x3FF2F0000BB8AD96, 0xBC85FF51503041C5,\n 0x3FF30FFFFB7AE2AF, 0xBC810071885E289D,\n 0x3FF32FFFFEAC5F7F, 0xBC91FF5D3FB7B715,\n 0x3FF350000CA66756, 0x3C957F82228B82BD,\n 0x3FF3700011FBF721, 0x3C8000BAC40DD5CC,\n 0x3FF38FFFF9592FB9, 0xBC943F9D2DB2A751,\n 0x3FF3B00004DDD242, 0x3C857F6B707638E1,\n 0x3FF3CFFFF5B2C957, 0x3C7A023A10BF1231,\n 0x3FF3EFFFEAB0B418, 0x3C987F6D66B152B0,\n 0x3FF410001532AFF4, 0x3C67F8375F198524,\n 0x3FF4300017478B29, 0x3C8301E672DC5143,\n 0x3FF44FFFE795B463, 0x3C89FF69B8B2895A,\n 0x3FF46FFFE80475E0, 0xBC95C0B19BC2F254,\n 0x3FF48FFFEF6FC1E7, 0x3C9B4009F23A2A72,\n 0x3FF4AFFFE5BEA704, 0xBC94FFB7BF0D7D45,\n 0x3FF4D000171027DE, 0xBC99C06471DC6A3D,\n 0x3FF4F0000FF03EE2, 0x3C977F890B85531C,\n 0x3FF5100012DC4BD1, 0x3C6004657166A436,\n 0x3FF530001605277A, 0xBC96BFCECE233209,\n 0x3FF54FFFECDB704C, 0xBC8902720505A1D7,\n 0x3FF56FFFEF5F54A9, 0x3C9BBFE60EC96412,\n 0x3FF5900017E61012, 0x3C887EC581AFEF90,\n 0x3FF5B00003C93E92, 0xBC9F41080ABF0CC0,\n 0x3FF5D0001D4919BC, 0xBC98812AFB254729,\n 0x3FF5EFFFE7B87A89, 0xBC947EB780ED6904\n]);\n\n// @ts-ignore: decorator\n@inline\nexport function log_lut(x: f64): f64 {\n const N_MASK = (1 << LOG_TABLE_BITS) - 1;\n\n const\n B0 = reinterpret(0xBFE0000000000000), // -0x1p-1\n B1 = reinterpret(0x3FD5555555555577), // 0x1.5555555555577p-2\n B2 = reinterpret(0xBFCFFFFFFFFFFDCB), // -0x1.ffffffffffdcbp-3\n B3 = reinterpret(0x3FC999999995DD0C), // 0x1.999999995dd0cp-3\n B4 = reinterpret(0xBFC55555556745A7), // -0x1.55555556745a7p-3\n B5 = reinterpret(0x3FC24924A344DE30), // 0x1.24924a344de3p-3\n B6 = reinterpret(0xBFBFFFFFA4423D65), // -0x1.fffffa4423d65p-4\n B7 = reinterpret(0x3FBC7184282AD6CA), // 0x1.c7184282ad6cap-4\n B8 = reinterpret(0xBFB999EB43B068FF), // -0x1.999eb43b068ffp-4\n B9 = reinterpret(0x3FB78182F7AFD085), // 0x1.78182f7afd085p-4\n B10 = reinterpret(0xBFB5521375D145CD); // -0x1.5521375d145cdp-4\n\n const\n A0 = reinterpret(0xBFE0000000000001), // -0x1.0000000000001p-1\n A1 = reinterpret(0x3FD555555551305B), // 0x1.555555551305bp-2\n A2 = reinterpret(0xBFCFFFFFFFEB4590), // -0x1.fffffffeb459p-3\n A3 = reinterpret(0x3FC999B324F10111), // 0x1.999b324f10111p-3\n A4 = reinterpret(0xBFC55575E506C89F); // -0x1.55575e506c89fp-3\n\n const\n LO: u64 = 0x3FEE000000000000,\n HI: u64 = 0x3FF1090000000000;\n\n const\n Ln2hi = reinterpret(0x3FE62E42FEFA3800), // 0x1.62e42fefa3800p-1\n Ln2lo = reinterpret(0x3D2EF35793C76730), // 0x1.ef35793c76730p-45\n Ox1p27 = reinterpret(0x41A0000000000000), // 0x1p27\n Ox1p52 = reinterpret(0x4330000000000000); // 0x1p52\n\n let ix = reinterpret(x);\n if (ix - LO < HI - LO) {\n let r = x - 1.0;\n let r2 = r * r;\n let r3 = r2 * r;\n let y =\n r3 * (B1 + r * B2 + r2 * B3 +\n r3 * (B4 + r * B5 + r2 * B6 +\n r3 * (B7 + r * B8 + r2 * B9 + r3 * B10)));\n // Worst-case error is around 0.507 ULP\n let w = r * Ox1p27;\n let rhi = r + w - w;\n let rlo = r - rhi;\n w = rhi * rhi * B0; // B[0] == -0.5\n let hi = r + w;\n let lo = r - hi + w;\n lo += B0 * rlo * (rhi + r);\n return y + lo + hi;\n }\n let top = u32(ix >> 48);\n if (top - 0x0010 >= 0x7FF0 - 0x0010) {\n // x < 0x1p-1022 or inf or nan\n if ((ix << 1) == 0) return -1.0 / (x * x);\n if (ix == reinterpret(Infinity)) return x; // log(inf) == inf\n if ((top & 0x8000) || (top & 0x7FF0) == 0x7FF0) return (x - x) / (x - x);\n // x is subnormal, normalize it\n ix = reinterpret(x * Ox1p52);\n ix -= u64(52) << 52;\n }\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n let tmp = ix - 0x3FE6000000000000;\n let i = ((tmp >> (52 - LOG_TABLE_BITS)) & N_MASK);\n let k = tmp >> 52;\n let iz = ix - (tmp & (u64(0xFFF) << 52));\n\n let invc = load(LOG_DATA_TAB1 + (i << (1 + alignof())), 0 << alignof()); // T[i].invc;\n let logc = load(LOG_DATA_TAB1 + (i << (1 + alignof())), 1 << alignof()); // T[i].logc;\n let z = reinterpret(iz);\n\n // log(x) = log1p(z/c-1) + log(c) + k*Ln2.\n // r ~= z/c - 1, |r| < 1/(2*N)\n // #if __FP_FAST_FMA\n // \t// rounding error: 0x1p-55/N\n // \tr = __builtin_fma(z, invc, -1.0);\n // #else\n // rounding error: 0x1p-55/N + 0x1p-66\n const chi = load(LOG_DATA_TAB2 + (i << (1 + alignof())), 0 << alignof()); // T2[i].chi\n const clo = load(LOG_DATA_TAB2 + (i << (1 + alignof())), 1 << alignof()); // T2[i].clo\n let r = (z - chi - clo) * invc;\n // #endif\n let kd = k;\n\n // hi + lo = r + log(c) + k*Ln2\n let w = kd * Ln2hi + logc;\n let hi = w + r;\n let lo = w - hi + r + kd * Ln2lo;\n\n // log(x) = lo + (log1p(r) - r) + hi\n let r2 = r * r; // rounding error: 0x1p-54/N^2\n // Worst case error if |y| > 0x1p-5:\n // 0.5 + 4.13/N + abs-poly-error*2^57 ULP (+ 0.002 ULP without fma)\n // Worst case error if |y| > 0x1p-4:\n // 0.5 + 2.06/N + abs-poly-error*2^56 ULP (+ 0.001 ULP without fma).\n return lo + r2 * A0 + r * r2 * (A1 + r * A2 + r2 * (A3 + r * A4)) + hi;\n}\n\n//\n// Lookup data for pow. See: https://git.musl-libc.org/cgit/musl/tree/src/math/pow.c\n//\n\n// @ts-ignore: decorator\n@inline const POW_LOG_TABLE_BITS = 7;\n\n/* Algorithm:\n\n x = 2^k z\n log(x) = k ln2 + log(c) + log(z/c)\n log(z/c) = poly(z/c - 1)\n\nwhere z is in [0x1.69555p-1; 0x1.69555p0] which is split into N subintervals\nand z falls into the ith one, then table entries are computed as\n\n tab[i].invc = 1/c\n tab[i].logc = round(0x1p43*log(c))/0x1p43\n tab[i].logctail = (double)(log(c) - logc)\n\nwhere c is chosen near the center of the subinterval such that 1/c has only a\nfew precision bits so z/c - 1 is exactly representible as double:\n\n 1/c = center < 1 ? round(N/center)/N : round(2*N/center)/N/2\n\nNote: |z/c - 1| < 1/N for the chosen c, |log(c) - logc - logctail| < 0x1p-97,\nthe last few bits of logc are rounded away so k*ln2hi + logc has no rounding\nerror and the interval for z is selected such that near x == 1, where log(x)\nis tiny, large cancellation error is avoided in logc + poly(z/c - 1). */\n\n// @ts-ignore: decorator\n@lazy @inline const POW_LOG_DATA_TAB = memory.data([\n // invc ,pad, logc , logctail\n 0x3FF6A00000000000, 0, 0xBFD62C82F2B9C800, 0x3CFAB42428375680,\n 0x3FF6800000000000, 0, 0xBFD5D1BDBF580800, 0xBD1CA508D8E0F720,\n 0x3FF6600000000000, 0, 0xBFD5767717455800, 0xBD2362A4D5B6506D,\n 0x3FF6400000000000, 0, 0xBFD51AAD872DF800, 0xBCE684E49EB067D5,\n 0x3FF6200000000000, 0, 0xBFD4BE5F95777800, 0xBD041B6993293EE0,\n 0x3FF6000000000000, 0, 0xBFD4618BC21C6000, 0x3D13D82F484C84CC,\n 0x3FF5E00000000000, 0, 0xBFD404308686A800, 0x3CDC42F3ED820B3A,\n 0x3FF5C00000000000, 0, 0xBFD3A64C55694800, 0x3D20B1C686519460,\n 0x3FF5A00000000000, 0, 0xBFD347DD9A988000, 0x3D25594DD4C58092,\n 0x3FF5800000000000, 0, 0xBFD2E8E2BAE12000, 0x3D267B1E99B72BD8,\n 0x3FF5600000000000, 0, 0xBFD2895A13DE8800, 0x3D15CA14B6CFB03F,\n 0x3FF5600000000000, 0, 0xBFD2895A13DE8800, 0x3D15CA14B6CFB03F,\n 0x3FF5400000000000, 0, 0xBFD22941FBCF7800, 0xBD165A242853DA76,\n 0x3FF5200000000000, 0, 0xBFD1C898C1699800, 0xBD1FAFBC68E75404,\n 0x3FF5000000000000, 0, 0xBFD1675CABABA800, 0x3D1F1FC63382A8F0,\n 0x3FF4E00000000000, 0, 0xBFD1058BF9AE4800, 0xBD26A8C4FD055A66,\n 0x3FF4C00000000000, 0, 0xBFD0A324E2739000, 0xBD0C6BEE7EF4030E,\n 0x3FF4A00000000000, 0, 0xBFD0402594B4D000, 0xBCF036B89EF42D7F,\n 0x3FF4A00000000000, 0, 0xBFD0402594B4D000, 0xBCF036B89EF42D7F,\n 0x3FF4800000000000, 0, 0xBFCFB9186D5E4000, 0x3D0D572AAB993C87,\n 0x3FF4600000000000, 0, 0xBFCEF0ADCBDC6000, 0x3D2B26B79C86AF24,\n 0x3FF4400000000000, 0, 0xBFCE27076E2AF000, 0xBD172F4F543FFF10,\n 0x3FF4200000000000, 0, 0xBFCD5C216B4FC000, 0x3D21BA91BBCA681B,\n 0x3FF4000000000000, 0, 0xBFCC8FF7C79AA000, 0x3D27794F689F8434,\n 0x3FF4000000000000, 0, 0xBFCC8FF7C79AA000, 0x3D27794F689F8434,\n 0x3FF3E00000000000, 0, 0xBFCBC286742D9000, 0x3D194EB0318BB78F,\n 0x3FF3C00000000000, 0, 0xBFCAF3C94E80C000, 0x3CBA4E633FCD9066,\n 0x3FF3A00000000000, 0, 0xBFCA23BC1FE2B000, 0xBD258C64DC46C1EA,\n 0x3FF3A00000000000, 0, 0xBFCA23BC1FE2B000, 0xBD258C64DC46C1EA,\n 0x3FF3800000000000, 0, 0xBFC9525A9CF45000, 0xBD2AD1D904C1D4E3,\n 0x3FF3600000000000, 0, 0xBFC87FA06520D000, 0x3D2BBDBF7FDBFA09,\n 0x3FF3400000000000, 0, 0xBFC7AB890210E000, 0x3D2BDB9072534A58,\n 0x3FF3400000000000, 0, 0xBFC7AB890210E000, 0x3D2BDB9072534A58,\n 0x3FF3200000000000, 0, 0xBFC6D60FE719D000, 0xBD10E46AA3B2E266,\n 0x3FF3000000000000, 0, 0xBFC5FF3070A79000, 0xBD1E9E439F105039,\n 0x3FF3000000000000, 0, 0xBFC5FF3070A79000, 0xBD1E9E439F105039,\n 0x3FF2E00000000000, 0, 0xBFC526E5E3A1B000, 0xBD20DE8B90075B8F,\n 0x3FF2C00000000000, 0, 0xBFC44D2B6CCB8000, 0x3D170CC16135783C,\n 0x3FF2C00000000000, 0, 0xBFC44D2B6CCB8000, 0x3D170CC16135783C,\n 0x3FF2A00000000000, 0, 0xBFC371FC201E9000, 0x3CF178864D27543A,\n 0x3FF2800000000000, 0, 0xBFC29552F81FF000, 0xBD248D301771C408,\n 0x3FF2600000000000, 0, 0xBFC1B72AD52F6000, 0xBD2E80A41811A396,\n 0x3FF2600000000000, 0, 0xBFC1B72AD52F6000, 0xBD2E80A41811A396,\n 0x3FF2400000000000, 0, 0xBFC0D77E7CD09000, 0x3D0A699688E85BF4,\n 0x3FF2400000000000, 0, 0xBFC0D77E7CD09000, 0x3D0A699688E85BF4,\n 0x3FF2200000000000, 0, 0xBFBFEC9131DBE000, 0xBD2575545CA333F2,\n 0x3FF2000000000000, 0, 0xBFBE27076E2B0000, 0x3D2A342C2AF0003C,\n 0x3FF2000000000000, 0, 0xBFBE27076E2B0000, 0x3D2A342C2AF0003C,\n 0x3FF1E00000000000, 0, 0xBFBC5E548F5BC000, 0xBD1D0C57585FBE06,\n 0x3FF1C00000000000, 0, 0xBFBA926D3A4AE000, 0x3D253935E85BAAC8,\n 0x3FF1C00000000000, 0, 0xBFBA926D3A4AE000, 0x3D253935E85BAAC8,\n 0x3FF1A00000000000, 0, 0xBFB8C345D631A000, 0x3D137C294D2F5668,\n 0x3FF1A00000000000, 0, 0xBFB8C345D631A000, 0x3D137C294D2F5668,\n 0x3FF1800000000000, 0, 0xBFB6F0D28AE56000, 0xBD269737C93373DA,\n 0x3FF1600000000000, 0, 0xBFB51B073F062000, 0x3D1F025B61C65E57,\n 0x3FF1600000000000, 0, 0xBFB51B073F062000, 0x3D1F025B61C65E57,\n 0x3FF1400000000000, 0, 0xBFB341D7961BE000, 0x3D2C5EDACCF913DF,\n 0x3FF1400000000000, 0, 0xBFB341D7961BE000, 0x3D2C5EDACCF913DF,\n 0x3FF1200000000000, 0, 0xBFB16536EEA38000, 0x3D147C5E768FA309,\n 0x3FF1000000000000, 0, 0xBFAF0A30C0118000, 0x3D2D599E83368E91,\n 0x3FF1000000000000, 0, 0xBFAF0A30C0118000, 0x3D2D599E83368E91,\n 0x3FF0E00000000000, 0, 0xBFAB42DD71198000, 0x3D1C827AE5D6704C,\n 0x3FF0E00000000000, 0, 0xBFAB42DD71198000, 0x3D1C827AE5D6704C,\n 0x3FF0C00000000000, 0, 0xBFA77458F632C000, 0xBD2CFC4634F2A1EE,\n 0x3FF0C00000000000, 0, 0xBFA77458F632C000, 0xBD2CFC4634F2A1EE,\n 0x3FF0A00000000000, 0, 0xBFA39E87B9FEC000, 0x3CF502B7F526FEAA,\n 0x3FF0A00000000000, 0, 0xBFA39E87B9FEC000, 0x3CF502B7F526FEAA,\n 0x3FF0800000000000, 0, 0xBF9F829B0E780000, 0xBD2980267C7E09E4,\n 0x3FF0800000000000, 0, 0xBF9F829B0E780000, 0xBD2980267C7E09E4,\n 0x3FF0600000000000, 0, 0xBF97B91B07D58000, 0xBD288D5493FAA639,\n 0x3FF0400000000000, 0, 0xBF8FC0A8B0FC0000, 0xBCDF1E7CF6D3A69C,\n 0x3FF0400000000000, 0, 0xBF8FC0A8B0FC0000, 0xBCDF1E7CF6D3A69C,\n 0x3FF0200000000000, 0, 0xBF7FE02A6B100000, 0xBD19E23F0DDA40E4,\n 0x3FF0200000000000, 0, 0xBF7FE02A6B100000, 0xBD19E23F0DDA40E4,\n 0x3FF0000000000000, 0, 0, 0,\n 0x3FF0000000000000, 0, 0, 0,\n 0x3FEFC00000000000, 0, 0x3F80101575890000, 0xBD10C76B999D2BE8,\n 0x3FEF800000000000, 0, 0x3F90205658938000, 0xBD23DC5B06E2F7D2,\n 0x3FEF400000000000, 0, 0x3F98492528C90000, 0xBD2AA0BA325A0C34,\n 0x3FEF000000000000, 0, 0x3FA0415D89E74000, 0x3D0111C05CF1D753,\n 0x3FEEC00000000000, 0, 0x3FA466AED42E0000, 0xBD2C167375BDFD28,\n 0x3FEE800000000000, 0, 0x3FA894AA149FC000, 0xBD197995D05A267D,\n 0x3FEE400000000000, 0, 0x3FACCB73CDDDC000, 0xBD1A68F247D82807,\n 0x3FEE200000000000, 0, 0x3FAEEA31C006C000, 0xBD0E113E4FC93B7B,\n 0x3FEDE00000000000, 0, 0x3FB1973BD1466000, 0xBD25325D560D9E9B,\n 0x3FEDA00000000000, 0, 0x3FB3BDF5A7D1E000, 0x3D2CC85EA5DB4ED7,\n 0x3FED600000000000, 0, 0x3FB5E95A4D97A000, 0xBD2C69063C5D1D1E,\n 0x3FED400000000000, 0, 0x3FB700D30AEAC000, 0x3CEC1E8DA99DED32,\n 0x3FED000000000000, 0, 0x3FB9335E5D594000, 0x3D23115C3ABD47DA,\n 0x3FECC00000000000, 0, 0x3FBB6AC88DAD6000, 0xBD1390802BF768E5,\n 0x3FECA00000000000, 0, 0x3FBC885801BC4000, 0x3D2646D1C65AACD3,\n 0x3FEC600000000000, 0, 0x3FBEC739830A2000, 0xBD2DC068AFE645E0,\n 0x3FEC400000000000, 0, 0x3FBFE89139DBE000, 0xBD2534D64FA10AFD,\n 0x3FEC000000000000, 0, 0x3FC1178E8227E000, 0x3D21EF78CE2D07F2,\n 0x3FEBE00000000000, 0, 0x3FC1AA2B7E23F000, 0x3D2CA78E44389934,\n 0x3FEBA00000000000, 0, 0x3FC2D1610C868000, 0x3D039D6CCB81B4A1,\n 0x3FEB800000000000, 0, 0x3FC365FCB0159000, 0x3CC62FA8234B7289,\n 0x3FEB400000000000, 0, 0x3FC4913D8333B000, 0x3D25837954FDB678,\n 0x3FEB200000000000, 0, 0x3FC527E5E4A1B000, 0x3D2633E8E5697DC7,\n 0x3FEAE00000000000, 0, 0x3FC6574EBE8C1000, 0x3D19CF8B2C3C2E78,\n 0x3FEAC00000000000, 0, 0x3FC6F0128B757000, 0xBD25118DE59C21E1,\n 0x3FEAA00000000000, 0, 0x3FC7898D85445000, 0xBD1C661070914305,\n 0x3FEA600000000000, 0, 0x3FC8BEAFEB390000, 0xBD073D54AAE92CD1,\n 0x3FEA400000000000, 0, 0x3FC95A5ADCF70000, 0x3D07F22858A0FF6F,\n 0x3FEA000000000000, 0, 0x3FCA93ED3C8AE000, 0xBD28724350562169,\n 0x3FE9E00000000000, 0, 0x3FCB31D8575BD000, 0xBD0C358D4EACE1AA,\n 0x3FE9C00000000000, 0, 0x3FCBD087383BE000, 0xBD2D4BC4595412B6,\n 0x3FE9A00000000000, 0, 0x3FCC6FFBC6F01000, 0xBCF1EC72C5962BD2,\n 0x3FE9600000000000, 0, 0x3FCDB13DB0D49000, 0xBD2AFF2AF715B035,\n 0x3FE9400000000000, 0, 0x3FCE530EFFE71000, 0x3CC212276041F430,\n 0x3FE9200000000000, 0, 0x3FCEF5ADE4DD0000, 0xBCCA211565BB8E11,\n 0x3FE9000000000000, 0, 0x3FCF991C6CB3B000, 0x3D1BCBECCA0CDF30,\n 0x3FE8C00000000000, 0, 0x3FD07138604D5800, 0x3CF89CDB16ED4E91,\n 0x3FE8A00000000000, 0, 0x3FD0C42D67616000, 0x3D27188B163CEAE9,\n 0x3FE8800000000000, 0, 0x3FD1178E8227E800, 0xBD2C210E63A5F01C,\n 0x3FE8600000000000, 0, 0x3FD16B5CCBACF800, 0x3D2B9ACDF7A51681,\n 0x3FE8400000000000, 0, 0x3FD1BF99635A6800, 0x3D2CA6ED5147BDB7,\n 0x3FE8200000000000, 0, 0x3FD214456D0EB800, 0x3D0A87DEBA46BAEA,\n 0x3FE7E00000000000, 0, 0x3FD2BEF07CDC9000, 0x3D2A9CFA4A5004F4,\n 0x3FE7C00000000000, 0, 0x3FD314F1E1D36000, 0xBD28E27AD3213CB8,\n 0x3FE7A00000000000, 0, 0x3FD36B6776BE1000, 0x3D116ECDB0F177C8,\n 0x3FE7800000000000, 0, 0x3FD3C25277333000, 0x3D183B54B606BD5C,\n 0x3FE7600000000000, 0, 0x3FD419B423D5E800, 0x3D08E436EC90E09D,\n 0x3FE7400000000000, 0, 0x3FD4718DC271C800, 0xBD2F27CE0967D675,\n 0x3FE7200000000000, 0, 0x3FD4C9E09E173000, 0xBD2E20891B0AD8A4,\n 0x3FE7000000000000, 0, 0x3FD522AE0738A000, 0x3D2EBE708164C759,\n 0x3FE6E00000000000, 0, 0x3FD57BF753C8D000, 0x3D1FADEDEE5D40EF,\n 0x3FE6C00000000000, 0, 0x3FD5D5BDDF596000, 0xBD0A0B2A08A465DC\n]);\n\n// Returns 0 if not int, 1 if odd int, 2 if even int. The argument is\n// the bit representation of a non-zero finite floating-point value.\n// @ts-ignore: decorator\n@inline\nfunction checkint(iy: u64): i32 {\n let e = iy >> 52 & 0x7FF;\n if (e < 0x3FF ) return 0;\n if (e > 0x3FF + 52) return 2;\n e = u64(1) << (0x3FF + 52 - e);\n if (iy & (e - 1)) return 0;\n if (iy & e ) return 1;\n return 2;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction xflow(sign: u32, y: f64): f64 {\n return select(-y, y, sign) * y;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction uflow(sign: u32): f64 {\n return xflow(sign, reinterpret(0x1000000000000000)); // 0x1p-767\n}\n\n// @ts-ignore: decorator\n@inline\nfunction oflow(sign: u32): f64 {\n return xflow(sign, reinterpret(0x7000000000000000)); // 0x1p769\n}\n\n// Returns 1 if input is the bit representation of 0, infinity or nan.\n// @ts-ignore: decorator\n@inline\nfunction zeroinfnan(u: u64): bool {\n return (u << 1) - 1 >= 0xFFE0000000000000 - 1;\n}\n\n// @ts-ignore: decorator\n@lazy let log_tail: f64 = 0;\n\n// Compute y+TAIL = log(x) where the rounded result is y and TAIL has about\n// additional 15 bits precision. IX is the bit representation of x, but\n// normalized in the subnormal range using the sign bit for the exponent.\n// @ts-ignore: decorator\n@inline\nfunction log_inline(ix: u64): f64 {\n const N = 1 << POW_LOG_TABLE_BITS;\n const N_MASK = N - 1;\n\n const\n Ln2hi = reinterpret(0x3FE62E42FEFA3800),\n Ln2lo = reinterpret(0x3D2EF35793C76730);\n\n const\n A0 = reinterpret(0xBFE0000000000000),\n A1 = reinterpret(0xBFE5555555555560),\n A2 = reinterpret(0x3FE0000000000006),\n A3 = reinterpret(0x3FE999999959554E),\n A4 = reinterpret(0xBFE555555529A47A),\n A5 = reinterpret(0xBFF2495B9B4845E9),\n A6 = reinterpret(0x3FF0002B8B263FC3);\n\n // x = 2^k z; where z is in range [OFF,2*OFF) and exact.\n // The range is split into N subintervals.\n // The ith subinterval contains z and c is near its center.\n let tmp = ix - 0x3fE6955500000000;\n let i = usize((tmp >> (52 - POW_LOG_TABLE_BITS)) & N_MASK);\n let k = tmp >> 52;\n let iz = ix - (tmp & u64(0xFFF) << 52);\n let z = reinterpret(iz);\n let kd = k;\n\n // log(x) = k*Ln2 + log(c) + log1p(z/c-1).\n let invc = load(POW_LOG_DATA_TAB + (i << (2 + alignof())), 0 << alignof()); // tab[i].invc\n let logc = load(POW_LOG_DATA_TAB + (i << (2 + alignof())), 2 << alignof()); // tab[i].logc\n let logctail = load(POW_LOG_DATA_TAB + (i << (2 + alignof())), 3 << alignof()); // tab[i].logctail\n\n // Note: 1/c is j/N or j/N/2 where j is an integer in [N,2N) and\n // |z/c - 1| < 1/N, so r = z/c - 1 is exactly representible.\n // Split z such that rhi, rlo and rhi*rhi are exact and |rlo| <= |r|.\n let zhi = reinterpret((iz + u64(0x80000000)) & 0xFFFFFFFF00000000);\n let zlo = z - zhi;\n let rhi = zhi * invc - 1.0;\n let rlo = zlo * invc;\n let r = rhi + rlo;\n\n // k * Ln2 + log(c) + r.\n let t1 = kd * Ln2hi + logc;\n let t2 = t1 + r;\n let lo1 = kd * Ln2lo + logctail;\n let lo2 = t1 - t2 + r;\n\n // Evaluation is optimized assuming superscalar pipelined execution.\n let ar = A0 * r; // A[0] = -0.5\n let ar2 = r * ar;\n let ar3 = r * ar2;\n // k * Ln2 + log(c) + r + A[0] * r * r.\n let arhi = A0 * rhi;\n let arhi2 = rhi * arhi;\n let hi = t2 + arhi2;\n let lo3 = rlo * (ar + arhi);\n let lo4 = t2 - hi + arhi2;\n\n // p = log1p(r) - r - A[0] * r * r.\n let p = ar3 * (A1 + r * A2 + ar2 * (A3 + r * A4 + ar2 * (A5 + r * A6)));\n let lo = lo1 + lo2 + lo3 + lo4 + p;\n let y = hi + lo;\n log_tail = hi - y + lo;\n\n return y;\n}\n\n// @ts-ignore: decorator\n@inline const SIGN_BIAS = 0x800 << EXP_TABLE_BITS;\n\n// Computes sign*exp(x+xtail) where |xtail| < 2^-8/N and |xtail| <= |x|.\n// The sign_bias argument is SIGN_BIAS or 0 and sets the sign to -1 or 1.\n// @ts-ignore: decorator\n@inline\nfunction exp_inline(x: f64, xtail: f64, sign_bias: u32): f64 {\n const N = 1 << EXP_TABLE_BITS;\n const N_MASK = N - 1;\n\n const\n InvLn2N = reinterpret(0x3FF71547652B82FE) * N, // 0x1.71547652b82fep0\n NegLn2hiN = reinterpret(0xBF762E42FEFA0000), // -0x1.62e42fefa0000p-8\n NegLn2loN = reinterpret(0xBD0CF79ABC9E3B3A), // -0x1.cf79abc9e3b3ap-47\n shift = reinterpret(0x4338000000000000); // 0x1.8p52\n\n const\n C2 = reinterpret(0x3FDFFFFFFFFFFDBD), // __exp_data.poly[0] (0x1.ffffffffffdbdp-2)\n C3 = reinterpret(0x3FC555555555543C), // __exp_data.poly[1] (0x1.555555555543cp-3)\n C4 = reinterpret(0x3FA55555CF172B91), // __exp_data.poly[2] (0x1.55555cf172b91p-5)\n C5 = reinterpret(0x3F81111167A4D017); // __exp_data.poly[3] (0x1.1111167a4d017p-7)\n\n let abstop: u32;\n let ki: u64, top: u64, sbits: u64;\n let idx: usize;\n // double_t for better performance on targets with FLT_EVAL_METHOD==2.\n let kd: f64, z: f64, r: f64, r2: f64, scale: f64, tail: f64, tmp: f64;\n\n let ux = reinterpret(x);\n abstop = u32(ux >> 52) & 0x7FF;\n if (abstop - 0x3C9 >= 0x03F) {\n if (abstop - 0x3C9 >= 0x80000000) {\n // Avoid spurious underflow for tiny x.\n // Note: 0 is common input.\n return select(-1.0, 1.0, sign_bias);\n }\n if (abstop >= 0x409) { // top12(1024.0)\n // Note: inf and nan are already handled.\n return ux < 0\n ? uflow(sign_bias)\n : oflow(sign_bias);\n }\n // Large x is special cased below.\n abstop = 0;\n }\n\n // exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)].\n // x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N].\n z = InvLn2N * x;\n\n // #if TOINT_INTRINSICS\n // kd = roundtoint(z);\n // ki = converttoint(z);\n // #elif EXP_USE_TOINT_NARROW\n // // z - kd is in [-0.5-2^-16, 0.5] in all rounding modes.\n // kd = eval_as_double(z + shift);\n // ki = asuint64(kd) >> 16;\n // kd = (double_t)(int32_t)ki;\n // #else\n // z - kd is in [-1, 1] in non-nearest rounding modes\n kd = z + shift;\n ki = reinterpret(kd);\n kd -= shift;\n // #endif\n r = x + kd * NegLn2hiN + kd * NegLn2loN;\n // The code assumes 2^-200 < |xtail| < 2^-8/N\n r += xtail;\n // 2^(k/N) ~= scale * (1 + tail)\n idx = usize((ki & N_MASK) << 1);\n top = (ki + sign_bias) << (52 - EXP_TABLE_BITS);\n\n tail = reinterpret(load(EXP_DATA_TAB + (idx << alignof())));\n // This is only a valid scale when -1023*N < k < 1024*N\n sbits = load(EXP_DATA_TAB + (idx << alignof()), 1 << alignof()) + top;\n // exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1).\n // Evaluation is optimized assuming superscalar pipelined execution.\n r2 = r * r;\n // Without fma the worst case error is 0.25/N ulp larger.\n // Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp\n tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5);\n if (abstop == 0) return specialcase(tmp, sbits, ki);\n scale = reinterpret(sbits);\n // Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there\n // is no spurious underflow here even without fma.\n return scale + scale * tmp;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function pow_lut(x: f64, y: f64): f64 {\n const Ox1p52 = reinterpret(0x4330000000000000); // 0x1p52\n\n let sign_bias: u32 = 0;\n let ix = reinterpret(x);\n let iy = reinterpret(y);\n let topx = ix >> 52;\n let topy = iy >> 52;\n\n if (topx - 0x001 >= 0x7FF - 0x001 || (topy & 0x7FF) - 0x3BE >= 0x43e - 0x3BE) {\n // Note: if |y| > 1075 * ln2 * 2^53 ~= 0x1.749p62 then pow(x,y) = inf/0\n // and if |y| < 2^-54 / 1075 ~= 0x1.e7b6p-65 then pow(x,y) = +-1.\n // Special cases: (x < 0x1p-126 or inf or nan) or\n // (|y| < 0x1p-65 or |y| >= 0x1p63 or nan).\n if (zeroinfnan(iy)) {\n if ((iy << 1) == 0) return 1.0;\n if (ix == 0x3FF0000000000000) return NaN; // original: 1.0\n if ((ix << 1) > 0xFFE0000000000000 || (iy << 1) > 0xFFE0000000000000) return x + y;\n if ((ix << 1) == 0x7FE0000000000000) return NaN; // original: 1.0\n if (((ix << 1) < 0x7FE0000000000000) == !(iy >> 63)) return 0; // |x|<1 && y==inf or |x|>1 && y==-inf.\n return y * y;\n }\n if (zeroinfnan(ix)) {\n let x2 = x * x;\n if (i32(ix >> 63) && checkint(iy) == 1) x2 = -x2;\n return iy < 0 ? 1 / x2 : x2;\n }\n // Here x and y are non-zero finite\n if (ix < 0) {\n // Finite x < 0\n let yint = checkint(iy);\n if (yint == 0) return (x - x) / (x - x);\n if (yint == 1) sign_bias = SIGN_BIAS;\n ix &= 0x7FFFFFFFFFFFFFFF;\n topx &= 0x7FF;\n }\n if ((topy & 0x7FF) - 0x3BE >= 0x43E - 0x3BE) {\n // Note: sign_bias == 0 here because y is not odd.\n if (ix == 0x3FF0000000000000) return 1;\n if ((topy & 0x7FF) < 0x3BE) return 1; // |y| < 2^-65, x^y ~= 1 + y*log(x).\n return (ix > 0x3FF0000000000000) == (topy < 0x800) ? Infinity : 0;\n }\n if (topx == 0) {\n // Normalize subnormal x so exponent becomes negative.\n ix = reinterpret(x * Ox1p52);\n ix &= 0x7FFFFFFFFFFFFFFF;\n ix -= u64(52) << 52;\n }\n }\n\n let hi = log_inline(ix);\n let lo = log_tail;\n let ehi: f64, elo: f64;\n // #if __FP_FAST_FMA\n // ehi = y * hi;\n // elo = y * lo + __builtin_fma(y, hi, -ehi);\n // #else\n let yhi = reinterpret(iy & 0xFFFFFFFFF8000000);\n let ylo = y - yhi;\n let lhi = reinterpret(reinterpret(hi) & 0xFFFFFFFFF8000000);\n let llo = hi - lhi + lo;\n ehi = yhi * lhi;\n elo = ylo * lhi + y * llo; // |elo| < |ehi| * 2^-25.\n // #endif\n return exp_inline(ehi, elo, sign_bias);\n}\n","import {\n itoa32,\n utoa32,\n itoa64,\n utoa64,\n dtoa,\n itoa_buffered,\n dtoa_buffered,\n MAX_DOUBLE_LENGTH\n} from \"./number\";\n\nimport {\n ipow32\n} from \"../math\";\n\n// All tables are stored as two staged lookup tables (static tries)\n// because the full range of Unicode symbols can't be efficiently\n// represented as-is in memory (see Unicode spec ch 5, p.196):\n// https://www.unicode.org/versions/Unicode12.0.0/ch05.pdf\n// Tables have been generated using these forked musl tools:\n// https://github.com/MaxGraey/musl-chartable-tools/tree/case-ignorable\n\n// Lookup table to check if a character is alphanumeric or not\n// See: https://git.musl-libc.org/cgit/musl/tree/src/ctype/alpha.h\n// size: 3904 bytes\n// @ts-ignore\n@inline @lazy const ALPHA_TABLE = memory.data([\n 18,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,17,34,35,36,17,37,38,39,40,\n 41,42,43,44,17,45,46,47,16,16,48,16,16,16,16,16,16,16,49,50,51,16,52,53,16,16,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,54,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,55,17,17,17,17,56,17,57,58,59,60,61,62,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,63,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,64,65,17,66,67,\n 68,69,70,71,72,73,74,17,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,\n 93,94,16,95,96,97,98,17,17,17,99,100,101,16,16,16,16,16,16,16,16,16,16,17,17,\n 17,17,102,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,103,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,17,17,104,105,16,16,106,107,17,17,17,17,17,17,17,17,17,17,17,17,17,\n 17,17,17,17,17,17,17,17,17,17,108,17,17,17,17,109,110,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 17,111,112,16,16,16,16,16,16,16,16,16,113,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,114,115,116,117,16,16,16,16,16,16,16,16,118,\n 119,120,16,16,16,16,16,121,122,16,16,16,16,123,16,16,124,16,16,16,16,16,16,16,\n 16,16,125,16,16,16,\n 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,254,255,255,7,254,\n 255,255,7,0,0,0,0,0,4,32,4,255,255,127,255,255,255,127,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,195,255,3,0,31,80,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,223,188,64,215,255,255,\n 251,255,255,255,255,255,255,255,255,255,191,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,3,252,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,254,255,255,255,127,2,255,255,255,\n 255,255,1,0,0,0,0,255,191,182,0,255,255,255,135,7,0,0,0,255,7,255,255,255,255,\n 255,255,255,254,255,195,255,255,255,255,255,255,255,255,255,255,255,255,239,\n 31,254,225,255,\n 159,0,0,255,255,255,255,255,255,0,224,255,255,255,255,255,255,255,255,255,255,\n 255,255,3,0,255,255,255,255,255,7,48,4,255,255,255,252,255,31,0,0,255,255,255,\n 1,255,7,0,0,0,0,0,0,255,255,223,255,255,0,240,255,248,3,255,255,255,255,255,\n 255,255,255,255,239,255,223,225,255,207,255,254,255,239,159,249,255,255,253,\n 197,227,159,89,128,176,207,255,3,16,238,135,249,255,255,253,109,195,135,25,2,\n 94,192,255,63,0,238,191,251,255,255,253,237,227,191,27,1,0,207,255,0,30,238,\n 159,249,255,255,253,237,227,159,25,192,176,207,255,2,0,236,199,61,214,24,199,\n 255,195,199,29,129,0,192,255,0,0,239,223,253,255,255,253,255,227,223,29,96,7,\n 207,255,0,0,239,223,253,255,255,253,239,227,223,29,96,64,207,255,6,0,255,223,\n 253,255,255,255,255,231,223,93,240,128,207,255,0,252,238,255,127,252,255,255,\n 251,47,127,128,95,255,192,255,12,0,254,255,255,255,255,127,255,7,63,32,255,3,\n 0,0,0,0,214,247,255,255,175,255,255,59,95,32,255,243,0,0,0,\n 0,1,0,0,0,255,3,0,0,255,254,255,255,255,31,254,255,3,255,255,254,255,255,255,\n 31,0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,249,255,3,255,255,255,255,255,\n 255,255,255,255,63,255,255,255,255,191,32,255,255,255,255,255,247,255,255,255,\n 255,255,255,255,255,255,61,127,61,255,255,255,255,255,61,255,255,255,255,61,\n 127,61,255,127,255,255,255,255,255,255,255,61,255,255,255,255,255,255,255,255,\n 7,0,0,0,0,255,255,0,0,255,255,255,255,255,255,255,255,255,255,63,63,254,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,159,255,255,254,255,255,7,255,255,255,255,255,255,255,255,\n 255,199,255,1,255,223,15,0,255,255,15,0,255,255,15,0,255,223,13,0,255,255,255,\n 255,255,255,207,255,255,1,128,16,255,3,0,0,0,0,255,3,255,255,255,255,255,255,\n 255,255,255,255,255,1,255,255,255,255,255,7,255,255,255,255,255,255,255,255,\n 63,\n 0,255,255,255,127,255,15,255,1,192,255,255,255,255,63,31,0,255,255,255,255,\n 255,15,255,255,255,3,255,3,0,0,0,0,255,255,255,15,255,255,255,255,255,255,255,\n 127,254,255,31,0,255,3,255,3,128,0,0,128,1,0,0,0,0,0,0,0,255,255,255,255,255,\n 255,239,255,239,15,255,3,0,0,0,0,255,255,255,255,255,243,255,255,255,255,255,\n 255,191,255,3,0,255,255,255,255,255,255,127,0,255,227,255,255,255,255,255,63,\n 255,1,255,255,255,255,255,231,0,0,0,0,0,222,111,4,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,\n 128,255,31,0,255,255,63,63,255,255,255,255,63,63,255,170,255,255,255,63,255,\n 255,255,255,255,255,223,95,220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,2,128,0,0,255,31,0,0,0,0,0,0,0,0,0,0,0,0,132,252,47,62,80,189,255,243,\n 224,67,0,0,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,255,255,255,255,255,255,3,0,\n 0,255,255,255,255,255,127,255,255,255,255,255,127,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,31,120,12,0,255,255,255,255,191,32,255,\n 255,255,255,255,255,255,128,0,0,255,255,127,0,127,127,127,127,127,127,127,127,\n 255,255,255,255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,224,0,0,0,254,3,62,31,254,255,255,255,255,255,255,255,255,255,127,224,254,\n 255,255,255,255,255,255,255,255,255,255,247,224,255,255,255,255,255,254,255,\n 255,255,255,255,255,255,255,255,255,127,0,0,255,255,255,255,0,0,0,0,0,0,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,\n 31,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,\n 0,0,0,0,0,0,255,255,255,255,255,63,255,31,255,255,255,15,0,0,255,255,255,255,\n 255,127,240,143,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,\n 0,128,255,252,255,255,255,255,255,255,255,255,255,255,255,255,249,255,255,255,\n 255,255,255,252,7,0,0,0,0,224,255,191,255,255,255,255,0,0,0,255,255,255,255,\n 255,255,15,0,255,255,255,255,255,255,255,255,47,0,255,3,0,0,252,232,255,255,\n 255,255,255,7,255,255,255,255,7,0,255,255,255,31,255,255,255,255,255,255,247,\n 255,0,128,255,3,255,255,255,127,255,255,255,255,255,255,127,0,255,63,255,3,\n 255,255,127,252,255,255,255,255,255,255,255,127,5,0,0,56,255,255,60,0,126,126,\n 126,0,127,127,255,255,255,255,255,247,255,3,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,7,255,3,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,15,0,255,255,127,248,255,255,255,255,\n 255,\n 15,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,3,0,0,0,0,127,0,248,224,255,253,127,95,219,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,3,0,0,0,248,255,255,255,\n 255,255,255,255,255,255,255,255,255,63,0,0,255,255,255,255,255,255,255,255,\n 252,255,255,255,255,255,255,0,0,0,0,0,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,223,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,255,3,\n 254,255,255,7,254,255,255,7,192,255,255,255,255,255,255,255,255,255,255,127,\n 252,252,252,28,0,0,0,0,255,239,255,255,127,255,255,183,255,63,255,63,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,31,255,255,255,255,255,255,1,0,0,0,0,\n 0,255,255,255,255,0,224,255,255,255,7,255,255,255,255,255,7,255,255,255,63,\n 255,255,255,255,15,255,62,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,63,255,3,255,255,255,255,15,255,255,255,\n 255,15,255,255,255,255,255,0,255,255,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,0,255,255,63,0,255,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,63,253,255,255,255,255,191,145,255,255,63,0,255,255,\n 127,0,255,255,255,127,0,0,0,0,0,0,0,0,255,255,55,0,255,255,63,0,255,255,255,3,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,192,0,0,0,0,0,0,0,0,111,240,239,\n 254,255,255,63,0,0,0,0,0,255,255,255,31,255,255,255,31,0,0,0,0,255,254,255,\n 255,31,0,0,0,255,255,255,255,255,255,63,0,255,255,63,0,255,255,7,0,255,255,3,\n 0,0,0,0,0,0,0,0,0,0,0,0,\n 0,255,255,255,255,255,255,255,255,255,1,0,0,0,0,0,0,255,255,255,255,255,255,7,\n 0,255,255,255,255,255,255,7,0,255,255,255,255,255,0,255,3,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,\n 255,27,3,0,0,0,0,0,0,0,0,0,255,255,255,31,128,0,255,255,63,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,255,31,0,0,0,255,255,127,0,255,255,255,255,255,255,255,255,63,0,0,\n 0,192,255,0,0,252,255,255,255,255,255,255,1,0,0,255,255,255,1,255,3,255,255,\n 255,255,255,255,199,255,240,0,255,255,255,255,71,0,255,255,255,255,255,255,\n 255,255,30,192,255,23,0,0,0,0,255,255,251,255,255,255,159,64,0,0,0,0,0,0,0,0,\n 127,189,255,191,255,1,255,255,255,255,255,255,255,1,255,3,239,159,249,255,255,\n 253,237,227,159,25,129,224,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,255,255,255,255,255,255,255,255,187,7,255,131,3,0,0,0,255,255,255,255,255,\n 255,255,255,179,0,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,\n 255,255,255,63,127,0,0,0,63,0,0,0,0,255,255,255,255,255,255,255,127,17,0,255,\n 3,0,0,0,0,255,255,255,255,255,255,63,1,255,3,0,0,0,0,0,0,255,255,255,231,255,\n 7,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,\n 255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,3,0,128,\n 127,242,111,255,255,255,191,153,7,0,255,3,0,0,0,0,0,0,0,0,255,252,255,255,255,\n 255,255,252,26,0,0,0,255,255,255,255,255,255,231,127,0,0,255,255,255,255,255,\n 255,255,255,255,32,0,0,0,0,255,255,255,255,255,255,255,1,255,253,255,255,255,\n 255,127,127,1,0,255,3,0,0,252,255,255,255,252,255,255,254,127,0,0,0,0,0,0,0,0,\n 0,127,251,255,255,255,255,127,180,203,0,255,3,191,253,255,255,255,127,123,1,\n 255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,\n 0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,3,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,127,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,255,255,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,\n 0,255,255,255,255,255,255,255,1,255,255,255,127,255,3,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,63,0,0,255,255,255,255,255,255,0,0,15,0,255,3,248,255,255,224,255,\n 255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,\n 255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,135,\n 255,255,255,255,255,255,255,128,255,255,0,0,0,0,0,0,0,0,11,0,3,0,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,0,0,0,0,0,\n 255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,\n 127,0,0,0,0,0,0,7,0,240,0,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,15,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,7,255,31,255,1,255,67,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,223,255,255,255,255,255,255,255,255,\n 223,100,222,255,235,239,255,255,255,255,255,255,255,191,231,223,223,255,255,\n 255,123,95,252,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,63,255,255,255,253,255,255,247,255,255,255,\n 247,255,255,223,255,255,255,223,255,255,127,255,255,255,127,255,255,255,253,\n 255,255,255,253,255,255,247,207,255,255,255,255,255,255,127,255,255,249,219,7,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,31,\n 128,63,255,67,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,15,255,\n 3,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,31,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,143,8,\n 255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,239,255,255,255,150,254,247,10,\n 132,234,150,170,150,247,247,94,255,251,255,15,238,251,255,15,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,255,255,255,3,255,255,255,3,255,255,255,3,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,3\n]);\n\n// size: 1568 bytes (compressed to ~1380 bytes after binaryen)\n// @ts-ignore: decorator\n@lazy @inline const CASED = memory.data([\n 18,19,20,21,22,23,16,16,16,16,16,16,16,16,16,16,\n 24,16,16,25,16,16,16,16,16,16,16,16,26,27,17,28,\n 29,30,16,16,31,16,16,16,16,16,16,16,32,33,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,34,35,16,16,16,36,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,37,16,16,16,38,\n 16,16,16,16,39,16,16,16,16,16,16,16,40,16,16,16,\n 16,16,16,16,16,16,16,16,41,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,42,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,43,44,45,46,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,47,16,16,16,16,16,16,\n 16,48,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,254,255,255,7,254,255,255,7,0,0,0,0,0,4,32,4,\n 255,255,127,255,255,255,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,247,240,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,239,255,255,255,255,1,3,0,0,0,31,0,0,0,\n 0,0,0,0,0,0,0,0,32,0,0,0,0,0,207,188,64,215,255,255,251,255,255,255,\n 255,255,255,255,255,255,191,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 3,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,255,\n 255,255,127,0,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,\n 191,32,255,255,255,255,255,231,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,255,255,255,255,255,255,255,255,255,63,63,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,1,255,255,255,255,255,231,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,255,255,63,63,255,255,255,255,63,63,255,170,255,255,255,63,\n 255,255,255,255,255,255,223,95,220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,2,128,0,0,255,31,0,0,0,0,0,0,0,0,0,0,0,0,\n 132,252,47,62,80,189,31,242,224,67,0,0,255,255,255,255,24,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,192,255,255,255,255,255,255,3,0,0,255,255,255,255,255,127,255,255,\n 255,255,255,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,120,12,0,\n 255,255,255,255,191,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,63,0,0,\n 255,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,255,255,255,\n 255,255,255,255,255,255,255,255,255,120,255,255,255,255,255,255,252,7,0,0,0,0,96,7,\n 0,0,0,0,0,0,255,255,255,255,255,247,255,1,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,0,0,0,0,127,0,248,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254,255,255,7,\n 254,255,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,255,255,\n 255,255,15,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,7,0,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,223,255,255,255,255,255,\n 255,255,255,223,100,222,255,235,239,255,255,255,255,255,255,255,191,231,223,223,255,255,255,123,\n 95,252,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,\n 253,255,255,247,255,255,255,247,255,255,223,255,255,255,223,255,255,127,255,255,255,127,255,255,\n 255,253,255,255,255,253,255,255,247,15,0,0,0,0,0,0,255,255,255,255,255,255,255,255,\n 15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,255,255,255,3,255,255,255,3,255,255,255,3,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0\n]);\n\n// size: 2976 bytes (compressed to ~2050 bytes after binaryen)\n// @ts-ignore: decorator\n@lazy @inline const CASE_IGNORABLES = memory.data([\n 18,16,19,20,21,22,23,24,25,26,27,28,29,30,31,32,\n 33,16,16,34,16,16,16,35,36,37,38,39,40,41,16,42,\n 43,16,16,16,16,16,16,16,16,16,16,16,44,45,46,16,\n 47,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 48,16,16,16,49,16,50,51,52,53,54,55,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,56,16,16,57,58,\n 16,59,60,61,16,16,16,16,16,16,62,16,16,63,64,65,\n 66,67,68,69,70,71,72,73,74,75,76,16,77,78,79,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,80,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,81,82,16,16,16,83,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,84,16,16,16,\n 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,\n 16,85,86,16,16,16,16,16,16,16,87,16,16,16,16,16,\n 88,89,90,16,16,16,16,16,91,92,16,16,16,16,16,16,\n 16,16,16,93,16,16,16,16,16,16,16,16,16,16,16,16,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 0,0,0,0,128,64,0,4,0,0,0,64,1,0,0,0,0,0,0,0,0,161,144,1,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,\n 255,255,255,255,255,255,48,4,176,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,3,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,130,0,0,0,0,\n 0,0,254,255,255,255,255,191,182,0,0,0,0,0,16,0,63,0,255,23,0,0,0,0,\n 1,248,255,255,0,0,1,0,0,0,0,0,0,0,0,0,0,0,192,191,255,61,0,0,\n 0,128,2,0,0,0,255,255,255,7,0,0,0,0,0,0,0,0,0,0,192,255,1,0,\n 0,0,0,0,0,248,63,36,0,0,192,255,255,63,0,0,0,0,0,14,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,248,255,255,255,255,255,7,0,0,0,0,0,0,20,\n 254,33,254,0,12,0,2,0,2,0,0,0,0,0,0,16,30,32,0,0,12,0,0,64,\n 6,0,0,0,0,0,0,16,134,57,2,0,0,0,35,0,6,0,0,0,0,0,0,16,\n 190,33,0,0,12,0,0,252,2,0,0,0,0,0,0,144,30,32,96,0,12,0,0,0,\n 4,0,0,0,0,0,0,0,1,32,0,0,0,0,0,0,17,0,0,0,0,0,0,192,\n 193,61,96,0,12,0,0,0,2,0,0,0,0,0,0,144,64,48,0,0,12,0,0,0,\n 3,0,0,0,0,0,0,24,30,32,0,0,12,0,0,0,2,0,0,0,0,0,0,0,\n 0,4,92,0,0,0,0,0,0,0,0,0,0,0,242,7,192,127,0,0,0,0,0,0,\n 0,0,0,0,0,0,242,31,64,63,0,0,0,0,0,0,0,0,0,3,0,0,160,2,\n 0,0,0,0,0,0,254,127,223,224,255,254,255,255,255,31,64,0,0,0,0,0,0,0,\n 0,0,0,0,0,224,253,102,0,0,0,195,1,0,30,0,100,32,0,32,0,0,0,0,\n 0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0,0,0,28,0,\n 0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,143,32,0,0,0,0,\n 0,120,0,0,0,0,0,0,8,0,0,0,0,0,0,0,96,0,0,0,0,2,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,135,1,4,14,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,9,0,0,0,0,\n 0,0,64,127,229,31,248,159,0,0,0,0,128,0,255,255,1,0,0,0,0,0,0,0,\n 15,0,0,0,0,0,208,23,4,0,0,0,0,248,15,0,3,0,0,0,60,59,0,0,\n 0,0,0,0,64,163,3,0,0,0,0,0,0,240,207,0,0,0,0,0,0,0,0,63,\n 0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,3,0,0,0,0,0,240,255,255,\n 255,255,255,255,255,7,0,1,0,0,0,248,255,255,255,255,255,255,255,255,255,255,255,251,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,160,\n 3,224,0,224,0,224,0,96,0,248,0,3,144,124,0,0,0,0,0,0,223,255,2,128,\n 0,0,255,31,0,0,0,0,0,0,255,255,255,255,1,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,48,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,128,0,0,0,0,0,0,0,0,\n 0,0,0,0,255,255,255,255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,60,62,8,\n 0,0,0,0,0,0,0,0,0,0,0,126,0,0,0,0,0,0,0,0,0,0,0,112,\n 0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,63,0,16,0,0,0,0,0,0,\n 0,0,0,0,0,128,247,191,0,0,0,240,0,0,0,0,0,0,0,0,0,0,3,0,\n 255,255,255,255,3,0,0,0,0,0,0,0,0,0,1,0,0,7,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,3,68,8,0,0,96,16,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,48,0,0,0,255,255,3,128,0,0,0,0,192,63,0,0,\n 128,255,3,0,0,0,0,0,7,0,0,0,0,0,200,51,0,128,0,0,96,0,0,0,\n 0,0,0,0,0,126,102,0,8,16,0,0,0,0,1,16,0,0,0,0,0,0,157,193,\n 2,0,0,32,0,48,88,0,0,0,0,0,0,0,0,0,0,0,0,248,0,14,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,32,33,0,0,0,0,0,64,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,255,3,0,0,0,0,0,0,0,\n 255,255,8,0,255,255,0,0,0,0,36,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,128,128,64,0,4,0,0,0,64,1,0,0,0,0,0,1,0,\n 0,0,0,192,0,0,0,0,0,0,0,0,8,0,0,14,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,7,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,110,240,0,0,0,0,0,135,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,\n 0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 192,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 2,0,0,0,0,0,0,255,127,0,0,0,0,0,0,128,3,0,0,0,0,0,120,38,\n 0,32,0,0,0,0,0,0,7,0,0,0,128,239,31,0,0,0,0,0,0,0,8,0,\n 3,0,0,0,0,0,192,127,0,158,0,0,0,0,0,0,0,0,0,0,0,128,211,64,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,248,7,0,0,\n 3,0,0,0,0,0,0,24,1,0,0,0,192,31,31,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,92,0,0,64,0,0,0,0,\n 0,0,0,0,0,0,248,133,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,60,176,1,0,0,48,0,0,0,0,\n 0,0,0,0,0,0,248,167,1,0,0,0,0,0,0,0,0,0,0,0,0,40,191,0,\n 0,0,0,0,0,0,0,0,0,0,0,224,188,15,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,255,6,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,88,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,240,12,1,0,0,0,254,7,0,0,0,0,248,121,128,0,126,14,0,0,0,0,\n 0,252,127,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,191,\n 0,0,0,0,0,0,0,0,0,0,252,255,255,252,109,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,126,180,191,0,0,0,0,0,0,0,0,0,163,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,0,0,0,0,0,0,255,1,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,31,0,0,0,0,0,0,0,127,0,15,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,128,0,0,0,0,0,0,0,128,255,255,0,0,0,0,0,0,0,0,27,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,15,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,248,255,\n 231,15,0,0,0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 255,255,255,255,255,255,127,248,255,255,255,255,255,31,32,0,16,0,0,248,254,255,0,0,\n 0,0,0,0,0,0,0,0,127,255,255,249,219,7,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,63,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 240,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n 0,0,0,0,0,0,0,248\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const LOWER127 = memory.data([\n 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,\n 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,\n 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,\n 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,\n 64,\n 97,98,99,100,101,102,103,104,105,106,107,108,109,\n 110,111,112,113,114,115,116,117,118,119,120,121,122,\n 91,92,93,94,95,96,\n 97,98,99,100,101,102,103,104,105,106,107,108,109,\n 110,111,112,113,114,115,116,117,118,119,120,121,122,\n 123,124,125,126,127\n]);\n\n// @ts-ignore: decorator\n@lazy @inline const UPPER127 = memory.data([\n 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,\n 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,\n 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,\n 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,\n 64,\n 65,66,67,68,69,70,71,72,73,74,75,76,77,\n 78,79,80,81,82,83,84,85,86,87,88,89,90,\n 91,92,93,94,95,96,\n 65,66,67,68,69,70,71,72,73,74,75,76,77,\n 78,79,80,81,82,83,84,85,86,87,88,89,90,\n 123,124,125,126,127\n]);\n\n// 23 * 8 = 184 bytes\n// @ts-ignore: decorator\n@lazy @inline const POWERS10 = memory.data([\n 1e00, 1e01, 1e02, 1e03, 1e04, 1e05, 1e06, 1e07, 1e08, 1e09,\n 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,\n 1e20, 1e21, 1e22\n]);\n\n// @ts-ignore: decorator\n@inline\nexport const enum CharCode {\n PERCENT = 0x25,\n PLUS = 0x2B,\n MINUS = 0x2D,\n DOT = 0x2E,\n _0 = 0x30,\n _1 = 0x31,\n _2 = 0x32,\n _3 = 0x33,\n _4 = 0x34,\n _5 = 0x35,\n _6 = 0x36,\n _7 = 0x37,\n _8 = 0x38,\n _9 = 0x39,\n A = 0x41,\n B = 0x42,\n E = 0x45,\n I = 0x49,\n N = 0x4E,\n O = 0x4F,\n X = 0x58,\n Z = 0x5A,\n a = 0x61,\n b = 0x62,\n e = 0x65,\n n = 0x6E,\n o = 0x6F,\n u = 0x75,\n x = 0x78,\n z = 0x7A\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isAscii(c: u32): bool {\n return !(c >> 7);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isLower8(c: u32): bool {\n return c - CharCode.a < 26;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isUpper8(c: u32): bool {\n return c - CharCode.A < 26;\n}\n\nexport function isSpace(c: u32): bool {\n if (c < 0x1680) { // < (1)\n // , , , , , and \n // (c == 0x20 || c == 0xA0) was optimized to (c | 0x80) == 0xA0\n return ((c | 0x80) == 0xA0) || (c - 0x09 <= 0x0D - 0x09);\n }\n if (c - 0x2000 <= 0x200A - 0x2000) return true;\n switch (c) {\n case 0x1680: // (1)\n case 0x2028: // (2)\n case 0x2029: // \n case 0x202F: // \n case 0x205F: // \n case 0x3000: // \n case 0xFEFF: return true; // \n }\n return false;\n}\n\nexport function isAlpha(c: u32): bool {\n if (isAscii(c)) return (c | 32) - CharCode.a < 26;\n if (c < 0x20000) {\n // @ts-ignore: cast\n return stagedBinaryLookup(ALPHA_TABLE, c);\n }\n return c < 0x2FFFE;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isCased(c: u32): bool {\n // @ts-ignore: cast\n return c < 0x1F18A && stagedBinaryLookup(CASED, c);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isCaseIgnorable(c: u32): bool {\n // @ts-ignore: cast\n return c < 0xE01F0 && stagedBinaryLookup(CASE_IGNORABLES, c);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function isFinalSigma(buffer: usize, index: isize, len: isize): bool {\n const lookaheadLimit = 30; // max lookahead limit\n let found = false;\n let pos = index;\n let minPos = max(0, pos - lookaheadLimit);\n while (pos > minPos) {\n let c = codePointBefore(buffer, pos);\n if (!isCaseIgnorable(c)) {\n if (isCased(c)) {\n found = true;\n } else {\n return false;\n }\n }\n pos -= isize(c >= 0x10000) + 1;\n }\n if (!found) return false;\n pos = index + 1;\n let maxPos = min(pos + lookaheadLimit, len);\n while (pos < maxPos) {\n let c = load(buffer + (pos << 1));\n if (u32((c & 0xFC00) == 0xD800) & u32(pos + 1 != len)) {\n let c1 = load(buffer + (pos << 1), 2);\n if ((c1 & 0xFC00) == 0xDC00) {\n c = (c - 0xD800 << 10) + (c1 - 0xDC00) + 0x10000;\n }\n }\n if (!isCaseIgnorable(c)) {\n return !isCased(c);\n }\n pos += isize(c >= 0x10000) + 1;\n }\n return true;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction codePointBefore(buffer: usize, index: isize): i32 {\n if (index <= 0) return -1;\n let c = load(buffer + (index - 1 << 1));\n if (u32((c & 0xFC00) == 0xDC00) & u32(index - 2 >= 0)) {\n let c1 = load(buffer + (index - 2 << 1));\n if ((c1 & 0xFC00) == 0xD800) {\n return ((c1 & 0x3FF) << 10) + (c & 0x3FF) + 0x10000;\n }\n }\n return (c & 0xF800) == 0xD800 ? 0xFFFD : c;\n}\n\n// Search routine for two-staged lookup tables\nfunction stagedBinaryLookup(table: usize, c: u32): bool {\n return ((load(table + (load(table + (c >>> 8)) << 5) + ((c & 255) >> 3)) >>> (c & 7)) & 1);\n}\n\nexport function compareImpl(str1: string, index1: usize, str2: string, index2: usize, len: usize): i32 {\n let ptr1 = changetype(str1) + (index1 << 1);\n let ptr2 = changetype(str2) + (index2 << 1);\n if (ASC_SHRINK_LEVEL < 2) {\n if (len >= 4 && !((ptr1 & 7) | (ptr2 & 7))) {\n do {\n if (load(ptr1) != load(ptr2)) break;\n ptr1 += 8;\n ptr2 += 8;\n len -= 4;\n } while (len >= 4);\n }\n }\n while (len--) {\n let a = load(ptr1);\n let b = load(ptr2);\n if (a != b) return a - b;\n ptr1 += 2;\n ptr2 += 2;\n }\n return 0;\n}\n\n// @ts-ignore: decorator\n@inline\nexport function toLower8(c: u32): u32 {\n if (ASC_SHRINK_LEVEL > 0) {\n return c | u32(isUpper8(c)) << 5;\n } else {\n return load(LOWER127 + c);\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function toUpper8(c: u32): u32 {\n if (ASC_SHRINK_LEVEL > 0) {\n return c & ~(u32(isLower8(c)) << 5);\n } else {\n return load(UPPER127 + c);\n }\n}\n\n/** Parses a string to an integer (usually), using the specified radix. */\nexport function strtol(str: string, radix: i32 = 0): T {\n let len = str.length;\n if (!len) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n\n let ptr = changetype(str) /* + HEAD -> offset */;\n let code = load(ptr);\n\n // trim white spaces\n while (isSpace(code)) {\n code = load(ptr += 2);\n --len;\n }\n // determine sign\n // @ts-ignore\n let sign: T = 1;\n if (code == CharCode.MINUS || code == CharCode.PLUS) {\n if (!--len) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n if (code == CharCode.MINUS) {\n // @ts-ignore: type\n sign = -1;\n }\n code = load(ptr += 2);\n }\n\n // See https://tc39.es/ecma262/#sec-parseint-string-radix\n if (radix) {\n if (radix < 2 || radix > 36) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n // handle case as parseInt(\"0xFF\", 16) by spec\n if (radix == 16) {\n if (\n len > 2 &&\n code == CharCode._0 &&\n (load(ptr, 2) | 32) == CharCode.x\n ) {\n ptr += 4; len -= 2;\n }\n }\n } else {\n // determine radix by literal prefix\n if (code == CharCode._0 && len > 2) {\n switch (load(ptr, 2) | 32) {\n case CharCode.b: {\n ptr += 4; len -= 2;\n radix = 2;\n break;\n }\n case CharCode.o: {\n ptr += 4; len -= 2;\n radix = 8;\n break;\n }\n case CharCode.x: {\n ptr += 4; len -= 2;\n radix = 16;\n break;\n }\n }\n }\n if (!radix) radix = 10;\n }\n\n // calculate value\n // @ts-ignore: type\n let num: T = 0;\n let initial = len - 1;\n while (len--) {\n code = load(ptr);\n if (code - CharCode._0 < 10) {\n code -= CharCode._0;\n } else if (code - CharCode.A <= (CharCode.Z - CharCode.A)) {\n code -= CharCode.A - 10;\n } else if (code - CharCode.a <= (CharCode.z - CharCode.a)) {\n code -= CharCode.a - 10;\n }\n if (code >= radix) {\n if (initial == len) {\n if (isFloat()) {\n // @ts-ignore: cast\n return NaN;\n } else {\n // @ts-ignore: cast\n return 0;\n }\n }\n break;\n }\n // @ts-ignore: type\n num = num * radix + code;\n ptr += 2;\n }\n // @ts-ignore: type\n return sign * num;\n}\n\nexport function strtod(str: string): f64 {\n let len = str.length;\n if (!len) return NaN;\n\n let ptr = changetype(str);\n let code = load(ptr);\n\n let sign = 1.0;\n // skip white spaces\n while (len && isSpace(code)) {\n code = load(ptr += 2);\n --len;\n }\n if (!len) return NaN;\n\n // try parse '-' or '+'\n if (code == CharCode.MINUS) {\n if (!--len) return NaN;\n code = load(ptr += 2);\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) return NaN;\n code = load(ptr += 2);\n }\n\n // try parse Infinity\n if (len >= 8 && code == CharCode.I) {\n if (\n load(ptr, 0) == 0x690066006E0049 && // ifnI\n load(ptr, 8) == 0x7900740069006E // ytin\n ) {\n return Infinity * sign;\n }\n return NaN;\n }\n // validate next symbol\n if (code != CharCode.DOT && (code - CharCode._0) >= 10) {\n return NaN;\n }\n let savedPtr = ptr;\n // skip zeros\n while (code == CharCode._0) {\n code = load(ptr += 2);\n --len;\n }\n if (len <= 0) return 0.0 * sign;\n const capacity = 19; // int(64 * 0.3010)\n let pointed = false;\n let consumed = 0;\n let position = 0;\n let x: u64 = 0;\n if (code == CharCode.DOT) {\n let noDigits = !(savedPtr - ptr);\n ptr += 2; --len;\n if (!len && noDigits) return NaN;\n for (pointed = true; (code = load(ptr)) == CharCode._0; --position, ptr += 2) --len;\n if (len <= 0) return 0.0 * sign;\n if (!position && noDigits && code - CharCode._0 >= 10) return NaN;\n }\n for (let digit = code - CharCode._0; digit < 10 || (code == CharCode.DOT && !pointed); digit = code - CharCode._0) {\n if (digit < 10) {\n x = consumed < capacity ? 10 * x + digit : x | u64(!!digit);\n ++consumed;\n } else {\n position = consumed;\n pointed = true;\n }\n if (!--len) break;\n code = load(ptr += 2);\n }\n\n if (!pointed) position = consumed;\n return copysign(scientific(x, position - min(capacity, consumed) + parseExp(ptr, len)), sign);\n}\n\nexport function strtob(str: string): bool {\n let size: usize = str.length << 1;\n let offset: usize = 0;\n if (size > 8) {\n // try trim end whitespaces first\n while (size && isSpace(load(changetype(str) + size - 2))) size -= 2;\n if (size > 8) {\n // trim start whitespaces\n while (offset < size && isSpace(load(changetype(str) + offset))) offset += 2;\n size -= offset;\n }\n }\n if (size != 8) return false;\n // \"true\" represents as \\00\\e\\00\\u\\00\\e\\00\\t (00 65 00 75 00 72 00 74)\n return load(changetype(str) + offset) == 0x0065_0075_0072_0074;\n}\n\nexport function joinBooleanArray(dataStart: usize, length: i32, separator: string): string {\n let lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) return select(\"true\", \"false\", load(dataStart));\n\n let sepLen = separator.length;\n let valueLen = 5; // max possible length of element len(\"false\")\n let estLen = (valueLen + sepLen) * lastIndex + valueLen;\n let result = changetype(__new(estLen << 1, idof()));\n let offset = 0;\n let value: bool;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + i);\n valueLen = 4 + i32(!value);\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(select(\"true\", \"false\", value)),\n valueLen << 1\n );\n offset += valueLen;\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + lastIndex);\n valueLen = 4 + i32(!value);\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(select(\"true\", \"false\", value)),\n valueLen << 1\n );\n offset += valueLen;\n\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinIntegerArray(dataStart: usize, length: i32, separator: string): string {\n let lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) {\n let value = load(dataStart);\n if (isSigned()) {\n if (sizeof() <= 4) {\n // @ts-ignore: type\n return changetype(itoa32(value, 10));\n } else {\n // @ts-ignore: type\n return changetype(itoa64(value, 10));\n }\n } else {\n if (sizeof() <= 4) {\n // @ts-ignore: type\n return changetype(utoa32(value, 10));\n } else {\n // @ts-ignore: type\n return changetype(utoa64(value, 10));\n }\n }\n }\n\n let sepLen = separator.length;\n const valueLen = (sizeof() <= 4 ? 10 : 20) + i32(isSigned());\n let estLen = (valueLen + sepLen) * lastIndex + valueLen;\n let result = changetype(__new(estLen << 1, idof()));\n let offset = 0;\n let value: T;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n // @ts-ignore: type\n offset += itoa_buffered(changetype(result) + (offset << 1), value);\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + (lastIndex << alignof()));\n // @ts-ignore: type\n offset += itoa_buffered(changetype(result) + (offset << 1), value);\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinFloatArray(dataStart: usize, length: i32, separator: string): string {\n let lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) {\n return changetype(dtoa(\n // @ts-ignore: type\n load(dataStart))\n );\n }\n\n const valueLen = MAX_DOUBLE_LENGTH;\n let sepLen = separator.length;\n let estLen = (valueLen + sepLen) * lastIndex + valueLen;\n let result = changetype(__new(estLen << 1, idof()));\n let offset = 0;\n let value: T;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n // @ts-ignore: type\n offset += dtoa_buffered(changetype(result) + (offset << 1), value);\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + (lastIndex << alignof()));\n // @ts-ignore: type\n offset += dtoa_buffered(changetype(result) + (offset << 1), value);\n if (estLen > offset) return result.substring(0, offset);\n return result;\n}\n\nexport function joinStringArray(dataStart: usize, length: i32, separator: string): string {\n let lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n if (!lastIndex) {\n // @ts-ignore: type\n return load(dataStart) || \"\";\n }\n let estLen = 0;\n let value: string;\n for (let i = 0; i < length; ++i) {\n value = load(dataStart + (i << alignof()));\n if (changetype(value) != 0) estLen += value.length;\n }\n let offset = 0;\n let sepLen = separator.length;\n let result = changetype(__new((estLen + sepLen * lastIndex) << 1, idof()));\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n if (changetype(value) != 0) {\n let valueLen = value.length;\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(value),\n valueLen << 1\n );\n offset += valueLen;\n }\n if (sepLen) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(separator),\n sepLen << 1\n );\n offset += sepLen;\n }\n }\n value = load(dataStart + (lastIndex << alignof()));\n if (changetype(value) != 0) {\n memory.copy(\n changetype(result) + (offset << 1),\n changetype(value),\n value.length << 1\n );\n }\n return result;\n}\n\nexport function joinReferenceArray(dataStart: usize, length: i32, separator: string): string {\n let lastIndex = length - 1;\n if (lastIndex < 0) return \"\";\n let value: T;\n if (!lastIndex) {\n value = load(dataStart);\n // @ts-ignore: type\n return value != null ? value.toString() : \"\";\n }\n let result = \"\";\n let sepLen = separator.length;\n for (let i = 0; i < lastIndex; ++i) {\n value = load(dataStart + (i << alignof()));\n // @ts-ignore: type\n if (value != null) result += value.toString();\n if (sepLen) result += separator;\n }\n value = load(dataStart + (lastIndex << alignof()));\n // @ts-ignore: type\n if (value != null) result += value.toString();\n return result;\n}\n\n// @ts-ignore: decorator\n@inline\nfunction scientific(significand: u64, exp: i32): f64 {\n if (!significand || exp < -342) return 0;\n if (exp > 308) return Infinity;\n // Try use fast path\n // Use fast path for string-to-double conversion if possible\n // see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion\n // Simple integer\n let significandf = significand;\n if (!exp) return significandf;\n if (exp > 22 && exp <= 22 + 15) {\n significandf *= pow10(exp - 22);\n exp = 22;\n }\n if (significand <= 9007199254740991 && abs(exp) <= 22) {\n if (exp > 0) return significandf * pow10(exp);\n return significandf / pow10(-exp);\n } else if (exp < 0) {\n return scaledown(significand, exp);\n } else {\n return scaleup(significand, exp);\n }\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction scaledown(significand: u64, exp: i32): f64 {\n const denom: u64 = 6103515625; // 1e14 * 0x1p-14\n const scale = reinterpret(0x3F06849B86A12B9B); // 1e-14 * 0x1p32\n\n let shift = clz(significand);\n significand <<= shift;\n shift = exp - shift;\n\n for (; exp <= -14; exp += 14) {\n let q = significand / denom;\n let r = significand % denom;\n let s = clz(q);\n significand = (q << s) + nearest(scale * (r << (s - 18)));\n shift -= s;\n }\n let b = ipow32(5, -exp);\n let q = significand / b;\n let r = significand % b;\n let s = clz(q);\n significand = (q << s) + (reinterpret(reinterpret(r) + (s << 52)) / b);\n shift -= s;\n\n return NativeMath.scalbn(significand, shift);\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction scaleup(significand: u64, exp: i32): f64 {\n const coeff: u32 = 1220703125; // 1e13 * 0x1p-13;\n let shift = ctz(significand);\n significand >>= shift;\n shift += exp;\n\n __fixmulShift = shift;\n for (; exp >= 13; exp -= 13) {\n significand = fixmul(significand, coeff);\n }\n significand = fixmul(significand, ipow32(5, exp));\n shift = __fixmulShift;\n return NativeMath.scalbn(significand, shift);\n}\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction parseExp(ptr: usize, len: i32): i32 {\n let sign = 1, magnitude = 0;\n let code = load(ptr);\n // check code is 'e' or 'E'\n if ((code | 32) != CharCode.e) return 0;\n\n if (!--len) return 0;\n code = load(ptr += 2);\n if (code == CharCode.MINUS) {\n if (!--len) return 0;\n code = load(ptr += 2);\n sign = -1;\n } else if (code == CharCode.PLUS) {\n if (!--len) return 0;\n code = load(ptr += 2);\n }\n // skip zeros\n while (code == CharCode._0) {\n if (!--len) return 0;\n code = load(ptr += 2);\n }\n for (let digit: u32 = code - CharCode._0; len && digit < 10; digit = code - CharCode._0) {\n if (magnitude >= 3200) return sign * 3200;\n magnitude = 10 * magnitude + digit;\n code = load(ptr += 2);\n --len;\n }\n return sign * magnitude;\n}\n\n// @ts-ignore: decorator\n@lazy let __fixmulShift: u64 = 0;\n\n// Adopted from metallic lib:\n// https://github.com/jdh8/metallic/blob/master/src/stdlib/parse/scientific.h\n// @ts-ignore: decorator\n@inline\nfunction fixmul(a: u64, b: u32): u64 {\n let low = (a & 0xFFFFFFFF) * b;\n let high = (a >> 32) * b + (low >> 32);\n let overflow = (high >> 32);\n let space = clz(overflow);\n let revspace: u64 = 32 - space;\n __fixmulShift += revspace;\n return (high << space | (low & 0xFFFFFFFF) >> revspace) + (low << space >> 31 & 1);\n}\n\n// @ts-ignore: decorator\n@inline\nfunction pow10(n: i32): f64 {\n // argument `n` should bounds in [0, 22] range\n return load(POWERS10 + (n << alignof()));\n}\n","// This file is shared with the compiler and must remain portable\n\n/** Runtime types. */\nexport enum Runtime {\n /** Simple bump allocator without GC. */\n Stub = 0,\n /** Stop the world semi-automatic GC. */\n Minimal = 1,\n /** incremental GC. */\n Incremental = 2,\n}\n","import { compareImpl } from \"./string\";\n\ntype Comparator = (a: T, b: T) => i32;\n\n// @ts-ignore: decorator\n@lazy @inline const EMPTY = u32.MAX_VALUE;\n// @ts-ignore: decorator\n@inline const INSERTION_SORT_THRESHOLD = 48;\n// @ts-ignore: decorator\n@inline const MIN_RUN_LENGTH = 32;\n\n// @ts-ignore: decorator\n@inline\nfunction log2u(n: u32): u32 {\n return 31 - clz(n);\n}\n\n// @ts-ignore: decorator\n@inline\nexport function COMPARATOR(): Comparator {\n if (isInteger()) {\n if (isSigned() && sizeof() <= 4) {\n return (a, b) => i32(a) - i32(b);\n } else {\n return (a, b) => i32(a > b) - i32(a < b);\n }\n } else if (isFloat()) {\n if (sizeof() == 4) {\n return (a, b) => {\n let ia = reinterpret(f32(a));\n let ib = reinterpret(f32(b));\n ia ^= ia >> 31 >>> 1;\n ib ^= ib >> 31 >>> 1;\n return i32(ia > ib) - i32(ia < ib);\n };\n } else {\n return (a, b) => {\n let ia = reinterpret(f64(a));\n let ib = reinterpret(f64(b));\n ia ^= ia >> 63 >>> 1;\n ib ^= ib >> 63 >>> 1;\n return i32(ia > ib) - i32(ia < ib);\n };\n }\n } else if (isString()) {\n return (a, b) => {\n if (\n changetype(a) == changetype(b) ||\n changetype(a) == 0 ||\n changetype(b) == 0\n ) return 0;\n let alen = changetype(a).length;\n let blen = changetype(b).length;\n if (!(alen | blen)) return 0;\n if (!alen) return -1;\n if (!blen) return 1;\n let res = compareImpl(\n changetype(a), 0,\n changetype(b), 0,\n min(alen, blen)\n );\n return res ? res : alen - blen;\n };\n } else {\n return (a, b) => i32(a > b) - i32(a < b);\n }\n}\n\n// Power Sort implementation (stable) from paper \"Nearly-Optimal Mergesorts\"\n// https://arxiv.org/pdf/1805.04154.pdf\n// This method usually outperform TimSort.\n// TODO: refactor c >>> 31 to c < 0 when binaryen will support this opt\nexport function SORT(\n ptr: usize,\n len: i32,\n comparator: Comparator\n): void {\n if (len <= INSERTION_SORT_THRESHOLD) {\n if (len <= 1) return;\n if (ASC_SHRINK_LEVEL < 1) {\n switch (len) {\n case 3: {\n let a = load(ptr, 0);\n let b = load(ptr, 1 << alignof());\n let c = comparator(a, b) > 0;\n store(ptr, select(b, a, c), 0);\n a = select(a, b, c);\n b = load(ptr, 2 << alignof());\n c = comparator(a, b) > 0;\n store(ptr, select(b, a, c), 1 << alignof());\n store(ptr, select(a, b, c), 2 << alignof());\n }\n case 2: {\n let a = load(ptr, 0);\n let b = load(ptr, 1 << alignof());\n let c = comparator(a, b) > 0;\n store(ptr, select(b, a, c), 0);\n store(ptr, select(a, b, c), 1 << alignof());\n return;\n }\n }\n }\n insertionSort(ptr, 0, len - 1, 0, comparator);\n return;\n }\n\n let lgPlus2 = log2u(len) + 2;\n let lgPlus2Size = lgPlus2 << alignof();\n let leftRunStartBuf = __alloc(lgPlus2Size << 1);\n let leftRunEndBuf = leftRunStartBuf + lgPlus2Size;\n\n for (let i: u32 = 0; i < lgPlus2; ++i) {\n store(leftRunStartBuf + (i << alignof()), EMPTY);\n }\n\n let buffer = __alloc(len << alignof());\n\n let hi = len - 1;\n let endA = extendRunRight(ptr, 0, hi, comparator);\n let lenA = endA + 1;\n\n if (lenA < MIN_RUN_LENGTH) {\n endA = min(hi, MIN_RUN_LENGTH - 1);\n insertionSort(ptr, 0, endA, lenA, comparator);\n }\n\n let top: u32 = 0, startA = 0;\n while (endA < hi) {\n let startB = endA + 1;\n let endB = extendRunRight(ptr, startB, hi, comparator);\n let lenB = endB - startB + 1;\n\n if (lenB < MIN_RUN_LENGTH) {\n endB = min(hi, startB + MIN_RUN_LENGTH - 1);\n insertionSort(ptr, startB, endB, lenB, comparator);\n }\n\n let k = nodePower(0, hi, startA, startB, endB);\n\n for (let i = top; i > k; --i) {\n let start = load(leftRunStartBuf + (i << alignof()));\n if (start != EMPTY) {\n mergeRuns(\n ptr,\n start,\n load(leftRunEndBuf + (i << alignof())) + 1,\n endA,\n buffer,\n comparator\n );\n startA = start;\n store(leftRunStartBuf + (i << alignof()), EMPTY);\n }\n }\n\n store(leftRunStartBuf + (k << alignof()), startA);\n store(leftRunEndBuf + (k << alignof()), endA);\n startA = startB;\n endA = endB;\n top = k;\n }\n\n for (let i = top; i != 0; --i) {\n let start = load(leftRunStartBuf + (i << alignof()));\n if (start != EMPTY) {\n mergeRuns(\n ptr,\n start,\n load(leftRunEndBuf + (i << alignof())) + 1,\n hi,\n buffer,\n comparator\n );\n }\n }\n // dealloc aux buffers\n __free(buffer);\n __free(leftRunStartBuf);\n}\n\nfunction insertionSort(\n ptr: usize,\n left: i32,\n right: i32,\n presorted: i32,\n comparator: Comparator\n): void {\n if (ASC_SHRINK_LEVEL >= 1) {\n // slightly improved original insertion sort\n for (let i = left + presorted; i <= right; ++i) {\n let j = i - 1;\n let a = load(ptr + (i << alignof()));\n while (j >= left) {\n let b = load(ptr + (j << alignof()));\n if (comparator(a, b) < 0) {\n store(ptr + (j << alignof()), b, 1 << alignof()); --j;\n } else break;\n }\n store(ptr + (j << alignof()), a, 1 << alignof());\n }\n } else {\n // even-odd two-way insertion sort which allow increase minRunLen\n let range = right - left + 1;\n let i = left + select(range & 1, presorted - ((range - presorted) & 1), presorted == 0);\n for (; i <= right; i += 2) {\n let a = load(ptr + (i << alignof()), 0);\n let b = load(ptr + (i << alignof()), 1 << alignof());\n let min = b, max = a;\n if (comparator(a, b) <= 0) {\n min = a, max = b;\n }\n let j = i - 1;\n while (j >= left) {\n a = load(ptr + (j << alignof()));\n if (comparator(a, max) > 0) {\n store(ptr + (j << alignof()), a, 2 << alignof()); --j;\n } else break;\n }\n store(ptr + (j << alignof()), max, 2 << alignof());\n while (j >= left) {\n a = load(ptr + (j << alignof()));\n if (comparator(a, min) > 0) {\n store(ptr + (j << alignof()), a, 1 << alignof()); --j;\n } else break;\n }\n store(ptr + (j << alignof()), min, 1 << alignof());\n }\n }\n}\n\nfunction nodePower(left: u32, right: u32, startA: u32, startB: u32, endB: u32): u32 {\n let n: u64 = right - left + 1;\n let s = startB - (left << 1);\n let l = startA + s;\n let r = endB + s + 1;\n let a = (l << 30) / n;\n let b = (r << 30) / n;\n return clz((a ^ b));\n}\n\nfunction extendRunRight(\n ptr: usize,\n i: i32,\n right: i32,\n comparator: Comparator\n): i32 {\n if (i == right) return i;\n let j = i;\n if (comparator(\n load(ptr + ( j << alignof())),\n load(ptr + (++j << alignof()))\n ) > 0) {\n while (\n j < right &&\n (comparator(\n load(ptr + (j << alignof()), 1 << alignof()),\n load(ptr + (j << alignof()))\n ) >>> 31) // < 0\n ) ++j;\n // reverse\n let k = j;\n while (i < k) {\n let tmp = load(ptr + (i << alignof()));\n store(ptr + (i << alignof()), load(ptr + (k << alignof()))); ++i;\n store(ptr + (k << alignof()), tmp); --k;\n }\n } else {\n while (\n j < right &&\n comparator(\n load(ptr + (j << alignof()), 1 << alignof()),\n load(ptr + (j << alignof()))\n ) >= 0\n ) ++j;\n }\n return j;\n}\n\n// Merges arr[l..m - 1] and arr[m..r]\nfunction mergeRuns(\n ptr: usize,\n l: i32,\n m: i32,\n r: i32,\n buffer: usize,\n comparator: Comparator\n): void {\n --m;\n let i: i32, j: i32, t = r + m;\n for (i = m + 1; i > l; --i) {\n store(\n buffer + ((i - 1) << alignof()),\n load(ptr + ((i - 1) << alignof()))\n );\n }\n for (j = m; j < r; ++j) {\n store(\n buffer + ((t - j) << alignof()),\n load(ptr + (j << alignof()), 1 << alignof())\n );\n }\n for (let k = l; k <= r; ++k) {\n let a = load(buffer + (j << alignof()));\n let b = load(buffer + (i << alignof()));\n if (comparator(a, b) < 0) {\n store(ptr + (k << alignof()), a);\n --j;\n } else {\n store(ptr + (k << alignof()), b);\n ++i;\n }\n }\n}\n","/// \n\nimport { OBJECT, BLOCK_MAXSIZE, TOTAL_OVERHEAD } from \"./rt/common\";\nimport { compareImpl, strtol, strtod, isSpace, isAscii, isFinalSigma, toLower8, toUpper8 } from \"./util/string\";\nimport { SPECIALS_UPPER, casemap, bsearch } from \"./util/casemap\";\nimport { E_INDEXOUTOFRANGE, E_INVALIDLENGTH, E_UNPAIRED_SURROGATE } from \"./util/error\";\nimport { idof } from \"./builtins\";\nimport { Array } from \"./array\";\n\n@final export abstract class String {\n\n @lazy static readonly MAX_LENGTH: i32 = (BLOCK_MAXSIZE >>> alignof());\n\n static fromCharCode(unit: i32, surr: i32 = -1): String {\n let hasSur = surr > 0;\n let out = changetype(__new(2 << i32(hasSur), idof()));\n store(changetype(out), unit);\n if (hasSur) store(changetype(out), surr, 2);\n return out;\n }\n\n static fromCharCodes(units: Array): String {\n let length = units.length;\n let out = changetype(__new(length << 1, idof()));\n let ptr = units.dataStart;\n for (let i = 0; i < length; ++i) {\n store(changetype(out) + (i << 1), load(ptr + (i << 2)));\n }\n return out;\n }\n\n static fromCodePoint(code: i32): String {\n let hasSur = code > 0xFFFF;\n let out = changetype(__new(2 << i32(hasSur), idof()));\n if (!hasSur) {\n store(changetype(out), code);\n } else {\n // Checks valid code point range\n assert(code <= 0x10FFFF);\n code -= 0x10000;\n let hi = (code & 0x03FF) | 0xDC00;\n let lo = code >>> 10 | 0xD800;\n store(changetype(out), lo | hi << 16);\n }\n return out;\n }\n\n @builtin static raw(parts: TemplateStringsArray, ...args: unknown[]): string { return unreachable(); }\n\n get length(): i32 {\n return changetype(changetype(this) - TOTAL_OVERHEAD).rtSize >> 1;\n }\n\n at(pos: i32): String {\n let len = this.length;\n pos += select(0, len, pos >= 0);\n if (pos >= len) throw new RangeError(E_INDEXOUTOFRANGE);\n let out = __new(2, idof());\n store(out, load(changetype(this) + (pos << 1)));\n return changetype(out); // retains\n }\n\n @operator(\"[]\") charAt(pos: i32): String {\n if (pos >= this.length) return changetype(\"\");\n let out = changetype(__new(2, idof()));\n store(changetype(out), load(changetype(this) + (pos << 1)));\n return out;\n }\n\n charCodeAt(pos: i32): i32 {\n if (pos >= this.length) return -1; // (NaN)\n return load(changetype(this) + (pos << 1));\n }\n\n codePointAt(pos: i32): i32 {\n let len = this.length;\n if (pos >= len) return -1; // (undefined)\n let first = load(changetype(this) + (pos << 1));\n if ((first & 0xFC00) != 0xD800 || pos + 1 == len) return first;\n let second = load(changetype(this) + (pos << 1), 2);\n if ((second & 0xFC00) != 0xDC00) return first;\n return (first - 0xD800 << 10) + (second - 0xDC00) + 0x10000;\n }\n\n @operator(\"+\") private static __concat(left: String, right: String): String {\n return left.concat(right);\n }\n\n concat(other: String): String {\n let thisSize: isize = this.length << 1;\n let otherSize: isize = other.length << 1;\n let outSize: usize = thisSize + otherSize;\n if (outSize == 0) return changetype(\"\");\n let out = changetype(__new(outSize, idof()));\n memory.copy(changetype(out), changetype(this), thisSize);\n memory.copy(changetype(out) + thisSize, changetype(other), otherSize);\n return out;\n }\n\n endsWith(search: String, end: i32 = String.MAX_LENGTH): bool {\n end = min(max(end, 0), this.length);\n let searchLength = search.length;\n let searchStart = end - searchLength;\n if (searchStart < 0) return false;\n // @ts-ignore: string <-> String\n return !compareImpl(this, searchStart, search, 0, searchLength);\n }\n\n @operator(\"==\") private static __eq(left: String | null, right: String | null): bool {\n if (changetype(left) == changetype(right)) return true;\n if (changetype(left) == 0 || changetype(right) == 0) return false;\n let leftLength = changetype(left).length;\n if (leftLength != changetype(right).length) return false;\n // @ts-ignore: string <-> String\n return !compareImpl(left, 0, right, 0, leftLength);\n }\n\n @operator.prefix(\"!\")\n private static __not(str: String | null): bool {\n return changetype(str) == 0 || !changetype(str).length;\n }\n\n @operator(\"!=\")\n private static __ne(left: String | null, right: String | null): bool {\n return !this.__eq(left, right);\n }\n\n @operator(\">\") private static __gt(left: String, right: String): bool {\n if (changetype(left) == changetype(right)) return false;\n let leftLength = left.length;\n if (!leftLength) return false;\n let rightLength = right.length;\n if (!rightLength) return true;\n // @ts-ignore: string <-> String\n let res = compareImpl(left, 0, right, 0, min(leftLength, rightLength));\n return res ? res > 0 : leftLength > rightLength;\n }\n\n @operator(\">=\") private static __gte(left: String, right: String): bool {\n return !this.__lt(left, right);\n }\n\n @operator(\"<\") private static __lt(left: String, right: String): bool {\n if (changetype(left) == changetype(right)) return false;\n let rightLength = right.length;\n if (!rightLength) return false;\n let leftLength = left.length;\n if (!leftLength) return true;\n // @ts-ignore: string <-> String\n let res = compareImpl(left, 0, right, 0, min(leftLength, rightLength));\n return res ? res < 0 : leftLength < rightLength;\n }\n\n @operator(\"<=\") private static __lte(left: String, right: String): bool {\n return !this.__gt(left, right);\n }\n\n includes(search: String, start: i32 = 0): bool {\n return this.indexOf(search, start) != -1;\n }\n\n indexOf(search: String, start: i32 = 0): i32 {\n let searchLen = search.length;\n if (!searchLen) return 0;\n let len = this.length;\n if (!len) return -1;\n let searchStart = min(max(start, 0), len);\n for (len -= searchLen; searchStart <= len; ++searchStart) {\n // @ts-ignore: string <-> String\n if (!compareImpl(this, searchStart, search, 0, searchLen)) return searchStart;\n }\n return -1;\n }\n\n lastIndexOf(search: String, start: i32 = i32.MAX_VALUE): i32 {\n let searchLen = search.length;\n if (!searchLen) return this.length;\n let len = this.length;\n if (!len) return -1;\n let searchStart = min(max(start, 0), len - searchLen);\n for (; searchStart >= 0; --searchStart) {\n // @ts-ignore: string <-> String\n if (!compareImpl(this, searchStart, search, 0, searchLen)) return searchStart;\n }\n return -1;\n }\n\n // TODO: implement full locale comparison with locales and Collator options\n localeCompare(other: String): i32 {\n if (changetype(other) == changetype(this)) return 0;\n let alen = this.length;\n let blen = other.length;\n // @ts-ignore: string <-> String\n let res = compareImpl(this, 0, other, 0, min(alen, blen));\n res = res ? res : alen - blen;\n // normalize to [-1, 1] range\n return i32(res > 0) - i32(res < 0);\n }\n\n startsWith(search: String, start: i32 = 0): bool {\n let len = this.length;\n let searchStart = min(max(start, 0), len);\n let searchLength = search.length;\n if (searchLength + searchStart > len) return false;\n // @ts-ignore: string <-> String\n return !compareImpl(this, searchStart, search, 0, searchLength);\n }\n\n substr(start: i32, length: i32 = i32.MAX_VALUE): String { // legacy\n let intStart: isize = start;\n let end: isize = length;\n let len: isize = this.length;\n if (intStart < 0) intStart = max(len + intStart, 0);\n let size = min(max(end, 0), len - intStart) << 1;\n if (size <= 0) return changetype(\"\");\n let out = changetype(__new(size, idof()));\n memory.copy(changetype(out), changetype(this) + (intStart << 1), size);\n return out;\n }\n\n substring(start: i32, end: i32 = i32.MAX_VALUE): String {\n let len: isize = this.length;\n let finalStart = min(max(start, 0), len);\n let finalEnd = min(max(end, 0), len);\n let fromPos = min(finalStart, finalEnd) << 1;\n let toPos = max(finalStart, finalEnd) << 1;\n let size = toPos - fromPos;\n if (!size) return changetype(\"\");\n if (!fromPos && toPos == len << 1) return this;\n let out = changetype(__new(size, idof()));\n memory.copy(changetype(out), changetype(this) + fromPos, size);\n return out;\n }\n\n trim(): String {\n let len = this.length;\n let size: usize = len << 1;\n while (size && isSpace(load(changetype(this) + size - 2))) {\n size -= 2;\n }\n let offset: usize = 0;\n while (offset < size && isSpace(load(changetype(this) + offset))) {\n offset += 2; size -= 2;\n }\n if (!size) return changetype(\"\");\n if (!offset && size == len << 1) return this;\n let out = changetype(__new(size, idof()));\n memory.copy(changetype(out), changetype(this) + offset, size);\n return out;\n }\n\n @inline\n trimLeft(): String {\n return this.trimStart();\n }\n\n @inline\n trimRight(): String {\n return this.trimEnd();\n }\n\n trimStart(): String {\n let size = this.length << 1;\n let offset: usize = 0;\n while (offset < size && isSpace(load(changetype(this) + offset))) {\n offset += 2;\n }\n if (!offset) return this;\n size -= offset;\n if (!size) return changetype(\"\");\n let out = changetype(__new(size, idof()));\n memory.copy(changetype(out), changetype(this) + offset, size);\n return out;\n }\n\n trimEnd(): String {\n let originalSize = this.length << 1;\n let size = originalSize;\n while (size && isSpace(load(changetype(this) + size - 2))) {\n size -= 2;\n }\n if (!size) return changetype(\"\");\n if (size == originalSize) return this;\n let out = changetype(__new(size, idof()));\n memory.copy(changetype(out), changetype(this), size);\n return out;\n }\n\n padStart(length: i32, pad: string = \" \"): String {\n let thisSize = this.length << 1;\n let targetSize = length << 1;\n let padSize = pad.length << 1;\n if (targetSize < thisSize || !padSize) return this;\n let prependSize = targetSize - thisSize;\n let out = changetype(__new(targetSize, idof()));\n if (prependSize > padSize) {\n let repeatCount = (prependSize - 2) / padSize;\n let restBase = repeatCount * padSize;\n let restSize = prependSize - restBase;\n memory.repeat(changetype(out), changetype(pad), padSize, repeatCount);\n memory.copy(changetype(out) + restBase, changetype(pad), restSize);\n } else {\n memory.copy(changetype(out), changetype(pad), prependSize);\n }\n memory.copy(changetype(out) + prependSize, changetype(this), thisSize);\n return out;\n }\n\n padEnd(length: i32, pad: string = \" \"): String {\n let thisSize = this.length << 1;\n let targetSize = length << 1;\n let padSize = pad.length << 1;\n if (targetSize < thisSize || !padSize) return this;\n let appendSize = targetSize - thisSize;\n let out = changetype(__new(targetSize, idof()));\n memory.copy(changetype(out), changetype(this), thisSize);\n if (appendSize > padSize) {\n let repeatCount = (appendSize - 2) / padSize;\n let restBase = repeatCount * padSize;\n let restSize = appendSize - restBase;\n memory.repeat(changetype(out) + thisSize, changetype(pad), padSize, repeatCount);\n memory.copy(changetype(out) + thisSize + restBase, changetype(pad), restSize);\n } else {\n memory.copy(changetype(out) + thisSize, changetype(pad), appendSize);\n }\n return out;\n }\n\n repeat(count: i32 = 0): String {\n let length = this.length;\n\n // Most browsers can't handle strings 1 << 28 chars or longer\n if (count < 0 || length * count > (1 << 28)) {\n throw new RangeError(E_INVALIDLENGTH);\n }\n\n if (count == 0 || !length) return changetype(\"\");\n if (count == 1) return this;\n let out = changetype(__new((length * count) << 1, idof()));\n memory.repeat(changetype(out), changetype(this), length << 1, count);\n return out;\n }\n\n replace(search: String, replacement: String): String {\n let len: usize = this.length;\n let slen: usize = search.length;\n if (len <= slen) {\n return len < slen ? this : select(replacement, this, search == this);\n }\n let index: isize = this.indexOf(search);\n if (~index) {\n let rlen: usize = replacement.length;\n len -= slen;\n let olen = len + rlen;\n if (olen) {\n let out = changetype(__new(olen << 1, idof()));\n memory.copy(changetype(out), changetype(this), index << 1);\n memory.copy(\n changetype(out) + (index << 1),\n changetype(replacement),\n rlen << 1\n );\n memory.copy(\n changetype(out) + ((index + rlen) << 1),\n changetype(this) + ((index + slen) << 1),\n (len - index) << 1\n );\n return out;\n }\n }\n return this;\n }\n\n replaceAll(search: String, replacement: String): String {\n let thisLen: usize = this.length;\n let searchLen: usize = search.length;\n if (thisLen <= searchLen) {\n return thisLen < searchLen\n ? this\n : select(replacement, this, search == this);\n }\n let replaceLen: usize = replacement.length;\n if (!searchLen) {\n if (!replaceLen) return this;\n // Special case: 'abc'.replaceAll('', '-') -> '-a-b-c-'\n let out = changetype(__new((thisLen + (thisLen + 1) * replaceLen) << 1, idof()));\n memory.copy(changetype(out), changetype(replacement), replaceLen << 1);\n let offset = replaceLen;\n for (let i: usize = 0; i < thisLen; ++i) {\n store(\n changetype(out) + (offset++ << 1),\n load(changetype(this) + (i << 1))\n );\n memory.copy(\n changetype(out) + (offset << 1),\n changetype(replacement),\n replaceLen << 1\n );\n offset += replaceLen;\n }\n return out;\n }\n let prev: isize = 0, next: isize = 0;\n if (searchLen == replaceLen) {\n // Fast path when search and replacement have same length\n let outSize = thisLen << 1;\n let out = changetype(__new(outSize, idof()));\n memory.copy(changetype(out), changetype(this), outSize);\n while (~(next = this.indexOf(search, prev))) {\n memory.copy(changetype(out) + (next << 1), changetype(replacement), replaceLen << 1);\n prev = next + searchLen;\n }\n return out;\n }\n let out: String | null = null, offset: usize = 0, outSize = thisLen;\n while (~(next = this.indexOf(search, prev))) {\n if (!out) out = changetype(__new(thisLen << 1, idof()));\n let chunk = next - prev;\n if (offset + chunk + replaceLen > outSize) {\n outSize <<= 1;\n out = changetype(__renew(changetype(out), outSize << 1));\n }\n memory.copy(\n changetype(out) + (offset << 1),\n changetype(this) + (prev << 1),\n chunk << 1\n );\n offset += chunk;\n memory.copy(\n changetype(out) + (offset << 1),\n changetype(replacement),\n replaceLen << 1\n );\n offset += replaceLen;\n prev = next + searchLen;\n }\n if (out) {\n let rest = thisLen - prev;\n if (offset + rest > outSize) {\n outSize <<= 1;\n out = changetype(__renew(changetype(out), outSize << 1));\n }\n if (rest) {\n memory.copy(\n changetype(out) + (offset << 1),\n changetype(this) + (prev << 1),\n rest << 1\n );\n }\n rest += offset;\n if (outSize > rest) {\n out = changetype(__renew(changetype(out), rest << 1));\n }\n return out;\n }\n return this;\n }\n\n slice(start: i32, end: i32 = i32.MAX_VALUE): String {\n let len = this.length;\n start = start < 0 ? max(start + len, 0) : min(start, len);\n end = end < 0 ? max(end + len, 0) : min(end, len);\n len = end - start;\n if (len <= 0) return changetype(\"\");\n let out = changetype(__new(len << 1, idof()));\n memory.copy(changetype(out), changetype(this) + (start << 1), len << 1);\n return out;\n }\n\n split(separator: String | null = null, limit: i32 = i32.MAX_VALUE): String[] {\n if (!limit) return changetype(__newArray(0, alignof(), idof>()));\n if (changetype(separator) == 0) return [ this ];\n let length: isize = this.length;\n let sepLen = changetype(separator).length;\n if (limit < 0) limit = i32.MAX_VALUE;\n if (!sepLen) {\n if (!length) return changetype(__newArray(0, alignof(), idof>()));\n // split by chars\n length = min(length, limit);\n let result = changetype(__newArray(length, alignof(), idof>()));\n // @ts-ignore: cast\n let resultStart = result.dataStart as usize;\n for (let i: isize = 0; i < length; ++i) {\n let charStr = changetype(__new(2, idof()));\n store(changetype(charStr), load(changetype(this) + (i << 1)));\n store(resultStart + (i << alignof()), changetype(charStr)); // result[i] = charStr\n __link(changetype(result), changetype(charStr), true);\n }\n return result;\n } else if (!length) {\n let result = changetype(__newArray(1, alignof(), idof>()));\n // @ts-ignore: cast\n store(result.dataStart as usize, changetype(\"\")); // static \"\"\n return result;\n }\n let result = changetype(__newArray(0, alignof(), idof>()));\n let end = 0, start = 0, i = 0;\n while (~(end = this.indexOf(changetype(separator), start))) {\n let len = end - start;\n if (len > 0) {\n let out = changetype(__new(len << 1, idof()));\n memory.copy(changetype(out), changetype(this) + (start << 1), len << 1);\n result.push(out);\n } else {\n result.push(changetype(\"\"));\n }\n if (++i == limit) return result;\n start = end + sepLen;\n }\n if (!start) { // also means: loop above didn't do anything\n result.push(this);\n return result;\n }\n let len = length - start;\n if (len > 0) {\n let out = changetype(__new(len << 1, idof()));\n memory.copy(changetype(out), changetype(this) + (start << 1), len << 1);\n result.push(out);\n } else {\n result.push(changetype(\"\")); // static \"\"\n }\n return result;\n }\n\n toLowerCase(): String {\n let len = this.length;\n if (!len) return this;\n let codes = changetype(__new(len * 2 * 2, idof()));\n let j: usize = 0;\n for (let i: usize = 0; i < len; ++i, ++j) {\n let c = load(changetype(this) + (i << 1));\n if (isAscii(c)) {\n store(changetype(codes) + (j << 1), toLower8(c));\n } else {\n // check and read surrogate pair\n if ((c - 0xD7FF < 0xDC00 - 0xD7FF) && i < len - 1) {\n let c1 = load(changetype(this) + (i << 1), 2);\n if (c1 - 0xDBFF < 0xE000 - 0xDBFF) {\n let c0 = c;\n c = (((c & 0x03FF) << 10) | (c1 & 0x03FF)) + 0x10000;\n ++i;\n if (c >= 0x20000) {\n store(changetype(codes) + (j << 1), c0 | (c1 << 16));\n ++j;\n continue;\n }\n }\n }\n // check special casing for lower table. It has one ently so instead lookup we just inline this.\n if (c == 0x0130) {\n // 0x0130 -> [0x0069, 0x0307]\n store(changetype(codes) + (j << 1), (0x0307 << 16) | 0x0069);\n ++j;\n } else if (c == 0x03A3) { // 'Σ'\n // Σ maps to σ but except at the end of a word where it maps to ς\n let sigma = 0x03C3; // σ\n if (len > 1 && isFinalSigma(changetype(this), i, len)) {\n sigma = 0x03C2; // ς\n }\n store(changetype(codes) + (j << 1), sigma);\n } else if (c - 0x24B6 <= 0x24CF - 0x24B6) {\n // Range 0x24B6 <= c <= 0x24CF not covered by casemap and require special early handling\n store(changetype(codes) + (j << 1), c + 26);\n } else {\n let code = casemap(c, 0) & 0x1FFFFF;\n if (code < 0x10000) {\n store(changetype(codes) + (j << 1), code);\n } else {\n // store as surrogare pair\n code -= 0x10000;\n let lo = (code >>> 10) | 0xD800;\n let hi = (code & 0x03FF) | 0xDC00;\n store(changetype(codes) + (j << 1), lo | (hi << 16));\n ++j;\n }\n }\n }\n }\n return changetype(__renew(changetype(codes), j << 1));\n }\n\n toUpperCase(): String {\n let len = this.length;\n if (!len) return this;\n let codes = changetype(__new(len * 3 * 2, idof()));\n let specialsPtr = changetype(SPECIALS_UPPER);\n let specialsLen = SPECIALS_UPPER.length;\n let j: usize = 0;\n for (let i: usize = 0; i < len; ++i, ++j) {\n let c = load(changetype(this) + (i << 1));\n if (isAscii(c)) {\n store(changetype(codes) + (j << 1), toUpper8(c));\n } else {\n // check and read surrogate pair\n if ((c - 0xD7FF < 0xDC00 - 0xD7FF) && i < len - 1) {\n let c1 = load(changetype(this) + (i << 1), 2);\n if (c1 - 0xDBFF < 0xE000 - 0xDBFF) {\n let c0 = c;\n c = (((c & 0x03FF) << 10) | (c1 & 0x03FF)) + 0x10000;\n ++i;\n if (c >= 0x20000) {\n store(changetype(codes) + (j << 1), c0 | (c1 << 16));\n ++j;\n continue;\n }\n }\n }\n // Range 0x24D0 <= c <= 0x24E9 not covered by casemap and require special early handling\n if (c - 0x24D0 <= 0x24E9 - 0x24D0) {\n // monkey patch\n store(changetype(codes) + (j << 1), c - 26);\n } else {\n let index: usize = -1;\n // Fast range check. See first and last rows in specialsUpper table\n if (c - 0x00DF <= 0xFB17 - 0x00DF) {\n index = bsearch(c, specialsPtr, specialsLen);\n }\n if (~index) {\n // load next 3 code points from row with `index` offset for specialsUpper table\n let ab = load(specialsPtr + (index << 1), 2);\n let cc = load(specialsPtr + (index << 1), 6);\n store(changetype(codes) + (j << 1), ab, 0);\n store(changetype(codes) + (j << 1), cc, 4);\n j += 1 + usize(cc != 0);\n } else {\n let code = casemap(c, 1) & 0x1FFFFF;\n if (code < 0x10000) {\n store(changetype(codes) + (j << 1), code);\n } else {\n // store as surrogare pair\n code -= 0x10000;\n let lo = (code >>> 10) | 0xD800;\n let hi = (code & 0x03FF) | 0xDC00;\n store(changetype(codes) + (j << 1), lo | (hi << 16));\n ++j;\n }\n }\n }\n }\n }\n return changetype(__renew(changetype(codes), j << 1));\n }\n\n toString(): String {\n return this;\n }\n}\n\n// @ts-ignore: nolib\nexport type string = String;\n\nexport function parseInt(str: string, radix: i32 = 0): f64 {\n return strtol(str, radix);\n}\n\nexport function parseFloat(str: string): f64 {\n return strtod(str);\n}\n\n// Encoding helpers\nexport namespace String {\n\n export namespace UTF8 {\n\n export const enum ErrorMode {\n WTF8,\n REPLACE,\n ERROR\n }\n\n export function byteLength(str: string, nullTerminated: bool = false): i32 {\n let strOff = changetype(str);\n let strEnd = strOff + changetype(changetype(str) - TOTAL_OVERHEAD).rtSize;\n let bufLen = i32(nullTerminated);\n while (strOff < strEnd) {\n let c1 = load(strOff);\n if (c1 < 128) {\n // @ts-ignore: cast\n if (nullTerminated & !c1) break;\n bufLen += 1;\n } else if (c1 < 2048) {\n bufLen += 2;\n } else {\n if ((c1 & 0xFC00) == 0xD800 && strOff + 2 < strEnd) {\n if ((load(strOff, 2) & 0xFC00) == 0xDC00) {\n bufLen += 4; strOff += 4;\n continue;\n }\n }\n bufLen += 3;\n }\n strOff += 2;\n }\n return bufLen;\n }\n\n export function encode(str: string, nullTerminated: bool = false, errorMode: ErrorMode = ErrorMode.WTF8): ArrayBuffer {\n let buf = changetype(__new(byteLength(str, nullTerminated), idof()));\n encodeUnsafe(changetype(str), str.length, changetype(buf), nullTerminated, errorMode);\n return buf;\n }\n\n // @ts-ignore: decorator\n @unsafe\n export function encodeUnsafe(str: usize, len: i32, buf: usize, nullTerminated: bool = false, errorMode: ErrorMode = ErrorMode.WTF8): usize {\n let strEnd = str + (len << 1);\n let bufOff = buf;\n while (str < strEnd) {\n let c1 = load(str);\n if (c1 < 128) {\n store(bufOff, c1);\n bufOff++;\n // @ts-ignore: cast\n if (nullTerminated & !c1) return bufOff - buf;\n } else if (c1 < 2048) {\n let b0 = c1 >> 6 | 192;\n let b1 = c1 & 63 | 128;\n store(bufOff, b1 << 8 | b0);\n bufOff += 2;\n } else {\n // D800: 11011 0 0000000000 Lead\n // DBFF: 11011 0 1111111111\n // DC00: 11011 1 0000000000 Trail\n // DFFF: 11011 1 1111111111\n // F800: 11111 0 0000000000 Mask\n // FC00: 11111 1 0000000000\n if ((c1 & 0xF800) == 0xD800) {\n if (c1 < 0xDC00 && str + 2 < strEnd) {\n let c2 = load(str, 2);\n if ((c2 & 0xFC00) == 0xDC00) {\n c1 = 0x10000 + ((c1 & 0x03FF) << 10) | (c2 & 0x03FF);\n let b0 = c1 >> 18 | 240;\n let b1 = c1 >> 12 & 63 | 128;\n let b2 = c1 >> 6 & 63 | 128;\n let b3 = c1 & 63 | 128;\n store(bufOff, b3 << 24 | b2 << 16 | b1 << 8 | b0);\n bufOff += 4; str += 4;\n continue;\n }\n }\n if (errorMode != ErrorMode.WTF8) { // unlikely\n if (errorMode == ErrorMode.ERROR) throw new Error(E_UNPAIRED_SURROGATE);\n c1 = 0xFFFD;\n }\n }\n let b0 = c1 >> 12 | 224;\n let b1 = c1 >> 6 & 63 | 128;\n let b2 = c1 & 63 | 128;\n store(bufOff, b1 << 8 | b0);\n store(bufOff, b2, 2);\n bufOff += 3;\n }\n str += 2;\n }\n if (nullTerminated) {\n store(bufOff++, 0);\n }\n return bufOff - buf;\n }\n\n export function decode(buf: ArrayBuffer, nullTerminated: bool = false): String {\n return decodeUnsafe(changetype(buf), buf.byteLength, nullTerminated);\n }\n\n // @ts-ignore: decorator\n @unsafe\n export function decodeUnsafe(buf: usize, len: usize, nullTerminated: bool = false): String {\n let bufOff = buf;\n let bufEnd = buf + len;\n assert(bufEnd >= bufOff); // guard wraparound\n let str = changetype(__new(len << 1, idof())); // max is one u16 char per u8 byte\n let strOff = changetype(str);\n while (bufOff < bufEnd) {\n let u0 = load(bufOff); ++bufOff;\n if (!(u0 & 128)) {\n // @ts-ignore: cast\n if (nullTerminated & !u0) break;\n store(strOff, u0);\n } else {\n if (bufEnd == bufOff) break;\n let u1 = load(bufOff) & 63; ++bufOff;\n if ((u0 & 224) == 192) {\n store(strOff, (u0 & 31) << 6 | u1);\n } else {\n if (bufEnd == bufOff) break;\n let u2 = load(bufOff) & 63; ++bufOff;\n if ((u0 & 240) == 224) {\n u0 = (u0 & 15) << 12 | u1 << 6 | u2;\n } else {\n if (bufEnd == bufOff) break;\n u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | load(bufOff) & 63;\n ++bufOff;\n }\n if (u0 < 0x10000) {\n store(strOff, u0);\n } else {\n u0 -= 0x10000;\n let lo = u0 >> 10 | 0xD800;\n let hi = (u0 & 0x03FF) | 0xDC00;\n store(strOff, lo | (hi << 16));\n strOff += 2;\n }\n }\n }\n strOff += 2;\n }\n return changetype(__renew(changetype(str), strOff - changetype(str)));\n }\n }\n\n export namespace UTF16 {\n\n export function byteLength(str: string): i32 {\n return changetype(changetype(str) - TOTAL_OVERHEAD).rtSize;\n }\n\n export function encode(str: string): ArrayBuffer {\n let buf = changetype(__new(byteLength(str), idof()));\n encodeUnsafe(changetype(str), str.length, changetype(buf));\n return buf;\n }\n\n // @ts-ignore: decorator\n @unsafe\n export function encodeUnsafe(str: usize, len: i32, buf: usize): usize {\n let size = len << 1;\n memory.copy(buf, changetype(str), size);\n return size;\n }\n\n export function decode(buf: ArrayBuffer): String {\n return decodeUnsafe(changetype(buf), buf.byteLength);\n }\n\n // @ts-ignore: decorator\n @unsafe\n export function decodeUnsafe(buf: usize, len: usize): String {\n let str = changetype(__new(len &= ~1, idof()));\n memory.copy(changetype(str), buf, len);\n return str;\n }\n }\n}\n\nexport class TemplateStringsArray extends Array {\n readonly raw: string[];\n}\n","import { AL_MASK, OBJECT, OBJECT_OVERHEAD, BLOCK_MAXSIZE, BLOCK_OVERHEAD, BLOCK, OBJECT_MAXSIZE } from \"./common\";\nimport { E_ALLOCATION_TOO_LARGE } from \"../util/error\";\n\n// === A minimal runtime stub ===\n\n// @ts-ignore: decorator\n@lazy let startOffset: usize = ((__heap_base + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD;\n// @ts-ignore: decorator\n@lazy let offset: usize = startOffset;\n\nfunction maybeGrowMemory(newOffset: usize): void {\n // assumes newOffset is aligned\n let pagesBefore = memory.size();\n let maxOffset = ((pagesBefore << 16) + AL_MASK) & ~AL_MASK;\n if (newOffset > maxOffset) {\n let pagesNeeded = (((newOffset - maxOffset + 0xffff) & ~0xffff) >>> 16);\n let pagesWanted = max(pagesBefore, pagesNeeded); // double memory\n if (memory.grow(pagesWanted) < 0) {\n if (memory.grow(pagesNeeded) < 0) unreachable(); // out of memory\n }\n }\n offset = newOffset;\n}\n\n// @ts-ignore: decorator\n@inline function computeSize(size: usize): usize {\n return ((size + BLOCK_OVERHEAD + AL_MASK) & ~AL_MASK) - BLOCK_OVERHEAD;\n}\n\n// @ts-ignore: decorator\n@unsafe @global\nexport function __alloc(size: usize): usize {\n if (size > BLOCK_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);\n let block = changetype(offset);\n let ptr = offset + BLOCK_OVERHEAD;\n let payloadSize = computeSize(size);\n maybeGrowMemory(ptr + payloadSize);\n block.mmInfo = payloadSize;\n return ptr;\n}\n\n// @ts-ignore: decorator\n@unsafe @global\nexport function __realloc(ptr: usize, size: usize): usize {\n assert(ptr != 0 && !(ptr & AL_MASK)); // must exist and be aligned\n let block = changetype(ptr - BLOCK_OVERHEAD);\n let actualSize = block.mmInfo;\n let isLast = ptr + actualSize == offset;\n let payloadSize = computeSize(size);\n if (size > actualSize) {\n if (isLast) { // last block: grow\n if (size > BLOCK_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);\n maybeGrowMemory(ptr + payloadSize);\n block.mmInfo = payloadSize;\n } else { // copy to new block at least double the size\n let newPtr = __alloc(max(payloadSize, actualSize << 1));\n memory.copy(newPtr, ptr, actualSize);\n block = changetype((ptr = newPtr) - BLOCK_OVERHEAD);\n }\n } else if (isLast) { // last block: shrink\n offset = ptr + payloadSize;\n block.mmInfo = payloadSize;\n }\n return ptr;\n}\n\n// @ts-ignore: decorator\n@unsafe @global\nexport function __free(ptr: usize): void {\n assert(ptr != 0 && !(ptr & AL_MASK)); // must exist and be aligned\n let block = changetype(ptr - BLOCK_OVERHEAD);\n if (ptr + block.mmInfo == offset) { // last block: discard\n offset = changetype(block);\n }\n}\n\n// @ts-ignore: decorator\n@unsafe @global\nexport function __reset(): void { // special\n offset = startOffset;\n}\n\n// @ts-ignore: decorator\n@unsafe @global\nexport function __new(size: usize, id: u32): usize {\n if (size > OBJECT_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);\n let ptr = __alloc(OBJECT_OVERHEAD + size);\n let object = changetype(ptr - BLOCK_OVERHEAD);\n object.gcInfo = 0;\n object.gcInfo2 = 0;\n object.rtId = id;\n object.rtSize = size;\n return ptr + OBJECT_OVERHEAD;\n}\n\n// @ts-ignore: decorator\n@unsafe @global\nexport function __renew(oldPtr: usize, size: usize): usize {\n if (size > OBJECT_MAXSIZE) throw new Error(E_ALLOCATION_TOO_LARGE);\n let newPtr = __realloc(oldPtr - OBJECT_OVERHEAD, OBJECT_OVERHEAD + size);\n changetype(newPtr - BLOCK_OVERHEAD).rtSize = size;\n return newPtr + OBJECT_OVERHEAD;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __link(parentPtr: usize, childPtr: usize, expectMultiple: bool): void {\n // nop\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __pin(ptr: usize): usize {\n return ptr;\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __unpin(ptr: usize): void {\n // nop\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nfunction __visit(ptr: usize, cookie: u32): void { // eslint-disable-line @typescript-eslint/no-unused-vars\n // nop\n}\n\n// @ts-ignore: decorator\n@global @unsafe\nexport function __collect(): void {\n // nop\n}\n","// Common error messages for use across the standard library. Keeping error messages compact\n// and reusing them where possible ensures minimal static data in binaries.\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_INDEXOUTOFRANGE: string = \"Index out of range\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_VALUEOUTOFRANGE: string = \"Value out of range\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_INVALIDLENGTH: string = \"Invalid length\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_EMPTYARRAY: string = \"Array is empty\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_HOLEYARRAY: string = \"Element type must be nullable if array is holey\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_NOTIMPLEMENTED: string = \"Not implemented\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_KEYNOTFOUND: string = \"Key does not exist\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_ALLOCATION_TOO_LARGE: string = \"Allocation too large\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_ALREADY_PINNED: string = \"Object already pinned\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_NOT_PINNED: string = \"Object is not pinned\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_URI_MALFORMED: string = \"URI malformed\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_INVALIDDATE: string = \"Invalid Date\";\n\n// @ts-ignore: decorator\n@lazy @inline\nexport const E_UNPAIRED_SURROGATE: string = \"Unpaired surrogate\";\n","import { itoa32, utoa32, itoa64, utoa64, dtoa } from \"./util/number\";\nimport { strtol, strtod } from \"./util/string\";\n\n// @ts-ignore: decorator\n@builtin @inline\nexport const NaN: f64 = 0 / 0; // context-aware\n\n// @ts-ignore: decorator\n@builtin @inline\nexport const Infinity: f64 = 1 / 0; // context-aware\n\n// @ts-ignore: decorator\n@builtin\nexport declare function isNaN(value: T): bool;\n\n// @ts-ignore: decorator\n@builtin\nexport declare function isFinite(value: T): bool;\n\n@final @unmanaged\nexport abstract class I8 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: i8 = i8.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: i8 = i8.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): i8 {\n return strtol(value, radix);\n }\n\n toString(this: i8, radix: i32 = 10): String {\n return itoa32(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class I16 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: i16 = i16.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: i16 = i16.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): i16 {\n return strtol(value, radix);\n }\n\n toString(this: i16, radix: i32 = 10): String {\n return itoa32(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class I32 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: i32 = i32.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: i32 = i32.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): i32 {\n return strtol(value, radix);\n }\n\n toString(this: i32, radix: i32 = 10): String {\n return itoa32(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class I64 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: i64 = i64.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: i64 = i64.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): i64 {\n return strtol(value, radix);\n }\n\n toString(this: i64, radix: i32 = 10): String {\n return itoa64(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class Isize {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: isize = isize.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: isize = isize.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): isize {\n return strtol(value, radix);\n }\n\n toString(this: isize, radix: i32 = 10): String {\n if (sizeof() == 4) {\n return itoa32(this, radix);\n } else {\n return itoa64(this, radix);\n }\n }\n}\n\n@final @unmanaged\nexport abstract class U8 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: u8 = u8.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: u8 = u8.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): u8 {\n return strtol(value, radix);\n }\n\n toString(this: u8, radix: i32 = 10): String {\n return utoa32(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class U16 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: u16 = u16.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: u16 = u16.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): u16 {\n return strtol(value, radix);\n }\n\n toString(this: u16, radix: i32 = 10): String {\n return utoa32(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class U32 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: u32 = u32.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: u32 = u32.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): u32 {\n return strtol(value, radix);\n }\n\n toString(this: u32, radix: i32 = 10): String {\n return utoa32(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class U64 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: u64 = u64.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: u64 = u64.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): u64 {\n return strtol(value, radix);\n }\n\n toString(this: u64, radix: i32 = 10): String {\n return utoa64(this, radix);\n }\n}\n\n@final @unmanaged\nexport abstract class Usize {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: usize = usize.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: usize = usize.MAX_VALUE;\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): usize {\n return strtol(value, radix);\n }\n\n toString(this: usize, radix: i32 = 10): String {\n if (sizeof() == 4) {\n return utoa32(this, radix);\n } else {\n return utoa64(this, radix);\n }\n }\n}\n\n@final @unmanaged\nexport abstract class Bool {\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: bool = bool.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: bool = bool.MAX_VALUE;\n\n toString(this: bool, radix: i32 = 0): String {\n return this ? \"true\" : \"false\";\n }\n}\n\nexport { Bool as Boolean };\n\n@final @unmanaged\nexport abstract class F32 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly EPSILON: f32 = f32.EPSILON;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: f32 = f32.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: f32 = f32.MAX_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_SAFE_INTEGER: f32 = f32.MIN_SAFE_INTEGER;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_SAFE_INTEGER: f32 = f32.MAX_SAFE_INTEGER;\n\n // @ts-ignore: decorator\n @lazy\n static readonly POSITIVE_INFINITY: f32 = f32.POSITIVE_INFINITY;\n\n // @ts-ignore: decorator\n @lazy\n static readonly NEGATIVE_INFINITY: f32 = f32.NEGATIVE_INFINITY;\n\n // @ts-ignore: decorator\n @lazy\n static readonly NaN: f32 = f32.NaN;\n\n static isNaN(value: f32): bool {\n return isNaN(value);\n }\n\n static isFinite(value: f32): bool {\n return isFinite(value);\n }\n\n static isSafeInteger(value: f32): bool {\n return abs(value) <= f32.MAX_SAFE_INTEGER && trunc(value) == value;\n }\n\n static isInteger(value: f32): bool {\n return isFinite(value) && trunc(value) == value;\n }\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): f32 {\n return strtol(value, radix);\n }\n\n /** @deprecated */\n static parseFloat(value: string): f32 {\n return strtod(value);\n }\n\n toString(this: f32, radix: i32 = 0): String {\n return dtoa(this);\n }\n}\n\n@final @unmanaged\nexport abstract class F64 {\n\n // @ts-ignore: decorator\n @lazy\n static readonly EPSILON: f64 = f64.EPSILON;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_VALUE: f64 = f64.MIN_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_VALUE: f64 = f64.MAX_VALUE;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MIN_SAFE_INTEGER: f64 = f64.MIN_SAFE_INTEGER;\n\n // @ts-ignore: decorator\n @lazy\n static readonly MAX_SAFE_INTEGER: f64 = f64.MAX_SAFE_INTEGER;\n\n // @ts-ignore: decorator\n @lazy\n static readonly POSITIVE_INFINITY: f64 = f64.POSITIVE_INFINITY;\n\n // @ts-ignore: decorator\n @lazy\n static readonly NEGATIVE_INFINITY: f64 = f64.NEGATIVE_INFINITY;\n\n // @ts-ignore: decorator\n @lazy\n static readonly NaN: f64 = f64.NaN;\n\n static isNaN(value: f64): bool {\n return isNaN(value);\n }\n\n static isFinite(value: f64): bool {\n return isFinite(value);\n }\n\n static isSafeInteger(value: f64): bool {\n return abs(value) <= f64.MAX_SAFE_INTEGER && trunc(value) == value;\n }\n\n static isInteger(value: f64): bool {\n return isFinite(value) && trunc(value) == value;\n }\n\n /** @deprecated */\n static parseInt(value: string, radix: i32 = 0): f64 {\n return strtol(value, radix);\n }\n\n /** @deprecated */\n static parseFloat(value: string): f64 {\n return strtod(value);\n }\n\n toString(this: f64, radix: i32 = 0): String {\n return dtoa(this);\n }\n}\n\nexport { F64 as Number };\n","import { memcmp, memmove, memset } from \"./util/memory\";\nimport { E_NOTIMPLEMENTED } from \"./util/error\";\n\n/** Memory manager interface. */\nexport namespace memory {\n\n /** Gets the size of the memory in pages. */\n // @ts-ignore: decorator\n @builtin\n export declare function size(): i32;\n\n /** Grows the memory by the given size in pages and returns the previous size in pages. */\n // @ts-ignore: decorator\n @unsafe @builtin\n export declare function grow(pages: i32): i32;\n\n /** Fills a section in memory with the specified byte value. */\n // @ts-ignore: decorator\n @unsafe @builtin\n export function fill(dst: usize, c: u8, n: usize): void {\n memset(dst, c, n); // fallback if \"bulk-memory\" isn't enabled\n }\n\n /** Copies a section of memory to another. Has move semantics. */\n // @ts-ignore: decorator\n @unsafe @builtin\n export function copy(dst: usize, src: usize, n: usize): void {\n memmove(dst, src, n); // fallback if \"bulk-memory\" isn't enabled\n }\n\n export namespace atomic {\n\n // @ts-ignore: decorator\n @unsafe @builtin\n export declare function wait32(ptr: usize, expected: i32, timeout: i64): AtomicWaitResult;\n\n // @ts-ignore: decorator\n @unsafe @builtin\n export declare function wait64(ptr: usize, expected: i64, timeout: i64): AtomicWaitResult;\n }\n\n /** Initializes a memory segment. */\n // @ts-ignore: decorator\n @unsafe\n export function init(segmentIndex: u32, srcOffset: usize, dstOffset: usize, n: usize): void {\n throw new Error(E_NOTIMPLEMENTED);\n }\n\n /** Drops a memory segment. */\n // @ts-ignore: decorator\n @unsafe\n export function drop(segmentIndex: u32): void {\n throw new Error(E_NOTIMPLEMENTED);\n }\n\n /** Repeats a section of memory at a specific address. */\n // @ts-ignore: decorator\n @unsafe\n export function repeat(dst: usize, src: usize, srcLength: usize, count: usize): void {\n let index: usize = 0;\n let total = srcLength * count;\n while (index < total) {\n memory.copy(dst + index, src, srcLength);\n index += srcLength;\n }\n }\n\n /** Compares a section of memory to another. */\n // @ts-ignore: decorator\n @inline\n export function compare(vl: usize, vr: usize, n: usize): i32 {\n return memcmp(vl, vr, n);\n }\n\n /** Gets a pointer to a static chunk of memory of the given size. */\n // @ts-ignore: decorator\n @builtin\n export declare function data(size: T, align?: i32): usize;\n}\n\n// @ts-ignore: decorator\n@builtin\nexport declare const __data_end: usize;\n\n// @ts-ignore: decorator\n@builtin\nexport declare let __stack_pointer: usize;\n\n// @ts-ignore: decorator\n@builtin\nexport declare const __heap_base: usize;\n\n/** Heap memory interface. */\nexport namespace heap {\n\n /** Allocates a chunk of memory of at least the specified size. */\n // @ts-ignore: decorator\n @unsafe export function alloc(size: usize): usize {\n return __alloc(size);\n }\n\n /** Reallocates a chunk of memory to have at least the specified size. */\n // @ts-ignore: decorator\n @unsafe export function realloc(ptr: usize, size: usize): usize {\n return __realloc(ptr, size);\n }\n\n /** Frees a chunk of memory. Does hardly anything (most recent block only) with the stub runtime. */\n // @ts-ignore: decorator\n @unsafe export function free(ptr: usize): void {\n __free(ptr);\n }\n\n /** Dangerously resets the entire heap. Specific to the stub runtime. */\n // @ts-ignore: decorator\n @unsafe export function reset(): void {\n if (isDefined(__reset)) {\n __reset();\n } else {\n throw new Error(E_NOTIMPLEMENTED);\n }\n }\n}\n","export function memcpy(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memcpy.c\n let w: u32, x: u32;\n\n // copy 1 byte each until src is aligned to 4 bytes\n while (n && (src & 3)) {\n store(dest++, load(src++));\n n--;\n }\n\n // if dst is aligned to 4 bytes as well, copy 4 bytes each\n if ((dest & 3) == 0) {\n while (n >= 16) {\n store(dest , load(src ));\n store(dest + 4, load(src + 4));\n store(dest + 8, load(src + 8));\n store(dest + 12, load(src + 12));\n src += 16; dest += 16; n -= 16;\n }\n if (n & 8) {\n store(dest , load(src ));\n store(dest + 4, load(src + 4));\n dest += 8; src += 8;\n }\n if (n & 4) {\n store(dest, load(src));\n dest += 4; src += 4;\n }\n if (n & 2) { // drop to 2 bytes each\n store(dest, load(src));\n dest += 2; src += 2;\n }\n if (n & 1) { // drop to 1 byte\n store(dest++, load(src++));\n }\n return;\n }\n\n // if dst is not aligned to 4 bytes, use alternating shifts to copy 4 bytes each\n // doing shifts if faster when copying enough bytes (here: 32 or more)\n if (n >= 32) {\n switch (dest & 3) {\n // known to be != 0\n case 1: {\n w = load(src);\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n n -= 3;\n while (n >= 17) {\n x = load(src + 1);\n store(dest, w >> 24 | x << 8);\n w = load(src + 5);\n store(dest + 4, x >> 24 | w << 8);\n x = load(src + 9);\n store(dest + 8, w >> 24 | x << 8);\n w = load(src + 13);\n store(dest + 12, x >> 24 | w << 8);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n case 2: {\n w = load(src);\n store(dest++, load(src++));\n store(dest++, load(src++));\n n -= 2;\n while (n >= 18) {\n x = load(src + 2);\n store(dest, w >> 16 | x << 16);\n w = load(src + 6);\n store(dest + 4, x >> 16 | w << 16);\n x = load(src + 10);\n store(dest + 8, w >> 16 | x << 16);\n w = load(src + 14);\n store(dest + 12, x >> 16 | w << 16);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n case 3: {\n w = load(src);\n store(dest++, load(src++));\n n -= 1;\n while (n >= 19) {\n x = load(src + 3);\n store(dest, w >> 8 | x << 24);\n w = load(src + 7);\n store(dest + 4, x >> 8 | w << 24);\n x = load(src + 11);\n store(dest + 8, w >> 8 | x << 24);\n w = load(src + 15);\n store(dest + 12, x >> 8 | w << 24);\n src += 16; dest += 16; n -= 16;\n }\n break;\n }\n }\n }\n\n // copy remaining bytes one by one\n if (n & 16) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 8) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 4) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 2) {\n store(dest++, load(src++));\n store(dest++, load(src++));\n }\n if (n & 1) {\n store(dest++, load(src++));\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function memmove(dest: usize, src: usize, n: usize): void { // see: musl/src/string/memmove.c\n if (dest == src) return;\n if (ASC_SHRINK_LEVEL < 1) {\n if (src - dest - n <= -(n << 1)) {\n memcpy(dest, src, n);\n return;\n }\n }\n if (dest < src) {\n if (ASC_SHRINK_LEVEL < 2) {\n if ((src & 7) == (dest & 7)) {\n while (dest & 7) {\n if (!n) return;\n --n;\n store(dest++, load(src++));\n }\n while (n >= 8) {\n store(dest, load(src));\n n -= 8;\n dest += 8;\n src += 8;\n }\n }\n }\n while (n) {\n store(dest++, load(src++));\n --n;\n }\n } else {\n if (ASC_SHRINK_LEVEL < 2) {\n if ((src & 7) == (dest & 7)) {\n while ((dest + n) & 7) {\n if (!n) return;\n store(dest + --n, load(src + n));\n }\n while (n >= 8) {\n n -= 8;\n store(dest + n, load(src + n));\n }\n }\n }\n while (n) {\n store(dest + --n, load(src + n));\n }\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function memset(dest: usize, c: u8, n: usize): void { // see: musl/src/string/memset\n if (ASC_SHRINK_LEVEL > 1) {\n while (n) {\n store(dest++, c);\n --n;\n }\n } else {\n // fill head and tail with minimal branching\n if (!n) return;\n let dend = dest + n;\n store(dest, c);\n store(dend - 1, c);\n if (n <= 2) return;\n store(dest, c, 1);\n store(dest, c, 2);\n store(dend - 2, c);\n store(dend - 3, c);\n if (n <= 6) return;\n store(dest, c, 3);\n store(dend - 4, c);\n if (n <= 8) return;\n\n // advance pointer to align it at 4-byte boundary\n let k: usize = -dest & 3;\n dest += k;\n n -= k;\n n &= -4;\n\n let c32: u32 = -1 / 255 * c;\n\n // fill head/tail up to 28 bytes each in preparation\n dend = dest + n;\n store(dest, c32);\n store(dend - 4, c32);\n if (n <= 8) return;\n store(dest, c32, 4);\n store(dest, c32, 8);\n store(dend - 12, c32);\n store(dend - 8, c32);\n if (n <= 24) return;\n store(dest, c32, 12);\n store(dest, c32, 16);\n store(dest, c32, 20);\n store(dest, c32, 24);\n store(dend - 28, c32);\n store(dend - 24, c32);\n store(dend - 20, c32);\n store(dend - 16, c32);\n\n // align to a multiple of 8\n k = 24 + (dest & 4);\n dest += k;\n n -= k;\n\n // copy 32 bytes each\n let c64: u64 = c32 | (c32 << 32);\n while (n >= 32) {\n store(dest, c64);\n store(dest, c64, 8);\n store(dest, c64, 16);\n store(dest, c64, 24);\n n -= 32;\n dest += 32;\n }\n }\n}\n\n// @ts-ignore: decorator\n@inline\nexport function memcmp(vl: usize, vr: usize, n: usize): i32 {\n if (vl == vr) return 0;\n if (ASC_SHRINK_LEVEL < 2) {\n if ((vl & 7) == (vr & 7)) {\n while (vl & 7) {\n if (!n) return 0;\n let a = load(vl);\n let b = load(vr);\n if (a != b) return a - b;\n n--; vl++; vr++;\n }\n while (n >= 8) {\n if (load(vl) != load(vr)) break;\n vl += 8;\n vr += 8;\n n -= 8;\n }\n }\n }\n while (n--) {\n let a = load(vl);\n let b = load(vr);\n if (a != b) return a - b;\n vl++; vr++;\n }\n return 0;\n}\n"]} \ No newline at end of file diff --git a/tutorials/wat/main/blink.wat b/tutorials/wat/main/blink.wat index 1ef04beea..ff61dca29 100644 --- a/tutorials/wat/main/blink.wat +++ b/tutorials/wat/main/blink.wat @@ -6,11 +6,13 @@ ;; Imports from the WARDuino VM (import "env" "chip_delay" (func $env.chip_delay (type $int32->void))) + (import "env" "display_init" (func $env.display_init (type $void->void))) + (import "env" "chip_pin_mode" (func $env.chip_pin_mode (type $int32->int32->void))) (import "env" "chip_digital_write" (func $env.chip_digital_write (type $int32->int32->void))) ;; Non-mutable globals - (global $led i32 (i32.const 23)) + (global $led i32 (i32.const 4)) (global $on i32 (i32.const 1)) (global $off i32 (i32.const 0)) @@ -18,8 +20,10 @@ (func $init (type $void->void) ;; Set pin mode global.get $led - i32.const 2 - call $env.chip_pin_mode) + i32.const 3 + call $env.chip_pin_mode + call $env.display_init + ) ;; Blink function (public) (func $blink (type $void->void)