Coverage Report

Created: 2025-10-12 06:32

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