📝 Documentation updates for machine.rs
This commit is contained in:
parent
cc6aab7c3f
commit
bee0e8ce71
@ -109,6 +109,7 @@ pub struct Machine {
|
|||||||
|
|
||||||
impl Machine {
|
impl Machine {
|
||||||
|
|
||||||
|
/// Machine constructor
|
||||||
pub fn init_machine() -> Machine {
|
pub fn init_machine() -> Machine {
|
||||||
let mut shiftmask : [u64 ; 64] = [0 ; 64];
|
let mut shiftmask : [u64 ; 64] = [0 ; 64];
|
||||||
let mut value : u64 = 0xffffffff;
|
let mut value : u64 = 0xffffffff;
|
||||||
@ -195,6 +196,11 @@ impl Machine {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Print the status of the machine to the standard output
|
||||||
|
///
|
||||||
|
/// ### Parameters
|
||||||
|
///
|
||||||
|
/// - **machine** the machine to get the status from
|
||||||
pub fn print_machine_status(machine: &mut Machine) {
|
pub fn print_machine_status(machine: &mut Machine) {
|
||||||
println!("######### Machine status #########");
|
println!("######### Machine status #########");
|
||||||
for i in (0..32).step_by(3) {
|
for i in (0..32).step_by(3) {
|
||||||
@ -213,6 +219,11 @@ impl Machine {
|
|||||||
println!("##################################");
|
println!("##################################");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the state of the registers as a string
|
||||||
|
///
|
||||||
|
/// ### Parameters
|
||||||
|
///
|
||||||
|
/// - **machine** the machine to read the registers from
|
||||||
pub fn string_registers(machine: &mut Machine) -> String {
|
pub fn string_registers(machine: &mut Machine) -> String {
|
||||||
let mut s = String::from("");
|
let mut s = String::from("");
|
||||||
for i in 0..32 {
|
for i in 0..32 {
|
||||||
@ -554,7 +565,8 @@ impl Machine {
|
|||||||
} else {
|
} else {
|
||||||
machine.fp_reg.set_reg(inst.rd as usize, -local_float)
|
machine.fp_reg.set_reg(inst.rd as usize, -local_float)
|
||||||
},
|
},
|
||||||
RISCV_FP_FSGN_JX => if (machine.fp_reg.get_reg(inst.rs2 as usize) < 0.0 && machine.fp_reg.get_reg(inst.rs1 as usize) >= 0.0) || (machine.fp_reg.get_reg(inst.rs2 as usize) >= 0.0 && machine.fp_reg.get_reg(inst.rs1 as usize) < 0.0) {
|
RISCV_FP_FSGN_JX => if (machine.fp_reg.get_reg(inst.rs2 as usize) < 0.0 && machine.fp_reg.get_reg(inst.rs1 as usize) >= 0.0) ||
|
||||||
|
(machine.fp_reg.get_reg(inst.rs2 as usize) >= 0.0 && machine.fp_reg.get_reg(inst.rs1 as usize) < 0.0) {
|
||||||
machine.fp_reg.set_reg(inst.rd as usize, -local_float)
|
machine.fp_reg.set_reg(inst.rd as usize, -local_float)
|
||||||
} else {
|
} else {
|
||||||
machine.fp_reg.set_reg(inst.rd as usize, local_float)
|
machine.fp_reg.set_reg(inst.rd as usize, local_float)
|
||||||
@ -608,7 +620,7 @@ impl Machine {
|
|||||||
|
|
||||||
/// print memory FOR DEBUG
|
/// print memory FOR DEBUG
|
||||||
///
|
///
|
||||||
/// "@"adresse [16 bytes]
|
/// "@"adress [16 bytes]
|
||||||
pub fn _print_memory(machine : &mut Machine, from: usize, to: usize) {
|
pub fn _print_memory(machine : &mut Machine, from: usize, to: usize) {
|
||||||
for i in from..to {
|
for i in from..to {
|
||||||
if i%16 == 0 {
|
if i%16 == 0 {
|
||||||
@ -619,18 +631,22 @@ impl Machine {
|
|||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get value from int register
|
||||||
pub fn read_int_register(&self, index: usize) -> i64 {
|
pub fn read_int_register(&self, index: usize) -> i64 {
|
||||||
self.int_reg.get_reg(index)
|
self.int_reg.get_reg(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get value from float register
|
||||||
pub fn read_fp_register(&self, index: usize) -> f32 {
|
pub fn read_fp_register(&self, index: usize) -> f32 {
|
||||||
self.fp_reg.get_reg(index)
|
self.fp_reg.get_reg(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Write into int register
|
||||||
pub fn write_int_register(&mut self, index: usize, value: i64) {
|
pub fn write_int_register(&mut self, index: usize, value: i64) {
|
||||||
self.int_reg.set_reg(index, value);
|
self.int_reg.set_reg(index, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Write info float register
|
||||||
pub fn write_fp_register(&mut self, index: usize, value: f32) {
|
pub fn write_fp_register(&mut self, index: usize, value: f32) {
|
||||||
self.fp_reg.set_reg(index, value);
|
self.fp_reg.set_reg(index, value);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user