UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ClangPlatformMath.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================================
4 ClangPlatformMath.h: Clang intrinsic implementations of some platform Math functions
5==============================================================================================*/
6
7#pragma once
8
9#ifdef __clang__
10
11#include "Concepts/Integral.h"
13
14// HEADER_UNIT_UNSUPPORTED - Clang not supporting header units
15
19struct FClangPlatformMath : public FGenericPlatformMath
20{
29 {
30 return uint8(__builtin_clz((uint32(Value) << 1) | 1) - 23);
31 }
32
41 {
42 return __builtin_clzll((uint64(Value) << 1) | 1) - 31;
43 }
44
52 static inline constexpr uint64 CountLeadingZeros64(uint64 Value)
53 {
54 if (Value == 0)
55 {
56 return 64;
57 }
58
59 return __builtin_clzll(Value);
60 }
61
69 static inline constexpr uint32 CountTrailingZeros(uint32 Value)
70 {
71 if (Value == 0)
72 {
73 return 32;
74 }
75
76 return (uint32)__builtin_ctz(Value);
77 }
78
86 static inline constexpr uint64 CountTrailingZeros64(uint64 Value)
87 {
88 if (Value == 0)
89 {
90 return 64;
91 }
92
94 }
95
97 {
98 return 31 - __builtin_clz(Value | 1);
99 }
100
102 {
103 return 31 - __builtin_clz(Value);
104 }
105
107 {
108 return 63 - __builtin_clzll(Value | 1);
109 }
110
112 {
113 return 63 - __builtin_clzll(Value);
114 }
115
121 template <UE::CIntegral IntType>
122 static UE_FORCEINLINE_HINT bool AddAndCheckForOverflow(IntType A, IntType B, IntType& OutResult)
123 {
125 }
126
132 template <UE::CIntegral IntType>
133 static UE_FORCEINLINE_HINT bool SubtractAndCheckForOverflow(IntType A, IntType B, IntType& OutResult)
134 {
136 }
137
143 template <UE::CIntegral IntType>
144 static UE_FORCEINLINE_HINT bool MultiplyAndCheckForOverflow(IntType A, IntType B, IntType& OutResult)
145 {
147 }
148};
149
150#endif //~__clang__
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition GenericPlatformMath.h:32
static constexpr uint64 FloorLog2_64(uint64 Value)
Definition GenericPlatformMath.h:683
static constexpr UE_FORCEINLINE_HINT uint64 FloorLog2NonZero_64(uint64 Value)
Definition GenericPlatformMath.h:696
static bool AddAndCheckForOverflow(IntType A, IntType B, IntType &OutResult)
Definition GenericPlatformMath.h:1188
static bool SubtractAndCheckForOverflow(IntType A, IntType B, IntType &OutResult)
Definition GenericPlatformMath.h:1235
static constexpr uint64 CountTrailingZeros64(uint64 Value)
Definition GenericPlatformMath.h:775
static constexpr uint32 CountTrailingZeros(uint32 Value)
Definition GenericPlatformMath.h:747
static bool MultiplyAndCheckForOverflow(IntType A, IntType B, IntType &OutResult)
Definition GenericPlatformMath.h:1276
static constexpr uint64 CountLeadingZeros64(uint64 Value)
Definition GenericPlatformMath.h:734
static constexpr uint32 CountLeadingZeros(uint32 Value)
Definition GenericPlatformMath.h:721
static constexpr uint8 CountLeadingZeros8(uint8 Value)
Definition GenericPlatformMath.h:708
static constexpr uint32 FloorLog2(uint32 Value)
Definition GenericPlatformMath.h:659
static constexpr UE_FORCEINLINE_HINT uint32 FloorLog2NonZero(uint32 Value)
Definition GenericPlatformMath.h:671