View unanswered posts | View active topics It is currently Wed May 01, 2024 8:17 pm



Reply to topic  [ 98 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7
 LALU Computer: Lookup Arithmetic Logic Unit 
Author Message

Joined: Mon Oct 07, 2019 2:41 am
Posts: 596
mmruzek wrote:
I've been spending alot of time reading about BCPL and C Compilers. Not ready to take the leap yet!

Michael

You can have one or the other but not both.
Tiny Pascal is another option, but they always hide the run-time source.
The version I am thinking about had a BASIC program comple the p-code on a 8080
computer.
https://archive.org/details/the-byte-book-of-pascal
other versions
http://www.trs-80.org/tiny-pascal/


Thu Apr 18, 2024 4:05 pm
Profile

Joined: Sun Oct 14, 2018 5:05 pm
Posts: 62
mmruzek wrote:
I ran the Sieve benchmark (previously discussed in this thread) and calculation of prime numbers up to 1000 takes 19 seconds. I'm pretty happy with that, considering I'm at 1MHZ and running a self-written interpreted language. I'm considering increasing the number of keyboard stacks from 16 to 256. I've been spending alot of time reading about BCPL and C Compilers. Not ready to take the leap yet!

Michael


19 seconds isn't bad, but I wonder if you're missing the "trick" of only checking up to the square root of the number of numbers? (31 in this case)

(Although I'm now wondering if you meant generate the first 1000 primes? If I change my code to do that the time does up to 882ms with 10,000 locations in the sieve)

This is my implementation of the old Byte Sieve program in BCPL - it includes an integer square root function and runs in just 84 milliseconds.

Below is the output of the source code, a compile and run on my Ruby 816 board - it's a 16Mhz 65C816 8/16 bit CPU running a bytecode interpreter for the BCPL compiled bytecode (CINTCODE). It runs at maximum of 400K instructions/second and usually much much slower. It's a 32-bit VM and spends a lot of its time overcoming the 64K banks of RAM that the '816 manages.

As for actually writing the compiler - I didn't do that - I just provided the run-time and bytecode interpreter/vm for it all. While I've written many interpreters I've yet to tackle a "proper" compiler for anything - maybe one day!

Still - designing your own CPU and computer from scratch, writing your own language for it is still very impressive. Well done.

-Gordon


Code:
% cat byteSieve.b

// Byte Sieve - Integer version

GET "libhdr.h"
GET "sys.h"

MANIFEST
{
  size = 1000
}

LET start () = VALOF
{
  LET flags = getvec (size/4 + 1)
  LET tStart, tEnd = ?,?
  LET count = 0

  writes ("Starting*n")
  UNLESS flags THEN
  {
    writes ("Out of memory*n")
    RESULTIS 1
  }

  FOR i = 0 TO size DO    // Assume everything is prime to start with
    flags%i := 1

  flags%0 := 0  // 0 and 1 are not prime
  flags%1 := 0

  tStart := sys (Sys_cputime)

  FOR i = 2 TO sqrt (size) DO
  {
    LET k = ?

    IF flags%i = 1 THEN   // It's prime
    {
      LET k = i + i
      WHILE k <= size DO
      {
        flags%k := 0      // ... but all multiples aren't
        k := k + i
      }
    }
  }

  tEnd := sys (Sys_cputime)

  writef ("Time: %d ms*n", tEnd - tStart)

  FOR i = 0 TO size-1 DO
    TEST flags%i THEN
      wrch ('**')
    ELSE
      wrch ('.')
  newline ()

// Count

  FOR i = 0 TO size DO
    IF flags%i = 1 THEN
      count := count + 1

  writef ("  %d  primes found.*n", count)

  freevec (flags)

  RESULTIS 0
}

AND sqrt (s) = VALOF
{
  LET x,y = s/2, (s/x+x)/2
  writef ("sqrt (%n) = ", s)

  {
    x := y
    y := (s/x+x)/2
  } REPEATWHILE x > y
  writef ("%n*n", x)
  RESULTIS x
}

%
% bc byteSieve.b to byteSieve

Ruby BCPL (10 Oct 2014) with simple floating point
Code size =   356 bytes of 32-bit little ender Cintcode
%
% byteSieve
Starting
sqrt (1000) = 31
Time: 84ms

  168 primes found.
%




Thu Apr 18, 2024 6:41 pm
Profile

Joined: Sun Oct 14, 2018 5:05 pm
Posts: 62
oldben wrote:
mmruzek wrote:
I've been spending alot of time reading about BCPL and C Compilers. Not ready to take the leap yet!

Michael

You can have one or the other but not both.


I don't see why not.

e.g. under Linux I have C and BCPL.

if I had the time/energy/learning I could write a C (and Pascal and Basic) compiler in BCPL and have them output the same bytecode the BCPL compiler outputs so they'd all run on my system.

I'd really love to do that, but the closest I think I'll get is to re-write my existing C based BASIC interpreter in BCPL...

-Gordon


Thu Apr 18, 2024 6:46 pm
Profile

Joined: Sun Oct 14, 2018 5:05 pm
Posts: 62


Now that is a book I've not yet seen and it looks to be very well worth the read - thanks.

From the description:

Code:
A collection of 1970s articles in BYTE magazine about or using Pascal for microcomputers.

From the back: "This book not only provides a general introduction to the Pascal language, but is also a tremendous resource for software. There are two versions of a Pascal compiler (one written in Basic, the other in 8080 assembly language), a P-Code interpreter written in both Pascal and 8080 assembly languages, a chess-playing program, and an APL interpreter."


-Gordon


Thu Apr 18, 2024 6:51 pm
Profile
User avatar

Joined: Sun Dec 19, 2021 1:36 pm
Posts: 74
Location: Michigan USA
Quote:
19 seconds isn't bad, but I wonder if you're missing the "trick" of only checking up to the square root of the number of numbers? (31 in this case)


I went from "that can't possibly be right", to "of course it's right" after about 5 minutes of thought! Thank you for pointing that out. Here is the same thing explained over in a mathematics forum...

https://math.stackexchange.com/question ... -out-numbe

Also, here is a link an early description of this benchmark. Courtesy of BigEd, earlier in this thread.

https://archive.org/details/InterfaceAg ... 1/mode/1up


Thu Apr 18, 2024 7:38 pm
Profile WWW

Joined: Mon Oct 07, 2019 2:41 am
Posts: 596
Quote:
don't see why not.
e.g. under Linux I have C and BCPL.
if I had the time/energy/learning I could write a C (and Pascal and Basic) compiler in BCPL and have them output the same bytecode the BCPL compiler outputs so they'd all run on my system.
I'd really love to do that, but the closest I think I'll get is to re-write my existing C based BASIC interpreter in BCPL...


Byte code does work indeed for all, I guess.
I still think of compiling to machine code, with byte or word addressed machines.


Thu Apr 18, 2024 11:15 pm
Profile
User avatar

Joined: Sun Dec 19, 2021 1:36 pm
Posts: 74
Location: Michigan USA
Just a quick update on LALU. By using the suggested code improvement of only going to the square root of N, the time to execute the byte sieve was reduced from 19 seconds to 14 seconds. I also improved the coding in the parser and gained another 2 seconds, so the sieve benchmark is now executing in 12 seconds flat.

I wrapped up all my design files for the SBC version of LALU into a zipfile. Here is a link :

https://www.mtmscientific.com/lalu_sbc.zip

If anyone gets the crazy idea of building one of these let me know, I can likely help with a PCB or whatever. Thanks! Michael


Sun Apr 28, 2024 9:46 pm
Profile WWW

Joined: Mon Oct 07, 2019 2:41 am
Posts: 596
mmruzek wrote:
If anyone gets the crazy idea of building one of these let me know, I can likely help with a PCB or whatever. Thanks! Michael

Only when you get crazy and have 0xA bits per byte.
I have the crazy idea of building something and it works. Good to see you have a working product.
Ben.
The Byte Sive bench mark makes the IBM-PC look good, every thing else is slower .
The code for a long gone FPGA cpu, was about 30 seconds with a slow memory cycle.


Mon Apr 29, 2024 5:38 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 98 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7

Who is online

Users browsing this forum: Bing [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software