BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
sortlib.c File Reference
#include "blitzlib.h"

Macros

#define FFP_CC_(cc, pivot, elem, ffp)
#define GT_I(p, v, f)
#define LT_I(p, v, f)
#define GT_F(p, v, f)
#define LT_F(p, v, f)
#define GT_S(p, v, f)
#define LT_S(p, v, f)
#define SCAN_UP(T, COND, R, p)
#define SCAN_DOWN(T, COND, R, p)
#define SORT_FN(name, T, GT, LT, R)

Functions

void dosort (ULONG base, const UBYTE *args, const void *ffp)
 Sort Arrayname() - sort the whole array in place.
void dosortup (void)
 SortUp - the following Sort commands sort ascending.
void dosortdown (void)
 SortDown - the following Sort commands sort descending.
static LONG strcmpptr (ULONG pivot, ULONG elem)

Variables

static UWORD sdir

Macro Definition Documentation

◆ FFP_CC_

#define FFP_CC_ ( cc,
pivot,
elem,
ffp )
Value:
({ \
register ULONG _d0 __asm("d0") = (pivot); \
register ULONG _d1 __asm("d1") = (elem); \
register const void *_a6 __asm("a6") = (ffp); \
UBYTE _cc; \
__asm volatile("jsr -42(a6)\n\ts" cc " %0" \
: "=d"(_cc), "+d"(_d0), "+d"(_d1) : "a"(_a6) \
: "a0", "a1", "cc", "memory"); \
_cc; })

◆ GT_F

#define GT_F ( p,
v,
f )
Value:
FFP_CC_("gt", p, v, f)
static struct @342026374002303043102303243063125232020331002053 v
#define FFP_CC_(cc, pivot, elem, ffp)
Definition sortlib.c:102

◆ GT_I

#define GT_I ( p,
v,
f )
Value:
((p) > (v))

◆ GT_S

#define GT_S ( p,
v,
f )
Value:
(strcmpptr(p, v) > 0)
static LONG strcmpptr(ULONG pivot, ULONG elem)
Definition sortlib.c:118

◆ LT_F

#define LT_F ( p,
v,
f )
Value:
FFP_CC_("lt", p, v, f)

◆ LT_I

#define LT_I ( p,
v,
f )
Value:
((p) < (v))

◆ LT_S

#define LT_S ( p,
v,
f )
Value:
(strcmpptr(p, v) < 0)

◆ SCAN_DOWN

#define SCAN_DOWN ( T,
COND,
R,
p )
Value:
do { \
T v_; \
do { \
p--; \
__asm__("" : "+" R(p)); \
v_ = *p; \
} while (COND(pivot, v_, ffp)); \
} while (0)
#define T(maxbp, fetchwid, xmask, xrshift, adjwid, adjstop, fmode, diwstrt, diwstop, ddfstrt, ddfstop, bplcon0)
Definition displaylib.c:377

◆ SCAN_UP

#define SCAN_UP ( T,
COND,
R,
p )
Value:
do { \
T v_; \
do { \
v_ = *p++; \
__asm__("" : "+" R(p)); \
} while (COND(pivot, v_, ffp)); \
} while (0)

◆ SORT_FN

#define SORT_FN ( name,
T,
GT,
LT,
R )

Function Documentation

◆ dosort()

void dosort ( ULONG base,
const UBYTE * args,
const void * ffp )

Sort Arrayname() - sort the whole array in place.

"The Blitz 1 Sort algorithm": a recursive Hoare quicksort, ascending or descending as set by SortUp/SortDown. !args{$38} (array|arrayend| unknown): the compiler passes the base of the array data in d0 and pushes the end address (long) and the element type (word); the routine reads them with MOVE.l -(a2),a1 / MOVE -(a2),d1. Types: 1 byte, 2 word, 5 float (mathffp SPCmp), 7 string (strcomplib $CE02 on the string pointers), everything else (3 long, 4 quick) as signed longs. The original leaves a2 decremented by 6; the compiler does not use a2 afterwards.

Fixed (#275): for word arrays the pivot is read as a word, the middle element (the original read it with MOVE.l and compared with CMP.w: the element after the middle one, for a one element array the word behind the array; reads only, the result was right).

Fixed (#276): string elements that were never assigned (pointer 0) are the empty string (the original read their length from -4(0)).

Parameters
based0: the base (lowest element) of the array data
argsa2: the stack pointer before the pushes: -4 = the end address (long), -6 = the element type (word)
ffpa6: the mathffp base (ffplib), for float arrays

◆ dosortdown()

void dosortdown ( void )

SortDown - the following Sort commands sort descending.

MOVE #-1,sdir.

◆ dosortup()

void dosortup ( void )

SortUp - the following Sort commands sort ascending.

CLR sdir. Also the library's init (BLITZ_NULLSUB_AT): ascending is the default.

◆ strcmpptr()

LONG strcmpptr ( ULONG pivot,
ULONG elem )
static

Variable Documentation

◆ sdir

UWORD sdir
static