aeabi_memclr.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #![cfg(all(target_arch = "arm",
  2. not(any(target_env = "gnu", target_env = "musl")),
  3. target_os = "linux",
  4. feature = "mem"))]
  5. #![feature(compiler_builtins_lib)]
  6. #![feature(lang_items)]
  7. #![no_std]
  8. extern crate compiler_builtins;
  9. // test runner
  10. extern crate utest_cortex_m_qemu;
  11. // overrides `panic!`
  12. #[macro_use]
  13. extern crate utest_macros;
  14. use core::mem;
  15. macro_rules! panic {
  16. ($($tt:tt)*) => {
  17. upanic!($($tt)*);
  18. };
  19. }
  20. extern "C" {
  21. fn __aeabi_memclr4(dest: *mut u8, n: usize);
  22. fn __aeabi_memset4(dest: *mut u8, n: usize, c: u32);
  23. }
  24. struct Aligned {
  25. array: [u8; 8],
  26. _alignment: [u32; 0],
  27. }
  28. impl Aligned {
  29. fn new() -> Self {
  30. Aligned {
  31. array: [0; 8],
  32. _alignment: [],
  33. }
  34. }
  35. }
  36. #[test]
  37. fn memclr4() {
  38. let mut aligned = Aligned::new();;
  39. assert_eq!(mem::align_of_val(&aligned), 4);
  40. let xs = &mut aligned.array;
  41. for n in 0..9 {
  42. unsafe {
  43. __aeabi_memset4(xs.as_mut_ptr(), n, 0xff);
  44. __aeabi_memclr4(xs.as_mut_ptr(), n);
  45. }
  46. assert!(xs[0..n].iter().all(|x| *x == 0));
  47. }
  48. }