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

World: r3wp

[rebcode] Rebcode discussion

Geomol
7-Jan-2008
[2290x2]
I feel, the main goal for rebcode implentation is speed, so it makes 
sense, that none is the same as zero. It would probably hit performance 
a lot, if you had the usual REBOL datatypes in rebcode.
Maybe it's confusing, that rebcode has NONE at all!?
BrianH
7-Jan-2008
[2292]
Maybe it's confusting that something as basic as NONE? doesn't have 
a corresponding opcode.
Geomol
11-Feb-2008
[2293x2]
Ready for some fun?
Here's a MOS 6502 emulator written in rebcode, I made over the last 
few days:
http://www.fys.ku.dk/~niclasen/rebol/language/em6502.r
GiuseppeC
11-Feb-2008
[2295]
Geomol: you are crazy !
Geomol
11-Feb-2008
[2296x3]
And no, you can't play Elite with it! ;)

I made this to test the speed of rebcode. That's my primary goal 
with this. So there is no Operating System stuff of any kind, so 
no I/O for keyboard, joysticks or screen.
Guiseppe: I know! But shhh, don't tell the others!
It's v. 0.9.0, and I didn't call it v. 1.0.0, because it needs some 
more testing, I think. It's GPL license.
GiuseppeC
11-Feb-2008
[2299]
Well, I am at the command prompt, I did a do http://www.fys.ku.dk/~niclasen/rebol/language/em6502.r
and the prompt is here again. What could I do ?
Geomol
11-Feb-2008
[2300]
It require REBOL/view v. 1.3.50. That's the rebcode version, I used, 
because it's the one, that run on most platforms.
Oldes
11-Feb-2008
[2301]
is there any ram file to test with?
GiuseppeC
11-Feb-2008
[2302]
Nothing ! I want to play Last Ninja 3, how could I do this ? :-)
Geomol
11-Feb-2008
[2303x2]
To make a little test:
do http://www.fys.ku.dk/~niclasen/rebol/language/asm6502.r
do http://www.fys.ku.dk/~niclasen/rebol/language/em6502.r
ram: asm6502 "lda #&01 adc #&02"
em6502 ram 0
Those 4 lines do this: load the assembler, load the emulator, call 
the asssembler with a 6502 asm program returning 64kb ram, and finally 
run the program.
Oldes
11-Feb-2008
[2305]
Why you are using the old and slower rebcode version?
Geomol
11-Feb-2008
[2306x2]
Not much to see, but the program ram. To check things, put e.g. print 
lines in the end of the emulator. Like those 2 already in there commented 
out:
print A
print P

which will print the content of the A register and the P (status) 
register.
Oldes, because that's the one I have under OS X.
Oldes
11-Feb-2008
[2308]
how sad:/
Geomol
11-Feb-2008
[2309x2]
I think, we can convert it to the other version with one of (I think) 
Ladislav's scripts.
Yes, there is a script called convert-rc.r by Ladislav Mecir.
Oldes
11-Feb-2008
[2311]
And what's the result of your test, how fast the rebcode is?
Geomol
11-Feb-2008
[2312x2]
I only did very little test so far. I got around 1.5 MHz. The cpu 
(actually a 6512, it seems buth with 6502 instructions) in the BBC 
was 1MHz.
I plan to do more tests in the coming days. Or maybe some of you 
wanna test too!
GiuseppeC
11-Feb-2008
[2314]
Script Error: rebcode has no value
Geomol
11-Feb-2008
[2315x2]
And this is on a 1.2 GHz G4 powerpc on my iBook.
Guiseppe, make sure you run rebol 1.3.50!
GiuseppeC
11-Feb-2008
[2317]
I am running view 2.7.5
Oldes
11-Feb-2008
[2318]
You must have version with the old rebcode
Henrik
11-Feb-2008
[2319]
only 1.3.50 and one more version has rebcode. not later versions
GiuseppeC
11-Feb-2008
[2320]
Ok, I will try later
Geomol
11-Feb-2008
[2321x4]
This win version should work: http://www.rebol.net/builds/031/rebview1350031.exe
OS X version: http://www.rebol.net/builds/024/rebview1350024.tar.gz

