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

World: r3wp

[rebcode] Rebcode discussion

BrianH
14-Oct-2005
[339]
:)
Volker
14-Oct-2005
[340]
Bye Jaime.
Pekr
14-Oct-2005
[341]
guys - take your time to do it right :-) We know "the date" is on 
14.November. I can't imagine what the rebcode will be like at that 
time, if we have two releases daily :-)
Ammon
15-Oct-2005
[342]
Pekr, we just can't win with you, can we?  You say speed it up but 
as soon as things speed up you say slow down. ;-)
Pekr
15-Oct-2005
[343]
No, nothing like that - I just said that with current speed of development, 
Microsoft should be scared, as ppl will soon realise .NET is big 
mistake ;-)
Volker
15-Oct-2005
[344x4]
Should ifs pass the true-flag? So that this works like and:
rc-and: rebcode[f1 f2 /r ] [
 sett f1  ift[ sett f2 ]
 gett r  return r   
]
and a syntax-suggestion to make multiple statements in a line more 
readable:
rc-and: rebcode[f1 f2 /r ] [
 :sett f1 :ift[ :sett f2 ]
 :gett r :return r   
]
BrianH
15-Oct-2005
[348]
Volker, the first could be written as
rc-and: rebcode [fi f2] [
    and f1 f2
    return f1
]
Volker
15-Oct-2005
[349x3]
Yes, but its more complex. i need a real shortcut-and.
like in rebol
 if p: find/tail s "x"[ not tail? p]
(artificial example, not my problem)
BrianH
15-Oct-2005
[352]
Translating to assembler style:
rc-and: rebcode [fi f2 /local l1 l2] [
    sett f1
    braf l1
    sett f2
    braf l1
    return true
    label l1
    return false
]
Volker
15-Oct-2005
[353x3]
Yes, that was my other thought.
But i am curious about passing the true-flag back. IS there a reason 
not to do it, or just not addressed now?
btw will /local stay? thats an extra step. in rebol it is no problem, 
but in tuned rebcode its an extra assignment?
BrianH
15-Oct-2005
[356]
Yes, /local will stay, as it is just another refinement and the local 
variables are just other parameters that aren't used. Since the parameter 
passing to a rebcode function is performed by the outer interpreter, 
getting rid of local would mean getting rid of all refinements to 
all functions. BTW, the treatment of /local as a special situation 
is just an artifact of the help function.
Volker
15-Oct-2005
[357]
i know. WHat i mean is, special handling of locals may be faster 
than handling that refinement. But you ae right, it would add complexety 
to the outer interpreter.
BrianH
15-Oct-2005
[358x2]
REBOL local variables are implemented with the USE statement - anything 
in the parameter spec, including /local vars, are just parameters 
you can reuse. For now, rebcode doesn't have anything like the use 
statement.
After checking, you can't pass the truth flag back, as inner rebcode 
blocks are implemented by recursing the interpreter, but you can 
pass variables back so your code can be implemented like this:
rc-and: rebcode[f1 f2 /r ] [
    sett f1 gett r
    ift [sett f2  gett r]
    return r
]
Pekr
15-Oct-2005
[360]
just want to ask - does one instruction here or there cause huge 
slowdown?
BrianH
15-Oct-2005
[361]
Volker, or a better (than the last one) assembler style:
rc-and: rebcode [fi f2 /local r l1] [
    sett f1
    braf l1
    sett f2
    label l1
    gett r
    return r
]
Henrik
15-Oct-2005
[362]
pekr: I tried doing this:

repeat i 100000 [<some rebcode function>]

vs.

<rebcode [] [repeat i 1000000 [rebcode stuff]]>

