]>
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 | |
1d3ba0bf | 9 | * or https://opensource.org/licenses/CDDL-1.0. |
428870ff BB |
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 | |
739cfb96 | 30 | #define _ZFS_FLETCHER_H extern __attribute__((visibility("default"))) |
428870ff BB |
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 | */ |
739cfb96 AZ |
51 | _ZFS_FLETCHER_H void fletcher_init(zio_cksum_t *); |
52 | _ZFS_FLETCHER_H void fletcher_2_native(const void *, uint64_t, const void *, | |
53 | zio_cksum_t *); | |
54 | _ZFS_FLETCHER_H void fletcher_2_byteswap(const void *, uint64_t, const void *, | |
55 | zio_cksum_t *); | |
56 | _ZFS_FLETCHER_H void fletcher_4_native(const void *, uint64_t, const void *, | |
57 | zio_cksum_t *); | |
58 | _ZFS_FLETCHER_H int fletcher_2_incremental_native(void *, size_t, void *); | |
59 | _ZFS_FLETCHER_H int fletcher_2_incremental_byteswap(void *, size_t, void *); | |
60 | _ZFS_FLETCHER_H void fletcher_4_native_varsize(const void *, uint64_t, | |
61 | zio_cksum_t *); | |
62 | _ZFS_FLETCHER_H void fletcher_4_byteswap(const void *, uint64_t, const void *, | |
63 | zio_cksum_t *); | |
64 | _ZFS_FLETCHER_H int fletcher_4_incremental_native(void *, size_t, void *); | |
65 | _ZFS_FLETCHER_H int fletcher_4_incremental_byteswap(void *, size_t, void *); | |
66 | _ZFS_FLETCHER_H int fletcher_4_impl_set(const char *selector); | |
67 | _ZFS_FLETCHER_H void fletcher_4_init(void); | |
68 | _ZFS_FLETCHER_H void fletcher_4_fini(void); | |
1eeb4562 | 69 | |
fc897b24 | 70 | |
5bf703b8 GN |
71 | |
72 | /* Internal fletcher ctx */ | |
73 | ||
7f319493 RD |
74 | typedef struct zfs_fletcher_superscalar { |
75 | uint64_t v[4]; | |
76 | } zfs_fletcher_superscalar_t; | |
77 | ||
5bf703b8 | 78 | typedef struct zfs_fletcher_sse { |
0ad5f434 | 79 | uint64_t v[2]; |
5bf703b8 GN |
80 | } zfs_fletcher_sse_t; |
81 | ||
82 | typedef struct zfs_fletcher_avx { | |
0ad5f434 | 83 | uint64_t v[4]; |
5bf703b8 GN |
84 | } zfs_fletcher_avx_t; |
85 | ||
86 | typedef struct zfs_fletcher_avx512 { | |
0ad5f434 | 87 | uint64_t v[8]; |
5bf703b8 GN |
88 | } zfs_fletcher_avx512_t; |
89 | ||
24cdeaf1 | 90 | typedef struct zfs_fletcher_aarch64_neon { |
0ad5f434 | 91 | uint64_t v[2]; |
24cdeaf1 RD |
92 | } zfs_fletcher_aarch64_neon_t; |
93 | ||
5bf703b8 GN |
94 | |
95 | typedef union fletcher_4_ctx { | |
96 | zio_cksum_t scalar; | |
7f319493 | 97 | zfs_fletcher_superscalar_t superscalar[4]; |
5bf703b8 GN |
98 | |
99 | #if defined(HAVE_SSE2) || (defined(HAVE_SSE2) && defined(HAVE_SSSE3)) | |
100 | zfs_fletcher_sse_t sse[4]; | |
101 | #endif | |
102 | #if defined(HAVE_AVX) && defined(HAVE_AVX2) | |
103 | zfs_fletcher_avx_t avx[4]; | |
104 | #endif | |
105 | #if defined(__x86_64) && defined(HAVE_AVX512F) | |
106 | zfs_fletcher_avx512_t avx512[4]; | |
107 | #endif | |
24cdeaf1 RD |
108 | #if defined(__aarch64__) |
109 | zfs_fletcher_aarch64_neon_t aarch64_neon[4]; | |
110 | #endif | |
5bf703b8 GN |
111 | } fletcher_4_ctx_t; |
112 | ||
1eeb4562 JX |
113 | /* |
114 | * fletcher checksum struct | |
115 | */ | |
5bf703b8 GN |
116 | typedef void (*fletcher_4_init_f)(fletcher_4_ctx_t *); |
117 | typedef void (*fletcher_4_fini_f)(fletcher_4_ctx_t *, zio_cksum_t *); | |
118 | typedef void (*fletcher_4_compute_f)(fletcher_4_ctx_t *, | |
119 | const void *, uint64_t); | |
fc897b24 | 120 | |
1eeb4562 | 121 | typedef struct fletcher_4_func { |
fc897b24 GN |
122 | fletcher_4_init_f init_native; |
123 | fletcher_4_fini_f fini_native; | |
124 | fletcher_4_compute_f compute_native; | |
125 | fletcher_4_init_f init_byteswap; | |
126 | fletcher_4_fini_f fini_byteswap; | |
127 | fletcher_4_compute_f compute_byteswap; | |
1eeb4562 | 128 | boolean_t (*valid)(void); |
78289b84 | 129 | boolean_t uses_fpu; |
1eeb4562 | 130 | const char *name; |
78289b84 | 131 | } __attribute__((aligned(64))) fletcher_4_ops_t; |
1eeb4562 | 132 | |
739cfb96 AZ |
133 | _ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_superscalar_ops; |
134 | _ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_superscalar4_ops; | |
5bf703b8 | 135 | |
35a76a03 | 136 | #if defined(HAVE_SSE2) |
739cfb96 | 137 | _ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_sse2_ops; |
35a76a03 TS |
138 | #endif |
139 | ||
140 | #if defined(HAVE_SSE2) && defined(HAVE_SSSE3) | |
739cfb96 | 141 | _ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_ssse3_ops; |
35a76a03 TS |
142 | #endif |
143 | ||
1eeb4562 | 144 | #if defined(HAVE_AVX) && defined(HAVE_AVX2) |
739cfb96 | 145 | _ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_avx2_ops; |
1eeb4562 | 146 | #endif |
428870ff | 147 | |
70b258fc | 148 | #if defined(__x86_64) && defined(HAVE_AVX512F) |
739cfb96 | 149 | _ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_avx512f_ops; |
70b258fc GN |
150 | #endif |
151 | ||
0b2a6423 | 152 | #if defined(__x86_64) && defined(HAVE_AVX512BW) |
739cfb96 | 153 | _ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_avx512bw_ops; |
0b2a6423 RD |
154 | #endif |
155 | ||
24cdeaf1 | 156 | #if defined(__aarch64__) |
739cfb96 | 157 | _ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_aarch64_neon_ops; |
24cdeaf1 RD |
158 | #endif |
159 | ||
428870ff BB |
160 | #ifdef __cplusplus |
161 | } | |
162 | #endif | |
163 | ||
164 | #endif /* _ZFS_FLETCHER_H */ |