From fd6a44296210867dbc4b9d2cc60e3b1262d605bd Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Wed, 24 Apr 2019 13:26:19 +0200 Subject: [PATCH] Implement bucket-sort without inline insertion sort --- sort3.uc | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 sort3.uc diff --git a/sort3.uc b/sort3.uc new file mode 100644 index 0000000..6181f8b --- /dev/null +++ b/sort3.uc @@ -0,0 +1,73 @@ +#define LIST_START 0xE0 +#define HASH_MASK 0b1111 +#define FIRST_BUCKET 0x10 // Index of start of first bucket +#define LAST_BUCKET 0xD3 // Index of start of last bucket +#define BUCKET_SIZE 13 // Each bucket an hold 13 elements before spilling + + +#data 0x00 0x77 +#data 0x01 0x84 +#data 0x02 0x91 +#data 0x03 0x9e +#data 0x04 0xab +#data 0x05 0xb8 +#data 0x06 0xc5 +#data 0x07 0xd2 +#data 0x08 0x0f +#data 0x09 0x1c +#data 0x0a 0x29 +#data 0x0b 0x36 +#data 0x0c 0x43 +#data 0x0d 0x50 +#data 0x0e 0x5d +#data 0x0f 0x6a + +const LIST_START +mov ar pc +reset ir // Point PC to start of list. Let MUX activate GR3 + +// Two values sorted per iteration, so half the iterations obv ;) +lcset 16 + +$BUCKET_SORT +declc; bls @MERGE_INIT + +mov pc asr; incpc +mov pm ar; mov pm ir // Use whatever value we're sorting to index GR at complete random :))))))) +mov pc asr; incpc; incpc +mov pm hr + +// Shift AR and HR +brl; mov pm gr +brl +brl +brl +and HASH_MASK // Completely hash value from HR +mov ar asr +mov pm ar +add 1 +mov ar pm +mov ar asr +mov gr pm + +mov hr ar +and HASH_MASK // Completely hash value from AR +mov ar asr +mov pm ar +add 1 +mov ar pm +mov ar asr +mov ir pm + +bra @BUCKET_SORT + + + + +$MERGE_INIT + + +$END + +$BREAK +halt