MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / read_f32

Method read_f32

crates/virtual-machine/src/cpu/registers.rs:62–68  ·  view source on GitHub ↗

Reads the register as an f32, applying NaN-boxing validation. If bits [63:32] are not all 1s the stored value is not a valid NaN-boxed f32, so the canonical NaN is returned (RISC-V spec 11.3).

(&self, reg: usize)

Source from the content-addressed store, hash-verified

60 pub fn read_f32(&self, reg: usize) -> f32 {
61 let bits = self.f[reg];
62 if bits & NAN_BOX_UPPER != NAN_BOX_UPPER {
63 return f32::NAN;
64 }
65 f32::from_bits(bits as u32)
66 }
67
68 /// Writes an f32, NaN-boxing it by setting bits `63:32` to all 1s.
69 pub fn write_f32(&mut self, reg: usize, val: f32) {
70 self.f[reg] = NAN_BOX_UPPER | u64::from(val.to_bits());
71 }

Callers 4

exec_fp_opFunction · 0.80
exec_fmacFunction · 0.80
fp_nan_box_invalid_upperFunction · 0.80

Calls

no outgoing calls

Tested by 2

fp_nan_box_invalid_upperFunction · 0.64