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 [ - + ]: 252 : 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 : : */ 31 : : RTE_EXPORT_SYMBOL(rte_hash_crc_set_alg) 32 : : void 33 : 4349 : rte_hash_crc_set_alg(uint8_t alg) 34 : : { 35 : 4349 : rte_hash_crc32_alg = CRC32_SW; 36 : : 37 [ + + ]: 4349 : if (alg == CRC32_SW) 38 : : return; 39 : : 40 : : #if defined RTE_ARCH_X86 41 [ + + ]: 3325 : if (!(alg & CRC32_SSE42_x64)) 42 : 1024 : HASH_CRC_LOG(WARNING, 43 : : "Unsupported CRC32 algorithm requested using CRC32_x64/CRC32_SSE42"); 44 [ + - + + ]: 3325 : if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_EM64T) || alg == CRC32_SSE42) 45 : 1024 : rte_hash_crc32_alg = CRC32_SSE42; 46 : : else 47 : 2301 : rte_hash_crc32_alg = CRC32_SSE42_x64; 48 : : #endif 49 : : 50 : : #if defined RTE_ARCH_ARM64 51 : : if (!(alg & CRC32_ARM64)) 52 : : HASH_CRC_LOG(WARNING, 53 : : "Unsupported CRC32 algorithm requested using CRC32_ARM64"); 54 : : if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_CRC32)) 55 : : rte_hash_crc32_alg = CRC32_ARM64; 56 : : #endif 57 : : 58 [ - + ]: 3325 : if (rte_hash_crc32_alg == CRC32_SW) 59 : 0 : HASH_CRC_LOG(WARNING, 60 : : "Unsupported CRC32 algorithm requested using CRC32_SW"); 61 : : } 62 : : 63 : : /* Setting the best available algorithm */ 64 : 252 : RTE_INIT(rte_hash_crc_init_alg) 65 : : { 66 : : #if defined(RTE_ARCH_X86) 67 : 252 : rte_hash_crc_set_alg(CRC32_SSE42_x64); 68 : : #elif defined(RTE_ARCH_ARM64) && defined(__ARM_FEATURE_CRC32) 69 : : rte_hash_crc_set_alg(CRC32_ARM64); 70 : : #else 71 : : rte_hash_crc_set_alg(CRC32_SW); 72 : : #endif 73 : 252 : }