1*b843c749SSergey Zigachev /*
2*b843c749SSergey Zigachev * Copyright 2017 Advanced Micro Devices, Inc.
3*b843c749SSergey Zigachev *
4*b843c749SSergey Zigachev * Permission is hereby granted, free of charge, to any person obtaining a
5*b843c749SSergey Zigachev * copy of this software and associated documentation files (the "Software"),
6*b843c749SSergey Zigachev * to deal in the Software without restriction, including without limitation
7*b843c749SSergey Zigachev * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*b843c749SSergey Zigachev * and/or sell copies of the Software, and to permit persons to whom the
9*b843c749SSergey Zigachev * Software is furnished to do so, subject to the following conditions:
10*b843c749SSergey Zigachev *
11*b843c749SSergey Zigachev * The above copyright notice and this permission notice shall be included in
12*b843c749SSergey Zigachev * all copies or substantial portions of the Software.
13*b843c749SSergey Zigachev *
14*b843c749SSergey Zigachev * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*b843c749SSergey Zigachev * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*b843c749SSergey Zigachev * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17*b843c749SSergey Zigachev * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*b843c749SSergey Zigachev * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*b843c749SSergey Zigachev * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*b843c749SSergey Zigachev * OTHER DEALINGS IN THE SOFTWARE.
21*b843c749SSergey Zigachev *
22*b843c749SSergey Zigachev * Authors: AMD
23*b843c749SSergey Zigachev *
24*b843c749SSergey Zigachev */
25*b843c749SSergey Zigachev
26*b843c749SSergey Zigachev #ifndef __DML_INLINE_DEFS_H__
27*b843c749SSergey Zigachev #define __DML_INLINE_DEFS_H__
28*b843c749SSergey Zigachev
29*b843c749SSergey Zigachev #include "dml_common_defs.h"
30*b843c749SSergey Zigachev #include "dcn_calc_math.h"
31*b843c749SSergey Zigachev #include "dml_logger.h"
32*b843c749SSergey Zigachev
dml_min(double a,double b)33*b843c749SSergey Zigachev static inline double dml_min(double a, double b)
34*b843c749SSergey Zigachev {
35*b843c749SSergey Zigachev return (double) dcn_bw_min2(a, b);
36*b843c749SSergey Zigachev }
37*b843c749SSergey Zigachev
dml_min3(double a,double b,double c)38*b843c749SSergey Zigachev static inline double dml_min3(double a, double b, double c)
39*b843c749SSergey Zigachev {
40*b843c749SSergey Zigachev return dml_min(dml_min(a, b), c);
41*b843c749SSergey Zigachev }
42*b843c749SSergey Zigachev
dml_min4(double a,double b,double c,double d)43*b843c749SSergey Zigachev static inline double dml_min4(double a, double b, double c, double d)
44*b843c749SSergey Zigachev {
45*b843c749SSergey Zigachev return dml_min(dml_min(a, b), dml_min(c, d));
46*b843c749SSergey Zigachev }
47*b843c749SSergey Zigachev
dml_max(double a,double b)48*b843c749SSergey Zigachev static inline double dml_max(double a, double b)
49*b843c749SSergey Zigachev {
50*b843c749SSergey Zigachev return (double) dcn_bw_max2(a, b);
51*b843c749SSergey Zigachev }
52*b843c749SSergey Zigachev
dml_max3(double a,double b,double c)53*b843c749SSergey Zigachev static inline double dml_max3(double a, double b, double c)
54*b843c749SSergey Zigachev {
55*b843c749SSergey Zigachev return dml_max(dml_max(a, b), c);
56*b843c749SSergey Zigachev }
57*b843c749SSergey Zigachev
dml_max4(double a,double b,double c,double d)58*b843c749SSergey Zigachev static inline double dml_max4(double a, double b, double c, double d)
59*b843c749SSergey Zigachev {
60*b843c749SSergey Zigachev return dml_max(dml_max(a, b), dml_max(c, d));
61*b843c749SSergey Zigachev }
62*b843c749SSergey Zigachev
dml_max5(double a,double b,double c,double d,double e)63*b843c749SSergey Zigachev static inline double dml_max5(double a, double b, double c, double d, double e)
64*b843c749SSergey Zigachev {
65*b843c749SSergey Zigachev return dml_max(dml_max4(a, b, c, d), e);
66*b843c749SSergey Zigachev }
67*b843c749SSergey Zigachev
dml_ceil(double a,double granularity)68*b843c749SSergey Zigachev static inline double dml_ceil(double a, double granularity)
69*b843c749SSergey Zigachev {
70*b843c749SSergey Zigachev return (double) dcn_bw_ceil2(a, granularity);
71*b843c749SSergey Zigachev }
72*b843c749SSergey Zigachev
dml_floor(double a,double granularity)73*b843c749SSergey Zigachev static inline double dml_floor(double a, double granularity)
74*b843c749SSergey Zigachev {
75*b843c749SSergey Zigachev return (double) dcn_bw_floor2(a, granularity);
76*b843c749SSergey Zigachev }
77*b843c749SSergey Zigachev
dml_log2(double x)78*b843c749SSergey Zigachev static inline int dml_log2(double x)
79*b843c749SSergey Zigachev {
80*b843c749SSergey Zigachev return dml_round((double)dcn_bw_log(x, 2));
81*b843c749SSergey Zigachev }
82*b843c749SSergey Zigachev
dml_pow(double a,int exp)83*b843c749SSergey Zigachev static inline double dml_pow(double a, int exp)
84*b843c749SSergey Zigachev {
85*b843c749SSergey Zigachev return (double) dcn_bw_pow(a, exp);
86*b843c749SSergey Zigachev }
87*b843c749SSergey Zigachev
dml_fmod(double f,int val)88*b843c749SSergey Zigachev static inline double dml_fmod(double f, int val)
89*b843c749SSergey Zigachev {
90*b843c749SSergey Zigachev return (double) dcn_bw_mod(f, val);
91*b843c749SSergey Zigachev }
92*b843c749SSergey Zigachev
dml_ceil_2(double f)93*b843c749SSergey Zigachev static inline double dml_ceil_2(double f)
94*b843c749SSergey Zigachev {
95*b843c749SSergey Zigachev return (double) dcn_bw_ceil2(f, 2);
96*b843c749SSergey Zigachev }
97*b843c749SSergey Zigachev
dml_ceil_ex(double x,double granularity)98*b843c749SSergey Zigachev static inline double dml_ceil_ex(double x, double granularity)
99*b843c749SSergey Zigachev {
100*b843c749SSergey Zigachev return (double) dcn_bw_ceil2(x, granularity);
101*b843c749SSergey Zigachev }
102*b843c749SSergey Zigachev
dml_floor_ex(double x,double granularity)103*b843c749SSergey Zigachev static inline double dml_floor_ex(double x, double granularity)
104*b843c749SSergey Zigachev {
105*b843c749SSergey Zigachev return (double) dcn_bw_floor2(x, granularity);
106*b843c749SSergey Zigachev }
107*b843c749SSergey Zigachev
dml_log(double x,double base)108*b843c749SSergey Zigachev static inline double dml_log(double x, double base)
109*b843c749SSergey Zigachev {
110*b843c749SSergey Zigachev return (double) dcn_bw_log(x, base);
111*b843c749SSergey Zigachev }
112*b843c749SSergey Zigachev
dml_round_to_multiple(unsigned int num,unsigned int multiple,bool up)113*b843c749SSergey Zigachev static inline unsigned int dml_round_to_multiple(unsigned int num,
114*b843c749SSergey Zigachev unsigned int multiple,
115*b843c749SSergey Zigachev bool up)
116*b843c749SSergey Zigachev {
117*b843c749SSergey Zigachev unsigned int remainder;
118*b843c749SSergey Zigachev
119*b843c749SSergey Zigachev if (multiple == 0)
120*b843c749SSergey Zigachev return num;
121*b843c749SSergey Zigachev
122*b843c749SSergey Zigachev remainder = num % multiple;
123*b843c749SSergey Zigachev
124*b843c749SSergey Zigachev if (remainder == 0)
125*b843c749SSergey Zigachev return num;
126*b843c749SSergey Zigachev
127*b843c749SSergey Zigachev if (up)
128*b843c749SSergey Zigachev return (num + multiple - remainder);
129*b843c749SSergey Zigachev else
130*b843c749SSergey Zigachev return (num - remainder);
131*b843c749SSergey Zigachev }
132*b843c749SSergey Zigachev #endif
133