Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2010-2014 Intel Corporation 3 : : */ 4 : : 5 : : #include <eal_export.h> 6 : : #include <rte_cpuflags.h> 7 : : #include <rte_log.h> 8 : : 9 : : #include "rte_hash_crc.h" 10 : : 11 [ - + ]: 301 : RTE_LOG_REGISTER_SUFFIX(hash_crc_logtype, crc, INFO); 12 : : #define RTE_LOGTYPE_HASH_CRC hash_crc_logtype 13 : : #define HASH_CRC_LOG(level, ...) \ 14 : : RTE_LOG_LINE(level, HASH_CRC, "" __VA_ARGS__) 15 : : 16 : : RTE_EXPORT_SYMBOL(rte_hash_crc32_alg) 17 : : uint8_t rte_hash_crc32_alg = CRC32_SW; 18 : : 19 : : /** 20 : : * Allow or disallow use of SSE4.2/ARMv8 intrinsics for CRC32 hash 21 : : * calculation. 22 : : * 23 : : * @param alg 24 : : * An OR of following flags: 25 : : * - (CRC32_SW) Don't use SSE4.2/ARMv8 intrinsics (default non-[x86/ARMv8]) 26 : : * - (CRC32_SSE42) Use SSE4.2 intrinsics if available 27 : : * - (CRC32_SSE42_x64) Use 64-bit SSE4.2 intrinsic if available (default x86) 28 : : * - (CRC32_ARM64) Use ARMv8 CRC intrinsic if available (default ARMv8) 29 : : */ 30 : : RTE_EXPORT_SYMBOL(rte_hash_crc_set_alg) 31 : : void 32 : 4398 : rte_hash_crc_set_alg(uint8_t alg) 33 : : { 34 : 4398 : rte_hash_crc32_alg = CRC32_SW; 35 : : 36 [ + + ]: 4398 : if (alg == CRC32_SW) 37 : : return; 38 : : 39 : : #if defined RTE_ARCH_X86 40 [ + - + + ]: 3374 : if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_EM64T) || alg == CRC32_SSE42) 41 : 1024 : rte_hash_crc32_alg = CRC32_SSE42; 42 : : else 43 : 2350 : rte_hash_crc32_alg = CRC32_SSE42_x64; 44 : : #endif 45 : : 46 : : #if defined RTE_ARCH_ARM64 47 : : if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_CRC32)) 48 : : rte_hash_crc32_alg = CRC32_ARM64; 49 : : #endif 50 : : 51 [ - + ]: 3374 : if (rte_hash_crc32_alg == CRC32_SW) 52 : 0 : HASH_CRC_LOG(WARNING, 53 : : "Unsupported CRC32 algorithm requested, using CRC32_SW"); 54 : : } 55 : : 56 : : /* Setting the best available algorithm */ 57 : 301 : RTE_INIT(rte_hash_crc_init_alg) 58 : : { 59 : : #if defined(RTE_ARCH_X86) 60 : 301 : rte_hash_crc_set_alg(CRC32_SSE42_x64); 61 : : #elif defined(RTE_ARCH_ARM64) && defined(__ARM_FEATURE_CRC32) 62 : : rte_hash_crc_set_alg(CRC32_ARM64); 63 : : #else 64 : : rte_hash_crc_set_alg(CRC32_SW); 65 : : #endif 66 : 301 : }