Programs: Added initial draft of quicksort porgram that is currently broken and two other benchmarks

This commit is contained in:
(Tim) Efthimis Kritikos 2024-05-05 11:45:38 +01:00
parent 8e2eed0130
commit d6ff86499e
4 changed files with 518 additions and 14 deletions

View File

@ -5,7 +5,7 @@ USE_AALIB=1
OBJECT_FILES=gui.o gui_display.o gui_internals.o main.o simdata.o assembly.o cpu.o
MAIN_ROM=programs/utah_teapot.rom
ROMS=test.rom ${MAIN_ROM} programs/cube.rom programs/quicksort.rom
ROMS=test.rom ${MAIN_ROM} programs/cube.rom programs/quicksort.rom programs/max_performance.rom programs/cube_benchmark.rom
UTAH_TEAPOT_ASCII_STL=assets/Utah_teapot_ascii.stl
AXIL_PROGS=auxiliary_progs/stl_to_source_code

278
programs/cube_benchmark.asm Normal file
View File

@ -0,0 +1,278 @@
MOV $0xFF0000,%SP
#Set up vector mode
MOV $0xFFFC,%R4l
MOV $0x00FF,%R4h
MOV $0xFFFF,%R1l
MOV $0xFFFF,%R1h
MOV %R1,(%R4)
MOV $0x0008,%R7l
MOV $0x0000,%R7h #The number of rotate,render itrations
:MAIN_LOOP
PUSH %R7
CALL $RENDER
CALL $SPIN
POP %R7
DEC %R7
JMP,NZ $MAIN_LOOP
HALT
:SPIN
MOV $0x0008,%R2l
MOV $0x0000,%R2h #Constant 8
MOV $0x0004,%R5l
MOV $0x0000,%R5h #Constant 4
MOV $>DATA_START,%R0l
MOV $<DATA_START,%R0h
MOV (%R0),%R7
ADD %R5,%R0 #Load the number of lines
SL %R7 # x2 to get the number of points
MOV $0x3ccc,%R6h
MOV $0xcccd,%R6l #The angle to rotate by
:SPIN_LOOP
#Read in a point R1:x R3:z
MOV (%R0),%R1
ADD %R2,%R0
MOV (%R0),%R3
MOV %R6,%R4
COS %R4
PUSH %R1
FMUL %R4, %R1
MOV %R6,%R4
SIN %R4
FMUL %R3,%R4
FADD %R4,%R1
SUB %R2,%R0
MOV %R1,(%R0)
ADD %R2,%R0
MOV %R6,%R4
SIN %R4
POP %R1
FMUL %R4,%R1
MOV %R6,%R4
COS %R4
FMUL %R4,%R3
FSUB %R1,%R3
MOV %R3,(%R0)
ADD %R5,%R0
DEC %R7
JMP,NZ $SPIN_LOOP
:RENDER
MOV $>DATA_START,%R0l
MOV $<DATA_START,%R0h
MOV $0x000D,%R7l
MOV $0x0000,%R7h
MOV $0x0004,%R5l
MOV $0x0000,%R5h
MOV $0xFFFC,%R4l
MOV $0x00FF,%R4h
MOV $0x0002,%R1l
MOV $0x0000,%R1h #Clear the frame
MOV %R1,(%R4)
MOV (%R0),%R7
ADD %R5,%R0
MOV $0xFFFC,%R4l
MOV $0x00FF,%R4h
MOV $0x3f80,%R6h
MOV $0x0000,%R6l
:RENDER_LOOP
MOV $0xFFFF,%R1l
MOV $0xFFFF,%R1h
MOV %R1,(%R4)
#Read in a point R1:x R2:y R3:z
MOV (%R0),%R1
ADD %R5,%R0
MOV (%R0),%R2
ADD %R5,%R0
MOV (%R0),%R3
ADD %R5,%R0
FSUB %R6,%R1
FSUB %R6,%R2
FADD %R6,%R3
FADD %R6,%R3
FADD %R6,%R1
FADD %R6,%R2
FDIV %R3,%R1
FDIV %R3,%R2
MOV %R1,(%R4)
MOV %R2,(%R4)
MOV (%R0),%R1
ADD %R5,%R0
MOV (%R0),%R2
ADD %R5,%R0
MOV (%R0),%R3
ADD %R5,%R0
FSUB %R6,%R1
FSUB %R6,%R2
FADD %R6,%R3
FADD %R6,%R3
FADD %R6,%R1
FADD %R6,%R2
FDIV %R3,%R1
FDIV %R3,%R2
MOV %R1,(%R4)
MOV %R2,(%R4)
DEC %R7
JMP,NZ $RENDER_LOOP
MOV $0x0003,%R1l
MOV $0x0000,%R1h #Display the frame
MOV %R1,(%R4)
RET
:DATA_START
# 12 lines
DDW $0x0000000C
#0,0,0
DDW $0xbf800000
DDW $0xbf800000
DDW $0xbf800000
#0,0,1
DDW $0xbf800000
DDW $0xbf800000
DDW $0x3f800000
#0,0,0
DDW $0xbf800000
DDW $0xbf800000
DDW $0xbf800000
#1,0,0
DDW $0x3f800000
DDW $0xbf800000
DDW $0xbf800000
#0,0,0
DDW $0xbf800000
DDW $0xbf800000
DDW $0xbf800000
#0,1,0
DDW $0xbf800000
DDW $0x3f800000
DDW $0xbf800000
#1,1,1
DDW $0x3f800000
DDW $0x3f800000
DDW $0x3f800000
#1,1,0
DDW $0x3f800000
DDW $0x3f800000
DDW $0xbf800000
#1,1,1
DDW $0x3f800000
DDW $0x3f800000
DDW $0x3f800000
#1,0,1
DDW $0x3f800000
DDW $0xbf800000
DDW $0x3f800000
#1,1,1
DDW $0x3f800000
DDW $0x3f800000
DDW $0x3f800000
#0,1,1
DDW $0xbf800000
DDW $0x3f800000
DDW $0x3f800000
#0,1,1
DDW $0xbf800000
DDW $0x3f800000
DDW $0x3f800000
#0,1,0
DDW $0xbf800000
DDW $0x3f800000
DDW $0xbf800000
#0,1,1
DDW $0xbf800000
DDW $0x3f800000
DDW $0x3f800000
#0,0,1
DDW $0xbf800000
DDW $0xbf800000
DDW $0x3f800000
#0,1,0
DDW $0xbf800000
DDW $0x3f800000
DDW $0xbf800000
#1,1,0
DDW $0x3f800000
DDW $0x3f800000
DDW $0xbf800000
#0,0,1
DDW $0xbf800000
DDW $0xbf800000
DDW $0x3f800000
#1,0,1
DDW $0x3f800000
DDW $0xbf800000
DDW $0x3f800000
#1,0,0
DDW $0x3f800000
DDW $0xbf800000
DDW $0xbf800000
#1,1,0
DDW $0x3f800000
DDW $0x3f800000
DDW $0xbf800000
#1,0,0
DDW $0x3f800000
DDW $0xbf800000
DDW $0xbf800000
#1,0,1
DDW $0x3f800000
DDW $0xbf800000
DDW $0x3f800000

