Coverage Report

Created: 2025-10-10 06:20

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