Coverage Report

Created: 2026-12-01 07:03

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