After writing a couple of library functions, I realized that we have to
do alot of data shuffling to do common tasks.  Reserving a register to 
hold 0 or 1 and/or filling up registers with constants just takes up cpu
time and could better be handled if the opcodes took constants directly
as well as registers.

substr was really annoying in this regard:

        set     I0,0
        set     I1,1
        substr  S0,S1,I0,I1

pre-allocating the registers (I.e. I31=1, I30=0) helped a bit, but it
took away from the size of the general purpose register pool, and
obscured the code.

So, with that in mind, here are some opcodes to fill in the blanks.  I
tried to make sure that none of the opcodes below could be computed in
advance (i.e. there's no add(i,ic,ic)) and when the order of the args
doesn't matter (in add, for example), the constant comes last.

** Suggested Opcodes to minimize data shuffling **
-- arithmetic operations

[unification of add & inc, except in the 'inc I0' case]
add(i,i,ic)
add(n,n,nc)

cmod(i,i,ic)
cmod(i,ic,i)
cmod(n,n,nc)
cmod(n,nc,n)

div(i,i,ic)
div(i,ic,i)
div(n,n,nc)
div(n,nc,n)

mod(i,i,ic)
mod(i,ic,i)
mod(n,n,nc)
mod(n,n,nc)

mul(i,i,ic)
mul(n,n,nc)

pow(n,i,ic)
pow(n,ic,i)
pow(n,i,nc)
pow(n,ic,n)
pow(n,n,ic)
pow(n,nc,i)
pow(n,n,nc)
pow(n,nc,n)

[unification of sub & dec, except in the 'dec I0' case]
sub(i,i,ic)
sub(n,n,nc)


-- string operations

chopn(s,i)

concat(s,sc)

substr(s,s,i,ic)
substr(s,s,ic,i)
substr(s,s,ic,ic)
substr(s,sc,i,i)
substr(s,sc,i,ic)
substr(s,sc,ic,i)

-- trancendental operations
atan(n,i,ic)
atan(n,ic,i)
atan(n,i,nc)
atan(n,ic,n)
atan(n,n,ic)
atan(n,nc,i)
atan(n,n,nc)
atan(n,nc,n)

-- bitwise logical operations
and(i,i,ic)
or(i,i,ic)
shl(i,i,i)
shr(i,i,i)
xor(i,i,ic)




WHEW!  That's alot of opcodes.  However, it would lead to more compact
(and probably faster) bytecode to be able to avoid having to load
registers all the time with values you know in advance.

Thoughts?

Brian

Reply via email to