Coverage Report

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