Coverage Report

Created: 2025-11-09 07:00

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