Coverage Report

Created: 2026-01-09 06:55

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