Coverage Report

Created: 2026-03-11 06:06

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