-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize memset and memclr for ARM #164
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#![cfg(all(target_arch = "arm", | ||
not(any(target_env = "gnu", target_env = "musl")), | ||
target_os = "linux", | ||
feature = "mem"))] | ||
#![feature(compiler_builtins_lib)] | ||
#![no_std] | ||
|
||
extern crate compiler_builtins; | ||
|
||
// test runner | ||
extern crate utest_cortex_m_qemu; | ||
|
||
// overrides `panic!` | ||
#[macro_use] | ||
extern crate utest_macros; | ||
|
||
use core::mem; | ||
|
||
macro_rules! panic { | ||
($($tt:tt)*) => { | ||
upanic!($($tt)*); | ||
}; | ||
} | ||
|
||
extern "C" { | ||
fn __aeabi_memclr4(dest: *mut u8, n: usize); | ||
fn __aeabi_memset4(dest: *mut u8, n: usize, c: u32); | ||
} | ||
|
||
struct Aligned { | ||
array: [u8; 8], | ||
_alignment: [u32; 0], | ||
} | ||
|
||
impl Aligned { | ||
fn new() -> Self { | ||
Aligned { | ||
array: [0; 8], | ||
_alignment: [], | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn memclr4() { | ||
let mut aligned = Aligned::new();; | ||
assert_eq!(mem::align_of_val(&aligned), 4); | ||
let xs = &mut aligned.array; | ||
|
||
for n in 0..9 { | ||
unsafe { | ||
__aeabi_memset4(xs.as_mut_ptr(), n, 0xff); | ||
__aeabi_memclr4(xs.as_mut_ptr(), n); | ||
} | ||
|
||
assert!(xs[0..n].iter().all(|x| *x == 0)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#![cfg(all(target_arch = "arm", | ||
not(any(target_env = "gnu", target_env = "musl")), | ||
target_os = "linux", | ||
feature = "mem"))] | ||
#![feature(compiler_builtins_lib)] | ||
#![no_std] | ||
|
||
extern crate compiler_builtins; | ||
|
||
// test runner | ||
extern crate utest_cortex_m_qemu; | ||
|
||
// overrides `panic!` | ||
#[macro_use] | ||
extern crate utest_macros; | ||
|
||
macro_rules! panic { | ||
($($tt:tt)*) => { | ||
upanic!($($tt)*); | ||
}; | ||
} | ||
|
||
extern "C" { | ||
fn __aeabi_memcpy(dest: *mut u8, src: *const u8, n: usize); | ||
fn __aeabi_memcpy4(dest: *mut u8, src: *const u8, n: usize); | ||
} | ||
|
||
struct Aligned { | ||
array: [u8; 8], | ||
_alignment: [u32; 0], | ||
} | ||
|
||
impl Aligned { | ||
fn new(array: [u8; 8]) -> Self { | ||
Aligned { | ||
array: array, | ||
_alignment: [], | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn memcpy() { | ||
let mut dest = [0; 4]; | ||
let src = [0xde, 0xad, 0xbe, 0xef]; | ||
|
||
for n in 0..dest.len() { | ||
dest.copy_from_slice(&[0; 4]); | ||
|
||
unsafe { __aeabi_memcpy(dest.as_mut_ptr(), src.as_ptr(), n) } | ||
|
||
assert_eq!(&dest[0..n], &src[0..n]) | ||
} | ||
} | ||
|
||
#[test] | ||
fn memcpy4() { | ||
let mut aligned = Aligned::new([0; 8]); | ||
let dest = &mut aligned.array; | ||
let src = [0xde, 0xad, 0xbe, 0xef, 0xba, 0xad, 0xf0, 0x0d]; | ||
|
||
for n in 0..dest.len() { | ||
dest.copy_from_slice(&[0; 8]); | ||
|
||
unsafe { __aeabi_memcpy4(dest.as_mut_ptr(), src.as_ptr(), n) } | ||
|
||
assert_eq!(&dest[0..n], &src[0..n]) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to confirm, the
4
in the name is "aligned to 4 bytes", right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. That's why we can optimize the routine by doing these aligned 4-byte reads / writes here.