From f248c1a500305fa597528d1b1e0ac54ac4dc3e12 Mon Sep 17 00:00:00 2001 From: Gaurav Gautam Date: Sun, 23 Apr 2023 14:48:33 +0530 Subject: [PATCH] Add instructions for viewing asm with v8 --- langs_to_asm.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/langs_to_asm.md b/langs_to_asm.md index a6971edc..a866b552 100644 --- a/langs_to_asm.md +++ b/langs_to_asm.md @@ -22,8 +22,10 @@ If it supports machine code output for your language, Compiler Explorer is often | C / C++ | CLANG | -O3 | | C# | .NET | | | ZIG(1) | ZIG | -OReleaseFast / -OReleaseSmall / -OReleaseSafe | +| javascript (2)| v8(11.3) | | (1) For Zig, you might need to type in "Zig" in the language text box to find it, as some versions of Compiler Explorer have a bug where it does not show up in the drop-down menu. +(2) For javascript optimized assembly code is only generated by v8 after it thinks the code path in question is hot enough to trigger an optimization. This behaviour also changes from version to version. In some versions the optimized code is generated with less number of runs. In the trunk version of v8 add `--no-lazy-feedback-allocation`. Note that not all languages supported by Compiler Explorer provide _actual_ ASM output. Some - like Python - only provide interpreter bytecode output, which is not particularly useful. The table above includes only those languages for which Compiler Explorer can produce real ASM. @@ -122,6 +124,30 @@ instructions may work for LLVM's objdump too. objdump -d --demangle test > test_disassembly.asm ``` +### turbolizer (v8/nodejs) + +v8 creates optimized assembly code only if it thinks the code path in question is hot. To view +the assembly using v8's `d8` shell or `nodejs`, run your script with the flag `--trace-turbo`. For +example with nodejs: +``` +node --trace-turbo myscript.js +``` +This will generate .json files in the directory where this command was run (multiple files may be generated). +You can load those json files into this tool: https://v8.github.io/tools/head/turbolizer/index.html, by hitting `Ctrl+L` +and then selecting the json file. You will be able to see the bytecode on the leftpane and the assembly on the rightpane. + +You can try running this script to generate a sample json file +``` + function square(a) { + let result = a * a; + return result; +} + +// Call function once to fill type information +for (let i = 0; i < 1e5; i++) +square(i); +``` + # If you'd like to contribute a new language or method... ... please submit a pull request! Note that in order to be included here, you must provide comprehensive instructions that allow someone to either step through or conveniently view the assembly language output of a program snippet.