|
BB2 C port
API reference: Blitz libraries in C and the shared code
|
#include "blitzlib.h"Functions | |
| void | strcomp (void) |
| $CE00 (strcomp) - compare the two strings at the end of the string work area (the string operators = <> < <= > >=). | |
| void | casestrcomp (void) |
| void | strcomp2 (void) |
| static LONG | compare (const UBYTE *a, ULONG alen, const UBYTE *b, ULONG blen) |
| static LONG | strcomp2_c (const UBYTE *a, ULONG alen, const UBYTE *b, ULONG blen) |
| $CE02 (strcomp2) - compare two strings given by address and length. | |
| static LONG | casestrcomp_c (const UBYTE *cs, ULONG cslen, const UBYTE *sel) |
| $CE01 (casestrcomp) - compare a CASE string with the SELECT string. | |
| void casestrcomp | ( | void | ) |
|
static |
$CE01 (casestrcomp) - compare a CASE string with the SELECT string.
MOVE.l d0,a0:MOVE.l 4(a7),d0:MOVE.l 8(a7),a1:MOVE.l -4(a1),d1: MOVE.l (a7)+,(a7) then strcomp2. The CASE string's length at 4(a7) is removed by the routine; the SELECT string at 8(a7) stays on the stack for the next CASE. The thunk loads d1/a1 from the stack.
| cs | d0: the CASE string |
| cslen | d1: its length (from 4(a7)) |
| sel | a1: the SELECT string (from 8(a7)), its length at -4 |
|
static |
| void strcomp | ( | void | ) |
$CE00 (strcomp) - compare the two strings at the end of the string work area (the string operators = <> < <= > >=).
The right string is just below a3, the left string below it; their lengths are on the stack (8(a7) left, 4(a7) right) and removed by the routine. a3 = the start of the left string afterwards. The result is only in the CCR, as MOVEQ of -1/0/1 sets it (left <, =, > right; V = C = 0). Keeps d0-d7/a2/a4-a6: the compiler saves nothing around it, with d0..d(regat-1) live (perf-analysis thunks.md 1.4); a0 and a1 are free (the original changes them too). No third-party library calls it.
An assembler entry: C cannot keep d0/d1, and the thunk around the C function cost about 100 cycles (bstr.strcmp 3336 against the original's 2944). For lengths below 2^31 (every string) the loop is CMPM.b/DBNE over the shorter length, then the lengths decide; that is the original's result, whose loop counts both lengths down (SUBQ.l/BMI), at 22 instead of 54 cycles per character. A length from 2^31 on takes the original's loop, with its results for such lengths.
| void strcomp2 | ( | void | ) |
|
static |
$CE02 (strcomp2) - compare two strings given by address and length.
Bytes compare unsigned; the shorter string is less when it is a prefix. The result is also in the CCR (TST.l d0 in the thunk). d1/a0/a1 are kept: the original leaves them unchanged when a string is empty (its loop stops before CMPM / SUBQ d1).
| a | a0: the left string |
| alen | d0: its length |
| b | a1: the right string |
| blen | d1: its length |