Coverage Report

Created: 2026-08-14 06:51

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