mirror of
https://github.com/irmen/prog8.git
synced 2025-01-28 17:33:13 +00:00
implemented avg() asm
This commit is contained in:
parent
6e8cf7e1d3
commit
9ee1628901
@ -4,27 +4,26 @@
|
||||
~ main {
|
||||
|
||||
; @todo fix floating point number corruption
|
||||
; @todo add avg implementations
|
||||
|
||||
word[10] xword = [1,2,3,4,5,6,7,8,9,-1111]
|
||||
word[10] yword = [11,22,33,44,55,66,77,88,99,-1111 ]
|
||||
word[10] zword = [1,2,3,4,5,6,7,8,9,-9999]
|
||||
|
||||
uword[10] xuword = [1,2,3,4,5,6,7,88,99,1111]
|
||||
uword[10] yuword = [11,22,33,44,55,66,77,88,99,1111 ]
|
||||
uword[10] zuword = [1,2,3,4,5,6,77,88,99,9999]
|
||||
|
||||
byte[10] xbyte = [1,2,3,4,5,6,7,8,9,-110]
|
||||
byte[10] ybyte = [ 11,22,33,44,55,-66,-77,-88,-99,-110 ]
|
||||
byte[10] zbyte = [1,2,3,4,5,6,7,8,9,-99]
|
||||
byte[10] xbyte = [1,2,3,4,5,6,7,8,9,-110]
|
||||
byte[10] ybyte = [11,22,33,44,55,-66,-77,-88,-99,-110 ]
|
||||
byte[10] zbyte = [1,2,3,4,5,6,7,8,9,-99]
|
||||
|
||||
ubyte[10] xubyte = [1,2,3,4,5,6,77,88,99,111]
|
||||
ubyte[10] yubyte = [11,22,33,44,55,66,77,88,99,111]
|
||||
ubyte[10] zubyte = [1,2,3,4,5,66,7,88,99,111]
|
||||
|
||||
float[10] xcoor = [ 1,2,3,4,5,6,7,8,9.9,11.11 ]
|
||||
float[10] ycoor = [ 11,22,33,44,55,66,77,88,99.9,111.11 ]
|
||||
float[10] zcoor = [ 111,222,333,444,555,666,777,888,999.9,1001.11 ]
|
||||
word[10] xword = [1,2,3,4,5,6,7,8,9,-1111]
|
||||
word[10] yword = [11,22,33,44,55,66,77,88,99,-1111 ]
|
||||
word[10] zword = [1,2,3,4,5,6,7,8,9,-9999]
|
||||
|
||||
uword[10] xuword = [1,2,3,4,5,6,7,88,99,1111]
|
||||
uword[10] yuword = [11,22,33,44,55,66,77,88,99,1111 ]
|
||||
uword[10] zuword = [1,2,3,4,5,6,77,88,99,9999]
|
||||
|
||||
float[10] xcoor = [1,2,3,4,5,6,7,8,9.9,11.11 ]
|
||||
float[10] ycoor = [11,22,33,44,55,66,77,88,99.9,111.11 ]
|
||||
float[10] zcoor = [111,222,333,444,555,666,777,888,999.9,1001.11 ]
|
||||
|
||||
sub start() {
|
||||
; c64scr.print("\nxword:\n")
|
||||
@ -56,148 +55,77 @@
|
||||
c64.CHROUT('X')
|
||||
c64scr.print_ub(X)
|
||||
c64.CHROUT('\n')
|
||||
word sumbx = min(xbyte) ; -65
|
||||
word sumby = min(ybyte) ; -275
|
||||
word sumbz = min(zbyte) ; -54
|
||||
uword sumubx = min(xubyte) ; 396
|
||||
uword sumuby = min(yubyte) ; 606
|
||||
uword sumubz = min(zubyte) ; 386
|
||||
word sumwx = min(xword) ; -1066
|
||||
word sumwy = min(yword) ; -616
|
||||
word sumwz = min(zword) ; -9954
|
||||
uword sumuwx = min(xuword) ; 1326
|
||||
uword sumuwy = min(yuword) ; 1606
|
||||
uword sumuwz = min(zuword) ; 10284
|
||||
float sumfx = min(xcoor) ; 57.01
|
||||
float sumfy = min(ycoor) ; 607.01
|
||||
float sumfz = min(zcoor) ; 5997.01
|
||||
|
||||
float avgbx = avg(xbyte)
|
||||
float avgby = avg(ybyte)
|
||||
float avgbz = avg(zbyte)
|
||||
float avgubx = avg(xubyte)
|
||||
float avguby = avg(yubyte)
|
||||
float avgubz = avg(zubyte)
|
||||
float avgwx = avg(xword)
|
||||
float avgwy = avg(yword)
|
||||
float avgwz = avg(zword)
|
||||
float avguwx = avg(xuword)
|
||||
float avguwy = avg(yuword)
|
||||
float avguwz = avg(zuword)
|
||||
float avgfx = avg(xcoor)
|
||||
float avgfy = avg(ycoor)
|
||||
float avgfz = avg(zcoor)
|
||||
c64.CHROUT('X')
|
||||
c64scr.print_ub(X)
|
||||
c64.CHROUT('\n')
|
||||
; float avgbx = avg(xbyte)
|
||||
; float avgby = avg(ybyte)
|
||||
; float avgbz = avg(zbyte)
|
||||
; float avgubx = avg(xubyte)
|
||||
; float avguby = avg(yubyte)
|
||||
; float avgubz = avg(zubyte)
|
||||
; float avgwx = avg(xword)
|
||||
; float avgwy = avg(yword)
|
||||
; float avgwz = avg(zword)
|
||||
; float avguwx = avg(xuword)
|
||||
; float avguwy = avg(yuword)
|
||||
; float avguwz = avg(zuword)
|
||||
; float avgfx = avg(xcoor)
|
||||
; float avgfy = avg(ycoor)
|
||||
; float avgfz = avg(zcoor)
|
||||
; c64.CHROUT('X')
|
||||
; c64scr.print_ub(X)
|
||||
; c64.CHROUT('\n')
|
||||
|
||||
c64scr.print("sumbx=")
|
||||
c64scr.print_w(sumbx)
|
||||
c64scr.print("avgbx=")
|
||||
c64flt.print_f(avgbx)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("sumby=")
|
||||
c64scr.print_w(sumby)
|
||||
c64scr.print("avgby=")
|
||||
c64flt.print_f(avgby)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("sumbz=")
|
||||
c64scr.print_w(sumbz)
|
||||
c64scr.print("avgbz=")
|
||||
c64flt.print_f(avgbz)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print("sumubx=")
|
||||
c64scr.print_uw(sumubx)
|
||||
c64scr.print("avgubx=")
|
||||
c64flt.print_f(avgubx)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("sumuby=")
|
||||
c64scr.print_uw(sumuby)
|
||||
c64scr.print("avguby=")
|
||||
c64flt.print_f(avguby)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("sumubz=")
|
||||
c64scr.print_uw(sumubz)
|
||||
c64scr.print("avgubz=")
|
||||
c64flt.print_f(avgubz)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print("sumwx=")
|
||||
c64scr.print_w(sumwx)
|
||||
c64scr.print("avgwx=")
|
||||
c64flt.print_f(avgwx)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("sumwy=")
|
||||
c64scr.print_w(sumwy)
|
||||
c64scr.print("avgwy=")
|
||||
c64flt.print_f(avgwy)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("sumwz=")
|
||||
c64scr.print_w(sumwz)
|
||||
c64scr.print("avgwz=")
|
||||
c64flt.print_f(avgwz)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print("sumuwx=")
|
||||
c64scr.print_uw(sumuwx)
|
||||
c64scr.print("avguwx=")
|
||||
c64flt.print_f(avguwx)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("sumuwy=")
|
||||
c64scr.print_uw(sumuwy)
|
||||
c64scr.print("avguwy=")
|
||||
c64flt.print_f(avguwy)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("sumuwz=")
|
||||
c64scr.print_uw(sumuwz)
|
||||
c64scr.print("avguwz=")
|
||||
c64flt.print_f(avguwz)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
c64scr.print("sumfx=")
|
||||
c64flt.print_f(sumfx)
|
||||
c64scr.print("avgfx=")
|
||||
c64flt.print_f(avgfx)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("sumfy=")
|
||||
c64flt.print_f(sumfy)
|
||||
c64scr.print("avgfy=")
|
||||
c64flt.print_f(avgfy)
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print("sumfz=")
|
||||
c64flt.print_f(sumfz)
|
||||
c64scr.print("avgfz=")
|
||||
c64flt.print_f(avgfz)
|
||||
c64.CHROUT('\n')
|
||||
|
||||
return
|
||||
|
||||
; c64scr.print("avgbx=")
|
||||
; c64flt.print_f(avgbx)
|
||||
; c64.CHROUT('\n')
|
||||
; c64scr.print("avgby=")
|
||||
; c64flt.print_f(avgby)
|
||||
; c64.CHROUT('\n')
|
||||
; c64scr.print("avgbz=")
|
||||
; c64flt.print_f(avgbz)
|
||||
; c64.CHROUT('\n')
|
||||
;
|
||||
; c64scr.print("avgubx=")
|
||||
; c64flt.print_f(avgubx)
|
||||
; c64.CHROUT('\n')
|
||||
; c64scr.print("avguby=")
|
||||
; c64flt.print_f(avguby)
|
||||
; c64.CHROUT('\n')
|
||||
; c64scr.print("avgubz=")
|
||||
; c64flt.print_f(avgubz)
|
||||
; c64.CHROUT('\n')
|
||||
;
|
||||
; c64scr.print("avgwx=")
|
||||
; c64flt.print_f(avgwx)
|
||||
; c64.CHROUT('\n')
|
||||
; c64scr.print("avgwy=")
|
||||
; c64flt.print_f(avgwy)
|
||||
; c64.CHROUT('\n')
|
||||
; c64scr.print("avgwz=")
|
||||
; c64flt.print_f(avgwz)
|
||||
; c64.CHROUT('\n')
|
||||
;
|
||||
; c64scr.print("avguwx=")
|
||||
; c64flt.print_f(avguwx)
|
||||
; c64.CHROUT('\n')
|
||||
; c64scr.print("avguwy=")
|
||||
; c64flt.print_f(avguwy)
|
||||
; c64.CHROUT('\n')
|
||||
; c64scr.print("avguwz=")
|
||||
; c64flt.print_f(avguwz)
|
||||
; c64.CHROUT('\n')
|
||||
;
|
||||
; c64scr.print("avgfx=")
|
||||
; c64flt.print_f(avgfx)
|
||||
; c64.CHROUT('\n')
|
||||
; c64scr.print("avgfy=")
|
||||
; c64flt.print_f(avgfy)
|
||||
; c64.CHROUT('\n')
|
||||
; c64scr.print("avgfz=")
|
||||
; c64flt.print_f(avgfz)
|
||||
; c64.CHROUT('\n')
|
||||
;
|
||||
; return
|
||||
|
||||
|
||||
c64scr.print("\nseparated i=2\n")
|
||||
c64scr.print(" x[2]=")
|
||||
|
@ -721,7 +721,38 @@ private class StatementTranslator(private val prog: IntermediateProgram,
|
||||
else -> throw CompilerException("wrong datatype for $funcname()")
|
||||
}
|
||||
}
|
||||
"min", "max", "avg", "sum" -> {
|
||||
"avg" -> {
|
||||
// 1 array argument, type determines the exact syscall to use
|
||||
val arg=args.single() as IdentifierReference
|
||||
val target=arg.targetStatement(namespace) as VarDecl
|
||||
val length=Value(DataType.UBYTE, target.arrayspec!!.size()!!)
|
||||
val arrayDt=arg.resultingDatatype(namespace, heap)
|
||||
prog.instr(Opcode.PUSH_BYTE, length)
|
||||
when (arrayDt) {
|
||||
DataType.ARRAY_UB -> {
|
||||
createSyscall("sum_ub")
|
||||
prog.instr(Opcode.CAST_UW_TO_F) // result of sum(ubyte) is uword, so cast
|
||||
}
|
||||
DataType.ARRAY_B -> {
|
||||
createSyscall("sum_b")
|
||||
prog.instr(Opcode.CAST_W_TO_F) // result of sum(byte) is word, so cast
|
||||
}
|
||||
DataType.ARRAY_UW -> {
|
||||
createSyscall("sum_uw")
|
||||
prog.instr(Opcode.CAST_UW_TO_F) // result of sum(uword) is uword, so cast
|
||||
}
|
||||
DataType.ARRAY_W -> {
|
||||
createSyscall("sum_w")
|
||||
prog.instr(Opcode.CAST_W_TO_F) // result of sum(word) is word, so cast
|
||||
}
|
||||
DataType.ARRAY_F -> createSyscall("sum_f")
|
||||
else -> throw CompilerException("wrong datatype for avg")
|
||||
}
|
||||
// divide by the number of elements
|
||||
prog.instr(opcodePush(DataType.FLOAT), Value(DataType.FLOAT, length.numericValue()))
|
||||
prog.instr(Opcode.DIV_F)
|
||||
}
|
||||
"min", "max", "sum" -> {
|
||||
// 1 array argument, type determines the exact syscall to use
|
||||
val arg=args.single() as IdentifierReference
|
||||
val target=arg.targetStatement(namespace) as VarDecl
|
||||
@ -735,7 +766,6 @@ private class StatementTranslator(private val prog: IntermediateProgram,
|
||||
DataType.ARRAY_F -> createSyscall("${funcname}_f")
|
||||
else -> throw CompilerException("wrong datatype for $funcname()")
|
||||
}
|
||||
|
||||
}
|
||||
"abs" -> {
|
||||
// 1 argument, type determines the exact opcode to use
|
||||
|
Loading…
x
Reference in New Issue
Block a user