Coverage Report

Created: 2025-07-01 07:03

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