LCOV - code coverage report
Current view: top level - spdk/lib/util - math.c (source / functions) Hit Total Coverage
Test: Combined Lines: 8 8 100.0 %
Date: 2024-08-09 23:39:43 Functions: 6 16 37.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 8 75.0 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2019 Intel Corporation. All rights reserved.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "spdk/stdinc.h"
       7                 :            : #include "spdk/util.h"
       8                 :            : #include "spdk/assert.h"
       9                 :            : 
      10                 :            : /* The following will automatically generate several version of
      11                 :            :  * this function, targeted at different architectures. This
      12                 :            :  * is only supported by GCC 6 or newer. */
      13                 :            : #if defined(__GNUC__) && __GNUC__ >= 6 && !defined(__clang__) \
      14                 :            :         && (defined(__i386__) || defined(__x86_64__)) \
      15                 :            :         && defined(__ELF__)
      16                 :            : __attribute__((target_clones("bmi", "arch=core2", "arch=atom", "default")))
      17                 :            : #endif
      18                 :            : uint32_t
      19                 :  393380416 : spdk_u32log2(uint32_t x)
      20                 :            : {
      21         [ +  + ]:  393380416 :         if (x == 0) {
      22                 :            :                 /* log(0) is undefined */
      23                 :        355 :                 return 0;
      24                 :            :         }
      25                 :            :         SPDK_STATIC_ASSERT(sizeof(x) == sizeof(unsigned int), "Incorrect size");
      26         [ -  + ]:  393380061 :         return 31u - __builtin_clz(x);
      27                 :            : }
      28                 :            : 
      29                 :            : /* The following will automatically generate several version of
      30                 :            :  * this function, targeted at different architectures. This
      31                 :            :  * is only supported by GCC 6 or newer. */
      32                 :            : #if defined(__GNUC__) && __GNUC__ >= 6 && !defined(__clang__) \
      33                 :            :         && (defined(__i386__) || defined(__x86_64__)) \
      34                 :            :         && defined(__ELF__)
      35                 :            : __attribute__((target_clones("bmi", "arch=core2", "arch=atom", "default")))
      36                 :            : #endif
      37                 :            : uint64_t
      38                 :   28747213 : spdk_u64log2(uint64_t x)
      39                 :            : {
      40         [ +  + ]:   28747213 :         if (x == 0) {
      41                 :            :                 /* log(0) is undefined */
      42                 :        762 :                 return 0;
      43                 :            :         }
      44                 :            :         SPDK_STATIC_ASSERT(sizeof(x) == sizeof(unsigned long long), "Incorrect size");
      45         [ -  + ]:   28746451 :         return 63u - __builtin_clzll(x);
      46                 :            : }

Generated by: LCOV version 1.14