View File

@ -0,0 +1,68 @@
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
MOV %R0,%R3
HALT

View File

@ -1,12 +1,14 @@
MOV $0xFF0000,%SP
MOV $0x0000,%R0h
MOV $DATA,%R0l
MOV $0x0000,%R0l
PUSH %R0
MOV $DATA_END,%R0l
MOV $0x0005,%R0l
PUSH %R0
CALL $QUICKSORT
HALT
#Doing Quicksort from DATA+%R3 to DATA+%R2
:QUICKSORT
#Get parameters from stack
MOV %SP,%R0
@ -18,25 +20,181 @@ MOV (%R0),%R2
SUB %R1,%R0
MOV (%R0),%R3
#Compare input and quit if start >= end
CMP %R2,%R3
JMP,NS $BAIL
ADD %R2,%R3
#Get pivot to %R5
MOV $<DATA,%R7h
MOV $>DATA,%R7l
MOV %R3,%R6
SL %R6
SL %R6
ADD %R7,%R6
MOV (%R6),%R5
#Set %R0 and %R1
MOV %R3,%R0
DEC %R0
MOV %R3,%R1
#MAIN LOOP
:MAIN_LOOP
#Get current data being pointed to %R4
MOV %R1,%R6
SL %R6
SL %R6
ADD %R7,%R6
MOV (%R6),%R4
#Check if we swap
CMP %R5,%R4
JMP,NS $COND_EXIT
INC %R0
PUSH %R2
#Do swap
MOV %R1,%R6
SL %R6
SL %R6
ADD %R7,%R6
MOV (%R6),%R2
MOV %R0,%R6
SL %R6
SL %R6
ADD %R7,%R6
MOV (%R6),%R4
MOV %R2,(%R6)
MOV %R1,%R6
SL %R6
SL %R6
ADD %R7,%R6
MOV %R4,(%R6)
POP %R2
:COND_EXIT
INC %R1
CMP %R2,%R1
JMP,NZ $MAIN_LOOP
INC %R0
#Do swap
PUSH %R2
MOV %R2,%R6
SL %R6
SL %R6
ADD %R7,%R6
MOV (%R6),%R2
MOV %R0,%R6
SL %R6
SL %R6
ADD %R7,%R6
MOV (%R6),%R4
MOV %R2,(%R6)
MOV %R0,%R6
SL %R6
SL %R6
ADD %R7,%R6
MOV %R4,(%R6)
POP %R2
DEC %R0
#SAVE REGISTERS
PUSH %R0
PUSH %R1
PUSH %R2
PUSH %R3
PUSH %R4
#PASS PARAMETERS
PUSH %R2
PUSH %R0
CALL $QUICKSORT
#SKIP PARAMETERS
POP %R4
POP %R4
#RESTORE REGISTERS
POP %R4
POP %R3
POP %R2
POP %R1
POP %R0
#SAVE REGISTERS
PUSH %R0
PUSH %R1
PUSH %R2
PUSH %R3
PUSH %R4
#PASS PARAMETERS
INC %R0
INC %R0
PUSH %R0
PUSH %R3
CALL $QUICKSORT
#SKIP PARAMETERS
POP %R4
POP %R4
#RESTORE REGISTERS
POP %R4
POP %R3
POP %R2
POP %R1
POP %R0
:BAIL
RET
:DATA
DDW $0x00000000
DDW $0x00000004
DDW $0x00000010
DDW $0x00000007
DDW $0x00000008
DDW $0x00000009
DDW $0x00000031
DDW $0x000000BB
DDW $0x0000000e
DDW $0x00000002
DDW $0x000000BB
DDW $0x01000000
:DATA_END
DDW $0xFFFFFFFF
DDW $0x00000001
DDW $0x00000005
#DDW $0x00000006
#DDW $0x00000007
#DDW $0x00000008
#DDW $0x00000009
#DDW $0x0000000a
#DDW $0x0000000b
#DDW $0x0000000c
#DDW $0x0000000d
#DDW $0x0000000e
#DDW $0x00000010
#DDW $0xfe4cb7ad
#DDW $0xb925a7a6
#DDW $0xce117350
#DDW $0xd587026a
#DDW $0xc341474a
#DDW $0x709182e0
#DDW $0x3b3d9cb8
#DDW $0x9b36108d
#DDW $0x069a847f
#DDW $0x0137e24c
#DDW $0xe848d5dc
#DDW $0xf98a1bc4
#DDW $0xe019a8e4
#DDW $0xd42640c3
#DDW $0x9dba659a
#DDW $0xdd94f7b9