From 9ec2bc913cd57f6f09f79cd673b0327d9cc2fcbf Mon Sep 17 00:00:00 2001 From: Javier Date: Sun, 11 Oct 2026 00:45:13 +0200 Subject: small utils.h comment fixes --- utils.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/utils.h b/utils.h index e1258c9..7d9a15b 100644 --- a/utils.h +++ b/utils.h @@ -54,7 +54,7 @@ static inline uint32_t linear_addr(const void __far * ptr) /** Map x linearly from range [0, srcmax] to [0, dstmax]. * Equivalent of (x * dstmax) / srcmax but with 32-bit unsigned precision. */ -static unsigned scaleu(unsigned x, unsigned srcmax, unsigned dstmax); +static uint16_t scaleu(uint16_t x, uint16_t srcmax, uint16_t dstmax); #pragma aux scaleu = \ "mul cx" /* dx:ax = x * dstmax */\ "div bx" /* ax = dx:ax / srcmax */\ @@ -62,19 +62,19 @@ static unsigned scaleu(unsigned x, unsigned srcmax, unsigned dstmax); __value [ax] \ __modify exact [ax dx] -/** Map x linearly from range [0, srcmax] to [0, 2^dstmax]. +/** Map x linearly from range [0, 2^srcmax_bits] to [0, dstmax]. * Equivalent to above, but uses shift instead of division. */ -static unsigned scaleu_shift(unsigned x, unsigned char srcmax, unsigned dstmax); +static uint16_t scaleu_shift(uint16_t x, uint8_t srcmax_bits, uint16_t dstmax); #pragma aux scaleu_shift = \ "mul dx" /* dx:ax = x * dstmax */ \ - "shrd ax, dx, cl" /* ax = dx:ax / 2^srcmax */ \ + "shrd ax, dx, cl" /* ax = dx:ax / 2^srcmax_bits */ \ __parm [ax] [cl] [dx] \ __value [ax] \ __modify exact [ax dx] -/** Map x linearly from range [0, srcmax] to [0, dstmax]. +/** Map x linearly from range [-srcmax, srcmax] to [-dstmax, dstmax]. * Equivalent of (x * dstmax) / srcmax but with 32-bit signed precision. */ -static int scalei(int x, int srcmax, int dstmax); +static int16_t scalei(int16_t x, int16_t srcmax, int16_t dstmax); #pragma aux scalei = \ "imul cx" /* dx:ax = x * dstmax */ \ "idiv bx" /* ax = dx:ax / srcmax */ \ @@ -82,24 +82,24 @@ static int scalei(int x, int srcmax, int dstmax); __value [ax] \ __modify exact [ax dx] -/** Map x linearly from range [0, srcmax] to [0, dstmax]. +/** Map x linearly from range [-srcmax, srcmax] to [-dstmax, dstmax]. * Equivalent to scalei, but the division remainder is returned in rem, * which can be reused in future calls to reduce rounding error. */ -static int scalei_rem(int x, int srcmax, int dstmax, short *rem); +static int16_t scalei_rem(int16_t x, int16_t srcmax, int16_t dstmax, int16_t *rem); #pragma aux scalei_rem = \ "imul cx" /* dx:ax = x * dstmax */ \ "mov cx, [si]" /* cx = rem */ \ "test cx, cx" \ - "setns cl" /* cl = 1 if rem positive, 0 if negative */ \ + "setns cl" /* cl = 1 if rem sign positive, 0 if negative */ \ "movzx cx, cl" \ - "dec cx" /* cx = 0 if rem positive, -1 if negative */ \ + "dec cx" /* cx = 0 if rem positive, -1 if negative => rem sign extended */ \ "add ax, [si]" /* ax += *rem */ \ - "adc dx, cx" /* dx += 1 if carry and rem positive, 0 if carry and rem negative (aka. signed addition) */ \ + "adc dx, cx" /* dx += "upper part of rem" +cf */ \ "idiv bx" /* ax = dx:ax / srcmax, dx = new remainder */ \ "mov [si], dx" /* store the new remainder */ \ __parm [ax] [bx] [cx] [si] \ __value [ax] \ - __modify [ax cx dx si] + __modify [ax cx dx] /** Sign extend x from b bits to 16. */ static inline int16_t sign_extend(int16_t x, int b) -- cgit v1.2.3