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

Unified Diff: crosstest/mem_intrin.c

Issue 321993002: Add a few Subzero intrinsics (not the atomic ones yet). (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: add a run test Created 6 years, 6 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.c
diff --git a/crosstest/mem_intrin.c b/crosstest/mem_intrin.c
new file mode 100644
index 0000000000000000000000000000000000000000..bb85f5ab788e01d16c0e88101dd6e4b10e9010dd
--- /dev/null
+++ b/crosstest/mem_intrin.c
@@ -0,0 +1,67 @@
+/* Simple sanity test of memcpy, memmove, and memset intrinsics. */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+typedef int elem_t;
+#define NWORDS 32
+#define BYTE_LENGTH (32 * sizeof(elem_t))
+
+/*
+ * Reset buf to the sequence of bytes: n, n+1, n+2 ... length - 1
+ */
+void __attribute__((noinline)) reset_buf(uint8_t *buf,
+ uint8_t n,
+ size_t length) {
+ size_t i;
+ for (i = n; i < length; ++i)
+ buf[i] = i;
+}
+
+int __attribute__((noinline)) sum_buf(uint8_t *buf,
+ size_t length) {
+ size_t i;
+ int sum = 0;
+ for (i = 0; i < length; ++i)
+ sum += buf[i];
+ return sum;
+}
+
+/*
+ * Workaround: There seems to be a mis-alignment of parameters
+ * when you stack allocate two buffers. So, instead of allocating
+ * both buf and buf2 in the same function, only allocate buf,
+ * then call this helper, which allocates buf2, then use both.
+ */
+int __attribute__((noinline)) memcpy_helper(uint8_t *buf,
+ uint8_t n) {
+ elem_t buf2[NWORDS];
+ reset_buf((uint8_t *)buf, n, BYTE_LENGTH);
+ memcpy((void *)buf2, (void *)buf, BYTE_LENGTH);
+ return sum_buf((uint8_t*)buf2, BYTE_LENGTH);
+}
+
+int memcpy_test(uint8_t n) {
+ elem_t buf[NWORDS];
+ return memcpy_helper(buf, n);
+}
+
+int memmove_test(uint8_t n) {
+ elem_t buf[NWORDS];
+ reset_buf((uint8_t *)buf, n, BYTE_LENGTH);
+ memmove((void *)(buf + 4), (void *)buf, BYTE_LENGTH - (4 * sizeof(elem_t)));
+ return sum_buf((uint8_t*)buf + 4, BYTE_LENGTH - 4);
+}
+
+/* Broken: invalid push byte for the memset 'n'.
+ Probably Subzero assumes that all parameters
+ are at least i32, so the fact that the intrinsic
+ violates that breaks it. Otherwise, we should widen
+ the parameter ourselves before doing the call.
+int memset_test(uint8_t n) {
+ elem_t buf[NWORDS];
+ memset((void *)buf, n, BYTE_LENGTH);
+ return sum_buf((uint8_t*)buf, BYTE_LENGTH);
+}
+*/
« no previous file with comments | « Makefile.standalone ('k') | crosstest/mem_intrin_main.c » ('j') | src/IceTargetLoweringX8632.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698