aeabi_memclr.rs 1.1 KB

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