summaryrefslogtreecommitdiff
path: root/src/arm32/predicate
diff options
context:
space:
mode:
Diffstat (limited to 'src/arm32/predicate')
-rw-r--r--src/arm32/predicate/mod.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/arm32/predicate/mod.rs b/src/arm32/predicate/mod.rs
index 0b761d9..66b6534 100644
--- a/src/arm32/predicate/mod.rs
+++ b/src/arm32/predicate/mod.rs
@@ -20,6 +20,7 @@
// If not, see <https://www.gnu.org/licenses/>.
use core::fmt::Display;
+use core::mem::transmute;
/// An instruction predicate (condition code).
///
@@ -48,6 +49,22 @@ pub enum Predicate {
//Never = 0b1111,
}
+impl Predicate {
+ /// Converts the provided byte into a register identifier.
+ /// If the byte's value is not a valid predicate, [`None`] is returned.
+ ///
+ /// This conversion is valid for all values less than or equal (14).
+ #[inline]
+ #[must_use]
+ pub const fn from_u8(value: u8) -> Option<Self> {
+ if value <= 0b1110 {
+ Some(unsafe { transmute::<u8, Self>(value) })
+ } else {
+ None
+ }
+ }
+}
+
impl Display for Predicate {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
use Predicate::*;