forked from MightyPork/crsn
basic float arith, wip float trig, abs
This commit is contained in:
@@ -9,7 +9,7 @@ pub type Value = u64;
|
||||
|
||||
#[inline(always)]
|
||||
pub const fn is_positive(val: Value) -> bool {
|
||||
0 == (val & 0x8000_0000_0000_0000)
|
||||
0 == (val & 0x8000_0000_0000_0000) && val != 0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
||||
+19
-2
@@ -14,11 +14,28 @@ impl Rd {
|
||||
pub const fn new(src: RdData) -> Self {
|
||||
Rd(src)
|
||||
}
|
||||
pub const fn immediate(val: Value) -> Rd {
|
||||
|
||||
pub const fn new_imm(val: Value) -> Rd {
|
||||
Rd(RdData::Immediate(val))
|
||||
}
|
||||
|
||||
pub fn is_immediate_equal(self, other: Value) -> bool {
|
||||
/// Construct new from float
|
||||
pub fn new_float(val: f64) -> Rd { // TODO const when stabilized
|
||||
Rd(RdData::Immediate(val.to_bits()))
|
||||
}
|
||||
|
||||
/// Convert immediate read to float
|
||||
pub fn imm_to_float(self) -> Rd {
|
||||
match self {
|
||||
Rd(RdData::Immediate(v)) => {
|
||||
let signed : i64 = unsafe { std::mem::transmute(v) };
|
||||
Rd::new_float(signed as f64)
|
||||
}
|
||||
other => other
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_imm_equal(self, other: Value) -> bool {
|
||||
match self.0 {
|
||||
RdData::Immediate(val) => {
|
||||
val == other
|
||||
|
||||
@@ -291,7 +291,7 @@ impl<'a> TokenParser<'a> {
|
||||
pub fn parse_wr_rd_rd_or_n(&mut self, n : Value) -> Result<(Wr, Rd, Rd), CrsnError> {
|
||||
if self.len() == 1 {
|
||||
let rw = self.next_rdwr()?;
|
||||
Ok((rw.wr(), rw.rd(), Rd::immediate(n)))
|
||||
Ok((rw.wr(), rw.rd(), Rd::new_imm(n)))
|
||||
} else if self.len() == 2 {
|
||||
let rw = self.next_rdwr()?;
|
||||
let rd = self.next_rd()?;
|
||||
|
||||
@@ -78,6 +78,13 @@ impl StatusFlags {
|
||||
self.negative = is_negative(val);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn update_float(&mut self, val: f64) {
|
||||
self.zero = val == 0.0;
|
||||
self.positive = val > 0.0;
|
||||
self.negative = val < 0.0;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn test(&self, cond: Cond) -> bool {
|
||||
match cond {
|
||||
|
||||
@@ -102,6 +102,13 @@ impl RunState {
|
||||
self.frame.status.update(val);
|
||||
}
|
||||
|
||||
/// Update status flags using a variable.
|
||||
/// The update is additive - call `clear_status()` first if desired!
|
||||
#[inline(always)]
|
||||
pub fn update_status_float(&mut self, val: f64) {
|
||||
self.frame.status.update_float(val);
|
||||
}
|
||||
|
||||
/// Read object handle value
|
||||
pub fn read_obj(&mut self, rdo: impl Into<RdObj>) -> Result<Value, Fault> {
|
||||
rdo.into().read(self)
|
||||
|
||||
Reference in New Issue
Block a user