|
BB2 C port
API reference: Blitz libraries in C and the shared code
|
#include "blitzlib.h"Functions | |
| void | domodbyte (void) |
| void | domodword (void) |
| void | domodlong (void) |
| a MOD b for Long (token modlong $D402). | |
| void | domodquick (void) |
| void | domodfloat (void) |
| a MOD b for Float (token modfloat $D404). | |
| static ULONG | mod_w (ULONG acc, ULONG divisor) |
| static ULONG | domodword_c (ULONG a, ULONG b) |
| a MOD b for Word and Byte (tokens modword $D401, modbyte $D400). | |
| BLITZ_ALIAS (domodword, domodword_c) | |
| BLITZ_ALIAS (domodbyte, domodword_c) | |
| static ULONG | domodquick_c (ULONG a, ULONG b) |
| a MOD b for Quick (token modquick $D403). | |
| BLITZ_ALIAS (domodquick, domodquick_c) | |
| BLITZ_ALIAS | ( | domodbyte | , |
| domodword_c | ) |
| BLITZ_ALIAS | ( | domodquick | , |
| domodquick_c | ) |
| BLITZ_ALIAS | ( | domodword | , |
| domodword_c | ) |
| void domodbyte | ( | void | ) |
| void domodfloat | ( | void | ) |
a MOD b for Float (token modfloat $D404).
SPFix(a), SPFix(b) (d0 in, d0 out; the original passes the other operand in d1, mathffp ignores it), then the long code. The result is a Long, not an FFP number - the compiler types it as a Long (blitz2.s:9463 domodf "now a long"), so this is correct (only the fractions are lost, #222). Keeps d2-d7/a2-a6 (mathffp keeps them); d1, a0 and a1 are free.
In assembler, the original's code: in C the two mathffp calls made GCC save d2-d7/a2/a6 (BLITZ_BASEJSR assumes the call may change them), 150 cycles of a routine of about 1300.
| void domodlong | ( | void | ) |
a MOD b for Long (token modlong $D402).
a - (a/b)*b with ldivlib ldivide ($CB01) and lmullib lmultiply ($CA01), plus b if negative (the original's code). Keeps d2-d7 and a0-a6; d1 is changed (the original leaves (a/b)*b in d1).
In assembler for speed (a hot path, every Mod on Long). For a divisor of 1 to $FFFF in magnitude the remainder comes from two DIVU instead of the two calls, with the same result: ldivide's quotient is the exact one of the magnitudes with the sign applied, lmultiply's product is the one modulo 2^32, so a - (a/b)*b is the remainder of the magnitudes with the dividend's sign. A divisor 0 (ldivide's 'infinity; the result is a) or one from $10000 on takes the calls.
| void domodquick | ( | void | ) |
|
static |
a MOD b for Quick (token modquick $D403).
SWAP d0:SWAP d1, then the word code on the integer parts (the fractions of the inputs are ignored). The result is quotient<<16 | remainder, but the compiler types it as a Word (blitz2.s:9459 domodq "now a word"), so only the remainder is used - not a visible bug (#221). Keeps d2-d7/a2-a6 like the word code (the original leaves d1 swapped).
Errors as for Word.
| a | d0: the left operand (Quick). |
| b | d1: the right operand (Quick). |
| void domodword | ( | void | ) |
|
static |
a MOD b for Word and Byte (tokens modword $D401, modbyte $D400).
EXT.l d0:DIVS d1,d0:SWAP d0, a negative remainder gets the divisor added (once). domodbyte is the same code (the byte is sign extended by the compiler; only EXT.l on the word). Keeps d2-d7/a2-a6 (the contract of an operator); d1, a0 and a1 are free.
Errors: b = 0 raises the 68000 divide-by-zero exception (vector 5) like the original; on a DIVS overflow d0 stays unchanged.
| a | d0: the left operand. |
| b | d1: the right operand. |
|
inlinestatic |