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

World: r3wp

[rebcode] Rebcode discussion

BrianH
5-Nov-2005
[1199x4]
Any time Gregg! In particular, every time changes are made to the 
engine or docs :)
Romano, I feel your pain. If you look at the history in this group, 
you will find that I have gone into great detail about how much I 
feel your pain :(
But given your cases here, keep in mind that the only instruction 
now that takes a block of offsets is BRAB. As I have said above, 
BRAB with relative jumps means that it is only practical to use an 
offset block from a single branch statement. Branching to a block 
referenced by a word is only practical for rather obscure circumatances 
(for instance a multistate machine). So for most code using brab 
the offset block will be placed right there in the statement., so 
you will definitely know the starting position. But your second case 
is a little off, because with relative jumps, you don't need to know 
the absolute position of anything.


Assuming a branch offset block like the one in your second case, 
the relevant section of the code block you are using starts with 
the beginning position of the first target statement and ends with 
the beginning position of the last target statement. Branch offsets 
are calculated relative to the end of the branch statement, a position 
we will call the source. With relative jumps, you don't have to take 
into account the absolute position of the end of the branch statement, 
you just need to count the positions between the source source and 
the target. You don't need to know that any added instructions are 
on line 37 (a meaningless concept in rebcode because lines are ignored), 
you only need to tell whether the added instructions are in between 
the source and the target, and then increase the offsets on that 
side of the branch accordingly.


For most branches you will probably be better off with labels and 
let the assembler do the work. But for code snippets, what I often 
do is just do the intiial writing with labels, put the code in a 
rebcode block and let the assembler do the offset calculations. Then 
I copy the fixed up code, remove any label statements and adjust 
affected offsets by two for every removed label statement. Let the 
assembler do most of the work.
(sorry, that could have used a little more proofreading)
Romano
6-Nov-2005
[1203x2]
maybe relative addresses are shorter than absolute ones? absolutes 
need 32/64bit, relatives 8
 rebcode use 32 bit for relative jumps
Brianh: tell me how to adjust the brab block [-10 -5 15 30] knowing 
that the statement "add a 1" has been added at index 37 (you do no 
like "line") in the same block in which brab appears. You do not 
know the absolute position of the brab block.
BrianH
6-Nov-2005
[1205x4]
Is the index 37 position relative to the beginning of the entire 
code block that contains the brab statement, or relative to the statement 
targeted by the -10 offset in your brab offset block? The "affected 
area" of your brab statement is the 40 instructions beginning with 
the one pointed to by the -10 and ending with that pointed to by 
the 30. This is also referred to as a "basic block". When your branches 
are relative, this area is the one that you should be concerned with. 
If you are counting your insertion index relative to the affected 
area then the only offset affected by the insertion would be the 
30, which would need to be changed to 33.


If you are counting your index of 37 as an absolute offset (actually, 
relative to the beginning of the code block that contains the branch 
statement), then you need to subtract the absolute offset of the 
branch statement to convert to the offset scale that matters, that 
relative to the branch statement. Coincidently, that is exactly the 
calculation performed by the label fixup phase of the assembler. 
Because of this I tend to suggest that when you are programming based 
on the whole code block, typical of programming-by-hand, that you 
use label statements and branch to them.


When you use literal offsets you have to consider the range of instructions 
from the branch to the target as being one entity, a "basic block". 
When inserting instructions into a basic block, all you need to consider 
is how it affects that segment of code. These code segments are usually 
developed and tested independently, and then dropped whole into the 
greater stream of code without much change. Programming by stringing 
together a set of these basic blocks (or code snippets) is often 
what code-generating dialect processor (or "compiler") does.
An optimizer does just the opposite: It converts the literal offset 
to a kind of virtual label statement (the difference being that the 
virtual one takes no space in the code); then after code insertions 
or deletes have happened, it changes the offsets to their new values, 
just like rerunning the fixup phase of the assembler. Of course optimizations 
like this can get a little more complicated when you have branch 
targets calculated at runtime - this was probably why they added 
BRAB and removed BRAW in the recent release, replacing general branch 
calculations with a simple lookup table.
As for whether the relative offsets are more efficient than absolute, 
that is only true of actual machine code, and then maybe only on 
older processors without an instruction cache. What we are calling 
an absolute offset here isn't a memory address like it is in machine 
code, it is really just an offset relative to the beginning of the 
code block, rather than the location of the branch statement. I think 
that the reason Carl chose offsets relative to the location of the 
branch statement is that he decided to only implement one branch 
method in the VM, and this method is more friendly to generated code 
(or maybe that was just luck).
Offsets relative to a fixed location are the (currently theoretical) 
"special case" of the BRAB statement. See RAMBO 3953 for details.
Gabriele
8-Nov-2005
[1209x2]
that case is no more theoretical, see new build. however, i don't 
think it has been tested much so far.
so, the first argument of brab can now be either a literal block 
(with labels or integers), or a label. the second arg can only be 
a word referring to an integer.
Rebolek
8-Nov-2005
[1211]
Is there some changelog for 1.3.52 ?
Pekr
8-Nov-2005
[1212]
yes, source, diff :-)
BrianH
8-Nov-2005
[1213]
The great rename is here! Woohoo!
Rebolek
8-Nov-2005
[1214x2]
ah, the dots
so it's good to cheat in surveys...
BrianH
8-Nov-2005
[1216]
I didn't cheat.
Rebolek
8-Nov-2005
[1217]
I don't know who did, but opinions here were different from the survey
BrianH
8-Nov-2005
[1218]
The dots were one of my favorite choices.
Rebolek
8-Nov-2005
[1219]
OK I know it's a dialect, not REBOL, but there is not a single word 
in REBOL that uses dot. Decimals and tupples use them, but not words.
BrianH
8-Nov-2005
[1220x2]
You can use dots in words.
Most don't.
Rebolek
8-Nov-2005
[1222]
I can live with dots but I don't like it, looks really un-REBOLish
BrianH
8-Nov-2005
[1223x3]
Quick to type though, at least compared to - on my keyboard.
So, why hasn't the syntax signiature of brab changed to match the 
new behavior? In theory, we can now specify a literal integer at 
the first position, as that is what the label fixup changes brab 
to in the special case. The syntax check doesn't allow it though, 
because it still looks for word! or block! only.
; BRAB should be like this
brab: ["Branch block table" block! | word! | integer! word!]
Rebolek
8-Nov-2005
[1226]
Hm this is not directly related to ".",  but now I realize I've got 
some 1000 lines of rebcode to rewrite :)
BrianH
8-Nov-2005
[1227]
Search and replace :)
Rebolek
8-Nov-2005
[1228]
:)
Pekr
8-Nov-2005
[1229x2]
Brian - it was not about "qick to type" ;-) If so, we should replace 
path char with dots too ...
I agree with Kru that once again probably the poll was only informative 
and the voice of most - ignored ...
BrianH
8-Nov-2005
[1231x4]
Well, the dot and dash versions were really arbitrary between them. 
We couldn't do paths and the no-change and no-seperator choices had 
significant negatives.
At least the dot being unlikely in normal rebol code makes these 
opcodes more useful in rewrite rules, since you will know what to 
not look for.
I suggested the dash, but the dot is just as good to me.
And anyway, REBOL syntax is designed to be quick to type. That is 
why we use - instead of _ and [ ] instead of { } like other languages.
Pekr
8-Nov-2005
[1235]
but why not -
Rebolek
8-Nov-2005
[1236]
As Cyphre said: because dot looks more like assembler ;)
Pekr
8-Nov-2005
[1237]
never mind, I will probably never write rebcode leve code anyway 
:-)
BrianH
8-Nov-2005
[1238x4]
It is a good visual reminder of the different semantic model, this 
is true...
Well, I don't write View code. We all have our strengths :)
And on that note, where's the Core version of the new build?
Testing: The new brab works. The eq.i opcode still works on logic 
and datatype values as well.
Gregg
8-Nov-2005
[1242x2]
For those with a lot of rebcode already, there will probably be a 
conversion tool to update your scripts available shortly.
I can live with dots but I don't like it, looks really un-REBOLish

 -- That's by design. The opcode names are not human friendly either; 
 also by design. The idea being that rebcode is *not* REBOL, and having 
 it look more like ASM makes you more aware of that. There will probably 
 also be a separate style guide for rebcode at some point.
Gabriele
9-Nov-2005
[1244x2]
Kru: we have a script that does the conversion automatically. Ask 
Ladislav.
(ah, i see Gregg told you already ;)
Rebolek
9-Nov-2005
[1246]
Gabriele: thanks but I've already rewrote most of my code yesterday. 
I don't know your conversion script but I've had different scripts 
using 1.30.50, .51, .52 and even old 1.4 alphas so does your script 
cover all different syntaxes or just the latest one?
Gabriele
9-Nov-2005
[1247]
only   mul -> mul.i, muld -> mul.d and so on. i.e. latest.
Rebolek
9-Nov-2005
[1248]
And rewriting scripts manually was great opportunity to otimize them 
to (and sometimes by factor of two, so it was for good :))