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/genop.tab.

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/ops.tab.
The Perl script erts/emulator/utils/beam_makeops reads genop.tab and
ops.tab and generates the following files needed by the loader:

	beam_hot.h
	beam_cold.h
	beam_opcodes.c
	beam_opcodes.h
	beam_pred_funcs.h
	beam_tr_funcs.h

(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
beam_cold.h.

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 ops.tab:

	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):

OpCase(move_xy):
    { 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
-- 
Björn Gustavsson            Ericsson Utvecklings AB
      ÄT2/UAB/F/P
			    BOX 1505
		 	    125 25 Älvsjö



More information about the erlang-questions mailing list