Coverage Report

Created: 2025-07-09 06:32

/src/capstonenext/arch/TMS320C64x/TMS320C64xInstPrinter.c
Line
Count
Source (jump to first uncovered line)
1
/* Capstone Disassembly Engine */
2
/* TMS320C64x Backend by Fotis Loukos <me@fotisl.com> 2016 */
3
4
#ifdef CAPSTONE_HAS_TMS320C64X
5
6
#include <ctype.h>
7
#include <string.h>
8
9
#include "TMS320C64xInstPrinter.h"
10
#include "../../MCInst.h"
11
#include "../../utils.h"
12
#include "../../SStream.h"
13
#include "../../MCRegisterInfo.h"
14
#include "../../MathExtras.h"
15
#include "TMS320C64xMapping.h"
16
17
#include "capstone/tms320c64x.h"
18
19
static const char *getRegisterName(unsigned RegNo);
20
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O);
21
static void printMemOperand(MCInst *MI, unsigned OpNo, SStream *O);
22
static void printMemOperand2(MCInst *MI, unsigned OpNo, SStream *O);
23
static void printRegPair(MCInst *MI, unsigned OpNo, SStream *O);
24
25
void TMS320C64x_post_printer(csh ud, cs_insn *insn, SStream *insn_asm, MCInst *mci)
26
37.8k
{
27
37.8k
  SStream ss;
28
37.8k
  const char *op_str_ptr, *p2;
29
37.8k
  char tmp[8] = { 0 };
30
37.8k
  unsigned int unit = 0;
31
37.8k
  int i;
32
37.8k
  cs_tms320c64x *tms320c64x;
33
34
37.8k
  if (mci->csh->detail_opt) {
35
37.8k
    tms320c64x = &mci->flat_insn->detail->tms320c64x;
36
37
37.8k
    for (i = 0; i < insn->detail->groups_count; i++) {
38
37.8k
      switch(insn->detail->groups[i]) {
39
11.4k
        case TMS320C64X_GRP_FUNIT_D:
40
11.4k
          unit = TMS320C64X_FUNIT_D;
41
11.4k
          break;
42
7.42k
        case TMS320C64X_GRP_FUNIT_L:
43
7.42k
          unit = TMS320C64X_FUNIT_L;
44
7.42k
          break;
45
2.47k
        case TMS320C64X_GRP_FUNIT_M:
46
2.47k
          unit = TMS320C64X_FUNIT_M;
47
2.47k
          break;
48
15.6k
        case TMS320C64X_GRP_FUNIT_S:
49
15.6k
          unit = TMS320C64X_FUNIT_S;
50
15.6k
          break;
51
800
        case TMS320C64X_GRP_FUNIT_NO:
52
800
          unit = TMS320C64X_FUNIT_NO;
53
800
          break;
54
37.8k
      }
55
37.8k
      if (unit != 0)
56
37.8k
        break;
57
37.8k
    }
58
37.8k
    tms320c64x->funit.unit = unit;
59
60
37.8k
    SStream_Init(&ss);
61
37.8k
    if (tms320c64x->condition.reg != TMS320C64X_REG_INVALID)
62
25.4k
      SStream_concat(&ss, "[%c%s]|", (tms320c64x->condition.zero == 1) ? '!' : '|', cs_reg_name(ud, tms320c64x->condition.reg));
63
64
    // Sorry for all the fixes below. I don't have time to add more helper SStream functions.
65
    // Before that they messed around with the private buffer of the stream.
66
    // So it is better now. But still not efficient.
67
37.8k
    op_str_ptr = strchr(SStream_rbuf(insn_asm), '\t');
68
69
37.8k
    if ((op_str_ptr != NULL) && (((p2 = strchr(op_str_ptr, '[')) != NULL) || ((p2 = strchr(op_str_ptr, '(')) != NULL))) {
70
41.7k
      while ((p2 > op_str_ptr) && ((*p2 != 'a') && (*p2 != 'b')))
71
31.7k
        p2--;
72
10.0k
      if (p2 == op_str_ptr) {
73
0
        SStream_Flush(insn_asm, NULL);
74
0
        SStream_concat0(insn_asm, "Invalid!");
75
0
        return;
76
0
      }
77
10.0k
      if (*p2 == 'a')
78
4.78k
        strncpy(tmp, "1T", sizeof(tmp));
79
5.26k
      else
80
5.26k
        strncpy(tmp, "2T", sizeof(tmp));
81
27.7k
    } else {
82
27.7k
      tmp[0] = '\0';
83
27.7k
    }
84
37.8k
    SStream mnem_post = { 0 };
85
37.8k
    SStream_Init(&mnem_post);
86
37.8k
    switch(tms320c64x->funit.unit) {
87
11.4k
      case TMS320C64X_FUNIT_D:
88
11.4k
        SStream_concat(&mnem_post, ".D%s%u", tmp, tms320c64x->funit.side);
89
11.4k
        break;
90
7.42k
      case TMS320C64X_FUNIT_L:
91
7.42k
        SStream_concat(&mnem_post, ".L%s%u", tmp, tms320c64x->funit.side);
92
7.42k
        break;
93
2.47k
      case TMS320C64X_FUNIT_M:
94
2.47k
        SStream_concat(&mnem_post, ".M%s%u", tmp, tms320c64x->funit.side);
95
2.47k
        break;
96
15.6k
      case TMS320C64X_FUNIT_S:
97
15.6k
        SStream_concat(&mnem_post, ".S%s%u", tmp, tms320c64x->funit.side);
98
15.6k
        break;
99
37.8k
    }
100
37.8k
    if (tms320c64x->funit.crosspath > 0)
101
10.3k
      SStream_concat0(&mnem_post, "X");
102
103
37.8k
    if (op_str_ptr != NULL) {
104
      // There is an op_str
105
37.0k
      SStream_concat1(&mnem_post, '\t');
106
37.0k
      SStream_replc_str(insn_asm, '\t', SStream_rbuf(&mnem_post));
107
37.0k
    }
108
109
37.8k
    if (tms320c64x->parallel != 0)
110
15.7k
      SStream_concat0(insn_asm, "\t||");
111
37.8k
    SStream_concat0(&ss, SStream_rbuf(insn_asm));
112
37.8k
    SStream_Flush(insn_asm, NULL);
113
37.8k
    SStream_concat0(insn_asm, SStream_rbuf(&ss));
114
37.8k
  }
115
37.8k
}
116
117
#define PRINT_ALIAS_INSTR
118
#include "TMS320C64xGenAsmWriter.inc"
119
120
#define GET_INSTRINFO_ENUM
121
#include "TMS320C64xGenInstrInfo.inc"
122
123
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
124
149k
{
125
149k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
126
149k
  unsigned reg;
127
128
149k
  if (MCOperand_isReg(Op)) {
129
108k
    reg = MCOperand_getReg(Op);
130
108k
    if ((MCInst_getOpcode(MI) == TMS320C64x_MVC_s1_rr) && (OpNo == 1)) {
131
3.33k
      switch(reg) {
132
587
        case TMS320C64X_REG_EFR:
133
587
          SStream_concat0(O, "EFR");
134
587
          break;
135
1.42k
        case TMS320C64X_REG_IFR:
136
1.42k
          SStream_concat0(O, "IFR");
137
1.42k
          break;
138
1.32k
        default:
139
1.32k
          SStream_concat0(O, getRegisterName(reg));
140
1.32k
          break;
141
3.33k
      }
142
105k
    } else {
143
105k
      SStream_concat0(O, getRegisterName(reg));
144
105k
    }
145
146
108k
    if (MI->csh->detail_opt) {
147
108k
      MI->flat_insn->detail->tms320c64x.operands[MI->flat_insn->detail->tms320c64x.op_count].type = TMS320C64X_OP_REG;
148
108k
      MI->flat_insn->detail->tms320c64x.operands[MI->flat_insn->detail->tms320c64x.op_count].reg = reg;
149
108k
      MI->flat_insn->detail->tms320c64x.op_count++;
150
108k
    }
151
108k
  } else if (MCOperand_isImm(Op)) {
152
40.3k
    int64_t Imm = MCOperand_getImm(Op);
153
154
40.3k
    if (Imm >= 0) {
155
32.6k
      if (Imm > HEX_THRESHOLD)
156
19.6k
        SStream_concat(O, "0x%"PRIx64, Imm);
157
13.0k
      else
158
13.0k
        SStream_concat(O, "%"PRIu64, Imm);
159
32.6k
    } else {
160
7.66k
      if (Imm < -HEX_THRESHOLD)
161
6.59k
        SStream_concat(O, "-0x%"PRIx64, -Imm);
162
1.06k
      else
163
1.06k
        SStream_concat(O, "-%"PRIu64, -Imm);
164
7.66k
    }
165
166
40.3k
    if (MI->csh->detail_opt) {
167
40.3k
      MI->flat_insn->detail->tms320c64x.operands[MI->flat_insn->detail->tms320c64x.op_count].type = TMS320C64X_OP_IMM;
168
40.3k
      MI->flat_insn->detail->tms320c64x.operands[MI->flat_insn->detail->tms320c64x.op_count].imm = Imm;
169
40.3k
      MI->flat_insn->detail->tms320c64x.op_count++;
170
40.3k
    }
171
40.3k
  }
172
149k
}
173
174
static void printMemOperand(MCInst *MI, unsigned OpNo, SStream *O)
175
9.28k
{
176
9.28k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
177
9.28k
  int64_t Val = MCOperand_getImm(Op);
178
9.28k
  unsigned scaled, base, offset, mode, unit;
179
9.28k
  cs_tms320c64x *tms320c64x;
180
9.28k
  char st, nd;
181
182
9.28k
  scaled = (Val >> 19) & 1;
183
9.28k
  base = (Val >> 12) & 0x7f;
184
9.28k
  offset = (Val >> 5) & 0x7f;
185
9.28k
  mode = (Val >> 1) & 0xf;
186
9.28k
  unit = Val & 1;
187
188
9.28k
  if (scaled) {
189
8.09k
    st = '[';
190
8.09k
    nd = ']';
191
8.09k
  } else {
192
1.18k
    st = '(';
193
1.18k
    nd = ')';
194
1.18k
  }
195
196
9.28k
  switch(mode) {
197
1.13k
    case 0:
198
1.13k
      SStream_concat(O, "*-%s%c%u%c", getRegisterName(base), st, offset, nd);
199
1.13k
      break;
200
738
    case 1:
201
738
      SStream_concat(O, "*+%s%c%u%c", getRegisterName(base), st, offset, nd);
202
738
      break;
203
615
    case 4:
204
615
      SStream_concat(O, "*-%s%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);
205
615
      break;
206
357
    case 5:
207
357
      SStream_concat(O, "*+%s%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);
208
357
      break;
209
519
    case 8:
210
519
      SStream_concat(O, "*--%s%c%u%c", getRegisterName(base), st, offset, nd);
211
519
      break;
212
912
    case 9:
213
912
      SStream_concat(O, "*++%s%c%u%c", getRegisterName(base), st, offset, nd);
214
912
      break;
215
1.19k
    case 10:
216
1.19k
      SStream_concat(O, "*%s--%c%u%c", getRegisterName(base), st, offset, nd);
217
1.19k
      break;
218
1.77k
    case 11:
219
1.77k
      SStream_concat(O, "*%s++%c%u%c", getRegisterName(base), st, offset, nd);
220
1.77k
      break;
221
898
    case 12:
222
898
      SStream_concat(O, "*--%s%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);
223
898
      break;
224
450
    case 13:
225
450
      SStream_concat(O, "*++%s%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);
226
450
      break;
227
457
    case 14:
228
457
      SStream_concat(O, "*%s--%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);
229
457
      break;
230
230
    case 15:
231
230
      SStream_concat(O, "*%s++%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);
232
230
      break;
233
9.28k
  }
234
235
9.28k
  if (MI->csh->detail_opt) {
236
9.28k
    tms320c64x = &MI->flat_insn->detail->tms320c64x;
237
238
9.28k
    tms320c64x->operands[tms320c64x->op_count].type = TMS320C64X_OP_MEM;
239
9.28k
    tms320c64x->operands[tms320c64x->op_count].mem.base = base;
240
9.28k
    tms320c64x->operands[tms320c64x->op_count].mem.disp = offset;
241
9.28k
    tms320c64x->operands[tms320c64x->op_count].mem.unit = unit + 1;
242
9.28k
    tms320c64x->operands[tms320c64x->op_count].mem.scaled = scaled;
243
9.28k
    switch(mode) {
244
1.13k
      case 0:
245
1.13k
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;
246
1.13k
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;
247
1.13k
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;
248
1.13k
        break;
249
738
      case 1:
250
738
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;
251
738
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;
252
738
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;
253
738
        break;
254
615
      case 4:
255
615
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;
256
615
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;
257
615
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;
258
615
        break;
259
357
      case 5:
260
357
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;
261
357
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;
262
357
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;
263
357
        break;
264
519
      case 8:
265
519
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;
266
519
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;
267
519
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_PRE;
268
519
        break;
269
912
      case 9:
270
912
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;
271
912
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;
272
912
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_PRE;
273
912
        break;
274
1.19k
      case 10:
275
1.19k
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;
276
1.19k
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;
277
1.19k
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_POST;
278
1.19k
        break;
279
1.77k
      case 11:
280
1.77k
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;
281
1.77k
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;
282
1.77k
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_POST;
283
1.77k
        break;
284
898
      case 12:
285
898
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;
286
898
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;
287
898
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_PRE;
288
898
        break;
289
450
      case 13:
290
450
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;
291
450
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;
292
450
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_PRE;
293
450
        break;
294
457
      case 14:
295
457
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;
296
457
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;
297
457
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_POST;
298
457
        break;
299
230
      case 15:
300
230
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;
301
230
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;
302
230
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_POST;
303
230
        break;
304
9.28k
    }
305
9.28k
    tms320c64x->op_count++;
306
9.28k
  }
307
9.28k
}
308
309
static void printMemOperand2(MCInst *MI, unsigned OpNo, SStream *O)
310
8.81k
{
311
8.81k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
312
8.81k
  int64_t Val = MCOperand_getImm(Op);
313
8.81k
  uint16_t offset;
314
8.81k
  unsigned basereg;
315
8.81k
  cs_tms320c64x *tms320c64x;
316
317
8.81k
  basereg = Val & 0x7f;
318
8.81k
  offset = (Val >> 7) & 0x7fff;
319
8.81k
  SStream_concat(O, "*+%s[0x%x]", getRegisterName(basereg), offset);
320
321
8.81k
  if (MI->csh->detail_opt) {
322
8.81k
    tms320c64x = &MI->flat_insn->detail->tms320c64x;
323
324
8.81k
    tms320c64x->operands[tms320c64x->op_count].type = TMS320C64X_OP_MEM;
325
8.81k
    tms320c64x->operands[tms320c64x->op_count].mem.base = basereg;
326
8.81k
    tms320c64x->operands[tms320c64x->op_count].mem.unit = 2;
327
8.81k
    tms320c64x->operands[tms320c64x->op_count].mem.disp = offset;
328
8.81k
    tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;
329
8.81k
    tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;
330
8.81k
    tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;
331
8.81k
    tms320c64x->op_count++;
332
8.81k
  }
333
8.81k
}
334
335
static void printRegPair(MCInst *MI, unsigned OpNo, SStream *O)
336
23.1k
{
337
23.1k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
338
23.1k
  unsigned reg = MCOperand_getReg(Op);
339
23.1k
  cs_tms320c64x *tms320c64x;
340
341
23.1k
  SStream_concat(O, "%s:%s", getRegisterName(reg + 1), getRegisterName(reg));
342
343
23.1k
  if (MI->csh->detail_opt) {
344
23.1k
    tms320c64x = &MI->flat_insn->detail->tms320c64x;
345
346
23.1k
    tms320c64x->operands[tms320c64x->op_count].type = TMS320C64X_OP_REGPAIR;
347
23.1k
    tms320c64x->operands[tms320c64x->op_count].reg = reg;
348
23.1k
    tms320c64x->op_count++;
349
23.1k
  }
350
23.1k
}
351
352
static bool printAliasInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)
353
80.0k
{
354
80.0k
  unsigned opcode = MCInst_getOpcode(MI);
355
80.0k
  MCOperand *op;
356
357
80.0k
  switch(opcode) {
358
    /* ADD.Dx -i, x, y -> SUB.Dx x, i, y */
359
299
    case TMS320C64x_ADD_d2_rir:
360
    /* ADD.L -i, x, y -> SUB.L x, i, y */
361
1.13k
    case TMS320C64x_ADD_l1_irr:
362
1.73k
    case TMS320C64x_ADD_l1_ipp:
363
    /* ADD.S -i, x, y -> SUB.S x, i, y */
364
2.31k
    case TMS320C64x_ADD_s1_irr:
365
2.31k
      if ((MCInst_getNumOperands(MI) == 3) &&
366
2.31k
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
367
2.31k
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
368
2.31k
        MCOperand_isImm(MCInst_getOperand(MI, 2)) &&
369
2.31k
        (MCOperand_getImm(MCInst_getOperand(MI, 2)) < 0)) {
370
371
850
        MCInst_setOpcodePub(MI, TMS320C64X_INS_SUB);
372
850
        op = MCInst_getOperand(MI, 2);
373
850
        MCOperand_setImm(op, -MCOperand_getImm(op));
374
375
850
        SStream_concat0(O, "SUB\t");
376
850
        printOperand(MI, 1, O);
377
850
        SStream_concat0(O, ", ");
378
850
        printOperand(MI, 2, O);
379
850
        SStream_concat0(O, ", ");
380
850
        printOperand(MI, 0, O);
381
382
850
        return true;
383
850
      }
384
1.46k
      break;
385
80.0k
  }
386
79.1k
  switch(opcode) {
387
    /* ADD.D 0, x, y -> MV.D x, y */
388
504
    case TMS320C64x_ADD_d1_rir:
389
    /* OR.D x, 0, y -> MV.D x, y */
390
813
    case TMS320C64x_OR_d2_rir:
391
    /* ADD.L 0, x, y -> MV.L x, y */
392
1.30k
    case TMS320C64x_ADD_l1_irr:
393
1.57k
    case TMS320C64x_ADD_l1_ipp:
394
    /* OR.L 0, x, y -> MV.L x, y */
395
2.10k
    case TMS320C64x_OR_l1_irr:
396
    /* ADD.S 0, x, y -> MV.S x, y */
397
2.67k
    case TMS320C64x_ADD_s1_irr:
398
    /* OR.S 0, x, y -> MV.S x, y */
399
3.23k
    case TMS320C64x_OR_s1_irr:
400
3.23k
      if ((MCInst_getNumOperands(MI) == 3) &&
401
3.23k
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
402
3.23k
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
403
3.23k
        MCOperand_isImm(MCInst_getOperand(MI, 2)) &&
404
3.23k
        (MCOperand_getImm(MCInst_getOperand(MI, 2)) == 0)) {
405
406
258
        MCInst_setOpcodePub(MI, TMS320C64X_INS_MV);
407
258
        MI->size--;
408
409
258
        SStream_concat0(O, "MV\t");
410
258
        printOperand(MI, 1, O);
411
258
        SStream_concat0(O, ", ");
412
258
        printOperand(MI, 0, O);
413
414
258
        return true;
415
258
      }
416
2.98k
      break;
417
79.1k
  }
418
78.9k
  switch(opcode) {
419
    /* XOR.D -1, x, y -> NOT.D x, y */
420
548
    case TMS320C64x_XOR_d2_rir:
421
    /* XOR.L -1, x, y -> NOT.L x, y */
422
788
    case TMS320C64x_XOR_l1_irr:
423
    /* XOR.S -1, x, y -> NOT.S x, y */
424
1.60k
    case TMS320C64x_XOR_s1_irr:
425
1.60k
      if ((MCInst_getNumOperands(MI) == 3) &&
426
1.60k
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
427
1.60k
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
428
1.60k
        MCOperand_isImm(MCInst_getOperand(MI, 2)) &&
429
1.60k
        (MCOperand_getImm(MCInst_getOperand(MI, 2)) == -1)) {
430
431
262
        MCInst_setOpcodePub(MI, TMS320C64X_INS_NOT);
432
262
        MI->size--;
433
434
262
        SStream_concat0(O, "NOT\t");
435
262
        printOperand(MI, 1, O);
436
262
        SStream_concat0(O, ", ");
437
262
        printOperand(MI, 0, O);
438
439
262
        return true;
440
262
      }
441
1.34k
      break;
442
78.9k
  }
443
78.6k
  switch(opcode) {
444
    /* MVK.D 0, x -> ZERO.D x */
445
662
    case TMS320C64x_MVK_d1_rr:
446
    /* MVK.L 0, x -> ZERO.L x */
447
2.31k
    case TMS320C64x_MVK_l2_ir:
448
2.31k
      if ((MCInst_getNumOperands(MI) == 2) &&
449
2.31k
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
450
2.31k
        MCOperand_isImm(MCInst_getOperand(MI, 1)) &&
451
2.31k
        (MCOperand_getImm(MCInst_getOperand(MI, 1)) == 0)) {
452
453
505
        MCInst_setOpcodePub(MI, TMS320C64X_INS_ZERO);
454
505
        MI->size--;
455
456
505
        SStream_concat0(O, "ZERO\t");
457
505
        printOperand(MI, 0, O);
458
459
505
        return true;
460
505
      }
461
1.80k
      break;
462
78.6k
  }
463
78.1k
  switch(opcode) {
464
    /* SUB.L x, x, y -> ZERO.L y */
465
992
    case TMS320C64x_SUB_l1_rrp_x1:
466
    /* SUB.S x, x, y -> ZERO.S y */
467
1.14k
    case TMS320C64x_SUB_s1_rrr:
468
1.14k
      if ((MCInst_getNumOperands(MI) == 3) &&
469
1.14k
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
470
1.14k
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
471
1.14k
        MCOperand_isReg(MCInst_getOperand(MI, 2)) &&
472
1.14k
        (MCOperand_getReg(MCInst_getOperand(MI, 1)) == MCOperand_getReg(MCInst_getOperand(MI, 2)))) {
473
474
411
        MCInst_setOpcodePub(MI, TMS320C64X_INS_ZERO);
475
411
        MI->size -= 2;
476
477
411
        SStream_concat0(O, "ZERO\t");
478
411
        printOperand(MI, 0, O);
479
480
411
        return true;
481
411
      }
482
738
      break;
483
78.1k
  }
484
77.7k
  switch(opcode) {
485
    /* SUB.L 0, x, y -> NEG.L x, y */
486
854
    case TMS320C64x_SUB_l1_irr:
487
1.36k
    case TMS320C64x_SUB_l1_ipp:
488
    /* SUB.S 0, x, y -> NEG.S x, y */
489
1.47k
    case TMS320C64x_SUB_s1_irr:
490
1.47k
      if ((MCInst_getNumOperands(MI) == 3) &&
491
1.47k
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
492
1.47k
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
493
1.47k
        MCOperand_isImm(MCInst_getOperand(MI, 2)) &&
494
1.47k
        (MCOperand_getImm(MCInst_getOperand(MI, 2)) == 0)) {
495
496
292
        MCInst_setOpcodePub(MI, TMS320C64X_INS_NEG);
497
292
        MI->size--;
498
499
292
        SStream_concat0(O, "NEG\t");
500
292
        printOperand(MI, 1, O);
501
292
        SStream_concat0(O, ", ");
502
292
        printOperand(MI, 0, O);
503
504
292
        return true;
505
292
      }
506
1.17k
      break;
507
77.7k
  }
508
77.4k
  switch(opcode) {
509
    /* PACKLH2.L x, x, y -> SWAP2.L x, y */
510
417
    case TMS320C64x_PACKLH2_l1_rrr_x2:
511
    /* PACKLH2.S x, x, y -> SWAP2.S x, y */
512
781
    case TMS320C64x_PACKLH2_s1_rrr:
513
781
      if ((MCInst_getNumOperands(MI) == 3) &&
514
781
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
515
781
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
516
781
        MCOperand_isReg(MCInst_getOperand(MI, 2)) &&
517
781
        (MCOperand_getReg(MCInst_getOperand(MI, 1)) == MCOperand_getReg(MCInst_getOperand(MI, 2)))) {
518
519
49
        MCInst_setOpcodePub(MI, TMS320C64X_INS_SWAP2);
520
49
        MI->size--;
521
522
49
        SStream_concat0(O, "SWAP2\t");
523
49
        printOperand(MI, 1, O);
524
49
        SStream_concat0(O, ", ");
525
49
        printOperand(MI, 0, O);
526
527
49
        return true;
528
49
      }
529
732
      break;
530
77.4k
  }
531
77.4k
  switch(opcode) {
532
    /* NOP 16 -> IDLE */
533
    /* NOP 1 -> NOP */
534
1.71k
    case TMS320C64x_NOP_n:
535
1.71k
      if ((MCInst_getNumOperands(MI) == 1) &&
536
1.71k
        MCOperand_isImm(MCInst_getOperand(MI, 0)) &&
537
1.71k
        (MCOperand_getReg(MCInst_getOperand(MI, 0)) == 16)) {
538
539
274
        MCInst_setOpcodePub(MI, TMS320C64X_INS_IDLE);
540
274
        MI->size--;
541
542
274
        SStream_concat0(O, "IDLE");
543
544
274
        return true;
545
274
      }
546
1.44k
      if ((MCInst_getNumOperands(MI) == 1) &&
547
1.44k
        MCOperand_isImm(MCInst_getOperand(MI, 0)) &&
548
1.44k
        (MCOperand_getReg(MCInst_getOperand(MI, 0)) == 1)) {
549
550
1.07k
        MI->size--;
551
552
1.07k
        SStream_concat0(O, "NOP");
553
554
1.07k
        return true;
555
1.07k
      }
556
369
      break;
557
77.4k
  }
558
559
76.0k
  return false;
560
77.4k
}
561
562
void TMS320C64x_printInst(MCInst *MI, SStream *O, void *Info)
563
80.0k
{
564
80.0k
  if (!printAliasInstruction(MI, O, Info))
565
76.0k
    printInstruction(MI, O, Info);
566
80.0k
}
567
568
#endif