Skip to content

Commit

Permalink
word arrays for sorting should be @NoSplit
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Dec 29, 2024
1 parent 78c71bb commit c84cc8f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
6 changes: 2 additions & 4 deletions compiler/res/prog8lib/sorting.p8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/source/libraries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions examples/cx16/sortingbench.p8
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c84cc8f

Please sign in to comment.