Coverage Report

Created: 2025-06-13 06:43

/src/php-src/ext/hash/murmur/endianness.h
Line
Count
Source (jump to first uncovered line)
1
static const union {
2
  uint8_t u8[2];
3
  uint16_t u16;
4
} EndianMix = {{ 1, 0 }};
5
FORCE_INLINE int IsBigEndian(void)
6
495k
{
7
  // Constant-folded by the compiler.
8
495k
  return EndianMix.u16 != 1;
9
495k
}
PMurHash.c:IsBigEndian
Line
Count
Source
6
376k
{
7
  // Constant-folded by the compiler.
8
376k
  return EndianMix.u16 != 1;
9
376k
}
PMurHash128.c:IsBigEndian
Line
Count
Source
6
119k
{
7
  // Constant-folded by the compiler.
8
119k
  return EndianMix.u16 != 1;
9
119k
}
10
11
#if defined(_MSC_VER)
12
#  include <stdlib.h>
13
#  define BSWAP32(u) _byteswap_ulong(u)
14
#  define BSWAP64(u) _byteswap_uint64(u)
15
#else
16
#  if defined(__GNUC__) && ( \
17
                    __GNUC__ > 4 || ( \
18
                      __GNUC__ == 4 && ( \
19
                        __GNUC_MINOR__ >= 3 \
20
                      ) \
21
                    ) \
22
                  )
23
#    define BSWAP32(u) __builtin_bswap32(u)
24
#    define BSWAP64(u) __builtin_bswap64(u)
25
#  elif defined(__has_builtin)
26
#    if __has_builtin(__builtin_bswap32)
27
0
#      define BSWAP32(u) __builtin_bswap32(u)
28
#    endif // __has_builtin(__builtin_bswap32)
29
#    if __has_builtin(__builtin_bswap64)
30
0
#      define BSWAP64(u) __builtin_bswap64(u)
31
#    endif // __has_builtin(__builtin_bswap64)
32
#  endif // __has_builtin
33
#endif // defined(_MSC_VER)
34
35
#ifndef BSWAP32
36
FORCE_INLINE uint32_t BSWAP32(uint32_t u)
37
{
38
  return (((u & 0xff000000) >> 24)
39
          | ((u & 0x00ff0000) >>  8)
40
          | ((u & 0x0000ff00) <<  8)
41
          | ((u & 0x000000ff) << 24));
42
}
43
#endif
44
#ifndef BSWAP64
45
FORCE_INLINE uint64_t BSWAP64(uint64_t u)
46
{
47
   return (((u & 0xff00000000000000ULL) >> 56)
48
          | ((u & 0x00ff000000000000ULL) >> 40)
49
          | ((u & 0x0000ff0000000000ULL) >> 24)
50
          | ((u & 0x000000ff00000000ULL) >>  8)
51
          | ((u & 0x00000000ff000000ULL) <<  8)
52
          | ((u & 0x0000000000ff0000ULL) << 24)
53
          | ((u & 0x000000000000ff00ULL) << 40)
54
          | ((u & 0x00000000000000ffULL) << 56));
55
}
56
#endif
57
58
#if defined(__clang__) || defined(__GNUC__) &&  __GNUC__ >= 8
59
# define NO_SANITIZE_ALIGNMENT __attribute__((no_sanitize("alignment")))
60
#else
61
# define NO_SANITIZE_ALIGNMENT
62
#endif
63
64
NO_SANITIZE_ALIGNMENT
65
FORCE_INLINE uint32_t getblock32 ( const uint32_t * const p, const int i)
66
479k
{
67
479k
  if (IsBigEndian()) {
68
0
    return BSWAP32(p[i]);
69
479k
  } else {
70
479k
    return p[i];
71
479k
  }
72
479k
}
PMurHash.c:getblock32
Line
Count
Source
66
376k
{
67
376k
  if (IsBigEndian()) {
68
0
    return BSWAP32(p[i]);
69
376k
  } else {
70
376k
    return p[i];
71
376k
  }
72
376k
}
PMurHash128.c:getblock32
Line
Count
Source
66
103k
{
67
103k
  if (IsBigEndian()) {
68
0
    return BSWAP32(p[i]);
69
103k
  } else {
70
103k
    return p[i];
71
103k
  }
72
103k
}
73
74
NO_SANITIZE_ALIGNMENT
75
FORCE_INLINE uint64_t getblock64 ( const uint64_t * const p, const int i)
76
16.1k
{
77
16.1k
  if (IsBigEndian()) {
78
0
    return BSWAP64(p[i]);
79
16.1k
  } else {
80
16.1k
    return p[i];
81
16.1k
  }
82
16.1k
}
Unexecuted instantiation: PMurHash.c:getblock64
PMurHash128.c:getblock64
Line
Count
Source
76
16.1k
{
77
16.1k
  if (IsBigEndian()) {
78
0
    return BSWAP64(p[i]);
79
16.1k
  } else {
80
16.1k
    return p[i];
81
16.1k
  }
82
16.1k
}
83
84
#undef NO_SANITIZE_ALIGNMENT