Coverage Report

Created: 2026-06-15 06:41

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