Skip to content

Commit

Permalink
Vectorized fletcher_4 must be 64-bit aligned
Browse files Browse the repository at this point in the history
The fletcher_4_native() and fletcher_4_byteswap() functions may only
safely use the vectorized implementations when the buffer is 128-bit
aligned.  This is because both the AVX2 and SSE implementations process
four 32-bit words per iterations.  Fallback to the scalar implementation
which only processes a single 32-bit word for unaligned buffers.

Signed-off-by: Brian Behlendorf <[email protected]>
Issue openzfs#4330
  • Loading branch information
behlendorf committed Jun 28, 2016
1 parent d1d19c7 commit 832fe89
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions module/zcommon/zfs_fletcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,12 @@ fletcher_4_impl_get(void)
void
fletcher_4_native(const void *buf, uint64_t size, zio_cksum_t *zcp)
{
const fletcher_4_ops_t *ops = fletcher_4_impl_get();
const fletcher_4_ops_t *ops;

if (IS_P2ALIGNED(size, 4 * sizeof (uint32_t)))
ops = fletcher_4_impl_get();
else
ops = &fletcher_4_scalar_ops;

ops->init(zcp);
ops->compute(buf, size, zcp);
Expand All @@ -345,7 +350,12 @@ fletcher_4_native(const void *buf, uint64_t size, zio_cksum_t *zcp)
void
fletcher_4_byteswap(const void *buf, uint64_t size, zio_cksum_t *zcp)
{
const fletcher_4_ops_t *ops = fletcher_4_impl_get();
const fletcher_4_ops_t *ops;

if (IS_P2ALIGNED(size, 4 * sizeof (uint32_t)))
ops = fletcher_4_impl_get();
else
ops = &fletcher_4_scalar_ops;

ops->init(zcp);
ops->compute_byteswap(buf, size, zcp);
Expand Down

0 comments on commit 832fe89

Please sign in to comment.