fix float constants prefix mistakes, removed broken max_f/min_f (fix pending), tweaked sum_f

This commit is contained in:
Irmen de Jong 2019-04-04 22:01:26 +02:00
parent 1069b5f5d5
commit eebd4e5f18
2 changed files with 46 additions and 85 deletions

View File

@ -34,6 +34,7 @@
memory float FL_PIHALF = $e2e0 ; PI / 2 memory float FL_PIHALF = $e2e0 ; PI / 2
memory float FL_TWOPI = $e2e5 ; 2 * PI memory float FL_TWOPI = $e2e5 ; 2 * PI
memory float FL_FR4 = $e2ea ; .25 memory float FL_FR4 = $e2ea ; .25
float FL_ZERO = 0.0 ; oddly enough 0.0 isn't available in the kernel
; note: fac1/2 might get clobbered even if not mentioned in the function's name. ; note: fac1/2 might get clobbered even if not mentioned in the function's name.
@ -775,8 +776,8 @@ func_log2 .proc
stx c64.SCRATCH_ZPREGX stx c64.SCRATCH_ZPREGX
jsr c64flt.LOG jsr c64flt.LOG
jsr c64flt.MOVEF jsr c64flt.MOVEF
lda #<c64.FL_LOG2 lda #<FL_LOG2
ldy #>c64.FL_LOG2 ldy #>FL_LOG2
jsr c64flt.MOVFM jsr c64flt.MOVFM
jsr c64flt.FDIVT jsr c64flt.FDIVT
jmp push_fac1_as_result jmp push_fac1_as_result
@ -853,7 +854,7 @@ func_any_f .proc
asl a asl a
clc clc
adc c64.SCRATCH_ZPB1 ; times 5 because of float adc c64.SCRATCH_ZPB1 ; times 5 because of float
jmp func_any_b._entry jmp prog8_lib.func_any_b._entry
.pend .pend
func_all_f .proc func_all_f .proc
@ -865,7 +866,7 @@ func_all_f .proc
clc clc
adc c64.SCRATCH_ZPB1 ; times 5 because of float adc c64.SCRATCH_ZPB1 ; times 5 because of float
sta _cmp_mod+1 ; self-modifying code sta _cmp_mod+1 ; self-modifying code
jsr peek_address jsr prog8_lib.peek_address
ldy #0 ldy #0
- lda (c64.SCRATCH_ZPWORD1),y - lda (c64.SCRATCH_ZPWORD1),y
bne + bne +
@ -893,53 +894,18 @@ _cmp_mod cpy #255 ; modified
.pend .pend
func_max_f .proc func_max_f .proc
lda #<_min_float .warn "todo: fix func_max_f / func_min_f" ; TODO
ldy #>_min_float
jsr c64flt.MOVFM ; fac1=min(float)
lda #255
sta _cmp_mod+1 ; compare using 255 so we keep larger values
_minmax_entry jsr pop_array_and_lengthmin1Y
stx c64.SCRATCH_ZPREGX
- sty c64.SCRATCH_ZPREG
lda c64.SCRATCH_ZPWORD1
ldy c64.SCRATCH_ZPWORD1+1
jsr c64flt.FCOMP
_cmp_mod cmp #255 ; will be modified
bne +
; fac1 is smaller/larger, so store the new value instead
lda c64.SCRATCH_ZPWORD1
ldy c64.SCRATCH_ZPWORD1+1
jsr c64flt.MOVFM
ldy c64.SCRATCH_ZPREG
dey
cmp #255
beq +
lda c64.SCRATCH_ZPWORD1
clc
adc #5
sta c64.SCRATCH_ZPWORD1
bcc -
inc c64.SCRATCH_ZPWORD1+1
bne -
+ jmp push_fac1_as_result
_min_float .byte 255,255,255,255,255 ; -1.7014118345e+38
.pend .pend
func_min_f .proc func_min_f .proc
lda #<_max_float .warn "todo: fix func_max_f / func_min_f" ; TODO
ldy #>_max_float
jsr c64flt.MOVFM ; fac1=max(float)
lda #1
sta func_max_f._cmp_mod+1 ; compare using 1 so we keep smaller values
jmp func_max_f._minmax_entry
_max_float .byte 255,127,255,255,255 ; 1.7014118345e+38
.pend .pend
func_sum_f .proc func_sum_f .proc
lda #<c64.FL_NEGHLF lda #<FL_ZERO
ldy #>c64.FL_NEGHLF ldy #>FL_ZERO
jsr c64flt.MOVFM jsr c64flt.MOVFM
jsr pop_array_and_lengthmin1Y jsr prog8_lib.pop_array_and_lengthmin1Y
stx c64.SCRATCH_ZPREGX stx c64.SCRATCH_ZPREGX
- sty c64.SCRATCH_ZPREG - sty c64.SCRATCH_ZPREG
lda c64.SCRATCH_ZPWORD1 lda c64.SCRATCH_ZPWORD1
@ -956,8 +922,7 @@ func_sum_f .proc
bcc - bcc -
inc c64.SCRATCH_ZPWORD1+1 inc c64.SCRATCH_ZPWORD1+1
bne - bne -
+ jsr c64flt.FADDH + jmp push_fac1_as_result
jmp push_fac1_as_result
.pend .pend
}} }}