Linux version: http://www.rebol.net/builds/042/rebview1350042.tar.gz
For 6502 asm documentation, I use the "BBC Advanced User Guide" found 
here: http://www.nvg.ntnu.no/bbc/docs.php3
I'll see, if I can make a good ram-file to test with. And maybe a 
little wrapper, so it's possible to monitor, what's going on in the 
emulation.
BrianH
11-Feb-2008
[2325]
Oldes, the older rebcode version wasn't slower, it just had less 
features. We had to change the naming convention of the opcodes to 
add the features.
Geomol
11-Feb-2008
[2326]
Just to clear things out regarding performance. This is an emulation 
of a 1MHz cpu. It requires quite some computing power to emulate 
another cpu. To give a hint: an instruction line INX, which increment 
the X register by 1 requires 2 cycles on the 6502. So you can do 
half a million of those instructions on a 1MHz 6502 each second. 
In my emulator, that INX instruction become 11 rebcode instructions 
plus 6 rebcode instructions to control the loop, a total of 17 rebcode 
instructions. And it takes less than half a second to do 1 million 
of those, which is like a 4MHz 6502. So with this initial test, I'll 
say, rebcode is useable.
btiffin
11-Feb-2008
[2327]
John; still can't get into 6502.org but the site holds quite a bit 
of source code, from snippets to floating point math by Steve Wozniak.
Geomol
12-Feb-2008
[2328x6]
A first version of a MOS 6502 workbench tool is ready:
do http://www.fys.ku.dk/~niclasen/rebol/language/m6502wb.r

It'll load the 6502 assembler and emulator. It's a tool to compile 
6502 assembler programs to machinecode and run it with the rebcode 
emulator. It's possible to see the 6502 registers and flags. Both 
asm6502.r and em6502.r has been updated.
You'll need REBOL 1.3.50 to run this!!!
Scroll the 65kb ram with arrow-keys, page-up/down, home and end.
It works like this:
1) Write some 6502 asm in the text area. Example:
lda #&80

2) Press the button "Assemble". Now you can see the opcodes in the 
ram at address 0000.

3) Press the button "Begin" to run the emulator with the produced 
machine code and see the results in the registers and flags.
Hm, probably a bad idea to use arrows to navigate ram, because it 
makes them not work in the text area.
A performance test program:

lda #0
sta &1001
.l1
lda #0
sta &1002
.l2
lda #0
sta &1003
.l3
lda &1003
adc #1
sta &1003
lda &1003
bne l3
lda &1002
adc #1
sta &1002
lda &1002
bne l2
lda &1001
adc #1
sta &1001
lda &1001
bne l1


It takes 40s to run on a BBC emulator emulating a 1MHz 6502. It took 
around 14s using the rebcode emulator on my 1.2 GHz G4, and it took 
9.5s using the rebcode emulator on my 2.4GHz Pentium 4.
Geomol
13-Feb-2008
[2334x3]
A similar rebcode performance test program might look like:

ram: make binary! 3
insert/dup ram #"^(00)" 3
looptest: rebcode [/local a] [
	set a 0
	pokez ram 0 a
	label l1
	set a 0
	pokez ram 1 a
	label l2
	set a 0
	pokez ram 2 a
	label l3
	pickz a ram 2
	add a 1
	pokez ram 2 a
	eq a 256
	braf l3
	pickz a ram 1
	add a 1
	pokez ram 1 a
	eq a 256
	braf l2
	pickz a ram 0
	add a 1
	pokez ram 0 a
	eq a 256
	braf l1
]


It does 16'777'216 loops and takes less than 3 seconds on my 1.2 
GHz G4.
To sum it up:
A 1MHz 6502 takes 40 sec to do 16'777'216 loops of this kind.

Emulating the 6502 using rebcode can do the same thing in 14 sec 
(on a 1.2 GHz G4) and in 9.5 sec (on a 2.4 GHz P4).

A pure rebcode program (no emulation) can do the 'same' 16'777'216 
loops in around 2.7 sec on a 1.2 GHz G4.


So a conclusion might be, that programming in rebcode is like having 
a 40 / 2.7 = 15 MHz cpu (if run on a 1.2 GHz G4). Is this a correct 
conclusion?
Is it known how many cpu clocks, each rebcode instruction use in 
average?
Henrik
13-Feb-2008
[2337]
sounds pretty slow?
Geomol
13-Feb-2008
[2338x2]
I'm not sure.
This is just one single test using only a few of the available instructions. 
To have a better view, more tests are needed. I made a similar loop 
in C, compiled it with gcc, and it runs around 6 times faster than 
the pure rebcode version. Initially I won't call rebcode slow, but 
not blasting fast either.