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
112k
{
137
112k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
138
112k
  unsigned reg;
139
140
112k
  if (MCOperand_isReg(Op)) {
141
81.2k
    reg = MCOperand_getReg(Op);
142
81.2k
    if ((MCInst_getOpcode(MI) == TMS320C64x_MVC_s1_rr) &&
143
2.04k
        (OpNo == 1)) {
144
1.02k
      switch (reg) {
145
37
      case TMS320C64X_REG_EFR:
146
37
        SStream_concat0(O, "EFR");
147
37
        break;
148
103
      case TMS320C64X_REG_IFR:
149
103
        SStream_concat0(O, "IFR");
150
103
        break;
151
880
      default:
152
880
        SStream_concat0(O, getRegisterName(reg));
153
880
        break;
154
1.02k
      }
155
80.2k
    } else {
156
80.2k
      SStream_concat0(O, getRegisterName(reg));
157
80.2k
    }
158
159
81.2k
    if (MI->csh->detail_opt) {
160
81.2k
      MI->flat_insn->detail->tms320c64x
161
81.2k
        .operands[MI->flat_insn->detail->tms320c64x
162
81.2k
              .op_count]
163
81.2k
        .type = TMS320C64X_OP_REG;
164
81.2k
      MI->flat_insn->detail->tms320c64x
165
81.2k
        .operands[MI->flat_insn->detail->tms320c64x
166
81.2k
              .op_count]
167
81.2k
        .reg = reg;
168
81.2k
      MI->flat_insn->detail->tms320c64x.op_count++;
169
81.2k
    }
170
81.2k
  } else if (MCOperand_isImm(Op)) {
171
31.4k
    int64_t Imm = MCOperand_getImm(Op);
172
173
31.4k
    if (Imm >= 0) {
174
25.9k
      if (Imm > HEX_THRESHOLD)
175
15.8k
        SStream_concat(O, "0x%" PRIx64, Imm);
176
10.0k
      else
177
10.0k
        SStream_concat(O, "%" PRIu64, Imm);
178
25.9k
    } else {
179
5.45k
      if (Imm < -HEX_THRESHOLD)
180
4.20k
        SStream_concat(O, "-0x%" PRIx64, -Imm);
181
1.24k
      else
182
1.24k
        SStream_concat(O, "-%" PRIu64, -Imm);
183
5.45k
    }
184
185
31.4k
    if (MI->csh->detail_opt) {
186
31.4k
      MI->flat_insn->detail->tms320c64x
187
31.4k
        .operands[MI->flat_insn->detail->tms320c64x
188
31.4k
              .op_count]
189
31.4k
        .type = TMS320C64X_OP_IMM;
190
31.4k
      MI->flat_insn->detail->tms320c64x
191
31.4k
        .operands[MI->flat_insn->detail->tms320c64x
192
31.4k
              .op_count]
193
31.4k
        .imm = Imm;
194
31.4k
      MI->flat_insn->detail->tms320c64x.op_count++;
195
31.4k
    }
196
31.4k
  }
197
112k
}
198
199
static void printMemOperand(MCInst *MI, unsigned OpNo, SStream *O)
200
5.65k
{
201
5.65k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
202
5.65k
  int64_t Val = MCOperand_getImm(Op);
203
5.65k
  unsigned scaled, base, offset, mode, unit;
204
5.65k
  cs_tms320c64x *tms320c64x;
205
5.65k
  char st, nd;
206
207
5.65k
  scaled = (Val >> 19) & 1;
208
5.65k
  base = (Val >> 12) & 0x7f;
209
5.65k
  offset = (Val >> 5) & 0x7f;
210
5.65k
  mode = (Val >> 1) & 0xf;
211
5.65k
  unit = Val & 1;
212
213
5.65k
  if (scaled) {
214
4.65k
    st = '[';
215
4.65k
    nd = ']';
216
4.65k
  } else {
217
1.00k
    st = '(';
218
1.00k
    nd = ')';
219
1.00k
  }
220
221
5.65k
  switch (mode) {
222
914
  case 0:
223
914
    SStream_concat(O, "*-%s%c%u%c", getRegisterName(base), st,
224
914
             offset, nd);
225
914
    break;
226
174
  case 1:
227
174
    SStream_concat(O, "*+%s%c%u%c", getRegisterName(base), st,
228
174
             offset, nd);
229
174
    break;
230
262
  case 4:
231
262
    SStream_concat(O, "*-%s%c%s%c", getRegisterName(base), st,
232
262
             getRegisterName(offset), nd);
233
262
    break;
234
151
  case 5:
235
151
    SStream_concat(O, "*+%s%c%s%c", getRegisterName(base), st,
236
151
             getRegisterName(offset), nd);
237
151
    break;
238
695
  case 8:
239
695
    SStream_concat(O, "*--%s%c%u%c", getRegisterName(base), st,
240
695
             offset, nd);
241
695
    break;
242
313
  case 9:
243
313
    SStream_concat(O, "*++%s%c%u%c", getRegisterName(base), st,
244
313
             offset, nd);
245
313
    break;
246
500
  case 10:
247
500
    SStream_concat(O, "*%s--%c%u%c", getRegisterName(base), st,
248
500
             offset, nd);
249
500
    break;
250
329
  case 11:
251
329
    SStream_concat(O, "*%s++%c%u%c", getRegisterName(base), st,
252
329
             offset, nd);
253
329
    break;
254
979
  case 12:
255
979
    SStream_concat(O, "*--%s%c%s%c", getRegisterName(base), st,
256
979
             getRegisterName(offset), nd);
257
979
    break;
258
261
  case 13:
259
261
    SStream_concat(O, "*++%s%c%s%c", getRegisterName(base), st,
260
261
             getRegisterName(offset), nd);
261
261
    break;
262
318
  case 14:
263
318
    SStream_concat(O, "*%s--%c%s%c", getRegisterName(base), st,
264
318
             getRegisterName(offset), nd);
265
318
    break;
266
763
  case 15:
267
763
    SStream_concat(O, "*%s++%c%s%c", getRegisterName(base), st,
268
763
             getRegisterName(offset), nd);
269
763
    break;
270
5.65k
  }
271
272
5.65k
  if (MI->csh->detail_opt) {
273
5.65k
    tms320c64x = &MI->flat_insn->detail->tms320c64x;
274
275
5.65k
    tms320c64x->operands[tms320c64x->op_count].type =
276
5.65k
      TMS320C64X_OP_MEM;
277
5.65k
    tms320c64x->operands[tms320c64x->op_count].mem.base = base;
278
5.65k
    tms320c64x->operands[tms320c64x->op_count].mem.disp = offset;
279
5.65k
    tms320c64x->operands[tms320c64x->op_count].mem.unit = unit + 1;
280
5.65k
    tms320c64x->operands[tms320c64x->op_count].mem.scaled = scaled;
281
5.65k
    switch (mode) {
282
914
    case 0:
283
914
      tms320c64x->operands[tms320c64x->op_count].mem.disptype =
284
914
        TMS320C64X_MEM_DISP_CONSTANT;
285
914
      tms320c64x->operands[tms320c64x->op_count]
286
914
        .mem.direction = TMS320C64X_MEM_DIR_BW;
287
914
      tms320c64x->operands[tms320c64x->op_count].mem.modify =
288
914
        TMS320C64X_MEM_MOD_NO;
289
914
      break;
290
174
    case 1:
291
174
      tms320c64x->operands[tms320c64x->op_count].mem.disptype =
292
174
        TMS320C64X_MEM_DISP_CONSTANT;
293
174
      tms320c64x->operands[tms320c64x->op_count]
294
174
        .mem.direction = TMS320C64X_MEM_DIR_FW;
295
174
      tms320c64x->operands[tms320c64x->op_count].mem.modify =
296
174
        TMS320C64X_MEM_MOD_NO;
297
174
      break;
298
262
    case 4:
299
262
      tms320c64x->operands[tms320c64x->op_count].mem.disptype =
300
262
        TMS320C64X_MEM_DISP_REGISTER;
301
262
      tms320c64x->operands[tms320c64x->op_count]
302
262
        .mem.direction = TMS320C64X_MEM_DIR_BW;
303
262
      tms320c64x->operands[tms320c64x->op_count].mem.modify =
304
262
        TMS320C64X_MEM_MOD_NO;
305
262
      break;
306
151
    case 5:
307
151
      tms320c64x->operands[tms320c64x->op_count].mem.disptype =
308
151
        TMS320C64X_MEM_DISP_REGISTER;
309
151
      tms320c64x->operands[tms320c64x->op_count]
310
151
        .mem.direction = TMS320C64X_MEM_DIR_FW;
311
151
      tms320c64x->operands[tms320c64x->op_count].mem.modify =
312
151
        TMS320C64X_MEM_MOD_NO;
313
151
      break;
314
695
    case 8:
315
695
      tms320c64x->operands[tms320c64x->op_count].mem.disptype =
316
695
        TMS320C64X_MEM_DISP_CONSTANT;
317
695
      tms320c64x->operands[tms320c64x->op_count]
318
695
        .mem.direction = TMS320C64X_MEM_DIR_BW;
319
695
      tms320c64x->operands[tms320c64x->op_count].mem.modify =
320
695
        TMS320C64X_MEM_MOD_PRE;
321
695
      break;
322
313
    case 9:
323
313
      tms320c64x->operands[tms320c64x->op_count].mem.disptype =
324
313
        TMS320C64X_MEM_DISP_CONSTANT;
325
313
      tms320c64x->operands[tms320c64x->op_count]
326
313
        .mem.direction = TMS320C64X_MEM_DIR_FW;
327
313
      tms320c64x->operands[tms320c64x->op_count].mem.modify =
328
313
        TMS320C64X_MEM_MOD_PRE;
329
313
      break;
330
500
    case 10:
331
500
      tms320c64x->operands[tms320c64x->op_count].mem.disptype =
332
500
        TMS320C64X_MEM_DISP_CONSTANT;
333
500
      tms320c64x->operands[tms320c64x->op_count]
334
500
        .mem.direction = TMS320C64X_MEM_DIR_BW;
335
500
      tms320c64x->operands[tms320c64x->op_count].mem.modify =
336
500
        TMS320C64X_MEM_MOD_POST;
337
500
      break;
338
329
    case 11:
339
329
      tms320c64x->operands[tms320c64x->op_count].mem.disptype =
340
329
        TMS320C64X_MEM_DISP_CONSTANT;
341
329
      tms320c64x->operands[tms320c64x->op_count]
342
329
        .mem.direction = TMS320C64X_MEM_DIR_FW;
343
329
      tms320c64x->operands[tms320c64x->op_count].mem.modify =
344
329
        TMS320C64X_MEM_MOD_POST;
345
329
      break;
346
979
    case 12:
347
979
      tms320c64x->operands[tms320c64x->op_count].mem.disptype =
348
979
        TMS320C64X_MEM_DISP_REGISTER;
349
979
      tms320c64x->operands[tms320c64x->op_count]
350
979
        .mem.direction = TMS320C64X_MEM_DIR_BW;
351
979
      tms320c64x->operands[tms320c64x->op_count].mem.modify =
352
979
        TMS320C64X_MEM_MOD_PRE;
353
979
      break;
354
261
    case 13:
355
261
      tms320c64x->operands[tms320c64x->op_count].mem.disptype =
356
261
        TMS320C64X_MEM_DISP_REGISTER;
357
261
      tms320c64x->operands[tms320c64x->op_count]
358
261
        .mem.direction = TMS320C64X_MEM_DIR_FW;
359
261
      tms320c64x->operands[tms320c64x->op_count].mem.modify =
360
261
        TMS320C64X_MEM_MOD_PRE;
361
261
      break;
362
318
    case 14:
363
318
      tms320c64x->operands[tms320c64x->op_count].mem.disptype =
364
318
        TMS320C64X_MEM_DISP_REGISTER;
365
318
      tms320c64x->operands[tms320c64x->op_count]
366
318
        .mem.direction = TMS320C64X_MEM_DIR_BW;
367
318
      tms320c64x->operands[tms320c64x->op_count].mem.modify =
368
318
        TMS320C64X_MEM_MOD_POST;
369
318
      break;
370
763
    case 15:
371
763
      tms320c64x->operands[tms320c64x->op_count].mem.disptype =
372
763
        TMS320C64X_MEM_DISP_REGISTER;
373
763
      tms320c64x->operands[tms320c64x->op_count]
374
763
        .mem.direction = TMS320C64X_MEM_DIR_FW;
375
763
      tms320c64x->operands[tms320c64x->op_count].mem.modify =
376
763
        TMS320C64X_MEM_MOD_POST;
377
763
      break;
378
5.65k
    }
379
5.65k
    tms320c64x->op_count++;
380
5.65k
  }
381
5.65k
}
382
383
static void printMemOperand2(MCInst *MI, unsigned OpNo, SStream *O)
384
8.37k
{
385
8.37k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
386
8.37k
  int64_t Val = MCOperand_getImm(Op);
387
8.37k
  uint16_t offset;
388
8.37k
  unsigned basereg;
389
8.37k
  cs_tms320c64x *tms320c64x;
390
391
8.37k
  basereg = Val & 0x7f;
392
8.37k
  offset = (Val >> 7) & 0x7fff;
393
8.37k
  SStream_concat(O, "*+%s[0x%x]", getRegisterName(basereg), offset);
394
395
8.37k
  if (MI->csh->detail_opt) {
396
8.37k
    tms320c64x = &MI->flat_insn->detail->tms320c64x;
397
398
8.37k
    tms320c64x->operands[tms320c64x->op_count].type =
399
8.37k
      TMS320C64X_OP_MEM;
400
8.37k
    tms320c64x->operands[tms320c64x->op_count].mem.base = basereg;
401
8.37k
    tms320c64x->operands[tms320c64x->op_count].mem.unit = 2;
402
8.37k
    tms320c64x->operands[tms320c64x->op_count].mem.disp = offset;
403
8.37k
    tms320c64x->operands[tms320c64x->op_count].mem.disptype =
404
8.37k
      TMS320C64X_MEM_DISP_CONSTANT;
405
8.37k
    tms320c64x->operands[tms320c64x->op_count].mem.direction =
406
8.37k
      TMS320C64X_MEM_DIR_FW;
407
8.37k
    tms320c64x->operands[tms320c64x->op_count].mem.modify =
408
8.37k
      TMS320C64X_MEM_MOD_NO;
409
8.37k
    tms320c64x->op_count++;
410
8.37k
  }
411
8.37k
}
412
413
static void printRegPair(MCInst *MI, unsigned OpNo, SStream *O)
414
14.5k
{
415
14.5k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
416
14.5k
  unsigned reg = MCOperand_getReg(Op);
417
14.5k
  cs_tms320c64x *tms320c64x;
418
419
14.5k
  SStream_concat(O, "%s:%s", getRegisterName(reg + 1),
420
14.5k
           getRegisterName(reg));
421
422
14.5k
  if (MI->csh->detail_opt) {
423
14.5k
    tms320c64x = &MI->flat_insn->detail->tms320c64x;
424
425
14.5k
    tms320c64x->operands[tms320c64x->op_count].type =
426
14.5k
      TMS320C64X_OP_REGPAIR;
427
14.5k
    tms320c64x->operands[tms320c64x->op_count].reg = reg;
428
14.5k
    tms320c64x->op_count++;
429
14.5k
  }
430
14.5k
}
431
432
static bool printAliasInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)
433
60.6k
{
434
60.6k
  unsigned opcode = MCInst_getOpcode(MI);
435
60.6k
  MCOperand *op;
436
437
60.6k
  switch (opcode) {
438
  /* ADD.Dx -i, x, y -> SUB.Dx x, i, y */
439
547
  case TMS320C64x_ADD_d2_rir:
440
  /* ADD.L -i, x, y -> SUB.L x, i, y */
441
1.24k
  case TMS320C64x_ADD_l1_irr:
442
1.60k
  case TMS320C64x_ADD_l1_ipp:
443
  /* ADD.S -i, x, y -> SUB.S x, i, y */
444
2.67k
  case TMS320C64x_ADD_s1_irr:
445
2.67k
    if ((MCInst_getNumOperands(MI) == 3) &&
446
2.67k
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
447
2.67k
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
448
2.67k
        MCOperand_isImm(MCInst_getOperand(MI, 2)) &&
449
2.67k
        (MCOperand_getImm(MCInst_getOperand(MI, 2)) < 0)) {
450
475
      MCInst_setOpcodePub(MI, TMS320C64X_INS_SUB);
451
475
      op = MCInst_getOperand(MI, 2);
452
475
      MCOperand_setImm(op, -MCOperand_getImm(op));
453
454
475
      SStream_concat0(O, "SUB\t");
455
475
      printOperand(MI, 1, O);
456
475
      SStream_concat0(O, ", ");
457
475
      printOperand(MI, 2, O);
458
475
      SStream_concat0(O, ", ");
459
475
      printOperand(MI, 0, O);
460
461
475
      return true;
462
475
    }
463
2.19k
    break;
464
60.6k
  }
465
60.1k
  switch (opcode) {
466
  /* ADD.D 0, x, y -> MV.D x, y */
467
483
  case TMS320C64x_ADD_d1_rir:
468
  /* OR.D x, 0, y -> MV.D x, y */
469
1.01k
  case TMS320C64x_OR_d2_rir:
470
  /* ADD.L 0, x, y -> MV.L x, y */
471
1.45k
  case TMS320C64x_ADD_l1_irr:
472
1.79k
  case TMS320C64x_ADD_l1_ipp:
473
  /* OR.L 0, x, y -> MV.L x, y */
474
2.02k
  case TMS320C64x_OR_l1_irr:
475
  /* ADD.S 0, x, y -> MV.S x, y */
476
3.08k
  case TMS320C64x_ADD_s1_irr:
477
  /* OR.S 0, x, y -> MV.S x, y */
478
3.30k
  case TMS320C64x_OR_s1_irr:
479
3.30k
    if ((MCInst_getNumOperands(MI) == 3) &&
480
3.30k
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
481
3.30k
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
482
3.30k
        MCOperand_isImm(MCInst_getOperand(MI, 2)) &&
483
3.30k
        (MCOperand_getImm(MCInst_getOperand(MI, 2)) == 0)) {
484
1.06k
      MCInst_setOpcodePub(MI, TMS320C64X_INS_MV);
485
1.06k
      MI->size--;
486
487
1.06k
      SStream_concat0(O, "MV\t");
488
1.06k
      printOperand(MI, 1, O);
489
1.06k
      SStream_concat0(O, ", ");
490
1.06k
      printOperand(MI, 0, O);
491
492
1.06k
      return true;
493
1.06k
    }
494
2.23k
    break;
495
60.1k
  }
496
59.0k
  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
433
  case TMS320C64x_XOR_l1_irr:
501
  /* XOR.S -1, x, y -> NOT.S x, y */
502
783
  case TMS320C64x_XOR_s1_irr:
503
783
    if ((MCInst_getNumOperands(MI) == 3) &&
504
783
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
505
783
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
506
783
        MCOperand_isImm(MCInst_getOperand(MI, 2)) &&
507
783
        (MCOperand_getImm(MCInst_getOperand(MI, 2)) == -1)) {
508
170
      MCInst_setOpcodePub(MI, TMS320C64X_INS_NOT);
509
170
      MI->size--;
510
511
170
      SStream_concat0(O, "NOT\t");
512
170
      printOperand(MI, 1, O);
513
170
      SStream_concat0(O, ", ");
514
170
      printOperand(MI, 0, O);
515
516
170
      return true;
517
170
    }
518
613
    break;
519
59.0k
  }
