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

PPC: Use non prefixed instructions when possible

This CL adds a check to all integer/and fp load/store operations,
if the offset fits in an `is_int16` and if alignment requirements
are met (specific to lwa, ld and std) then a non prefixed load/store
instruction will be used.

Note that operation mode (MRI vs MRR) gets set during instruction selection.

Change-Id: I68e2aa1d559c7ff058d715e6e577a14b590b632b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3669186Reviewed-by: 's avatarJunliang Yan <junyan@redhat.com>
Commit-Queue: Milad Farazmand <mfarazma@redhat.com>
Cr-Commit-Position: refs/heads/main@{#80765}
parent 1b13172d
...@@ -461,10 +461,12 @@ Condition FlagsConditionToCondition(FlagsCondition condition, ArchOpcode op) { ...@@ -461,10 +461,12 @@ Condition FlagsConditionToCondition(FlagsCondition condition, ArchOpcode op) {
MemOperand operand = i.MemoryOperand(&mode); \ MemOperand operand = i.MemoryOperand(&mode); \
bool is_atomic = i.InputInt32(2); \ bool is_atomic = i.InputInt32(2); \
if (mode == kMode_MRI) { \ if (mode == kMode_MRI) { \
if (CpuFeatures::IsSupported(PPC_10_PLUS)) { \ intptr_t offset = operand.offset(); \
__ asm_instrp(result, operand); \ if (is_int16(offset)) { \
} else { \
__ asm_instr(result, operand); \ __ asm_instr(result, operand); \
} else { \
CHECK(CpuFeatures::IsSupported(PPC_10_PLUS)); \
__ asm_instrp(result, operand); \
} \ } \
} else { \ } else { \
__ asm_instrx(result, operand); \ __ asm_instrx(result, operand); \
...@@ -473,17 +475,21 @@ Condition FlagsConditionToCondition(FlagsCondition condition, ArchOpcode op) { ...@@ -473,17 +475,21 @@ Condition FlagsConditionToCondition(FlagsCondition condition, ArchOpcode op) {
DCHECK_EQ(LeaveRC, i.OutputRCBit()); \ DCHECK_EQ(LeaveRC, i.OutputRCBit()); \
} while (0) } while (0)
#define ASSEMBLE_LOAD_INTEGER(asm_instr, asm_instrp, asm_instrx) \ #define ASSEMBLE_LOAD_INTEGER(asm_instr, asm_instrp, asm_instrx, \
must_be_aligned) \
do { \ do { \
Register result = i.OutputRegister(); \ Register result = i.OutputRegister(); \
AddressingMode mode = kMode_None; \ AddressingMode mode = kMode_None; \
MemOperand operand = i.MemoryOperand(&mode); \ MemOperand operand = i.MemoryOperand(&mode); \
bool is_atomic = i.InputInt32(2); \ bool is_atomic = i.InputInt32(2); \
if (mode == kMode_MRI) { \ if (mode == kMode_MRI) { \
if (CpuFeatures::IsSupported(PPC_10_PLUS)) { \ intptr_t offset = operand.offset(); \
__ asm_instrp(result, operand); \ bool misaligned = offset & 3; \
} else { \ if (is_int16(offset) && (!must_be_aligned || !misaligned)) { \
__ asm_instr(result, operand); \ __ asm_instr(result, operand); \
} else { \
CHECK(CpuFeatures::IsSupported(PPC_10_PLUS)); \
__ asm_instrp(result, operand); \
} \ } \
} else { \ } else { \
__ asm_instrx(result, operand); \ __ asm_instrx(result, operand); \
...@@ -515,10 +521,12 @@ Condition FlagsConditionToCondition(FlagsCondition condition, ArchOpcode op) { ...@@ -515,10 +521,12 @@ Condition FlagsConditionToCondition(FlagsCondition condition, ArchOpcode op) {
/* removed frsp as instruction-selector checked */ \ /* removed frsp as instruction-selector checked */ \
/* value to be kFloat32 */ \ /* value to be kFloat32 */ \
if (mode == kMode_MRI) { \ if (mode == kMode_MRI) { \
if (CpuFeatures::IsSupported(PPC_10_PLUS)) { \ intptr_t offset = operand.offset(); \
__ asm_instrp(value, operand); \ if (is_int16(offset)) { \
} else { \
__ asm_instr(value, operand); \ __ asm_instr(value, operand); \
} else { \
CHECK(CpuFeatures::IsSupported(PPC_10_PLUS)); \
__ asm_instrp(value, operand); \
} \ } \
} else { \ } else { \
__ asm_instrx(value, operand); \ __ asm_instrx(value, operand); \
...@@ -527,7 +535,8 @@ Condition FlagsConditionToCondition(FlagsCondition condition, ArchOpcode op) { ...@@ -527,7 +535,8 @@ Condition FlagsConditionToCondition(FlagsCondition condition, ArchOpcode op) {
DCHECK_EQ(LeaveRC, i.OutputRCBit()); \ DCHECK_EQ(LeaveRC, i.OutputRCBit()); \
} while (0) } while (0)
#define ASSEMBLE_STORE_INTEGER(asm_instr, asm_instrp, asm_instrx) \ #define ASSEMBLE_STORE_INTEGER(asm_instr, asm_instrp, asm_instrx, \
must_be_aligned) \
do { \ do { \
size_t index = 0; \ size_t index = 0; \
AddressingMode mode = kMode_None; \ AddressingMode mode = kMode_None; \
...@@ -536,10 +545,13 @@ Condition FlagsConditionToCondition(FlagsCondition condition, ArchOpcode op) { ...@@ -536,10 +545,13 @@ Condition FlagsConditionToCondition(FlagsCondition condition, ArchOpcode op) {
bool is_atomic = i.InputInt32(3); \ bool is_atomic = i.InputInt32(3); \
if (is_atomic) __ lwsync(); \ if (is_atomic) __ lwsync(); \
if (mode == kMode_MRI) { \ if (mode == kMode_MRI) { \
if (CpuFeatures::IsSupported(PPC_10_PLUS)) { \ intptr_t offset = operand.offset(); \
__ asm_instrp(value, operand); \ bool misaligned = offset & 3; \
} else { \ if (is_int16(offset) && (!must_be_aligned || !misaligned)) { \
__ asm_instr(value, operand); \ __ asm_instr(value, operand); \
} else { \
CHECK(CpuFeatures::IsSupported(PPC_10_PLUS)); \
__ asm_instrp(value, operand); \
} \ } \
} else { \ } else { \
__ asm_instrx(value, operand); \ __ asm_instrx(value, operand); \
...@@ -1967,27 +1979,27 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( ...@@ -1967,27 +1979,27 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
break; break;
#endif #endif
case kPPC_LoadWordU8: case kPPC_LoadWordU8:
ASSEMBLE_LOAD_INTEGER(lbz, plbz, lbzx); ASSEMBLE_LOAD_INTEGER(lbz, plbz, lbzx, false);
break; break;
case kPPC_LoadWordS8: case kPPC_LoadWordS8:
ASSEMBLE_LOAD_INTEGER(lbz, plbz, lbzx); ASSEMBLE_LOAD_INTEGER(lbz, plbz, lbzx, false);
__ extsb(i.OutputRegister(), i.OutputRegister()); __ extsb(i.OutputRegister(), i.OutputRegister());
break; break;
case kPPC_LoadWordU16: case kPPC_LoadWordU16:
ASSEMBLE_LOAD_INTEGER(lhz, plhz, lhzx); ASSEMBLE_LOAD_INTEGER(lhz, plhz, lhzx, false);
break; break;
case kPPC_LoadWordS16: case kPPC_LoadWordS16:
ASSEMBLE_LOAD_INTEGER(lha, plha, lhax); ASSEMBLE_LOAD_INTEGER(lha, plha, lhax, false);
break; break;
case kPPC_LoadWordU32: case kPPC_LoadWordU32:
ASSEMBLE_LOAD_INTEGER(lwz, plwz, lwzx); ASSEMBLE_LOAD_INTEGER(lwz, plwz, lwzx, false);
break; break;
case kPPC_LoadWordS32: case kPPC_LoadWordS32:
ASSEMBLE_LOAD_INTEGER(lwa, plwa, lwax); ASSEMBLE_LOAD_INTEGER(lwa, plwa, lwax, true);
break; break;
#if V8_TARGET_ARCH_PPC64 #if V8_TARGET_ARCH_PPC64
case kPPC_LoadWord64: case kPPC_LoadWord64:
ASSEMBLE_LOAD_INTEGER(ld, pld, ldx); ASSEMBLE_LOAD_INTEGER(ld, pld, ldx, true);
break; break;
#endif #endif
case kPPC_LoadFloat32: case kPPC_LoadFloat32:
...@@ -2012,17 +2024,17 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( ...@@ -2012,17 +2024,17 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
break; break;
} }
case kPPC_StoreWord8: case kPPC_StoreWord8:
ASSEMBLE_STORE_INTEGER(stb, pstb, stbx); ASSEMBLE_STORE_INTEGER(stb, pstb, stbx, false);
break; break;
case kPPC_StoreWord16: case kPPC_StoreWord16:
ASSEMBLE_STORE_INTEGER(sth, psth, sthx); ASSEMBLE_STORE_INTEGER(sth, psth, sthx, false);
break; break;
case kPPC_StoreWord32: case kPPC_StoreWord32:
ASSEMBLE_STORE_INTEGER(stw, pstw, stwx); ASSEMBLE_STORE_INTEGER(stw, pstw, stwx, false);
break; break;
#if V8_TARGET_ARCH_PPC64 #if V8_TARGET_ARCH_PPC64
case kPPC_StoreWord64: case kPPC_StoreWord64:
ASSEMBLE_STORE_INTEGER(std, pstd, stdx); ASSEMBLE_STORE_INTEGER(std, pstd, stdx, true);
break; break;
#endif #endif
case kPPC_StoreFloat32: case kPPC_StoreFloat32:
...@@ -3778,23 +3790,23 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction( ...@@ -3778,23 +3790,23 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
} }
case kPPC_StoreCompressTagged: { case kPPC_StoreCompressTagged: {
ASSEMBLE_STORE_INTEGER(StoreTaggedField, StoreTaggedField, ASSEMBLE_STORE_INTEGER(StoreTaggedField, StoreTaggedField,
StoreTaggedField); StoreTaggedField, true);
break; break;
} }
case kPPC_LoadDecompressTaggedSigned: { case kPPC_LoadDecompressTaggedSigned: {
CHECK(instr->HasOutput()); CHECK(instr->HasOutput());
ASSEMBLE_LOAD_INTEGER(lwz, plwz, lwzx); ASSEMBLE_LOAD_INTEGER(lwz, plwz, lwzx, false);
break; break;
} }
case kPPC_LoadDecompressTaggedPointer: { case kPPC_LoadDecompressTaggedPointer: {
CHECK(instr->HasOutput()); CHECK(instr->HasOutput());
ASSEMBLE_LOAD_INTEGER(lwz, plwz, lwzx); ASSEMBLE_LOAD_INTEGER(lwz, plwz, lwzx, false);
__ add(i.OutputRegister(), i.OutputRegister(), kRootRegister); __ add(i.OutputRegister(), i.OutputRegister(), kRootRegister);
break; break;
} }
case kPPC_LoadDecompressAnyTagged: { case kPPC_LoadDecompressAnyTagged: {
CHECK(instr->HasOutput()); CHECK(instr->HasOutput());
ASSEMBLE_LOAD_INTEGER(lwz, plwz, lwzx); ASSEMBLE_LOAD_INTEGER(lwz, plwz, lwzx, false);
__ add(i.OutputRegister(), i.OutputRegister(), kRootRegister); __ add(i.OutputRegister(), i.OutputRegister(), kRootRegister);
break; break;
} }
......
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