Coverage Report

Created: 2025-11-11 06:33

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