Coverage Report

Created: 2025-07-11 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
39.5k
{
27
39.5k
  SStream ss;
28
39.5k
  const char *op_str_ptr, *p2;
29
39.5k
  char tmp[8] = { 0 };
30
39.5k
  unsigned int unit = 0;
31
39.5k
  int i;
32
39.5k
  cs_tms320c64x *tms320c64x;
33
34
39.5k
  if (mci->csh->detail_opt) {
35
39.5k
    tms320c64x = &mci->flat_insn->detail->tms320c64x;
36
37
39.5k
    for (i = 0; i < insn->detail->groups_count; i++) {
38
39.5k
      switch(insn->detail->groups[i]) {
39
11.6k
        case TMS320C64X_GRP_FUNIT_D:
40
11.6k
          unit = TMS320C64X_FUNIT_D;
41
11.6k
          break;
42
8.51k
        case TMS320C64X_GRP_FUNIT_L:
43
8.51k
          unit = TMS320C64X_FUNIT_L;
44
8.51k
          break;
45
2.45k
        case TMS320C64X_GRP_FUNIT_M:
46
2.45k
          unit = TMS320C64X_FUNIT_M;
47
2.45k
          break;
48
16.1k
        case TMS320C64X_GRP_FUNIT_S:
49
16.1k
          unit = TMS320C64X_FUNIT_S;
50
16.1k
          break;
51
804
        case TMS320C64X_GRP_FUNIT_NO:
52
804
          unit = TMS320C64X_FUNIT_NO;
53
804
          break;
54
39.5k
      }
55
39.5k
      if (unit != 0)
56
39.5k
        break;
57
39.5k
    }
58
39.5k
    tms320c64x->funit.unit = unit;
59
60
39.5k
    SStream_Init(&ss);
61
39.5k
    if (tms320c64x->condition.reg != TMS320C64X_REG_INVALID)
62
26.8k
      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
39.5k
    op_str_ptr = strchr(SStream_rbuf(insn_asm), '\t');
68
69
39.5k
    if ((op_str_ptr != NULL) && (((p2 = strchr(op_str_ptr, '[')) != NULL) || ((p2 = strchr(op_str_ptr, '(')) != NULL))) {
70
42.3k
      while ((p2 > op_str_ptr) && ((*p2 != 'a') && (*p2 != 'b')))
71
32.1k
        p2--;
72
10.1k
      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.1k
      if (*p2 == 'a')
78
4.82k
        strncpy(tmp, "1T", sizeof(tmp));
79
5.36k
      else
80
5.36k
        strncpy(tmp, "2T", sizeof(tmp));
81
29.3k
    } else {
82
29.3k
      tmp[0] = '\0';
83
29.3k
    }
84
39.5k
    SStream mnem_post = { 0 };
85
39.5k
    SStream_Init(&mnem_post);
86
39.5k
    switch(tms320c64x->funit.unit) {
87
11.6k
      case TMS320C64X_FUNIT_D:
88
11.6k
        SStream_concat(&mnem_post, ".D%s%u", tmp, tms320c64x->funit.side);
89
11.6k
        break;
90
8.51k
      case TMS320C64X_FUNIT_L:
91
8.51k
        SStream_concat(&mnem_post, ".L%s%u", tmp, tms320c64x->funit.side);
92
8.51k
        break;
93
2.45k
      case TMS320C64X_FUNIT_M:
94
2.45k
        SStream_concat(&mnem_post, ".M%s%u", tmp, tms320c64x->funit.side);
95
2.45k
        break;
96
16.1k
      case TMS320C64X_FUNIT_S:
97
16.1k
        SStream_concat(&mnem_post, ".S%s%u", tmp, tms320c64x->funit.side);
98
16.1k
        break;
99
39.5k
    }
100
39.5k
    if (tms320c64x->funit.crosspath > 0)
101
10.6k
      SStream_concat0(&mnem_post, "X");
102
103
39.5k
    if (op_str_ptr != NULL) {
104
      // There is an op_str
105
38.8k
      SStream_concat1(&mnem_post, '\t');
106
38.8k
      SStream_replc_str(insn_asm, '\t', SStream_rbuf(&mnem_post));
107
38.8k
    }
108
109
39.5k
    if (tms320c64x->parallel != 0)
110
16.4k
      SStream_concat0(insn_asm, "\t||");
111
39.5k
    SStream_concat0(&ss, SStream_rbuf(insn_asm));
112
39.5k
    SStream_Flush(insn_asm, NULL);
113
39.5k
    SStream_concat0(insn_asm, SStream_rbuf(&ss));
114
39.5k
  }
115
39.5k
}
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
72.6k
{
125
72.6k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
126
72.6k
  unsigned reg;
127
128
72.6k
  if (MCOperand_isReg(Op)) {
129
53.5k
    reg = MCOperand_getReg(Op);
130
53.5k
    if ((MCInst_getOpcode(MI) == TMS320C64x_MVC_s1_rr) && (OpNo == 1)) {
131
1.37k
      switch(reg) {
132
42
        case TMS320C64X_REG_EFR:
133
42
          SStream_concat0(O, "EFR");
134
42
          break;
135
1.19k
        case TMS320C64X_REG_IFR:
136
1.19k
          SStream_concat0(O, "IFR");
137
1.19k
          break;
138
144
        default:
139
144
          SStream_concat0(O, getRegisterName(reg));
140
144
          break;
141
1.37k
      }
142
52.1k
    } else {
143
52.1k
      SStream_concat0(O, getRegisterName(reg));
144
52.1k
    }
145
146
53.5k
    if (MI->csh->detail_opt) {
147
53.5k
      MI->flat_insn->detail->tms320c64x.operands[MI->flat_insn->detail->tms320c64x.op_count].type = TMS320C64X_OP_REG;
148
53.5k
      MI->flat_insn->detail->tms320c64x.operands[MI->flat_insn->detail->tms320c64x.op_count].reg = reg;
149
53.5k
      MI->flat_insn->detail->tms320c64x.op_count++;
150
53.5k
    }
151
53.5k
  } else if (MCOperand_isImm(Op)) {
152
19.0k
    int64_t Imm = MCOperand_getImm(Op);
153
154
19.0k
    if (Imm >= 0) {
155
15.5k
      if (Imm > HEX_THRESHOLD)
156
10.4k
        SStream_concat(O, "0x%"PRIx64, Imm);
157
5.08k
      else
158
5.08k
        SStream_concat(O, "%"PRIu64, Imm);
159
15.5k
    } else {
160
3.49k
      if (Imm < -HEX_THRESHOLD)
161
2.81k
        SStream_concat(O, "-0x%"PRIx64, -Imm);
162
680
      else
163
680
        SStream_concat(O, "-%"PRIu64, -Imm);
164
3.49k
    }
165
166
19.0k
    if (MI->csh->detail_opt) {
167
19.0k
      MI->flat_insn->detail->tms320c64x.operands[MI->flat_insn->detail->tms320c64x.op_count].type = TMS320C64X_OP_IMM;
168
19.0k
      MI->flat_insn->detail->tms320c64x.operands[MI->flat_insn->detail->tms320c64x.op_count].imm = Imm;
169
19.0k
      MI->flat_insn->detail->tms320c64x.op_count++;
170
19.0k
    }
171
19.0k
  }
172
72.6k
}
173
174
static void printMemOperand(MCInst *MI, unsigned OpNo, SStream *O)
175
4.82k
{
176
4.82k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
177
4.82k
  int64_t Val = MCOperand_getImm(Op);
178
4.82k
  unsigned scaled, base, offset, mode, unit;
179
4.82k
  cs_tms320c64x *tms320c64x;
180
4.82k
  char st, nd;
181
182
4.82k
  scaled = (Val >> 19) & 1;
183
4.82k
  base = (Val >> 12) & 0x7f;
184
4.82k
  offset = (Val >> 5) & 0x7f;
185
4.82k
  mode = (Val >> 1) & 0xf;
186
4.82k
  unit = Val & 1;
187
188
4.82k
  if (scaled) {
189
4.18k
    st = '[';
190
4.18k
    nd = ']';
191
4.18k
  } else {
192
640
    st = '(';
193
640
    nd = ')';
194
640
  }
195
196
4.82k
  switch(mode) {
197
668
    case 0:
198
668
      SStream_concat(O, "*-%s%c%u%c", getRegisterName(base), st, offset, nd);
199
668
      break;
200
477
    case 1:
201
477
      SStream_concat(O, "*+%s%c%u%c", getRegisterName(base), st, offset, nd);
202
477
      break;
203
269
    case 4:
204
269
      SStream_concat(O, "*-%s%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);
205
269
      break;
206
99
    case 5:
207
99
      SStream_concat(O, "*+%s%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);
208
99
      break;
209
246
    case 8:
210
246
      SStream_concat(O, "*--%s%c%u%c", getRegisterName(base), st, offset, nd);
211
246
      break;
212
390
    case 9:
213
390
      SStream_concat(O, "*++%s%c%u%c", getRegisterName(base), st, offset, nd);
214
390
      break;
215
653
    case 10:
216
653
      SStream_concat(O, "*%s--%c%u%c", getRegisterName(base), st, offset, nd);
217
653
      break;
218
1.00k
    case 11:
219
1.00k
      SStream_concat(O, "*%s++%c%u%c", getRegisterName(base), st, offset, nd);
220
1.00k
      break;
221
445
    case 12:
222
445
      SStream_concat(O, "*--%s%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);
223
445
      break;
224
217
    case 13:
225
217
      SStream_concat(O, "*++%s%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);
226
217
      break;
227
236
    case 14:
228
236
      SStream_concat(O, "*%s--%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);
229
236
      break;
230
120
    case 15:
231
120
      SStream_concat(O, "*%s++%c%s%c", getRegisterName(base), st, getRegisterName(offset), nd);
232
120
      break;
233
4.82k
  }
234
235
4.82k
  if (MI->csh->detail_opt) {
236
4.82k
    tms320c64x = &MI->flat_insn->detail->tms320c64x;
237
238
4.82k
    tms320c64x->operands[tms320c64x->op_count].type = TMS320C64X_OP_MEM;
239
4.82k
    tms320c64x->operands[tms320c64x->op_count].mem.base = base;
240
4.82k
    tms320c64x->operands[tms320c64x->op_count].mem.disp = offset;
241
4.82k
    tms320c64x->operands[tms320c64x->op_count].mem.unit = unit + 1;
242
4.82k
    tms320c64x->operands[tms320c64x->op_count].mem.scaled = scaled;
243
4.82k
    switch(mode) {
244
668
      case 0:
245
668
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;
246
668
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;
247
668
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;
248
668
        break;
249
477
      case 1:
250
477
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;
251
477
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;
252
477
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;
253
477
        break;
254
269
      case 4:
255
269
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;
256
269
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;
257
269
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;
258
269
        break;
259
99
      case 5:
260
99
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;
261
99
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;
262
99
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;
263
99
        break;
264
246
      case 8:
265
246
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;
266
246
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;
267
246
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_PRE;
268
246
        break;
269
390
      case 9:
270
390
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;
271
390
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;
272
390
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_PRE;
273
390
        break;
274
653
      case 10:
275
653
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;
276
653
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;
277
653
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_POST;
278
653
        break;
279
1.00k
      case 11:
280
1.00k
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;
281
1.00k
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;
282
1.00k
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_POST;
283
1.00k
        break;
284
445
      case 12:
285
445
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;
286
445
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;
287
445
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_PRE;
288
445
        break;
289
217
      case 13:
290
217
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;
291
217
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;
292
217
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_PRE;
293
217
        break;
294
236
      case 14:
295
236
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;
296
236
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_BW;
297
236
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_POST;
298
236
        break;
299
120
      case 15:
300
120
        tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_REGISTER;
301
120
        tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;
302
120
        tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_POST;
303
120
        break;
304
4.82k
    }
305
4.82k
    tms320c64x->op_count++;
306
4.82k
  }
307
4.82k
}
308
309
static void printMemOperand2(MCInst *MI, unsigned OpNo, SStream *O)
310
5.36k
{
311
5.36k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
312
5.36k
  int64_t Val = MCOperand_getImm(Op);
313
5.36k
  uint16_t offset;
314
5.36k
  unsigned basereg;
315
5.36k
  cs_tms320c64x *tms320c64x;
316
317
5.36k
  basereg = Val & 0x7f;
318
5.36k
  offset = (Val >> 7) & 0x7fff;
319
5.36k
  SStream_concat(O, "*+%s[0x%x]", getRegisterName(basereg), offset);
320
321
5.36k
  if (MI->csh->detail_opt) {
322
5.36k
    tms320c64x = &MI->flat_insn->detail->tms320c64x;
323
324
5.36k
    tms320c64x->operands[tms320c64x->op_count].type = TMS320C64X_OP_MEM;
325
5.36k
    tms320c64x->operands[tms320c64x->op_count].mem.base = basereg;
326
5.36k
    tms320c64x->operands[tms320c64x->op_count].mem.unit = 2;
327
5.36k
    tms320c64x->operands[tms320c64x->op_count].mem.disp = offset;
328
5.36k
    tms320c64x->operands[tms320c64x->op_count].mem.disptype = TMS320C64X_MEM_DISP_CONSTANT;
329
5.36k
    tms320c64x->operands[tms320c64x->op_count].mem.direction = TMS320C64X_MEM_DIR_FW;
330
5.36k
    tms320c64x->operands[tms320c64x->op_count].mem.modify = TMS320C64X_MEM_MOD_NO;
331
5.36k
    tms320c64x->op_count++;
332
5.36k
  }
333
5.36k
}
334
335
static void printRegPair(MCInst *MI, unsigned OpNo, SStream *O)
336
12.3k
{
337
12.3k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
338
12.3k
  unsigned reg = MCOperand_getReg(Op);
339
12.3k
  cs_tms320c64x *tms320c64x;
340
341
12.3k
  SStream_concat(O, "%s:%s", getRegisterName(reg + 1), getRegisterName(reg));
342
343
12.3k
  if (MI->csh->detail_opt) {
344
12.3k
    tms320c64x = &MI->flat_insn->detail->tms320c64x;
345
346
12.3k
    tms320c64x->operands[tms320c64x->op_count].type = TMS320C64X_OP_REGPAIR;
347
12.3k
    tms320c64x->operands[tms320c64x->op_count].reg = reg;
348
12.3k
    tms320c64x->op_count++;
349
12.3k
  }
350
12.3k
}
351
352
static bool printAliasInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)
353
39.5k
{
354
39.5k
  unsigned opcode = MCInst_getOpcode(MI);
355
39.5k
  MCOperand *op;
356
357
39.5k
  switch(opcode) {
358
    /* ADD.Dx -i, x, y -> SUB.Dx x, i, y */
359
85
    case TMS320C64x_ADD_d2_rir:
360
    /* ADD.L -i, x, y -> SUB.L x, i, y */
361
519
    case TMS320C64x_ADD_l1_irr:
362
782
    case TMS320C64x_ADD_l1_ipp:
363
    /* ADD.S -i, x, y -> SUB.S x, i, y */
364
1.05k
    case TMS320C64x_ADD_s1_irr:
365
1.05k
      if ((MCInst_getNumOperands(MI) == 3) &&
366
1.05k
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
367
1.05k
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
368
1.05k
        MCOperand_isImm(MCInst_getOperand(MI, 2)) &&
369
1.05k
        (MCOperand_getImm(MCInst_getOperand(MI, 2)) < 0)) {
370
371
269
        MCInst_setOpcodePub(MI, TMS320C64X_INS_SUB);
372
269
        op = MCInst_getOperand(MI, 2);
373
269
        MCOperand_setImm(op, -MCOperand_getImm(op));
374
375
269
        SStream_concat0(O, "SUB\t");
376
269
        printOperand(MI, 1, O);
377
269
        SStream_concat0(O, ", ");
378
269
        printOperand(MI, 2, O);
379
269
        SStream_concat0(O, ", ");
380
269
        printOperand(MI, 0, O);
381
382
269
        return true;
383
269
      }
384
784
      break;
385
39.5k
  }
386
39.2k
  switch(opcode) {
387
    /* ADD.D 0, x, y -> MV.D x, y */
388
69
    case TMS320C64x_ADD_d1_rir:
389
    /* OR.D x, 0, y -> MV.D x, y */
390
293
    case TMS320C64x_OR_d2_rir:
391
    /* ADD.L 0, x, y -> MV.L x, y */
392
705
    case TMS320C64x_ADD_l1_irr:
393
755
    case TMS320C64x_ADD_l1_ipp:
394
    /* OR.L 0, x, y -> MV.L x, y */
395
833
    case TMS320C64x_OR_l1_irr:
396
    /* ADD.S 0, x, y -> MV.S x, y */
397
1.08k
    case TMS320C64x_ADD_s1_irr:
398
    /* OR.S 0, x, y -> MV.S x, y */
399
1.41k
    case TMS320C64x_OR_s1_irr:
400
1.41k
      if ((MCInst_getNumOperands(MI) == 3) &&
401
1.41k
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
402
1.41k
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
403
1.41k
        MCOperand_isImm(MCInst_getOperand(MI, 2)) &&
404
1.41k
        (MCOperand_getImm(MCInst_getOperand(MI, 2)) == 0)) {
405
406
155
        MCInst_setOpcodePub(MI, TMS320C64X_INS_MV);
407
155
        MI->size--;
408
409
155
        SStream_concat0(O, "MV\t");
410
155
        printOperand(MI, 1, O);
411
155
        SStream_concat0(O, ", ");
412
155
        printOperand(MI, 0, O);
413
414
155
        return true;
415
155
      }
416
1.25k
      break;
417
39.2k
  }
418
39.1k
  switch(opcode) {
419
    /* XOR.D -1, x, y -> NOT.D x, y */
420
83
    case TMS320C64x_XOR_d2_rir:
421
    /* XOR.L -1, x, y -> NOT.L x, y */
422
123
    case TMS320C64x_XOR_l1_irr:
423
    /* XOR.S -1, x, y -> NOT.S x, y */
424
597
    case TMS320C64x_XOR_s1_irr:
425
597
      if ((MCInst_getNumOperands(MI) == 3) &&
426
597
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
427
597
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
428
597
        MCOperand_isImm(MCInst_getOperand(MI, 2)) &&
429
597
        (MCOperand_getImm(MCInst_getOperand(MI, 2)) == -1)) {
430
431
69
        MCInst_setOpcodePub(MI, TMS320C64X_INS_NOT);
432
69
        MI->size--;
433
434
69
        SStream_concat0(O, "NOT\t");
435
69
        printOperand(MI, 1, O);
436
69
        SStream_concat0(O, ", ");
437
69
        printOperand(MI, 0, O);
438
439
69
        return true;
440
69
      }
441
528
      break;
442
39.1k
  }
443
39.0k
  switch(opcode) {
444
    /* MVK.D 0, x -> ZERO.D x */
445
119
    case TMS320C64x_MVK_d1_rr:
446
    /* MVK.L 0, x -> ZERO.L x */
447
681
    case TMS320C64x_MVK_l2_ir:
448
681
      if ((MCInst_getNumOperands(MI) == 2) &&
449
681
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
450
681
        MCOperand_isImm(MCInst_getOperand(MI, 1)) &&
451
681
        (MCOperand_getImm(MCInst_getOperand(MI, 1)) == 0)) {
452
453
359
        MCInst_setOpcodePub(MI, TMS320C64X_INS_ZERO);
454
359
        MI->size--;
455
456
359
        SStream_concat0(O, "ZERO\t");
457
359
        printOperand(MI, 0, O);
458
459
359
        return true;
460
359
      }
461
322
      break;
462
39.0k
  }
463
38.7k
  switch(opcode) {
464
    /* SUB.L x, x, y -> ZERO.L y */
465
84
    case TMS320C64x_SUB_l1_rrp_x1:
466
    /* SUB.S x, x, y -> ZERO.S y */
467
169
    case TMS320C64x_SUB_s1_rrr:
468
169
      if ((MCInst_getNumOperands(MI) == 3) &&
469
169
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
470
169
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
471
169
        MCOperand_isReg(MCInst_getOperand(MI, 2)) &&
472
169
        (MCOperand_getReg(MCInst_getOperand(MI, 1)) == MCOperand_getReg(MCInst_getOperand(MI, 2)))) {
473
474
73
        MCInst_setOpcodePub(MI, TMS320C64X_INS_ZERO);
475
73
        MI->size -= 2;
476
477
73
        SStream_concat0(O, "ZERO\t");
478
73
        printOperand(MI, 0, O);
479
480
73
        return true;
481
73
      }
482
96
      break;
483
38.7k
  }
484
38.6k
  switch(opcode) {
485
    /* SUB.L 0, x, y -> NEG.L x, y */
486
215
    case TMS320C64x_SUB_l1_irr:
487
504
    case TMS320C64x_SUB_l1_ipp:
488
    /* SUB.S 0, x, y -> NEG.S x, y */
489
572
    case TMS320C64x_SUB_s1_irr:
490
572
      if ((MCInst_getNumOperands(MI) == 3) &&
491
572
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
492
572
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
493
572
        MCOperand_isImm(MCInst_getOperand(MI, 2)) &&
494
572
        (MCOperand_getImm(MCInst_getOperand(MI, 2)) == 0)) {
495
496
85
        MCInst_setOpcodePub(MI, TMS320C64X_INS_NEG);
497
85
        MI->size--;
498
499
85
        SStream_concat0(O, "NEG\t");
500
85
        printOperand(MI, 1, O);
501
85
        SStream_concat0(O, ", ");
502
85
        printOperand(MI, 0, O);
503
504
85
        return true;
505
85
      }
506
487
      break;
507
38.6k
  }
508
38.5k
  switch(opcode) {
509
    /* PACKLH2.L x, x, y -> SWAP2.L x, y */
510
214
    case TMS320C64x_PACKLH2_l1_rrr_x2:
511
    /* PACKLH2.S x, x, y -> SWAP2.S x, y */
512
310
    case TMS320C64x_PACKLH2_s1_rrr:
513
310
      if ((MCInst_getNumOperands(MI) == 3) &&
514
310
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
515
310
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
516
310
        MCOperand_isReg(MCInst_getOperand(MI, 2)) &&
517
310
        (MCOperand_getReg(MCInst_getOperand(MI, 1)) == MCOperand_getReg(MCInst_getOperand(MI, 2)))) {
518
519
14
        MCInst_setOpcodePub(MI, TMS320C64X_INS_SWAP2);
520
14
        MI->size--;
521
522
14
        SStream_concat0(O, "SWAP2\t");
523
14
        printOperand(MI, 1, O);
524
14
        SStream_concat0(O, ", ");
525
14
        printOperand(MI, 0, O);
526
527
14
        return true;
528
14
      }
529
296
      break;
530
38.5k
  }
531
38.5k
  switch(opcode) {
532
    /* NOP 16 -> IDLE */
533
    /* NOP 1 -> NOP */
534
804
    case TMS320C64x_NOP_n:
535
804
      if ((MCInst_getNumOperands(MI) == 1) &&
536
804
        MCOperand_isImm(MCInst_getOperand(MI, 0)) &&
537
804
        (MCOperand_getReg(MCInst_getOperand(MI, 0)) == 16)) {
538
539
195
        MCInst_setOpcodePub(MI, TMS320C64X_INS_IDLE);
540
195
        MI->size--;
541
542
195
        SStream_concat0(O, "IDLE");
543
544
195
        return true;
545
195
      }
546
609
      if ((MCInst_getNumOperands(MI) == 1) &&
547
609
        MCOperand_isImm(MCInst_getOperand(MI, 0)) &&
548
609
        (MCOperand_getReg(MCInst_getOperand(MI, 0)) == 1)) {
549
550
533
        MI->size--;
551
552
533
        SStream_concat0(O, "NOP");
553
554
533
        return true;
555
533
      }
556
76
      break;
557
38.5k
  }
558
559
37.8k
  return false;
560
38.5k
}
561
562
void TMS320C64x_printInst(MCInst *MI, SStream *O, void *Info)
563
39.5k
{
564
39.5k
  if (!printAliasInstruction(MI, O, Info))
565
37.8k
    printInstruction(MI, O, Info);
566
39.5k
}
567
568
#endif