mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 05:25:32 +03:00
Base: Return the correct value for fib(0)
in Wasm example
Previously, using `wasm-decompile` to decompile the Wasm bytecode on the `wasm.html` example page gave this output: ``` export function fib(a:int):int { if (a < 2) { return 1 } return fib(a - 2) + fib(a - 1); } ``` With this change the bytecode now decompiles to: ``` export function fib(a:int):int { if (a <= 0) { return 0 } if (a == 1) { return 1 } return fib(a - 2) + fib(a - 1); } ``` This means that the example page now prints the correct answer of 55 to the console for `fib(10)`. Previously, `fib(10)` returned 89. I also used `wasm-opt -Oz`, which removed an unnecessary `return` instruction, saving 1 byte!
This commit is contained in:
parent
da60529ab8
commit
8892c25520
Notes:
sideshowbarker
2024-07-17 02:38:39 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/8892c25520 Pull-request: https://github.com/SerenityOS/serenity/pull/23924
@ -4,10 +4,10 @@
|
||||
const bytes = new Uint8Array([
|
||||
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60,
|
||||
0x01, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x07, 0x01, 0x03,
|
||||
0x66, 0x69, 0x62, 0x00, 0x00, 0x0a, 0x1f, 0x01, 0x1d, 0x00, 0x20, 0x00,
|
||||
0x41, 0x02, 0x48, 0x04, 0x40, 0x41, 0x01, 0x0f, 0x0b, 0x20, 0x00, 0x41,
|
||||
0x02, 0x6b, 0x10, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6b, 0x10, 0x00, 0x6a,
|
||||
0x0f, 0x0b
|
||||
0x66, 0x69, 0x62, 0x00, 0x00, 0x0a, 0x29, 0x01, 0x27, 0x00, 0x20, 0x00,
|
||||
0x41, 0x00, 0x4c, 0x04, 0x40, 0x41, 0x00, 0x0f, 0x0b, 0x20, 0x00, 0x41,
|
||||
0x01, 0x46, 0x04, 0x40, 0x41, 0x01, 0x0f, 0x0b, 0x20, 0x00, 0x41, 0x02,
|
||||
0x6b, 0x10, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6b, 0x10, 0x00, 0x6a, 0x0b
|
||||
]);
|
||||
WebAssembly.compile(bytes)
|
||||
.then(module => WebAssembly.instantiate(module))
|
||||
|
Loading…
Reference in New Issue
Block a user