Thread (102 messages) 102 messages, 22 authors, 2013-12-01

Re: Triple parity and beyond

From: "H. Peter Anvin" <hpa@zytor.com>
Date: 2013-11-20 21:06:51
Also in: linux-btrfs

On 11/20/2013 01:04 PM, Andrea Mazzoleni wrote:
Hi Peter,
quoted
quoted
static inline uint64_t d2_64(uint64_t v)
{
        uint64_t mask = v & 0x0101010101010101U;
        mask = (mask << 8) - mask;
(mask << 7) I assume...
No. It's "(mask << 8) - mask". We want to expand the bit at position 0
(in each byte) to the full byte, resulting in 0xFF if the bit is at 1,
and 0x00 if the bit is 0.

(0 << 8) - 0 = 0x00
(1 << 8) - 1 = 0x100 - 1 = 0xFF
Oh, right... it is the same as (v << 1) - (v >> 7) except everything is
shifted over one.

	-hpa

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help