Turning the diagrams into code was easy but the first exhaustive tests have shown some.... behaviour that I suspected but didn't find at first.
The principle of the popcount is to flip the whole word when not enough bits are set.
0 => 8 1 => 7 2 => 6 3 => 5
OK but what about 4 ?
Flipping the word when 4 bits are set will not change the number of set bits. So the only effect is to set the corresponding "flip" bit. There are a number of pros & cons about its activation.
- Defaulting to f=0 (no flip) means less activity, spectrum power is lower at high frequencies.
- f=1 would increase activity and potentially reduce droop.
- Since F could be either 1 or 0 without actual effect, it acts like a possible "return to neutral" bit and be occasionally "chosen" to favour a certain parity.
- OTOH 4 is fairly common and if/when the byte is altered, the "nevermind" value of f could reduce the rate of error detection, so it better be fixed in all cases.
- It is easier to just detect > 3 because the MSB is set for 4,5,6,7... and 8 is not representable in 3 bits. So I think that settles the issue.
Unfortunately it's more complex than that.
The code might have some bugs but already shows that
- 4 flips 15 times in 70 occurrences. Fine, no worries, though it could be better.
- 5 flips 20 times out of 56 !
31 : 00011111 : 5 : 1?0 : - 47 : 00101111 : 5 : 1?0 : - 55 : 00110111 : 5 : 1?0 : - 59 : 00111011 : 5 : 1?0 : - 79 : 01001111 : 5 : 1?0 : - 87 : 01010111 : 5 : 1?0 : - 91 : 01011011 : 5 : 1?0 : - 103 : 01100111 : 5 : 1?0 : - 107 : 01101011 : 5 : 1?0 : - 115 : 01110011 : 5 : 1?0 : - 143 : 10001111 : 5 : 1?0 : - 151 : 10010111 : 5 : 1?0 : - 155 : 10011011 : 5 : 1?0 : - 167 : 10100111 : 5 : 1?0 : - 171 : 10101011 : 5 : 1?0 : - 179 : 10110011 : 5 : 1?0 : - 199 : 11000111 : 5 : 1?0 : - 203 : 11001011 : 5 : 1?0 : - 211 : 11010011 : 5 : 1?0 : - 227 : 11100011 : 5 : 1?0 : -
That's ... a problem : this increases the max run length ! The common condition is MSB=11. If the word was not flipped, there would be the solution to combine the LSB and MSB (instead of two LSB) to bound the situation only to cases where a 1 delimits the start and end of the word. But it's not possible.
Apparently a better, precise popcount is required. I didn't know how to do it but it seems I have figured out a solution at last.
Yann Guidon / YGDES
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.