Coverage Report

Created: 2025-11-16 06:38

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