File tree Expand file tree Collapse file tree 2 files changed +18
-10
lines changed
Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -394,4 +394,21 @@ inline char printable( uint8_t x )
394394 } // wcslen
395395#endif
396396
397+ inline bool is_parity_even8 ( uint8_t x )
398+ {
399+ // use popcnt if possible. It's not available on the Q9650 and other older Intel CPUs. use fallback code below instead if needed.
400+
401+ #if defined( __GNUC__ ) || defined( __clang__ )
402+ return ( ! ( __builtin_popcount ( x ) & 1 ) );
403+ #elif defined( _MSC_VER )
404+ return ( ! ( __popcnt16 ( x ) & 1 ) );
405+ #elif defined( __aarch64__ )
406+ return ( ! ( std::bitset<8 >( x ).count () & 1 ) );
407+ #else
408+ x ^= ( x >> 4 );
409+ x ^= ( x >> 2 );
410+ x ^= ( x >> 1 );
411+ return ! ( x & 1 );
412+ #endif
413+ } // is_parity_even8
397414
Original file line number Diff line number Diff line change @@ -175,16 +175,7 @@ static uint16_t pcword() { uint16_t r = mword( reg.pc ); reg.pc += 2; return r;
175175static void pushword ( uint16_t val ) { reg.sp -= 2 ; setmword ( reg.sp , val ); }
176176static uint16_t popword () { uint16_t val = mword ( reg.sp ); reg.sp += 2 ; return val; }
177177
178- bool is_parity_even ( uint8_t x )
179- {
180- #if defined(_M_AMD64) && !defined(__GNUC__)
181- return ( ! ( __popcnt16 ( x ) & 1 ) ); // less portable, but faster
182- #else
183- return ( ! ( std::bitset<8 >( x ).count () & 1 ) );
184- #endif
185- } // is_parity_even
186-
187- void set_parity ( uint8_t x ) { reg.fParityEven_Overflow = is_parity_even ( x ); }
178+ void set_parity ( uint8_t x ) { reg.fParityEven_Overflow = is_parity_even8 ( x ); }
188179
189180void set_sign_zero ( uint8_t x )
190181{
You can’t perform that action at this time.
0 commit comments