2 * Copyright 2017 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #ifndef __DML_INLINE_DEFS_H__
27 #define __DML_INLINE_DEFS_H__
29 #include "dcn_calc_math.h"
30 #include "dml_logger.h"
32 static inline double dml_min(double a
, double b
)
34 return (double) dcn_bw_min2(a
, b
);
37 static inline double dml_min3(double a
, double b
, double c
)
39 return dml_min(dml_min(a
, b
), c
);
42 static inline double dml_min4(double a
, double b
, double c
, double d
)
44 return dml_min(dml_min(a
, b
), dml_min(c
, d
));
47 static inline double dml_max(double a
, double b
)
49 return (double) dcn_bw_max2(a
, b
);
52 static inline double dml_max3(double a
, double b
, double c
)
54 return dml_max(dml_max(a
, b
), c
);
57 static inline double dml_max4(double a
, double b
, double c
, double d
)
59 return dml_max(dml_max(a
, b
), dml_max(c
, d
));
62 static inline double dml_max5(double a
, double b
, double c
, double d
, double e
)
64 return dml_max(dml_max4(a
, b
, c
, d
), e
);
67 static inline double dml_ceil(double a
, double granularity
)
69 return (double) dcn_bw_ceil2(a
, granularity
);
72 static inline double dml_floor(double a
, double granularity
)
74 return (double) dcn_bw_floor2(a
, granularity
);
77 static inline double dml_round(double a
)
79 double round_pt
= 0.5;
80 double ceil
= dml_ceil(a
, 1);
81 double floor
= dml_floor(a
, 1);
83 if (a
- floor
>= round_pt
)
90 static inline int dml_log2(float x)
92 unsigned int ix = *((unsigned int *)&x);
94 return (int)((ix >> 23) & 0xff) - 127;
98 static inline int dml_log2(double x
)
100 unsigned long long ix
= *((unsigned long long *)&x
);
102 return (int)((ix
>> 52) & 0x7ff) - 1023;
105 static inline double dml_pow(double a
, int exp
)
107 return (double) dcn_bw_pow(a
, exp
);
110 static inline double dml_fmod(double f
, int val
)
112 return (double) dcn_bw_mod(f
, val
);
115 static inline double dml_ceil_2(double f
)
117 return (double) dcn_bw_ceil2(f
, 2);
120 static inline double dml_ceil_ex(double x
, double granularity
)
122 return (double) dcn_bw_ceil2(x
, granularity
);
125 static inline double dml_floor_ex(double x
, double granularity
)
127 return (double) dcn_bw_floor2(x
, granularity
);
130 static inline unsigned int dml_round_to_multiple(unsigned int num
,
131 unsigned int multiple
,
134 unsigned int remainder
;
139 remainder
= num
% multiple
;
145 return (num
+ multiple
- remainder
);
147 return (num
- remainder
);
149 static inline double dml_abs(double a
)