Path: blob/main/sys/contrib/openzfs/include/zfs_fletcher.h
48254 views
// SPDX-License-Identifier: CDDL-1.01/*2* CDDL HEADER START3*4* The contents of this file are subject to the terms of the5* 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.LICENSE9* or https://opensource.org/licenses/CDDL-1.0.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/21/*22* Copyright 2009 Sun Microsystems, Inc. All rights reserved.23* Use is subject to license terms.24*/25/*26* Copyright 2013 Saso Kiselkov. All rights reserved.27*/2829#ifndef _ZFS_FLETCHER_H30#define _ZFS_FLETCHER_H extern __attribute__((visibility("default")))3132#include <sys/types.h>33#include <sys/spa_checksum.h>3435#ifdef __cplusplus36extern "C" {37#endif3839/*40* fletcher checksum functions41*42* Note: Fletcher checksum methods expect buffer size to be 4B aligned. This43* limitation stems from the algorithm design. Performing incremental checksum44* without said alignment would yield different results. Therefore, the code45* includes assertions for the size alignment.46* For compatibility, it is required that some code paths calculate checksum of47* non-aligned buffer sizes. For this purpose, `fletcher_4_native_varsize()`48* checksum method is added. This method will ignore last (size % 4) bytes of49* the data buffer.50*/51_ZFS_FLETCHER_H void fletcher_init(zio_cksum_t *);52_ZFS_FLETCHER_H void fletcher_2_native(const void *, uint64_t, const void *,53zio_cksum_t *);54_ZFS_FLETCHER_H void fletcher_2_byteswap(const void *, uint64_t, const void *,55zio_cksum_t *);56_ZFS_FLETCHER_H void fletcher_4_native(const void *, uint64_t, const void *,57zio_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,61zio_cksum_t *);62_ZFS_FLETCHER_H void fletcher_4_byteswap(const void *, uint64_t, const void *,63zio_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);69707172/* Internal fletcher ctx */7374typedef struct zfs_fletcher_superscalar {75uint64_t v[4];76} zfs_fletcher_superscalar_t;7778typedef struct zfs_fletcher_sse {79uint64_t v[2];80} zfs_fletcher_sse_t;8182typedef struct zfs_fletcher_avx {83uint64_t v[4];84} zfs_fletcher_avx_t;8586typedef struct zfs_fletcher_avx512 {87uint64_t v[8];88} zfs_fletcher_avx512_t;8990typedef struct zfs_fletcher_aarch64_neon {91uint64_t v[2];92} zfs_fletcher_aarch64_neon_t;939495typedef union fletcher_4_ctx {96zio_cksum_t scalar;97zfs_fletcher_superscalar_t superscalar[4];9899#if defined(HAVE_SSE2) || (defined(HAVE_SSE2) && defined(HAVE_SSSE3))100zfs_fletcher_sse_t sse[4];101#endif102#if defined(HAVE_AVX) && defined(HAVE_AVX2)103zfs_fletcher_avx_t avx[4];104#endif105#if defined(__x86_64) && defined(HAVE_AVX512F)106zfs_fletcher_avx512_t avx512[4];107#endif108#if defined(__aarch64__)109zfs_fletcher_aarch64_neon_t aarch64_neon[4];110#endif111} fletcher_4_ctx_t;112113/*114* fletcher checksum struct115*/116typedef void (*fletcher_4_init_f)(fletcher_4_ctx_t *);117typedef void (*fletcher_4_fini_f)(fletcher_4_ctx_t *, zio_cksum_t *);118typedef void (*fletcher_4_compute_f)(fletcher_4_ctx_t *,119const void *, uint64_t);120121typedef struct fletcher_4_func {122fletcher_4_init_f init_native;123fletcher_4_fini_f fini_native;124fletcher_4_compute_f compute_native;125fletcher_4_init_f init_byteswap;126fletcher_4_fini_f fini_byteswap;127fletcher_4_compute_f compute_byteswap;128boolean_t (*valid)(void);129boolean_t uses_fpu;130const char *name;131} __attribute__((aligned(64))) fletcher_4_ops_t;132133_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;135136#if defined(HAVE_SSE2)137_ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_sse2_ops;138#endif139140#if defined(HAVE_SSE2) && defined(HAVE_SSSE3)141_ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_ssse3_ops;142#endif143144#if defined(HAVE_AVX) && defined(HAVE_AVX2)145_ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_avx2_ops;146#endif147148#if defined(__x86_64) && defined(HAVE_AVX512F)149_ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_avx512f_ops;150#endif151152#if defined(__x86_64) && defined(HAVE_AVX512BW)153_ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_avx512bw_ops;154#endif155156#if defined(__aarch64__)157_ZFS_FLETCHER_H const fletcher_4_ops_t fletcher_4_aarch64_neon_ops;158#endif159160#ifdef __cplusplus161}162#endif163164#endif /* _ZFS_FLETCHER_H */165166167