Skip to content

Commit

Permalink
JIT ARM64-SVE: Add more templated encode immediate methods (dotnet#10…
Browse files Browse the repository at this point in the history
…0078)

Adds templated insEncodeUimm_MultipleOf and insEncodeSimm_MultipleOf methods to further reduce redundancy. The SVE unit test output remains unchanged.
  • Loading branch information
amanasifkhalid authored Mar 22, 2024
1 parent be1df80 commit bf828d8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 203 deletions.
143 changes: 0 additions & 143 deletions src/coreclr/jit/emitarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12249,138 +12249,6 @@ void emitter::emitIns_Call(EmitCallType callType,
return (h | l);
}

/*****************************************************************************
*
* Returns the encoding for the immediate value that is a multiple of 2 as 4-bits at bit locations '19-16'.
*/

/*static*/ emitter::code_t emitter::insEncodeSimm4_MultipleOf2_19_to_16(ssize_t imm)
{
assert((isValidSimm_MultipleOf<4, 2>(imm)));
return insEncodeSimm<19, 16>(imm / 2);
}

/*****************************************************************************
*
* Returns the encoding for the immediate value that is a multiple of 3 as 4-bits at bit locations '19-16'.
*/

/*static*/ emitter::code_t emitter::insEncodeSimm4_MultipleOf3_19_to_16(ssize_t imm)
{
assert((isValidSimm_MultipleOf<4, 3>(imm)));
return insEncodeSimm<19, 16>(imm / 3);
}

/*****************************************************************************
*
* Returns the encoding for the immediate value that is a multiple of 4 as 4-bits at bit locations '19-16'.
*/

/*static*/ emitter::code_t emitter::insEncodeSimm4_MultipleOf4_19_to_16(ssize_t imm)
{
assert((isValidSimm_MultipleOf<4, 4>(imm)));
return insEncodeSimm<19, 16>(imm / 4);
}

/*****************************************************************************
*
* Returns the encoding for the immediate value that is a multiple of 16 as 4-bits at bit locations '19-16'.
*/

/*static*/ emitter::code_t emitter::insEncodeSimm4_MultipleOf16_19_to_16(ssize_t imm)
{
assert((isValidSimm_MultipleOf<4, 16>(imm)));
return insEncodeSimm<19, 16>(imm / 16);
}

/*****************************************************************************
*
* Returns the encoding for the immediate value that is a multiple of 32 as 4-bits at bit locations '19-16'.
*/

/*static*/ emitter::code_t emitter::insEncodeSimm4_MultipleOf32_19_to_16(ssize_t imm)
{
assert((isValidSimm_MultipleOf<4, 32>(imm)));
return insEncodeSimm<19, 16>(imm / 32);
}

/*****************************************************************************
*
* Returns the encoding for the immediate value that is a multiple of 2 as 5-bits at bit locations '20-16'.
*/

/*static*/ emitter::code_t emitter::insEncodeUimm5_MultipleOf2_20_to_16(ssize_t imm)
{
assert((isValidUimm_MultipleOf<5, 2>(imm)));
return insEncodeUimm<20, 16>(imm / 2);
}

/*****************************************************************************
*
* Returns the encoding for the immediate value that is a multiple of 4 as 5-bits at bit locations '20-16'.
*/

/*static*/ emitter::code_t emitter::insEncodeUimm5_MultipleOf4_20_to_16(ssize_t imm)
{
assert((isValidUimm_MultipleOf<5, 4>(imm)));
return insEncodeUimm<20, 16>(imm / 4);
}

/*****************************************************************************
*
* Returns the encoding for the immediate value that is a multiple of 8 as 5-bits at bit locations '20-16'.
*/

/*static*/ emitter::code_t emitter::insEncodeUimm5_MultipleOf8_20_to_16(ssize_t imm)
{
assert((isValidUimm_MultipleOf<5, 8>(imm)));
return insEncodeUimm<20, 16>(imm / 8);
}

/*****************************************************************************
*
* Returns the encoding for the immediate value that is a multiple of 2 as 6-bits at bit locations '21-16'.
*/

/*static*/ emitter::code_t emitter::insEncodeUimm6_MultipleOf2_21_to_16(ssize_t imm)
{
assert((isValidUimm_MultipleOf<6, 2>(imm)));
return insEncodeUimm<21, 16>(imm / 2);
}

/*****************************************************************************
*
* Returns the encoding for the immediate value that is a multiple of 4 as 6-bits at bit locations '21-16'.
*/

/*static*/ emitter::code_t emitter::insEncodeUimm6_MultipleOf4_21_to_16(ssize_t imm)
{
assert((isValidUimm_MultipleOf<6, 4>(imm)));
return insEncodeUimm<21, 16>(imm / 4);
}

/*****************************************************************************
*
* Returns the encoding for the immediate value that is a multiple of 8 as 6-bits at bit locations '21-16'.
*/

/*static*/ emitter::code_t emitter::insEncodeUimm6_MultipleOf8_21_to_16(ssize_t imm)
{
assert((isValidUimm_MultipleOf<6, 8>(imm)));
return insEncodeUimm<21, 16>(imm / 8);
}

/*****************************************************************************
*
* Returns the encoding for the immediate value as 1-bit at bit locations '23'.
*/

