Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2010-2014 Intel Corporation 3 : : */ 4 : : 5 : : #ifndef __INCLUDE_RTE_SCHED_COMMON_H__ 6 : : #define __INCLUDE_RTE_SCHED_COMMON_H__ 7 : : 8 : : #ifdef __cplusplus 9 : : extern "C" { 10 : : #endif 11 : : 12 : : #include <stdint.h> 13 : : #include <sys/types.h> 14 : : 15 : : #define __rte_aligned_16 __rte_aligned(16) 16 : : 17 : : #if 0 18 : : static inline uint32_t 19 : : rte_min_pos_4_u16(uint16_t *x) 20 : : { 21 : : uint32_t pos0, pos1; 22 : : 23 : : pos0 = (x[0] <= x[1])? 0 : 1; 24 : : pos1 = (x[2] <= x[3])? 2 : 3; 25 : : 26 : : return (x[pos0] <= x[pos1])? pos0 : pos1; 27 : : } 28 : : 29 : : #else 30 : : 31 : : /* simplified version to remove branches with CMOV instruction */ 32 : : static inline uint32_t 33 : : rte_min_pos_4_u16(uint16_t *x) 34 : : { 35 : : uint32_t pos0 = 0; 36 : : uint32_t pos1 = 2; 37 : : 38 [ # # ]: 0 : if (x[1] <= x[0]) pos0 = 1; 39 [ # # ]: 0 : if (x[3] <= x[2]) pos1 = 3; 40 [ # # ]: 0 : if (x[pos1] <= x[pos0]) pos0 = pos1; 41 : : 42 : : return pos0; 43 : : } 44 : : 45 : : #endif 46 : : 47 : : /* 48 : : * Compute the Greatest Common Divisor (GCD) of two numbers. 49 : : * This implementation uses Euclid's algorithm: 50 : : * gcd(a, 0) = a 51 : : * gcd(a, b) = gcd(b, a mod b) 52 : : */ 53 : : static inline uint64_t 54 : : rte_get_gcd64(uint64_t a, uint64_t b) 55 : : { 56 : : uint64_t c; 57 : : 58 [ # # # # ]: 3 : if (a == 0) 59 : : return b; 60 [ + - + - : 3 : if (b == 0) + - ] 61 : : return a; 62 : : 63 [ - + - + : 3 : if (a < b) { - + ] 64 : : c = a; 65 : : a = b; 66 : : b = c; 67 : : } 68 : : 69 [ + + + + : 6 : while (b != 0) { + + ] 70 : 3 : c = a % b; 71 : : a = b; 72 : : b = c; 73 : : } 74 : : 75 : : return a; 76 : : } 77 : : 78 : : /* 79 : : * 32-bit version of Greatest Common Divisor (GCD). 80 : : */ 81 : : static inline uint32_t 82 : : rte_get_gcd(uint32_t a, uint32_t b) 83 : : { 84 : 4 : return rte_get_gcd64(a, b); 85 : : } 86 : : 87 : : /* 88 : : * Compute the Lowest Common Denominator (LCD) of two numbers. 89 : : * This implementation computes GCD first: 90 : : * LCD(a, b) = (a * b) / GCD(a, b) 91 : : */ 92 : : static inline uint32_t 93 : : rte_get_lcd(uint32_t a, uint32_t b) 94 : : { 95 [ + - + - : 3 : return (a * b) / rte_get_gcd(a, b); + - ] 96 : : } 97 : : 98 : : #ifdef __cplusplus 99 : : } 100 : : #endif 101 : : 102 : : #endif /* __INCLUDE_RTE_SCHED_COMMON_H__ */