[erlang-questions] Question about the VM

Anthony Ramine n.oxyde@REDACTED
Thu Sep 25 21:52:10 CEST 2014

Last time I tried manually changing a map/2 function to a "native loop" with simple jumps, I couldn't compile using BEAM optimisation passes because liveness analysis currently cannot cope with a backwards jump (e.g. {label,2}. ... {jump,{f,2}}):

$ bin/erlc foo.S
Function: map/3
foo.S: internal error in beam_block;
crash reason: {case_clause,

  in function  compile:'-select_passes/2-anonymous-2-'/2 (compile.erl, line 495)
  in call from compile:'-internal_comp/4-anonymous-1-'/2 (compile.erl, line 292)
  in call from compile:fold_comp/3 (compile.erl, line 310)
  in call from compile:internal_comp/4 (compile.erl, line 294)
  in call from compile:'-do_compile/2-anonymous-0-'/2 (compile.erl, line 153)

Without the BEAM optimisations (+no_postopt), compilation succeeds.

foo.S, for reference:


For the other points, see what Björn-Egil said. AFAIK only calls and gc-inducing instructions can yield.

Le 25 sept. 2014 à 21:17, Samuel Barney <samjbarney@REDACTED> a écrit :

> 1. A native loop is a loop that is not emulated via function calls.
> 2. I am planning on generating loops using plain jump instructions.
> 3. It shouldn't hang the VM any since, if I understand correctly, the thread can yield after any instruction is called.
> 4. What do you mean by, 'Did you measure that you actuall need such a thing?'
> 5. I have checked that the erlc compiler can handle it, and still benefit.
> 6. If I wanted to use HiPE, I would use it. Where's the fun in having HiPE do all my dirty work? I might integrate it into my language later on, but for right now I want pure BEAM.
> On Thu, Sep 25, 2014 at 3:07 AM, Anthony Ramine <n.oxyde@REDACTED> wrote:
> What do you call native loops? Are you planning to generate BEAM code that loops using plain jump instructions? What do you do in that loop? Can you be sure your process will still yield in a cooperative fashion to not hang the VM? Did you measure that you actually need such a thing? Did you check that you will still be able to feed that assembly to the erlc compiler to benefit from the other usual instructions? In the end couldn't you just use HiPE to take care of these loops?
> Regards,
> -- 
> Anthony Ramine
> Le 24 sept. 2014 à 23:36, Samuel Barney <samjbarney@REDACTED> a écrit :
>> I did look at targeting Core Erlang first, but it doesn't allow for native loops. I could emulate them with function calls, however, if I move down to the assembly level I can build loops with what is provided there.
>> Thank you for the information, I'll do some more searching to see what I can find.
>> Respectfully,
>> Samuel Barney
>> On Wed, Sep 24, 2014 at 4:40 AM, Anthony Ramine <n.oxyde@REDACTED> wrote:
>> Did you try targeting Core Erlang first? Which primitives do you want to access in BEAM?
>> There are 1024 X registers, and Y registers are used for locals in functions, to save them when calling other functions.
>> You can find such information by reading the source code or various talk slides made by the OTP team these last years, but I can't help you find the links right now.
>> Regards,
>> Le 24 sept. 2014 à 04:40, Samuel Barney <samjbarney@REDACTED> a écrit :
>> > I'm developing a language on top of the Erlang VM, and there are a couple of flow-control constructs that I can't implement without skipping the Erlang AST and using the erlang assembly code.
>> >
>> > Is there a specific amount of X and Y registers? Or is there a way that I can find that out via Erlang?
>> >
>> > Also, what is the purpose of the Y registers?
>> > _______________________________________________
>> > erlang-questions mailing list
>> > erlang-questions@REDACTED
>> > http://erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list