Commit 042f09a9 authored by mbrandy's avatar mbrandy Committed by Commit bot

Reland PPC portion of "Detect cache line size on Linux for PPC hosts."

This version does not modify arm64.

R=jkummerow@chromium.org, michael_dawson@ca.ibm.com
BUG=

Review URL: https://codereview.chromium.org/1806893002

Cr-Commit-Position: refs/heads/master@{#34827}
parent ee30626d
...@@ -82,7 +82,7 @@ static unsigned CpuFeaturesImpliedByCompiler() { ...@@ -82,7 +82,7 @@ static unsigned CpuFeaturesImpliedByCompiler() {
void CpuFeatures::ProbeImpl(bool cross_compile) { void CpuFeatures::ProbeImpl(bool cross_compile) {
supported_ |= CpuFeaturesImpliedByCompiler(); supported_ |= CpuFeaturesImpliedByCompiler();
cache_line_size_ = 64; dcache_line_size_ = 64;
// Only use statically determined features for cross compile (snapshot). // Only use statically determined features for cross compile (snapshot).
if (cross_compile) return; if (cross_compile) return;
...@@ -137,7 +137,7 @@ void CpuFeatures::ProbeImpl(bool cross_compile) { ...@@ -137,7 +137,7 @@ void CpuFeatures::ProbeImpl(bool cross_compile) {
if (cpu.implementer() == base::CPU::ARM && if (cpu.implementer() == base::CPU::ARM &&
(cpu.part() == base::CPU::ARM_CORTEX_A5 || (cpu.part() == base::CPU::ARM_CORTEX_A5 ||
cpu.part() == base::CPU::ARM_CORTEX_A9)) { cpu.part() == base::CPU::ARM_CORTEX_A9)) {
cache_line_size_ = 32; dcache_line_size_ = 32;
} }
if (FLAG_enable_32dregs && cpu.has_vfp3_d32()) supported_ |= 1u << VFP32DREGS; if (FLAG_enable_32dregs && cpu.has_vfp3_d32()) supported_ |= 1u << VFP32DREGS;
......
...@@ -108,23 +108,23 @@ MemCopyUint8Function CreateMemCopyUint8Function(Isolate* isolate, ...@@ -108,23 +108,23 @@ MemCopyUint8Function CreateMemCopyUint8Function(Isolate* isolate,
__ b(lt, &size_less_than_8); __ b(lt, &size_less_than_8);
__ cmp(chars, Operand(32)); __ cmp(chars, Operand(32));
__ b(lt, &less_32); __ b(lt, &less_32);
if (CpuFeatures::cache_line_size() == 32) { if (CpuFeatures::dcache_line_size() == 32) {
__ pld(MemOperand(src, 32)); __ pld(MemOperand(src, 32));
} }
__ cmp(chars, Operand(64)); __ cmp(chars, Operand(64));
__ b(lt, &less_64); __ b(lt, &less_64);
__ pld(MemOperand(src, 64)); __ pld(MemOperand(src, 64));
if (CpuFeatures::cache_line_size() == 32) { if (CpuFeatures::dcache_line_size() == 32) {
__ pld(MemOperand(src, 96)); __ pld(MemOperand(src, 96));
} }
__ cmp(chars, Operand(128)); __ cmp(chars, Operand(128));
__ b(lt, &less_128); __ b(lt, &less_128);
__ pld(MemOperand(src, 128)); __ pld(MemOperand(src, 128));
if (CpuFeatures::cache_line_size() == 32) { if (CpuFeatures::dcache_line_size() == 32) {
__ pld(MemOperand(src, 160)); __ pld(MemOperand(src, 160));
} }
__ pld(MemOperand(src, 192)); __ pld(MemOperand(src, 192));
if (CpuFeatures::cache_line_size() == 32) { if (CpuFeatures::dcache_line_size() == 32) {
__ pld(MemOperand(src, 224)); __ pld(MemOperand(src, 224));
} }
__ cmp(chars, Operand(256)); __ cmp(chars, Operand(256));
...@@ -134,7 +134,7 @@ MemCopyUint8Function CreateMemCopyUint8Function(Isolate* isolate, ...@@ -134,7 +134,7 @@ MemCopyUint8Function CreateMemCopyUint8Function(Isolate* isolate,
__ bind(&loop); __ bind(&loop);
__ pld(MemOperand(src, 256)); __ pld(MemOperand(src, 256));
__ vld1(Neon8, NeonListOperand(d0, 4), NeonMemOperand(src, PostIndex)); __ vld1(Neon8, NeonListOperand(d0, 4), NeonMemOperand(src, PostIndex));
if (CpuFeatures::cache_line_size() == 32) { if (CpuFeatures::dcache_line_size() == 32) {
__ pld(MemOperand(src, 256)); __ pld(MemOperand(src, 256));
} }
__ vld1(Neon8, NeonListOperand(d4, 4), NeonMemOperand(src, PostIndex)); __ vld1(Neon8, NeonListOperand(d4, 4), NeonMemOperand(src, PostIndex));
......
...@@ -271,7 +271,8 @@ CpuFeatureScope::~CpuFeatureScope() { ...@@ -271,7 +271,8 @@ CpuFeatureScope::~CpuFeatureScope() {
bool CpuFeatures::initialized_ = false; bool CpuFeatures::initialized_ = false;
unsigned CpuFeatures::supported_ = 0; unsigned CpuFeatures::supported_ = 0;
unsigned CpuFeatures::cache_line_size_ = 0; unsigned CpuFeatures::icache_line_size_ = 0;
unsigned CpuFeatures::dcache_line_size_ = 0;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Implementation of Label // Implementation of Label
......
...@@ -224,9 +224,14 @@ class CpuFeatures : public AllStatic { ...@@ -224,9 +224,14 @@ class CpuFeatures : public AllStatic {
static inline bool SupportsCrankshaft(); static inline bool SupportsCrankshaft();
static inline unsigned cache_line_size() { static inline unsigned icache_line_size() {
DCHECK(cache_line_size_ != 0); DCHECK(icache_line_size_ != 0);
return cache_line_size_; return icache_line_size_;
}
static inline unsigned dcache_line_size() {
DCHECK(dcache_line_size_ != 0);
return dcache_line_size_;
} }
static void PrintTarget(); static void PrintTarget();
...@@ -242,7 +247,8 @@ class CpuFeatures : public AllStatic { ...@@ -242,7 +247,8 @@ class CpuFeatures : public AllStatic {
static void ProbeImpl(bool cross_compile); static void ProbeImpl(bool cross_compile);
static unsigned supported_; static unsigned supported_;
static unsigned cache_line_size_; static unsigned icache_line_size_;
static unsigned dcache_line_size_;
static bool initialized_; static bool initialized_;
DISALLOW_COPY_AND_ASSIGN(CpuFeatures); DISALLOW_COPY_AND_ASSIGN(CpuFeatures);
}; };
......
...@@ -312,6 +312,8 @@ CPU::CPU() ...@@ -312,6 +312,8 @@ CPU::CPU()
architecture_(0), architecture_(0),
variant_(-1), variant_(-1),
part_(0), part_(0),
icache_line_size_(UNKNOWN_CACHE_LINE_SIZE),
dcache_line_size_(UNKNOWN_CACHE_LINE_SIZE),
has_fpu_(false), has_fpu_(false),
has_cmov_(false), has_cmov_(false),
has_sahf_(false), has_sahf_(false),
...@@ -644,9 +646,16 @@ CPU::CPU() ...@@ -644,9 +646,16 @@ CPU::CPU()
if (n == 0 || entry.a_type == AT_NULL) { if (n == 0 || entry.a_type == AT_NULL) {
break; break;
} }
if (entry.a_type == AT_PLATFORM) { switch (entry.a_type) {
auxv_cpu_type = reinterpret_cast<char*>(entry.a_un.a_val); case AT_PLATFORM:
break; auxv_cpu_type = reinterpret_cast<char*>(entry.a_un.a_val);
break;
case AT_ICACHEBSIZE:
icache_line_size_ = entry.a_un.a_val;
break;
case AT_DCACHEBSIZE:
dcache_line_size_ = entry.a_un.a_val;
break;
} }
} }
fclose(fp); fclose(fp);
......
...@@ -75,6 +75,9 @@ class CPU final { ...@@ -75,6 +75,9 @@ class CPU final {
// General features // General features
bool has_fpu() const { return has_fpu_; } bool has_fpu() const { return has_fpu_; }
int icache_line_size() const { return icache_line_size_; }
int dcache_line_size() const { return dcache_line_size_; }
static const int UNKNOWN_CACHE_LINE_SIZE = 0;
// x86 features // x86 features
bool has_cmov() const { return has_cmov_; } bool has_cmov() const { return has_cmov_; }
...@@ -118,6 +121,8 @@ class CPU final { ...@@ -118,6 +121,8 @@ class CPU final {
int architecture_; int architecture_;
int variant_; int variant_;
int part_; int part_;
int icache_line_size_;
int dcache_line_size_;
bool has_fpu_; bool has_fpu_;
bool has_cmov_; bool has_cmov_;
bool has_sahf_; bool has_sahf_;
......
...@@ -55,7 +55,7 @@ static unsigned CpuFeaturesImpliedByCompiler() { ...@@ -55,7 +55,7 @@ static unsigned CpuFeaturesImpliedByCompiler() {
void CpuFeatures::ProbeImpl(bool cross_compile) { void CpuFeatures::ProbeImpl(bool cross_compile) {
supported_ |= CpuFeaturesImpliedByCompiler(); supported_ |= CpuFeaturesImpliedByCompiler();
cache_line_size_ = 128; icache_line_size_ = 128;
// Only use statically determined features for cross compile (snapshot). // Only use statically determined features for cross compile (snapshot).
if (cross_compile) return; if (cross_compile) return;
...@@ -85,6 +85,9 @@ void CpuFeatures::ProbeImpl(bool cross_compile) { ...@@ -85,6 +85,9 @@ void CpuFeatures::ProbeImpl(bool cross_compile) {
// Assume support // Assume support
supported_ |= (1u << FPU); supported_ |= (1u << FPU);
} }
if (cpu.icache_line_size() != base::CPU::UNKNOWN_CACHE_LINE_SIZE) {
icache_line_size_ = cpu.icache_line_size();
}
#elif V8_OS_AIX #elif V8_OS_AIX
// Assume support FP support and default cache line size // Assume support FP support and default cache line size
supported_ |= (1u << FPU); supported_ |= (1u << FPU);
......
...@@ -25,7 +25,7 @@ void CpuFeatures::FlushICache(void* buffer, size_t size) { ...@@ -25,7 +25,7 @@ void CpuFeatures::FlushICache(void* buffer, size_t size) {
return; return;
} }
const int kCacheLineSize = CpuFeatures::cache_line_size(); const int kCacheLineSize = CpuFeatures::icache_line_size();
intptr_t mask = kCacheLineSize - 1; intptr_t mask = kCacheLineSize - 1;
byte *start = byte *start =
reinterpret_cast<byte *>(reinterpret_cast<intptr_t>(buffer) & ~mask); reinterpret_cast<byte *>(reinterpret_cast<intptr_t>(buffer) & ~mask);
......
...@@ -3453,39 +3453,6 @@ void MacroAssembler::CallCFunctionHelper(Register function, ...@@ -3453,39 +3453,6 @@ void MacroAssembler::CallCFunctionHelper(Register function,
} }
} }
void MacroAssembler::FlushICache(Register address, size_t size,
Register scratch) {
if (CpuFeatures::IsSupported(INSTR_AND_DATA_CACHE_COHERENCY)) {
sync();
icbi(r0, address);
isync();
return;
}
Label done;
dcbf(r0, address);
sync();
icbi(r0, address);
isync();
// This code handles ranges which cross a single cacheline boundary.
// scratch is last cacheline which intersects range.
const int kCacheLineSizeLog2 = WhichPowerOf2(CpuFeatures::cache_line_size());
DCHECK(size > 0 && size <= (size_t)(1 << kCacheLineSizeLog2));
addi(scratch, address, Operand(size - 1));
ClearRightImm(scratch, scratch, Operand(kCacheLineSizeLog2));
cmpl(scratch, address);
ble(&done);
dcbf(r0, scratch);
sync();
icbi(r0, scratch);
isync();
bind(&done);
}
void MacroAssembler::DecodeConstantPoolOffset(Register result, void MacroAssembler::DecodeConstantPoolOffset(Register result,
Register location) { Register location) {
......
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