Ask HN: Detecting All Zero or All One Memory

1 points by jadedhacker ↗ HN
I had a bit of a kooky idea. I was working on an algorithm that worked differently if there were any zeros in an array and I was wondering if there was an efficient way to do it without iterating over all the elements in it.

One concept that occurred to me is that a section of memory that's all zeros or all ones would have a characteristic voltage signature. Anything in between would be somewhere in the middle, but nebulously so (since you'd be adding bits in a commutative way). So this instruction would say something like 0 if the section of memory is all zeros, 1 if it's all ones, and -1 if the voltage is intermediate.

Is this concept technically workable and has it been done before on some chip? I imagine hardware engineers use tricks like this all the time, but I haven't heard of a software instruction that does this. The closest thing I found was the C library function memcmp, though it handles arbitrary patterns so it probably doesn't take advantage of a trick like this.

Thanks for your feedback. :)

0 comments

[ 4.7 ms ] story [ 9.3 ms ] thread

No comments yet.