-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Wojciech Zmuda <[email protected]>
- Loading branch information
Showing
9 changed files
with
456 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod and; | ||
pub mod or; | ||
pub mod xor; | ||
|
||
mod test_case; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
pub mod xor_bool; | ||
pub mod xor_i8; | ||
pub mod xor_i16; | ||
pub mod xor_i32; | ||
pub mod xor_i64; | ||
pub mod xor_i128; | ||
|
||
mod xor_test_cases; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use core::integer::Bitwise; | ||
extern fn bitwise(lhs: u128, rhs: u128) -> (u128, u128, u128) implicits(Bitwise) nopanic; | ||
|
||
pub fn __llvm__xor_bool_bool(lhs: u128, rhs: u128) -> u128 { | ||
if lhs > 1 { | ||
panic!("lhs = {:?} does not fit in bool", lhs) | ||
} | ||
|
||
if rhs > 1 { | ||
panic!("rhs = {:?} does not fit in bool", rhs) | ||
}; | ||
|
||
let (_, xor_result, _) = bitwise(lhs, rhs); | ||
xor_result | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::__llvm__xor_bool_bool; | ||
|
||
#[test] | ||
fn test_i1() { | ||
for case in crate::alu::xor::xor_test_cases::xor_i1.span() { | ||
assert_eq!(__llvm__xor_bool_bool(*case.lhs, *case.rhs), *case.expected); | ||
} | ||
} | ||
|
||
// Values larger than 1 bit should not work | ||
#[test] | ||
#[should_panic] | ||
fn test_i8() { | ||
for case in crate::alu::xor::xor_test_cases::xor_i8.span() { | ||
assert_eq!(__llvm__xor_bool_bool(*case.lhs, *case.rhs), *case.expected); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use core::integer::Bitwise; | ||
extern fn bitwise(lhs: u128, rhs: u128) -> (u128, u128, u128) implicits(Bitwise) nopanic; | ||
|
||
pub fn __llvm__xor_i128_i128(lhs: u128, rhs: u128) -> u128 { | ||
let (_, xor_result, _) = bitwise(lhs, rhs); | ||
xor_result | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::__llvm__xor_i128_i128; | ||
|
||
#[test] | ||
fn test_i128() { | ||
for case in crate::alu::xor::xor_test_cases::xor_i128.span() { | ||
assert_eq!(__llvm__xor_i128_i128(*case.lhs, *case.rhs), *case.expected); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use core::integer::Bitwise; | ||
extern fn bitwise(lhs: u128, rhs: u128) -> (u128, u128, u128) implicits(Bitwise) nopanic; | ||
|
||
pub fn __llvm__xor_i16_i16(lhs: u128, rhs: u128) -> u128 { | ||
let _: u16 = match lhs.try_into() { | ||
Option::Some(value) => value, | ||
Option::None => { | ||
panic!("lhs = {:?} does not fit in u16", lhs) | ||
}, | ||
}; | ||
|
||
let _: u16 = match rhs.try_into() { | ||
Option::Some(value) => value, | ||
Option::None => { | ||
panic!("rhs = {:?} does not fit in u16", rhs) | ||
}, | ||
}; | ||
|
||
let (_, xor_result, _) = bitwise(lhs, rhs); | ||
xor_result | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::__llvm__xor_i16_i16; | ||
|
||
#[test] | ||
fn test_i16() { | ||
for case in crate::alu::xor::xor_test_cases::xor_i16.span() { | ||
assert_eq!(__llvm__xor_i16_i16(*case.lhs, *case.rhs), *case.expected); | ||
} | ||
} | ||
|
||
// Values larger than 16 bit should not work | ||
#[test] | ||
#[should_panic] | ||
fn test_i32() { | ||
for case in crate::alu::xor::xor_test_cases::xor_i32.span() { | ||
__llvm__xor_i16_i16(*case.lhs, *case.rhs); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use core::integer::Bitwise; | ||
extern fn bitwise(lhs: u128, rhs: u128) -> (u128, u128, u128) implicits(Bitwise) nopanic; | ||
|
||
pub fn __llvm__xor_i32_i32(lhs: u128, rhs: u128) -> u128 { | ||
let _: u32 = match lhs.try_into() { | ||
Option::Some(value) => value, | ||
Option::None => { | ||
panic!("lhs = {:?} does not fit in u32", lhs) | ||
}, | ||
}; | ||
|
||
let _: u32 = match rhs.try_into() { | ||
Option::Some(value) => value, | ||
Option::None => { | ||
panic!("rhs = {:?} does not fit in u32", rhs) | ||
}, | ||
}; | ||
|
||
let (_, xor_result, _) = bitwise(lhs, rhs); | ||
xor_result | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::__llvm__xor_i32_i32; | ||
|
||
#[test] | ||
fn test_i32() { | ||
for case in crate::alu::xor::xor_test_cases::xor_i32.span() { | ||
assert_eq!(__llvm__xor_i32_i32(*case.lhs, *case.rhs), *case.expected); | ||
} | ||
} | ||
|
||
// Values larger than 32 bit should not work | ||
#[test] | ||
#[should_panic] | ||
fn test_i64() { | ||
for case in crate::alu::xor::xor_test_cases::xor_i64.span() { | ||
__llvm__xor_i32_i32(*case.lhs, *case.rhs); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use core::integer::Bitwise; | ||
extern fn bitwise(lhs: u128, rhs: u128) -> (u128, u128, u128) implicits(Bitwise) nopanic; | ||
|
||
pub fn __llvm__xor_i64_i64(lhs: u128, rhs: u128) -> u128 { | ||
let _: u64 = match lhs.try_into() { | ||
Option::Some(value) => value, | ||
Option::None => { | ||
panic!("lhs = {:?} does not fit in u64", lhs) | ||
}, | ||
}; | ||
|
||
let _: u64 = match rhs.try_into() { | ||
Option::Some(value) => value, | ||
Option::None => { | ||
panic!("rhs = {:?} does not fit in u64", rhs) | ||
}, | ||
}; | ||
|
||
let (_, xor_result, _) = bitwise(lhs, rhs); | ||
xor_result | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::__llvm__xor_i64_i64; | ||
|
||
#[test] | ||
fn test_i64() { | ||
for case in crate::alu::xor::xor_test_cases::xor_i64.span() { | ||
assert_eq!(__llvm__xor_i64_i64(*case.lhs, *case.rhs), *case.expected); | ||
} | ||
} | ||
|
||
// Values larger than 64 bit should not work | ||
#[test] | ||
#[should_panic] | ||
fn test_i128() { | ||
for case in crate::alu::xor::xor_test_cases::xor_i128.span() { | ||
__llvm__xor_i64_i64(*case.lhs, *case.rhs); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use core::integer::Bitwise; | ||
extern fn bitwise(lhs: u128, rhs: u128) -> (u128, u128, u128) implicits(Bitwise) nopanic; | ||
|
||
pub fn __llvm__xor_i8_i8(lhs: u128, rhs: u128) -> u128 { | ||
let _: u8 = match lhs.try_into() { | ||
Option::Some(value) => value, | ||
Option::None => { | ||
panic!("lhs = {:?} does not fit in u8", lhs) | ||
}, | ||
}; | ||
|
||
let _: u8 = match rhs.try_into() { | ||
Option::Some(value) => value, | ||
Option::None => { | ||
panic!("rhs = {:?} does not fit in u8", rhs) | ||
}, | ||
}; | ||
|
||
let (_, xor_result, _) = bitwise(lhs, rhs); | ||
xor_result | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::__llvm__xor_i8_i8; | ||
|
||
#[test] | ||
fn test_i8() { | ||
for case in crate::alu::xor::xor_test_cases::xor_i8.span() { | ||
assert_eq!(__llvm__xor_i8_i8(*case.lhs, *case.rhs), *case.expected); | ||
} | ||
} | ||
|
||
// Values larger than 8 bit should not work | ||
#[test] | ||
#[should_panic] | ||
fn test_i16() { | ||
for case in crate::alu::xor::xor_test_cases::xor_i16.span() { | ||
__llvm__xor_i8_i8(*case.lhs, *case.rhs); | ||
} | ||
} | ||
} |
Oops, something went wrong.