B. IMPLEMENTATION

B.1. Excerpts from the non-optimized EM_table

Even though the non-optimized version of the EM_table is relatively straight-forward, examples have never hurt anybody. One of the simplest instructions is the loc, which appears in our EM_table as follows:
C_loc    ==>    "set    $1, T1";
    "dec    4, SP";
    "st    T1, [SP]".
Just as SP is an alias for %l0, T1 is an alias for %g1. A little more complex is the adi which performs integer addition.
C_adi    ==>    "ld    [SP], T1";
    "ld    [SP+4], T2";
    "add    T1, T2, T3";
    "st    T3, [SP+4];
    "inc    4, SP".
We could go on with even more complex instructions, but since that would not contribute to anything the reader is referred to the implementation for more details.

B.2. Excerpts from the optimized EM_table

The optimized EM_table uses the cache primitives mentioned in chapter 4. This means that the loc this time appears as
C_loc    ==>    push_const($1).
The lol can now be written as
C_lol    ==>    push_reg(LB);
        inc_tos($1);
        push_const(4);
        C_los(4). Due to the law of conservation of misery somebody has to do the dirty work. In this case, it is the los. To show just a small part of the implementation of the los:
C_los    $1 == 4    ==>
        if (type_of_tos() == T_cst) {
            arith size;
            const_str_t n;
            size= pop_const();
            if (size <= 4) {
                reg_t a;
                reg_t a;
                char *LD;
                switch (size) {
    case 1:    LD = "ldub"; break;
    case 2:    LD = "lduh"; break;
    case 4:    LD = "ld"; break;
    default:    arg_error("C_los", size);
                }
                a = pop_reg_c13(n);
                b = alloc_reg();
    "$LD    [$a+$n], $b";
                push_reg(b);
                free_reg(a);
            } else ... For the full implementation, the reader is again referred to the actual implementation. Just to show how other instructions are affected by the optimization we will show that implementation of the tge instruction:
C_tge    ==>    {
            reg_t a;
            reg_t b;
            a = pop_reg();
            b = alloc_reg();
    "    tst    $a";
    "    bge,a    1f";
    "    mov    1, $b";    /* delay slot */
    "    set    0, $b";
            "1:";
            free_reg(a);
            push_reg(b);
        }.

CREDITS

In order of appearance:
Original idea | - | Dick Grune
Design & implementation | - | Philip Homburg
 | - | Raymond Michiels
Tutor | - | Dick Grune
Assistant Tutor | - | Ceriel Jacobs
Proofreading | - | Dick Grune
 | - | Hans van Eck

REFERENCES

$LIST$