comparison src/fps.s @ 105:65cb0a0297b3

Make integer to floating point conversion use extra bits in fp accumulator
author William Astle <lost@l-w.ca>
date Mon, 30 Oct 2023 22:25:47 -0600
parents eecb576c76c6
children 1396fe221ff7
comparison
equal deleted inserted replaced
104:eecb576c76c6 105:65cb0a0297b3
896 bpl fps_fromuint ; brif not 896 bpl fps_fromuint ; brif not
897 sex ; set sign to negative 897 sex ; set sign to negative
898 sta fpa0+fpa.sign 898 sta fpa0+fpa.sign
899 ldd zero ; negate the value and store it to temporary location 899 ldd zero ; negate the value and store it to temporary location
900 subd val.int+2,x 900 subd val.int+2,x
901 std fpaextra+2 901 std fpa0+fpa.extra+2
902 ldd zero 902 ldd zero
903 sbcb val.int+1,x 903 sbcb val.int+1,x
904 sbca val.int,x 904 sbca val.int,x
905 std fpaextra 905 std fpa0+fpa.extra
906 bra fps_fromint0 ; go finish the conversion 906 bra fps_fromint0 ; go finish the conversion
907 fps_fromuint clr fpa0+fpa.sign ; set sign to positive 907 fps_fromuint clr fpa0+fpa.sign ; set sign to positive
908 ldd val.int+2,x ; copy value to temporary accumulator 908 ldd val.int+2,x ; copy value to temporary accumulator
909 std fpaextra+2 909 std fpa0+fpa.extra+2
910 ldd val.int,x 910 ldd val.int,x
911 std fpaextra 911 std fpa0+fpa.extra
912 fps_fromint0 ldd zero ; zero out destination 912 fps_fromint0 ldd zero ; zero out destination
913 std fpa0+fpa.sig 913 std fpa0+fpa.sig
914 std fpa0+fpa.sig+2 914 std fpa0+fpa.sig+2
915 sta fpa0+fpa.sig+4 915 sta fpa0+fpa.sig+4
916 ldd #0x5f20 ; set exponent for decimal right of significand and 32 bit shifts 916 ldd #0x5f20 ; set exponent for decimal right of significand and 32 bit shifts
917 sta fpa0+fpa.exp ; save exponent 917 sta fpa0+fpa.exp ; save exponent
918 stb fpaextra+5 ; save counter 918 stb fpa0+fpa.extra+4 ; save counter
919 bra fps_fromint2 ; skip digit check on the first iteration since none need adjustment 919 bra fps_fromint2 ; skip digit check on the first iteration since none need adjustment
920 fps_fromint1 ldu #fpa0+fpa.sig ; point to significand 920 fps_fromint1 ldu #fpa0+fpa.sig ; point to significand
921 bsr fps_fromint3 ; do adjustments, 5 bytes worth of digits 921 bsr fps_fromint3 ; do adjustments, 5 bytes worth of digits
922 bsr fps_fromint3 922 bsr fps_fromint3
923 bsr fps_fromint3 923 bsr fps_fromint3
924 bsr fps_fromint3 924 bsr fps_fromint3
925 bsr fps_fromint3 925 bsr fps_fromint3
926 fps_fromint2 lsl fpaextra+3 ; shift left 926 fps_fromint2 lsl fpa0+fpa.extra+3 ; shift left
927 rol fpaextra+2 927 rol fpa0+fpa.extra+2
928 rol fpaextra+1 928 rol fpa0+fpa.extra+1
929 rol fpaextra 929 rol fpa0+fpa.extra
930 rol fpa0+fpa.sig+4 930 rol fpa0+fpa.sig+4
931 rol fpa0+fpa.sig+3 931 rol fpa0+fpa.sig+3
932 rol fpa0+fpa.sig+2 932 rol fpa0+fpa.sig+2
933 rol fpa0+fpa.sig+1 933 rol fpa0+fpa.sig+1
934 rol fpa0+fpa.sig 934 rol fpa0+fpa.sig
935 dec fpaextra+5 ; done all digits? 935 dec fpa0+fpa.extra+4 ; done all digits?
936 bne fps_fromint1 ; brif not 936 bne fps_fromint1 ; brif not
937 lda #valtype_float ; set result type to floating point 937 lda #valtype_float ; set result type to floating point
938 sta val.type,y 938 sta val.type,y
939 jsr fps_normalizea0 ; go normalize fpa0 939 jsr fps_normalizea0 ; go normalize fpa0
940 jmp fps_pack0 ; pack the result to the original accumulator 940 jmp fps_pack0 ; pack the result to the original accumulator