diff --git a/src/crt/bshl.src b/src/crt/bshl.src index b8d5d67a6..79da97207 100644 --- a/src/crt/bshl.src +++ b/src/crt/bshl.src @@ -1,12 +1,16 @@ .assume adl=1 .section .text + .global __bshl .type __bshl, @function + .global __bshl_nz + .type __bshl_nz, @function .ifdef PREFER_OS_CRT .set __bshl, 0x000100 + .set __bshl_nz, __bshl .else @@ -16,6 +20,7 @@ __bshl: inc b dec b ret z +__bshl_nz: push bc .L.loop: add a, a diff --git a/src/crt/bshrs.src b/src/crt/bshrs.src index ecb6b1aef..85136d463 100644 --- a/src/crt/bshrs.src +++ b/src/crt/bshrs.src @@ -1,8 +1,11 @@ .assume adl=1 .section .text + .global __bshrs .type __bshrs, @function + .global __bshrs_nz + .type __bshrs_nz, @function __bshrs: ; CC: if B!=0: B*(5*r(PC)+1)+6*r(PC)+(ADL?6*r(SPL)+3*w(SPL):4*r(SPS)+2*w(SPS))+1 @@ -10,6 +13,7 @@ __bshrs: inc b dec b ret z +__bshrs_nz: push bc .L.loop: sra a diff --git a/src/crt/bshru.src b/src/crt/bshru.src index 9001cb2d3..5795ad1a5 100644 --- a/src/crt/bshru.src +++ b/src/crt/bshru.src @@ -1,12 +1,16 @@ .assume adl=1 .section .text + .global __bshru .type __bshru, @function + .global __bshru_nz + .type __bshru_nz, @function .ifdef PREFER_OS_CRT .set __bshru, 0x000104 + .set __bshru_nz, __bshru .else @@ -16,6 +20,7 @@ __bshru: inc b dec b ret z +__bshru_nz: push bc .L.loop: srl a diff --git a/src/crt/dtof.src b/src/crt/dtof.src index 6cfdb2138..c5c4c0f7b 100644 --- a/src/crt/dtof.src +++ b/src/crt/dtof.src @@ -32,7 +32,7 @@ __dtof_helper: push de pop bc ld l, 5 - call __lshru + call __lshru_nz push bc pop hl .L.finish_inf_nan: @@ -101,7 +101,8 @@ __dtof: and a, $1F .L.round_up: .L.round_down: - call __llshru + ; BC:UDE:UHL >>= 29 + call __llshru_nz ; B, C, and UDE are zero here or a, a jr z, .L.no_round @@ -192,7 +193,7 @@ __dtof: and a, $0F or a, $10 - call __lshru + call __lshru_nz xor a, a ; subnormal exponent ; HL = BC >> 1 scf @@ -216,5 +217,5 @@ __dtof: .extern __lland .extern __llcmpzero - .extern __llshru - .extern __lshru + .extern __llshru_nz + .extern __lshru_nz diff --git a/src/crt/dtoll.src b/src/crt/dtoll.src index f712f8d9b..64799e392 100644 --- a/src/crt/dtoll.src +++ b/src/crt/dtoll.src @@ -50,7 +50,7 @@ __dtoull: ld l, a ex (sp), hl ; shift is non-zero and [1, 11] in the non-UB case - call c, __llshl + call c, __llshl_nz jr .finish .shift_right: ; A is [-1, -52] @@ -85,5 +85,5 @@ __dtoull: jr .finish_zero_or_one .extern __llneg - .extern __llshl + .extern __llshl_nz .extern __llshru diff --git a/src/crt/ftod.src b/src/crt/ftod.src index 2a640d559..193512c74 100644 --- a/src/crt/ftod.src +++ b/src/crt/ftod.src @@ -71,9 +71,9 @@ __ftod: .L.subnormal: ; since this is subnormal, the LSB of the exponent is already zero call __ictlz - ld c, a + ld c, a ; A is [1, 23] ; shift until the MSB of the mantissa is the LSB of the exponent - call __ishl + call __ishl_nz ; (Float64_bias - Float32_bias) = $0380 ; expon = (Float64_bias - Float32_bias) - clz_result add hl, hl @@ -101,4 +101,4 @@ __ftod: jr .L.shift_28 .extern __ictlz - .extern __ishl + .extern __ishl_nz diff --git a/src/crt/i48shl.src b/src/crt/i48shl.src index 5ae71cadb..485c8a79b 100644 --- a/src/crt/i48shl.src +++ b/src/crt/i48shl.src @@ -6,9 +6,13 @@ .assume adl=1 .section .text + .global __i48shl .type __i48shl, @function + .global __i48shl_nz + .type __i48shl_nz, @function +__i48shl_nz: __i48shl: push bc ld b, a diff --git a/src/crt/i48shr.src b/src/crt/i48shr.src index 14fe85163..0d3606201 100644 --- a/src/crt/i48shr.src +++ b/src/crt/i48shr.src @@ -6,21 +6,29 @@ .assume adl=1 .section .text + .global __i48shrs .type __i48shrs, @function + .global __i48shrs_nz + .type __i48shrs_nz, @function + .global __i48shru .type __i48shru, @function + .global __i48shru_nz + .type __i48shru_nz, @function __i48shrs: inc c dec c ret z +__i48shrs_nz: cp a, a ; Set Z flag db $C2 ; inc c \ dec c \ ret z -> jp nz, * __i48shru: inc c dec c ret z +__i48shru_nz: ; NZ for unsigned shift, Z for signed shift push bc ld b, c diff --git a/src/crt/ishl.src b/src/crt/ishl.src index 88a2ab192..d3d04134d 100644 --- a/src/crt/ishl.src +++ b/src/crt/ishl.src @@ -1,18 +1,28 @@ .assume adl=1 .section .text + .global __ishl .type __ishl, @function + .global __ishl_nz + .type __ishl_nz, @function + .global __sshl .type __sshl, @function + .global __sshl_nz + .type __sshl_nz, @function .ifdef PREFER_OS_CRT .set __ishl, 0x000174 + .set __ishl_nz, __ishl + .set __sshl, 0x000240 + .set __sshl_nz, __sshl .else +__ishl_nz: __ishl: ; CC: if 0<=C<8: 23*r(PC)+3*r(SPL)+4+(C&1==0)+(C&2!=0)*(1*r(PC)-1)+(C&4!=0)*(3*r(PC)-1) ; if 8<=C<16: 30*r(PC)+3*r(SPL)+5+(C&1==0)+(C&2!=0)*(1*r(PC)-1)+(C&4!=0)*(3*r(PC)-1) @@ -52,5 +62,6 @@ __ishl_8: ret .set __sshl, __ishl + .set __sshl_nz, __ishl_nz .endif diff --git a/src/crt/ishrs.src b/src/crt/ishrs.src index a7b000621..bcf3af162 100644 --- a/src/crt/ishrs.src +++ b/src/crt/ishrs.src @@ -1,24 +1,35 @@ .assume adl=1 .section .text + .global __ishrs .type __ishrs, @function + .global __ishrs_nz + .type __ishrs_nz, @function + .global __ishru .type __ishru, @function + .global __ishru_nz + .type __ishru_nz, @function .ifdef PREFER_OS_CRT .set __ishrs, 0x00017C + .set __ishrs_nz, __ishrs + .set __ishru, 0x000184 + .set __ishru_nz, __ishru .else +__ishru_nz: __ishru: push af xor a, a add hl, hl rla db $DA ; push af \ add hl, hl \ sbc a, a -> jp c, * +__ishrs_nz: __ishrs: ; CC: if 0<=C<8: 35*r(PC)+9*r(SPL)+9*w(SPL)+4+(C&1==0)*(1*r(PC)-1)+(C&2==0)*(3*r(PC)-1)+(C&4==0)*(7*r(PC)-1) ; if 8<=C<16: 34*r(PC)+9*r(SPL)+6*w(SPL)+5+(C&1==0)*(1*r(PC)-1)+(C&2==0)*(3*r(PC)-1)+(C&4==0)*(7*r(PC)-1) diff --git a/src/crt/llshl.src b/src/crt/llshl.src index 1a5067f2e..6e67ebde0 100644 --- a/src/crt/llshl.src +++ b/src/crt/llshl.src @@ -1,9 +1,13 @@ .assume adl=1 .section .text + .global __llshl .type __llshl, @function + .global __llshl_nz + .type __llshl_nz, @function +__llshl_nz: __llshl: ; Suboptimal for large shift amounts push af diff --git a/src/crt/llshrs.src b/src/crt/llshrs.src index 962331ae8..bef5b25e2 100644 --- a/src/crt/llshrs.src +++ b/src/crt/llshrs.src @@ -4,9 +4,15 @@ .global __llshru .type __llshru, @function + .global __llshru_nz + .type __llshru_nz, @function + .global __llshrs .type __llshrs, @function + .global __llshrs_nz + .type __llshrs_nz, @function +__llshru_nz: __llshru: ; Suboptimal for large shift amounts push af @@ -21,6 +27,7 @@ __llshru: srl b jr .L.hijack_llshru +__llshrs_nz: __llshrs: ; Suboptimal for large shift amounts push af diff --git a/src/crt/lshl.src b/src/crt/lshl.src index 4dc3966bb..6a98e300b 100644 --- a/src/crt/lshl.src +++ b/src/crt/lshl.src @@ -3,10 +3,13 @@ .section .text .global __lshl .type __lshl, @function + .global __lshl_nz + .type __lshl_nz, @function .ifdef PREFER_OS_CRT .set __lshl, 0x0001E4 + .set __lshl_nz, __lshl .else @@ -17,6 +20,7 @@ __lshl: inc l dec l ret z +__lshl_nz: push bc ld b, l ex (sp), hl diff --git a/src/crt/lshrs.src b/src/crt/lshrs.src index afc91d74d..202f353b1 100644 --- a/src/crt/lshrs.src +++ b/src/crt/lshrs.src @@ -1,14 +1,18 @@ .assume adl=1 .section .text + .global __lshrs .type __lshrs, @function + .global __lshrs_nz + .type __lshrs_nz, @function .global __lshrs.hijack_lshru .type __lshrs.hijack_lshru, @function .ifdef PREFER_OS_CRT .set __lshrs, 0x0001E8 + .set __lshrs_nz, __lshrs .else @@ -19,6 +23,7 @@ __lshrs: inc l dec l ret z +__lshrs_nz: push hl push bc ld b, l diff --git a/src/crt/lshru.src b/src/crt/lshru.src index e00b52d63..7e759d6df 100644 --- a/src/crt/lshru.src +++ b/src/crt/lshru.src @@ -1,12 +1,16 @@ .assume adl=1 .section .text + .global __lshru .type __lshru, @function + .global __lshru_nz + .type __lshru_nz, @function .ifdef PREFER_OS_CRT .set __lshru, 0x0001EC + .set __lshru_nz, __lshru .else @@ -17,6 +21,7 @@ __lshru: inc l dec l ret z +__lshru_nz: push hl push bc ld b, l diff --git a/src/crt/ltod.src b/src/crt/ltod.src index 0299e84aa..97f35d70f 100644 --- a/src/crt/ltod.src +++ b/src/crt/ltod.src @@ -69,7 +69,7 @@ __lltod: pop bc ex (sp), hl ; (SP) = shift - call __llshru + call __llshru_nz add a, 51 - 1 ; compensate for the implicit mantissa bit ; BC/exponent = [$434*, $43E*] @@ -174,7 +174,7 @@ __ltod: .extern __lctlz .extern __llctlz .extern __llshl - .extern __llshru + .extern __llshru_nz .extern __llneg .extern __lladd_1 .extern ___fe_cur_env diff --git a/src/crt/sshrs.src b/src/crt/sshrs.src index 06d30dbfd..e7765eed6 100644 --- a/src/crt/sshrs.src +++ b/src/crt/sshrs.src @@ -1,12 +1,16 @@ .assume adl=1 .section .text + .global __sshrs .type __sshrs, @function + .global __sshrs_nz + .type __sshrs_nz, @function .ifdef PREFER_OS_CRT .set __sshrs, 0x000248 + .set __sshrs_nz, __sshrs .else @@ -17,6 +21,7 @@ __sshrs: inc c dec c ret z +__sshrs_nz: push bc ld b, c .L.loop: diff --git a/src/crt/sshru.src b/src/crt/sshru.src index 7663bb4cb..2bb9c4498 100644 --- a/src/crt/sshru.src +++ b/src/crt/sshru.src @@ -1,12 +1,16 @@ .assume adl=1 .section .text + .global __sshru .type __sshru, @function + .global __sshru_nz + .type __sshru_nz, @function .ifdef PREFER_OS_CRT .set __sshru, 0x000250 + .set __sshru_nz, __sshru .else @@ -17,6 +21,7 @@ __sshru: inc c dec c ret z +__sshru_nz: push bc ld b, c .L.loop: diff --git a/src/libc/frexpf.src b/src/libc/frexpf.src index 239c4cad9..c8b8cd40f 100644 --- a/src/libc/frexpf.src +++ b/src/libc/frexpf.src @@ -54,10 +54,10 @@ _frexp: add hl, de inc hl ; restore HL jr nc, .L.ret_zero - ; input: HL output: A + ; input: HL output: A in [1, 23] call __ictlz ld c, a - call __ishl + call __ishl_nz ld (iy + 3), hl sub a, 131 ; (127 + 3) + 1? idk where this magic number comes from cpl @@ -69,6 +69,6 @@ _frexp: jr .L.ret_subnormal .extern __ictlz - .extern __ishl + .extern __ishl_nz .endif diff --git a/src/libc/truncf.src b/src/libc/truncf.src index 85b25940d..37648c4fb 100644 --- a/src/libc/truncf.src +++ b/src/libc/truncf.src @@ -31,7 +31,7 @@ _truncf: neg ld d, c ; store C ld c, a - call __ishl + call __ishl_nz ld c, d ; restore C jp __iand @@ -49,5 +49,5 @@ _truncf: sbc hl, hl ret - .extern __ishl + .extern __ishl_nz .extern __iand