Starting to remove some macros.

This commit is contained in:
Ben Vanik 2014-08-16 16:57:00 -07:00
parent ead74f2cdb
commit 54ce9db743
21 changed files with 74 additions and 97 deletions

View File

@ -9,6 +9,7 @@
#include <alloy/frontend/ppc/ppc_scanner.h>
#include <algorithm>
#include <map>
#include <alloy/frontend/ppc/ppc_frontend.h>
@ -49,10 +50,10 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
XELOGSDB("Analyzing function %.8X...", symbol_info->address());
uint64_t start_address = symbol_info->address();
uint64_t end_address = symbol_info->end_address();
uint64_t address = start_address;
uint64_t furthest_target = start_address;
uint32_t start_address = symbol_info->address();
uint32_t end_address = symbol_info->end_address();
uint32_t address = start_address;
uint32_t furthest_target = start_address;
size_t blocks_found = 0;
bool in_block = false;
bool starts_with_mfspr_lr = false;
@ -191,7 +192,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
*/
if (!ends_fn && !IsRestGprLr(target)) {
furthest_target = MAX(furthest_target, target);
furthest_target = std::max(furthest_target, target);
// TODO(benvanik): perhaps queue up for a speculative check? I think
// we are running over tail-call functions here that branch to
@ -217,7 +218,7 @@ int PPCScanner::FindExtents(FunctionInfo* symbol_info) {
// TODO(benvanik): GetOrInsertFunction? it's likely a BB
if (!IsRestGprLr(target)) {
furthest_target = MAX(furthest_target, target);
furthest_target = std::max(furthest_target, target);
}
}
ends_block = true;

View File

@ -14,7 +14,7 @@
namespace alloy {
StringBuffer::StringBuffer(size_t initial_capacity) {
buffer_.reserve(MAX(initial_capacity, 1024));
buffer_.reserve(std::max(initial_capacity, 1024ull));
}
StringBuffer::~StringBuffer() = default;

View File

@ -9,6 +9,7 @@
#include <xenia/core/pal.h>
#include <algorithm>
namespace {
typedef struct xe_pal_win {
@ -38,7 +39,7 @@ int xe_pal_init(xe_pal_options_t options) {
// Setup COM on the main thread.
// NOTE: this may fail if COM has already been initialized - that's OK.
XEIGNORE(CoInitializeEx(NULL, COINIT_MULTITHREADED));
CoInitializeEx(NULL, COINIT_MULTITHREADED);
atexit(xe_pal_dealloc);
return 0;
@ -114,9 +115,9 @@ int xe_pal_get_system_info(xe_system_info* out_info) {
}
out_info->processors.physical_count =
MAX(1, out_info->processors.physical_count);
std::max(1u, out_info->processors.physical_count);
out_info->processors.logical_count =
MAX(1, out_info->processors.logical_count);
std::max(1u, out_info->processors.logical_count);
result_code = 0;
XECLEANUP:

View File

@ -264,7 +264,7 @@ int xe_socket_loop_poll(xe_socket_loop_t* loop,
loop->pending_queued_write = loop->events[1].revents != 0;
if (loop->pending_queued_write) {
char dummy;
XEIGNORE(recv(loop->notify_rd_id, &dummy, 1, 0));
recv(loop->notify_rd_id, &dummy, 1, 0);
}
loop->events[1].revents = 0;
loop->events[1].events = POLLIN;

View File

@ -9,6 +9,7 @@
#include <xenia/cpu/xenon_memory.h>
#include <algorithm>
#include <mutex>
#include <gflags/gflags.h>
@ -482,7 +483,7 @@ XenonMemoryHeap::~XenonMemoryHeap() {
}
if (ptr_) {
XEIGNORE(VirtualFree(ptr_, 0, MEM_RELEASE));
VirtualFree(ptr_, 0, MEM_RELEASE);
}
}
@ -508,13 +509,11 @@ uint64_t XenonMemoryHeap::Alloc(
size_t alloc_size = size;
size_t heap_guard_size = FLAGS_heap_guard_pages * 4096;
if (heap_guard_size) {
alignment = (uint32_t)MAX(alignment, heap_guard_size);
alignment = std::max(alignment, static_cast<uint32_t>(heap_guard_size));
alloc_size = (uint32_t)XEROUNDUP(size, heap_guard_size);
}
uint8_t* p = (uint8_t*)mspace_memalign(
space_,
alignment,
alloc_size + heap_guard_size * 2);
uint8_t* p = (uint8_t*)mspace_memalign(space_, alignment,
alloc_size + heap_guard_size * 2);
assert_true(reinterpret_cast<uint64_t>(p) <= 0xFFFFFFFFFull);
if (FLAGS_heap_guard_pages) {
size_t real_size = mspace_usable_size(p);

View File

@ -9,6 +9,8 @@
#include <xenia/cpu/xex_module.h>
#include <algorithm>
#include <xenia/cpu/cpu-private.h>
#include <xenia/cpu/xenon_runtime.h>
#include <xenia/export_resolver.h>
@ -54,8 +56,10 @@ int XexModule::Load(const std::string& name, const std::string& path, xe_xex2_re
const size_t end_address =
start_address + (section->info.page_count * xe_xex2_section_length);
if (section->info.type == XEX_SECTION_CODE) {
low_address_ = (uint32_t)MIN(low_address_, start_address);
high_address_ = (uint32_t)MAX(high_address_, end_address);
low_address_ =
static_cast<uint32_t>(std::min(low_address_, start_address));
high_address_ =
static_cast<uint32_t>(std::max(high_address_, end_address));
}
i += section->info.page_count;
}

View File

@ -22,7 +22,7 @@ ExportResolver::~ExportResolver() {
void ExportResolver::RegisterTable(
const char* library_name, KernelExport* exports, const size_t count) {
ExportTable table;
XEIGNORE(xestrcpya(table.name, XECOUNT(table.name), library_name));
xestrcpya(table.name, XECOUNT(table.name), library_name);
table.exports = exports;
table.count = count;
tables_.push_back(table);

View File

@ -9,6 +9,8 @@
#include <xenia/gpu/command_processor.h>
#include <algorithm>
#include <xenia/gpu/gpu-private.h>
#include <xenia/gpu/graphics_driver.h>
#include <xenia/gpu/graphics_system.h>
@ -79,8 +81,9 @@ void CommandProcessor::EnableReadPointerWriteBack(uint32_t ptr,
}
void CommandProcessor::UpdateWritePointer(uint32_t value) {
write_ptr_max_index_ = MAX(write_ptr_max_index_, value);
write_ptr_index_ = value;
write_ptr_max_index_ =
std::max(static_cast<uint32_t>(write_ptr_max_index_), value);
write_ptr_index_ = value;
SetEvent(write_ptr_index_event_);
}

View File

@ -9,6 +9,8 @@
#include <xenia/gpu/d3d11/d3d11_profiler_display.h>
#include <algorithm>
#include <xenia/gpu/gpu-private.h>
#include <xenia/gpu/d3d11/d3d11_window.h>
@ -548,8 +550,8 @@ void D3D11ProfilerDisplay::DrawBox(
uint32_t r = 0xFF & (color >> 16);
uint32_t g = 0xFF & (color >> 8);
uint32_t b = 0xFF & color;
uint32_t max_c = MAX(MAX(MAX(r, g), b), 30u);
uint32_t min_c = MIN(MIN(MIN(r, g), b), 180u);
uint32_t max_c = std::max(std::max(std::max(r, g), b), 30u);
uint32_t min_c = std::min(std::min(std::min(r, g), b), 180u);
uint32_t r0 = 0xFF & ((r + max_c)/2);
uint32_t g0 = 0xFF & ((g + max_c)/2);
uint32_t b0 = 0xFF & ((b + max_c)/2);

View File

@ -9,6 +9,8 @@
#include <xenia/gpu/d3d11/d3d11_shader_translator.h>
#include <algorithm>
#include <xenia/gpu/gpu-private.h>
#include <xenia/gpu/d3d11/d3d11_geometry_shader.h>
#include <xenia/gpu/d3d11/d3d11_resource_cache.h>
@ -282,7 +284,7 @@ int D3D11ShaderTranslator::TranslatePixelShader(
// Add temporary registers.
uint32_t temp_regs = program_cntl.vs_regs + program_cntl.ps_regs;
for (uint32_t n = 0; n <= MAX(15, temp_regs); n++) {
for (uint32_t n = 0; n <= std::max(15u, temp_regs); n++) {
append(
" float4 r%d = c[%d];\n", n, n + 256);
}

View File

@ -57,12 +57,12 @@ Entry* DiscImageDevice::ResolvePath(const char* path) {
// Walk the path, one separator at a time.
// We copy it into the buffer and shift it left over and over.
char remaining[poly::max_path];
XEIGNORE(xestrcpya(remaining, XECOUNT(remaining), path));
xestrcpya(remaining, XECOUNT(remaining), path);
while (remaining[0]) {
char* next_slash = strchr(remaining, '\\');
if (next_slash == remaining) {
// Leading slash - shift
XEIGNORE(xestrcpya(remaining, XECOUNT(remaining), remaining + 1));
xestrcpya(remaining, XECOUNT(remaining), remaining + 1);
continue;
}
@ -82,7 +82,7 @@ Entry* DiscImageDevice::ResolvePath(const char* path) {
if (!next_slash) {
break;
}
XEIGNORE(xestrcpya(remaining, XECOUNT(remaining), next_slash + 1));
xestrcpya(remaining, XECOUNT(remaining), next_slash + 1);
}
Entry::Type type = gdfx_entry->attributes & X_FILE_ATTRIBUTE_DIRECTORY ?

View File

@ -9,6 +9,8 @@
#include <xenia/kernel/fs/devices/disc_image_entry.h>
#include <algorithm>
#include <xenia/kernel/fs/gdfx.h>
#include <xenia/kernel/fs/devices/disc_image_file.h>
@ -118,7 +120,7 @@ MemoryMapping* DiscImageEntry::CreateMemoryMapping(
size_t real_offset = gdfx_entry_->offset + offset;
size_t real_length = length ?
MIN(length, gdfx_entry_->size) : gdfx_entry_->size;
std::min(length, gdfx_entry_->size) : gdfx_entry_->size;
return new DiscImageMemoryMapping(
xe_mmap_get_addr(mmap_) + real_offset,
real_length,

View File

@ -9,10 +9,11 @@
#include <xenia/kernel/fs/devices/disc_image_file.h>
#include <xenia/kernel/fs/gdfx.h>
#include <xenia/kernel/fs/devices/disc_image_entry.h>
#include <algorithm>
#include <xenia/kernel/fs/device.h>
#include <xenia/kernel/fs/devices/disc_image_entry.h>
#include <xenia/kernel/fs/gdfx.h>
using namespace xe;
using namespace xe::kernel;
@ -67,7 +68,7 @@ X_STATUS DiscImageFile::ReadSync(
return X_STATUS_END_OF_FILE;
}
size_t real_offset = gdfx_entry->offset + byte_offset;
size_t real_length = MIN(buffer_length, gdfx_entry->size - byte_offset);
size_t real_length = std::min(buffer_length, gdfx_entry->size - byte_offset);
xe_copy_memory(
buffer, buffer_length,
xe_mmap_get_addr(mmap) + real_offset, real_length);

View File

@ -57,12 +57,12 @@ Entry* STFSContainerDevice::ResolvePath(const char* path) {
// Walk the path, one separator at a time.
// We copy it into the buffer and shift it left over and over.
char remaining[poly::max_path];
XEIGNORE(xestrcpya(remaining, XECOUNT(remaining), path));
xestrcpya(remaining, XECOUNT(remaining), path);
while (remaining[0]) {
char* next_slash = strchr(remaining, '\\');
if (next_slash == remaining) {
// Leading slash - shift
XEIGNORE(xestrcpya(remaining, XECOUNT(remaining), remaining + 1));
xestrcpya(remaining, XECOUNT(remaining), remaining + 1);
continue;
}
@ -82,7 +82,7 @@ Entry* STFSContainerDevice::ResolvePath(const char* path) {
if (!next_slash) {
break;
}
XEIGNORE(xestrcpya(remaining, XECOUNT(remaining), next_slash + 1));
xestrcpya(remaining, XECOUNT(remaining), next_slash + 1);
}
Entry::Type type = stfs_entry->attributes & X_FILE_ATTRIBUTE_DIRECTORY ?

View File

@ -9,10 +9,11 @@
#include <xenia/kernel/fs/devices/stfs_container_file.h>
#include <xenia/kernel/fs/stfs.h>
#include <xenia/kernel/fs/devices/stfs_container_entry.h>
#include <algorithm>
#include <xenia/kernel/fs/device.h>
#include <xenia/kernel/fs/devices/stfs_container_entry.h>
#include <xenia/kernel/fs/stfs.h>
using namespace xe;
using namespace xe::kernel;
@ -71,20 +72,20 @@ X_STATUS STFSContainerFile::ReadSync(
// Each block is 4096.
// Blocks may not be sequential, so we need to read by blocks and handle the
// offsets.
size_t real_length = MIN(buffer_length, stfs_entry->size - byte_offset);
size_t real_length = std::min(buffer_length, stfs_entry->size - byte_offset);
size_t start_block = byte_offset / 4096;
size_t end_block = MIN(
stfs_entry->block_list.size(),
(size_t)ceil((byte_offset + real_length) / 4096.0));
size_t end_block =
std::min(stfs_entry->block_list.size(),
(size_t)ceil((byte_offset + real_length) / 4096.0));
uint8_t* dest_ptr = (uint8_t*)buffer;
size_t remaining_length = real_length;
for (size_t n = start_block; n < end_block; n++) {
auto& record = stfs_entry->block_list[n];
size_t offset = record.offset;
size_t read_length = MIN(remaining_length, record.length);
size_t read_length = std::min(remaining_length, record.length);
if (n == start_block) {
offset += byte_offset % 4096;
read_length = MIN(read_length, record.length - (byte_offset % 4096));
read_length = std::min(read_length, record.length - (byte_offset % 4096));
}
xe_copy_struct(dest_ptr, map_ptr + offset, read_length);
dest_ptr += read_length;

View File

@ -11,6 +11,7 @@
#include <xenia/kernel/fs/stfs.h>
#include <algorithm>
using namespace xe;
using namespace xe::kernel;
@ -257,7 +258,7 @@ STFS::Error STFS::ReadAllEntries(const uint8_t* map_ptr) {
while (remaining_size &&
block_index &&
info >= 0x80) {
size_t block_size = MIN(0x1000, remaining_size);
size_t block_size = std::min(0x1000ull, remaining_size);
size_t offset = BlockToOffset(ComputeBlockNumber(block_index));
entry->block_list.push_back({ offset, block_size });
remaining_size -= block_size;

View File

@ -9,6 +9,8 @@
#include <xenia/kernel/object_table.h>
#include <algorithm>
#include <xenia/kernel/xobject.h>
#include <xenia/kernel/objects/xthread.h>
@ -61,10 +63,9 @@ X_STATUS ObjectTable::FindFreeSlot(uint32_t* out_slot) {
}
// Table out of slots, expand.
uint32_t new_table_capacity = MAX(16 * 1024, table_capacity_ * 2);
uint32_t new_table_capacity = std::max(16 * 1024u, table_capacity_ * 2);
ObjectTableEntry* new_table = (ObjectTableEntry*)xe_recalloc(
table_,
table_capacity_ * sizeof(ObjectTableEntry),
table_, table_capacity_ * sizeof(ObjectTableEntry),
new_table_capacity * sizeof(ObjectTableEntry));
if (!new_table) {
return X_STATUS_NO_MEMORY;

View File

@ -9,6 +9,7 @@
#include <xenia/kernel/util/xex2.h>
#include <algorithm>
#include <vector>
#include <gflags/gflags.h>
@ -262,8 +263,8 @@ int xe_xex2_read_header(const uint8_t *addr, const size_t length,
for (size_t i = 0, j = 0; i < string_table_size;) {
assert_true(j <= 0xFF);
if (j == name_index) {
XEIGNORE(xestrcpya(library->name, XECOUNT(library->name),
string_table + i));
xestrcpya(library->name, XECOUNT(library->name),
string_table + i);
break;
}
if (string_table[i] == 0) {
@ -481,7 +482,7 @@ void mspack_memory_close(mspack_memory_file *file) {
int mspack_memory_read(struct mspack_file *file, void *buffer, int chars) {
mspack_memory_file *memfile = (mspack_memory_file*)file;
const off_t remaining = memfile->buffer_size - memfile->offset;
const off_t total = MIN(chars, remaining);
const off_t total = std::min(static_cast<off_t>(chars), remaining);
if (xe_copy_memory(buffer, total,
(uint8_t*)memfile->buffer + memfile->offset, total)) {
return -1;
@ -492,7 +493,7 @@ int mspack_memory_read(struct mspack_file *file, void *buffer, int chars) {
int mspack_memory_write(struct mspack_file *file, void *buffer, int chars) {
mspack_memory_file *memfile = (mspack_memory_file*)file;
const off_t remaining = memfile->buffer_size - memfile->offset;
const off_t total = MIN(chars, remaining);
const off_t total = std::min(static_cast<off_t>(chars), remaining);
if (xe_copy_memory((uint8_t*)memfile->buffer + memfile->offset,
memfile->buffer_size - memfile->offset, buffer, total)) {
return -1;
@ -501,7 +502,6 @@ int mspack_memory_write(struct mspack_file *file, void *buffer, int chars) {
return (int)total;
}
void *mspack_memory_alloc(struct mspack_system *sys, size_t chars) {
XEUNREFERENCED(sys);
return xe_calloc(chars);
}
void mspack_memory_free(void *ptr) {
@ -876,7 +876,7 @@ int xe_xex2_load_pe(xe_xex2_ref xex) {
for (size_t n = 0; n < filehdr->NumberOfSections; n++, sechdr++) {
const size_t physical_address = opthdr->ImageBase + sechdr->VirtualAddress;
upper_address =
MAX(upper_address, physical_address + sechdr->Misc.VirtualSize);
std::max(upper_address, physical_address + sechdr->Misc.VirtualSize);
}
// Setup/load sections.

View File

@ -74,7 +74,7 @@ void xe_log_line(const char* file_path, const uint32_t line_number,
#if 0// defined(OutputDebugString)
OutputDebugStringA(buffer);
#else
XEIGNORE(fprintf(stdout, buffer));
fprintf(stdout, buffer);
fflush(stdout);
#endif // OutputDebugString
if (!FLAGS_fast_stdout) {
@ -99,7 +99,7 @@ void xe_handle_fatal(
#if defined(OutputDebugString)
OutputDebugStringA(buffer);
#else
XEIGNORE(fprintf(stderr, buffer));
fprintf(stderr, buffer);
fflush(stderr);
#endif // OutputDebugString
if (!FLAGS_fast_stdout) {

View File

@ -18,8 +18,6 @@
#define XE_EMPTY_MACRO do { } while(0)
#define XEUNREFERENCED(expr) (void)(expr)
#define XEDECLARECLASS1(ns1, name) \
namespace ns1 { class name; }
#define XEDECLARECLASS2(ns1, ns2, name) \
@ -35,28 +33,6 @@
class name; \
} } } }
#if XE_COMPILER_MSVC
#define XEASSUME(expr) __analysis_assume(expr)
#else
#define XEASSUME(expr)
#endif // MSVC
#if XE_COMPILER_MSVC
#define XECDECL __cdecl
#else
#define XECDECL
#endif // MSVC
#if defined(__cplusplus)
#define XEEXTERNC extern "C"
#define XEEXTERNC_BEGIN extern "C" {
#define XEEXTERNC_END }
#else
#define XEEXTERNC extern
#define XEEXTERNC_BEGIN
#define XEEXTERNC_END
#endif // __cplusplus
#if XE_COMPILER_MSVC
// http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
#define XEFORCEINLINE static __forceinline
@ -115,21 +91,6 @@ typedef XECACHEALIGN volatile void xe_aligned_void_t;
#define XECOUNT(array) (sizeof(array) / sizeof(array[0]))
#endif // MSVC
#if !defined(MIN)
#if XE_COMPILER_GNUC
#define MIN(A, B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); (__a < __b) ? __a : __b; })
#define MAX(A, B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); (__a < __b) ? __b : __a; })
//#elif XE_COMPILER_MSVC
// TODO(benvanik): experiment with decltype:
// http://msdn.microsoft.com/en-us/library/dd537655.aspx
#else
// NOTE: this implementation will evaluate the arguments twice - may be worth
// writing an inline function instead.
#define MIN(A, B) ( ((A) < (B)) ? (A) : (B) )
#define MAX(A, B) ( ((A) < (B)) ? (B) : (A) )
#endif // GNUC
#endif // !MIN
XEFORCEINLINE size_t hash_combine(size_t seed) {
return seed;
}
@ -153,7 +114,6 @@ static inline uint32_t XENEXTPOW2(uint32_t v) {
}
#define XEALIGN(value, align) ((value + align - 1) & ~(align - 1))
#define XESUCCEED() goto XECLEANUP
#define XEFAIL() goto XECLEANUP
#define XEEXPECT(expr) if (!(expr) ) { goto XECLEANUP; }
#define XEEXPECTTRUE(expr) if (!(expr) ) { goto XECLEANUP; }
@ -162,7 +122,6 @@ static inline uint32_t XENEXTPOW2(uint32_t v) {
#define XEEXPECTNOTZERO(expr) if ( (expr) == 0 ) { goto XECLEANUP; }
#define XEEXPECTNULL(expr) if ( (expr) != NULL ) { goto XECLEANUP; }
#define XEEXPECTNOTNULL(expr) if ( (expr) == NULL ) { goto XECLEANUP; }
#define XEIGNORE(expr) do { (void)(expr); } while(0)
#endif // XENIA_TYPES_H_

View File

@ -169,7 +169,7 @@ bool Win32Window::set_title(const std::wstring& title) {
if (!Window::set_title(title)) {
return false;
}
XEIGNORE(SetWindowText(handle_, title.c_str()));
SetWindowText(handle_, title.c_str());
return true;
}