Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
n-o-o-n committed Jun 26, 2023
1 parent 3198349 commit 7ef6cef
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 76 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ History
2022-02-07 duplex instructions decoded into two separate insn_t
2022-02-14 predicate operands stored at the end of ops array; version 5.0 released
2023-03-31 added support for IDA v7.7
2023-06-26 added support for Hexagon v73; version 5.2 released
33 changes: 16 additions & 17 deletions hexagon/ana.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ static void op_mxmem( op_t &op, uint32_t type, uint32_t rs, uint32_t rt = 0xFF )
op.reg = (rs << 8) | rt;
}

static void op_acc( op_t &op, uint32_t type, uint32_t rs = 0xFF )
static void op_acc( op_t &op, uint32_t type = 0, uint32_t rs = 0xFF )
{
// acc[(Rs)][:...]
op.type = o_acc;
Expand Down Expand Up @@ -4103,7 +4103,7 @@ static uint32_t iclass_9_HMX( uint32_t word, uint64_t /*extender*/, op_t *ops, u
default: return 0;
}
op_reg( ops[0], REG_WEIGHT, REG_POST_N );
op_mxmem( ops[1], MEM_MX | MX_2X | suff, REG_R(s5), REG_R(t5) );
op_mxmem( ops[1], MX_2X | suff, REG_R(s5), REG_R(t5) );
return Hex_mov;
}
if( BITS(7:6) == 0b11 )
Expand All @@ -4112,7 +4112,7 @@ static uint32_t iclass_9_HMX( uint32_t word, uint64_t /*extender*/, op_t *ops, u
{
// bias = mxmem[2](Rs32)
op_reg( ops[0], REG_BIAS );
op_mxmem( ops[1], BIT(0)? MEM_MX : MEM_MX2, REG_R(s5) );
op_mxmem( ops[1], BIT(0)? 0 : MX_MEM2, REG_R(s5) );
return Hex_mov;
}
if( BIT(13) == 0 && BIT(5) == 1 )
Expand All @@ -4139,7 +4139,7 @@ static uint32_t iclass_9_HMX( uint32_t word, uint64_t /*extender*/, op_t *ops, u
default: return 0;
}
op_reg( ops[0], REG_ACTIVATION, ub? REG_POST_UB : REG_POST_HF );
op_mxmem( ops[1], MEM_MX | suff, REG_R(s5), REG_R(t5) );
op_mxmem( ops[1], suff, REG_R(s5), REG_R(t5) );
return Hex_mov;
}
if( BIT(13) == 1 )
Expand Down Expand Up @@ -4199,7 +4199,7 @@ static uint32_t iclass_9_HMX( uint32_t word, uint64_t /*extender*/, op_t *ops, u
default: return 0;
}
op_reg( ops[0], REG_WEIGHT, dt );
op_mxmem( ops[1], MEM_MX | suff, REG_R(s5), REG_R(t5) );
op_mxmem( ops[1], suff, REG_R(s5), REG_R(t5) );
return Hex_mov;
}
}
Expand All @@ -4215,12 +4215,12 @@ static uint32_t iclass_10_HMX( uint32_t word, uint64_t /*extender*/, op_t *ops,
if( BIT(13) == 0 && BIT(4) == 0 )
{
// mxmem(Rs32,Rt32):{before|after}[:retain][:cm][:sat}.ub=acc
op_mxmem( ops[0], MEM_MX | MX_UB |
op_mxmem( ops[0], MX_UB |
(BIT(0)? MX_CM : 0) |
(BIT(1)? 0 : MX_SAT) |
(BIT(2)? MX_AFTER : MX_BEFORE) |
(BIT(3)? MX_RETAIN : 0), REG_R(s5), REG_R(t5) );
op_reg( ops[1], REG_ACC );
op_acc( ops[1] );
return Hex_mov;
}
if( BIT(13) == 1 && BIT(4) == 0 )
Expand All @@ -4232,22 +4232,21 @@ static uint32_t iclass_10_HMX( uint32_t word, uint64_t /*extender*/, op_t *ops,
MX_BEFORE | MX_RETAIN, MX_AFTER | MX_POS, MX_AFTER | MX_SAT, MX_AFTER,
MX_AFTER | MX_RETAIN, MX_AFTER | MX_RETAIN | MX_POS, MX_AFTER | MX_RETAIN | MX_SAT, MX_AFTER | MX_RETAIN,
};
op_mxmem( ops[0], MEM_MX |
suff[ BITS(3:0) ] |
op_mxmem( ops[0], suff[ BITS(3:0) ] |
(BIT(1)? MX_UH : MX_HF),
REG_R(s5), REG_R(t5) );
op_reg( ops[1], REG_ACC, BIT(1)? REG_POST_2x1 : 0 );
op_acc( ops[1], BIT(1)? ACC_2X1 : 0 );
return Hex_mov;
}
if( BIT(13) == 1 && BIT(4) == 1 && BIT(1) == 1 )
{
// mxmem(Rs32,Rt32):{before|after}[:retain][:sat].uh=acc:2x2
op_mxmem( ops[0], MEM_MX | MX_UH |
op_mxmem( ops[0], MX_UH |
(BIT(3)? MX_AFTER : MX_BEFORE) |
(BIT(2)? MX_RETAIN : 0) |
(BIT(0)? 0 : MX_SAT),
REG_R(s5), REG_R(t5) );
op_reg( ops[1], REG_ACC, REG_POST_2x2 );
op_acc( ops[1], ACC_2X2 );
return Hex_mov;
}
// rest of instructions
Expand All @@ -4258,24 +4257,24 @@ static uint32_t iclass_10_HMX( uint32_t word, uint64_t /*extender*/, op_t *ops,
case 0b000:
case 0b110:
// mxmem[2](Rs32)=bias
op_mxmem( ops[0], BIT(1)? MEM_MX2 : MEM_MX, REG_R(s5) );
op_mxmem( ops[0], BIT(1)? MX_MEM2 : 0, REG_R(s5) );
op_reg( ops[1], REG_BIAS );
return Hex_mov;
case 0b001:
case 0b011:
// mxclracc[.hf]
if( s5 ) return 0;
op_reg( ops[0], REG_ACC, BIT(1)? REG_POST_HF : 0 );
op_acc( ops[0], BIT(1)? ACC_HF : 0 );
return Hex_mxclr;
case 0b100:
case 0b101:
// mxswapacc[.hf]
if( s5 ) return 0;
op_reg( ops[0], REG_ACC, BIT(0)? REG_POST_HF : 0 );
op_acc( ops[0], BIT(0)? ACC_HF : 0 );
return Hex_mxswap;
case 0b111:
// acc=mxshl(acc,#16)
op_reg( ops[0], REG_ACC );
op_acc( ops[0] );
op_imm( ops[1], 16 );
return Hex_mxshl;
}
Expand All @@ -4302,7 +4301,7 @@ static uint32_t iclass_10_HMX( uint32_t word, uint64_t /*extender*/, op_t *ops,
{
// mxmem(Rs32,Rt32)[:cm|:2x2] = cvt
static const uint32_t suff[3] = { 0, MX_CM, MX_2X2 };
op_mxmem( ops[0], MEM_MX | suff[ BITS(1:0) ], REG_R(s5), REG_R(t5) );
op_mxmem( ops[0], suff[ BITS(1:0) ], REG_R(s5), REG_R(t5) );
op_reg( ops[1], REG_CVT );
return Hex_mov;
}
Expand Down
41 changes: 21 additions & 20 deletions hexagon/ins.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ enum {
REG_POST_SM = (21 << 4), // .sm
REG_POST_UBIT = (22 << 4), // .ubit
REG_POST_SBIT = (23 << 4), // .sbit
REG_POST_2x1 = (24 << 4), // :2x1
REG_POST_2x2 = (25 << 4), // :2x2
REG_POST_MASK = (31 << 4),
REG_POST_SHIFT = 4,
REG_POST_INC = (1 << 9), // ...++
Expand All @@ -130,8 +128,6 @@ enum {
MEM_D = 7, // memd
MEM_V = 8, // vmem
MEM_VU = 9, // vmemu
MEM_MX = 10, // mxmem
MEM_MX2 = 11, // mxmem2
MEM_TYPE_MASK = 0x0F,
MEM_FIFO = 1 << 4, // memX_fifo
MEM_LOCKED = 2 << 4, // memX_locked
Expand All @@ -145,23 +141,27 @@ enum {
MEM_SUFFIX_MASK = 0x180,
MEM_SUFFIX_SHIFT= 7,
MEM_IMM_EXT = 0x200,
};

enum {
// mxmem suffixes
MX_2X = 1 << 10, // :2x
MX_SINGLE = 1 << 11, // :single
MX_DROP = 2 << 11, // :drop
MX_DEEP = 3 << 11, // :deep
MX_BEFORE = 4 << 11, // :before
MX_AFTER = 5 << 11, // :after
MX_ABOVE = 6 << 11, // :above
MX_DILATE = 7 << 11, // :dilate
MX_RETAIN = 1 << 14, // :retain
MX_CM = 1 << 15, // :cm
MX_2X2 = 2 << 15, // :2x2
MX_POS = 1 << 17, // :pos
MX_SAT = 2 << 17, // :sat
MX_UB = 1 << 19, // .ub
MX_UH = 2 << 19, // .uh
MX_HF = 3 << 19, // .hf
MX_MEM2 = 1 << 0, // mxmem2
MX_2X = 1 << 1, // :2x
MX_SINGLE = 1 << 2, // :single
MX_DROP = 2 << 2, // :drop
MX_DEEP = 3 << 2, // :deep
MX_BEFORE = 4 << 2, // :before
MX_AFTER = 5 << 2, // :after
MX_ABOVE = 6 << 2, // :above
MX_DILATE = 7 << 2, // :dilate
MX_RETAIN = 1 << 5, // :retain
MX_CM = 1 << 6, // :cm
MX_2X2 = 2 << 6, // :2x2
MX_POS = 1 << 8, // :pos
MX_SAT = 2 << 8, // :sat
MX_UB = 1 << 10, // .ub
MX_UH = 2 << 10, // .uh
MX_HF = 3 << 10, // .hf
};

enum {
Expand All @@ -170,6 +170,7 @@ enum {
ACC_2X2 = 2 << 0, // :2x2
ACC_SC0 = 3 << 0, // :sc0
ACC_SC1 = 4 << 0, // :sc1
ACC_HF = 5 << 0, // .hf
};

static __inline uint32_t mem_op_type( const op_t &op )
Expand Down
75 changes: 36 additions & 39 deletions hexagon/out.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static void hex_out_reg( outctx_t &ctx, uint32_t reg, uint32_t flags = 0 )
"", ".new", ".cur", ".tmp", ".l", ".h", "*",
".b", ".h", ".w", ".ub", ".uh", ".uw",
".sf", ".hf", ".bf", ".qf32", ".qf16",
".n", ".c", ".sc", ".sm", ".ubit", ".sbit", ":2x1", ":2x2"
".n", ".c", ".sc", ".sm", ".ubit", ".sbit",
};
ctx.out_keyword( postfix[(flags & REG_POST_MASK) >> REG_POST_SHIFT] );
if( (flags & REG_POST_INC) )
Expand All @@ -213,7 +213,7 @@ static void hex_out_mem( outctx_t &ctx, uint32_t type )
{
static const char *types[] = {
"memb", "membh", "memub", "memubh", "memh", "memuh",
"memw", "memd", "vmem", "vmemu", "mxmem", "mxmem2",
"memw", "memd", "vmem", "vmemu",
};
static const char *infixes[] = {
"", "_fifo", "_locked", "_aq", "_rl",
Expand All @@ -230,7 +230,7 @@ ssize_t out_operand( outctx_t &ctx, const op_t &op )

// memory accesses
if( op.type == o_mem || op.type == o_displ ||
o_mem_abs_set <= op.type && op.type <= o_mxmem )
o_mem_abs_set <= op.type && op.type <= o_mem_locked )
{
hex_out_mem( ctx, mem_op_type( op ) );
ctx.out_symbol( '(' );
Expand Down Expand Up @@ -304,13 +304,6 @@ ssize_t out_operand( outctx_t &ctx, const op_t &op )
hex_out_reg( ctx, op.specflag2 );
}
break;
case o_mxmem: // mxmem[2](Rs[,Rt])
hex_out_reg( ctx, op.reg >> 8 );
if( (op.reg & 0xFF) != 0xFF ) {
ctx.out_line( ", ", COLOR_SYMBOL );
hex_out_reg( ctx, op.reg & 0xFF );
}
break;
}
ctx.out_symbol( ')' );
if( (mem_op_type( op ) & MEM_SUFFIX_MASK) )
Expand All @@ -320,34 +313,6 @@ ssize_t out_operand( outctx_t &ctx, const op_t &op )
};
ctx.out_keyword( suffixes[ (mem_op_type( op ) & MEM_SUFFIX_MASK) >> MEM_SUFFIX_SHIFT ] );
}
if( op.type == o_mxmem )
{
uint32_t type = mem_op_type( op );
static const char *suff1[] = {
"", ":single", ":drop", ":deep", ":before", ":after", ":above", ":dilate"
};
static const char *suff2[] = {
"", ":cm", ":2x2",
};
static const char *suff3[] = {
"", ":pos", ":sat",
};
static const char *types[] = {
"", ".ub", ".uh", ".hf",
};
if( (type & MX_2X) )
ctx.out_keyword( ":2x" );
if( ((type >> 11) & 7) )
ctx.out_keyword( suff1[ (type >> 11) & 7 ] );
if( (type & MX_RETAIN) )
ctx.out_keyword( ":retain" );
if( ((type >> 15) & 3) )
ctx.out_keyword( suff2[ (type >> 15) & 3 ] );
if( ((type >> 17) & 3) )
ctx.out_keyword( suff3[ (type >> 17) & 3 ] );
if( ((type >> 19) & 3) )
ctx.out_keyword( types[ (type >> 19) & 3 ] );
}
return 1;
}

Expand All @@ -364,6 +329,38 @@ ssize_t out_operand( outctx_t &ctx, const op_t &op )
ctx.out_value( op, OOFW_IMM | OOFW_32 | ((flags & IMM_SIGNED)? OOF_SIGNED : 0) );
if( (flags & IMM_PCREL) ) ctx.out_keyword( "@pcrel" );
break;
case o_mxmem:
ctx.out_line( (op.specval & MX_MEM2)? "mxmem2" : "mxmem", COLOR_INSN );
ctx.out_symbol( '(' );
hex_out_reg( ctx, op.reg >> 8 );
if( (op.reg & 0xFF) != 0xFF ) {
ctx.out_line( ", ", COLOR_SYMBOL );
hex_out_reg( ctx, op.reg & 0xFF );
}
ctx.out_symbol( ')' );
if( (op.specval & MX_2X) )
ctx.out_keyword( ":2x" );
if( ((op.specval >> 2) & 7) ) {
static const char *suff1[] = {
"", ":single", ":drop", ":deep", ":before", ":after", ":above", ":dilate"
};
ctx.out_keyword( suff1[ (op.specval >> 2) & 7 ] );
}
if( (op.specval & MX_RETAIN) )
ctx.out_keyword( ":retain" );
if( ((op.specval >> 6) & 3) ) {
static const char *suff2[] = { "", ":cm", ":2x2" };
ctx.out_keyword( suff2[ (op.specval >> 6) & 3 ] );
}
if( ((op.specval >> 8) & 3) ) {
static const char *suff3[] = { "", ":pos", ":sat" };
ctx.out_keyword( suff3[ (op.specval >> 8) & 3 ] );
}
if( ((op.specval >> 10) & 3) ) {
static const char *types[] = { "", ".ub", ".uh", ".hf" };
ctx.out_keyword( types[ (op.specval >> 10) & 3 ] );
}
break;
case o_acc:
ctx.out_line( "acc", COLOR_REG );
if( op.reg != 0xFF ) {
Expand All @@ -374,7 +371,7 @@ ssize_t out_operand( outctx_t &ctx, const op_t &op )
if( op.specval )
{
static const char *postfix[] = {
"", ":2x1", ":2x2", ":sc0", ":sc1"
"", ":2x1", ":2x2", ":sc0", ":sc1", ".hf",
};
ctx.out_keyword( postfix[op.specval] );
}
Expand Down

0 comments on commit 7ef6cef

Please sign in to comment.