1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-06-26 06:29:28 +00:00
This commit is contained in:
David Schmenk 2017-11-19 20:00:54 -08:00
parent 129f2bf601
commit f2e5d885c6

View File

@ -7,15 +7,21 @@ include "inc/fpstr.plh"
//
// External interface to FPU library
//
//export word[] fpu
//word = @reset
//word = @pushDbl, @pushDbl, @pushDbl, @pushExt, @pushStr
//word = @pullDbl, @pullDbl, @pullDbl, @pullExt, @pullStr
//word = @loadDbl, @loadDbl, @loadDbl, @loadExt, @loadStr
//word = @storDbl, @storDbl, @storDbl, @storExt, @storStr
//word = @shiftUp, @shiftDown, @rotateUp, @rotateDown, @dup, @swap, @clear
//word = @add, @sub, @mul, @div, @rem
//word = @neg, @abs, @trunc, @round
predef reset, pushInt, pushSgl, pushDbl, pushExt, pushStr
predef pullInt, pullSgl, pullDbl, pullExt, pullStr
predef loadInt, loadSgl, loadDbl, loadExt, loadStr
predef storInt, storSgl, storDbl, storExt, storStr
predef shiftUp, shiftDown, rotateUp, rotateDown, dup, swap, clear
predef add, sub, mul, div, rem
predef neg, abs, trunc, round, sqrt, square
export word fpu = @reset
word = @pushInt, @pushSgl, @pushDbl, @pushExt, @pushStr
word = @pullInt, @pullSgl, @pullDbl, @pullExt, @pullStr
word = @loadInt, @loadSgl, @loadDbl, @loadExt, @loadStr
word = @storInt, @storSgl, @storDbl, @storExt, @storStr
word = @shiftUp, @shiftDown, @rotateUp, @rotateDown, @dup, @swap, @clear
word = @add, @sub, @mul, @div, @rem
word = @neg, @abs, @trunc, @round, @sqrt, @square
//
// FP Stack
//
@ -24,31 +30,31 @@ word stackRegs[4]
//
// Stack manipulation routines
//
def rotateUp#1
def rotateUp
stackRegs[0], stackRegs[1], stackRegs[2], stackRegs[3] = stackRegs[3], stackRegs[0], stackRegs[1], stackRegs[2]
end
def rotateDown#1
def rotateDown
stackRegs[0], stackRegs[1], stackRegs[2], stackRegs[3] = stackRegs[1], stackRegs[2], stackRegs[3], stackRegs[0]
end
def shiftUp#1
def shiftUp
stackRegs[0], stackRegs[1], stackRegs[2], stackRegs[3] = stackRegs[3], stackRegs[0], stackRegs[1], stackRegs[2]
memset(stackRegs[0], 0, t_extended)
end
def shiftDown#1
def shiftDown
stackRegs[0], stackRegs[1], stackRegs[2], stackRegs[3] = stackRegs[1], stackRegs[2], stackRegs[3], stackRegs[0]
memset(stackRegs[3], 0, t_extended)
end
def dup#1
def dup
stackRegs[0], stackRegs[1], stackRegs[2], stackRegs[3] = stackRegs[3], stackRegs[0], stackRegs[1], stackRegs[2]
memcpy(stackRegs[0], stackRegs[1], t_extended)
end
def swap#1
def swap
byte temp[t_extended]
memcpy(temp, stackRegs[1], t_extended)
memcpy(stackRegs[1], stackRegs[0], t_extended)
memcpy(stackRegs[0], temp, t_extended)
end
def clear#1
def clear
memset(stackRegs[0], 0, t_extended)
end
//
@ -71,7 +77,7 @@ def loadInt(pInt, reg)
sane:fpOp2(FFINT|FOZ2X, stackRegs[reg & $03], pInt)
return sane:zpRestore()
end
def storeInt(pInt, reg)
def storInt(pInt, reg)
sane:zpSave()
sane:fpOp2(FFINT|FOX2Z, pInt, stackRegs[reg & $03])
return sane:zpRestore()
@ -93,7 +99,7 @@ def loadSgl(pSgl, reg)
sane:fpOp2(FFSGL|FOZ2X, stackRegs[reg & $03], pSgl)
return sane:zpRestore()
end
def storeSgl(pSgl, reg)
def storSgl(pSgl, reg)
sane:zpSave()
sane:fpOp2(FFSGL|FOX2Z, pSgl, stackRegs[reg & $03])
return sane:zpRestore()
@ -115,7 +121,7 @@ def loadDbl(pDbl, reg)
sane:fpOp2(FFDBL|FOZ2X, stackRegs[reg & $03], pDbl)
return sane:zpRestore()
end
def storeDbl(pDbl, reg)
def storDbl(pDbl, reg)
sane:zpSave()
sane:fpOp2(FFDBL|FOX2Z, pDbl, stackRegs[reg & $03])
return sane:zpRestore()
@ -137,7 +143,7 @@ def loadExt(pExt, reg)
sane:fpOp2(FFEXT|FOZ2X, stackRegs[reg & $03], pExt)
return sane:zpRestore()
end
def storeExt(pExt, reg)
def storExt(pExt, reg)
sane:zpSave()
sane:fpOp2(FFEXT|FOX2Z, pExt, stackRegs[reg & $03])
return sane:zpRestore()
@ -167,31 +173,31 @@ end
//
// Basic math operations
//
def add#1
def add
sane:zpSave()
sane:fpOp2(FFEXT|FOADD, stackRegs[1], stackRegs[0])
sane:zpRestore()
return shiftDown
end
def sub#1
def sub
sane:zpSave()
sane:fpOp2(FFEXT|FOSUB, stackRegs[1], stackRegs[0])
sane:zpRestore()
return shiftDown
end
def mul#1
def mul
sane:zpSave()
sane:fpOp2(FFEXT|FOMUL, stackRegs[1], stackRegs[0])
sane:zpRestore()
return shiftDown
end
def div#1
def div
sane:zpSave()
sane:fpOp2(FFEXT|FODIV, stackRegs[1], stackRegs[0])
sane:zpRestore()
return shiftDown
end
def rem#1
def rem
sane:zpSave()
sane:fpOp2(FFEXT|FOREM, stackRegs[1], stackRegs[0])
sane:zpRestore()
@ -202,30 +208,35 @@ def neg#1
sane:fpOp1(FFEXT|FONEG, stackRegs[0])
return sane:zpRestore()
end
def abs#1
def abs
sane:zpSave()
sane:fpOp1(FFEXT|FOABS, stackRegs[0])
return sane:zpRestore()
end
def trunc#1
def trunc
sane:zpSave()
sane:fpOp1(FFEXT|FOTTI, stackRegs[0])
return sane:zpRestore()
end
def round#1
def round
sane:zpSave()
sane:fpOp1(FFEXT|FORTI, stackRegs[0])
return sane:zpRestore()
end
def sqrt#1
def sqrt
sane:zpSave()
sane:fpOp1(FFEXT|FOSQRT, stackRegs[0])
return sane:zpRestore()
end
def square
sane:zpSave()
sane:fpOp2(FFEXT|FOMUL, stackRegs[0], stackRegs[0])
sane:zpRestore()
end
//
// Reset FPU and SANE
//
def reset#1
def reset
byte i
word zero
@ -264,4 +275,10 @@ dumpStack
puts("Add\n")
add
dumpStack
puts("Square\n")
square
dumpStack
puts("Sqrt\n")
sqrt
dumpStack
done