Reviewers: paul.l..., dusmil.imgtec, akos.palfi.imgtec, balazs.kilvady,

Description:
MIPS[64]: Improved checking target ranges for J and JAL instructions. Adapted
disassembler test for J and JAL instructions.

TEST=cctest/test-disasm-mips[64]
BUG=

Please review this at https://codereview.chromium.org/1237083003/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+54, -24 lines):
  M src/mips/assembler-mips.cc
  M test/cctest/test-disasm-mips.cc
  M test/cctest/test-disasm-mips64.cc


Index: src/mips/assembler-mips.cc
diff --git a/src/mips/assembler-mips.cc b/src/mips/assembler-mips.cc
index 971e17b995c3f0c299dc234fc941fe34c49bdbb1..f907fe77d13411eab04c199c42cac37d186977cd 100644
--- a/src/mips/assembler-mips.cc
+++ b/src/mips/assembler-mips.cc
@@ -1406,11 +1406,11 @@ void Assembler::j(int32_t target) {
 #if DEBUG
   // Get pc of delay slot.
   uint32_t ipc = reinterpret_cast<uint32_t>(pc_ + 1 * kInstrSize);
-  bool in_range = (ipc ^ static_cast<uint32_t>(target) >>
-                  (kImm26Bits + kImmFieldShift)) == 0;
+  bool in_range = ((ipc ^ static_cast<uint32_t>(target)) >>
+                   (kImm26Bits + kImmFieldShift)) == 0;
   DCHECK(in_range && ((target & 3) == 0));
 #endif
-  GenInstrJump(J, target >> 2);
+  GenInstrJump(J, (target >> 2) & kImm26Mask);
 }


@@ -1432,12 +1432,12 @@ void Assembler::jal(int32_t target) {
 #ifdef DEBUG
   // Get pc of delay slot.
   uint32_t ipc = reinterpret_cast<uint32_t>(pc_ + 1 * kInstrSize);
-  bool in_range = (ipc ^ static_cast<uint32_t>(target) >>
-                  (kImm26Bits + kImmFieldShift)) == 0;
+  bool in_range = ((ipc ^ static_cast<uint32_t>(target)) >>
+                   (kImm26Bits + kImmFieldShift)) == 0;
   DCHECK(in_range && ((target & 3) == 0));
 #endif
   positions_recorder()->WriteRecordedPositions();
-  GenInstrJump(JAL, target >> 2);
+  GenInstrJump(JAL, (target >> 2) & kImm26Mask);
 }


