Coverage Report

Created: 2025-08-26 06:30

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