LMM AiChip Industries - rosco-pc/propeller-wiki GitHub Wiki

LMM Kernel Specification - AiChip Industries version

AiChip Industries have created a Large Memory Model Virtual Machine implementation ( LmmVm ) which is designed to be usable with the Propeller Tool. Some native Propeller instructions need to be modified for LMM usage but those changes are designed to be achievable by hand rather than requiring any additional tools.

The LmmVm allows to up to 8k longs of code or data and allows access to cog-based registers for fast run-time data storage.

The LmmVm is is a linearly executing LMM engine which takes one instruction at a time, executes it, and moves on to the next. There is no caching, overlays or 'block load and execute' operations supported. The LmmVm is therefore most efficient with sequential rather than looping LMM code, however the overhead of looping will often be tolerable for many LMM programs.

The LmmVm executes most native Propeller Assembler instructions in LMM mode without change ( including conditional execution plus WC, WZ and NR options ) but branches, subroutines and some data access instructions need to be replaced by calls into the LmmVm itself to perform as required. These calls into the LmmVm are followed by parameters which indicate what the call is to achieve and are usually specified by 'long' constant settings. This is less eficient in code space than it could be but allows the calls to be reasonably easily created by hand.

Instructions which need to be replaced by calls into LmmVm are -

jmp call, ret djnz, tjz, tjnz

In addition, the LmmVm provides support for conditional execution of calls into the LmmVm ( Conditional , Skip ) and for operations which would normally be done using self-modifying code with native Propeller instructions ( Get Register Indirect, Store Register Indirect, Execute Register, Case Jump ). The ability to load a register with a 10-bit to 32-bit constant which would normally require the allocation of pre-loaded Cog register is also added ( Load ).

To overcome the need to modify native Propeller 'ret' instructions on subroutine calls, the LmmVm implements a a software stack which can either be held in Cog memory or in Hub memory. Benchmarking shows there is little, if at all any, impact on performance of LmmVm regardless of which is used.

LmmVm is designed to extensible. New LMM instructions can be freely added to the LmmVm as required. The only consequence is that additions will reduce the Cog memory available for LMM program register and stack use. Conversely, LMM support can be reduced where such specific support is not required.

LmmVm can be run standalone, executing programs written entirely as LMM programs, but it may also be used as a sub-component of any other VM which needs to perform tasks where Cog memory limitations mean that not all required code can be held within the Cog memory. The 'Primary VM' will pass control to the LmmVm indicating where the LMM code is to execute, and the LMM program upon completion will jump back to the Primary VM. In this way a Primary VM can have full-speed assembler execution when required and use slower speed LMM execution as necessary. This is convenient when designing any Primary VM as the Cog memory limitations can be ignored during development. Speed critical parts can be brought back to within the Cog memory for native execution as development nears its end. LmmVm evolved from originally being a sub-system in such a Primary VM.

LmmVm allows Primary VM's to be written as LMM code which can execute end-user program code ( bytecode ) which has better code density than that provided for by Propeller Assembler or LMM code. The LMM program interprets the bytecode program, while LmmVm interprets the LMM code. Again, Cog memory limitations can largely be ignored while the Primary VM is being developed ( using LMM code ) although each level of interpretation does result in a lower overall execution speed of the interpreted bytecode.

As well as providing a VM support service for Primary VM's, LmmVm can also be utilised by any Cog program which needs to execute more code than can be held in Cog memory and is a general purpose tool for any Propeller Assembler Programmer.

⚠️ **GitHub.com Fallback** ⚠️