2010-05-28 20:45:14 +00:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
2022-07-11 21:16:13 +00:00
|
|
|
* or https://opensource.org/licenses/CDDL-1.0.
|
2010-05-28 20:45:14 +00:00
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
|
|
|
|
* Use is subject to license terms.
|
|
|
|
*/
|
2016-06-15 22:47:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Saso Kiselkov. All rights reserved.
|
|
|
|
*/
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
#ifndef _ZFS_FLETCHER_H
|
2021-05-15 09:53:14 +00:00
|
|
|
#define _ZFS_FLETCHER_H extern __attribute__((visibility("default")))
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
2015-12-09 23:34:16 +00:00
|
|
|
#include <sys/spa_checksum.h>
|
2010-05-28 20:45:14 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fletcher checksum functions
|
2016-07-12 15:50:54 +00:00
|
|
|
*
|
|
|
|
* Note: Fletcher checksum methods expect buffer size to be 4B aligned. This
|
|
|
|
* limitation stems from the algorithm design. Performing incremental checksum
|
|
|
|
* without said alignment would yield different results. Therefore, the code
|
|
|
|
* includes assertions for the size alignment.
|
|
|
|
* For compatibility, it is required that some code paths calculate checksum of
|
|
|
|
* non-aligned buffer sizes. For this purpose, `fletcher_4_native_varsize()`
|
|
|
|
* checksum method is added. This method will ignore last (size % 4) bytes of
|
|
|
|
* the data buffer.
|
2010-05-28 20:45:14 +00:00
|
|
|
*/
|
2021-05-15 09:53:14 +00:00
|
|
|
_ZFS_FLETCHER_H void fletcher_init(zio_cksum_t *);
|
|
|
|
_ZFS_FLETCHER_H void fletcher_2_native(const void *, uint64_t, const void *,
|
|
|
|
zio_cksum_t *);
|
|
|
|
_ZFS_FLETCHER_H void fletcher_2_byteswap(const void *, uint64_t, const void *,
|
|
|
|
zio_cksum_t *);
|
|
|
|
_ZFS_FLETCHER_H void fletcher_4_native(const void *, uint64_t, const void *,
|
|
|
|
zio_cksum_t *);
|
|
|
|
_ZFS_FLETCHER_H int fletcher_2_incremental_native(void *, size_t, void *);
|
|
|
|
_ZFS_FLETCHER_H int fletcher_2_incremental_byteswap(void *, size_t, void *);
|
|
|
|
_ZFS_FLETCHER_H void fletcher_4_native_varsize(const void *, uint64_t,
|
|
|
|
zio_cksum_t *);
|
|
|
|
_ZFS_FLETCHER_H void fletcher_4_byteswap(const void *, uint64_t, const void *,
|
|
|
|
zio_cksum_t *);
|
|
|
|
_ZFS_FLETCHER_H int fletcher_4_incremental_native(void *, size_t, void *);
|
|
|
|
_ZFS_FLETCHER_H int fletcher_4_incremental_byteswap(void *, size_t, void *);
|
|
|
|
_ZFS_FLETCHER_H int fletcher_4_impl_set(const char *selector);
|
|
|
|
_ZFS_FLETCHER_H void fletcher_4_init(void);
|
|
|
|
_ZFS_FLETCHER_H void fletcher_4_fini(void);
|
2015-12-09 23:34:16 +00:00
|
|
|
|
2016-07-12 15:50:54 +00:00
|
|
|
|
2016-09-24 22:56:22 +00:00
|
|
|
|
|
|
|
/* Internal fletcher ctx */
|
|
|
|
|
2016-11-04 17:53:03 +00:00
|
|
|
typedef struct zfs_fletcher_superscalar {
|
|
|
|
uint64_t v[4];
|
|
|
|
} zfs_fletcher_superscalar_t;
|
|
|
|
|
2016-09-24 22:56:22 +00:00
|
|
|
typedef struct zfs_fletcher_sse {
|
|
|
|
uint64_t v[2] __attribute__((aligned(16)));
|
|
|
|
} zfs_fletcher_sse_t;
|
|
|
|
|
|
|
|
typedef struct zfs_fletcher_avx {
|
|
|
|
uint64_t v[4] __attribute__((aligned(32)));
|
|
|
|
} zfs_fletcher_avx_t;
|
|
|
|
|
|
|
|
typedef struct zfs_fletcher_avx512 {
|
|
|
|
uint64_t v[8] __attribute__((aligned(64)));
|
|
|
|
} zfs_fletcher_avx512_t;
|
|
|
|
|
2016-10-21 17:55:49 +00:00
|
|
|
typedef struct zfs_fletcher_aarch64_neon {
|
|
|
|
uint64_t v[2] __attribute__((aligned(16)));
|
|
|
|
} zfs_fletcher_aarch64_neon_t;
|
|
|
|
|
2016-09-24 22:56:22 +00:00
|
|
|
|
|
|
|
typedef union fletcher_4_ctx {
|
|
|
|
zio_cksum_t scalar;
|
2016-11-04 17:53:03 +00:00
|
|
|
zfs_fletcher_superscalar_t superscalar[4];
|
2016-09-24 22:56:22 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_SSE2) || (defined(HAVE_SSE2) && defined(HAVE_SSSE3))
|
|
|
|
zfs_fletcher_sse_t sse[4];
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_AVX) && defined(HAVE_AVX2)
|
|
|
|
zfs_fletcher_avx_t avx[4];
|
|
|
|
#endif
|
|
|
|
#if defined(__x86_64) && defined(HAVE_AVX512F)
|
|
|
|
zfs_fletcher_avx512_t avx512[4];
|
|
|
|
#endif
|
2016-10-21 17:55:49 +00:00
|
|
|
#if defined(__aarch64__)
|
|
|
|
zfs_fletcher_aarch64_neon_t aarch64_neon[4];
|
|
|
|
#endif
|
2016-09-24 22:56:22 +00:00
|
|
|
} fletcher_4_ctx_t;
|
|
|
|
|
2015-12-09 23:34:16 +00:00
|
|
|
/*
|
|
|
|
* fletcher checksum struct
|
|
|
|
*/
|
2016-09-24 22:56:22 +00:00
|
|
|
typedef void (*fletcher_4_init_f)(fletcher_4_ctx_t *);
|
|
|
|
typedef void (*fletcher_4_fini_f)(fletcher_4_ctx_t *, zio_cksum_t *);
|
|
|
|
typedef void (*fletcher_4_compute_f)(fletcher_4_ctx_t *,
|
|
|
|
const void *, uint64_t);
|
2016-07-12 15:50:54 +00:00
|
|
|
|
2015-12-09 23:34:16 +00:00
|
|
|
typedef struct fletcher_4_func {
|
2016-07-12 15:50:54 +00:00
|
|
|
fletcher_4_init_f init_native;
|
|
|
|
fletcher_4_fini_f fini_native;
|
|
|
|
fletcher_4_compute_f compute_native;
|
|
|
|
fletcher_4_init_f init_byteswap;
|
|
|
|
fletcher_4_fini_f fini_byteswap;
|
|
|
|
fletcher_4_compute_f compute_byteswap;
|
2015-12-09 23:34:16 +00:00
|
|
|
boolean_t (*valid)(void);
|
2023-03-14 16:45:28 +00:00
|
|
|
boolean_t uses_fpu;
|
2015-12-09 23:34:16 +00:00
|
|
|
const char *name;
|
2023-03-14 16:45:28 +00:00
|
|
|
} __attribute__((aligned(64))) fletcher_4_ops_t;
|
2015-12-09 23:34:16 +00:00
|
|
|
|
2021-05-15 09:53:14 +00:00
|
|
|
_ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_superscalar_ops;
|
|
|
|
_ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_superscalar4_ops;
|
2016-09-24 22:56:22 +00:00
|
|
|
|
2016-06-24 03:32:40 +00:00
|
|
|
#if defined(HAVE_SSE2)
|
2021-05-15 09:53:14 +00:00
|
|
|
_ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_sse2_ops;
|
2016-06-24 03:32:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_SSE2) && defined(HAVE_SSSE3)
|
2021-05-15 09:53:14 +00:00
|
|
|
_ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_ssse3_ops;
|
2016-06-24 03:32:40 +00:00
|
|
|
#endif
|
|
|
|
|
2015-12-09 23:34:16 +00:00
|
|
|
#if defined(HAVE_AVX) && defined(HAVE_AVX2)
|
2021-05-15 09:53:14 +00:00
|
|
|
_ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_avx2_ops;
|
2015-12-09 23:34:16 +00:00
|
|
|
#endif
|
2010-05-28 20:45:14 +00:00
|
|
|
|
2016-07-06 11:42:04 +00:00
|
|
|
#if defined(__x86_64) && defined(HAVE_AVX512F)
|
2021-05-15 09:53:14 +00:00
|
|
|
_ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_avx512f_ops;
|
2016-07-06 11:42:04 +00:00
|
|
|
#endif
|
|
|
|
|
2019-10-30 19:26:14 +00:00
|
|
|
#if defined(__x86_64) && defined(HAVE_AVX512BW)
|
2021-05-15 09:53:14 +00:00
|
|
|
_ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_avx512bw_ops;
|
2019-10-30 19:26:14 +00:00
|
|
|
#endif
|
|
|
|
|
2016-10-21 17:55:49 +00:00
|
|
|
#if defined(__aarch64__)
|
2021-05-15 09:53:14 +00:00
|
|
|
_ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_aarch64_neon_ops;
|
2016-10-21 17:55:49 +00:00
|
|
|
#endif
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-02-03 22:35:38 +00:00
|
|
|
#if defined(ZFS_UBSAN_ENABLED)
|
|
|
|
#if defined(__has_attribute)
|
|
|
|
#if __has_attribute(no_sanitize_undefined)
|
|
|
|
#define ZFS_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize_undefined))
|
|
|
|
#elif __has_attribute(no_sanitize)
|
|
|
|
#define ZFS_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined")))
|
|
|
|
#else
|
|
|
|
#error "Compiler has to support attribute "
|
|
|
|
"`no_sanitize_undefined` or `no_sanitize(\"undefined\")`"
|
|
|
|
"when compiling with UBSan enabled"
|
|
|
|
#endif /* __has_attribute(no_sanitize_undefined) */
|
|
|
|
#endif /* defined(__has_attribute) */
|
|
|
|
#else
|
|
|
|
#define ZFS_NO_SANITIZE_UNDEFINED
|
|
|
|
#endif /* defined(ZFS_UBSAN_ENABLED) */
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
#endif /* _ZFS_FLETCHER_H */
|