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

Workaround for a gcc7 compiler bug #50

Merged
merged 1 commit into from
May 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions nall/bit.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#ifndef NALL_BIT_HPP
#define NALL_BIT_HPP

// workaround for an infinite loop compiler bug in gcc7
// https://github.com/libretro/bsnes-mercury/issues/47
#if defined(PROFILE_ACCURACY)
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif

#include <nall/stdint.hpp>

namespace nall {
Expand All @@ -10,11 +16,24 @@ template<unsigned bits> inline uintmax_t uclamp(const uintmax_t x) {
return y + ((x - y) & -(x < y)); //min(x, y);
}

#if defined(PROFILE_ACCURACY)
#if GCC_VERSION > 70000
#pragma GCC push_options
#pragma GCC optimize ("no-strict-aliasing")
#endif
#endif

template<unsigned bits> inline uintmax_t uclip(const uintmax_t x) {
enum : uintmax_t { b = 1ull << (bits - 1), m = b * 2 - 1 };
return (x & m);
}

#if defined(PROFILE_ACCURACY)
#if GCC_VERSION > 70000
#pragma GCC pop_options
#endif
#endif

template<unsigned bits> inline intmax_t sclamp(const intmax_t x) {
enum : intmax_t { b = 1ull << (bits - 1), m = b - 1 };
return (x > m) ? m : (x < -b) ? -b : x;
Expand Down