Coder Social home page Coder Social logo

howerj / muxleq Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 0.0 68 KB

A two instruction set computer that greatly speeds things up over SUBLEQ

License: The Unlicense

Makefile 0.21% C 0.75% Forth 99.04%
c eforth forth multiplexing mux oisc subleq muxleq

muxleq's Introduction

MUXLEQ

A faster SUBLEQ variant called MUXLEQ. SUBLEQ is a single instruction machine, this is a two instruction machine. By just adding one instruction is becomes possible to speed up the system dramatically whilst also reducing the program size. The machine is not much more complex, and it would still be trivial to implement the system in hardware.

SUBLEQ programs can (usually) run unaltered on the MUXLEQ CPU.

MUXLEQ runs a Forth interpreter, a programming language, as a test program. To run, type:

make run

This requires a C compiler and make to be installed.

The pseudo code for this SUBLEQ variant, MUXLEQ, is:

while pc >= 0:
	a = m[pc + 0]
	b = m[pc + 1]
	c = m[pc + 2]
	pc = pc + 3
	if a == -1:
		m[b] = get_byte()
	else if b == -1:
		put_byte(m[a])
	else if c != -1 and c < 0:
		m[b] = (m[a] & ~m[c]) | (m[b] & m[c])
	else:
		r = m[b] - m[a]
		if r <= 0:
			pc = c
		m[b] = r

Removing the line else if c != -1 and c < 0: along with the clause turns this variant back into a SUBLEQ machine.

Possible variants to pack as much functionality as possible in would include:

  • Bit reversal, the resulting multiplexed value could have its bits reversed. This could be folded into the mux instruction.
  • Right shift, even if only by one place.
  • Comparison, the result of comparing m[a] and m[b] could be stored in m[a], useful comparisons would be is zero?, signed or unsigned less than or greater than. Any of those five would be useful.
  • The paper https://janders.eecg.utoronto.ca/pdfs/esl.pdf "Subleq(?): An Area-Efficient Two-Instruction-Set Computer" extends SUBLEQ in a different way using bit-reversal that should lend itself to a hardware implementation that uses minimal extra resources as the structure of the new instruction is very similar SUBLEQ. If the c operand is negative it computes r = reverse(reverse(m[b]) - reverse(m[a])). This turns the less than or equal to zero branch into a branch on evenness, allowing a quicker right shift to be implemented using minimal resources. reverse reverses all bits in a cell.

This variant greatly speeds up loading, storing and the bitwise operations, even with minimal effort. There are a few features missing from this MUXLEQ variant (such as the "self-interpreter") and as such have been disabled. No doubt if more effort was expended many more performance gains could be made.

The old SUBLEQ only version of the Forth interpreter can be run with:

make old

This is useful for speed tests.

This project could contain alternative SUBLEQ instructions and improvements in the future, altleq might be a better name for the project.

gforth can be used to build the images from either muxleq.fth or subleq.fth, but the Forth systems are self-hosting so you can use them to build the new images if you modify either Forth source file.

References

muxleq's People

Contributors

howerj avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.