Coverage Report

Created: 2025-11-11 06:33

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