Coverage Report

Created: 2026-04-12 06:30

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