POV-Ray : Newsgroups : povray.advanced-users : function optimization question : Re: function optimization question Server Time
29 Jul 2024 20:27:15 EDT (-0400)
  Re: function optimization question  
From: Thorsten Froehlich
Date: 31 Mar 2002 10:45:45
Message: <3ca72f29@news.povray.org>
In article <3ca6f75f$1@news.povray.org> , "Jan Walzer" <jan### [at] lzernet> wrote:

> No ... this is not what I meant ... I mean, that the prog, can modify itself
> in memory, to speedup execution ...
> ... or to make unreadable code ...

Which would make it close to impossible to just-in-time compile anything.

Anyway, here is a list from the source code.  It may not be fully up-to-date
and probably won't we very readable in a newsreader, but that is what text
editiors and printers are for :-)

    Thorsten

- - - - - - - - -

# Rs = R0 - R7, one of eight floating-point registers
# Rd = R0 - R7, one of eight floating-point registers
# k = constant, can be DBL or int depending on function
# SP = data stack point
# PSP = program stack pointer
# CC = condition code register
# PC = program counter
# global = global variable data space
# local = local variable data space
# const = const floating-point value data space
# eq = equal
# ne = not equal
# lt = lower
# le = lower or equal
# gt = greater
# ge = greater or equal


R-Type Instructions (9 * 64 = 576)

Opcode|Source| Dest | k-data |Instruction   | Operation
4 bits|3 bits|3 bits|16 bits |              |
------+------+------+--------+--------------+-----------------------------
  00  |  Rs  |  Rd  |  0000  | add   Rs, Rd | Rd + Rs -> Rd
  01  |  Rs  |  Rd  |  0000  | sub   Rs, Rd | Rd - Rs -> Rd
  02  |  Rs  |  Rd  |  0000  | mul   Rs, Rd | Rd * Rs -> Rd
  03  |  Rs  |  Rd  |  0000  | div   Rs, Rd | Rd / Rs -> Rd
  04  |  Rs  |  Rd  |  0000  | mod   Rs, Rd | Rd % Rs -> Rd
  05  |  Rs  |  Rd  |  0000  | move  Rs, Rd | Rs -> Rd
  06  |  Rs  |  Rd  |  0000  | cmp   Rs, Rd | Rd - Rs -> CC
  07  |  Rs  |  Rd  |  0000  | neg   Rs, Rd | -Rs -> Rd
  08  |  Rs  |  Rd  |  0000  | abs   Rs, Rd | |Rs| -> Rd


I-Type Instructions (7 * 8 = 56)

Opcode|Ext.Op| Dest | k-data |Instruction   | Operation
4 bits|3 bits|3 bits|16 bits |              |
------+------+------+--------+--------------+-----------------------------
  09  |  00  |  Rd  |const(k)|addi  c, Rd   | Rd + const(k) -> Rd
  09  |  01  |  Rd  |const(k)|subi  c, Rd   | Rd - const(k) -> Rd
  09  |  02  |  Rd  |const(k)|muli  c, Rd   | Rd * const(k) -> Rd
  09  |  03  |  Rd  |const(k)|divi  c, Rd   | Rd / const(k) -> Rd
  09  |  04  |  Rd  |const(k)|modi  c, Rd   | Rd % const(k) -> Rd
  09  |  05  |  Rd  |const(k)|loadi c, Rd   | const(k) -> Rd
  09  |  06  |  Rd  |const(k)|cmpi  c, Rd   | Rd - const(k) -> CC


JS-Type Instructions (6 * 8 = 48)

Opcode|Ext.Op| Dest | k-data |Instruction   | Operation
4 bits|3 bits|3 bits|16 bits |              |
------+------+------+--------+--------------+-----------------------------
  10  |  00  |  Rd  |  0000  |seq   Rd      | (CC = eq) -> Rd
  10  |  01  |  Rd  |  0000  |sne   Rd      | (CC = ne) -> Rd
  10  |  02  |  Rd  |  0000  |slt   Rd      | (CC = lt) -> Rd
  10  |  03  |  Rd  |  0000  |sle   Rd      | (CC = le) -> Rd
  10  |  04  |  Rd  |  0000  |sgt   Rd      | (CC = gt) -> Rd
  10  |  05  |  Rd  |  0000  |sge   Rd      | (CC = ge) -> Rd
  10  |  06  |  Rd  |  0000  |teq   Rd      | (Rd == 0) -> Rd
  10  |  07  |  Rd  |  0000  |tne   Rd      | (Rd != 0) -> Rd


