Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Unified Diff: crosstest/mem_intrin.cpp

Issue 1278173009: Inline memove for small constant sizes and refactor memcpy and memset. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Simplify xtests and add flags for memory intrinsic optimization. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: crosstest/mem_intrin.cpp
diff --git a/crosstest/mem_intrin.cpp b/crosstest/mem_intrin.cpp
index 612edce481722e3cba8804d1e3a7b1ddec13bc43..2e39e17c2c1d5d15bd7e9ce0c72ad9e17036cf0b 100644
--- a/crosstest/mem_intrin.cpp
+++ b/crosstest/mem_intrin.cpp
@@ -39,30 +39,6 @@ fletcher_checksum(uint8_t *buf, size_t length) {
return (sum_of_sums << 8) | sum;
}
-#define NWORDS 32
-#define BYTE_LENGTH (NWORDS * sizeof(elem_t))
-
-int memcpy_test_fixed_len(uint8_t init) {
- elem_t buf[NWORDS];
- elem_t buf2[NWORDS];
- reset_buf((uint8_t *)buf, init, BYTE_LENGTH);
- memcpy((void *)buf2, (void *)buf, BYTE_LENGTH);
- return fletcher_checksum((uint8_t *)buf2, BYTE_LENGTH);
-}
-
-int memmove_test_fixed_len(uint8_t init) {
- elem_t buf[NWORDS];
- reset_buf((uint8_t *)buf, init, BYTE_LENGTH);
- memmove((void *)(buf + 4), (void *)buf, BYTE_LENGTH - (4 * sizeof(elem_t)));
- return fletcher_checksum((uint8_t *)buf + 4, BYTE_LENGTH - 4);
-}
-
-int memset_test_fixed_len(uint8_t init) {
- elem_t buf[NWORDS];
- memset((void *)buf, init, BYTE_LENGTH);
- return fletcher_checksum((uint8_t *)buf, BYTE_LENGTH);
-}
-
int memcpy_test(uint8_t *buf, uint8_t *buf2, uint8_t init, size_t length) {
reset_buf(buf, init, length);
memcpy((void *)buf2, (void *)buf, length);
@@ -93,3 +69,33 @@ int memset_test(uint8_t *buf, uint8_t *buf2, uint8_t init, size_t length) {
memset((void *)buf2, init + 4, length);
return fletcher_checksum(buf, length) + fletcher_checksum(buf2, length);
}
+
+#define X(NBYTES) \
+ int memcpy_test_fixed_len_##NBYTES(uint8_t init) { \
+ uint8_t buf[NBYTES]; \
+ uint8_t buf2[NBYTES]; \
+ reset_buf(buf, init, NBYTES); \
+ memcpy((void *)buf2, (void *)buf, NBYTES); \
+ return fletcher_checksum(buf2, NBYTES); \
+ } \
+ \
+ int memmove_test_fixed_len_##NBYTES(uint8_t init) { \
+ uint8_t buf[NBYTES + 16]; \
+ uint8_t buf2[NBYTES + 16]; \
+ reset_buf(buf, init, NBYTES + 16); \
+ reset_buf(buf2, init, NBYTES + 16); \
+ /* Move up */ \
+ memmove((void *)(buf + 16), (void *)buf, NBYTES); \
+ /* Move down */ \
+ memmove((void *)buf2, (void *)(buf2 + 16), NBYTES); \
+ return fletcher_checksum(buf, NBYTES + 16) + \
+ fletcher_checksum(buf2, NBYTES + 16); \
+ } \
+ \
+ int memset_test_fixed_len_##NBYTES(uint8_t init) { \
+ uint8_t buf[NBYTES]; \
+ memset((void *)buf, init, NBYTES); \
+ return fletcher_checksum(buf, NBYTES); \
+ }
+VALUES
+#undef X

Powered by Google App Engine
This is Rietveld 408576698