Proposed method of LMM for PropBASIC. Comments requested.
Bean
Posts: 8,129
Before everyone gets all fired-up...LMM will not be in PropBASIC until AFTER the inital release. There are too many potential bugs.
But I was cleaning up the compiler code and though I'd better at least get an idea of how I am going to implement it.
So here is my version of LMM.
I have about zero experience with LMM, so I'd like some comments from member who have used it.
I have unrolled the execute loop 4 times, I know I could go further but I want to save as much space as possible for variables.
This code seems to work fine. You can copy and paste the main body of the code many times (past the 496 instruction limit) and it will still work.
Bean
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
Post Edited (Bean) : 2/5/2010 6:21:04 PM GMT
But I was cleaning up the compiler code and though I'd better at least get an idea of how I am going to implement it.
So here is my version of LMM.
I have about zero experience with LMM, so I'd like some comments from member who have used it.
I have unrolled the execute loop 4 times, I know I could go further but I want to save as much space as possible for variables.
This code seems to work fine. You can copy and paste the main body of the code many times (past the 496 instruction limit) and it will still work.
'' *** COMPILED WITH PropBasic VERSION 00.00.79 Feb 3, 2010 *** CON 'DEVICE P8X32A, XTAL1, PLL16X _ClkMode = XTAL1 + PLL16X _XInFreq = 5000000 'FREQ 80_000_000 ' LEDS PIN 23..16 LOW 'LEDS PIN 23..16 LOW ' Delay SUB 1 'Delay SUB 1 PUB __Program 'PROGRAM Start LMM __OFFSET := @__Init CogInit(0, @_LMM_Entry, @__DATASTART) DAT org 0 __Init mov dira,__InitDirA mov outa,__InitOutA jmp #_LMM_JUMP long @Start - @__Init Start 'Start: mov __temp1,#255 ' LEDS = 255 shl __temp1,#16 and __temp1,LEDS andn outa,LEDS or outa,__temp1 mov __param1,#100 ' Delay 100 jmp #_LMM_CALL long @Delay_ret - @__Init long @Delay - @__Init mov __temp1,#0 ' LEDS = 0 shl __temp1,#16 and __temp1,LEDS andn outa,LEDS or outa,__temp1 mov __param1,#100 ' Delay 100 jmp #_LMM_CALL long @Delay_ret - @__Init long @Delay - @__Init jmp #_LMM_JUMP ' GOTO Start long @Start - @__Init mov __temp1,#0 'END waitpne __temp1,__temp1 Delay 'SUB Delay mov __temp1,cnt ' PAUSE __param1 adds __temp1,_1mSec mov __temp2,__param1 mins __temp2,#1 WC __L0001 IF_NC waitcnt __temp1,_1mSec IF_NC djnz __temp2,#_LMM_JUMP long @__L0001 - @__Init rdlong __PC,__PC 'ENDSUB Delay_ret long 0-0 DAT '------------------------------------------------------------------------------------------- 'LMM Execution code ' ------------------------------------------------------------------------------------------- ORG 0 _LMM_Entry mov __PC,__OFFSET _LMM_LOOP rdlong __INSTR1,__PC add __PC,#4 __INSTR1 nop ' Placeholder for LMM instruction rdlong __INSTR2,__PC add __PC,#4 __INSTR2 nop ' Placeholder for LMM instruction rdlong __INSTR3,__PC add __PC,#4 __INSTR3 nop ' Placeholder for LMM instruction rdlong __INSTR4,__PC add __PC,#4 __INSTR4 nop ' Placeholder for LMM instruction jmp #_LMM_LOOP _LMM_JUMP rdlong __PC,__PC add __PC,__OFFSET jmp #_LMM_LOOP _LMM_CALL rdlong __temp1,__PC add __temp1,__OFFSET add __PC,#8 wrlong __PC,__temp1 sub __PC,#4 rdlong __PC,__PC add __PC,__OFFSET jmp #_LMM_LOOP ' Variables for LMM execution code __OFFSET LONG 0-0' Set by spin __PC LONG 0 ' Program counter '********************************************************************** __InitDirA LONG %00000000_11111111_00000000_00000000 __InitOutA LONG %00000000_00000000_00000000_00000000 _1mSec LONG 80000 LEDS LONG 255 << 16 _FREQ LONG 80000000 __remainder __temp1 RES 1 __temp2 RES 1 __temp3 RES 1 __temp4 RES 1 __temp5 RES 1 __param1 RES 1 __param2 RES 1 __param3 RES 1 __param4 RES 1 __paramcnt RES 1 FIT 492 CON LSBFIRST = 0 MSBFIRST = 1 MSBPRE = 0 LSBPRE = 1 MSBPOST = 2 LSBPOST = 3 DAT __DATASTART
Bean
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
Post Edited (Bean) : 2/5/2010 6:21:04 PM GMT
Comments
Using an LMM macro jump vector table will simplify things and allow you to use
the same kernel regardless of where the LMM macros are implemented.
The downside is using longs for the table and slightly delayed execution.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.mikronauts.com E-mail: mikronauts _at_ gmail _dot_ com 5.0" VGA LCD in stock!
Morpheus dual Prop SBC w/ 512KB kit $119.95, Mem+2MB memory/IO kit $89.95, both kits $189.95 SerPlug $9.95
Propteus and Proteus for Propeller prototyping 6.250MHz custom Crystals run Propellers at 100MHz
Las - Large model assembler Largos - upcoming nano operating system
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.mikronauts.com E-mail: mikronauts _at_ gmail _dot_ com 5.0" VGA LCD in stock!
Morpheus dual Prop SBC w/ 512KB kit $119.95, Mem+2MB memory/IO kit $89.95, both kits $189.95 SerPlug $9.95
Propteus and Proteus for Propeller prototyping 6.250MHz custom Crystals run Propellers at 100MHz
Las - Large model assembler Largos - upcoming nano operating system
A few months ago I was pretty chuffed when I compiled a C and a Basic program on the Zicog, and after compilation both returned a "40kb free" message. More than the memory on the propeller. Then RossH goes and blows that out of the water with ten times that. And now PropBasic is heading the same way. I am *very* impressed.
The code looks great. Speed is not a big issue ('tis now as it ever was, use assembly for speed), but the ability to start writing a program and to keep writing and keep writing and never worry about running out of space, well that is just awesome.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
· PropBASIC LMM is not virtual memory. It runs from HUB ram, so programs are still limited to 32K. But that is a far cry from 2K. Also lots of room for variables with LMM.
· Speed is about 1/5 of native code. I think that is a fair trade-off. Code with lots of calls and jumps will suffer most, but will still be·blazing compared to spin.
· You will be able to specify LMM for the main code, and for each TASK. So some tasks can be native (for video drivers and stuff) and some can be LMM within the same program.
· Actually for small TASKs it takes less space to make them native. I think very few TASKs will be LMM, but I wanted to have the option.
· I ran into an issue using VAR arrays. I use MOVS and MOVD to do indexing, well that doesn't work in LMM. So I had to make two more LMM routines to handle it.
· I'm going through the compiler and making the changes to handle LMM. I may post it for some testing, but NOT as the offical beta version.
· Once you get your head around it, LMM isn't that hard. I hope the LMM code generated will provide assistance to PropBASIC users who want to do LMM in assembly.
· Thanks for the encouragement.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
Post Edited (Bean) : 2/6/2010 4:32:32 AM GMT
I'm looking at my code at the moment and thinking maybe it could be ported to propbasic?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.smarthome.viviti.com/propeller
Thats not "awesome" its "Microsoft"
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Style and grace : Nil point
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
during my experiments with PropBasic I have seen, that you can do really very much without LMM and you have got full speed.
So I am very glad to read, that there will be the choice for each task if this task will run in the cog only or with LMM!
Is there a chance to include some sort of debugging feature into the LMM? It should be possible to insert debugging steps between program parts?
Perhaps you could install some sort of a "hook" for a debugger routine,·that can be called after each basic line. This debugger routine could be done later.
The debugger routine might copy a source code line number and all cog variables to hub ram. A debug task might then send the information to a serial line.
The hook could perhaps be used for some sort of polled interrupts too?
I think, that debugging features are often·very valuable, perhaps more valuable then execution speed.
(I would like to have multi line comments too...)
Christof
Just to give you some idea of speed:
PASM instructions without jumps require 20 clocks (on average), 3 instructions require 16 clocks, then the·4th requires 32 clocks.
Jumps require 32 clocks. Calls require 96 clocks.
So code with alot of jumps and calls do take a real performace hit.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Use BASIC on the Propeller with the speed of assembly language.
PropBASIC thread http://forums.parallax.com/showthread.php?p=867134
March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
Post Edited (Bean) : 2/11/2010 7:29:27 PM GMT