520
58.9k
  switch (opcode) {
521
  /* MVK.D 0, x -> ZERO.D x */
522
268
  case TMS320C64x_MVK_d1_rr:
523
  /* MVK.L 0, x -> ZERO.L x */
524
1.43k
  case TMS320C64x_MVK_l2_ir:
525
1.43k
    if ((MCInst_getNumOperands(MI) == 2) &&
526
1.43k
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
527
1.43k
        MCOperand_isImm(MCInst_getOperand(MI, 1)) &&
528
1.43k
        (MCOperand_getImm(MCInst_getOperand(MI, 1)) == 0)) {
529
358
      MCInst_setOpcodePub(MI, TMS320C64X_INS_ZERO);
530
358
      MI->size--;
531
532
358
      SStream_concat0(O, "ZERO\t");
533
358
      printOperand(MI, 0, O);
534
535
358
      return true;
536
358
    }
537
1.07k
    break;
538
58.9k
  }
539
58.5k
  switch (opcode) {
540
  /* SUB.L x, x, y -> ZERO.L y */
541
259
  case TMS320C64x_SUB_l1_rrp_x1:
542
  /* SUB.S x, x, y -> ZERO.S y */
543
867
  case TMS320C64x_SUB_s1_rrr:
544
867
    if ((MCInst_getNumOperands(MI) == 3) &&
545
867
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
546
867
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
547
867
        MCOperand_isReg(MCInst_getOperand(MI, 2)) &&
548
867
        (MCOperand_getReg(MCInst_getOperand(MI, 1)) ==
549
867
         MCOperand_getReg(MCInst_getOperand(MI, 2)))) {
550
392
      MCInst_setOpcodePub(MI, TMS320C64X_INS_ZERO);
551
392
      MI->size -= 2;
552
553
392
      SStream_concat0(O, "ZERO\t");
554
392
      printOperand(MI, 0, O);
555
556
392
      return true;
557
392
    }
558
475
    break;
559
58.5k
  }
