Skip to content

Commit

Permalink
x86: move conversion CondCodeCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
soc committed Sep 28, 2023
1 parent 299ea26 commit ad131b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
21 changes: 21 additions & 0 deletions dora/src/cpu/x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use lazy_static::lazy_static;
use std::sync::atomic::{compiler_fence, Ordering};

use crate::language::ty::SourceType;
use crate::masm::CondCode;
use dora_asm::x64::Condition;
use dora_asm::x64::Register;

pub fn flush_icache(_: *const u8, _: usize) {
Expand Down Expand Up @@ -164,6 +166,25 @@ impl FReg {
}
}

impl From<CondCode> for Condition {
fn from(cond: CondCode) -> Condition {
match cond {
CondCode::Zero => Condition::Zero,
CondCode::NonZero => Condition::NotZero,
CondCode::Equal => Condition::Equal,
CondCode::NotEqual => Condition::NotEqual,
CondCode::Less => Condition::Less,
CondCode::LessEq => Condition::LessOrEqual,
CondCode::Greater => Condition::Greater,
CondCode::GreaterEq => Condition::GreaterOrEqual,
CondCode::UnsignedGreater => Condition::Above, // above
CondCode::UnsignedGreaterEq => Condition::AboveOrEqual, // above or equal
CondCode::UnsignedLess => Condition::Below, // below
CondCode::UnsignedLessEq => Condition::BelowOrEqual, // below or equal
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
21 changes: 2 additions & 19 deletions dora/src/masm/x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl MacroAssembler {
}

pub fn set(&mut self, dest: Reg, cond: CondCode) {
self.asm.setcc_r(convert_into_condition(cond), dest.into());
self.asm.setcc_r(cond.into(), dest.into());
self.asm.movzxb_rr(dest.into(), dest.into());
}

Expand Down Expand Up @@ -390,7 +390,7 @@ impl MacroAssembler {
}

pub fn jump_if(&mut self, cond: CondCode, target: Label) {
self.asm.jcc(convert_into_condition(cond), target)
self.asm.jcc(cond.into(), target)
}

pub fn jump(&mut self, target: Label) {
Expand Down Expand Up @@ -1550,23 +1550,6 @@ impl MacroAssembler {
}
}

fn convert_into_condition(cond: CondCode) -> Condition {
match cond {
CondCode::Zero => Condition::Zero,
CondCode::NonZero => Condition::NotZero,
CondCode::Equal => Condition::Equal,
CondCode::NotEqual => Condition::NotEqual,
CondCode::Less => Condition::Less,
CondCode::LessEq => Condition::LessOrEqual,
CondCode::Greater => Condition::Greater,
CondCode::GreaterEq => Condition::GreaterOrEqual,
CondCode::UnsignedGreater => Condition::Above, // above
CondCode::UnsignedGreaterEq => Condition::AboveOrEqual, // above or equal
CondCode::UnsignedLess => Condition::Below, // below
CondCode::UnsignedLessEq => Condition::BelowOrEqual, // below or equal
}
}

impl From<FReg> for XmmRegister {
fn from(reg: FReg) -> XmmRegister {
XmmRegister::new(reg.0)
Expand Down

0 comments on commit ad131b0

Please sign in to comment.