blob: fb52a001193a7b1a81663b5c186ef7b3b1149bda [file] [log] [blame]
Shad Ansari2f7f9be2017-06-07 13:34:53 -07001/*
2<:copyright-BRCM:2016:DUAL/GPL:standard
3
4 Broadcom Proprietary and Confidential.(c) 2016 Broadcom
5 All Rights Reserved
6
7Unless you and Broadcom execute a separate written software license
8agreement governing use of this software, this software is licensed
9to you under the terms of the GNU General Public License version 2
10(the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
11with the following added to such license:
12
13 As a special exception, the copyright holders of this software give
14 you permission to link this software with independent modules, and
15 to copy and distribute the resulting executable under terms of your
16 choice, provided that you also meet, for each linked independent
17 module, the terms and conditions of the license of that module.
18 An independent module is a module which is not derived from this
19 software. The special exception does not apply to any modifications
20 of the software.
21
22Not withstanding the above, under no circumstances may you combine
23this software in any way with any other Broadcom software provided
24under a license other than the GPL, without Broadcom's express prior
25written consent.
26
27:>
28 */
29
30#ifndef _BCMOLT_MATH_H_
31#define _BCMOLT_MATH_H_
32
33#include <math.h>
34
35#define ROUND_U32(size_in_bytes) ((uint32_t)((size_in_bytes) + 0.5))
36#define CEIL_U32(size_in_bytes) (((size_in_bytes)-(uint32_t)(size_in_bytes)) > 0 ? ((uint32_t)(size_in_bytes)+1) : (uint32_t)(size_in_bytes))
37#define SQUARE(x) ((x) * (x))
38#define PERCENT(percent, x) (((float)(percent) * (x)) / 100)
39
40/*
41 * Unit Conversion
42 */
43#define BITS_TO_BYTES(bits) ((bits) >> 3)
44#define BYTES_TO_BITS(bytes) ((bytes) << 3)
45
46/* Quantization */
47
48/*
49 * VAL_TO_BIN classifies the value of val to the proper bin
50 * val - a value in the range [0, maxval]
51 * bin - a value in the range [0, bins-1] (result of macro)
52 */
53#define VAL_TO_BIN(val, maxval, bins) ((val) < (maxval) ? ((val) * (bins)) / (maxval) : (bins) - 1)
54
55/* If a value is in a certain bin, it is in the range [min_bin_val, max_bin_val]
56 * min_bin_val - minimum value that belongs to bin
57 * max_bin_val - maximum value that belongs to bin
58 */
59#define BIN_TO_MIN_BIN_VAL(bin, maxval, bins) ((bin) * ((double)(maxval) / (bins)))
60#define BIN_TO_MAX_BIN_VAL(bin, maxval, bins) (((bin) + 1) * ((double)(maxval) / (bins)))
61
62#define GET_MASK(width) ((1 << (width)) - 1)
63
64#define MAX(a, b) ((a) > (b) ? (a) : (b))
65#define MIN(a, b) ((a) < (b) ? (a) : (b))
66#define MAX3(a, b, c) MAX(MAX(a, b), c)
67#define MIN3(a, b, c) MIN(MIN(a, b), c)
68
69#define CEILING(a, b) (((a) + ((b) - 1)) / (b))
70
71#endif /* _BCMOLT_MATH_H_ */