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
[1698]
Do you do basic block analysis of the source opcodes to determine 
where the subroutine boundaries are? For that matter, does the Z80 
have indirect branches?
Steeve
20-Feb-2007
[1699]
;-_-
BrianH
20-Feb-2007
[1700]
Sorry, I don't speak IRC.
Steeve
20-Feb-2007
[1701x2]
yes indirect branches exist
but it's not a problem, the management of branches is done in real 
time, it's in a stack, so i can manage fixed as indirect branches.
BrianH
20-Feb-2007
[1703]
How common are they? Can you analyze them to determine their destinations 
to convert them into branches or calls?
Steeve
20-Feb-2007
[1704x2]
all branches are converted into call
difficult to explain with my bad english
BrianH
20-Feb-2007
[1706x2]
Call of function or continuation? (Sorry if your English doesn't 
include computer-science terms)
Meaning, does the call return?
Steeve
20-Feb-2007
[1708x2]
when i seek a Z80 branch opcode (direct or indirect), i stop the 
current rebcode function construction and i build new one for the 
folowing opcodes
so each rebcode function (routines) must return the adress of the 
next branch
BrianH
20-Feb-2007
[1710x2]
Continuation then.
How do you handle back-branches then?
Steeve
20-Feb-2007
[1712x2]
if a routine return an unknwon adress, then the parser jump a these 
adress and rebuild a new function.
back-branches are treated in the same manner
BrianH
20-Feb-2007
[1714]
So, no basic block analysis at all. All branches are considered non-local.
Steeve
20-Feb-2007
[1715]
yep
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
[1747]
hum i don't understand