Reviewers: Erik Corry,

Message:
On 2010/04/28 09:07:58, Erik Corry wrote:

Thanks for the comments. I am making changes accordingly and testing them out
both for the actual ARMv7 hardware and for the simulator version (with the
unaligned check disabled when we assume the simulator is supporting ARMv7). Once
testing is done properly, I will upload the changes.

Meanwhile some discussion:

It appears even if we define CAN_USE_ARMV7_INSTRUCTIONS in globals.h (and that
being used to define V8_TARGET_CAN_READ_UNALIGNED), it's not visible to the
simulator-arm.cc. For the arm simulator it's visible only through the
definitions in constants-arm.h

So I am also defining CAN_USE_ARMV7_INSTRUCTIONS and based on that defining the
macro V8_TARGET_CAN_READ_UNALIGNED for the simulator mode, i.e.,  #if
!defined(__arm__), in constants-arm.h, and use CAN_USE_ARMV7_INSTRUCTIONS to
bypass unaligned access checks in the simulator.






Description:
enabled the support for unaligned memory access for ARMv7.
Previous ARM ISA implementations didn't support unaligned access, however ARMv7 ISA implementations made it mandatory to support so. In ARMv7 when SCTLR (system control register) has A=0, unaligned access is allowed for LDR, STR, LDRH, STRH
instructions.
SCTLT.A = 0 is also the default setting for ARMv7.
Also, Linux and all modern Operating systems on ARMv7 always sets SCTLR.A = 0 to support unaligned access, so does many applications on ARMv7 assumes it and uses
unaligned access. Hence, it is most efficient to turn on through the Macros
defines in global.h, rather than using any kind of runtime detection, as done in
this Issue for review.
Support has been added to enable unaligned access also in the ARM specific
implementation of the regular expression engine.


Please review this at http://codereview.chromium.org/1731013/show

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
  M     src/arm/regexp-macro-assembler-arm.cc
  M     src/globals.h


Index: src/globals.h
===================================================================
--- src/globals.h       (revision 4519)
+++ src/globals.h       (working copy)
@@ -46,6 +46,14 @@
 #elif defined(__ARMEL__)
 #define V8_HOST_ARCH_ARM 1
 #define V8_HOST_ARCH_32_BIT 1
+// Linux and modern OS on ARMv7 enable unaligned accesses,
+// and many applications on ARMv7 already use unaligned accesses.
+// So it is safe to use unaligned access for ARMv7 backend in v8
+#if defined(__ARM_ARCH_7A__) || \
+  defined(__ARM_ARCH_7R__) || \
+  defined(__ARM_ARCH_7__)
+#define V8_HOST_CAN_READ_UNALIGNED 1
+#endif
 #elif defined(_MIPS_ARCH_MIPS32R2)
 #define V8_HOST_ARCH_MIPS 1
 #define V8_HOST_ARCH_32_BIT 1
@@ -73,6 +81,14 @@
 #if defined(V8_TARGET_ARCH_X64) || defined(V8_TARGET_ARCH_IA32)
 #define V8_TARGET_CAN_READ_UNALIGNED 1
 #elif V8_TARGET_ARCH_ARM
+// Linux and modern OS on ARMv7 enable unaligned accesses,
+// and many applications on ARMv7 already use unaligned accesses.
+// So it is safe to use unaligned access for ARMv7 backend in v8
+#if defined(__ARM_ARCH_7A__) || \
+  defined(__ARM_ARCH_7R__) || \
+  defined(__ARM_ARCH_7__)
+#define V8_TARGET_CAN_READ_UNALIGNED 1
+#endif
 #elif V8_TARGET_ARCH_MIPS
 #else
 #error Target architecture is not supported by v8
Index: src/arm/regexp-macro-assembler-arm.cc
===================================================================
--- src/arm/regexp-macro-assembler-arm.cc       (revision 4519)
+++ src/arm/regexp-macro-assembler-arm.cc       (working copy)
@@ -1210,14 +1210,32 @@
     __ add(r0, current_input_offset(), Operand(cp_offset * char_size()));
     offset = r0;
   }
-  // We assume that we cannot do unaligned loads on ARM, so this function
-  // must only be used to load a single character at a time.
+  // LDR, STR, LDRH, STRH instructions in ARMv7 can do unaligned accesses
+  // Linux and modern OS on ARMv7 enable unaligned accesses,
+  // and many applications on ARMv7 already use unaligned accesses.
+  // If the target is not ARMv7, then we cannot do unaligned loads on ARM,
+ // so this function must only be used to load a single character at a time.
+#if !V8_TARGET_CAN_READ_UNALIGNED
   ASSERT(characters == 1);
+#endif
+
   if (mode_ == ASCII) {
- __ ldrb(current_character(), MemOperand(end_of_input_address(), offset));
+    if (characters == 4) {
+ __ ldr(current_character(), MemOperand(end_of_input_address(), offset));
+    } else if (characters == 2) {
+ __ ldrh(current_character(), MemOperand(end_of_input_address(), offset));
+    } else {
+      ASSERT(characters == 1);
+ __ ldrb(current_character(), MemOperand(end_of_input_address(), offset));
+    }
   } else {
     ASSERT(mode_ == UC16);
- __ ldrh(current_character(), MemOperand(end_of_input_address(), offset));
+    if (characters == 2) {
+ __ ldr(current_character(), MemOperand(end_of_input_address(), offset));
+    } else {
+      ASSERT(characters == 1);
+ __ ldrh(current_character(), MemOperand(end_of_input_address(), offset));
+    }
   }
 }



--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to