Subtracting packed 8-bit integers in an 64-bit integer by 1 in parallel, SWAR without hardware SIMD

If you have a CPU with efficient SIMD instructions, SSE/MMX paddb (_mm_add_epi8) is also viable. Peter Cordes’ answer also describes GNU C (gcc/clang) vector syntax, and safety for strict-aliasing UB. I strongly encourage reviewing that answer as well. Doing it yourself with uint64_t is fully portable, but still requires care to avoid alignment problems and … Read more

Have you ever had to use bit shifting in real projects? [closed]

I still write code for systems that do not have floating point support in hardware. In these systems you need bit-shifting for nearly all your arithmetic. Also you need shifts to generate hashes. Polynomial arithmetic (CRC, Reed-Solomon Codes are the mainstream applications) or uses shifts as well. However, shifts are just used because they are … Read more

Efficiently find binary strings with low Hamming distance in large set

Question: What do we know about the Hamming distance d(x,y)? Answer: It is non-negative: d(x,y) ≥ 0 It is only zero for identical inputs: d(x,y) = 0 ⇔ x = y It is symmetric: d(x,y) = d(y,x) It obeys the triangle inequality, d(x,z) ≤ d(x,y) + d(y,z) Question: Why do we care? Answer: Because it … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)