The pure rebcode example is much, much faster.
BrianH
15-Oct-2005
[363x2]
Pekr, it would depend on the instruction. Like in assembly code on 
real machines, some operations are faster than others. An assign 
or an add would be fast, a mul slower, and a div slower yet.
Adding an instruction in a loop will multiply the slowdown by the 
number of times the loop runs.
Volker
15-Oct-2005
[365]
A nice thing to try would be forall in rebcode. We have apply now.
Pekr
15-Oct-2005
[366x2]
Henrik - I know - but guys here are talking about rebcode only stuff 
- simply what other opcodes to add, to save e.g. 1 single rebcode 
operation. So I am just trying to find out, if even in some longer 
rebcode loop, one operation here or there makes any significant difference? 
Of course I am the last who would not wish rebcode stuff being optimized 
as much as possible :-)
OK, million iterations of loop is million opcodes. How much does 
it take? Just asking, theoretically :-)
Henrik
15-Oct-2005
[368]
well, it's usually very literal? with regular assembler you can count 
the amount of nanoseconds or CPU cycles it takes to do do some operation. 
I don't know if you can do that with rebcode. it gets more and more 
difficult, the higher level you go
BrianH
15-Oct-2005
[369]
That answer would require some testing. In theory it would be

(instructions to execute the function of the opcode) + (instruction 
overhead of executing any opcode) + ((overhead to retrieve a parameter) 
* (number of parameters))
Volker
15-Oct-2005
[370]
Depends how often that instruction runs. In the discussion about 
relative braw for example: Usually that is no problem. But if you 
write an interpreter in rebcode, it would be: braw, do a little bit, 
braw, ... And then the braw could have a huge impact, as the little 
bits may be just "add" or such which are fast. In that case an absolute 
braw may give 10%.
Pekr
15-Oct-2005
[371]
ok, thanks ....
BrianH
15-Oct-2005
[372x2]
Yeah, with braw I wasn't concerned with the 2 opcodes you would have 
to add before any call to braw to make it usable; I was more concerned 
with actually being able to get the address offsets to compute with 
without having to write a compiler (which I am going to do anyways, 
just not right now). That was why I came up with that HERE assembler 
directive.
Still, an absolute braw would take less than half the time that using 
a relative braw takes when you have to compute those offsets.
Pekr
15-Oct-2005
[374x2]
Have you tried to communicate that with Carl?
BrianH - you seem to be skilled in that area. What speedup do you 
think compiling rebcode could achieve? And - how large the compiler 
would be?
BrianH
15-Oct-2005
[376]
Gabriele says he relayed my concerns, but the rewrite of fix-bl hasn't 
been incorporated. Sounds like Carl hasn't agreed.
Pekr
15-Oct-2005
[377]
then there must be some reason :-) let's wait for an explanation. 
IMO Carl is opened to suggestions ...
Rebolek
15-Oct-2005
[378]
rebcode12 added GLT (a < b < c) and GLTE (a <= b <= c). It's nice 
to have intervals, but in practice I use intervals that are open 
from one side and closed from second side or vice versa, i. e. (a 
<=b < c)
BrianH
15-Oct-2005
[379x3]
As for how large the compiler would be, it depends on the source 
language and how ambitious you are. If the language is REBOL-based, 
then at least I don't have to write a lexer. It would depend on what 
kind of optimizations you want to incorporate and how static you 
are willing to make the language dialect that you want to compile. 
Type inferencing would add a lot too, but would have a major benefit 
when translating from a dynamic language like REBOL to a static one 
like rebcode.
Parse would help a lot, obviously.
Carl is open to suggestions when he has time to hear them. He is 
very busy, and niether he nor Gabriele have suggested I contact him 
directly about this.
Pekr
15-Oct-2005
[382]
ah, you talk about separate compiler? I thought you will just JIT 
rebcode?
BrianH
15-Oct-2005
[383]
That's Carl's job. A job which could make rebcode twice as fast to 
be sure :)
Pekr
15-Oct-2005
[384]
where in rebol such stuff as JIT belongs? Would it be just a function 
you would point to a rebcode code?
BrianH
15-Oct-2005
[385x2]
In theory, it would be an implementation feature of the rebcode VM. 
Now that you mention it though, there are a few JITs that can be 
called as a library, such as libjit, LLVM and libtcc. If you took 
the finished rebcode code block you could translate it to one of 
their intermediate languages and have them translate it to native 
code. Sort of like a to-native function.
The apply and do opcodes wouldn't survive the trip though.
Pekr
15-Oct-2005
[387]
hmm, but then you just will have few helper funcs in rebcode to speed 
your code execution here or there. OK, so you produce JIT using some 
external library, but how you link it back to rebol? (maybe wrong 
question not understanding properly how this stuff would work :-)
Volker
15-Oct-2005
[388]
Rebol would have to provide better hooks. To access rebol-values 
directly.