View File

@ -2090,7 +2090,6 @@ class StackVm(private var traceOutputFile: String?) {
Syscall.FUNC_MAX_F -> { Syscall.FUNC_MAX_F -> {
val iterable = evalstack.pop() val iterable = evalstack.pop()
val value = heap.get(iterable.heapId) val value = heap.get(iterable.heapId)
// TODO CHECK max(floatarray) correctness
val result = value.doubleArray!!.max() ?: 0.0 val result = value.doubleArray!!.max() ?: 0.0
evalstack.push(Value(DataType.FLOAT, result)) evalstack.push(Value(DataType.FLOAT, result))
} }
@ -2129,7 +2128,6 @@ class StackVm(private var traceOutputFile: String?) {
Syscall.FUNC_MIN_F -> { Syscall.FUNC_MIN_F -> {
val iterable = evalstack.pop() val iterable = evalstack.pop()
val value = heap.get(iterable.heapId) val value = heap.get(iterable.heapId)
// TODO check min(floatarray) correctness
val result = value.doubleArray!!.min() ?: 0.0 val result = value.doubleArray!!.min() ?: 0.0
evalstack.push(Value(DataType.FLOAT, result)) evalstack.push(Value(DataType.FLOAT, result))
} }
@ -2143,7 +2141,6 @@ class StackVm(private var traceOutputFile: String?) {
Syscall.FUNC_AVG_F -> { Syscall.FUNC_AVG_F -> {
val iterable = evalstack.pop() val iterable = evalstack.pop()
val value = heap.get(iterable.heapId) val value = heap.get(iterable.heapId)
// TODO check avg(floatarray) correctness
evalstack.push(Value(DataType.FLOAT, value.doubleArray!!.average())) evalstack.push(Value(DataType.FLOAT, value.doubleArray!!.average()))
} }
Syscall.FUNC_SUM_UB -> { Syscall.FUNC_SUM_UB -> {
@ -2168,7 +2165,6 @@ class StackVm(private var traceOutputFile: String?) {
evalstack.push(Value(DataType.FLOAT, value.array.map{it.integer!!}.sum())) evalstack.push(Value(DataType.FLOAT, value.array.map{it.integer!!}.sum()))
} }
Syscall.FUNC_SUM_F -> { Syscall.FUNC_SUM_F -> {
// TODO check sum(floatarray) correctness
val iterable = evalstack.pop() val iterable = evalstack.pop()
val value = heap.get(iterable.heapId) val value = heap.get(iterable.heapId)
evalstack.push(Value(DataType.FLOAT, value.doubleArray!!.sum())) evalstack.push(Value(DataType.FLOAT, value.doubleArray!!.sum()))