]>
Commit | Line | Data |
---|---|---|
428870ff BB |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
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. | |
7 | * | |
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. | |
12 | * | |
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] | |
18 | * | |
19 | * CDDL HEADER END | |
20 | */ | |
21 | /* | |
22 | * Copyright 2009 Sun Microsystems, Inc. All rights reserved. | |
23 | * Use is subject to license terms. | |
24 | */ | |
3c67d83a TH |
25 | /* |
26 | * Copyright 2013 Saso Kiselkov. All rights reserved. | |
27 | */ | |
428870ff BB |
28 | |
29 | #ifndef _ZFS_FLETCHER_H | |
30 | #define _ZFS_FLETCHER_H | |
31 | ||
32 | #include <sys/types.h> | |
1eeb4562 | 33 | #include <sys/spa_checksum.h> |
428870ff BB |
34 | |
35 | #ifdef __cplusplus | |
36 | extern "C" { | |
37 | #endif | |
38 | ||
39 | /* | |
40 | * fletcher checksum functions | |
fc897b24 GN |
41 | * |
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 | |
49 | * the data buffer. | |
428870ff | 50 | */ |
a6255b7f | 51 | void fletcher_init(zio_cksum_t *); |
3c67d83a TH |
52 | void fletcher_2_native(const void *, uint64_t, const void *, zio_cksum_t *); |
53 | void fletcher_2_byteswap(const void *, uint64_t, const void *, zio_cksum_t *); | |
54 | void fletcher_4_native(const void *, uint64_t, const void *, zio_cksum_t *); | |
a6255b7f DQ |
55 | int fletcher_2_incremental_native(void *, size_t, void *); |
56 | int fletcher_2_incremental_byteswap(void *, size_t, void *); | |
fc897b24 | 57 | void fletcher_4_native_varsize(const void *, uint64_t, zio_cksum_t *); |
3c67d83a | 58 | void fletcher_4_byteswap(const void *, uint64_t, const void *, zio_cksum_t *); |
a6255b7f DQ |
59 | int fletcher_4_incremental_native(void *, size_t, void *); |
60 | int fletcher_4_incremental_byteswap(void *, size_t, void *); | |
1eeb4562 JX |
61 | int fletcher_4_impl_set(const char *selector); |
62 | void fletcher_4_init(void); | |
63 | void fletcher_4_fini(void); | |
64 | ||
fc897b24 | 65 | |
5bf703b8 GN |
66 | |
67 | /* Internal fletcher ctx */ | |
68 | ||
7f319493 RD |
69 | typedef struct zfs_fletcher_superscalar { |
70 | uint64_t v[4]; | |
71 | } zfs_fletcher_superscalar_t; | |
72 | ||
5bf703b8 GN |
73 | typedef struct zfs_fletcher_sse { |
74 | uint64_t v[2] __attribute__((aligned(16))); | |
75 | } zfs_fletcher_sse_t; | |
76 | ||
77 | typedef struct zfs_fletcher_avx { | |
78 | uint64_t v[4] __attribute__((aligned(32))); | |
79 | } zfs_fletcher_avx_t; | |
80 | ||
81 | typedef struct zfs_fletcher_avx512 { | |
82 | uint64_t v[8] __attribute__((aligned(64))); | |
83 | } zfs_fletcher_avx512_t; | |
84 | ||
24cdeaf1 RD |
85 | typedef struct zfs_fletcher_aarch64_neon { |
86 | uint64_t v[2] __attribute__((aligned(16))); | |
87 | } zfs_fletcher_aarch64_neon_t; | |
88 | ||
5bf703b8 GN |
89 | |
90 | typedef union fletcher_4_ctx { | |
91 | zio_cksum_t scalar; | |
7f319493 | 92 | zfs_fletcher_superscalar_t superscalar[4]; |
5bf703b8 GN |
93 | |
94 | #if defined(HAVE_SSE2) || (defined(HAVE_SSE2) && defined(HAVE_SSSE3)) | |
95 | zfs_fletcher_sse_t sse[4]; | |
96 | #endif | |
97 | #if defined(HAVE_AVX) && defined(HAVE_AVX2) | |
98 | zfs_fletcher_avx_t avx[4]; | |
99 | #endif | |
100 | #if defined(__x86_64) && defined(HAVE_AVX512F) | |
101 | zfs_fletcher_avx512_t avx512[4]; | |
102 | #endif | |
24cdeaf1 RD |
103 | #if defined(__aarch64__) |
104 | zfs_fletcher_aarch64_neon_t aarch64_neon[4]; | |
105 | #endif | |
5bf703b8 GN |
106 | } fletcher_4_ctx_t; |
107 | ||
1eeb4562 JX |
108 | /* |
109 | * fletcher checksum struct | |
110 | */ | |
5bf703b8 GN |
111 | typedef void (*fletcher_4_init_f)(fletcher_4_ctx_t *); |
112 | typedef void (*fletcher_4_fini_f)(fletcher_4_ctx_t *, zio_cksum_t *); | |
113 | typedef void (*fletcher_4_compute_f)(fletcher_4_ctx_t *, | |
114 | const void *, uint64_t); | |
fc897b24 | 115 | |
1eeb4562 | 116 | typedef struct fletcher_4_func { |
fc897b24 GN |
117 | fletcher_4_init_f init_native; |
118 | fletcher_4_fini_f fini_native; | |
119 | fletcher_4_compute_f compute_native; | |
120 | fletcher_4_init_f init_byteswap; | |
121 | fletcher_4_fini_f fini_byteswap; | |
122 | fletcher_4_compute_f compute_byteswap; | |
1eeb4562 JX |
123 | boolean_t (*valid)(void); |
124 | const char *name; | |
125 | } fletcher_4_ops_t; | |
126 | ||
7f319493 RD |
127 | extern const fletcher_4_ops_t fletcher_4_superscalar_ops; |
128 | extern const fletcher_4_ops_t fletcher_4_superscalar4_ops; | |
5bf703b8 | 129 | |
35a76a03 TS |
130 | #if defined(HAVE_SSE2) |
131 | extern const fletcher_4_ops_t fletcher_4_sse2_ops; | |
132 | #endif | |
133 | ||
134 | #if defined(HAVE_SSE2) && defined(HAVE_SSSE3) | |
135 | extern const fletcher_4_ops_t fletcher_4_ssse3_ops; | |
136 | #endif | |
137 | ||
1eeb4562 JX |
138 | #if defined(HAVE_AVX) && defined(HAVE_AVX2) |
139 | extern const fletcher_4_ops_t fletcher_4_avx2_ops; | |
140 | #endif | |
428870ff | 141 | |
70b258fc GN |
142 | #if defined(__x86_64) && defined(HAVE_AVX512F) |
143 | extern const fletcher_4_ops_t fletcher_4_avx512f_ops; | |
144 | #endif | |
145 | ||
24cdeaf1 RD |
146 | #if defined(__aarch64__) |
147 | extern const fletcher_4_ops_t fletcher_4_aarch64_neon_ops; | |
148 | #endif | |
149 | ||
428870ff BB |
150 | #ifdef __cplusplus |
151 | } | |
152 | #endif | |
153 | ||
154 | #endif /* _ZFS_FLETCHER_H */ |