Coverage Report

Created: 2026-01-17 06:58

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