Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vacuum 😢 #9464

Merged
merged 2 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion Utilities/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <typeinfo>
#include <map>

#include "util/asm.hpp"

using namespace std::literals::string_literals;

#ifdef _WIN32
Expand Down Expand Up @@ -1725,7 +1727,7 @@ u64 fs::get_dir_size(const std::string& path, u64 rounding_alignment)

if (!entry.is_directory)
{
result += ::align(entry.size, rounding_alignment);
result += utils::align(entry.size, rounding_alignment);
}
else
{
Expand Down
19 changes: 10 additions & 9 deletions Utilities/JIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "util/logs.hpp"
#include "mutex.h"
#include "util/vm.hpp"
#include "util/asm.hpp"
#include <immintrin.h>
#include <zlib.h>

Expand Down Expand Up @@ -52,8 +53,8 @@ static u8* add_jit_memory(usz size, uint align)
// Simple allocation by incrementing pointer to the next free data
const u64 pos = Ctr.atomic_op([&](u64& ctr) -> u64
{
const u64 _pos = ::align(ctr & 0xffff'ffff, align);
const u64 _new = ::align(_pos + size, align);
const u64 _pos = utils::align(ctr & 0xffff'ffff, align);
const u64 _new = utils::align(_pos + size, align);

if (_new > 0x40000000) [[unlikely]]
{
Expand All @@ -69,7 +70,7 @@ static u8* add_jit_memory(usz size, uint align)
// Check the necessity to commit more memory
if (_new > olda) [[unlikely]]
{
newa = ::align(_new, 0x200000);
newa = utils::align(_new, 0x200000);
}

ctr += _new - (ctr & 0xffff'ffff);
Expand Down Expand Up @@ -223,7 +224,7 @@ asmjit::Runtime& asmjit::get_global_runtime()
return asmjit::kErrorNoCodeGenerated;
}

void* p = m_pos.fetch_add(::align(codeSize, 4096));
void* p = m_pos.fetch_add(utils::align(codeSize, 4096));
if (!p || m_pos > m_max) [[unlikely]]
{
*dst = nullptr;
Expand All @@ -237,7 +238,7 @@ asmjit::Runtime& asmjit::get_global_runtime()
return asmjit::kErrorInvalidState;
}

utils::memory_protect(p, ::align(codeSize, 4096), utils::protection::rx);
utils::memory_protect(p, utils::align(codeSize, 4096), utils::protection::rx);
flush(p, relocSize);
*dst = p;

Expand Down Expand Up @@ -351,8 +352,8 @@ struct MemoryManager1 : llvm::RTDyldMemoryManager
return nullptr;
}

const u64 olda = ::align(oldp, align);
const u64 newp = ::align(olda + size, align);
const u64 olda = utils::align(oldp, align);
const u64 newp = utils::align(olda + size, align);

if ((newp - 1) / c_max_size != oldp / c_max_size)
{
Expand All @@ -363,8 +364,8 @@ struct MemoryManager1 : llvm::RTDyldMemoryManager
if ((oldp - 1) / c_page_size != (newp - 1) / c_page_size)
{
// Allocate pages on demand
const u64 pagea = ::align(oldp, c_page_size);
const u64 psize = ::align(newp - pagea, c_page_size);
const u64 pagea = utils::align(oldp, c_page_size);
const u64 psize = utils::align(newp - pagea, c_page_size);
utils::memory_commit(this->ptr + pagea, psize, prot);
}

Expand Down
5 changes: 3 additions & 2 deletions rpcs3/Crypto/unedat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cmath>

#include "util/v128.hpp"
#include "util/asm.hpp"

LOG_CHANNEL(edat_log, "EDAT");

Expand Down Expand Up @@ -949,7 +950,7 @@ bool EDATADecrypter::ReadHeader()
}*/

file_size = edatHeader.file_size;
total_blocks = ::aligned_div(edatHeader.file_size, edatHeader.block_size);
total_blocks = utils::aligned_div(edatHeader.file_size, edatHeader.block_size);

return true;
}
Expand All @@ -962,7 +963,7 @@ u64 EDATADecrypter::ReadData(u64 pos, u8* data, u64 size)
// now we need to offset things to account for the actual 'range' requested
const u64 startOffset = pos % edatHeader.block_size;

const u32 num_blocks = static_cast<u32>(::aligned_div(startOffset + size, edatHeader.block_size));
const u32 num_blocks = static_cast<u32>(utils::aligned_div(startOffset + size, edatHeader.block_size));
const u64 bufSize = num_blocks*edatHeader.block_size;
if (data_buf_size < (bufSize))
{
Expand Down
2 changes: 2 additions & 0 deletions rpcs3/Emu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ target_sources(rpcs3_emu PRIVATE
RSX/GL/GLTexture.cpp
RSX/GL/GLVertexBuffers.cpp
RSX/GL/GLVertexProgram.cpp
RSX/GL/GLTextureCache.cpp
RSX/GL/OpenGL.cpp
)

Expand All @@ -454,6 +455,7 @@ if(TARGET 3rdparty_vulkan)
RSX/VK/VKTexture.cpp
RSX/VK/VKVertexBuffers.cpp
RSX/VK/VKVertexProgram.cpp
RSX/VK/VKTextureCache.cpp
)
endif()

Expand Down
8 changes: 4 additions & 4 deletions rpcs3/Emu/Cell/Modules/cellDmux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "cellPamf.h"
#include "cellDmux.h"

#include <thread>
#include "util/asm.hpp"

LOG_CHANNEL(cellDmux);

Expand Down Expand Up @@ -753,9 +753,9 @@ PesHeader::PesHeader(DemuxerStream& stream)
}

ElementaryStream::ElementaryStream(Demuxer* dmux, u32 addr, u32 size, u32 fidMajor, u32 fidMinor, u32 sup1, u32 sup2, vm::ptr<CellDmuxCbEsMsg> cbFunc, u32 cbArg, u32 spec)
: put(align(addr, 128))
: put(utils::align(addr, 128))
, dmux(dmux)
, memAddr(align(addr, 128))
, memAddr(utils::align(addr, 128))
, memSize(size - (addr - memAddr))
, fidMajor(fidMajor)
, fidMinor(fidMinor)
Expand Down Expand Up @@ -847,7 +847,7 @@ void ElementaryStream::push_au(u32 size, u64 dts, u64 pts, u64 userdata, bool ra

addr = put;

put = align(put + 128 + size, 128);
put = utils::align(put + 128 + size, 128);

put_count++;
}
Expand Down
8 changes: 5 additions & 3 deletions rpcs3/Emu/Cell/Modules/cellSaveData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <mutex>
#include <algorithm>

#include "util/asm.hpp"

LOG_CHANNEL(cellSaveData);

template<>
Expand Down Expand Up @@ -953,7 +955,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
{
if (!file.is_directory)
{
size_bytes += ::align(file.size, 1024);
size_bytes += utils::align(file.size, 1024);
}
}

Expand Down Expand Up @@ -1334,7 +1336,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
{
statGet->fileNum++;

size_bytes += ::align(entry.size, 1024); // firmware rounds this value up
size_bytes += utils::align(entry.size, 1024); // firmware rounds this value up

if (statGet->fileListNum >= setBuf->fileListMax)
continue;
Expand Down Expand Up @@ -1892,7 +1894,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v
// add file list per FS order to PARAM.SFO
std::string final_blist;
final_blist = fmt::merge(blist, "/");
psf::assign(psf, "RPCS3_BLIST", psf::string(::align(::size32(final_blist) + 1, 4), final_blist));
psf::assign(psf, "RPCS3_BLIST", psf::string(utils::align(::size32(final_blist) + 1, 4), final_blist));

// Write all files in temporary directory
auto& fsfo = all_files["PARAM.SFO"];
Expand Down
5 changes: 3 additions & 2 deletions rpcs3/Emu/Cell/Modules/cellVdec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern "C"
#include <cmath>
#include "Utilities/lockless.h"
#include <variant>
#include "util/asm.hpp"

std::mutex g_mutex_avcodec_open2;

Expand Down Expand Up @@ -879,7 +880,7 @@ error_code cellVdecGetPicture(u32 handle, vm::cptr<CellVdecPicFormat> format, vm

sws_scale(vdec->sws, in_data, in_line, 0, h, out_data, out_line);

//const u32 buf_size = align(av_image_get_buffer_size(vdec->ctx->pix_fmt, vdec->ctx->width, vdec->ctx->height, 1), 128);
//const u32 buf_size = utils::align(av_image_get_buffer_size(vdec->ctx->pix_fmt, vdec->ctx->width, vdec->ctx->height, 1), 128);

//// TODO: zero padding bytes

Expand Down Expand Up @@ -974,7 +975,7 @@ error_code cellVdecGetPicItem(u32 handle, vm::pptr<CellVdecPicItem> picItem)
info->startAddr = 0x00000123; // invalid value (no address for picture)
const int buffer_size = av_image_get_buffer_size(vdec->ctx->pix_fmt, vdec->ctx->width, vdec->ctx->height, 1);
ensure(buffer_size >= 0);
info->size = align<u32>(buffer_size, 128);
info->size = utils::align<u32>(buffer_size, 128);
info->auNum = 1;
info->auPts[0].lower = static_cast<u32>(pts);
info->auPts[0].upper = static_cast<u32>(pts >> 32);
Expand Down
3 changes: 2 additions & 1 deletion rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Emu/Cell/lv2/sys_process.h"

#include <cmath>
#include "util/asm.hpp"

LOG_CHANNEL(sceNpTrophy);

Expand Down Expand Up @@ -1109,7 +1110,7 @@ error_code sceNpTrophyGetGameProgress(u32 context, u32 handle, vm::ptr<s32> perc
const u32 trp_count = ctxt->tropusr->GetTrophiesCount();

// Round result to nearest (TODO: Check 0 trophies)
*percentage = trp_count ? ::rounded_div(unlocked * 100, trp_count) : 0;
*percentage = trp_count ? utils::rounded_div(unlocked * 100, trp_count) : 0;

if (trp_count == 0 || trp_count > 128)
{
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/PPUCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace ppu_cb_detail
is_context ? ARG_CONTEXT :
ARG_UNKNOWN;

const u32 g = g_count + (is_general || is_float ? 1 : is_vector ? ::align(g_count, 2) + 2 : 0);
const u32 g = g_count + (is_general || is_float ? 1 : is_vector ? (g_count & 1) + 2 : 0);
const u32 f = f_count + is_float;
const u32 v = v_count + is_vector;

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/PPUFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace ppu_func_detail
is_variadic ? ARG_VARIADIC :
ARG_UNKNOWN;

const u32 g = g_count + (is_general || is_float ? 1 : is_vector ? ::align(g_count, 2) + 2 : 0);
const u32 g = g_count + (is_general || is_float ? 1 : is_vector ? (g_count & 1) + 2 : 0);
const u32 f = f_count + is_float;
const u32 v = v_count + is_vector;

Expand Down
13 changes: 7 additions & 6 deletions rpcs3/Emu/Cell/PPUModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <map>
#include <set>
#include <algorithm>
#include "util/asm.hpp"

LOG_CHANNEL(ppu_loader);

Expand Down Expand Up @@ -263,7 +264,7 @@ static void ppu_initialize_modules(ppu_linkage_info* link)
}

// Set memory protection to read-only
vm::page_protect(ppu_function_manager::addr, ::align(::size32(hle_funcs) * 8, 0x1000), 0, 0, vm::page_writable);
vm::page_protect(ppu_function_manager::addr, utils::align(::size32(hle_funcs) * 8, 0x1000), 0, 0, vm::page_writable);

// Initialize function names
const bool is_first = g_ppu_function_names.empty();
Expand Down Expand Up @@ -319,7 +320,7 @@ static void ppu_initialize_modules(ppu_linkage_info* link)
}
else
{
const u32 next = ::align(alloc_addr, variable.second.align);
const u32 next = utils::align(alloc_addr, variable.second.align);
const u32 end = next + variable.second.size;

if (!next || (end >> 12 != alloc_addr >> 12))
Expand Down Expand Up @@ -1500,7 +1501,7 @@ void ppu_load_exec(const ppu_exec_object& elf)

for (const auto& arg : Emu.argv)
{
const u32 arg_size = ::align(::size32(arg) + 1, 0x10);
const u32 arg_size = utils::align(::size32(arg) + 1, 0x10);
const u32 arg_addr = vm::alloc(arg_size, vm::main);

std::memcpy(vm::base(arg_addr), arg.data(), arg_size);
Expand All @@ -1513,7 +1514,7 @@ void ppu_load_exec(const ppu_exec_object& elf)

for (const auto& arg : Emu.envp)
{
const u32 arg_size = ::align(::size32(arg) + 1, 0x10);
const u32 arg_size = utils::align(::size32(arg) + 1, 0x10);
const u32 arg_addr = vm::alloc(arg_size, vm::main);

std::memcpy(vm::base(arg_addr), arg.data(), arg_size);
Expand All @@ -1533,7 +1534,7 @@ void ppu_load_exec(const ppu_exec_object& elf)
case 0x70: primary_stacksize = 1024 * 1024; break; // SYS_PROCESS_PRIMARY_STACK_SIZE_1M
default:
{
primary_stacksize = ::align<u32>(std::clamp<u32>(sz, 0x10000, 0x100000), 4096);
primary_stacksize = utils::align<u32>(std::clamp<u32>(sz, 0x10000, 0x100000), 4096);
break;
}
}
Expand Down Expand Up @@ -1636,7 +1637,7 @@ void ppu_load_exec(const ppu_exec_object& elf)
if (prog.p_type == 0x1u /* LOAD */ && prog.p_memsz && (prog.p_flags & 0x2) == 0u /* W */)
{
// Set memory protection to read-only when necessary
ensure(vm::page_protect(addr, ::align(size, 0x1000), 0, 0, vm::page_writable));
ensure(vm::page_protect(addr, utils::align(size, 0x1000), 0, 0, vm::page_writable));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/PPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ extern void ppu_register_range(u32 addr, u32 size)

// Register executable range at
utils::memory_commit(&ppu_ref(addr), size * 2, utils::protection::rw);
vm::page_protect(addr, align(size, 0x10000), 0, vm::page_executable);
vm::page_protect(addr, utils::align(size, 0x10000), 0, vm::page_executable);

const u64 fallback = g_cfg.core.ppu_decoder == ppu_decoder_type::llvm ? reinterpret_cast<uptr>(ppu_recompiler_fallback) : reinterpret_cast<uptr>(ppu_fallback);

Expand Down Expand Up @@ -1098,7 +1098,7 @@ u32 ppu_thread::stack_push(u32 size, u32 align_v)
ppu_thread& context = static_cast<ppu_thread&>(*cpu);

const u32 old_pos = vm::cast(context.gpr[1]);
context.gpr[1] -= align(size + 4, 8); // room minimal possible size
context.gpr[1] -= utils::align(size + 4, 8); // room minimal possible size
context.gpr[1] &= ~(u64{align_v} - 1); // fix stack alignment

if (old_pos >= context.stack_addr && old_pos < context.stack_addr + context.stack_size && context.gpr[1] < context.stack_addr)
Expand Down
6 changes: 3 additions & 3 deletions rpcs3/Emu/Cell/SPUASMJITRecompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ spu_function_t spu_recompiler::compile(spu_program&& _func)
words_align = 64;

const u32 starta = start & -64;
const u32 enda = ::align(end, 64);
const u32 enda = utils::align(end, 64);
const u32 sizea = (enda - starta) / 64;
ensure(sizea);

Expand Down Expand Up @@ -369,7 +369,7 @@ spu_function_t spu_recompiler::compile(spu_program&& _func)
words_align = 32;

const u32 starta = start & -32;
const u32 enda = ::align(end, 32);
const u32 enda = utils::align(end, 32);
const u32 sizea = (enda - starta) / 32;
ensure(sizea);

Expand Down Expand Up @@ -491,7 +491,7 @@ spu_function_t spu_recompiler::compile(spu_program&& _func)
words_align = 32;

const u32 starta = start & -32;
const u32 enda = ::align(end, 32);
const u32 enda = utils::align(end, 32);
const u32 sizea = (enda - starta) / 32;
ensure(sizea);

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/SPUThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2338,7 +2338,7 @@ void spu_thread::do_dma_transfer(spu_thread* _this, const spu_mfc_cmd& args, u8*
}

u32 range_addr = eal & -128;
u32 range_end = ::align(eal + size, 128);
u32 range_end = utils::align(eal + size, 128);

// Handle the case of crossing 64K page borders (TODO: maybe split in 4K fragments?)
if (range_addr >> 16 != (range_end - 1) >> 16)
Expand Down
5 changes: 3 additions & 2 deletions rpcs3/Emu/Cell/lv2/sys_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Emu/IdManager.h"

#include "util/vm.hpp"
#include "util/asm.hpp"

LOG_CHANNEL(sys_memory);

Expand Down Expand Up @@ -57,7 +58,7 @@ error_code sys_memory_allocate(cpu_thread& cpu, u32 size, u64 flags, vm::ptr<u32
return CELL_ENOMEM;
}

if (const auto area = vm::reserve_map(align == 0x10000 ? vm::user64k : vm::user1m, 0, ::align(size, 0x10000000), 0x401))
if (const auto area = vm::reserve_map(align == 0x10000 ? vm::user64k : vm::user1m, 0, utils::align(size, 0x10000000), 0x401))
{
if (u32 addr = area->alloc(size, nullptr, align))
{
Expand Down Expand Up @@ -128,7 +129,7 @@ error_code sys_memory_allocate_from_container(cpu_thread& cpu, u32 size, u32 cid
return ct.ret;
}

if (const auto area = vm::reserve_map(align == 0x10000 ? vm::user64k : vm::user1m, 0, ::align(size, 0x10000000), 0x401))
if (const auto area = vm::reserve_map(align == 0x10000 ? vm::user64k : vm::user1m, 0, utils::align(size, 0x10000000), 0x401))
{
if (u32 addr = area->alloc(size))
{
Expand Down