Coverage Report

Created: 2026-01-17 06:58

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