From da806bddcbff36577688dbd05a92c539b2da3398 Mon Sep 17 00:00:00 2001 From: "Adrian.Conlon" Date: Sun, 3 Sep 2017 21:30:46 +0100 Subject: [PATCH] Tidy some more Windows/Linux compatibility issues. Signed-off-by: Adrian.Conlon --- Intel8080/inc/Intel8080.h | 16 ++++------------ Intel8080/src/Intel8080.cpp | 28 ++++++++++++++-------------- Intel8080/src/stdafx.h | 2 -- inc/IntelProcessor.h | 3 --- inc/Processor.h | 6 +++++- inc/TestHarness.h | 6 +++--- src/stdafx.h | 8 +++----- 7 files changed, 29 insertions(+), 40 deletions(-) diff --git a/Intel8080/inc/Intel8080.h b/Intel8080/inc/Intel8080.h index 18986b9..dd640bd 100644 --- a/Intel8080/inc/Intel8080.h +++ b/Intel8080/inc/Intel8080.h @@ -46,8 +46,6 @@ namespace EightBit { register16_t hl; uint8_t R(int r) { - __assume(r < 8); - __assume(r >= 0); switch (r) { case 0b000: return B(); @@ -66,14 +64,12 @@ namespace EightBit { case 0b111: return A(); default: - __assume(0); + UNREACHABLE; } throw std::logic_error("Unhandled registry mechanism"); } void R(int r, uint8_t value) { - __assume(r < 8); - __assume(r >= 0); switch (r) { case 0b000: B() = value; @@ -100,13 +96,11 @@ namespace EightBit { A() = value; break; default: - __assume(0); + UNREACHABLE; } } register16_t& RP(int rp) { - __assume(rp < 4); - __assume(rp >= 0); switch (rp) { case 0b00: return BC(); @@ -117,13 +111,11 @@ namespace EightBit { case 0b11: return SP(); default: - __assume(0); + UNREACHABLE; } } register16_t& RP2(int rp) { - __assume(rp < 4); - __assume(rp >= 0); switch (rp) { case 0b00: return BC(); @@ -134,7 +126,7 @@ namespace EightBit { case 0b11: return AF(); default: - __assume(0); + UNREACHABLE; } } diff --git a/Intel8080/src/Intel8080.cpp b/Intel8080/src/Intel8080.cpp index 9047a78..1933724 100644 --- a/Intel8080/src/Intel8080.cpp +++ b/Intel8080/src/Intel8080.cpp @@ -57,7 +57,7 @@ bool EightBit::Intel8080::jumpConditionalFlag(uint8_t& f, int flag) { case 7: // M return jumpConditional(f & SF); default: - __assume(0); + UNREACHABLE; } throw std::logic_error("Unhandled JP conditional"); } @@ -81,7 +81,7 @@ bool EightBit::Intel8080::returnConditionalFlag(uint8_t& f, int flag) { case 7: // M return returnConditional(f & SF); default: - __assume(0); + UNREACHABLE; } throw std::logic_error("Unhandled RET conditional"); } @@ -105,7 +105,7 @@ bool EightBit::Intel8080::callConditionalFlag(uint8_t& f, int flag) { case 7: // M return callConditional(f & SF); default: - __assume(0); + UNREACHABLE; } throw std::logic_error("Unhandled CALL conditional"); } @@ -317,7 +317,7 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) { cycles += 13; break; default: - __assume(0); + UNREACHABLE; } break; case 1: @@ -346,11 +346,11 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) { cycles += 13; break; default: - __assume(0); + UNREACHABLE; } break; default: - __assume(0); + UNREACHABLE; } break; case 3: // 16-bit INC/DEC @@ -362,7 +362,7 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) { --RP(p).word; break; default: - __assume(0); + UNREACHABLE; } cycles += 6; break; @@ -413,12 +413,12 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) { cmc(a, f); break; default: - __assume(0); + UNREACHABLE; } cycles += 4; break; default: - __assume(0); + UNREACHABLE; } break; case 1: // 8-bit loading @@ -458,7 +458,7 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) { compare(f, a, R(z)); break; default: - __assume(0); + UNREACHABLE; } cycles += 4; if (z == 6) @@ -494,7 +494,7 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) { } break; default: - __assume(0); + UNREACHABLE; } break; case 2: // Conditional jump @@ -555,7 +555,7 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) { } break; default: - __assume(0); + UNREACHABLE; } break; case 6: // Operate on accumulator and immediate operand: alu[y] n @@ -585,7 +585,7 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) { compare(f, a, fetchByte()); break; default: - __assume(0); + UNREACHABLE; } cycles += 7; break; @@ -594,7 +594,7 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) { cycles += 11; break; default: - __assume(0); + UNREACHABLE; } break; } diff --git a/Intel8080/src/stdafx.h b/Intel8080/src/stdafx.h index d77c746..414a1a4 100644 --- a/Intel8080/src/stdafx.h +++ b/Intel8080/src/stdafx.h @@ -1,6 +1,4 @@ -#ifdef _MSC_VER #pragma once -#endif #include #include diff --git a/inc/IntelProcessor.h b/inc/IntelProcessor.h index e33be19..48d9be2 100644 --- a/inc/IntelProcessor.h +++ b/inc/IntelProcessor.h @@ -98,19 +98,16 @@ namespace EightBit { // static int buildHalfCarryIndex(uint8_t before, uint8_t value, int calculation) { - __assume(calculation < 0x1ffff); return ((before & 0x88) >> 1) | ((value & 0x88) >> 2) | ((calculation & 0x88) >> 3); } static bool calculateHalfCarryAdd(uint8_t before, uint8_t value, int calculation) { - __assume(calculation < 0x1ffff); static std::array m_halfCarryTableAdd = { { false, false, true, false, true, false, true, true } }; auto index = buildHalfCarryIndex(before, value, calculation); return m_halfCarryTableAdd[index & Mask3]; } static bool calculateHalfCarrySub(uint8_t before, uint8_t value, int calculation) { - __assume(calculation < 0x1ffff); std::array m_halfCarryTableSub = { { false, true, true, true, false, false, false, true } }; auto index = buildHalfCarryIndex(before, value, calculation); return m_halfCarryTableSub[index & Mask3]; diff --git a/inc/Processor.h b/inc/Processor.h index 163899a..574a488 100644 --- a/inc/Processor.h +++ b/inc/Processor.h @@ -4,9 +4,13 @@ #include "Memory.h" +#ifdef _MSC_VER +# define UNREACHABLE __assume(0) +#endif + #ifdef __GNUG__ -# define __assume(cond) do { if (!(cond)) __builtin_unreachable(); } while (0) # define __popcnt __builtin_popcount +# define UNREACHABLE __builtin_unreachable(); #endif namespace EightBit { diff --git a/inc/TestHarness.h b/inc/TestHarness.h index f7e9095..1f4a388 100644 --- a/inc/TestHarness.h +++ b/inc/TestHarness.h @@ -4,10 +4,10 @@ #include #include -#ifdef __GNUG__ -#include -#else +#ifdef _MSC_VER #include +#else +#include #endif namespace EightBit { diff --git a/src/stdafx.h b/src/stdafx.h index 9d6547d..19d92f2 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -1,6 +1,4 @@ -#ifdef _MSC_VER #pragma once -#endif #include #include @@ -14,8 +12,8 @@ #include #include -#ifdef __GNUG__ -#include -#else +#ifdef _MSC_VER #include +#else +#include #endif