mod arg_mode;
mod has_alu;
pub mod semantics;
pub use arg_mode::{ArgMode, BinaryArgMode, TernaryArgMode};
pub use has_alu::HasAlu;
pub use semantics::{HasBinaryOp, HasTernaryOp, HasUnaryOp};
use std::fmt::{self, Display, Formatter};
use super::alu::{FpMulAlu, RngdAlu};
use furiosa_opt_macro::primitive;
#[primitive(op::LogicBinaryOpI32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LogicBinaryOpI32 {
BitAnd,
BitOr,
BitXor,
LeftShift,
LogicRightShift,
ArithRightShift,
}
impl Display for LogicBinaryOpI32 {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::BitAnd => write!(f, "LogicBinaryOpI32::BitAnd"),
Self::BitOr => write!(f, "LogicBinaryOpI32::BitOr"),
Self::BitXor => write!(f, "LogicBinaryOpI32::BitXor"),
Self::LeftShift => write!(f, "LogicBinaryOpI32::LeftShift"),
Self::LogicRightShift => write!(f, "LogicBinaryOpI32::LogicRightShift"),
Self::ArithRightShift => write!(f, "LogicBinaryOpI32::ArithRightShift"),
}
}
}
impl LogicBinaryOpI32 {
pub(crate) fn alu(&self) -> RngdAlu {
match self {
Self::BitAnd => RngdAlu::LogicAnd,
Self::BitOr => RngdAlu::LogicOr,
Self::BitXor => RngdAlu::LogicXor,
Self::LeftShift => RngdAlu::LogicLshift,
Self::LogicRightShift | Self::ArithRightShift => RngdAlu::LogicRshift,
}
}
}
#[primitive(op::LogicBinaryOpF32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LogicBinaryOpF32 {
BitAnd,
BitOr,
BitXor,
}
impl Display for LogicBinaryOpF32 {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::BitAnd => write!(f, "LogicBinaryOpF32::BitAnd"),
Self::BitOr => write!(f, "LogicBinaryOpF32::BitOr"),
Self::BitXor => write!(f, "LogicBinaryOpF32::BitXor"),
}
}
}
impl LogicBinaryOpF32 {
pub(crate) fn alu(&self) -> RngdAlu {
match self {
Self::BitAnd => RngdAlu::LogicAnd,
Self::BitOr => RngdAlu::LogicOr,
Self::BitXor => RngdAlu::LogicXor,
}
}
}
#[primitive(op::FxpBinaryOp)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FxpBinaryOp {
AddFxp,
AddFxpSat,
SubFxp,
SubFxpSat,
LeftShift,
LeftShiftSat,
MulFxp,
MulInt,
LogicRightShift,
ArithRightShift,
ArithRightShiftRound,
}
impl Display for FxpBinaryOp {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::AddFxp => write!(f, "FxpBinaryOp::AddFxp"),
Self::AddFxpSat => write!(f, "FxpBinaryOp::AddFxpSat"),
Self::SubFxp => write!(f, "FxpBinaryOp::SubFxp"),
Self::SubFxpSat => write!(f, "FxpBinaryOp::SubFxpSat"),
Self::LeftShift => write!(f, "FxpBinaryOp::LeftShift"),
Self::LeftShiftSat => write!(f, "FxpBinaryOp::LeftShiftSat"),
Self::MulFxp => write!(f, "FxpBinaryOp::MulFxp"),
Self::MulInt => write!(f, "FxpBinaryOp::MulInt"),
Self::LogicRightShift => write!(f, "FxpBinaryOp::LogicRightShift"),
Self::ArithRightShift => write!(f, "FxpBinaryOp::ArithRightShift"),
Self::ArithRightShiftRound => write!(f, "FxpBinaryOp::ArithRightShiftRound"),
}
}
}
impl FxpBinaryOp {
pub(crate) fn alu(&self) -> RngdAlu {
match self {
Self::AddFxp | Self::AddFxpSat | Self::SubFxp | Self::SubFxpSat => RngdAlu::FxpAdd,
Self::LeftShift | Self::LeftShiftSat => RngdAlu::FxpLshift,
Self::MulFxp | Self::MulInt => RngdAlu::FxpMul,
Self::LogicRightShift | Self::ArithRightShift | Self::ArithRightShiftRound => RngdAlu::FxpRshift,
}
}
}
#[primitive(op::FpUnaryOp)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FpUnaryOp {
Exp,
NegExp,
Sqrt,
Tanh,
Sigmoid,
Erf,
Log,
Sin,
Cos,
}
impl Display for FpUnaryOp {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Exp => write!(f, "FpUnaryOp::Exp"),
Self::NegExp => write!(f, "FpUnaryOp::NegExp"),
Self::Sqrt => write!(f, "FpUnaryOp::Sqrt"),
Self::Tanh => write!(f, "FpUnaryOp::Tanh"),
Self::Sigmoid => write!(f, "FpUnaryOp::Sigmoid"),
Self::Erf => write!(f, "FpUnaryOp::Erf"),
Self::Log => write!(f, "FpUnaryOp::Log"),
Self::Sin => write!(f, "FpUnaryOp::Sin"),
Self::Cos => write!(f, "FpUnaryOp::Cos"),
}
}
}
impl FpUnaryOp {
pub(crate) fn alu(&self) -> RngdAlu {
match self {
Self::Exp | Self::NegExp => RngdAlu::FpExp,
_ => RngdAlu::FpFpu,
}
}
}
#[primitive(op::FpBinaryOp)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FpBinaryOp {
AddF,
SubF,
MulF(FpMulAlu),
DivF,
}
impl FpBinaryOp {
pub(crate) fn alu(&self) -> RngdAlu {
match self {
Self::AddF | Self::SubF => RngdAlu::FpFma,
Self::MulF(alu) => alu.to_alu(),
Self::DivF => RngdAlu::FpFpu,
}
}
}
#[primitive(op::FpTernaryOp)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FpTernaryOp {
FmaF,
}
impl Display for FpTernaryOp {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::FmaF => write!(f, "FpTernaryOp::FmaF"),
}
}
}
impl FpTernaryOp {
pub(crate) fn alu(&self) -> RngdAlu {
RngdAlu::FpFma
}
}
#[primitive(op::IntraSliceReduceOpI32)]
#[derive(Debug, Clone, Copy)]
pub enum IntraSliceReduceOpI32 {
AddSat,
Max,
Min,
}
impl IntraSliceReduceOpI32 {
pub(crate) fn alu(&self) -> RngdAlu {
RngdAlu::ReduceAccTree
}
}
#[primitive(op::IntraSliceReduceOpF32)]
#[derive(Debug, Clone, Copy)]
pub enum IntraSliceReduceOpF32 {
Add,
Max,
Min,
}
impl IntraSliceReduceOpF32 {
pub(crate) fn alu(&self) -> RngdAlu {
RngdAlu::ReduceAccTree
}
}
#[primitive(op::InterSliceReduceOpI32)]
#[derive(Debug, Clone, Copy)]
pub enum InterSliceReduceOpI32 {
Add,
AddSat,
Max,
Min,
}
#[primitive(op::InterSliceReduceOpF32)]
#[derive(Debug, Clone, Copy)]
pub enum InterSliceReduceOpF32 {
Add,
Max,
Min,
Mul,
}
#[primitive(op::FpDivBinaryOp)]
#[derive(Debug, Clone, Copy)]
pub enum FpDivBinaryOp {
DivF,
}
impl Display for FpDivBinaryOp {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::DivF => write!(f, "FpDivBinaryOp::DivF"),
}
}
}
impl FpDivBinaryOp {
pub(crate) fn alu(&self) -> RngdAlu {
RngdAlu::ReduceFpDiv
}
}
#[primitive(op::ClipBinaryOpI32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ClipBinaryOpI32 {
Min,
Max,
AbsMin,
AbsMax,
AddFxp,
AddFxpSat,
}
impl Display for ClipBinaryOpI32 {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Min => write!(f, "ClipBinaryOpI32::Min"),
Self::Max => write!(f, "ClipBinaryOpI32::Max"),
Self::AbsMin => write!(f, "ClipBinaryOpI32::AbsMin"),
Self::AbsMax => write!(f, "ClipBinaryOpI32::AbsMax"),
Self::AddFxp => write!(f, "ClipBinaryOpI32::AddFxp"),
Self::AddFxpSat => write!(f, "ClipBinaryOpI32::AddFxpSat"),
}
}
}
impl ClipBinaryOpI32 {
pub(crate) fn alu(&self) -> RngdAlu {
match self {
Self::AddFxp | Self::AddFxpSat => RngdAlu::ClipAdd,
Self::Max | Self::AbsMax => RngdAlu::ClipMax,
Self::Min | Self::AbsMin => RngdAlu::ClipMin,
}
}
}
#[primitive(op::ClipBinaryOpF32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ClipBinaryOpF32 {
Min,
Max,
AbsMin,
AbsMax,
Add,
}
impl Display for ClipBinaryOpF32 {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Min => write!(f, "ClipBinaryOpF32::Min"),
Self::Max => write!(f, "ClipBinaryOpF32::Max"),
Self::AbsMin => write!(f, "ClipBinaryOpF32::AbsMin"),
Self::AbsMax => write!(f, "ClipBinaryOpF32::AbsMax"),
Self::Add => write!(f, "ClipBinaryOpF32::Add"),
}
}
}
impl ClipBinaryOpF32 {
pub(crate) fn alu(&self) -> RngdAlu {
match self {
Self::Add => RngdAlu::ClipAdd,
Self::Max | Self::AbsMax => RngdAlu::ClipMax,
Self::Min | Self::AbsMin => RngdAlu::ClipMin,
}
}
}