nukeykt / Nuked-OPN2

Cycle-accurate Yamaha YM3438(YM2612) emulator
GNU Lesser General Public License v2.1
219 stars 15 forks source link

Eliminate some shifting of signed integers. #20

Closed Clownacy closed 2 years ago

Clownacy commented 2 years ago

In C, shifting a signed integer does not have standard well-defined behaviour: right-shifting could 'shift in' a copy of the sign bit, or it could not.

https://stackoverflow.com/questions/4009885/arithmetic-bit-shift-on-a-signed-integer

Shifting signed integers is used in at least two places in the codebase in order to perform sign-extension. To avoid the use of shifting, sign extension is now instead achieved with two ANDs and a subtraction. The behaviour of this logic should be consistent across all platforms, improving this library's portability.

nukeykt commented 2 years ago

looks good, thanks :)