2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #ifndef __SH_CSS_FRAC_H
16 #define __SH_CSS_FRAC_H
18 #include <math_support.h>
20 #define sISP_REG_BIT ISP_VEC_ELEMBITS
21 #define uISP_REG_BIT ((unsigned)(sISP_REG_BIT-1))
22 #define sSHIFT (16-sISP_REG_BIT)
23 #define uSHIFT ((unsigned)(16-uISP_REG_BIT))
24 #define sFRACTION_BITS_FITTING(a) (a-sSHIFT)
25 #define uFRACTION_BITS_FITTING(a) ((unsigned)(a-uSHIFT))
26 #define sISP_VAL_MIN (-(1<<uISP_REG_BIT))
27 #define sISP_VAL_MAX ((1<<uISP_REG_BIT)-1)
28 #define uISP_VAL_MIN ((unsigned)0)
29 #define uISP_VAL_MAX ((unsigned)((1<<uISP_REG_BIT)-1))
31 /* a:fraction bits for 16bit precision, b:fraction bits for ISP precision */
32 #define sDIGIT_FITTING(v, a, b) \
33 min(max((((v)>>sSHIFT) >> max(sFRACTION_BITS_FITTING(a)-(b), 0)), \
34 sISP_VAL_MIN), sISP_VAL_MAX)
35 #define uDIGIT_FITTING(v, a, b) \
36 min((unsigned)max((unsigned)(((v)>>uSHIFT) \
37 >> max((int)(uFRACTION_BITS_FITTING(a)-(b)), 0)), \
38 uISP_VAL_MIN), uISP_VAL_MAX)
40 #endif /* __SH_CSS_FRAC_H */