1 /*
2 * Copyright 2017 Advanced Micro Devices, Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: AMD
23 *
24 */
25
26 #ifndef __DML_INLINE_DEFS_H__
27 #define __DML_INLINE_DEFS_H__
28
29 #include "dml_common_defs.h"
30 #include "dcn_calc_math.h"
31 #include "dml_logger.h"
32
dml_min(double a,double b)33 static inline double dml_min(double a, double b)
34 {
35 return (double) dcn_bw_min2(a, b);
36 }
37
dml_min3(double a,double b,double c)38 static inline double dml_min3(double a, double b, double c)
39 {
40 return dml_min(dml_min(a, b), c);
41 }
42
dml_min4(double a,double b,double c,double d)43 static inline double dml_min4(double a, double b, double c, double d)
44 {
45 return dml_min(dml_min(a, b), dml_min(c, d));
46 }
47
dml_max(double a,double b)48 static inline double dml_max(double a, double b)
49 {
50 return (double) dcn_bw_max2(a, b);
51 }
52
dml_max3(double a,double b,double c)53 static inline double dml_max3(double a, double b, double c)
54 {
55 return dml_max(dml_max(a, b), c);
56 }
57
dml_max4(double a,double b,double c,double d)58 static inline double dml_max4(double a, double b, double c, double d)
59 {
60 return dml_max(dml_max(a, b), dml_max(c, d));
61 }
62
dml_max5(double a,double b,double c,double d,double e)63 static inline double dml_max5(double a, double b, double c, double d, double e)
64 {
65 return dml_max(dml_max4(a, b, c, d), e);
66 }
67
dml_ceil(double a,double granularity)68 static inline double dml_ceil(double a, double granularity)
69 {
70 return (double) dcn_bw_ceil2(a, granularity);
71 }
72
dml_floor(double a,double granularity)73 static inline double dml_floor(double a, double granularity)
74 {
75 return (double) dcn_bw_floor2(a, granularity);
76 }
77
dml_log2(double x)78 static inline int dml_log2(double x)
79 {
80 return dml_round((double)dcn_bw_log(x, 2));
81 }
82
dml_pow(double a,int exp)83 static inline double dml_pow(double a, int exp)
84 {
85 return (double) dcn_bw_pow(a, exp);
86 }
87
dml_fmod(double f,int val)88 static inline double dml_fmod(double f, int val)
89 {
90 return (double) dcn_bw_mod(f, val);
91 }
92
dml_ceil_2(double f)93 static inline double dml_ceil_2(double f)
94 {
95 return (double) dcn_bw_ceil2(f, 2);
96 }
97
dml_ceil_ex(double x,double granularity)98 static inline double dml_ceil_ex(double x, double granularity)
99 {
100 return (double) dcn_bw_ceil2(x, granularity);
101 }
102
dml_floor_ex(double x,double granularity)103 static inline double dml_floor_ex(double x, double granularity)
104 {
105 return (double) dcn_bw_floor2(x, granularity);
106 }
107
dml_log(double x,double base)108 static inline double dml_log(double x, double base)
109 {
110 return (double) dcn_bw_log(x, base);
111 }
112
dml_round_to_multiple(unsigned int num,unsigned int multiple,bool up)113 static inline unsigned int dml_round_to_multiple(unsigned int num,
114 unsigned int multiple,
115 bool up)
116 {
117 unsigned int remainder;
118
119 if (multiple == 0)
120 return num;
121
122 remainder = num % multiple;
123
124 if (remainder == 0)
125 return num;
126
127 if (up)
128 return (num + multiple - remainder);
129 else
130 return (num - remainder);
131 }
132 #endif
133