Latest BEAM spec?

Bjorn Gustavsson <>
Tue Nov 30 21:21:14 CET 1999

James Hague <> writes:

> I've been looking at the BEAM emulator source code and a BEAM
> specification document (the latter is from October 1997, version 1.2).  It
> seems that only a subset of the BEAM instruction set is actually
> implemented in the current system.  True?  Were the other instructions
> simply not implemented or have they been removed from the BEAM spec?  Is a
> more recent spec publicly available? 

The specification is very much out of date. I am rewriting the specification,
but don't hold your breath waiting for it... :-)

Here is some information about the instruction set and the loader:

The compiler only emits GENERIC instructions. There are currently only 78 generic
instructions. The generic instructions was chosen to be as simple and as few
as possible. They take operands tagged by type. All generic instructions are
listed in lib/compiler/src/

The loader translates the generic instructions to SPECIFIC instructions.
There are currently more than 300 specific instructions. Many specific
instructions are specialised to operate on only certain operand types.
For instance, there is one generic 'move' instructions but 12 (if I counted
correctly) specific 'move' instructions in the emulator.

The specific instructions are listed in erts/emulator/beam/
The Perl script erts/emulator/utils/beam_makeops reads and and generates the following files needed by the loader:


(They are placed into the architecture-dependent directory in erts/emulator.)

You'll probably find most of your missing instructions in beam_hot.h and

Using these files, the loader does some other tricks:

1. It can combine several consecutive instructions into one, or split one
into several others. This is specified using patterns like this in

	move X1=x Y1=y | move X2=x Y2=y => move2 X1 Y1 X2 Y2

(combines two instructions moving from an x register to y register (stack frame)
to one move2 instruction).

2. It can pack several operands for an instruction into one word to save
space and time. Since the unpacking code is tricky, the beam_makops script
generates the complete instruction. Given

%macro:move Move -pack -gen_dest
move x y

the beam_makeops script generates (into beam_hot.h):

    { unsigned tmp_packed1;
    uint32* next;
    PreFetch(1, next);
    tmp_packed1 = Arg(0);
    Move(xb(tmp_packed1&0xFFF), yb((tmp_packed1>>16)), StoreSimpleDest);
    NextPF(1, next);

The Move C-prepreprocessor macro that does the real work is defined in
beam_emu.c, as are the other macros.

Björn Gustavsson            Ericsson Utvecklings AB
			    BOX 1505
		 	    125 25 Älvsjö

More information about the erlang-questions mailing list