Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instructions for viewing asm with v8 #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions langs_to_asm.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand Down