word arrays for sorting should be @nosplit

This commit is contained in:
Irmen de Jong 2024-12-29 23:14:25 +01:00
parent 78c71bbf0e
commit c84cc8f8c9
3 changed files with 6 additions and 8 deletions

View File

@ -120,10 +120,9 @@ _done
uword @zp temp = peekw(values+i*$0002)
ubyte @zp j = i
ubyte @zp k = j-gap
repeat {
while j>=gap {
uword @zp v = peekw(values+k*2)
if v <= temp break
if j < gap break
pokew(values+j*2, v)
j = k
k -= gap
@ -144,11 +143,10 @@ _done
cx16.r1 = peekw(pointers+i*$0002)
ubyte @zp j = i
ubyte @zp k = j-gap
repeat {
while j>=gap {
cx16.r0 = peekw(pointers+k*2)
void call(comparefunc)
if_cs break
if j < gap break
pokew(pointers+j*2, cx16.r0)
j = k
k -= gap

View File

@ -833,10 +833,10 @@ sorting (experimental)
----------------------
Various sorting routines (gnome sort and shell sort variants) for byte, word and string arrays.
API is experimental and may change or disappear in a future version.
**NOTE:** all word arrays are assumed to be @nosplit, words and pointers need to be consecutive in memory.
**NOTE:** all word and str arrays have to be @nosplit! Words and pointers need to be consecutive in memory for now.
**NOTE:** sorting is done in ascending order.
Read the `sorting source code <https://github.com/irmen/prog8/tree/master/compiler/res/prog8lib/sorting.p8>`_
to see what's in there.
to see what's in there. Also check out the `sortingbech` example.
sprites (cx16 only)

View File

@ -9,8 +9,8 @@
main {
ubyte[50] array1
ubyte[50] array2
uword[50] warray1
uword[50] warray2
uword[50] @nosplit warray1
uword[50] @nosplit warray2
str[22] @nosplit fruits
str[] @nosplit original_fruits = ["mango", "banana", "cranberry", "zucchini", "blackberry", "orange", "dragonfruit", "cherry",
"kiwifruit", "lychee", "peach", "apricot", "tomato", "avocado", "nectarine", "pear",