560
58.1k
  switch (opcode) {
561
  /* SUB.L 0, x, y -> NEG.L x, y */
562
797
  case TMS320C64x_SUB_l1_irr:
563
1.13k
  case TMS320C64x_SUB_l1_ipp:
564
  /* SUB.S 0, x, y -> NEG.S x, y */
565
1.30k
  case TMS320C64x_SUB_s1_irr:
566
1.30k
    if ((MCInst_getNumOperands(MI) == 3) &&
567
1.30k
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
568
1.30k
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
569
1.30k
        MCOperand_isImm(MCInst_getOperand(MI, 2)) &&
570
1.30k
        (MCOperand_getImm(MCInst_getOperand(MI, 2)) == 0)) {
571
331
      MCInst_setOpcodePub(MI, TMS320C64X_INS_NEG);
572
331
      MI->size--;
573
574
331
      SStream_concat0(O, "NEG\t");
575
331
      printOperand(MI, 1, O);
576
331
      SStream_concat0(O, ", ");
577
331
      printOperand(MI, 0, O);
578
579
331
      return true;
580
331
    }
581
977
    break;
582
58.1k
  }
583
57.8k
  switch (opcode) {
584
  /* PACKLH2.L x, x, y -> SWAP2.L x, y */
585
256
  case TMS320C64x_PACKLH2_l1_rrr_x2:
586
  /* PACKLH2.S x, x, y -> SWAP2.S x, y */
587
1.09k
  case TMS320C64x_PACKLH2_s1_rrr:
588
1.09k
    if ((MCInst_getNumOperands(MI) == 3) &&
589
1.09k
        MCOperand_isReg(MCInst_getOperand(MI, 0)) &&
590
1.09k
        MCOperand_isReg(MCInst_getOperand(MI, 1)) &&
591
1.09k
        MCOperand_isReg(MCInst_getOperand(MI, 2)) &&
592
1.09k
        (MCOperand_getReg(MCInst_getOperand(MI, 1)) ==
593
1.09k
         MCOperand_getReg(MCInst_getOperand(MI, 2)))) {
594
40
      MCInst_setOpcodePub(MI, TMS320C64X_INS_SWAP2);
595
40
      MI->size--;
596
597
40
      SStream_concat0(O, "SWAP2\t");
598
40
      printOperand(MI, 1, O);
599
40
      SStream_concat0(O, ", ");
600
40
      printOperand(MI, 0, O);
601
602
40
      return true;
603
40
    }
604
1.05k
    break;
605
57.8k
  }
