How does the JS -> ASM generation work for ia32

15 views
Skip to first unread message

D T

unread,
Jul 31, 2016, 2:41:40 PM7/31/16
to v8-users
Hi there!

This mailing list helped me so many times, so I will give it another try :)
I am executing a javascript file containing a simple addition program as follows:
user@debugbox: v8/out/ia32.release/d8 --print_opt_code test.js

The addition in the program is called a few thousand times in a for loop to trigger the optimization.
When looking at the produced assembler code I wondered about its generation: 
Sometimes, when executing different JS programs, similar ASM code is generated, which means, that different JS code is optimized into the same ASM (or similar ASM code).
So far so good. But is there something like a template, which specifies which JS code is translated into which ASM code?
I mean something like "If there is a JS assignment, use 'mov register, variable' in ASM".

Sorry, if the question is dumb. I just want to understand what's going on :)

Thanks!

Jakob Kummerow

unread,
Aug 1, 2016, 4:39:08 AM8/1/16
to v8-users
That's the basic idea. The details are complicated enough to fill many books titled "compiler construction" and similar ;-) . It's a very interesting area of research!

In particular, optimizing compilers usually use several processing steps operating on various intermediate representations. For example, V8's "Crankshaft" optimizing compiler goes from the AST (abstract syntax tree) to high-level IR to low-level IR and then finally to machine code. The reason is that different operations are most easily done at specific steps of this workflow, e.g. variable scopes are resolved on the AST, dead code is eliminated in high-level IR, registers are allocated in low-level IR.

Sorry, if the question is dumb. I just want to understand what's going on :)

Thanks!

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages