BinaryAnalysisPlatform / bap

Binary Analysis Platform
MIT License
2.07k stars 273 forks source link

Reimplements x86 bitscan and popcnt #1416

Closed bmourad01 closed 2 years ago

bmourad01 commented 2 years ago

The previous implementation did a naive test of every single bit. This resulted in a giant chain Ite expressions, which is probably hard on SMT solvers and at the very least does not seem very readable to me.

This reimplements the lifting of bsr, bsf, lzcnt, tzcnt, and popcnt instructions based on the branchless algorithms described in Hacker's Delight, chapters 5-3 and 5-4:

http://index-of.es/Security/Addison%20Wesley%20-%20Hackers%20Delight%202002.pdf

as well as the efficient implementation of Hamming weight:

https://en.wikipedia.org/wiki/Hamming_weight#Efficient_implementation