Coverage Report

Created: 2025-08-24 06:59

/src/FreeRDP/winpr/include/winpr/intrin.h
Line
Count
Source (jump to first uncovered line)
1
/**
2
 * WinPR: Windows Portable Runtime
3
 * C Run-Time Library Routines
4
 *
5
 * Copyright 2015 Thincast Technologies GmbH
6
 * Copyright 2015 Bernhard Miklautz <bernhard.miklautz@thincast.com>
7
 *
8
 *
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12
 *
13
 *     http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20
 */
21
22
#ifndef WINPR_INTRIN_H
23
#define WINPR_INTRIN_H
24
25
#if !defined(_WIN32) || defined(__MINGW32__) || defined(_M_ARM64)
26
27
/**
28
 * __lzcnt16, __lzcnt, __lzcnt64:
29
 * http://msdn.microsoft.com/en-us/library/bb384809/
30
 *
31
 * Beware: the result of __builtin_clz(0) is undefined
32
 */
33
34
#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2))
35
36
static INLINE UINT32 __lzcnt(UINT32 _val32)
37
0
{
38
0
  return ((UINT32)__builtin_clz(_val32));
39
0
}
40
41
#if !(defined(__MINGW32__) && defined(__clang__))
42
static INLINE UINT16 __lzcnt16(UINT16 _val16)
43
0
{
44
0
  return ((UINT16)(__builtin_clz((UINT32)_val16) - 16));
45
0
}
46
#endif /* !(defined(__MINGW32__) && defined(__clang__)) */
47
48
#else /* (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2) */
49
50
static INLINE UINT32 __lzcnt(UINT32 x)
51
{
52
  unsigned y;
53
  int n = 32;
54
  y = x >> 16;
55
  if (y != 0)
56
  {
57
    n = n - 16;
58
    x = y;
59
  }
60
  y = x >> 8;
61
  if (y != 0)
62
  {
63
    n = n - 8;
64
    x = y;
65
  }
66
  y = x >> 4;
67
  if (y != 0)
68
  {
69
    n = n - 4;
70
    x = y;
71
  }
72
  y = x >> 2;
73
  if (y != 0)
74
  {
75
    n = n - 2;
76
    x = y;
77
  }
78
  y = x >> 1;
79
  if (y != 0)
80
    return n - 2;
81
  return n - x;
82
}
83
84
static INLINE UINT16 __lzcnt16(UINT16 x)
85
{
86
  return ((UINT16)__lzcnt((UINT32)x));
87
}
88
89
#endif /* (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2) */
90
91
#endif /* !defined(_WIN32) || defined(__MINGW32__) */
92
93
#endif /* WINPR_INTRIN_H */