Function
exec_alu
(
funct3: u8,
funct7: u8,
rd: usize,
rs1: usize,
rs2: usize,
regs: &Registers,
pc: u64,
)
Source from the content-addressed store, hash-verified
| 423 | } |
| 424 | |
| 425 | fn exec_alu( |
| 426 | funct3: u8, |
| 427 | funct7: u8, |
| 428 | rd: usize, |
| 429 | rs1: usize, |
| 430 | rs2: usize, |
| 431 | regs: &Registers, |
| 432 | pc: u64, |
| 433 | ) -> Result<ExecResult, VmError> { |
| 434 | let a = regs.read_x(rs1); |
| 435 | let b = regs.read_x(rs2); |
| 436 | let result = match funct7 { |
| 437 | 0x00 => match funct3 { |
| 438 | 0 => alu::add(a, b), |
| 439 | 1 => alu::sll(a, b), |
| 440 | 2 => alu::slt(a, b), |
| 441 | 3 => alu::sltu(a, b), |
| 442 | 4 => alu::xor(a, b), |
| 443 | 5 => alu::srl(a, b), |
| 444 | 6 => alu::or(a, b), |
| 445 | 7 => alu::and(a, b), |
| 446 | _ => return Err(VmError::IllegalInstruction(funct3 as u32)), |
| 447 | }, |
| 448 | 0x20 => match funct3 { |
| 449 | 0 => alu::sub(a, b), |
| 450 | 5 => alu::sra(a, b), |
| 451 | _ => return Err(VmError::IllegalInstruction(funct3 as u32)), |
| 452 | }, |
| 453 | 0x01 => match funct3 { |
| 454 | 0 => alu::mul(a, b), |
| 455 | 1 => alu::mulh(a, b), |
| 456 | 2 => alu::mulhsu(a, b), |
| 457 | 3 => alu::mulhu(a, b), |
| 458 | 4 => alu::div(a, b), |
| 459 | 5 => alu::divu(a, b), |
| 460 | 6 => alu::rem(a, b), |
| 461 | 7 => alu::remu(a, b), |
| 462 | _ => return Err(VmError::IllegalInstruction(funct3 as u32)), |
| 463 | }, |
| 464 | _ => return Err(VmError::IllegalInstruction(funct7 as u32)), |
| 465 | }; |
| 466 | Ok(ExecResult::WriteInt { |
| 467 | rd, |
| 468 | val: result, |
| 469 | next_pc: pc.wrapping_add(4), |
| 470 | }) |
| 471 | } |
| 472 | |
| 473 | fn exec_alu32( |
| 474 | funct3: u8, |
Tested by
no test coverage detected