Merge pull request #2953 from scottmcm/add-memcmp
Cranelift: Add `LibCall::Memcmp`
This commit is contained in:
@@ -56,6 +56,8 @@ pub enum LibCall {
|
||||
Memset,
|
||||
/// libc.memmove
|
||||
Memmove,
|
||||
/// libc.memcmp
|
||||
Memcmp,
|
||||
|
||||
/// Elf __tls_get_addr
|
||||
ElfTlsGetAddr,
|
||||
@@ -92,6 +94,7 @@ impl FromStr for LibCall {
|
||||
"Memcpy" => Ok(Self::Memcpy),
|
||||
"Memset" => Ok(Self::Memset),
|
||||
"Memmove" => Ok(Self::Memmove),
|
||||
"Memcmp" => Ok(Self::Memcmp),
|
||||
|
||||
"ElfTlsGetAddr" => Ok(Self::ElfTlsGetAddr),
|
||||
_ => Err(()),
|
||||
@@ -157,6 +160,7 @@ impl LibCall {
|
||||
Memcpy,
|
||||
Memset,
|
||||
Memmove,
|
||||
Memcmp,
|
||||
ElfTlsGetAddr,
|
||||
]
|
||||
}
|
||||
@@ -201,4 +205,11 @@ mod tests {
|
||||
fn parsing() {
|
||||
assert_eq!("FloorF32".parse(), Ok(LibCall::FloorF32));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_libcalls_to_from_string() {
|
||||
for &libcall in LibCall::all_libcalls() {
|
||||
assert_eq!(libcall.to_string().parse(), Ok(libcall));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +104,8 @@ impl Type {
|
||||
}
|
||||
|
||||
/// Get an integer type with the requested number of bits.
|
||||
///
|
||||
/// For the same thing but in *bytes*, use [`Self::int_with_byte_size`].
|
||||
pub fn int(bits: u16) -> Option<Self> {
|
||||
match bits {
|
||||
8 => Some(I8),
|
||||
@@ -115,6 +117,13 @@ impl Type {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get an integer type with the requested number of bytes.
|
||||
///
|
||||
/// For the same thing but in *bits*, use [`Self::int`].
|
||||
pub fn int_with_byte_size(bytes: u16) -> Option<Self> {
|
||||
Self::int(bytes.checked_mul(8)?)
|
||||
}
|
||||
|
||||
/// Get a type with the same number of lanes as `self`, but using `lane` as the lane type.
|
||||
fn replace_lanes(self, lane: Self) -> Self {
|
||||
debug_assert!(lane.is_lane() && !self.is_special());
|
||||
@@ -595,4 +604,22 @@ mod tests {
|
||||
assert_eq!(B8.as_int(), I8);
|
||||
assert_eq!(B128.as_int(), I128);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn int_from_size() {
|
||||
assert_eq!(Type::int(0), None);
|
||||
assert_eq!(Type::int(8), Some(I8));
|
||||
assert_eq!(Type::int(33), None);
|
||||
assert_eq!(Type::int(64), Some(I64));
|
||||
|
||||
assert_eq!(Type::int_with_byte_size(0), None);
|
||||
assert_eq!(Type::int_with_byte_size(2), Some(I16));
|
||||
assert_eq!(Type::int_with_byte_size(6), None);
|
||||
assert_eq!(Type::int_with_byte_size(16), Some(I128));
|
||||
|
||||
// Ensure `int_with_byte_size` handles overflow properly
|
||||
let evil = 0xE001_u16;
|
||||
assert_eq!(evil.wrapping_mul(8), 8, "check the constant is correct");
|
||||
assert_eq!(Type::int_with_byte_size(evil), None);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user