1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef __SH_CSS_FRAC_H
17#define __SH_CSS_FRAC_H
18
19#include <math_support.h>
20
21#define sISP_REG_BIT ISP_VEC_ELEMBITS
22#define uISP_REG_BIT ((unsigned int)(sISP_REG_BIT - 1))
23#define sSHIFT (16 - sISP_REG_BIT)
24#define uSHIFT ((unsigned int)(16 - uISP_REG_BIT))
25#define sFRACTION_BITS_FITTING(a) (a - sSHIFT)
26#define uFRACTION_BITS_FITTING(a) ((unsigned int)(a - uSHIFT))
27#define sISP_VAL_MIN (-(1 << uISP_REG_BIT))
28#define sISP_VAL_MAX ((1 << uISP_REG_BIT) - 1)
29#define uISP_VAL_MIN (0U)
30#define uISP_VAL_MAX ((unsigned int)((1 << uISP_REG_BIT) - 1))
31
32
33#define sDIGIT_FITTING(v, a, b) \
34 min_t(int, max_t(int, (((v) >> sSHIFT) >> max(sFRACTION_BITS_FITTING(a) - (b), 0)), \
35 sISP_VAL_MIN), sISP_VAL_MAX)
36#define uDIGIT_FITTING(v, a, b) \
37 min((unsigned int)max((unsigned)(((v) >> uSHIFT) \
38 >> max((int)(uFRACTION_BITS_FITTING(a) - (b)), 0)), \
39 uISP_VAL_MIN), uISP_VAL_MAX)
40
41#endif
42