ML-Type Instructions (2 * 8 = 16)

Opcode|Ext.Op| Dest | k-data |Instruction   | Operation
4 bits|3 bits|3 bits|16 bits |              |
------+------+------+--------+--------------+-----------------------------
  11  |  00  |  Rd  |  0000  |load 0(k), Rd | global(k) -> Rd
  11  |  01  |  Rd  |  0000  |load SP(k), Rd| local(k) -> Rd


MS-Type Instructions (2 * 8 = 16)

Opcode|Ext.Op|Source| k-data |Instruction   | Operation
4 bits|3 bits|3 bits|16 bits |              |
------+------+------+--------+--------------+-----------------------------
  12  |  00  |  Rs  |  0000  |store Rs, 0(k)| Rs -> global(k)
  12  |  01  |  Rs  |  0000  |store Rs, SP(k)| Rs -> local(k)


JB-Type Instructions (6)

Opcode|Ext.Op|Unused| k-data |Instruction   | Operation
4 bits|3 bits|3 bits|16 bits |              |
------+------+------+--------+--------------+-----------------------------
  13  |  00  |  00  | offset |beq   k       | if (CC = eq) then k -> PC
  13  |  01  |  00  | offset |bne   k       | if (CC = ne) then k -> PC
  13  |  02  |  00  | offset |blt   k       | if (CC = lt) then k -> PC
  13  |  03  |  00  | offset |ble   k       | if (CC = le) then k -> PC
  13  |  04  |  00  | offset |bgt   k       | if (CC = gt) then k -> PC
  13  |  05  |  00  | offset |bge   k       | if (CC = ge) then k -> PC


XS-Type Instructions (6 * 8 = 48)

Opcode|Ext.Op|Source| k-data |Instruction   | Operation
4 bits|3 bits|3 bits|16 bits |              |
------+------+------+--------+--------------+-----------------------------
  14  |  00  |  Rs  |  0000  |xeq   Rs      | if (Rs == 0) then exception
  14  |  01  |  Rs  |  0000  |xne   Rs      | if (Rs != 0) then exception
  14  |  02  |  Rs  |  0000  |xlt   Rs      | if (Rs < 0) then exception
  14  |  03  |  Rs  |  0000  |xle   Rs      | if (Rs <= 0) then exception
  14  |  04  |  Rs  |  0000  |xgt   Rs      | if (Rs > 0) then exception
  14  |  05  |  Rs  |  0000  |xge   Rs      | if (Rs >= 0) then exception
  14  |  06  |  Rs  |  0000  |xdz   R0, Rs  | if (R0 == 0) && (Rs == 0) then
exception


X-Type Instructions (11)

Opcode|Ext.Op| k-data |Instruction   | Operation
4 bits|6 bits|16 bits |              |
------+------+--------+--------------+--------------------------------
  15  |  00  |  0000  |jsr   k       | PSP + 1 -> PSP, PC -> (PSP), k -> PC
  15  |  01  |  0000  |jmp   k       | k -> PC
  15  |  02  |  0000  |rts           | (PSP) -> PC, PSP - 1 -> PSP
  15  |  03  |  0000  |call  k       | calls user-defined function k, result
will be in R0
  15  |  04  |  0000  |sys1  k       | calls internal function k with one
argument, result will be in R0
  15  |  05  |  0000  |sys2  k       | calls internal function k with two
arguments, result will be in R0
  15  |  06  |  0000  |trap  k       | calls internal function k with
arguments on stack, result will be in R0
  15  |  07  |  0000  |traps k       | calls internal function k with
arguments on stack, result will be on the stack
  15  |  08  |  0000  |grow  k       | grow the stack to hold k elements
(floating-point numbers)
  15  |  09  |  0000  |push  k       | move the stack pointer k elements
forward
  15  |  10  |  0000  |pop   k       | move the stack pointer k elements
backward
  15  |  63  |  0000  |nop           | no operation

Total number of defined instructions: 780
Density of instruction set: 780 / 1024 = 0.7617


OF COURSE THIS IS ALL SUBJECT TO COMPLETE CHANGE AND REDESIGN IN CURRENT AND
FUTURE VERSIONS OF POV-RAY!

____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trfde

Visit POV-Ray on the web: http://mac.povray.org


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.