mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 11:18:08 +02:00
util: Deduplicate macros between u_math.h and macros.h
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24484>
This commit is contained in:
parent
16fa4621b8
commit
00f9e41251
2 changed files with 14 additions and 22 deletions
|
|
@ -350,7 +350,11 @@ do { \
|
|||
/** Compute ceiling of integer quotient of A divided by B. */
|
||||
#define DIV_ROUND_UP( A, B ) ( ((A) + (B) - 1) / (B) )
|
||||
|
||||
/** Clamp X to [MIN,MAX]. Turn NaN into MIN, arbitrarily. */
|
||||
/**
|
||||
* Clamp X to [MIN, MAX].
|
||||
* This is a macro to allow float, int, unsigned, etc. types.
|
||||
* We arbitrarily turn NaN into MIN.
|
||||
*/
|
||||
#define CLAMP( X, MIN, MAX ) ( (X)>(MIN) ? ((X)>(MAX) ? (MAX) : (X)) : (MIN) )
|
||||
|
||||
/* Syntax sugar occuring frequently in graphics code */
|
||||
|
|
@ -362,10 +366,18 @@ do { \
|
|||
/** Maximum of two values: */
|
||||
#define MAX2( A, B ) ( (A)>(B) ? (A) : (B) )
|
||||
|
||||
/** Minimum and maximum of three values: */
|
||||
/** Minimum of three values: */
|
||||
#define MIN3( A, B, C ) ((A) < (B) ? MIN2(A, C) : MIN2(B, C))
|
||||
|
||||
/** Maximum of three values: */
|
||||
#define MAX3( A, B, C ) ((A) > (B) ? MAX2(A, C) : MAX2(B, C))
|
||||
|
||||
/** Minimum of four values: */
|
||||
#define MIN4( A, B, C, D ) ((A) < (B) ? MIN3(A, C, D) : MIN3(B, C, D))
|
||||
|
||||
/** Maximum of four values: */
|
||||
#define MAX4( A, B, C, D ) ((A) > (B) ? MAX3(A, C, D) : MAX3(B, C, D))
|
||||
|
||||
/** Align a value to a power of two */
|
||||
#define ALIGN_POT(x, pot_align) (((x) + (pot_align) - 1) & ~((pot_align) - 1))
|
||||
|
||||
|
|
|
|||
|
|
@ -618,26 +618,6 @@ util_memcpy_cpu_to_le32(void * restrict dest, const void * restrict src, size_t
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamp X to [MIN, MAX].
|
||||
* This is a macro to allow float, int, uint, etc. types.
|
||||
* We arbitrarily turn NaN into MIN.
|
||||
*/
|
||||
#define CLAMP( X, MIN, MAX ) ( (X)>(MIN) ? ((X)>(MAX) ? (MAX) : (X)) : (MIN) )
|
||||
|
||||
/* Syntax sugar occuring frequently in graphics code */
|
||||
#define SATURATE( X ) CLAMP(X, 0.0f, 1.0f)
|
||||
|
||||
#define MIN2( A, B ) ( (A)<(B) ? (A) : (B) )
|
||||
#define MAX2( A, B ) ( (A)>(B) ? (A) : (B) )
|
||||
|
||||
#define MIN3( A, B, C ) ((A) < (B) ? MIN2(A, C) : MIN2(B, C))
|
||||
#define MAX3( A, B, C ) ((A) > (B) ? MAX2(A, C) : MAX2(B, C))
|
||||
|
||||
#define MIN4( A, B, C, D ) ((A) < (B) ? MIN3(A, C, D) : MIN3(B, C, D))
|
||||
#define MAX4( A, B, C, D ) ((A) > (B) ? MAX3(A, C, D) : MAX3(B, C, D))
|
||||
|
||||
|
||||
/**
|
||||
* Align a value up to an alignment value
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue