Add LUT
This commit is contained in:
parent
ec2b562610
commit
e4d45e470c
143
bsrt.uc
143
bsrt.uc
@ -1,29 +1,81 @@
|
|||||||
#define LIST_START 0xE0
|
#define LIST_START 0xE0
|
||||||
#define HASH_MASK 0b1111000
|
#define HASH_MASK 0b1111
|
||||||
|
|
||||||
// PM initial state
|
// PM initial state
|
||||||
#data 0x00 0x00
|
#data 0x00 0x10
|
||||||
#data 0x08 0x08
|
#data 0x01 0x1c
|
||||||
#data 0x10 0x10
|
#data 0x02 0x28
|
||||||
#data 0x18 0x18
|
#data 0x03 0x34
|
||||||
#data 0x20 0x20
|
#data 0x04 0x40
|
||||||
#data 0x28 0x28
|
#data 0x05 0x4c
|
||||||
#data 0x30 0x30
|
#data 0x06 0x58
|
||||||
#data 0x38 0x38
|
#data 0x07 0x64
|
||||||
#data 0x40 0x40
|
#data 0x08 0x70
|
||||||
#data 0x48 0x48
|
#data 0x09 0x7c
|
||||||
#data 0x50 0x50
|
#data 0x0a 0x88
|
||||||
#data 0x58 0x58
|
#data 0x0b 0x94
|
||||||
#data 0x60 0x60
|
#data 0x0c 0xa0
|
||||||
#data 0x68 0x68
|
#data 0x0d 0xac
|
||||||
#data 0x70 0x70
|
#data 0x0e 0xb8
|
||||||
#data 0x78 0x78
|
#data 0x0f 0xc4
|
||||||
|
|
||||||
|
#data 0x10 0x10
|
||||||
|
#data 0x1c 0x1c
|
||||||
|
#data 0x28 0x28
|
||||||
|
#data 0x34 0x34
|
||||||
|
#data 0x40 0x40
|
||||||
|
#data 0x4c 0x4c
|
||||||
|
#data 0x58 0x58
|
||||||
|
#data 0x64 0x64
|
||||||
|
#data 0x70 0x70
|
||||||
|
#data 0x7c 0x7c
|
||||||
|
#data 0x88 0x88
|
||||||
|
#data 0x94 0x94
|
||||||
|
#data 0xa0 0xa0
|
||||||
|
#data 0xac 0xac
|
||||||
|
#data 0xb8 0xb8
|
||||||
|
#data 0xc4 0xc4
|
||||||
|
|
||||||
|
// TODO: Include register initial-state compiler directive (saves, like, 2 cycles max)
|
||||||
// Set PC to LIST_START
|
// Set PC to LIST_START
|
||||||
const LIST_START
|
const LIST_START
|
||||||
mov ar pc
|
mov ar pc
|
||||||
|
|
||||||
|
bra @BUCKET_SORT_START
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// //// ---- START OF DANK BUCKET SORT ---- ////
|
||||||
|
// $DANK_SORT_START
|
||||||
|
//
|
||||||
|
// // Get value at index of PC and index of PC + 1
|
||||||
|
// // (ar = gr0 = data[pc]; hr = gr3 = data[pc + 1])
|
||||||
|
// mov pc asr
|
||||||
|
// mov pm ar; mov pm gr; incpc
|
||||||
|
// mov pc asr
|
||||||
|
// mov pm hr
|
||||||
|
// reset ir
|
||||||
|
// mov pm gr
|
||||||
|
//
|
||||||
|
// bsl
|
||||||
|
// bsl
|
||||||
|
// bsl
|
||||||
|
// bsl
|
||||||
|
// bsl
|
||||||
|
// bsl
|
||||||
|
// bsl
|
||||||
|
// and HASH_MASK
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//// ---- START OF NORMAL (TRASH) BUCKET SORT ---- ////
|
||||||
// Start of bucket sort loop
|
// Start of bucket sort loop
|
||||||
$BUCKET_SORT_START
|
$BUCKET_SORT_START
|
||||||
|
|
||||||
@ -37,48 +89,34 @@ mov pm ar; mov pm gr
|
|||||||
rol
|
rol
|
||||||
rol
|
rol
|
||||||
rol
|
rol
|
||||||
rol
|
rol; mov pc ir
|
||||||
rol
|
|
||||||
rol
|
|
||||||
rol
|
|
||||||
and HASH_MASK
|
and HASH_MASK
|
||||||
mov ar hr
|
mov ar asr
|
||||||
|
mov pm hr
|
||||||
// Dereference AR (HR) into AR (ar = buckets[ar])
|
mov pm asr
|
||||||
mov hr asr
|
|
||||||
mov pm ar
|
|
||||||
|
|
||||||
// Increment element end-index stored in program memory
|
|
||||||
add 1
|
|
||||||
mov ar pm
|
|
||||||
|
|
||||||
// Push PC
|
|
||||||
mov pc ir
|
|
||||||
|
|
||||||
|
mov pm pc; mov pm ar
|
||||||
|
incpc; sub hr
|
||||||
|
mov pc pm
|
||||||
|
|
||||||
// Prepare for insertion sort here:
|
// Prepare for insertion sort here:
|
||||||
|
|
||||||
// Compute length of bucket into LC
|
// Compute length of bucket into LC
|
||||||
sub hr
|
|
||||||
mov ar lc
|
mov ar lc
|
||||||
|
|
||||||
// Save start index to PC (for fast dereferencing)
|
// Save start index to PC (for fast dereferencing)
|
||||||
mov hr pc; declc
|
mov hr pc
|
||||||
|
|
||||||
// Start of nested insertion sort
|
// Start of nested insertion sort
|
||||||
$INSERTION_SORT_LOOP_START
|
$INSERTION_SORT_LOOP_START
|
||||||
|
|
||||||
// If LC is set, we've reached the end of the elements
|
// If LC is set, we've reached the end of the elements
|
||||||
bls @INSERTION_SORT_END_BIGGEST
|
bls @INSERTION_SORT_END_BIGGEST; incpc
|
||||||
|
|
||||||
// Increment check index
|
|
||||||
incpc
|
|
||||||
|
|
||||||
// If(data[pc] < gr) continue;
|
// If(data[pc] < gr) continue;
|
||||||
mov pc asr
|
mov pc asr
|
||||||
mov pm hr; mov pm ar
|
mov pm ar
|
||||||
sub gr
|
sub gr
|
||||||
brn @INSERTION_SORT_LOOP_BOTTOM
|
adn gr; brn @INSERTION_SORT_LOOP_BOTTOM
|
||||||
|
|
||||||
// Insert and shift here
|
// Insert and shift here
|
||||||
mov gr pm
|
mov gr pm
|
||||||
@ -89,8 +127,8 @@ bls @INSERTION_SORT_END_NOT_BIGGEST
|
|||||||
incpc
|
incpc
|
||||||
mov pc asr
|
mov pc asr
|
||||||
mov pm gr
|
mov pm gr
|
||||||
mov hr pm
|
mov ar pm
|
||||||
mov gr hr; declc
|
mov gr ar; declc
|
||||||
bra @INSERTION_SHIFT_LOOP
|
bra @INSERTION_SHIFT_LOOP
|
||||||
|
|
||||||
|
|
||||||
@ -100,7 +138,6 @@ declc; bra @INSERTION_SORT_LOOP_START
|
|||||||
|
|
||||||
// Jump here if gr wasn't inserted into list
|
// Jump here if gr wasn't inserted into list
|
||||||
$INSERTION_SORT_END_BIGGEST
|
$INSERTION_SORT_END_BIGGEST
|
||||||
incpc
|
|
||||||
mov pc asr
|
mov pc asr
|
||||||
mov gr pm
|
mov gr pm
|
||||||
|
|
||||||
@ -120,8 +157,6 @@ $BUCKET_SORT_END
|
|||||||
// PC is 0 here. Data is sorted smallest-to largest in memory: just spread out into buckets ;)
|
// PC is 0 here. Data is sorted smallest-to largest in memory: just spread out into buckets ;)
|
||||||
// Perform final merge here
|
// Perform final merge here
|
||||||
|
|
||||||
call @BREAK
|
|
||||||
|
|
||||||
// Set PC to write index
|
// Set PC to write index
|
||||||
const 0xE0
|
const 0xE0
|
||||||
mov ar pc
|
mov ar pc
|
||||||
@ -132,7 +167,7 @@ mov ar pc
|
|||||||
// COPY NEGATIVE
|
// COPY NEGATIVE
|
||||||
|
|
||||||
// Initialize GR as bucket pointer and IR as element pointer
|
// Initialize GR as bucket pointer and IR as element pointer
|
||||||
const 0x78
|
const 0xC4
|
||||||
mov ar gr
|
mov ar gr
|
||||||
|
|
||||||
$LOOP_NEGATIVE
|
$LOOP_NEGATIVE
|
||||||
@ -161,14 +196,14 @@ bra @COPY_BUCKET_NEGATIVE
|
|||||||
$NEXT_BUCKET_NEGATIVE
|
$NEXT_BUCKET_NEGATIVE
|
||||||
|
|
||||||
mov gr ar
|
mov gr ar
|
||||||
sub 0x08 // AR is one above the length, so sub 8.
|
sub 0x0C // AR is one above the length, so sub 8.
|
||||||
mov ar gr
|
mov ar gr
|
||||||
sub 0x38
|
sub 0x7C
|
||||||
bnz @LOOP_NEGATIVE
|
bnz @LOOP_NEGATIVE
|
||||||
|
|
||||||
|
|
||||||
// COPY POSITIVE
|
// COPY POSITIVE
|
||||||
const 0x00
|
const 0x10
|
||||||
mov ar gr
|
mov ar gr
|
||||||
|
|
||||||
$LOOP_POSITIVE
|
$LOOP_POSITIVE
|
||||||
@ -202,12 +237,10 @@ bra @COPY_BUCKET_POSITIVE
|
|||||||
$NEXT_BUCKET_POSITIVE
|
$NEXT_BUCKET_POSITIVE
|
||||||
|
|
||||||
mov gr ar
|
mov gr ar
|
||||||
add 0x08 // AR is one above the length, so sub 8.
|
add 0x0C // AR is one above the length, so sub 8.
|
||||||
mov ar gr
|
mov ar gr
|
||||||
sub 0x40
|
sub 0x88
|
||||||
bnz @LOOP_POSITIVE
|
bnz @LOOP_POSITIVE
|
||||||
|
|
||||||
call @BREAK
|
|
||||||
|
|
||||||
$BREAK
|
$BREAK
|
||||||
halt
|
halt
|
||||||
|
Loading…
x
Reference in New Issue
Block a user