Skip to content

Commit

Permalink
Enable most warnings in GCC
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekotekina committed May 10, 2019
1 parent 7492f33 commit 5d33d9a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 10 deletions.
33 changes: 26 additions & 7 deletions Utilities/types.h
Expand Up @@ -10,6 +10,7 @@

#include <cstdint>
#include <cstddef>
#include <cstring>
#include <type_traits>
#include <utility>
#include <chrono>
Expand Down Expand Up @@ -365,6 +366,9 @@ struct alignas(16) s128
CHECK_SIZE_ALIGN(u128, 16, 16);
CHECK_SIZE_ALIGN(s128, 16, 16);

using f32 = float;
using f64 = double;

union alignas(2) f16
{
u16 _u16;
Expand All @@ -375,22 +379,28 @@ union alignas(2) f16
_u16 = raw;
}

explicit operator float() const
explicit operator f32() const
{
// See http://stackoverflow.com/a/26779139
// The conversion doesn't handle NaN/Inf
u32 raw = ((_u16 & 0x8000) << 16) | // Sign (just moved)
(((_u16 & 0x7c00) + 0x1C000) << 13) | // Exponent ( exp - 15 + 127)
((_u16 & 0x03FF) << 13); // Mantissa
return (float&)raw;

union
{
char data[4];
u32 data32;
f32 res;
};

data32 = raw;
return res;
}
};

CHECK_SIZE_ALIGN(f16, 2, 2);

using f32 = float;
using f64 = double;

template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>>
constexpr T align(const T& value, ullong align)
{
Expand All @@ -400,12 +410,21 @@ constexpr T align(const T& value, ullong align)
template <typename T, typename T2>
inline u32 offset32(T T2::*const mptr)
{
union
{
char data[sizeof(std::size_t)];
std::size_t data_;
u32 data32;
};

#ifdef _MSC_VER
static_assert(sizeof(mptr) == sizeof(u32), "Invalid pointer-to-member size");
return reinterpret_cast<const u32&>(mptr);
std::memcpy(data, &mptr, sizeof(u32));
return data32;
#elif __GNUG__
static_assert(sizeof(mptr) == sizeof(std::size_t), "Invalid pointer-to-member size");
return static_cast<u32>(reinterpret_cast<const std::size_t&>(mptr));
std::memcpy(data, &mptr, sizeof(std::size_t));
return data_;
#else
static_assert(sizeof(mptr) == 0, "Invalid pointer-to-member size");
#endif
Expand Down
10 changes: 9 additions & 1 deletion rpcs3/Emu/Cell/Common.h
Expand Up @@ -12,5 +12,13 @@ enum FPSCR_RN
// Get the exponent of a float
inline int fexpf(float x)
{
return ((u32&)x >> 23) & 0xFF;
union
{
char data[4];
u32 data32;
float arg;
};

arg = x;
return (data32 >> 23) & 0xFF;
}
1 change: 1 addition & 0 deletions rpcs3/Emu/Cell/PPUInterpreter.cpp
Expand Up @@ -3,6 +3,7 @@
#include "PPUThread.h"
#include "PPUInterpreter.h"
#include "Utilities/asm.h"
#include "Emu/Cell/Common.h"

#include <cmath>

Expand Down
1 change: 0 additions & 1 deletion rpcs3/Emu/Cell/PPUThread.h
@@ -1,6 +1,5 @@
#pragma once

#include "Common.h"
#include "../CPU/CPUThread.h"
#include "../Memory/vm.h"
#include "Utilities/lockless.h"
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/Cell/SPUInterpreter.cpp
Expand Up @@ -6,6 +6,7 @@
#include "Utilities/asm.h"
#include "SPUThread.h"
#include "SPUInterpreter.h"
#include "Emu/Cell/Common.h"

#include <cmath>
#include <cfenv>
Expand Down
1 change: 0 additions & 1 deletion rpcs3/Emu/Cell/SPUThread.h
@@ -1,6 +1,5 @@
#pragma once

#include "Emu/Cell/Common.h"
#include "Emu/CPU/CPUThread.h"
#include "Emu/Cell/SPUInterpreter.h"
#include "Emu/Memory/vm.h"
Expand Down
3 changes: 3 additions & 0 deletions rpcs3/cmake_modules/ConfigureCompiler.cmake
Expand Up @@ -9,7 +9,9 @@ if(CMAKE_COMPILER_IS_GNUCXX)
# Set compiler options here

# Warnings
add_compile_options(-Wall)
add_compile_options(-Wno-attributes -Wno-enum-compare -Wno-invalid-offsetof)
add_compile_options(-Wno-unknown-pragmas -Wno-unused-variable -Wno-reorder -Wno-comment)

elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
# Clang 5.0 or latter is required
Expand All @@ -20,6 +22,7 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
# Set compiler options here

add_compile_options(-ftemplate-depth=1024)
add_compile_options(-Wunused-value -Wunused-comparison)
if(APPLE)
add_compile_options(-stdlib=libc++)
endif()
Expand Down

0 comments on commit 5d33d9a

Please sign in to comment.