606
57.7k
  switch (opcode) {
607
  /* NOP 16 -> IDLE */
608
  /* NOP 1 -> NOP */
609
1.34k
  case TMS320C64x_NOP_n:
610
1.34k
    if ((MCInst_getNumOperands(MI) == 1) &&
611
1.34k
        MCOperand_isImm(MCInst_getOperand(MI, 0)) &&
612
1.34k
        (MCOperand_getReg(MCInst_getOperand(MI, 0)) == 16)) {
613
300
      MCInst_setOpcodePub(MI, TMS320C64X_INS_IDLE);
614
300
      MI->size--;
615
616
300
      SStream_concat0(O, "IDLE");
617
618
300
      return true;
619
300
    }
620
1.04k
    if ((MCInst_getNumOperands(MI) == 1) &&
621
1.04k
        MCOperand_isImm(MCInst_getOperand(MI, 0)) &&
622
1.04k
        (MCOperand_getReg(MCInst_getOperand(MI, 0)) == 1)) {
623
853
      MI->size--;
624
625
853
      SStream_concat0(O, "NOP");
626
627
853
      return true;
628
853
    }
629
196
    break;
630
57.7k
  }
631
632
56.6k
  return false;
633
57.7k
}
634
635
void TMS320C64x_printInst(MCInst *MI, SStream *O, void *Info)
636
60.6k
{
637
60.6k
  if (!printAliasInstruction(MI, O, Info))
638
56.6k
    printInstruction(MI, O, Info);
639
60.6k
}
640
641
#endif