r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[rebcode] Rebcode discussion

BrianH
20-Feb-2007
[1716]
Would it be too difficult to translate branches to literal offsets 
into their rebcode equivalents, as an optimization?
Steeve
20-Feb-2007
[1717x3]
here you can see my first try without rebcode http://perso.orange.fr/rebol/galaga.r
i could try this as a final compilation step, perhaps
in the source you can see the concept of branches management i use
BrianH
20-Feb-2007
[1720]
Your trick of generating words for branch targets may need changing 
when you switch to rebcode. Pre-2.7 versions of REBOL had hard limits 
on the number of words possible at once (about 8000). You might consider 
issue! values instead with a lookup table (probably a hash!).
Steeve
20-Feb-2007
[1721]
ok
BrianH
20-Feb-2007
[1722x2]
It will be a little slower. You might then return references to the 
code rather than the names.
That will cut down on lookups. Make it threaded.
Steeve
20-Feb-2007
[1724]
i think i will implement  a cached routines cleaner (GC) ,  to keep 
in memory only routines which are frequently requested
BrianH
20-Feb-2007
[1725]
There are some optimizations you can make to the code too, such as 
changing code like this:
    set [v1 v2] reduce [_d _e]
to this:
    v1: _d
    v2: _e
Steeve
20-Feb-2007
[1726x3]
i know but i have some constraint do to my parser
anyway, with rebcode i changed my way
*due to
BrianH
20-Feb-2007
[1729]
No block set.
Steeve
20-Feb-2007
[1730x4]
i know
currently a rebuild the parser to generate rebcode instead of rebol 
instructions
*currently i
so i don' t use set block anymore ;-)
BrianH
20-Feb-2007
[1734]
It occurs to me that you might be able to do the fixups using a compile-time 
lookup table, or perhaps translating addresses to label statements.
Steeve
20-Feb-2007
[1735x2]
i agree
i add this to my to-do list
BrianH
20-Feb-2007
[1737]
It also occurs to me that you could assemble your own code and modify 
the code blocks at runtime to make lookups unnecessary.
Steeve
20-Feb-2007
[1738]
but there's some difficulties toing that in real time
BrianH
20-Feb-2007
[1739]
As long as you don't change the length of the code blocks any offsets 
would still be valid and the location in memory of the data underlying 
the code blocks wouldn't change, lowering the chance of a crash.
Steeve
20-Feb-2007
[1740x2]
*doing that
if i concatenate code  at the end only (append) the previous branch 
offsets should not  be disturbed ?
BrianH
20-Feb-2007
[1742]
How much memory does this machine you are emulating have?
Steeve
20-Feb-2007
[1743x3]
64 Ko
Z80 can only manage 64 Ko of ram at once
but there is a sort of memory mapper
BrianH
20-Feb-2007
[1746]
How much address arithmetic is common when doing indirect branches 
and calls, and can you reverse it using flow analysis?
Steeve
20-Feb-2007
[1747x3]
hum i don't understand
adresses are on 16 bits
so Z80 can jump anywhere in 64 ko space adressing
BrianH
20-Feb-2007
[1750]
Are the Z80 opcodes fixed or variable length? If variable, are real-programmer 
tricks like branching into the middle of an opcode common?
Steeve
20-Feb-2007
[1751x2]
variable length
and yes it is common to branch in the middle of opcodes, we can't 
predict that by a static analysis
BrianH
20-Feb-2007
[1753]
I mean, to the middle of opcodes, not from. The real-programmer trick 
is to treat the latter portion of an opcode as if it were a different 
opcode, just because it has the same bit pattern, or worse yet, branching 
into the middle of static data.
Steeve
20-Feb-2007
[1754]
yes and what is the question ?!?
BrianH
20-Feb-2007
[1755]
I was seeing how difficult it would be to do a full-program compilation 
to a single rebcode block, with label statements at every branch 
destination.
Steeve
20-Feb-2007
[1756]
agree, for me it's possible only for direct jumps
BrianH
20-Feb-2007
[1757]
You don't even have to use label statements if you have 2 blocks, 
one full of references to the other.
Steeve
20-Feb-2007
[1758x3]
but in my example source, there is 80% of direct jumps
agree BrianH
my parser was just a proof of concept, i agree there is a lot of 
optimizations to do
BrianH
20-Feb-2007
[1761]
If you are really evil, you could fill a BRAB block with the offsets 
of every Z80 operation into the offsets of their equivalent rebcode 
operations and turn every branch into an address calculation, a BRA 
to a label before the BRAB, then the BRAB.
Steeve
20-Feb-2007
[1762]
hmm...
BrianH
20-Feb-2007
[1763]
It would mean a 64K element BRAB block for every 64K set of memory, 
in addition to the size of the generated code.
Steeve
20-Feb-2007
[1764]
hurg !!!
BrianH
20-Feb-2007
[1765]
You can't run REBOL on a cell phone, you know. Everything else has 
plenty of RAM :)