aeabi_memclr.rs 1.1 KB

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