Coverage Report

Created: 2025-11-24 06:12

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