Coverage Report

Created: 2025-07-18 06:43

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