Coverage Report

Created: 2026-03-03 06:15

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