Index: test/cctest/test-disasm-mips.cc
diff --git a/test/cctest/test-disasm-mips.cc b/test/cctest/test-disasm-mips.cc index c04cd23bf5aa9c0c53fd586c0067347f21ee9a32..1688d199cc599f701cf07663c422ef33e8845e79 100644
--- a/test/cctest/test-disasm-mips.cc
+++ b/test/cctest/test-disasm-mips.cc
@@ -121,16 +121,25 @@ if (failure) { \
int pc_offset = assm.pc_offset(); \ byte *progcounter = &buffer[pc_offset]; \ char str_with_address[100]; \ - int instr_index = target >> 2; \ - snprintf(str_with_address, sizeof(str_with_address), "%s -> %p", \ - compare_string, reinterpret_cast<byte *>( \ - ((uint32_t)(progcounter + 1) & ~0xfffffff) | \ + int instr_index = (target >> 2) & kImm26Mask; \ + snprintf( \ + str_with_address, sizeof(str_with_address), "%s %p -> %p", \ + compare_string, reinterpret_cast<byte *>(target), \ + reinterpret_cast<byte *>(((uint32_t)(progcounter + 4) & ~0xfffffff) | \ (instr_index << 2))); \ assm.asm_; \ if (!DisassembleAndCompare(progcounter, str_with_address)) failure = true; \
   }


+#define GET_PC_REGION(pc_region)                                         \
+  {                                                                      \
+    int pc_offset = assm.pc_offset();                                    \
+    byte *progcounter = &buffer[pc_offset];                              \
+    pc_region = reinterpret_cast<int32_t>(progcounter + 4) & ~0xfffffff; \
+  }
+
+
 TEST(Type0) {
   SET_UP();

@@ -466,12 +475,18 @@ TEST(Type0) {
COMPARE_PC_REL_COMPACT(bgtz(a0, 32767), "1c807fff bgtz a0, 32767",
                          32767);

-  COMPARE_PC_JUMP(j(0x4), "08000001       j       0x4", 0x4);
- COMPARE_PC_JUMP(j(0xffffffc), "0bffffff j 0xffffffc", 0xffffffc);
+  int32_t pc_region;
+  GET_PC_REGION(pc_region);
+
+  int32_t target = pc_region | 0x4;
+  COMPARE_PC_JUMP(j(target), "08000001       j      ", target);
+  target = pc_region | 0xffffffc;
+  COMPARE_PC_JUMP(j(target), "0bffffff       j      ", target);

-  COMPARE_PC_JUMP(jal(0x4), "0c000001       jal     0x4", 0x4);
-  COMPARE_PC_JUMP(jal(0xffffffc), "0fffffff       jal     0xffffffc",
-                  0xffffffc);
+  target = pc_region | 0x4;
+  COMPARE_PC_JUMP(jal(target), "0c000001       jal    ", target);
+  target = pc_region | 0xffffffc;
+  COMPARE_PC_JUMP(jal(target), "0fffffff       jal    ", target);

   COMPARE(addiu(a0, a1, 0x0),
           "24a40000       addiu   a0, a1, 0");
Index: test/cctest/test-disasm-mips64.cc
diff --git a/test/cctest/test-disasm-mips64.cc b/test/cctest/test-disasm-mips64.cc index 225a1e7f0b1baa253c71d3d4157ab2922d10be2d..e224131d6d5219225d14a2b4b500a5aa23c68a48 100644
--- a/test/cctest/test-disasm-mips64.cc
+++ b/test/cctest/test-disasm-mips64.cc
@@ -121,16 +121,25 @@ if (failure) { \
int pc_offset = assm.pc_offset(); \ byte *progcounter = &buffer[pc_offset]; \ char str_with_address[100]; \ - int instr_index = target >> 2; \ - snprintf(str_with_address, sizeof(str_with_address), "%s -> %p", \ - compare_string, reinterpret_cast<byte *>( \ - ((uint64_t)(progcounter + 1) & ~0xfffffff) | \ + int instr_index = (target >> 2) & kImm26Mask; \ + snprintf( \ + str_with_address, sizeof(str_with_address), "%s %p -> %p", \ + compare_string, reinterpret_cast<byte *>(target), \ + reinterpret_cast<byte *>(((uint64_t)(progcounter + 1) & ~0xfffffff) | \ (instr_index << 2))); \ assm.asm_; \ if (!DisassembleAndCompare(progcounter, str_with_address)) failure = true; \
   }


+#define GET_PC_REGION(pc_region)                                         \
+  {                                                                      \
+    int pc_offset = assm.pc_offset();                                    \
+    byte *progcounter = &buffer[pc_offset];                              \
+    pc_region = reinterpret_cast<int64_t>(progcounter + 4) & ~0xfffffff; \
+  }
+
+
 TEST(Type0) {
   SET_UP();

@@ -1114,12 +1123,18 @@ TEST(Type3) {
COMPARE_PC_REL_COMPACT(bgtz(a0, 32767), "1c807fff bgtz a0, 32767",
                          32767);

-  COMPARE_PC_JUMP(j(0x4), "08000001       j       0x4", 0x4);
- COMPARE_PC_JUMP(j(0xffffffc), "0bffffff j 0xffffffc", 0xffffffc);
+  int64_t pc_region;
+  GET_PC_REGION(pc_region);
+
+  int64_t target = pc_region | 0x4;
+  COMPARE_PC_JUMP(j(target), "08000001       j      ", target);
+  target = pc_region | 0xffffffc;
+  COMPARE_PC_JUMP(j(target), "0bffffff       j      ", target);

-  COMPARE_PC_JUMP(jal(0x4), "0c000001       jal     0x4", 0x4);
-  COMPARE_PC_JUMP(jal(0xffffffc), "0fffffff       jal     0xffffffc",
-                  0xffffffc);
+  target = pc_region | 0x4;
+  COMPARE_PC_JUMP(jal(target), "0c000001       jal    ", target);
+  target = pc_region | 0xffffffc;
+  COMPARE_PC_JUMP(jal(target), "0fffffff       jal    ", target);

   VERIFY_RUN();
 }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to