shift.rs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. use testcrate::*;
  2. macro_rules! shift {
  3. ($($i:ty, $fn_std:ident, $fn_builtins:ident);*;) => {
  4. $(
  5. fuzz_shift(|x: $i, s: u32| {
  6. let tmp0: $i = x.$fn_std(s);
  7. let tmp1: $i = $fn_builtins(x, s);
  8. if tmp0 != tmp1 {
  9. panic!(
  10. "{}({}, {}): std: {}, builtins: {}",
  11. stringify!($fn_builtins), x, s, tmp0, tmp1
  12. );
  13. }
  14. });
  15. )*
  16. };
  17. }
  18. #[test]
  19. fn shift() {
  20. use compiler_builtins::int::shift::{
  21. __ashldi3, __ashlsi3, __ashlti3, __ashrdi3, __ashrsi3, __ashrti3, __lshrdi3, __lshrsi3,
  22. __lshrti3,
  23. };
  24. shift!(
  25. u32, wrapping_shl, __ashlsi3;
  26. u64, wrapping_shl, __ashldi3;
  27. u128, wrapping_shl, __ashlti3;
  28. i32, wrapping_shr, __ashrsi3;
  29. i64, wrapping_shr, __ashrdi3;
  30. i128, wrapping_shr, __ashrti3;
  31. u32, wrapping_shr, __lshrsi3;
  32. u64, wrapping_shr, __lshrdi3;
  33. u128, wrapping_shr, __lshrti3;
  34. );
  35. }