]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.cc] runtime: decode power64 branch instructions the way the CPU does
authorAustin Clements <austin@google.com>
Wed, 19 Nov 2014 19:24:41 +0000 (14:24 -0500)
committerAustin Clements <austin@google.com>
Wed, 19 Nov 2014 19:24:41 +0000 (14:24 -0500)
Previously, this used the top 8 bits of an instruction as a
sort-of opcode and ignored the top two bits of the relative
PC.  This worked because these jumps are always negative and
never big enough for the top two bits of the relative PC (also
the bottom 2 bits of the sort-of opcode) to be anything other
than 0b11, but the code is confusing because it doesn't match
the actual structure of the instruction.

Instead, use the real 6 bit opcode and use all 24 bits of
relative PC.

LGTM=rsc
R=rsc, dave
CC=golang-codereviews
https://golang.org/cl/179960043

src/runtime/sys_power64x.go

index f32d1a44f15a4df86dbb49820d31bf2d349372b6..90ebde7b408a178131ed2ffbbb20059f5f6e0b23 100644 (file)
@@ -26,9 +26,9 @@ func rewindmorestack(buf *gobuf) {
        var inst uint32
        if buf.pc&3 == 0 && buf.pc != 0 {
                inst = *(*uint32)(unsafe.Pointer(buf.pc))
-               if inst>>24 == 0x4b && inst&3 == 0 {
-                       //print("runtime: rewind pc=", hex(buf.pc), " to pc=", hex(uintptr(buf.pc + int32(inst<<8)>>8)), "\n");
-                       buf.pc += uintptr(int32(inst<<8) >> 8)
+               if inst>>26 == 18 && inst&3 == 0 {
+                       //print("runtime: rewind pc=", hex(buf.pc), " to pc=", hex(uintptr(buf.pc + int32(inst<<6)>>6)), "\n");
+                       buf.pc += uintptr(int32(inst<<6) >> 6)
                        return
                }
        }