x86 validator: Implement rewriting "movntps" to "movaps" on x86-32
We were already doing this rewrite for x86-64.
Use of "movntps" on x86-32 appears in the Chrome Web Store.
BUG= https://bugs.chromium.org/p/chromium/issues/detail?id=598085
TEST=run_validation_rewrite_test run_rewrite_nontemporals_test
run_validation_cache_test
Review URL: https://codereview.chromium.org/1837733002
(cherry picked from commit ca352b231f2f448e90549dd5cd09901f49f97cbd)
Review URL: https://codereview.chromium.org/1865743002
diff --git a/src/trusted/validator/validation_rewrite_test.cc b/src/trusted/validator/validation_rewrite_test.cc
index a392f69..f981dfc 100644
--- a/src/trusted/validator/validation_rewrite_test.cc
+++ b/src/trusted/validator/validation_rewrite_test.cc
@@ -38,6 +38,7 @@
DECLARE_TEMPLATE(no_rewrite_code)
#if NACL_BUILD_SUBARCH == 32
DECLARE_TEMPLATE(movntq_code)
+DECLARE_TEMPLATE(movntps_code)
DECLARE_TEMPLATE(movntdq_code)
DECLARE_TEMPLATE(prefetchnta_code)
#else
@@ -114,6 +115,10 @@
TestRewrite(&t_movntq_code);
}
+TEST_F(ValidationMovntRewriteTests, RewriteMovntps) {
+ TestRewrite(&t_movntps_code);
+}
+
TEST_F(ValidationMovntRewriteTests, RewriteMovntdq) {
TestRewrite(&t_movntdq_code);
}
diff --git a/src/trusted/validator/validation_rewrite_test_data.S b/src/trusted/validator/validation_rewrite_test_data.S
index 41d065d..6786144 100644
--- a/src/trusted/validator/validation_rewrite_test_data.S
+++ b/src/trusted/validator/validation_rewrite_test_data.S
@@ -29,6 +29,14 @@
movq %mm0, (%ebx)
GLOBAL_SYM(movntq_code_post_rewrite_end)
+GLOBAL_SYM(movntps_code)
+ movntps %xmm0, (%ebx)
+GLOBAL_SYM(movntps_code_end)
+
+GLOBAL_SYM(movntps_code_post_rewrite)
+ movaps %xmm0, (%ebx)
+GLOBAL_SYM(movntps_code_post_rewrite_end)
+
GLOBAL_SYM(movntdq_code)
movntdq %xmm0, (%edx)
GLOBAL_SYM(movntdq_code_end)
diff --git a/src/trusted/validator_ragel/dfa_validate_common.c b/src/trusted/validator_ragel/dfa_validate_common.c
index 7eb4465..ec77cad 100644
--- a/src/trusted/validator_ragel/dfa_validate_common.c
+++ b/src/trusted/validator_ragel/dfa_validate_common.c
@@ -83,6 +83,10 @@
/* movntq => movq */
ptr[1] = 0x7f;
return TRUE;
+ } else if (size >= 2 && memcmp(ptr, "\x0f\x2b", 2) == 0) {
+ /* movntps => movaps */
+ ptr[1] = 0x29;
+ return TRUE;
} else if (size >= 3 && memcmp(ptr, "\x66\x0f\xe7", 3) == 0) {
/* movntdq => movdqa */
ptr[2] = 0x7f;
diff --git a/tests/validator/rewrite_nontemporals.c b/tests/validator/rewrite_nontemporals.c
index cbed4b2..6e5f65f 100644
--- a/tests/validator/rewrite_nontemporals.c
+++ b/tests/validator/rewrite_nontemporals.c
@@ -46,13 +46,13 @@
"movntq %%mm0, g_dest" MEM_SUFFIX "\n" : : : "mm0");
ASSERT_EQ(memcmp(g_dest, g_src, 8), 0);
-#if defined(__x86_64__)
/* Test movntps. */
reset_test_vars();
- asm("movdqa g_src(%%r15), %%xmm0\n"
- "movntps %%xmm0, g_dest(%%r15)\n" : : : "xmm0");
+ asm("movdqa g_src" MEM_SUFFIX ", %%xmm0\n"
+ "movntps %%xmm0, g_dest" MEM_SUFFIX "\n" : : : "xmm0");
ASSERT_EQ(memcmp(g_dest, g_src, 16), 0);
+#if defined(__x86_64__)
/* Test movnti, using 32-bit operand. */
reset_test_vars();
asm("mov g_src(%%r15), %%eax\n"