Coverage Report

Created: 2026-08-31 06:58

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