@@ -30,18 +30,7 @@ func GoSyntax(inst Inst, pc uint64, symname func(uint64) (string, uint64)) strin
30
30
break
31
31
}
32
32
if s := plan9Arg (& inst , i , pc , a , symname ); s != "" {
33
- // In the case for some BC instructions, a CondReg arg has
34
- // both the CR and the branch condition encoded in its value.
35
- // plan9Arg will return a string with the string representation
36
- // of these values separated by a blank that will be treated
37
- // as 2 args from this point on.
38
- if strings .IndexByte (s , ' ' ) > 0 {
39
- t := strings .Split (s , " " )
40
- args = append (args , t [0 ])
41
- args = append (args , t [1 ])
42
- } else {
43
- args = append (args , s )
44
- }
33
+ args = append (args , s )
45
34
}
46
35
}
47
36
var op string
@@ -61,7 +50,7 @@ func GoSyntax(inst Inst, pc uint64, symname func(uint64) (string, uint64)) strin
61
50
case 1 :
62
51
return fmt .Sprintf ("%s %s" , op , args [0 ])
63
52
case 2 :
64
- if inst .Op == COPY || inst .Op == PASTECC || inst . Op == FCMPO || inst . Op == FCMPU {
53
+ if inst .Op == COPY || inst .Op == PASTECC {
65
54
return op + " " + args [0 ] + "," + args [1 ]
66
55
}
67
56
return op + " " + args [1 ] + "," + args [0 ]
@@ -97,13 +86,13 @@ func GoSyntax(inst Inst, pc uint64, symname func(uint64) (string, uint64)) strin
97
86
STQ , STFD , STFDU , STFS , STFSU :
98
87
return op + " " + strings .Join (args , "," )
99
88
100
- case CMPD , CMPDI , CMPLD , CMPLDI , CMPW , CMPWI , CMPLW , CMPLWI :
101
- if len ( args ) == 2 {
102
- return op + " " + args [0 ] + "," + args [1 ]
103
- } else if len ( args ) == 3 {
104
- return op + " " + args [ 0 ] + " ," + args [1 ] + "," + args [ 2 ]
89
+ case FCMPU , FCMPO , CMPD , CMPDI , CMPLD , CMPLDI , CMPW , CMPWI , CMPLW , CMPLWI :
90
+ crf := int ( inst . Args [ 0 ].( CondReg ) - CR0 )
91
+ cmpstr := op + " " + args [1 ] + "," + args [2 ]
92
+ if crf != 0 { // print CRx as the final operand if not implied (i.e BF != 0)
93
+ cmpstr += " ," + args [0 ]
105
94
}
106
- return op + " " + args [ 0 ] + " ??"
95
+ return cmpstr
107
96
108
97
case LIS :
109
98
return "ADDIS $0," + args [1 ] + "," + args [0 ]
@@ -152,16 +141,15 @@ func GoSyntax(inst Inst, pc uint64, symname func(uint64) (string, uint64)) strin
152
141
}
153
142
return op + " " + strings .Join (args , ", " )
154
143
case BC :
155
- if int (inst .Args [0 ].(Imm ))& 0x1c == 12 { // jump on cond bit set
156
- if len ( args ) == 4 {
157
- return fmt . Sprintf ( "B%s %s,%s" , args [ 1 ], args [ 2 ], args [ 3 ])
158
- }
159
- return fmt . Sprintf ( "B%s %s" , args [ 1 ], args [ 2 ])
160
- } else if int ( inst . Args [ 0 ].( Imm )) & 0x1c == 4 && revCondMap [ args [1 ]] != "" { // jump on cond bit not set
161
- if len ( args ) == 4 {
162
- return fmt .Sprintf ("B%s %s,%s " , revCondMap [ args [ 1 ]] , args [2 ], args [ 3 ])
144
+ bo := int (inst .Args [0 ].(Imm ))
145
+ bi := int ( inst . Args [ 1 ].( CondReg ) - Cond0LT )
146
+ bcname := condName [(( bo & 0x8 ) >> 1 ) | ( bi & 0x3 )]
147
+ if bo & 0x17 == 4 { // jump only a CR bit set/unset, no hints (at bits) set.
148
+ if bi >= 4 {
149
+ return fmt . Sprintf ( "B%s CR%d,%s" , bcname , bi >> 2 , args [2 ])
150
+ } else {
151
+ return fmt .Sprintf ("B%s %s" , bcname , args [2 ])
163
152
}
164
- return fmt .Sprintf ("B%s %s" , revCondMap [args [1 ]], args [2 ])
165
153
}
166
154
return op + " " + strings .Join (args , "," )
167
155
case BCCTR :
@@ -203,19 +191,14 @@ func plan9Arg(inst *Inst, argIndex int, pc uint64, arg Arg, symname func(uint64)
203
191
if inst .Op == ISEL {
204
192
return fmt .Sprintf ("$%d" , (arg - Cond0LT ))
205
193
}
206
- if arg == CR0 && (strings .HasPrefix (inst .Op .String (), "cmp" ) || strings .HasPrefix (inst .Op .String (), "fcmp" )) {
207
- return "" // don't show cr0 for cmp instructions
208
- } else if arg >= CR0 {
209
- return fmt .Sprintf ("CR%d" , int (arg - CR0 ))
210
- }
211
194
bit := [4 ]string {"LT" , "GT" , "EQ" , "SO" }[(arg - Cond0LT )% 4 ]
212
- if strings .HasPrefix (inst .Op .String (), "cr" ) {
213
- return fmt .Sprintf ("CR%d%s" , int (arg - Cond0LT )/ 4 , bit )
214
- }
215
195
if arg <= Cond0SO {
216
196
return bit
197
+ } else if arg > Cond0SO && arg <= Cond7SO {
198
+ return fmt .Sprintf ("CR%d%s" , int (arg - Cond0LT )/ 4 , bit )
199
+ } else {
200
+ return fmt .Sprintf ("CR%d" , int (arg - CR0 ))
217
201
}
218
- return fmt .Sprintf ("%s CR%d" , bit , int (arg - Cond0LT )/ 4 )
219
202
case Imm :
220
203
return fmt .Sprintf ("$%d" , arg )
221
204
case SpReg :
@@ -281,6 +264,20 @@ var revCondMap = map[string]string{
281
264
"LT" : "GE" , "GT" : "LE" , "EQ" : "NE" ,
282
265
}
283
266
267
+ // Lookup table to map BI[0:1] and BO[3] to an extended mnemonic for CR ops.
268
+ // Bits 0-1 map to a bit with a CR field, and bit 2 selects the inverted (0)
269
+ // or regular (1) extended mnemonic.
270
+ var condName = []string {
271
+ "GE" ,
272
+ "LE" ,
273
+ "NE" ,
274
+ "NSO" ,
275
+ "LT" ,
276
+ "GT" ,
277
+ "EQ" ,
278
+ "SO" ,
279
+ }
280
+
284
281
// plan9OpMap maps an Op to its Plan 9 mnemonics, if different than its GNU mnemonics.
285
282
var plan9OpMap = map [Op ]string {
286
283
LWARX : "LWAR" ,
0 commit comments