ack/doc/em/descr.nr

154 lines
5.8 KiB
Plaintext
Raw Permalink Normal View History

1993-03-30 15:43:44 +00:00
.bp
.P1 "DESCRIPTORS"
.PP
1984-06-29 14:46:39 +00:00
Several instructions use descriptors, notably the range check instruction,
the array instructions, the goto instruction and the case jump instructions.
Descriptors reside in data space.
They may be constructed at run time, but
more often they are fixed and allocated in ROM data.
1993-03-30 15:43:44 +00:00
.PP
1984-06-29 14:46:39 +00:00
All instructions using descriptors, except GTO, have as argument
the size of the integers in the descriptor.
All implementations have to allow integers of the size of a
word in descriptors.
All integers popped from the stack and used for indexing or comparing
must have the same size as the integers in the descriptor.
1993-03-30 15:43:44 +00:00
.P2 "Range check descriptors"
.PP
1984-06-29 14:46:39 +00:00
Range check descriptors consist of two integers:
1993-03-30 15:43:44 +00:00
.IP 1.
1990-02-05 10:06:42 +00:00
lower bound signed
1993-03-30 15:43:44 +00:00
.IP 2.
1990-02-05 10:06:42 +00:00
upper bound signed
1993-03-30 15:43:44 +00:00
.LP
1984-06-29 14:46:39 +00:00
The range check instruction checks an integer on the stack against
these bounds and causes a trap if the value is outside the interval.
The value itself is neither changed nor removed from the stack.
1993-03-30 15:43:44 +00:00
.P2 "Array descriptors"
.PP
1984-06-29 14:46:39 +00:00
Each array descriptor describes a single dimension.
For multi-dimensional arrays, several array instructions are
needed to access a single element.
Array descriptors contain the following three integers:
1993-03-30 15:43:44 +00:00
.IP 1.
1990-02-05 10:06:42 +00:00
lower bound signed
1993-03-30 15:43:44 +00:00
.IP 2.
1990-02-05 10:06:42 +00:00
upper bound \- lower bound unsigned
1993-03-30 15:43:44 +00:00
.IP 3.
1990-02-05 10:06:42 +00:00
number of bytes per element unsigned
1993-03-30 15:43:44 +00:00
.LP
1984-06-29 14:46:39 +00:00
The array instructions LAR, SAR and AAR have the pointer to the start
of the descriptor as operand on the stack.
1993-03-30 15:43:44 +00:00
.LP
1984-06-29 14:46:39 +00:00
The element A[I] is fetched as follows:
1993-03-30 15:43:44 +00:00
.IP 1.
1984-06-29 14:46:39 +00:00
Stack the address of A (e.g., using LAE or LAL)
1993-03-30 15:43:44 +00:00
.IP 2.
1984-06-29 14:46:39 +00:00
Stack the value of I (n-byte integer)
1993-03-30 15:43:44 +00:00
.IP 3.
1984-06-29 14:46:39 +00:00
Stack the pointer to the descriptor (e.g., using LAE)
1993-03-30 15:43:44 +00:00
.IP 4.
1984-06-29 14:46:39 +00:00
LAR n (n is the size of the integers in the descriptor and I)
1993-03-30 15:43:44 +00:00
.LP
1984-06-29 14:46:39 +00:00
All array instructions first pop the address of the descriptor
and the index.
If the index is not within the bounds specified, a trap occurs.
1986-02-04 17:37:41 +00:00
If ok, (I~\-~lower bound) is multiplied
1984-06-29 14:46:39 +00:00
by the number of bytes per element (the third word). The result is added
to the address of A and replaces A on the stack.
1993-03-30 15:43:44 +00:00
.QQ
1984-06-29 14:46:39 +00:00
At this point LAR, SAR and AAR diverge.
AAR is finished. LAR pops the address and fetches the data
item,
the size being specified by the descriptor.
The usual restrictions for memory access must be obeyed.
SAR pops the address and stores the
data item now exposed.
1993-03-30 15:43:44 +00:00
.P2 "Non-local goto descriptors"
.PP
1984-06-29 14:46:39 +00:00
The GTO instruction provides a way of returning directly to any
active procedure invocation.
The argument of the instruction is the address of a descriptor
containing three pointers:
1993-03-30 15:43:44 +00:00
.IP 1.
1984-06-29 14:46:39 +00:00
value of PC after the jump
1993-03-30 15:43:44 +00:00
.IP 2.
1984-06-29 14:46:39 +00:00
value of SP after the jump
1993-03-30 15:43:44 +00:00
.IP 3.
1984-06-29 14:46:39 +00:00
value of LB after the jump
1993-03-30 15:43:44 +00:00
.LP
1984-06-29 14:46:39 +00:00
GTO replaces the loads PC, SP and LB from the descriptor,
thereby jumping to a procedure
1990-02-05 10:06:42 +00:00
and removing zero or more frames from the stack.
1984-06-29 14:46:39 +00:00
The LB, SP and PC in the descriptor must belong to a
dynamically enclosing procedure,
because some EM implementations will need to backtrack through
the dynamic chain and use the implementation dependent data
in frames to restore registers etc.
1993-03-30 15:43:44 +00:00
.P2 "Case descriptors"
.PP
1984-06-29 14:46:39 +00:00
The case jump instructions CSA and CSB both
provide multiway branches selected by a case index.
Both fetch two operands from the stack:
first a pointer to the low address of the case descriptor
and then the case index.
CSA uses the case index as index in the descriptor table, but CSB searches
the table for an occurrence of the case index.
Therefore, the descriptors for CSA and CSB,
as shown in figure 4, are different.
All pointers in the table must be addresses of instructions in the
procedure executing the case instruction.
1993-03-30 15:43:44 +00:00
.PP
1984-06-29 14:46:39 +00:00
CSA selects the new PC by indexing.
If the index, a signed integer, is greater than or equal to
the lower bound and less than or equal to the upper bound,
then fetch the new PC from the list of instruction pointers by indexing with
index-lower.
The table does not contain the value of the upper bound,
but the value of upper-lower as an unsigned integer.
The default instruction pointer is used when the index is out of bounds.
1984-06-29 14:46:39 +00:00
If the resulting PC is 0, then trap.
1993-03-30 15:43:44 +00:00
.PP
1984-06-29 14:46:39 +00:00
CSB selects the new PC by searching.
The table is searched for an entry with index value equal to the case index.
That entry or, if none is found, the default entry contains the
new PC.
When the resulting PC is 0, a trap is performed.
1993-03-30 15:43:44 +00:00
.PP
1984-06-29 14:46:39 +00:00
The choice of which case instruction to use for
each source language case statement
is up to the front end.
If the range of the index value is dense, i.e
.DS
1986-02-04 17:37:41 +00:00
(highest value \- lowest value) / number of cases
1993-03-30 15:43:44 +00:00
.DE
1984-06-29 14:46:39 +00:00
is less than some threshold, then CSA is the obvious choice.
If the range is sparse, CSB is better.
1986-02-04 17:37:41 +00:00
.Dr 30
1984-06-29 14:46:39 +00:00
|--------------------| |--------------------| high address
| pointer for upb | | pointer n-1 |
|--------------------| |- - - - - - - |
| . | | index n-1 |
| . | |--------------------|
| . | | . |
| . | | . |
| . | | . |
| . | |--------------------|
| . | | pointer 1 |
|--------------------| |- - - - - - - |
| pointer for lwb+1 | | index 1 |
|--------------------| |--------------------|
| pointer for lwb | | pointer 0 |
|--------------------| |- - - - - - - |
| upper - lower | | index 0 |
|--------------------| |--------------------|
| lower bound | | number of entries |
|--------------------| |--------------------|
| default pointer | | default pointer | low address
|--------------------| |--------------------|
CSA descriptor CSB descriptor
1986-02-04 17:37:41 +00:00
.Df
1987-03-31 07:56:14 +00:00
Figure 4. Descriptor layout for CSA and CSB
1986-02-04 17:37:41 +00:00
.De