Commit 457112f6 authored by Milad Fa's avatar Milad Fa Committed by V8 LUCI CQ

PPC: optimize word and dw byte reverse on Power10

Change-Id: I89694796962d46b4fb1ae244ee39639576659465
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3092025Reviewed-by: 's avatarJunliang Yan <junyan@redhat.com>
Commit-Queue: Milad Fa <mfarazma@redhat.com>
Cr-Commit-Position: refs/heads/master@{#76273}
parent d58ef12c
......@@ -373,6 +373,11 @@ class Assembler : public AssemblerBase {
x_form(instr_name, cr.code() * B2, src1.code(), src2.code(), LeaveRC); \
}
#define DECLARE_PPC_X_INSTRUCTIONS_G_FORM(name, instr_name, instr_value) \
inline void name(const Register dst, const Register src) { \
x_form(instr_name, src, dst, r0, LeaveRC); \
}
#define DECLARE_PPC_X_INSTRUCTIONS_EH_S_FORM(name, instr_name, instr_value) \
inline void name(const Register dst, const MemOperand& src) { \
x_form(instr_name, src.ra(), dst, src.rb(), SetEH); \
......@@ -411,6 +416,7 @@ class Assembler : public AssemblerBase {
PPC_X_OPCODE_D_FORM_LIST(DECLARE_PPC_X_INSTRUCTIONS_D_FORM)
PPC_X_OPCODE_E_FORM_LIST(DECLARE_PPC_X_INSTRUCTIONS_E_FORM)
PPC_X_OPCODE_F_FORM_LIST(DECLARE_PPC_X_INSTRUCTIONS_F_FORM)
PPC_X_OPCODE_G_FORM_LIST(DECLARE_PPC_X_INSTRUCTIONS_G_FORM)
PPC_X_OPCODE_EH_S_FORM_LIST(DECLARE_PPC_X_INSTRUCTIONS_EH_S_FORM)
PPC_X_OPCODE_EH_L_FORM_LIST(DECLARE_PPC_X_INSTRUCTIONS_EH_L_FORM)
......@@ -442,6 +448,7 @@ class Assembler : public AssemblerBase {
#undef DECLARE_PPC_X_INSTRUCTIONS_D_FORM
#undef DECLARE_PPC_X_INSTRUCTIONS_E_FORM
#undef DECLARE_PPC_X_INSTRUCTIONS_F_FORM
#undef DECLARE_PPC_X_INSTRUCTIONS_G_FORM
#undef DECLARE_PPC_X_INSTRUCTIONS_EH_S_FORM
#undef DECLARE_PPC_X_INSTRUCTIONS_EH_L_FORM
......
......@@ -1270,6 +1270,14 @@ using Instr = uint32_t;
/* Compare Logical */ \
V(cmpl, CMPL, 0x7C000040)
#define PPC_X_OPCODE_G_FORM_LIST(V) \
/* Byte-Reverse Halfword */ \
V(brh, BRH, 0x7C0001B6) \
/* Byte-Reverse Word */ \
V(brw, BRW, 0x7C000136) \
/* Byte-Reverse Doubleword */ \
V(brd, BRD, 0x7C000176)
#define PPC_X_OPCODE_EH_S_FORM_LIST(V) \
/* Store Byte Conditional Indexed */ \
V(stbcx, STBCX, 0x7C00056D) \
......@@ -1740,6 +1748,7 @@ using Instr = uint32_t;
PPC_X_OPCODE_D_FORM_LIST(V) \
PPC_X_OPCODE_E_FORM_LIST(V) \
PPC_X_OPCODE_F_FORM_LIST(V) \
PPC_X_OPCODE_G_FORM_LIST(V) \
PPC_X_OPCODE_EH_L_FORM_LIST(V) \
PPC_X_OPCODE_UNUSED_LIST(V)
......
......@@ -2095,6 +2095,10 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
Register input = i.InputRegister(0);
Register output = i.OutputRegister();
Register temp1 = r0;
if (CpuFeatures::IsSupported(PPC_10_PLUS)) {
__ brw(output, input);
break;
}
__ rotlwi(temp1, input, 8);
__ rlwimi(temp1, input, 24, 0, 7);
__ rlwimi(temp1, input, 24, 16, 23);
......@@ -2115,6 +2119,10 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
Register temp1 = r0;
Register temp2 = kScratchReg;
Register temp3 = i.TempRegister(0);
if (CpuFeatures::IsSupported(PPC_10_PLUS)) {
__ brd(output, input);
break;
}
__ rldicl(temp1, input, 32, 32);
__ rotlwi(temp2, input, 8);
__ rlwimi(temp2, input, 24, 0, 7);
......
......@@ -917,6 +917,18 @@ void Decoder::DecodeExt2(Instruction* instr) {
Format(instr, "cnttzd'. 'ra, 'rs");
return;
}
case BRH: {
Format(instr, "brh 'ra, 'rs");
return;
}
case BRW: {
Format(instr, "brw 'ra, 'rs");
return;
}
case BRD: {
Format(instr, "brd 'ra, 'rs");
return;
}
case ANDX: {
Format(instr, "and'. 'ra, 'rs, 'rb");
return;
......
......@@ -3282,7 +3282,25 @@ void Simulator::ExecuteGeneric(Instruction* instr) {
}
break;
}
case BRW: {
constexpr int kBitsPerWord = 32;
int rs = instr->RSValue();
int ra = instr->RAValue();
uint64_t rs_val = get_register(rs);
uint32_t rs_high = rs_val >> kBitsPerWord;
uint32_t rs_low = (rs_val << kBitsPerWord) >> kBitsPerWord;
uint64_t result = __builtin_bswap32(rs_high);
result = (result << kBitsPerWord) | __builtin_bswap32(rs_low);
set_register(ra, result);
break;
}
case BRD: {
int rs = instr->RSValue();
int ra = instr->RAValue();
uint64_t rs_val = get_register(rs);
set_register(ra, __builtin_bswap64(rs_val));
break;
}
case FCFIDS: {
// fcfids
int frt = instr->RTValue();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment