Changeset View
Changeset View
Standalone View
Standalone View
source/lib/sysdep/arch/x86_x64/cache.h
/* Copyright (C) 2018 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
* | * | ||||
* The above copyright notice and this permission notice shall be included | * The above copyright notice and this permission notice shall be included | ||||
* in all copies or substantial portions of the Software. | * in all copies or substantial portions of the Software. | ||||
* | * | ||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||||
*/ | */ | ||||
#include "lib/sysdep/arch/x86_x64/x86_x64.h" | |||||
#ifndef INCLUDED_X86_X64_CACHE | #ifndef INCLUDED_X86_X64_CACHE | ||||
#define INCLUDED_X86_X64_CACHE | #define INCLUDED_X86_X64_CACHE | ||||
namespace x86_x64 { | namespace x86_x64 { | ||||
struct Cache // POD (may be used before static constructors) | struct Cache // POD (may be used before static constructors) | ||||
{ | { | ||||
enum Type | enum Type | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | void Initialize(size_t level, Type type) | ||||
m_Associativity = 0; | m_Associativity = 0; | ||||
m_SharedBy = 0; | m_SharedBy = 0; | ||||
ENSURE(Validate()); | ENSURE(Validate()); | ||||
} | } | ||||
bool Validate() const | bool Validate() const | ||||
{ | { | ||||
// TODO: The cache detection for Ryzen CPUs isn't implemented yet. | |||||
// Returning true is a workaround, to protect the system from crash. | |||||
// For a correct implementation please look here: https://community.amd.com/thread/244207 | |||||
if (x86_x64::Vendor() == x86_x64::VENDOR_AMD) | |||||
return true; | |||||
if(!(1 <= m_Level && m_Level <= maxLevels)) | if(!(1 <= m_Level && m_Level <= maxLevels)) | ||||
return false; | return false; | ||||
if(m_Type == kNull) | if(m_Type == kNull) | ||||
return false; | return false; | ||||
if(m_NumEntries == 0) // disabled | if(m_NumEntries == 0) // disabled | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator