Coverage Report

Created: 2026-09-28 06:34

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