Coverage Report

Created: 2025-10-14 06:42

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