1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-01 13:41:34 +00:00

remove woz float stuff and some test things

This commit is contained in:
mrdudz 2023-09-02 23:11:55 +02:00
parent 83d3927a7f
commit 14c71cd958
31 changed files with 0 additions and 2276 deletions

View File

@ -1,97 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
char buffer[32];
char * __fastcall__ _ftostr(char *d, float s)
{
float f;
unsigned char *p;
char *bp, *buf;
int exp;
unsigned long mantissa;
unsigned long val;
int sign;
unsigned char n;
static char digits[10]={0,1,2,3,4,5,6,7,8,9};
unsigned long mantissa_mod = 1000000000;
unsigned long mantissa_rest;
if (d == NULL) {
buf = bp = &buffer[0];
} else {
buf = bp = d;
}
f = s;
p = (unsigned char*)&f;
// printf("%02x %02x %02x %02x\n", p[3], p[2], p[1], p[0]);
sign = (p[3] & 0x80) ? 1 : 0;
exp = ((p[3] << 1) & 0xfe) | ((p[2] >> 7) & 1);
exp -= 127;
mantissa = p[2] & 0x7f;
mantissa <<=8;
mantissa |= p[1];
mantissa <<=8;
mantissa |= p[0];
*bp++ = sign ? '-' : ' ';
*bp++ = '1';
*bp++ = '.';
val = 0xff;
// printf("mantissa: %ld\n", mantissa);
mantissa_rest = mantissa;
for (n = 0; n < 10; n++) {
// printf("n:%2d rest:%ld mod:%ld\n", n, mantissa_rest, mantissa_mod);
if ((mantissa_mod <= mantissa_rest) && (mantissa_rest > 0)) {
val = mantissa_rest / mantissa_mod;
// printf("n:%2d val:%ld\n", n, val);
// *bp++ = digits[(int)val];
*bp++ = '0' + val;
mantissa_rest -= (val * mantissa_mod);
}
mantissa_mod /= 10;
}
if (val == 0xff) {
*bp++ = '0';
}
// *bp++ = 'e';
// *bp++ = 0;
*bp++ = '*';
*bp++ = '2';
*bp++ = '^';
// printf("exp: %ld\n", exp);
mantissa_mod = 1000;
if (exp < 0) {
mantissa_rest = -1 * exp;
*bp++ = '-';
} else {
mantissa_rest = exp;
}
val = 0xff;
for (n = 0; n < 10; n++) {
// printf("n:%2d rest:%ld mod:%ld\n", n, mantissa_rest, mantissa_mod);
if ((mantissa_mod <= mantissa_rest) && (mantissa_rest > 0)) {
val = mantissa_rest / mantissa_mod;
// printf("n:%2d val:%ld\n", n, val);
// *bp++ = digits[(int)val];
*bp++ = '0' + val;
mantissa_rest -= (val * mantissa_mod);
}
mantissa_mod /= 10;
}
if (val == 0xff) {
*bp++ = '0';
}
*bp++ = 0;
return buf;
}

View File

@ -1,7 +0,0 @@
.include "wozfp.inc"
.export afloat
afloat:
; FIXME
rts

View File

@ -1,7 +0,0 @@
.include "wozfp.inc"
.export aufloat
aufloat:
; FIXME
rts

View File

@ -1,7 +0,0 @@
.include "wozfp.inc"
.export axfloat
axfloat:
; FIXME
rts

View File

@ -1,7 +0,0 @@
.include "wozfp.inc"
.export axufloat
axufloat:
; FIXME
rts

View File

@ -1,7 +0,0 @@
.include "wozfp.inc"
.export eaxfloat
eaxfloat:
; FIXME
rts

View File

@ -1,7 +0,0 @@
.include "wozfp.inc"
.export eaxufloat
eaxufloat:
; FIXME
rts

View File

@ -1,7 +0,0 @@
.include "wozfp.inc"
.export fbnegeax
fbnegeax:
; FIXME
rts

View File

@ -1,8 +0,0 @@
.include "wozfp.inc"
; float -> 16bit int
.export feaxint
feaxint:
; FIXME
rts

View File

@ -1,8 +0,0 @@
.include "wozfp.inc"
; float -> 32bit long
.export feaxlong
feaxlong:
; FIXME
rts

View File

@ -1,9 +0,0 @@
.include "wozfp.inc"
.export ftosaddeax
ftosaddeax:
; FIXME
lda #0
tax
rts

View File

@ -1,9 +0,0 @@
.include "wozfp.inc"
.export ftosdiveax
ftosdiveax:
; FIXME
lda #0
tax
rts

View File

@ -1,8 +0,0 @@
.include "wozfp.inc"
.export ftoseqeax
ftoseqeax:
; FIXME
lda #0
tax
rts

View File

@ -1,8 +0,0 @@
.include "wozfp.inc"
.export ftosgeeax
ftosgeeax:
; FIXME
lda #0
tax
rts

View File

@ -1,8 +0,0 @@
.include "wozfp.inc"
.export ftosgteax
ftosgteax:
; FIXME
lda #0
tax
rts

View File

@ -1,8 +0,0 @@
.include "wozfp.inc"
.export ftosleeax
ftosleeax:
; FIXME
lda #0
tax
rts

View File

@ -1,8 +0,0 @@
.include "wozfp.inc"
.export ftoslteax
ftoslteax:
; FIXME
lda #0
tax
rts

View File

@ -1,9 +0,0 @@
.include "wozfp.inc"
.export ftosmuleax
ftosmuleax:
; FIXME
lda #0
tax
rts

