4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 * Copyright 2013 Saso Kiselkov. All rights reserved.
29 #ifndef _ZFS_FLETCHER_H
30 #define _ZFS_FLETCHER_H
32 #include <sys/types.h>
33 #include <sys/spa_checksum.h>
40 * fletcher checksum functions
42 * Note: Fletcher checksum methods expect buffer size to be 4B aligned. This
43 * limitation stems from the algorithm design. Performing incremental checksum
44 * without said alignment would yield different results. Therefore, the code
45 * includes assertions for the size alignment.
46 * For compatibility, it is required that some code paths calculate checksum of
47 * non-aligned buffer sizes. For this purpose, `fletcher_4_native_varsize()`
48 * checksum method is added. This method will ignore last (size % 4) bytes of
51 void fletcher_2_native(const void *, uint64_t, const void *, zio_cksum_t *);
52 void fletcher_2_byteswap(const void *, uint64_t, const void *, zio_cksum_t *);
53 void fletcher_4_native(const void *, uint64_t, const void *, zio_cksum_t *);
54 void fletcher_4_native_varsize(const void *, uint64_t, zio_cksum_t *);
55 void fletcher_4_byteswap(const void *, uint64_t, const void *, zio_cksum_t *);
56 void fletcher_4_incremental_native(const void *, uint64_t,
58 void fletcher_4_incremental_byteswap(const void *, uint64_t,
60 int fletcher_4_impl_set(const char *selector);
61 void fletcher_4_init(void);
62 void fletcher_4_fini(void);
66 /* Internal fletcher ctx */
68 typedef struct zfs_fletcher_sse {
69 uint64_t v[2] __attribute__((aligned(16)));
72 typedef struct zfs_fletcher_avx {
73 uint64_t v[4] __attribute__((aligned(32)));
76 typedef struct zfs_fletcher_avx512 {
77 uint64_t v[8] __attribute__((aligned(64)));
78 } zfs_fletcher_avx512_t;
81 typedef union fletcher_4_ctx {
84 #if defined(HAVE_SSE2) || (defined(HAVE_SSE2) && defined(HAVE_SSSE3))
85 zfs_fletcher_sse_t sse[4];
87 #if defined(HAVE_AVX) && defined(HAVE_AVX2)
88 zfs_fletcher_avx_t avx[4];
90 #if defined(__x86_64) && defined(HAVE_AVX512F)
91 zfs_fletcher_avx512_t avx512[4];
96 * fletcher checksum struct
98 typedef void (*fletcher_4_init_f)(fletcher_4_ctx_t *);
99 typedef void (*fletcher_4_fini_f)(fletcher_4_ctx_t *, zio_cksum_t *);
100 typedef void (*fletcher_4_compute_f)(fletcher_4_ctx_t *,
101 const void *, uint64_t);
103 typedef struct fletcher_4_func {
104 fletcher_4_init_f init_native;
105 fletcher_4_fini_f fini_native;
106 fletcher_4_compute_f compute_native;
107 fletcher_4_init_f init_byteswap;
108 fletcher_4_fini_f fini_byteswap;
109 fletcher_4_compute_f compute_byteswap;
110 boolean_t (*valid)(void);
115 #if defined(HAVE_SSE2)
116 extern const fletcher_4_ops_t fletcher_4_sse2_ops;
119 #if defined(HAVE_SSE2) && defined(HAVE_SSSE3)
120 extern const fletcher_4_ops_t fletcher_4_ssse3_ops;
123 #if defined(HAVE_AVX) && defined(HAVE_AVX2)
124 extern const fletcher_4_ops_t fletcher_4_avx2_ops;
127 #if defined(__x86_64) && defined(HAVE_AVX512F)
128 extern const fletcher_4_ops_t fletcher_4_avx512f_ops;
135 #endif /* _ZFS_FLETCHER_H */