WojciechMula / toys

Storage for my snippets, toy programs, etc.
BSD 2-Clause "Simplified" License
316 stars 38 forks source link

The code fails for test cases with non-zero bits in other positions #1

Closed quickfur closed 9 years ago

quickfur commented 9 years ago

Example: movmask(0x7f7f7f7f) (binary 01111111011111110111111101111111) should return 0x00 (upper bit of each byte in input is 0) but it returns 0xff instead.

Solution: mask out the irrelevant bits before performing the multiplication:

const uint64_t result = (uint64_t)(input & 0x80808080) * mult;

This now produces the correct result in all cases.

WojciechMula commented 9 years ago

You are right, thank you for reporting this issue. There are assertions in demo.c & proof.py that enforce bit layout of input word, but it must be also included in the main procedure.

WojciechMula commented 9 years ago

Fixed in b68de8fad45939ef1770724abad2e479ab5f4ed7