/*static*/ emitter::code_t emitter::insEncodeUimm1_23(ssize_t imm)
{
assert(isValidUimm<1>(imm));
return (code_t)imm << 23;
}

/*****************************************************************************
*
* Returns the encoding for the immediate value as 3-bits at bit locations '23-22' for high and '12' for low.
Expand All @@ -12396,17 +12264,6 @@ void emitter::emitIns_Call(EmitCallType callType,
return (h | l);
}

/*****************************************************************************
*
* Returns the encoding for the immediate value as 4-bits starting from 1, at bit locations '19-16'.
*/

/*static*/ emitter::code_t emitter::insEncodeUimm4From1_19_to_16(ssize_t imm)
{
assert(isValidUimmFrom1<4>(imm));
return (code_t)(imm - 1) << 16;
}

/*****************************************************************************
*
* Returns the encoding for the immediate value as 8-bits at bit locations '12-5'.
Expand Down
58 changes: 20 additions & 38 deletions src/coreclr/jit/emitarm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -676,51 +676,33 @@ static code_t insEncodeSimm(ssize_t imm)
return result << lo;
}

// Returns the encoding for the immediate value as 9-bits at bit locations '21-16' for high and '12-10' for low.
static code_t insEncodeSimm9h9l_21_to_16_and_12_to_10(ssize_t imm);

// Returns the encoding for the immediate value that is a multiple of 2 as 4-bits at bit locations '19-16'.
static code_t insEncodeSimm4_MultipleOf2_19_to_16(ssize_t imm);

// Returns the encoding for the immediate value that is a multiple of 3 as 4-bits at bit locations '19-16'.
static code_t insEncodeSimm4_MultipleOf3_19_to_16(ssize_t imm);

// Returns the encoding for the immediate value that is a multiple of 4 as 4-bits at bit locations '19-16'.
static code_t insEncodeSimm4_MultipleOf4_19_to_16(ssize_t imm);

// Returns the encoding for the immediate value that is a multiple of 16 as 4-bits at bit locations '19-16'.
static code_t insEncodeSimm4_MultipleOf16_19_to_16(ssize_t imm);

// Returns the encoding for the immediate value that is a multiple of 32 as 4-bits at bit locations '19-16'.
static code_t insEncodeSimm4_MultipleOf32_19_to_16(ssize_t imm);

// Returns the encoding for the immediate value that is a multiple of 2 as 5-bits at bit locations '20-16'.
static code_t insEncodeUimm5_MultipleOf2_20_to_16(ssize_t imm);

// Returns the encoding for the immediate value that is a multiple of 4 as 5-bits at bit locations '20-16'.
static code_t insEncodeUimm5_MultipleOf4_20_to_16(ssize_t imm);

// Returns the encoding for the immediate value that is a multiple of 8 as 5-bits at bit locations '20-16'.
static code_t insEncodeUimm5_MultipleOf8_20_to_16(ssize_t imm);

// Returns the encoding for the immediate value that is a multiple of 2 as 6-bits at bit locations '21-16'.
static code_t insEncodeUimm6_MultipleOf2_21_to_16(ssize_t imm);
// Returns the encoding for unsigned immediate `imm` that is a multiple of `mul` with `bits` number of bits,
// for bit locations `hi-lo`.
template <const size_t hi, const size_t lo, const ssize_t mul>
static code_t insEncodeUimm_MultipleOf(ssize_t imm)
{

// Returns the encoding for the immediate value that is a multiple of 4 as 6-bits at bit locations '21-16'.
static code_t insEncodeUimm6_MultipleOf4_21_to_16(ssize_t imm);
constexpr size_t bits = hi - lo + 1;
assert((isValidUimm_MultipleOf<bits, mul>(imm)));
return insEncodeUimm<hi, lo>(imm / mul);
}

// Returns the encoding for the immediate value that is a multiple of 8 as 6-bits at bit locations '21-16'.
static code_t insEncodeUimm6_MultipleOf8_21_to_16(ssize_t imm);
// Returns the encoding for signed immediate `imm` that is a multiple of `mul` with `bits` number of bits,
// for bit locations `hi-lo`.
template <const size_t hi, const size_t lo, const ssize_t mul>
static code_t insEncodeSimm_MultipleOf(ssize_t imm)
{
constexpr size_t bits = hi - lo + 1;
assert((isValidSimm_MultipleOf<bits, mul>(imm)));
return insEncodeSimm<hi, lo>(imm / mul);
}

// Returns the encoding for the immediate value as 1-bit at bit locations '23'.
static code_t insEncodeUimm1_23(ssize_t imm);
// Returns the encoding for the immediate value as 9-bits at bit locations '21-16' for high and '12-10' for low.
static code_t insEncodeSimm9h9l_21_to_16_and_12_to_10(ssize_t imm);

// Returns the encoding for the immediate value as 3-bits at bit locations '23-22' for high and '12' for low.
static code_t insEncodeUimm3h3l_23_to_22_and_12(ssize_t imm);

// Returns the encoding for the immediate value as 4-bits starting from 1, at bit locations '19-16'.
static code_t insEncodeUimm4From1_19_to_16(ssize_t imm);

// Returns the encoding for the immediate value as 8-bits at bit locations '12-5'.
static code_t insEncodeImm8_12_to_5(ssize_t imm);

Expand Down
Loading

0 comments on commit bf828d8

Please sign in to comment.