def IEEESPExp(self, ctx): arg = reg_to_float(ctx.cpu.r_reg(REG_D0)) try: res = math.exp(arg) except OverflowError: res = float('inf') log_math.info("SPExp(%s) = %s", arg, res) return float_to_reg(res)
def IEEEDPCeil(self, ctx): arg = regs_to_double(ctx.cpu.r_reg(REG_D0), ctx.cpu.r_reg(REG_D1)) res = math.ceil(arg) # Amiga forces pos zero if res == -0.0: res = 0.0 log_math.info("DPCeil(%s) = %s", arg, res) return double_to_regs(res)
def SPSqrt(self, ctx): arg = ffp_reg_to_float(ctx.cpu.r_reg(REG_D0)) try: res = math.sqrt(arg) except ValueError: res = float('-nan') log_math.info("SPSqrt(%s) = %s", arg, res) return float_to_ffp_reg(res)
def SPCosh(self, ctx): arg = ffp_reg_to_float(ctx.cpu.r_reg(REG_D0)) try: res = math.cosh(arg) except OverflowError: res = float('inf') log_math.info("SPCosh(%s) = %s", arg, res) return float_to_ffp_reg(res)
def IEEEDPAcos(self,ctx): arg = regs_to_double(ctx.cpu.r_reg(REG_D0),ctx.cpu.r_reg(REG_D1)) try: res = math.acos(arg) except ValueError: res = float('-nan') log_math.info("DPAcos(%s) = %s", arg, res) return double_to_regs(res)
def IEEESPCeil(self, ctx): arg = reg_to_float(ctx.cpu.r_reg(REG_D0)) res = math.ceil(arg) # Amiga forces pos zero if res == -0.0: res = 0.0 log_math.info("SPCeil(%s) = %s", arg, res) return float_to_reg(res)
def IEEESPAcos(self, ctx): arg = reg_to_float(ctx.cpu.r_reg(REG_D0)) try: res = math.acos(arg) except ValueError: res = float('-nan') log_math.info("SPAcos(%s) = %s", arg, res) return float_to_reg(res)
def IEEEDPExp(self,ctx): arg = regs_to_double(ctx.cpu.r_reg(REG_D0),ctx.cpu.r_reg(REG_D1)) try: res = math.exp(arg) except OverflowError: res = float('inf') log_math.info("DPExp(%s) = %s", arg, res) return double_to_regs(res)
def SPAbs(self, ctx): arg = ffp_reg_to_float(ctx.cpu.r_reg(REG_D0)) if arg < 0.0: res = -arg else: res = arg log_math.info("SPAbs(%s) = %s", arg, res) return float_to_ffp_reg(res)
def IEEEDPAbs(self, ctx): arg = regs_to_double(ctx.cpu.r_reg(REG_D0), ctx.cpu.r_reg(REG_D1)) if arg < 0.0: res = -arg else: res = arg log_math.info("DPAbs(%s) = %s", arg, res) return double_to_regs(res)
def IEEEDPPow(self,ctx): a = regs_to_double(ctx.cpu.r_reg(REG_D0),ctx.cpu.r_reg(REG_D1)) b = regs_to_double(ctx.cpu.r_reg(REG_D2),ctx.cpu.r_reg(REG_D3)) try: res = math.pow(a, b); except OverflowError: res = float('inf') log_math.info("DPPow(%s, %s) = %s", a, b, res) return double_to_regs(res)
def IEEESPPow(self, ctx): a = reg_to_float(ctx.cpu.r_reg(REG_D0)) b = reg_to_float(ctx.cpu.r_reg(REG_D1)) try: res = math.pow(a, b) except OverflowError: res = float('inf') log_math.info("SPPow(%s, %s) = %s", a, b, res) return float_to_reg(res)
def SPFix(self, ctx): arg = ffp_reg_to_float(ctx.cpu.r_reg(REG_D0)) if arg > Amiga_INT_MAX: arg = Amiga_INT_MAX elif arg < Amiga_INT_MIN: arg = Amiga_INT_MIN res = int(arg) log_math.info("SPFix(%s) = %s", arg, res) return res
def IEEEDPFix(self, ctx): arg = regs_to_double(ctx.cpu.r_reg(REG_D0), ctx.cpu.r_reg(REG_D1)) if arg > Amiga_INT_MAX: arg = Amiga_INT_MAX elif arg < Amiga_INT_MIN: arg = Amiga_INT_MIN res = int(arg) log_math.info("DPFix(%s) = %s", arg, res) return res
def IEEEDPTst(self, ctx): arg = regs_to_double(ctx.cpu.r_reg(REG_D0), ctx.cpu.r_reg(REG_D1)) if arg < 0.0: res = -1 elif arg > 0.0: res = +1 else: res = 0 log_math.info("DPTst(%s) = %s", arg, res) return res
def SPTst(self, ctx): arg = ffp_reg_to_float(ctx.cpu.r_reg(REG_D1)) if arg < 0.0: res = -1 elif arg > 0.0: res = +1 else: res = 0 log_math.info("SPTst(%s) = %s", arg, res) return res
def IEEEDPLog10(self,ctx): arg=regs_to_double(ctx.cpu.r_reg(REG_D0),ctx.cpu.r_reg(REG_D1)) try: if arg == 0.0: res = float('-inf') else: res = math.log10(arg) except ValueError: res = float('-nan') log_math.info("DPLog10(%s) = %s", arg, res) return double_to_regs(res)
def IEEESPLog10(self, ctx): arg = reg_to_float(ctx.cpu.r_reg(REG_D0)) try: if arg == 0.0: res = float('-inf') else: res = math.log10(arg) except ValueError: res = float('-nan') log_math.info("SPLog10(%s) = %s", arg, res) return float_to_reg(res)
def IEEEDPCmp(self, ctx): arg1 = regs_to_double(ctx.cpu.r_reg(REG_D0), ctx.cpu.r_reg(REG_D1)) arg2 = regs_to_double(ctx.cpu.r_reg(REG_D2), ctx.cpu.r_reg(REG_D3)) if arg1 < arg2: res = -1 elif arg1 > arg2: res = +1 else: res = 0 log_math.info("DPCmp(%s, %s) = %s", arg1, arg2, res) return res
def IEEESPAsin(self, ctx): arg = reg_to_float(ctx.cpu.r_reg(REG_D0)) try: res = math.asin(arg) except ValueError: if arg < 0.0: res = float('nan') else: res = float('-nan') log_math.info("SPAsin(%s) = %s", arg, res) return float_to_reg(res)
def IEEESPSinh(self, ctx): arg = reg_to_float(ctx.cpu.r_reg(REG_D0)) try: res = math.sinh(arg) except OverflowError: if arg < 0: res = float('-inf') else: res = float('inf') log_math.info("SPSinh(%s) = %s", arg, res) return float_to_reg(res)
def IEEEDPSinh(self,ctx): arg = regs_to_double(ctx.cpu.r_reg(REG_D0),ctx.cpu.r_reg(REG_D1)) try: res = math.sinh(arg) except OverflowError: if arg<0: res = float('-inf') else: res = float('inf') log_math.info("DPSinh(%s) = %s", arg, res) return double_to_regs(res)
def SPCmp(self, ctx): arg1 = ffp_reg_to_float(ctx.cpu.r_reg(REG_D1)) arg2 = ffp_reg_to_float(ctx.cpu.r_reg(REG_D0)) if arg1 < arg2: res = -1 elif arg1 > arg2: res = +1 else: res = 0 log_math.info("SPCmp(%s, %s) = %s", arg1, arg2, res) return res
def IEEESPSincos(self, ctx): ptr = ctx.cpu.r_reg(REG_A0) arg = reg_to_float(ctx.cpu.r_reg(REG_D0)) res_sin = math.sin(arg) res_cos = math.cos(arg) log_math.info("SPSincos(%s) = %s, %s", arg, res_sin, res_cos) vals_sin = float_to_reg(res_sin) vals_cos = float_to_reg(res_cos) #write cos to ptr ctx.mem.w32(ptr, vals_cos) return vals_sin
def IEEEDPSincos(self,ctx): ptr = ctx.cpu.r_reg(REG_A0) arg = regs_to_double(ctx.cpu.r_reg(REG_D0),ctx.cpu.r_reg(REG_D1)) res_sin = math.sin(arg) res_cos = math.cos(arg) log_math.info("DPSincos(%s) = %s, %s", arg, res_sin, res_cos) vals_sin = double_to_regs(res_sin) vals_cos = double_to_regs(res_cos) #write cos to ptr ctx.mem.w32(ptr, vals_cos[0]) ctx.mem.w32(ptr+4, vals_cos[1]) return vals_sin
def SPDiv(self, ctx): arg1 = ffp_reg_to_float(ctx.cpu.r_reg(REG_D0)) arg2 = ffp_reg_to_float(ctx.cpu.r_reg(REG_D1)) if arg2 == 0.0: if arg1 == 0.0: # Amiga returns sign bit set on nan... res = float('-nan') elif arg1 > 0.0: res = float('inf') else: res = float('-inf') else: res = arg1 / arg2 log_math.info("SPDiv(%s, %s) = %s", arg1, arg2, res) return float_to_ffp_reg(res)
def IEEEDPDiv(self, ctx): arg1 = regs_to_double(ctx.cpu.r_reg(REG_D0), ctx.cpu.r_reg(REG_D1)) arg2 = regs_to_double(ctx.cpu.r_reg(REG_D2), ctx.cpu.r_reg(REG_D3)) if arg2 == 0.0: if arg1 == 0.0: # Amiga returns sign bit set on nan... res = float('-nan') elif arg1 > 0.0: res = float('inf') else: res = float('-inf') else: res = arg1 / arg2 log_math.info("DPDiv(%s, %s) = %s", arg1, arg2, res) return double_to_regs(res)
def SPCeil(self, ctx): arg = ffp_reg_to_float(ctx.cpu.r_reg(REG_D0)) res = math.ceil(arg) log_math.info("SPCeil(%s) = %s", arg, res) return float_to_ffp_reg(res)
def SPMul(self, ctx): arg1 = ffp_reg_to_float(ctx.cpu.r_reg(REG_D0)) arg2 = ffp_reg_to_float(ctx.cpu.r_reg(REG_D1)) res = arg1 * arg2 log_math.info("SPMul(%s, %s) = %s", arg1, arg2, res) return float_to_ffp_reg(res)
def SPFlt(self, ctx): i = int32(ctx.cpu.r_reg(REG_D0)) d = float(i) log_math.info("SPFlt(%s) = %s", i, d) return float_to_ffp_reg(d)