Coverage Report

Created: 2026-08-14 06:51

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