def execute_amominu_w(s, inst): addr = s.rf[inst.rs1] value = s.mem.read(addr, 4) new = min(value, s.rf[inst.rs2]) s.mem.write(addr, 4, trim(new, 32)) s.rf[inst.rd] = sext_32(value) s.pc += 4
def execute_amomax_w(s, inst): addr = s.rf[inst.rs1] value = s.mem.read(addr, 4) new = max(signed(value, 32), signed(s.rf[inst.rs2], 32)) s.mem.write(addr, 4, trim(new, 32)) s.rf[inst.rd] = sext_32(value) s.pc += 4
def execute_amomax_w( s, inst ): addr = s.rf[inst.rs1] value = s.mem.read( addr, 4 ) new = max( signed(value, 32), signed(s.rf[inst.rs2], 32) ) s.mem.write( addr, 4, trim(new, 32)) s.rf[inst.rd] = sext_32( value ) s.pc += 4
def execute_amominu_w( s, inst ): addr = s.rf[inst.rs1] value = s.mem.read( addr, 4 ) new = min( value, s.rf[inst.rs2] ) s.mem.write( addr, 4, trim(new, 32)) s.rf[inst.rd] = sext_32( value ) s.pc += 4
def execute_remuw(s, inst): a = s.rf[inst.rs1] b = s.rf[inst.rs2] if b == 0: s.rf[inst.rd] = a else: s.rf[inst.rd] = sext_32(a % b) s.pc += 4
def execute_srai( s, inst ): if s.xlen == 64: s.rf[ inst.rd ] = signed( s.rf[inst.rs1], 64 ) >> SHAMT( s, inst ) elif SHAMT( s, inst ) & 0x20: raise TRAP_ILLEGAL_INSTRUCTION() else: s.rf[ inst.rd ] = sext_32( s.rf[inst.rs1] >> SHAMT( s, inst ) ) s.pc += 4
def execute_srai(s, inst): if s.xlen == 64: s.rf[inst.rd] = signed(s.rf[inst.rs1], 64) >> SHAMT(s, inst) elif SHAMT(s, inst) & 0x20: raise TRAP_ILLEGAL_INSTRUCTION() else: s.rf[inst.rd] = sext_32(s.rf[inst.rs1] >> SHAMT(s, inst)) s.pc += 4
def execute_divuw(s, inst): a = s.rf[inst.rs1] b = s.rf[inst.rs2] if b == 0: s.rf[inst.rd] = -1 else: s.rf[inst.rd] = sext_32(a / b) s.pc += 4
def execute_remuw( s, inst ): a = s.rf[inst.rs1] b = s.rf[inst.rs2] if b == 0: s.rf[ inst.rd ] = a else: s.rf[ inst.rd ] = sext_32( a % b ) s.pc += 4
def execute_divuw( s, inst ): a = s.rf[inst.rs1] b = s.rf[inst.rs2] if b == 0: s.rf[ inst.rd ] = -1 else: s.rf[ inst.rd ] = sext_32( a / b ) s.pc += 4
def execute_remw( s, inst ): a = signed( s.rf[inst.rs1], 64 ) b = signed( s.rf[inst.rs2], 64 ) if b == 0: s.rf[ inst.rd ] = a else: sign = 1 if (a > 0) else -1 s.rf[ inst.rd ] = sext_32( abs(a) % abs(b) * sign ) s.pc += 4
def execute_remw(s, inst): a = signed(s.rf[inst.rs1], 64) b = signed(s.rf[inst.rs2], 64) if b == 0: s.rf[inst.rd] = a else: sign = 1 if (a > 0) else -1 s.rf[inst.rd] = sext_32(abs(a) % abs(b) * sign) s.pc += 4
def execute_divw( s, inst ): a = signed( s.rf[inst.rs1], 64 ) b = signed( s.rf[inst.rs2], 64 ) if b == 0: s.rf[ inst.rd ] = -1 else: sign = -1 if (a < 0) ^ (b < 0) else 1 s.rf[ inst.rd ] = sext_32( abs(a) / abs(b) * sign ) s.pc += 4
def execute_divw(s, inst): a = signed(s.rf[inst.rs1], 64) b = signed(s.rf[inst.rs2], 64) if b == 0: s.rf[inst.rd] = -1 else: sign = -1 if (a < 0) ^ (b < 0) else 1 s.rf[inst.rd] = sext_32(abs(a) / abs(b) * sign) s.pc += 4
def execute_sllw( s, inst ): s.rf[ inst.rd ] = sext_32( s.rf[inst.rs1] << (s.rf[inst.rs2] & 0x1F ) ) s.pc += 4
def execute_lw(s, inst): addr = trim_64(s.rf[inst.rs1] + inst.i_imm) s.rf[inst.rd] = sext_32(s.mem.read(addr, 4)) s.pc += 4
def execute_sllw(s, inst): s.rf[inst.rd] = sext_32(s.rf[inst.rs1] << (s.rf[inst.rs2] & 0x1F)) s.pc += 4
def execute_sraw(s, inst): s.rf[inst.rd] = sext_32(s.rf[inst.rs1] >> (s.rf[inst.rs2] & 0x1F)) s.pc += 4
def execute_mulw(s, inst): s.rf[inst.rd] = sext_32(s.rf[inst.rs1] * s.rf[inst.rs2]) s.pc += 4
def u_imm(self): return sext_32(self.bits) >> 12 << 12
def execute_fcvt_wu_s( s, inst ): s.rf[inst.rd] = sext_32(sfp.f32_to_ui32( s.fp[inst.rs1], inst.rm, True )) s.fcsr = sfp.get_flags() sfp.set_flags( 0 ) s.pc += 4
def execute_fmv_x_s(s, inst): s.rf[inst.rd] = sext_32(s.fp[inst.rs1]) s.pc += 4
def execute_slliw(s, inst): s.rf[inst.rd] = sext_32(s.rf[inst.rs1] << SHAMT(s, inst)) s.pc += 4
def execute_fsqrt_s(s, inst): a = trim_32(s.fp[inst.rs1]) s.fp[inst.rd] = sext_32(sfp.f32_sqrt(a)) s.fcsr = sfp.get_flags() sfp.set_flags(0) s.pc += 4
def execute_fcvt_wu_s(s, inst): s.rf[inst.rd] = sext_32(sfp.f32_to_ui32(s.fp[inst.rs1], inst.rm, True)) s.fcsr = sfp.get_flags() sfp.set_flags(0) s.pc += 4
def execute_srliw(s, inst): s.rf[inst.rd] = sext_32(trim_32(s.rf[inst.rs1]) >> SHAMT(s, inst)) s.pc += 4
def execute_amoand_w(s, inst): addr = s.rf[inst.rs1] value = s.mem.read(addr, 4) s.mem.write(addr, 4, trim(value & s.rf[inst.rs2], 32)) s.rf[inst.rd] = sext_32(value) s.pc += 4
def execute_addw(s, inst): s.rf[inst.rd] = sext_32(s.rf[inst.rs1] + s.rf[inst.rs2]) s.pc += 4
def execute_srlw( s, inst ): s.rf[ inst.rd ] = sext_32( trim_32( s.rf[inst.rs1] ) >> (s.rf[inst.rs2] & 0x1F) ) s.pc += 4
def execute_addiw(s, inst): s.rf[inst.rd] = sext_32(inst.i_imm + s.rf[inst.rs1]) s.pc += 4
def execute_sraw( s, inst ): s.rf[ inst.rd ] = sext_32( s.rf[inst.rs1] >> (s.rf[inst.rs2] & 0x1F) ) s.pc += 4
def execute_fsub_s( s, inst ): a, b = trim_32( s.fp[inst.rs1] ), trim_32( s.fp[inst.rs2] ) s.fp[ inst.rd ] = sext_32( sfp.f32_sub( a, b ) ) s.fcsr = sfp.get_flags() sfp.set_flags( 0 ) s.pc += 4
def execute_fsqrt_s( s, inst ): a = trim_32( s.fp[inst.rs1] ) s.fp[ inst.rd ] = sext_32( sfp.f32_sqrt( a ) ) s.fcsr = sfp.get_flags() sfp.set_flags( 0 ) s.pc += 4
def execute_srl(s, inst): if s.xlen == 64: s.rf[inst.rd] = s.rf[inst.rs1] >> (s.rf[inst.rs2] & 0x3F) else: s.rf[inst.rd] = sext_32(s.rf[inst.rs1] >> (s.rf[inst.rs2] & 0x1F)) s.pc += 4
def execute_fmv_x_s( s, inst ): s.rf[inst.rd] = sext_32( s.fp[inst.rs1] ) s.pc += 4
def execute_srlw(s, inst): s.rf[inst.rd] = sext_32(trim_32(s.rf[inst.rs1]) >> (s.rf[inst.rs2] & 0x1F)) s.pc += 4
def execute_lw( s, inst ): addr = trim_64( s.rf[inst.rs1] + inst.i_imm ) s.rf[inst.rd] = sext_32( s.mem.read( addr, 4 ) ) s.pc += 4
def execute_slliw( s, inst ): s.rf[ inst.rd ] = sext_32( s.rf[inst.rs1] << SHAMT( s, inst ) ) s.pc += 4
def execute_srl( s, inst ): if s.xlen == 64: s.rf[ inst.rd ] = s.rf[inst.rs1] >> (s.rf[inst.rs2] & 0x3F) else: s.rf[ inst.rd ] = sext_32( s.rf[inst.rs1] >> (s.rf[inst.rs2] & 0x1F) ) s.pc += 4
def execute_srliw( s, inst ): s.rf[ inst.rd ] = sext_32( trim_32( s.rf[inst.rs1] ) >> SHAMT( s, inst ) ) s.pc += 4
def execute_addw( s, inst ): s.rf[ inst.rd ] = sext_32( s.rf[inst.rs1] + s.rf[inst.rs2] ) s.pc += 4
def execute_subw( s, inst ): s.rf[ inst.rd ] = sext_32( s.rf[inst.rs1] - s.rf[inst.rs2]) s.pc += 4
def execute_fadd_s(s, inst): a, b = trim_32(s.fp[inst.rs1]), trim_32(s.fp[inst.rs2]) s.fp[inst.rd] = sext_32(sfp.f32_add(a, b)) s.fcsr = sfp.get_flags() sfp.set_flags(0) s.pc += 4
def execute_subw(s, inst): s.rf[inst.rd] = sext_32(s.rf[inst.rs1] - s.rf[inst.rs2]) s.pc += 4
def execute_amoand_w( s, inst ): addr = s.rf[inst.rs1] value = s.mem.read( addr, 4 ) s.mem.write( addr, 4, trim(value & s.rf[inst.rs2], 32)) s.rf[inst.rd] = sext_32( value ) s.pc += 4
def execute_addiw( s, inst ): s.rf[ inst.rd ] = sext_32( inst.i_imm + s.rf[inst.rs1] ) s.pc += 4
def execute_mulw( s, inst ): s.rf[ inst.rd ] = sext_32( s.rf[inst.rs1] * s.rf[inst.rs2]) s.pc += 4