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