Gameboy, some random tidy ups.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon
2018-05-02 02:47:47 +01:00
parent 9de0f597f6
commit 0b2c1fa084
9 changed files with 50 additions and 45 deletions
+14 -10
View File
@@ -15,20 +15,24 @@ namespace EightBit {
void assume(int expression);
}
/*
Published in 1988, the C Programming Language 2nd Ed.
(by Brian W.Kernighan and Dennis M.Ritchie) mentions
this in exercise 2 - 9. On April 19, 2006 Don Knuth pointed
out to me that this method "was first published by Peter
Wegner in CACM 3 (1960), 322.
(Also discovered independently by Derrick Lehmer and published
in 1964 in a book edited by Beckenbach.)"
*/
inline int EightBit::countBits(uint8_t value) {
#ifdef _MSC_VER
return __popcnt(value);
#else
/*
Published in 1988, the C Programming Language 2nd Ed.
(by Brian W.Kernighan and Dennis M.Ritchie) mentions
this in exercise 2 - 9. On April 19, 2006 Don Knuth pointed
out to me that this method "was first published by Peter
Wegner in CACM 3 (1960), 322.
(Also discovered independently by Derrick Lehmer and published
in 1964 in a book edited by Beckenbach.)"
*/
int count; // c accumulates the total bits set in value
for (count = 0; value; ++count)
value &= value - 1; // clear the least significant bit set
return count;
#endif
}
inline bool EightBit::oddParity(uint8_t value) {
@@ -66,7 +70,7 @@ inline void EightBit::assume(int expression) {
# define LIKELY(x) (x)
# define UNLIKELY(x) (x)
# define PARITY(x) (__popcnt(x) % 2)
# define PARITY(x) EightBit::oddParity(x);
# define UNREACHABLE ASSUME(0)