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