Actually make MovType work

This commit is contained in:
Pyrex 2023-06-23 21:19:54 -07:00
parent acd0fd1b25
commit ff86792d69

View File

@ -40,6 +40,15 @@ pub enum ExitInstruction {
} }
pub enum MovType { Mov, Add, Xor } pub enum MovType { Mov, Add, Xor }
impl MovType {
fn merge(&self, old_value: Sample, new_value: Sample) -> Sample {
match self {
MovType::Mov => new_value,
MovType::Add => Sample(old_value.0 + new_value.0),
MovType::Xor => Sample(old_value.0 ^ new_value.0)
}
}
}
#[derive(Clone, Copy)] pub enum MovDst { L(RegL), R(RegR), Z(RegZ), Ix } #[derive(Clone, Copy)] pub enum MovDst { L(RegL), R(RegR), Z(RegZ), Ix }
#[derive(Clone, Copy)] pub enum MovSrc { A(RegA), L(RegL), R(RegR), Z(RegZ), Ix, Imm(Sample) } #[derive(Clone, Copy)] pub enum MovSrc { A(RegA), L(RegL), R(RegR), Z(RegZ), Ix, Imm(Sample) }
@ -155,20 +164,20 @@ impl Scope {
} }
MovDst::R(RegR(r)) => { MovDst::R(RegR(r)) => {
let r = r as usize; let r = r as usize;
self.reg_rs[r] = value; return self.reg_rs[r] = ty.merge(self.reg_rs[r], value); return
} }
MovDst::Z(RegZ(z)) => { MovDst::Z(RegZ(z)) => {
let z = z as usize; let z = z as usize;
(&mut self.reg_zs[z], &self.loop_zs[z]) (&mut self.reg_zs[z], &self.loop_zs[z])
} }
MovDst::Ix => { self.ix = value; return } MovDst::Ix => { self.ix = ty.merge(self.ix, value); return }
}; };
let mut ix = flat_ix + offset; let mut ix = flat_ix + offset;
if loop_.length != 0 { ix %= loop_.length; } if loop_.length != 0 { ix %= loop_.length; }
ix += chan.formal().start + loop_.start; ix += chan.formal().start + loop_.start;
chan[ix] = value chan[ix] = ty.merge(chan[ix], value)
} }
fn replace(&mut self, dst: OupDst, value: Channel) { fn replace(&mut self, dst: OupDst, value: Channel) {