Update nterp to advance PC early on branches

Nterp checks if a suspension is required on backward branches. The
PC update was happening after the suspend point. So it appeared as
if we are suspending at the branch instead of at the loop header.
This isn't a correctness issue but updating PC early makes it consistent
with interpreter and JITed code.

Bug: 206029744
Change-Id: Id66706aea59a616220ff254d37aafbeeb188ffed
diff --git a/runtime/interpreter/mterp/arm64ng/main.S b/runtime/interpreter/mterp/arm64ng/main.S
index b83e859..6d077d5 100644
--- a/runtime/interpreter/mterp/arm64ng/main.S
+++ b/runtime/interpreter/mterp/arm64ng/main.S
@@ -290,11 +290,11 @@
 .endm
 
 .macro BRANCH
+    add     xPC, xPC, wINST, sxtw #1    // update xPC
     // Update method counter and do a suspend check if the branch is negative or zero.
     cmp wINST, #0
     b.le 2f
 1:
-    add     xPC, xPC, wINST, sxtw #1    // update xPC
     FETCH wINST, 0                      // load wINST
     GET_INST_OPCODE ip                  // extract opcode from wINST
     GOTO_OPCODE ip                      // jump to next instruction
@@ -1783,11 +1783,10 @@
    b 1b
 
 NterpHandleHotnessOverflow:
-    add x1, xPC, xINST, lsl #1
+    mov x1, xPC
     mov x2, xFP
     bl nterp_hot_method
     cbnz x0, 1f
-    add     xPC, xPC, wINST, sxtw #1    // update xPC
     FETCH wINST, 0                      // load wINST
     GET_INST_OPCODE ip                  // extract opcode from wINST
     GOTO_OPCODE ip                      // jump to next instruction
diff --git a/runtime/interpreter/mterp/armng/main.S b/runtime/interpreter/mterp/armng/main.S
index e26d922..ac1a6b0 100644
--- a/runtime/interpreter/mterp/armng/main.S
+++ b/runtime/interpreter/mterp/armng/main.S
@@ -301,12 +301,12 @@
 .endm
 
 .macro BRANCH
+    add rPC, rPC, rINST, lsl #1
     // Update method counter and do a suspend check if the branch is negative or zero.
     cmp rINST, #0
     ble 2f
 1:
-    add r2, rINST, rINST                // r2<- byte offset
-    FETCH_ADVANCE_INST_RB r2            // update xPC, load rINST
+    FETCH_INST                          // load rINST
     GET_INST_OPCODE ip                  // extract opcode from rINST
     GOTO_OPCODE ip                      // jump to next instruction
 2:
@@ -1799,13 +1799,12 @@
 
 
 NterpHandleHotnessOverflow:
-    add r1, rPC, rINST, lsl #1
+    mov r1, rPC
     mov r2, rFP
     bl nterp_hot_method
     cmp r0, #0
     bne 1f
-    add r2, rINST, rINST                // w2<- byte offset
-    FETCH_ADVANCE_INST_RB r2            // update rPC, load rINST
+    FETCH_INST                          // load rINST
     GET_INST_OPCODE ip                  // extract opcode from rINST
     GOTO_OPCODE ip                      // jump to next instruction
 1:
diff --git a/runtime/interpreter/mterp/x86_64ng/main.S b/runtime/interpreter/mterp/x86_64ng/main.S
index 8ba3e3d..88e0285 100644
--- a/runtime/interpreter/mterp/x86_64ng/main.S
+++ b/runtime/interpreter/mterp/x86_64ng/main.S
@@ -251,11 +251,11 @@
 
 
 .macro BRANCH
+    leaq    (rPC, rINSTq, 2), rPC
     // Update method counter and do a suspend check if the branch is negative or zero.
     testq rINSTq, rINSTq
     jle 3f
 2:
-    leaq    (rPC, rINSTq, 2), rPC
     FETCH_INST
     GOTO_NEXT
 3:
@@ -2171,12 +2171,11 @@
   OP_IGET load="movl", wide=0
 
 NterpHandleHotnessOverflow:
-    leaq (rPC, rINSTq, 2), %rsi
+    movq rPC, %rsi
     movq rFP, %rdx
     call nterp_hot_method
     testq %rax, %rax
     jne 1f
-    leaq    (rPC, rINSTq, 2), rPC
     FETCH_INST
     GOTO_NEXT
 1:
diff --git a/runtime/interpreter/mterp/x86ng/main.S b/runtime/interpreter/mterp/x86ng/main.S
index b785f24..9130dd1 100644
--- a/runtime/interpreter/mterp/x86ng/main.S
+++ b/runtime/interpreter/mterp/x86ng/main.S
@@ -293,11 +293,11 @@
 
 
 .macro BRANCH
+    leal    (rPC, rINST, 2), rPC
     // Update method counter and do a suspend check if the branch is negative or zero.
     testl rINST, rINST
     jle 3f
 2:
-    leal    (rPC, rINST, 2), rPC
     FETCH_INST
     GOTO_NEXT
 3:
@@ -2240,12 +2240,11 @@
     call SYMBOL(art_quick_test_suspend)
     RESTORE_IBASE
     movl LOCAL0(%esp), rINST
-    leal    (rPC, rINST, 2), rPC
     FETCH_INST
     GOTO_NEXT
 
 NterpHandleHotnessOverflow:
-    leal (rPC, rINST, 2), %ecx
+    movl rPC, %ecx
     movl rFP, ARG2
     // Save next PC.
     movl %ecx, LOCAL0(%esp)