basic float arith, wip float trig, abs

This commit is contained in:
2020-10-17 23:58:24 +02:00
parent e560fc5657
commit 68c9b33637
10 changed files with 521 additions and 36 deletions
+1 -1
View File
@@ -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
View File
@@ -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
+1 -1
View File
@@ -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()?;
+7
View File
@@ -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 {
+7
View File
@@ -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)