View File

@ -1,8 +0,0 @@
.include "wozfp.inc"
.export ftosneeax
ftosneeax:
; FIXME
lda #0
tax
rts

View File

@ -1,8 +0,0 @@
.include "wozfp.inc"
.export ftossubeax
ftossubeax:
; FIXME
lda #0
tax
rts

View File

@ -1,16 +0,0 @@
; .org $40 ; SET BASE PAGE ADRESSES
; SIGN = *
SIGN = $40
X2 = SIGN+1 ; EXPONENT 2
M2 = X2+1 ; MANTISSA 2
X1 = M2+3 ; EXPONENT 1
M1 = X1+1 ; MANTISSA 1
E = M1+3 ; SCRATCH
ZZ = E+4
T = ZZ+4
SEXP = T+4
INT = SEXP+4
;

View File

@ -1,456 +0,0 @@
; JULY 5, 1976
; BASIC FLOATING POINT ROUTINES
; FOR 6502 MICROPROCESSOR
; BY R. RANKIN AND S. WOZNIAK
;
; CONSISTING OF:
; NATURAL LOG
; COMMON LOG
; EXPONENTIAL (E**X)
; FLOAT FIX
; FADD FSUB
; FMUL FDIV
;
;
; FLOATING POINT REPRESENTATION (4-BYTES)
; EXPONENT BYTE 1
; MANTISSA BYTES 2-4
;
; MANTISSA: TWO'S COMPLEMENT REPRESENTATION WITH SIGN IN
; MSB OF HIGH-ORDER BYTE. MANTISSA IS NORMALIZED WITH AN
; ASSUMED DECIMAL POINT BETWEEN BITS 5 AND 6 OF THE HIGH-ORDER
; BYTE. THUS THE MANTISSA IS IN THE RANGE 1. TO 2. EXCEPT
; WHEN THE NUMBER IS LESS THAN 2**(-128).
;
; EXPONENT: THE EXPONENT REPRESENTS POWERS OF TWO. THE
; REPRESENTATION IS 2'S COMPLEMENT EXCEPT THAT THE SIGN
; BIT (BIT 7) IS COMPLEMENTED. THIS ALLOWS DIRECT COMPARISON
; OF EXPONENTS FOR SIZE SINCE THEY ARE STORED IN INCREASING
; NUMERICAL SEQUENCE RANGING FROM $00 (-128) TO $FF (+127)
; ($ MEANS NUMBER IS HEXADECIMAL).
;
; REPRESENTATION OF DECIMAL NUMBERS: THE PRESENT FLOATING
; POINT REPRESENTATION ALLOWS DECIMAL NUMBERS IN THE APPROXIMATE
; RANGE OF 10**(-38) THROUGH 10**(38) WITH 6 TO 7 SIGNIFICANT
; DIGITS.
;
;
.include "wozfp.inc"
; .org $1D00 ; STARTING LOCATION FOR LOG
; .export WOZFP
;WOZFP:
;
;
; NATURAL LOG OF MANT/EXP1 WITH RESULT IN MANT/EXP1
;
LOG: LDA M1
BEQ ERROR
BPL CONT ; IF ARG>0 OK
ERROR: BRK ; ERROR ARG<=0
;
CONT: JSR SWAP ; MOVE ARG TO EXP/MANT2
LDX #0 ; LOAD X FOR HIGH BYTE OF EXPONENT
LDA X2 ; HOLD EXPONENT
LDY #$80
STY X2 ; SET EXPONENT 2 TO 0 ($80)
EOR #$80 ; COMPLEMENT SIGN BIT OF ORIGINAL EXPONENT
STA M1+1 ; SET EXPONENT INTO MANTISSA 1 FOR FLOAT
BPL *+3 ; IS EXPONENT NEGATIVE
DEX ; YES, SET X TO $FF
STX M1 ; SET UPPER BYTE OF EXPONENT
JSR FLOAT ; CONVERT TO FLOATING POINT
LDX #3 ; 4 BYTE TRANSFERS
SEXP1: LDA X2,X
STA ZZ,X ; COPY MANTISSA TO Z
LDA X1,X
STA SEXP,X ; SAVE EXPONENT IN SEXP
LDA R22,X ; LOAD EXP/MANT1 WITH SQRT(2)
STA X1,X
DEX
BPL SEXP1
JSR FSUB ; Z-SQRT(2)
LDX #3 ; 4 BYTE TRANSFER
SAVET: LDA X1,X ; SAVE EXP/MANT1 AS T
STA T,X
LDA ZZ,X ; LOAD EXP/MANT1 WITH Z
STA X1,X
LDA R22,X ; LOAD EXP/MANT2 WITH SQRT(2)
STA X2,X
DEX
BPL SAVET
JSR FADD ; Z+SQRT(2)
LDX #3 ; 4 BYTE TRANSFER
TM2: LDA T,X
STA X2,X ; LOAD T INTO EXP/MANT2
DEX
BPL TM2
JSR FDIV ; T=(Z-SQRT(2))/(Z+SQRT(2))
LDX #3 ; 4 BYTE TRANSFER
MIT: LDA X1,X
STA T,X ; COPY EXP/MANT1 TO T AND
STA X2,X ; LOAD EXP/MANT2 WITH T
DEX
BPL MIT
JSR FMUL ; T*T
JSR SWAP ; MOVE T*T TO EXP/MANT2
LDX #3 ; 4 BYTE TRANSFER
MIC: LDA C,X
STA X1,X ; LOAD EXP/MANT1 WITH C
DEX
BPL MIC
JSR FSUB ; T*T-C
LDX #3 ; 4 BYTE TRANSFER
M2MB: LDA MB,X
STA X2,X ; LOAD EXP/MANT2 WITH MB
DEX
BPL M2MB
JSR FDIV ; MB/(T*T-C)
LDX #3
M2A1: LDA A1,X
STA X2,X ; LOAD EXP/MANT2 WITH A1
DEX
BPL M2A1
JSR FADD ; MB/(T*T-C)+A1
LDX #3 ; 4 BYTE TRANSFER
M2T: LDA T,X
STA X2,X ; LOAD EXP/MANT2 WITH T
DEX
BPL M2T
JSR FMUL ; (MB/(T*T-C)+A1)*T
LDX #3 ; 4 BYTE TRANSFER
M2MHL: LDA MHLF,X
STA X2,X ; LOAD EXP/MANT2 WITH MHLF (.5)
DEX
BPL M2MHL
JSR FADD ; +.5
LDX #3 ; 4 BYTE TRANSFER
LDEXP: LDA SEXP,X
STA X2,X ; LOAD EXP/MANT2 WITH ORIGINAL EXPONENT
DEX
BPL LDEXP
JSR FADD ; +EXPN
LDX #3 ; 4 BYTE TRANSFER
MLE2: LDA LE2,X
STA X2,X ; LOAD EXP/MANT2 WITH LN(2)
DEX
BPL MLE2
JSR FMUL ; *LN(2)
RTS ; RETURN RESULT IN MANT/EXP1
;
; COMMON LOG OF MANT/EXP1 RESULT IN MANT/EXP1
;
LOG10: JSR LOG ; COMPUTE NATURAL LOG
LDX #3
L10: LDA LN10,X
STA X2,X ; LOAD EXP/MANT2 WITH 1/LN(10)
DEX
BPL L10
JSR FMUL ; LOG10(X)=LN(X)/LN(10)
RTS
;
LN10: .byte $7E, $6F, $2D, $ED ; 0.4342945
R22: .byte $80, $5A, $82, $7A ; 1.4142136 SQRT(2)
LE2: .byte $7F, $58, $B9, $0C ; 0.69314718 LOG BASE E OF 2
A1: .byte $80, $52, $B0, 40 ; 1.2920074
MB: .byte $81, $AB, $86, $49 ; -2.6398577
C: .byte $80, $6A, $08, $66 ; 1.6567626
MHLF: .byte $7F, $40, $00, $00 ; 0.5
;
; .res $1e00-*
; .org $1E00 ; STARTING LOCATION FOR EXP
;
; EXP OF MANT/EXP1 RESULT IN MANT/EXP1
;
EXP: LDX #3 ; 4 BYTE TRANSFER
LDA L2E,X
STA X2,X ; LOAD EXP/MANT2 WITH LOG BASE 2 OF E
DEX
BPL EXP+2
JSR FMUL ; LOG2(3)*X
LDX #3 ; 4 BYTE TRANSFER
FSA: LDA X1,X
STA ZZ,X ; STORE EXP/MANT1 IN Z
DEX
BPL FSA ; SAVE Z=LN(2)*X
JSR FIX ; CONVERT CONTENTS OF EXP/MANT1 TO AN INTEGER
LDA M1+1
STA INT ; SAVE RESULT AS INT
SEC ; SET CARRY FOR SUBTRACTION
SBC #124 ; INT-124
LDA M1
SBC #0
BPL OVFLW ; OVERFLOW INT>=124
CLC ; CLEAR CARRY FOR ADD
LDA M1+1
ADC #120 ; ADD 120 TO INT
LDA M1
ADC #0
BPL CONTIN ; IF RESULT POSITIVE CONTINUE
LDA #0 ; INT<-120 SET RESULT TO ZERO AND RETURN
LDX #3 ; 4 BYTE MOVE
ZERO: STA X1,X ; SET EXP/MANT1 TO ZERO
DEX
BPL ZERO
RTS ; RETURN
;
OVFLW: BRK ; OVERFLOW
;
CONTIN: JSR FLOAT ; FLOAT INT
LDX #3
ENTD: LDA ZZ,X
STA X2,X ; LOAD EXP/MANT2 WITH Z
DEX
BPL ENTD
JSR FSUB ; Z*Z-FLOAT(INT)
LDX #3 ; 4 BYTE MOVE
ZSAV: LDA X1,X
STA ZZ,X ; SAVE EXP/MANT1 IN Z
STA X2,X ; COPY EXP/MANT1 TO EXP/MANT2
DEX
BPL ZSAV
JSR FMUL ; Z*Z
LDX #3 ; 4 BYTE MOVE
LA2: LDA A2,X
STA X2,X ; LOAD EXP/MANT2 WITH A2
LDA X1,X
STA SEXP,X ; SAVE EXP/MANT1 AS SEXP
DEX
BPL LA2
JSR FADD ; Z*Z+A2
LDX #3 ; 4 BYTE MOVE
LB2: LDA B2,X
STA X2,X ; LOAD EXP/MANT2 WITH B2
DEX
BPL LB2
JSR FDIV ; T=B/(Z*Z+A2)
LDX #3 ; 4 BYTE MOVE
DLOAD: LDA X1,X
STA T,X ; SAVE EXP/MANT1 AS T
LDA C2,X
STA X1,X ; LOAD EXP/MANT1 WITH C2
LDA SEXP,X
STA X2,X ; LOAD EXP/MANT2 WITH SEXP
DEX
BPL DLOAD
JSR FMUL ; Z*Z*C2
JSR SWAP ; MOVE EXP/MANT1 TO EXP/MANT2
LDX #3 ; 4 BYTE TRANSFER
LTMP: LDA T,X
STA X1,X ; LOAD EXP/MANT1 WITH T
DEX
BPL LTMP
JSR FSUB ; C2*Z*Z-B2/(Z*Z+A2)
LDX #3 ; 4 BYTE TRANSFER
LDD: LDA D,X
STA X2,X ; LOAD EXP/MANT2 WITH D
DEX
BPL LDD
JSR FADD ; D+C2*Z*Z-B2/(Z*Z+A2)
JSR SWAP ; MOVE EXP/MANT1 TO EXP/MANT2
LDX #3 ; 4 BYTE TRANSFER
LFA: LDA ZZ,X
STA X1,X ; LOAD EXP/MANT1 WITH Z
DEX
BPL LFA
JSR FSUB ; -Z+D+C2*Z*Z-B2/(Z*Z+A2)
LDX #3 ; 4 BYTE TRANSFER
LF3: LDA ZZ,X
STA X2,X ; LOAD EXP/MANT2 WITH Z
DEX
BPL LF3
JSR FDIV ; Z/(**** )
LDX #3 ; 4 BYTE TRANSFER
LD12: LDA MHLF,X
STA X2,X ; LOAD EXP/MANT2 WITH .5
DEX
BPL LD12
JSR FADD ; +Z/(***)+.5
SEC ; ADD INT TO EXPONENT WITH CARRY SET
LDA INT ; TO MULTIPLY BY
ADC X1 ; 2**(INT+1)
STA X1 ; RETURN RESULT TO EXPONENT
RTS ; RETURN ANS=(.5+Z/(-Z+D+C2*Z*Z-B2/(Z*Z+A2))*2**(INT+1)
L2E: .byte $80, $5C, $55, $1E ; 1.4426950409 LOG BASE 2 OF E
A2: .byte $86, $57, $6A, $E1 ; 87.417497202
B2: .byte $89, $4D, $3F, $1D ; 617.9722695
C2: .byte $7B, $46, $FA, $70 ; .03465735903
D: .byte $83, $4F, $A3, $03 ; 9.9545957821
;
;
; BASIC FLOATING POINT ROUTINES
;
; .res $1F00-*
; .org $1F00 ; START OF BASIC FLOATING POINT ROUTINES
ADD: CLC ; CLEAR CARRY
LDX #$02 ; INDEX FOR 3-BYTE ADD
ADD1: LDA M1,X
ADC M2,X ; ADD A BYTE OF MANT2 TO MANT1
STA M1,X
DEX ; ADVANCE INDEX TO NEXT MORE SIGNIF.BYTE
BPL ADD1 ; LOOP UNTIL DONE.
RTS ; RETURN
MD1: ASL SIGN ; CLEAR LSB OF SIGN
JSR ABSWAP ; ABS VAL OF MANT1, THEN SWAP MANT2
ABSWAP: BIT M1 ; MANT1 NEG?
BPL ABSWP1 ; NO,SWAP WITH MANT2 AND RETURN
JSR FCOMPL ; YES, COMPLEMENT IT.
INC SIGN ; INCR SIGN, COMPLEMENTING LSB
ABSWP1: SEC ; SET CARRY FOR RETURN TO MUL/DIV
;
; SWAP EXP/MANT1 WITH EXP/MANT2
;
SWAP: LDX #$04 ; INDEX FOR 4-BYTE SWAP.
SWAP1: STY E-1,X
LDA X1-1,X ; SWAP A BYTE OF EXP/MANT1 WITH
LDY X2-1,X ; EXP/MANT2 AND LEAVEA COPY OF
STY X1-1,X ; MANT1 IN E(3BYTES). E+3 USED.
STA X2-1,X
DEX ; ADVANCE INDEX TO NEXT BYTE
BNE SWAP1 ; LOOP UNTIL DONE.
RTS
;
;
;
; CONVERT 16 BIT INTEGER IN M1(HIGH) AND M1+1(LOW) TO F.P.
; RESULT IN EXP/MANT1. EXP/MANT2 UNEFFECTED
;
;
FLOAT: LDA #$8E
STA X1 ; SET EXPN TO 14 DEC
LDA #0 ; CLEAR LOW ORDER BYTE
STA M1+2
BEQ NORML ; NORMALIZE RESULT
NORM1: DEC X1 ; DECREMENT EXP1
ASL M1+2
ROL M1+1 ; SHIFT MANT1 (3 BYTES) LEFT
ROL M1
NORML: LDA M1 ; HIGH ORDER MANT1 BYTE
ASL ; UPPER TWO BITS UNEQUAL?
EOR M1
BMI RTS1 ; YES,RETURN WITH MANT1 NORMALIZED
LDA X1 ; EXP1 ZERO?
BNE NORM1 ; NO, CONTINUE NORMALIZING
RTS1: RTS ; RETURN
;
;
; EXP/MANT2-EXP/MANT1 RESULT IN EXP/MANT1
;
FSUB: JSR FCOMPL ; CMPL MANT1 CLEARS CARRY UNLESS ZERO
SWPALG: JSR ALGNSW ; RIGHT SHIFT MANT1 OR SWAP WITH MANT2 ON CARRY
;
; ADD EXP/MANT1 AND EXP/MANT2 RESULT IN EXP/MANT1
;
FADD: LDA X2
CMP X1 ; COMPARE EXP1 WITH EXP2
BNE SWPALG ; IF UNEQUAL, SWAP ADDENDS OR ALIGN MANTISSAS
JSR ADD ; ADD ALIGNED MANTISSAS
ADDEND: BVC NORML ; NO OVERFLOW, NORMALIZE RESULTS
BVS RTLOG ; OV: SHIFT MANT1 RIGHT. NOTE CARRY IS CORRECT SIGN
ALGNSW: BCC SWAP ; SWAP IF CARRY CLEAR, ELSE SHIFT RIGHT ARITH.
RTAR: LDA M1 ; SIGN OF MANT1 INTO CARRY FOR
ASL ; RIGHT ARITH SHIFT
RTLOG: INC X1 ; INCR EXP1 TO COMPENSATE FOR RT SHIFT
BEQ OVFL ; EXP1 OUT OF RANGE.
RTLOG1: LDX #$FA ; INDEX FOR 6 BYTE RIGHT SHIFT
ROR1: LDA #$80
BCS ROR2
ASL
ROR2: LSR E+3,X ; SIMULATE ROR E+3,X
ORA E+3,X
STA E+3,X
INX ; NEXT BYTE OF SHIFT
BNE ROR1 ; LOOP UNTIL DONE
RTS ; RETURN
;
;
; EXP/MANT1 X EXP/MANT2 RESULT IN EXP/MANT1
;
FMUL: JSR MD1 ; ABS. VAL OF MANT1, MANT2
ADC X1 ; ADD EXP1 TO EXP2 FOR PRODUCT EXPONENT
JSR MD2 ; CHECK PRODUCT EXP AND PREPARE FOR MUL
CLC ; CLEAR CARRY
MUL1: JSR RTLOG1 ; MANT1 AND E RIGHT.(PRODUCT AND MPLIER)
BCC MUL2 ; IF CARRY CLEAR, SKIP PARTIAL PRODUCT
JSR ADD ; ADD MULTIPLICAN TO PRODUCT
MUL2: DEY ; NEXT MUL ITERATION
BPL MUL1 ; LOOP UNTIL DONE
MDEND: LSR SIGN ; TEST SIGN (EVEN/ODD)
NORMX: BCC NORML ; IF EXEN, NORMALIZE PRODUCT, ELSE COMPLEMENT
FCOMPL: SEC ; SET CARRY FOR SUBTRACT
LDX #$03 ; INDEX FOR 3 BYTE SUBTRACTION
COMPL1: LDA #$00 ; CLEAR A
SBC X1,X ; SUBTRACT BYTE OF EXP1
STA X1,X ; RESTORE IT
DEX ; NEXT MORE SIGNIFICANT BYTE
BNE COMPL1 ; LOOP UNTIL DONE
BEQ ADDEND ; NORMALIZE (OR SHIFT RIGHT IF OVERFLOW)
;
;
; EXP/MANT2 / EXP/MANT1 RESULT IN EXP/MANT1
;
FDIV: JSR MD1 ; TAKE ABS VAL OF MANT1, MANT2
SBC X1 ; SUBTRACT EXP1 FROM EXP2
JSR MD2 ; SAVE AS QUOTIENT EXP
DIV1: SEC ; SET CARRY FOR SUBTRACT
LDX #$02 ; INDEX FOR 3-BYTE INSTRUCTION
DIV2: LDA M2,X
SBC E,X ; SUBTRACT A BYTE OF E FROM MANT2
PHA ; SAVE ON STACK
DEX ; NEXT MORE SIGNIF BYTE
BPL DIV2 ; LOOP UNTIL DONE
LDX #$FD ; INDEX FOR 3-BYTE CONDITIONAL MOVE
DIV3: PLA ; PULL A BYTE OF DIFFERENCE OFF STACK
BCC DIV4 ; IF MANT2<E THEN DONT RESTORE MANT2
STA M2+3,X
DIV4: INX ; NEXT LESS SIGNIF BYTE
BNE DIV3 ; LOOP UNTIL DONE
ROL M1+2
ROL M1+1 ; ROLL QUOTIENT LEFT, CARRY INTO LSB
ROL M1
ASL M2+2
ROL M2+1 ; SHIFT DIVIDEND LEFT
ROL M2
BCS OVFL ; OVERFLOW IS DUE TO UNNORMALIZED DIVISOR
DEY ; NEXT DIVIDE ITERATION
BNE DIV1 ; LOOP UNTIL DONE 23 ITERATIONS
BEQ MDEND ; NORMALIZE QUOTIENT AND CORRECT SIGN
MD2: STX M1+2
STX M1+1 ; CLR MANT1 (3 BYTES) FOR MUL/DIV
STX M1
BCS OVCHK ; IF EXP CALC SET CARRY, CHECK FOR OVFL
BMI MD3 ; IF NEG NO UNDERFLOW
PLA ; POP ONE
PLA ; RETURN LEVEL
BCC NORMX ; CLEAR X1 AND RETURN
MD3: EOR #$80 ; COMPLEMENT SIGN BIT OF EXP
STA X1 ; STORE IT
LDY #$17 ; COUNT FOR 24 MUL OR 23 DIV ITERATIONS
RTS ; RETURN
OVCHK: BPL MD3 ; IF POS EXP THEN NO OVERFLOW
OVFL: BRK
;
;
; CONVERT EXP/MANT1 TO INTEGER IN M1 (HIGH) AND M1+1(LOW)
; EXP/MANT2 UNEFFECTED
;
JSR RTAR ; SHIFT MANT1 RT AND INCREMENT EXPNT
FIX: LDA X1 ; CHECK EXPONENT
CMP #$8E ; IS EXPONENT 14?
BNE FIX-3 ; NO, SHIFT
RTRN: RTS ; RETURN
; .include "util.s"

View File

@ -1,8 +0,0 @@
quick.bin
quick.prg
quick.s
quick.c64.s
float-basic
float-cmp
float-conv
float-minimal

View File

@ -1,95 +0,0 @@
.SILENT:
CC65=../../bin/cc65
CL65=../../bin/cl65
CA65=../../bin/ca65
SIM65=../../bin/sim65
OPT=-O
TDIR=../val
all: quick
##############################################################################
quick.bin: quick.c
$(CC65) $(OPT) -t sim6502 --add-source -o quick.s quick.c
# gdb --args $(CC65) $(OPT) -t sim6502 --add-source -o quick.s quick.c
$(CL65) $(OPT) -t sim6502 -o quick.bin quick.s
.PHONY: quick
quick: quick.bin
$(SIM65) quick.bin
quick.c64.s: quick.c
$(CC65) $(OPT) -DCONIO -t c64 -I ./include -I ./cbmkernal --add-source -o quick.c64.s quick.c
quick.prg: quick.c64.s
$(CL65) $(OPT) -t c64 -I ./include -I ./cbmkernal -o quick.prg quick.c64.s
runc64-quick: quick.prg
x64sc -autostartprgmode 1 quick.prg
###############################################################################
# test against GCC
COPT=-m32 -mpc32
gccminimal: $(TDIR)/float-minimal.c gccstubs.c
gcc $(COPT) -I ./ "-D__fastcall__= " -o float-minimal $(TDIR)/float-minimal.c gccstubs.c -lm
gccbasic-const-const: $(TDIR)/float-basic-const-const.c gccstubs.c
gcc $(COPT) -I ./ "-D__fastcall__= " -o float-basic-const-const $(TDIR)/float-basic-const-const.c gccstubs.c -lm
gccbasic-var-const: $(TDIR)/float-basic-var-const.c gccstubs.c
gcc $(COPT) -I ./ "-D__fastcall__= " -o float-basic-var-const $(TDIR)/float-basic-var-const.c gccstubs.c -lm
gccbasic-const-var: $(TDIR)/float-basic-const-var.c gccstubs.c
gcc $(COPT) -I ./ "-D__fastcall__= " -o float-basic-const-var $(TDIR)/float-basic-const-var.c gccstubs.c -lm
gccbasic-var-var: $(TDIR)/float-basic-var-var.c gccstubs.c
gcc $(COPT) -I ./ "-D__fastcall__= " -o float-basic-var-var $(TDIR)/float-basic-var-var.c gccstubs.c -lm
gccconv: $(TDIR)/float-conv.c gccstubs.c
gcc $(COPT) -I ./ "-D__fastcall__= " -o float-conv $(TDIR)/float-conv.c gccstubs.c -lm
gcccmp: $(TDIR)/float-cmp.c gccstubs.c
gcc $(COPT) -I ./ "-D__fastcall__= " -o float-cmp $(TDIR)/float-cmp.c gccstubs.c -lm
gccmisc: $(TDIR)/float-misc.c gccstubs.c
gcc $(COPT) -I ./ "-D__fastcall__= " -o float-misc $(TDIR)/float-misc.c gccstubs.c -lm
gccquick: quick.c gccstubs.c
gcc $(COPT) -I ./ "-D__fastcall__= " -o quick quick.c gccstubs.c -lm
rungcc-minimal: gccminimal
./float-minimal
rungcc-basic: gccbasic-const-const gccbasic-var-const gccbasic-const-var gccbasic-var-var
./float-basic-const-const
./float-basic-var-const
./float-basic-const-var
./float-basic-var-var
rungcc-conv: gccconv
./float-conv
rungcc-cmp: gcccmp
./float-cmp
rungcc-misc: gccmisc
./float-misc
rungcc-quick: gccquick
./quick
rungcc: gccminimal gccconv gccbasic gcccmp gccmisc gccquick
./float-minimal
./float-basic
./float-conv
./float-cmp
./float-misc
###############################################################################
clean:
$(RM) ./float-minimal
$(RM) ./float-basic
$(RM) ./float-cmp
$(RM) ./float-conv
$(RM) ./float-misc
$(RM) ./quick
$(RM) ./quick.bin
$(RM) ./quick.s
$(RM) quick.prg
$(RM) quick.c64.s
$(RM) quick.s

View File

@ -1,10 +0,0 @@
Some stuff that may be handy in the early stage of developing the floating
point support:
-------------------------------------------------------------------------------
find the floating point library in libsrc/float/softfloat
This directory, and all of its contents, should probably get deleted before
merging with master.

View File

@ -1,15 +0,0 @@
#ifndef FLOAT_H_
#define FLOAT_H_
#include "math.h"
float _fneg(float f);
float _fand(float f1, float f2);
char *_ftostr(char *d, float s);
char *_ftoa(char *d, float s);
float _ctof(char c);
float _utof(unsigned int c);
float _stof(signed int c);
#endif

View File

@ -1,50 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
float _fneg(float f)
{
return f * -1.0f;
}
float _fand(float f1, float f2)
{
return ((unsigned)f1) & ((unsigned)f2);
}
char buffer[32];
char *_ftostr(char *d, float s)
{
if (d == NULL) {
d = &buffer[0];
}
// printf("<%f>", (double)s);
sprintf(d, "%f", (double)s);
return d;
}
char *_ftoa(char *d, float s)
{
if (d == NULL) {
d = &buffer[0];
}
sprintf(d, "%f", (double)s);
return d;
}
float _ctof(char c)
{
return (float)c;
}
float _utof(unsigned int c)
{
return (float)c;
}
float _stof(signed int c)
{
return (float)c;
}

View File

@ -1,105 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
//#include <_float.h>
/*
#include <math.h>
*/
#if 0
unsigned char buf[32];
unsigned char var_uchar;
// float fp2;
float fp1 = 42.0f;
float fp2 = 23;
float fp3 = 33.0;
/*
TODO:
float-basic.c:
fp3 = fp1 / 2.3f; // FIXME: division by zero
fp3 = fp1 - 11.5f; // FIXME: Invalid operands for binary operator '-'
float-conv.c:
conversion from float variable to char variable does not work right
float-cmp.c:
many failing cases
float-math.c:
DONE:
float-minimal.c
float-misc.c:
*/
char *test(char *buffer, float f) {
signed long intpart = (signed long)(f);
float fracpart;
float f1, f2;
signed long n0;
// printf("f:%f\n",f);
f2 = intpart;
// printf("f2:%f\n",f2);
printf("f2:%08lx\n",*((unsigned long*)(&f2)));
fracpart = f - f2;
// printf("fracpart:%f\n",fracpart);
printf("fracpart:%08lx\n",*((unsigned long*)(&fracpart)));
// f1 = fracpart * 10000.0f;
f1 = 10000.0f;
printf("fracpart:%08lx\n",*((unsigned long*)(&f1)));
// f1 *= fracpart;
f1 = f1 * fracpart;
// f1 = fracpart;
// f1 = intpart;
// printf("fracpart:%f\n",f1);
printf("fracpart:%08lx\n",*((unsigned long*)(&f1)));
n0 = (signed long)f1;
printf("n0:%ld\n",n0);
if (n0 >= 1000) {
sprintf(buffer, "<0x%08lx:%ld.%ld>", *((unsigned long*)(&f)), intpart, n0);
} else if (n0 >= 100) {
sprintf(buffer, "<0x%08lx:%ld.0%ld>", *((unsigned long*)(&f)), intpart, n0);
} else if (n0 >= 10) {
sprintf(buffer, "<0x%08lx:%ld.00%ld>", *((unsigned long*)(&f)), intpart, n0);
} else if (n0 >= 1) {
sprintf(buffer, "<0x%08lx:%ld.000%ld>", *((unsigned long*)(&f)), intpart, n0);
} else {
sprintf(buffer, "<0x%08lx:%ld.0000%ld>", *((unsigned long*)(&f)), intpart, n0);
}
return &buffer[0];
}
#endif
int test1(void)
{
float fp2 = 1.5f;
if (1.5f == fp2) {
return 1;
}
return 0;
}
// int test2(void)
// {
// float fp2 = 1.5f;
// float fp1 = 1.6f;
// if (fp2 >= fp1) {
// return 0;
// }
// return 1;
// }
int main(void)
{
#if 0
fp2 = 0.001f; printf("fp2 0x%08lx %s\n", *((uint32_t*)&fp2), test(buf, fp2));
fp2 = 0.001234f; printf("fp2 0x%08lx %s\n", *((uint32_t*)&fp2), test(buf, fp2));
fp2 = 0.01f; printf("fp2 0x%08lx %s\n", *((uint32_t*)&fp2), test(buf, fp2));
fp2 = 0.01234f; printf("fp2 0x%08lx %s\n", *((uint32_t*)&fp2), test(buf, fp2));
fp2 = 0.1234f; printf("fp2 0x%08lx %s\n", *((uint32_t*)&fp2), test(buf, fp2));
fp2 = 1.234f; printf("fp2 0x%08lx %s\n", *((uint32_t*)&fp2), test(buf, fp2));
fp2 = 12.34f; printf("fp2 0x%08lx %s\n", *((uint32_t*)&fp2), test(buf, fp2));
fp2 = 123.4f; printf("fp2 0x%08lx %s\n", *((uint32_t*)&fp2), test(buf, fp2));
#endif
printf("test:%d\n", test1());
// printf("test:%d\n", test2());
// return 0;
}

View File

@ -1,35 +0,0 @@
PROCESSOR_H = 6502-CC65.h
SOFTFLOAT_MACROS = softfloat-macros
TARGET=-t sim6502
OBJ = .o
EXE =
INCLUDES = -I. -I..
COMPILE_C = ../../../bin/cl65 $(TARGET) -c -o $@ $(INCLUDES) -I- -O
COMPILE_ONLY = ../../../bin/cl65 $(TARGET) --add-source -S -o $@.s $(INCLUDES) -I- -O
LINK = ../../../bin/cl65 $(TARGET) -o $@
#------------------------------------------------------------------------------
# Probably okay below here.
#------------------------------------------------------------------------------
all: softfloat$(OBJ)
echo softfloat ok!
milieu.h: $(PROCESSOR_H)
touch milieu.h
softfloat$(OBJ): milieu.h softfloat.h softfloat-specialize $(SOFTFLOAT_MACROS) softfloat.c
$(COMPILE_C) softfloat.c
timesoftfloat$(OBJ): milieu.h softfloat.h timesoftfloat.c
# $(COMPILE_ONLY) timesoftfloat.c
# $(COMPILE_C) timesoftfloat.c
timesoftfloat$(EXE): softfloat$(OBJ) timesoftfloat$(OBJ)
# $(LINK) softfloat$(OBJ) timesoftfloat$(OBJ)
clean:
$(RM) softfloat$(OBJ) timesoftfloat$(EXE) timesoftfloat$(OBJ) timesoftfloat$(OBJ).s

File diff suppressed because it is too large Load Diff

View File

@ -1,157 +0,0 @@
Documentation for the `timesoftfloat' Program of Berkeley SoftFloat
Release 2c
John R. Hauser
2015 January 30
----------------------------------------------------------------------------
Introduction
The `timesoftfloat' program evaluates the speed of SoftFloat's floating-
point routines. Each routine can be evaluated for every relevant rounding
mode, tininess mode, and/or rounding precision.
----------------------------------------------------------------------------
Contents
Introduction
Contents
Legal Notice
Executing `timesoftfloat'
Options
-help
-precision32, -precision64, -precision80
-nearesteven, -tozero, -down, -up
-tininessbefore, -tininessafter
Function Sets
----------------------------------------------------------------------------
Legal Notice
The `timesoftfloat' program was written by John R. Hauser.
THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort
has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO
PERSONS AND ORGANIZATIONS WHO CAN AND WILL TOLERATE ALL LOSSES, COSTS, OR
OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE WITHOUT RECOMPENSE FROM JOHN
HAUSER OR THE INTERNATIONAL COMPUTER SCIENCE INSTITUTE, AND WHO FURTHERMORE
EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
INSTITUTE (possibly via similar legal notice) AGAINST ALL LOSSES, COSTS, OR
OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE,
OR INCURRED BY ANYONE DUE TO A DERIVATIVE WORK THEY CREATE USING ANY PART OF
THE SOFTWARE.
----------------------------------------------------------------------------
Executing `timesoftfloat'
The `timesoftfloat' program is intended to be invoked from a command line
interpreter as follows:
timesoftfloat [<option>...] <function>
Here square brackets ([]) indicate optional items, while angled brackets
(<>) denote parameters to be filled in. The `<function>' argument is
the name of the SoftFloat routine to evaluate, such as `float32_add' or
`float64_to_int32'. The allowed options are detailed in the next section,
_Options_. If `timesoftfloat' is executed without any arguments, a summary
of usage is written. It is also possible to evaluate all machine functions
in a single invocation as explained in the section _Function Sets_ later in
this document.
Ordinarily, a function's speed will be evaulated separately for each of
the four rounding modes, one after the other. If the rounding mode is not
supposed to have any effect on the results of a function--for instance,
some operations do not require rounding--only the nearest/even rounding mode
is timed. In the same way, if a function is affected by the way in which
underflow tininess is detected, `timesoftfloat' times the function both with
tininess detected before rounding and after rounding. For 80-bit double-
extended-precision operations affected by rounding precision control,
`timesoftfloat' also times the function for all three rounding precision
modes, one after the other. Evaluation of a function can be limited to
a single rounding mode, a single tininess mode, and/or a single rounding
precision with appropriate options (see _Options_).
For each function and mode evaluated, `timesoftfloat' reports the speed of
the function in kops/s, or "thousands of operations per second". This unit
of measure differs from the traditional MFLOPS ("millions of floating-
point operations per second") only in being a factor of 1000 smaller.
(1000 kops/s is exactly 1 MFLOPS.) Speeds are reported in thousands
instead of millions because software floating-point may execute at less than
1 MFLOPS.
The speeds reported by `timesoftfloat' may be affected somewhat by other
programs executing at the same time as `timesoftfloat'.
Note that the remainder operations (`float32_rem', `float64_rem',
`floatx80_rem' and `float128_rem') will be markedly slower than other
operations, particularly for 80-bit double-extended-precision (`floatx80')
and 128-bit quadruple-precision (`float128'). This is inherent to
the remainder function itself and is not a failing of the SoftFloat
implementation.
----------------------------------------------------------------------------
Options
The `timesoftfloat' program accepts several command options. If mutually
contradictory options are given, the last one has priority.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-help
The `-help' option causes a summary of program usage to be written, after
which the program exits.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-precision32, -precision64, -precision80
For 80-bit double-extended-precision functions affected by rounding
precision control, the `-precision32' option restricts evaluation to only
the cases in which rounding precision is equivalent to 32-bit single-
precision. The other rounding precision options are not timed. Likewise,
the `-precision64' and `-precision80' options fix the rounding precision
equivalent to 64-bit double-precision or the full 80-bit double-extended-
precision, respectively. These options are ignored for functions not
affected by rounding precision control.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-nearesteven, -tozero, -down, -up
The `-nearesteven' option restricts evaluation to only the cases in which
the rounding mode is nearest/even. The other rounding mode options are
not timed. Likewise, `-tozero' forces rounding toward zero; `-down' forces
rounding down; and `-up' forces rounding up. These options are ignored for
functions that are exact and thus do not round.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-tininessbefore, -tininessafter
The `-tininessbefore' option restricts evaluation to only the cases
detecting underflow tininess before rounding. Tininess after rounding
is not timed. Likewise, `-tininessafter' forces underflow tininess to be
detected after rounding only. These options are ignored for functions not
affected by the way in which underflow tininess is detected.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
----------------------------------------------------------------------------
Function Sets
Just as `timesoftfloat' can test an operation for all four rounding modes in
sequence, multiple operations can also be tested with a single invocation.
Three sets are recognized: `-all1', `-all2', and `-all'. The set `-all1'
comprises all one-operand functions; `-all2' is all two-operand functions;
and `-all' is all functions. A function set can be used in place of a
function name in the command line, as in
timesoftfloat [<option>...] -all