New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8294366: RISC-V: Partially mark out incompressible regions #28
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -664,8 +664,8 @@ class Assembler : public AbstractAssembler { | |
emit(insn); \ | ||
} | ||
|
||
INSN(_beq, 0b1100011, 0b000); | ||
INSN(_bne, 0b1100011, 0b001); | ||
INSN(beq, 0b1100011, 0b000); | ||
INSN(bne, 0b1100011, 0b001); | ||
INSN(bge, 0b1100011, 0b101); | ||
INSN(bgeu, 0b1100011, 0b111); | ||
INSN(blt, 0b1100011, 0b100); | ||
|
@@ -882,7 +882,7 @@ class Assembler : public AbstractAssembler { | |
emit(insn); \ | ||
} | ||
|
||
INSN(_jal, 0b1101111); | ||
INSN(jal, 0b1101111); | ||
|
||
#undef INSN | ||
|
||
|
@@ -2104,20 +2104,30 @@ enum Nf { | |
// RISC-V Compressed Instructions Extension | ||
// ======================================== | ||
// Note: | ||
// 1. When UseRVC is enabled, 32-bit instructions under 'CompressibleRegion's will be | ||
// transformed to 16-bit instructions if compressible. | ||
// 2. RVC instructions in Assembler always begin with 'c_' prefix, as 'c_li', | ||
// but most of time we have no need to explicitly use these instructions. | ||
// 3. 'CompressibleRegion' is introduced to hint instructions in this Region's RTTI range | ||
// are qualified to be compressed with their 2-byte versions. | ||
// An example: | ||
// 1. Assembler functions encoding 16-bit compressed instructions always begin with a 'c_' | ||
// prefix, such as 'c_add'. Correspondingly, assembler functions encoding normal 32-bit | ||
// instructions with begin with a '_' prefix, such as "_add". Most of time users have no | ||
// need to explicitly emit these compressed instructions. Instead, they still use unified | ||
// wrappers such as 'add' which do the compressing work through 'c_add' depending on the | ||
// the operands of the instruction and availability of the RVC hardware extension. | ||
// | ||
// CompressibleRegion cr(_masm); | ||
// __ andr(...); // this instruction could change to c.and if able to | ||
// 2. 'CompressibleRegion' and 'IncompressibleRegion' are introduced to mark assembler scopes | ||
// within which instructions are qualified or unqualified to be compressed into their 16-bit | ||
// versions. An example: | ||
// | ||
// 4. Using -XX:PrintAssemblyOptions=no-aliases could distinguish RVC instructions from | ||
// normal ones. | ||
// CompressibleRegion cr(_masm); | ||
// __ add(...); // this instruction will be compressed into 'c.and' when possible | ||
// { | ||
// IncompressibleRegion ir(_masm); | ||
// __ add(...); // this instruction will not be compressed | ||
// { | ||
// CompressibleRegion cr(_masm); | ||
// __ add(...); // this instruction will be compressed into 'c.and' when possible | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue here |
||
// } | ||
// } | ||
// | ||
// 3. When printing JIT assembly code, using -XX:PrintAssemblyOptions=no-aliases could help | ||
// distinguish compressed 16-bit instructions from normal 32-bit ones. | ||
|
||
private: | ||
bool _in_compressible_region; | ||
|
@@ -2126,21 +2136,36 @@ enum Nf { | |
void set_in_compressible_region(bool b) { _in_compressible_region = b; } | ||
public: | ||
|
||
// a compressible region | ||
class CompressibleRegion : public StackObj { | ||
// an abstract compressible region | ||
class AbstractCompressibleRegion : public StackObj { | ||
protected: | ||
Assembler *_masm; | ||
bool _saved_in_compressible_region; | ||
public: | ||
CompressibleRegion(Assembler *_masm) | ||
protected: | ||
AbstractCompressibleRegion(Assembler *_masm) | ||
: _masm(_masm) | ||
, _saved_in_compressible_region(_masm->in_compressible_region()) { | ||
, _saved_in_compressible_region(_masm->in_compressible_region()) {} | ||
}; | ||
// a compressible region | ||
class CompressibleRegion : public AbstractCompressibleRegion { | ||
public: | ||
CompressibleRegion(Assembler *_masm) : AbstractCompressibleRegion(_masm) { | ||
_masm->set_in_compressible_region(true); | ||
} | ||
~CompressibleRegion() { | ||
_masm->set_in_compressible_region(_saved_in_compressible_region); | ||
} | ||
}; | ||
// an incompressible region | ||
class IncompressibleRegion : public AbstractCompressibleRegion { | ||
public: | ||
IncompressibleRegion(Assembler *_masm) : AbstractCompressibleRegion(_masm) { | ||
_masm->set_in_compressible_region(false); | ||
} | ||
~IncompressibleRegion() { | ||
_masm->set_in_compressible_region(_saved_in_compressible_region); | ||
} | ||
}; | ||
|
||
// patch a 16-bit instruction. | ||
static void c_patch(address a, unsigned msb, unsigned lsb, uint16_t val) { | ||
|
@@ -2841,43 +2866,8 @@ enum Nf { | |
|
||
#undef INSN | ||
|
||
// -------------------------- | ||
// Conditional branch instructions | ||
// -------------------------- | ||
#define INSN(NAME, C_NAME, NORMAL_NAME) \ | ||
void NAME(Register Rs1, Register Rs2, const int64_t offset) { \ | ||
/* beq/bne -> c.beqz/c.bnez */ \ | ||
if (do_compress() && \ | ||
(offset != 0 && Rs2 == x0 && Rs1->is_compressed_valid() && \ | ||
is_imm_in_range(offset, 8, 1))) { \ | ||
C_NAME(Rs1, offset); \ | ||
return; \ | ||
} \ | ||
NORMAL_NAME(Rs1, Rs2, offset); \ | ||
} | ||
|
||
INSN(beq, c_beqz, _beq); | ||
INSN(bne, c_bnez, _bne); | ||
|
||
#undef INSN | ||
|
||
// -------------------------- | ||
// Unconditional branch instructions | ||
// -------------------------- | ||
#define INSN(NAME) \ | ||
void NAME(Register Rd, const int32_t offset) { \ | ||
/* jal -> c.j */ \ | ||
if (do_compress() && offset != 0 && Rd == x0 && is_imm_in_range(offset, 11, 1)) { \ | ||
c_j(offset); \ | ||
return; \ | ||
} \ | ||
_jal(Rd, offset); \ | ||
} | ||
|
||
INSN(jal); | ||
|
||
#undef INSN | ||
|
||
// -------------------------- | ||
#define INSN(NAME) \ | ||
void NAME(Register Rd, Register Rs, const int32_t offset) { \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments use
c.and
, but the example asm usesadd
, is this a typo?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed typos, thanks for the catch. The
openjdk/jdk
repo also has these two typos. Not sure about the rule of backporting: should I fix it here and then file another patch onopenjdk/jdk
, or?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is better way.
alternative
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the detailed approaches. Going to choose the first one for it is cleaner. :-)