Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2017 Advanced Micro Devices, Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: AMD
0023  *
0024  */
0025 
0026 #ifndef __DML_INLINE_DEFS_H__
0027 #define __DML_INLINE_DEFS_H__
0028 
0029 #include "dcn_calc_math.h"
0030 #include "dml_logger.h"
0031 
0032 static inline double dml_min(double a, double b)
0033 {
0034     return (double) dcn_bw_min2(a, b);
0035 }
0036 
0037 static inline double dml_min3(double a, double b, double c)
0038 {
0039     return dml_min(dml_min(a, b), c);
0040 }
0041 
0042 static inline double dml_min4(double a, double b, double c, double d)
0043 {
0044     return dml_min(dml_min(a, b), dml_min(c, d));
0045 }
0046 
0047 static inline double dml_max(double a, double b)
0048 {
0049     return (double) dcn_bw_max2(a, b);
0050 }
0051 
0052 static inline double dml_max3(double a, double b, double c)
0053 {
0054     return dml_max(dml_max(a, b), c);
0055 }
0056 
0057 static inline double dml_max4(double a, double b, double c, double d)
0058 {
0059     return dml_max(dml_max(a, b), dml_max(c, d));
0060 }
0061 
0062 static inline double dml_max5(double a, double b, double c, double d, double e)
0063 {
0064     return dml_max(dml_max4(a, b, c, d), e);
0065 }
0066 
0067 static inline double dml_ceil(double a, double granularity)
0068 {
0069     return (double) dcn_bw_ceil2(a, granularity);
0070 }
0071 
0072 static inline double dml_floor(double a, double granularity)
0073 {
0074     return (double) dcn_bw_floor2(a, granularity);
0075 }
0076 
0077 static inline double dml_round(double a)
0078 {
0079     double round_pt = 0.5;
0080     double ceil = dml_ceil(a, 1);
0081     double floor = dml_floor(a, 1);
0082 
0083     if (a - floor >= round_pt)
0084         return ceil;
0085     else
0086         return floor;
0087 }
0088 
0089 /* float
0090 static inline int dml_log2(float x)
0091 {
0092     unsigned int ix = *((unsigned int *)&x);
0093 
0094     return (int)((ix >> 23) & 0xff) - 127;
0095 }*/
0096 
0097 /* double */
0098 static inline int dml_log2(double x)
0099 {
0100     unsigned long long ix = *((unsigned long long *)&x);
0101 
0102     return (int)((ix >> 52) & 0x7ff) - 1023;
0103 }
0104 
0105 static inline double dml_pow(double a, int exp)
0106 {
0107     return (double) dcn_bw_pow(a, exp);
0108 }
0109 
0110 static inline double dml_fmod(double f, int val)
0111 {
0112     return (double) dcn_bw_mod(f, val);
0113 }
0114 
0115 static inline double dml_ceil_2(double f)
0116 {
0117     return (double) dcn_bw_ceil2(f, 2);
0118 }
0119 
0120 static inline double dml_ceil_ex(double x, double granularity)
0121 {
0122     return (double) dcn_bw_ceil2(x, granularity);
0123 }
0124 
0125 static inline double dml_floor_ex(double x, double granularity)
0126 {
0127     return (double) dcn_bw_floor2(x, granularity);
0128 }
0129 
0130 static inline unsigned int dml_round_to_multiple(unsigned int num,
0131                          unsigned int multiple,
0132                          unsigned char up)
0133 {
0134     unsigned int remainder;
0135 
0136     if (multiple == 0)
0137         return num;
0138 
0139     remainder = num % multiple;
0140 
0141     if (remainder == 0)
0142         return num;
0143 
0144     if (up)
0145         return (num + multiple - remainder);
0146     else
0147         return (num - remainder);
0148 }
0149 static inline double dml_abs(double a)
0150 {
0151     if (a > 0)
0152         return a;
0153     else
0154         return (a*(-1));
0155 }
0156 
0157 #endif