Skip to content

Commit

Permalink
Common: Rename General to HostSys
Browse files Browse the repository at this point in the history
Actually fits what it's doing.
  • Loading branch information
stenzek committed Dec 26, 2023
1 parent b5464f2 commit 7da57c4
Show file tree
Hide file tree
Showing 33 changed files with 61 additions and 87 deletions.
4 changes: 2 additions & 2 deletions common/Assertions.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
// SPDX-License-Identifier: LGPL-3.0+

#include "Threading.h"
#include "General.h"
#include "Assertions.h"
#include "CrashHandler.h"
#include "HostSys.h"
#include "Threading.h"

#include <mutex>
#include "fmt/core.h"
Expand Down
14 changes: 14 additions & 0 deletions common/BitUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "common/Pcsx2Defs.h"

#include <bit>
#include <cstring>

#ifdef _MSC_VER

Expand Down Expand Up @@ -84,3 +85,16 @@ namespace Common
return std::countl_zero(static_cast<u32>(n));
}
} // namespace Common

template <typename T>
[[maybe_unused]] __fi static T GetBufferT(u8* buffer, u32 offset)
{
T value;
std::memcpy(&value, buffer + offset, sizeof(value));
return value;
}

[[maybe_unused]] __fi static u8 GetBufferU8(u8* buffer, u32 offset) { return GetBufferT<u8>(buffer, offset); }
[[maybe_unused]] __fi static u16 GetBufferU16(u8* buffer, u32 offset) { return GetBufferT<u16>(buffer, offset); }
[[maybe_unused]] __fi static u32 GetBufferU32(u8* buffer, u32 offset) { return GetBufferT<u32>(buffer, offset); }
[[maybe_unused]] __fi static u64 GetBufferU64(u8* buffer, u32 offset) { return GetBufferT<u64>(buffer, offset); }
5 changes: 2 additions & 3 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ target_sources(common PRIVATE
Error.cpp
FastJmp.cpp
FileSystem.cpp
General.cpp
HostSys.cpp
Image.cpp
HTTPDownloader.cpp
MemorySettingsInterface.cpp
Misc.cpp
MD5Digest.cpp
PrecompiledHeader.cpp
Perf.cpp
Expand Down Expand Up @@ -72,8 +71,8 @@ target_sources(common PRIVATE
FPControl.h
FastJmp.h
FileSystem.h
General.h
HashCombine.h
HostSys.h
HeterogeneousContainers.h
Image.h
LRUCache.h
Expand Down
2 changes: 1 addition & 1 deletion common/Darwin/DarwinMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "common/Pcsx2Types.h"
#include "common/Console.h"
#include "common/General.h"
#include "common/HostSys.h"
#include "common/Threading.h"
#include "common/WindowInfo.h"

Expand Down
26 changes: 0 additions & 26 deletions common/General.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion common/Misc.cpp → common/HostSys.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team
// SPDX-License-Identifier: LGPL-3.0+

#include "General.h"
#include "HostSys.h"
#include "Console.h"
#include "VectorIntrin.h"

Expand Down
43 changes: 12 additions & 31 deletions common/General.h → common/HostSys.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,48 @@
#include <map>
#include <memory>
#include <string>
#include <cstring>

template <typename T>
[[maybe_unused]] __fi static T GetBufferT(u8* buffer, u32 offset)
{
T value;
std::memcpy(&value, buffer + offset, sizeof(value));
return value;
}

[[maybe_unused]] __fi static u8 GetBufferU8(u8* buffer, u32 offset) { return GetBufferT<u8>(buffer, offset); }
[[maybe_unused]] __fi static u16 GetBufferU16(u8* buffer, u32 offset) { return GetBufferT<u16>(buffer, offset); }
[[maybe_unused]] __fi static u32 GetBufferU32(u8* buffer, u32 offset) { return GetBufferT<u32>(buffer, offset); }
[[maybe_unused]] __fi static u64 GetBufferU64(u8* buffer, u32 offset) { return GetBufferT<u64>(buffer, offset); }

// --------------------------------------------------------------------------------------
// PageProtectionMode
// --------------------------------------------------------------------------------------
class PageProtectionMode
{
protected:
bool m_read;
bool m_write;
bool m_exec;
bool m_read = false;
bool m_write = false;
bool m_exec = false;

public:
PageProtectionMode()
{
All(false);
}
__fi constexpr PageProtectionMode() = default;

PageProtectionMode& Read(bool allow = true)
__fi constexpr PageProtectionMode& Read(bool allow = true)
{
m_read = allow;
return *this;
}

PageProtectionMode& Write(bool allow = true)
__fi constexpr PageProtectionMode& Write(bool allow = true)
{
m_write = allow;
return *this;
}

PageProtectionMode& Execute(bool allow = true)
__fi constexpr PageProtectionMode& Execute(bool allow = true)
{
m_exec = allow;
return *this;
}

PageProtectionMode& All(bool allow = true)
__fi constexpr PageProtectionMode& All(bool allow = true)
{
m_read = m_write = m_exec = allow;
return *this;
}

bool CanRead() const { return m_read; }
bool CanWrite() const { return m_write; }
bool CanExecute() const { return m_exec && m_read; }
bool IsNone() const { return !m_read && !m_write; }

std::string ToString() const;
__fi constexpr bool CanRead() const { return m_read; }
__fi constexpr bool CanWrite() const { return m_write; }
__fi constexpr bool CanExecute() const { return m_exec && m_read; }
__fi constexpr bool IsNone() const { return !m_read && !m_write; }
};

static __fi PageProtectionMode PageAccess_None()
Expand Down
2 changes: 1 addition & 1 deletion common/Linux/LnxHostSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "common/BitUtils.h"
#include "common/Assertions.h"
#include "common/Console.h"
#include "common/General.h"
#include "common/HostSys.h"

// Apple uses the MAP_ANON define instead of MAP_ANONYMOUS, but they mean
// the same thing.
Expand Down
2 changes: 1 addition & 1 deletion common/Linux/LnxMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#if !defined(_WIN32) && !defined(__APPLE__)

#include "common/Pcsx2Types.h"
#include "common/General.h"
#include "common/HostSys.h"
#include "common/ScopedGuard.h"
#include "common/StringUtil.h"
#include "common/Threading.h"
Expand Down
1 change: 1 addition & 0 deletions common/Semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "common/Threading.h"
#include "common/Assertions.h"
#include "common/HostSys.h"

#ifdef _WIN32
#include "common/RedtapeWindows.h"
Expand Down
1 change: 0 additions & 1 deletion common/Threading.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#pragma once

#include "common/Pcsx2Defs.h"
#include "common/General.h"

#if defined(__APPLE__)
#include <mach/semaphore.h>
Expand Down
2 changes: 1 addition & 1 deletion common/Windows/WinHostSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "common/BitUtils.h"
#include "common/RedtapeWindows.h"
#include "common/Console.h"
#include "common/General.h"
#include "common/HostSys.h"
#include "common/StringUtil.h"
#include "common/AlignedMalloc.h"
#include "common/Assertions.h"
Expand Down
3 changes: 1 addition & 2 deletions common/Windows/WinMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

#if defined(_WIN32)

#include "common/Pcsx2Defs.h"
#include "common/HostSys.h"
#include "common/RedtapeWindows.h"
#include "common/StringUtil.h"
#include "common/Threading.h"
#include "common/General.h"
#include "common/WindowInfo.h"

#include "fmt/core.h"
Expand Down
5 changes: 2 additions & 3 deletions common/common.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="FileSystem.cpp" />
<ClCompile Include="General.cpp" />
<ClCompile Include="Image.cpp" />
<ClCompile Include="HTTPDownloader.cpp" />
<ClCompile Include="HTTPDownloaderCurl.cpp">
Expand Down Expand Up @@ -84,7 +83,7 @@
<ClCompile Include="Windows\WinHostSys.cpp" />
<ClCompile Include="Windows\WinMisc.cpp" />
<ClCompile Include="Windows\WinThreads.cpp" />
<ClCompile Include="Misc.cpp" />
<ClCompile Include="HostSys.cpp" />
<ClCompile Include="Semaphore.cpp" />
<ClCompile Include="emitter\avx.cpp" />
<ClCompile Include="emitter\bmi.cpp" />
Expand Down Expand Up @@ -135,7 +134,7 @@
<ClInclude Include="SettingsWrapper.h" />
<ClInclude Include="Assertions.h" />
<ClInclude Include="Console.h" />
<ClInclude Include="General.h" />
<ClInclude Include="HostSys.h" />
<ClInclude Include="Path.h" />
<ClInclude Include="PrecompiledHeader.h" />
<ClInclude Include="ReadbackSpinManager.h" />
Expand Down
7 changes: 2 additions & 5 deletions common/common.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<ClCompile Include="emitter\movs.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Misc.cpp">
<ClCompile Include="HostSys.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Perf.cpp">
Expand Down Expand Up @@ -124,9 +124,6 @@
<ClCompile Include="FileSystem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="General.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Error.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -159,7 +156,7 @@
<ClInclude Include="emitter\implement\dwshift.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="General.h">
<ClInclude Include="HostSys.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="emitter\implement\group1.h">
Expand Down
1 change: 0 additions & 1 deletion pcsx2/Achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "common/Console.h"
#include "common/Error.h"
#include "common/FileSystem.h"
#include "common/General.h"
#include "common/HTTPDownloader.h"
#include "common/MD5Digest.h"
#include "common/Path.h"
Expand Down
1 change: 1 addition & 0 deletions pcsx2/CDVD/CDVD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "IopDma.h"
#include "VMManager.h"

#include "common/BitUtils.h"
#include "common/Error.h"
#include "common/FileSystem.h"
#include "common/Path.h"
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include "common/General.h"
#include "common/Pcsx2Defs.h"
#include "common/FPControl.h"
#include <array>
#include <string>
Expand Down
1 change: 0 additions & 1 deletion pcsx2/GS/GSJobQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "GS.h"
#include "common/boost_spsc_queue.hpp"
#include "common/Assertions.h"
#include "common/General.h"
#include "common/Threading.h"
#include <condition_variable>
#include <functional>
Expand Down
2 changes: 2 additions & 0 deletions pcsx2/GS/GSPerfMon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "GSPerfMon.h"
#include "GS.h"

#include <cstring>

GSPerfMon g_perfmon;

GSPerfMon::GSPerfMon() = default;
Expand Down
2 changes: 2 additions & 0 deletions pcsx2/GS/Renderers/Common/GSFunctionMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "GS/GSExtra.h"
#include "GS/Renderers/SW/GSScanlineEnvironment.h"

#include "common/HostSys.h"

template <class KEY, class VALUE>
class GSFunctionMap
{
Expand Down
1 change: 1 addition & 0 deletions pcsx2/GS/Renderers/DX12/GSDevice12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "common/Console.h"
#include "common/BitUtils.h"
#include "common/HostSys.h"
#include "common/ScopedGuard.h"
#include "common/StringUtil.h"

Expand Down
1 change: 1 addition & 0 deletions pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "GS/GSPerfMon.h"

#include "common/Console.h"
#include "common/HostSys.h"

#include "imgui.h"

Expand Down
1 change: 0 additions & 1 deletion pcsx2/GS/Renderers/SW/GSRasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "common/AlignedMalloc.h"
#include "common/Console.h"
#include "common/General.h"
#include "common/StringUtil.h"

#define ENABLE_DRAW_STATS 0
Expand Down
1 change: 1 addition & 0 deletions pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "common/Console.h"
#include "common/BitUtils.h"
#include "common/HostSys.h"
#include "common/Path.h"
#include "common/ScopedGuard.h"

Expand Down
1 change: 1 addition & 0 deletions pcsx2/GameDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "common/FPControl.h"

#include <cstring>
#include <optional>
#include <string>
#include <string_view>
Expand Down
2 changes: 0 additions & 2 deletions pcsx2/IPU/IPU_MultiISA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include "IPU/yuv2rgb.h"
#include "IPU/IPU_MultiISA.h"

#include "common/General.h"

// the IPU is fixed to 16 byte strides (128-bit / QWC resolution):
static const uint decoder_stride = 16;

Expand Down
Loading

0 comments on commit 7da57c4

Please sign in to comment.