aeabi_memcpy.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. macro_rules! panic {
  17. ($($tt:tt)*) => {
  18. upanic!($($tt)*);
  19. };
  20. }
  21. extern "C" {
  22. fn __aeabi_memcpy(dest: *mut u8, src: *const u8, n: usize);
  23. fn __aeabi_memcpy4(dest: *mut u8, src: *const u8, n: usize);
  24. }
  25. struct Aligned {
  26. array: [u8; 8],
  27. _alignment: [u32; 0],
  28. }
  29. impl Aligned {
  30. fn new(array: [u8; 8]) -> Self {
  31. Aligned {
  32. array: array,
  33. _alignment: [],
  34. }
  35. }
  36. }
  37. #[test]
  38. fn memcpy() {
  39. let mut dest = [0; 4];
  40. let src = [0xde, 0xad, 0xbe, 0xef];
  41. for n in 0..dest.len() {
  42. dest.copy_from_slice(&[0; 4]);
  43. unsafe { __aeabi_memcpy(dest.as_mut_ptr(), src.as_ptr(), n) }
  44. assert_eq!(&dest[0..n], &src[0..n])
  45. }
  46. }
  47. #[test]
  48. fn memcpy4() {
  49. let mut aligned = Aligned::new([0; 8]);
  50. let dest = &mut aligned.array;
  51. let src = [0xde, 0xad, 0xbe, 0xef, 0xba, 0xad, 0xf0, 0x0d];
  52. for n in 0..dest.len() {
  53. dest.copy_from_slice(&[0; 8]);
  54. unsafe { __aeabi_memcpy4(dest.as_mut_ptr(), src.as_ptr(), n) }
  55. assert_eq!(&dest[0..n], &src[0..n])
  56. }
  57. }