Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fmckeogh committed May 18, 2024
1 parent ce6a3db commit 5f4eef6
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 34 deletions.
31 changes: 0 additions & 31 deletions borealis/src/brig/denylist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,6 @@ const DENYLIST: &[&'static str] = &[
"_shl_int_general",
"_shr_int_general",
"fmod_int",
"subrange_subrange_eq",
"subrange_subrange_concat",
"zext_slice",
"zext_subrange",
"sext_slice",
"sext_subrange",
"place_slice_signed",
"place_subrange_signed",
"unsigned_subrange",
"vector_update_subrange_from_subrange",
"vector_update_subrange_from_integer_subrange",
"mem_read_request_is_exclusive<Uarm_acc_type<>,b,O<RTranslationInfo>>",
"mem_read_request_is_ifetch<Uarm_acc_type<>,b,O<RTranslationInfo>>",
"mem_write_request_is_exclusive<Uarm_acc_type<>,b,O<RTranslationInfo>>",
"Replicate__1",
"Ones",
"IsOnes",
"integer_access",
"integer_update_subrange",
"ZeroExtend1",
"RoundTowardsZero",
"IsUNDEFINED",
"IsUNPREDICTABLE",
"IsSEE",
"IsExceptionTaken",
"ThrowSError",
"ReservedEncoding",
"__UNKNOWN_integer",
Expand All @@ -68,12 +43,6 @@ const DENYLIST: &[&'static str] = &[
"Elem_read",
"write_gpr_bits",
"set_R_bits",
"PMUCounterIsHyp",
"PMUOverflowCondition",
"HiLoPMUOverflow",
"PhysicalCountInt",
"EffectiveSCR_EL3_RW",
"PhysicalOffsetIsValid",
"GetTimestamp",
"ELIsInHost",
"IsInHost",
Expand Down
2 changes: 2 additions & 0 deletions borealis/src/brig/functions_interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ pub fn codegen_stmt(stmt: Statement) -> TokenStream {
UnaryOperationKind::Complement => quote! {!#value},
UnaryOperationKind::Power2 => quote! { (#value).pow(2) },
UnaryOperationKind::Absolute => quote! { (#value).abs() },
UnaryOperationKind::Ceil => quote! { (#value).ceil() },
UnaryOperationKind::Floor => quote! { (#value).floor() },
}
}
StatementKind::ShiftOperation {
Expand Down
1 change: 1 addition & 0 deletions borealis/src/brig/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ fn codegen_workspace(rudder: &Context) -> (HashMap<PathBuf, String>, HashSet<Pat

let contents =
quote! {
// #[inline(never)]
pub fn #name_ident<T: Tracer>(#function_parameters) -> #return_type {
#fn_state

Expand Down
26 changes: 25 additions & 1 deletion borealis/src/rudder/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,30 @@ impl<'ctx: 'fn_ctx, 'fn_ctx> BlockBuildContext<'ctx, 'fn_ctx> {
}))
}

// val ceil : (%real) -> %i
"ceil" => {
let ceil = self.builder.build(StatementKind::UnaryOperation {
kind: UnaryOperationKind::Ceil,
value: args[0].clone(),
});
Some(
self.builder
.generate_cast(ceil, Arc::new(Type::ArbitraryLengthInteger)),
)
}

// val floor : (%real) -> %i
"floor" => {
let floor = self.builder.build(StatementKind::UnaryOperation {
kind: UnaryOperationKind::Floor,
value: args[0].clone(),
});
Some(
self.builder
.generate_cast(floor, Arc::new(Type::ArbitraryLengthInteger)),
)
}

// val to_real : (%i) -> %real
"to_real" => Some(
self.builder
Expand All @@ -707,7 +731,7 @@ impl<'ctx: 'fn_ctx, 'fn_ctx> BlockBuildContext<'ctx, 'fn_ctx> {
kind: UnaryOperationKind::Power2,
value: args[0].clone(),
})),
"lt_int" => Some(self.builder.build(StatementKind::BinaryOperation {
"lt_int" | "lt_real" => Some(self.builder.build(StatementKind::BinaryOperation {
kind: BinaryOperationKind::CompareLessThan,
lhs: args[0].clone(),
rhs: args[1].clone(),
Expand Down
81 changes: 79 additions & 2 deletions borealis/src/rudder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ pub enum UnaryOperationKind {
Complement,
Power2,
Absolute,
Ceil,
Floor,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -1090,10 +1092,85 @@ impl StatementInner {
index,
};
}
StatementKind::WritePc { value } => {
let value = if value == use_of {
with.clone()
} else {
value.clone()
};

self.kind = StatementKind::WritePc { value };
}
StatementKind::Panic(statements) => {
self.kind = StatementKind::Panic(
statements
.into_iter()
.map(|stmt| if stmt == use_of { with.clone() } else { stmt })
.collect(),
)
}

StatementKind::CreateBits { value, length } => {
let value = if value == use_of {
with.clone()
} else {
value.clone()
};

_ => {
panic!("use replacement not implemented for {}", self.kind);
let length = if length == use_of {
with.clone()
} else {
length.clone()
};

self.kind = StatementKind::CreateBits { value, length };
}
StatementKind::MatchesSum {
value,
variant_index,
} => {
let value = if value == use_of {
with.clone()
} else {
value.clone()
};

self.kind = StatementKind::MatchesSum {
value,
variant_index,
};
}
StatementKind::UnwrapSum {
value,
variant_index,
} => {
let value = if value == use_of {
with.clone()
} else {
value.clone()
};

self.kind = StatementKind::UnwrapSum {
value,
variant_index,
};
}
StatementKind::ExtractField { value, field_index } => {
let value = if value == use_of {
with.clone()
} else {
value.clone()
};

self.kind = StatementKind::ExtractField { value, field_index };
}

StatementKind::Constant { .. } => todo!(),
StatementKind::ReadVariable { .. } => todo!(),
StatementKind::ReadRegister { .. } => todo!(),
StatementKind::ReadPc => todo!(),
StatementKind::Jump { .. } => todo!(),
StatementKind::PhiNode { .. } => todo!(),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions borealis/src/rudder/pretty_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ impl Display for StatementKind {
UnaryOperationKind::Negate => "neg",
UnaryOperationKind::Power2 => "pow2",
UnaryOperationKind::Absolute => "abs",
UnaryOperationKind::Ceil => "ceil",
UnaryOperationKind::Floor => "floor",
};

write!(f, "{} {}", op, value.name())
Expand Down

0 comments on commit 5f4eef6

Please sign in to comment.