Loading...
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 "dcn_calc_math.h"
30#include "dml_logger.h"
31
32static inline double dml_min(double a, double b)
33{
34 return (double) dcn_bw_min2(a, b);
35}
36
37static inline double dml_min3(double a, double b, double c)
38{
39 return dml_min(dml_min(a, b), c);
40}
41
42static inline double dml_min4(double a, double b, double c, double d)
43{
44 return dml_min(dml_min(a, b), dml_min(c, d));
45}
46
47static inline double dml_max(double a, double b)
48{
49 return (double) dcn_bw_max2(a, b);
50}
51
52static inline double dml_max3(double a, double b, double c)
53{
54 return dml_max(dml_max(a, b), c);
55}
56
57static inline double dml_max4(double a, double b, double c, double d)
58{
59 return dml_max(dml_max(a, b), dml_max(c, d));
60}
61
62static inline double dml_max5(double a, double b, double c, double d, double e)
63{
64 return dml_max(dml_max4(a, b, c, d), e);
65}
66
67static inline double dml_ceil(double a, double granularity)
68{
69 return (double) dcn_bw_ceil2(a, granularity);
70}
71
72static inline double dml_floor(double a, double granularity)
73{
74 return (double) dcn_bw_floor2(a, granularity);
75}
76
77static inline double dml_round(double a)
78{
79 const double round_pt = 0.5;
80
81 return dml_floor(a + round_pt, 1);
82}
83
84/* float
85static inline int dml_log2(float x)
86{
87 unsigned int ix = *((unsigned int *)&x);
88
89 return (int)((ix >> 23) & 0xff) - 127;
90}*/
91
92/* double */
93static inline int dml_log2(double x)
94{
95 unsigned long long ix = *((unsigned long long *)&x);
96
97 return (int)((ix >> 52) & 0x7ff) - 1023;
98}
99
100static inline double dml_pow(double a, int exp)
101{
102 return (double) dcn_bw_pow(a, exp);
103}
104
105static inline double dml_fmod(double f, int val)
106{
107 return (double) dcn_bw_mod(f, val);
108}
109
110static inline double dml_ceil_2(double f)
111{
112 return (double) dcn_bw_ceil2(f, 2);
113}
114
115static inline double dml_ceil_ex(double x, double granularity)
116{
117 return (double) dcn_bw_ceil2(x, granularity);
118}
119
120static inline double dml_floor_ex(double x, double granularity)
121{
122 return (double) dcn_bw_floor2(x, granularity);
123}
124
125static inline unsigned int dml_round_to_multiple(unsigned int num,
126 unsigned int multiple,
127 unsigned char up)
128{
129 unsigned int remainder;
130
131 if (multiple == 0)
132 return num;
133
134 remainder = num % multiple;
135
136 if (remainder == 0)
137 return num;
138
139 if (up)
140 return (num + multiple - remainder);
141 else
142 return (num - remainder);
143}
144static inline double dml_abs(double a)
145{
146 if (a > 0)
147 return a;
148 else
149 return (a*(-1));
150}
151
152#endif
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 "../calcs/dcn_calc_math.h"
31#include "dml_logger.h"
32
33static inline double dml_min(double a, double b)
34{
35 return (double) dcn_bw_min2(a, b);
36}
37
38static inline double dml_max(double a, double b)
39{
40 return (double) dcn_bw_max2(a, b);
41}
42
43static inline double dml_max3(double a, double b, double c)
44{
45 return dml_max(dml_max(a, b), c);
46}
47
48static inline double dml_max4(double a, double b, double c, double d)
49{
50 return dml_max(dml_max(a, b), dml_max(c, d));
51}
52
53static inline double dml_max5(double a, double b, double c, double d, double e)
54{
55 return dml_max(dml_max4(a, b, c, d), e);
56}
57
58static inline double dml_ceil(double a, double granularity)
59{
60 return (double) dcn_bw_ceil2(a, granularity);
61}
62
63static inline double dml_floor(double a, double granularity)
64{
65 return (double) dcn_bw_floor2(a, granularity);
66}
67
68static inline int dml_log2(double x)
69{
70 return dml_round((double)dcn_bw_log(x, 2));
71}
72
73static inline double dml_pow(double a, int exp)
74{
75 return (double) dcn_bw_pow(a, exp);
76}
77
78static inline double dml_fmod(double f, int val)
79{
80 return (double) dcn_bw_mod(f, val);
81}
82
83static inline double dml_ceil_2(double f)
84{
85 return (double) dcn_bw_ceil2(f, 2);
86}
87
88static inline double dml_ceil_ex(double x, double granularity)
89{
90 return (double) dcn_bw_ceil2(x, granularity);
91}
92
93static inline double dml_floor_ex(double x, double granularity)
94{
95 return (double) dcn_bw_floor2(x, granularity);
96}
97
98static inline double dml_log(double x, double base)
99{
100 return (double) dcn_bw_log(x, base);
101}
102
103static inline unsigned int dml_round_to_multiple(unsigned int num,
104 unsigned int multiple,
105 bool up)
106{
107 unsigned int remainder;
108
109 if (multiple == 0)
110 return num;
111
112 remainder = num % multiple;
113
114 if (remainder == 0)
115 return num;
116
117 if (up)
118 return (num + multiple - remainder);
119 else
120 return (num - remainder);
121}
122#endif