Merge tag 'armsoc-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[sfrench/cifs-2.6.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / hive_isp_css_include / host / isp_op2w.h
1 /*
2  * Support for Intel Camera Imaging ISP subsystem.
3  * Copyright (c) 2015, Intel Corporation.
4  *
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.
8  *
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
12  * more details.
13  */
14
15 #ifndef __ISP_OP2W_H_INCLUDED__
16 #define __ISP_OP2W_H_INCLUDED__
17
18 /*
19  * This file is part of the Multi-precision vector operations exstension package.
20  */
21
22 /*
23  * Double-precision vector operations
24  */
25
26 /*
27  * Prerequisites:
28  *
29  */
30
31 #ifdef INLINE_ISP_OP2W
32 #define STORAGE_CLASS_ISP_OP2W_FUNC_H static inline
33 #define STORAGE_CLASS_ISP_OP2W_DATA_H static inline_DATA
34 #else /* INLINE_ISP_OP2W */
35 #define STORAGE_CLASS_ISP_OP2W_FUNC_H extern
36 #define STORAGE_CLASS_ISP_OP2W_DATA_H extern_DATA
37 #endif  /* INLINE_ISP_OP2W */
38
39 /*
40  * Double-precision data type specification
41  */
42
43 #include "isp_op2w_types.h"
44
45 /*
46  * Double-precision prototype specification
47  */
48
49 /* Arithmetic */
50
51 /* @brief bitwise AND
52  *
53  * @param[in] _a        first argument
54  * @param[in] _b        second argument
55  *
56  * @return              bitwise and of both input arguments
57  *
58  * This function will calculate the bitwise and.
59  * result = _a & _b
60  */
61 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_and(
62     const tvector2w     _a,
63     const tvector2w     _b);
64
65 /* @brief bitwise OR
66  *
67  * @param[in] _a        first argument
68  * @param[in] _b        second argument
69  *
70  * @return              bitwise or of both input arguments
71  *
72  * This function will calculate the bitwise or.
73  * result = _a | _b
74  */
75 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_or(
76     const tvector2w     _a,
77     const tvector2w     _b);
78
79 /* @brief bitwise XOR
80  *
81  * @param[in] _a        first argument
82  * @param[in] _b        second argument
83  *
84  * @return              bitwise xor of both input arguments
85  *
86  * This function will calculate the bitwise xor.
87  * result = _a ^ _b
88  */
89 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_xor(
90     const tvector2w     _a,
91     const tvector2w     _b);
92
93 /* @brief bitwise inverse
94  *
95  * @param[in] _a        first argument
96  *
97  * @return              bitwise inverse of both input arguments
98  *
99  * This function will calculate the bitwise inverse.
100  * result = ~_a
101  */
102 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_inv(
103     const tvector2w     _a);
104
105 /* Additive */
106
107 /* @brief addition
108  *
109  * @param[in] _a        first argument
110  * @param[in] _b        second argument
111  *
112  * @return              sum of both input arguments
113  *
114  * This function will calculate the sum of the input arguments.
115  * in case of overflow it will wrap around.
116  * result = _a + _b
117  */
118 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_add(
119     const tvector2w     _a,
120     const tvector2w     _b);
121
122 /* @brief subtraction
123  *
124  * @param[in] _a        first argument
125  * @param[in] _b        second argument
126  *
127  * @return              _b subtracted from _a.
128  *
129  * This function will subtract _b from _a.
130  * in case of overflow it will wrap around.
131  * result = _a - _b
132  */
133 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_sub(
134     const tvector2w     _a,
135     const tvector2w     _b);
136
137 /* @brief saturated addition
138  *
139  * @param[in] _a        first argument
140  * @param[in] _b        second argument
141  *
142  * @return              saturated sum of both input arguments
143  *
144  * This function will calculate the sum of the input arguments.
145  * in case of overflow it will saturate
146  * result = CLIP(_a + _b, MIN_RANGE, MAX_RANGE);
147  */
148 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_addsat(
149     const tvector2w     _a,
150     const tvector2w     _b);
151
152 /* @brief saturated subtraction
153  *
154  * @param[in] _a        first argument
155  * @param[in] _b        second argument
156  *
157  * @return              saturated subtraction of both input arguments
158  *
159  * This function will subtract _b from _a.
160  * in case of overflow it will saturate
161  * result = CLIP(_a - _b, MIN_RANGE, MAX_RANGE);
162  */
163 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subsat(
164     const tvector2w     _a,
165     const tvector2w     _b);
166
167 /* @brief subtraction with shift right and rounding
168  *
169  * @param[in] _a        first argument
170  * @param[in] _b        second argument
171  *
172  * @return              (a - b) >> 1
173  *
174  * This function subtracts _b from _a and right shifts
175  * the result by 1 bit with rounding.
176  * No overflow can occur.
177  * result = (_a - _b) >> 1
178  *
179  * Note: This function will be deprecated due to
180  * the naming confusion and it will be replaced
181  * by "OP_2w_subhalfrnd".
182  */
183 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subasr1(
184     const tvector2w     _a,
185     const tvector2w     _b);
186
187 /* @brief Subtraction with shift right and rounding
188  *
189  * @param[in] _a        first operand
190  * @param[in] _b        second operand
191  *
192  * @return              (_a - _b) >> 1
193  *
194  * This function subtracts _b from _a and right shifts
195  * the result by 1 bit with rounding.
196  * No overflow can occur.
197  */
198 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subhalfrnd(
199     const tvector2w     _a,
200     const tvector2w     _b);
201
202 /* @brief Subtraction with shift right and no rounding
203  *
204  * @param[in] _a        first operand
205  * @param[in] _b        second operand
206  *
207  * @return              (_a - _b) >> 1
208  *
209  * This function subtracts _b from _a and right shifts
210  * the result by 1 bit without rounding (i.e. truncation).
211  * No overflow can occur.
212  */
213 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subhalf(
214     const tvector2w     _a,
215     const tvector2w     _b);
216
217 /* @brief saturated absolute value
218  *
219  * @param[in] _a        input
220  *
221  * @return              saturated absolute value of the input
222  *
223  * This function will calculate the saturated absolute value of the input.
224  * In case of overflow it will saturate.
225  * if (_a > 0) return _a;<br>
226  * else return CLIP(-_a, MIN_RANGE, MAX_RANGE);<br>
227  */
228 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_abs(
229     const tvector2w     _a);
230
231 /* @brief saturated absolute difference
232  *
233  * @param[in] _a        first argument
234  * @param[in] _b        second argument
235  *
236  * @return              sat(abs(sat(a-b)));
237  *
238  * This function will calculate the saturated absolute value
239  * of the saturated difference of both inputs.
240  * result = sat(abs(sat(_a - _b)));
241  */
242 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_subabssat(
243     const tvector2w     _a,
244     const tvector2w     _b);
245
246 /* Multiplicative */
247
248 /* @brief integer multiply
249  *
250  * @param[in] _a        first argument
251  * @param[in] _b        second argument
252  *
253  * @return              product of _a and _b
254  *
255  * This function will calculate the product
256  * of the input arguments and returns the LSB
257  * aligned double precision result.
258  * In case of overflow it will wrap around.
259  * result = _a * _b;
260  */
261 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_mul(
262     const tvector2w     _a,
263     const tvector2w     _b);
264
265 /* @brief fractional saturating multiply
266  *
267  * @param[in] _a        first argument
268  * @param[in] _b        second argument
269  *
270  * @return              saturated product of _a and _b
271  *
272  * This function will calculate the fixed point
273  * product of the input arguments
274  * and returns a double precision result.
275  * In case of overflow it will saturate.
276  * result =((_a * _b) << 1) >> (2*NUM_BITS);
277  */
278 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_qmul(
279     const tvector2w     _a,
280     const tvector2w     _b);
281
282 /* @brief fractional saturating multiply with rounding
283  *
284  * @param[in] _a        first argument
285  * @param[in] _b        second argument
286  *
287  * @return              product of _a and _b
288  *
289  * This function will calculate the fixed point
290  * product of the input arguments
291  * and returns a double precision result.
292  * Depending on the rounding mode of the core
293  * it will round to nearest or to nearest even.
294  * In case of overflow it will saturate.
295  * result = ((_a * _b) << 1) >> (2*NUM_BITS);
296  */
297
298 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_qrmul(
299     const tvector2w     _a,
300     const tvector2w     _b);
301
302 /* Comparative */
303
304 /* @brief equal
305  *
306  * @param[in] _a        first argument
307  * @param[in] _b        second argument
308  *
309  * @return              _a == _b
310  *
311  * This function will return true if both inputs
312  * are equal, and false if not equal.
313  */
314 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_eq(
315     const tvector2w     _a,
316     const tvector2w     _b);
317
318 /* @brief not equal
319  *
320  * @param[in] _a        first argument
321  * @param[in] _b        second argument
322  *
323  * @return              _a != _b
324  *
325  * This function will return false if both inputs
326  * are equal, and true if not equal.
327  */
328 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_ne(
329     const tvector2w     _a,
330     const tvector2w     _b);
331
332 /* @brief less or equal
333  *
334  * @param[in] _a        first argument
335  * @param[in] _b        second argument
336  *
337  * @return              _a <= _b
338  *
339  * This function will return true if _a is smaller
340  * or equal than _b.
341  */
342 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_le(
343     const tvector2w     _a,
344     const tvector2w     _b);
345
346 /* @brief less then
347  *
348  * @param[in] _a        first argument
349  * @param[in] _b        second argument
350  *
351  * @return              _a < _b
352  *
353  * This function will return true if _a is smaller
354  * than _b.
355  */
356 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_lt(
357     const tvector2w     _a,
358     const tvector2w     _b);
359
360 /* @brief greater or equal
361  *
362  * @param[in] _a        first argument
363  * @param[in] _b        second argument
364  *
365  * @return              _a >= _b
366  *
367  * This function will return true if _a is greater
368  * or equal than _b.
369  */
370 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_ge(
371     const tvector2w     _a,
372     const tvector2w     _b);
373
374 /* @brief greater than
375  *
376  * @param[in] _a        first argument
377  * @param[in] _b        second argument
378  *
379  * @return              _a > _b
380  *
381  * This function will return true if _a is greater
382  * than _b.
383  */
384 STORAGE_CLASS_ISP_OP2W_FUNC_H tflags OP_2w_gt(
385     const tvector2w     _a,
386     const tvector2w     _b);
387
388 /* Shift */
389
390 /* @brief aritmetic shift right
391  *
392  * @param[in] _a        input
393  * @param[in] _b        shift amount
394  *
395  * @return              _a >> _b
396  *
397  * This function will shift _a with _b bits to the right,
398  * preserving the sign bit.
399  * It asserts 0 <= _b <= MAX_SHIFT_2W.
400  * The operation count for this function assumes that
401  * the shift amount is a cloned scalar input.
402  */
403 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_asr(
404     const tvector2w     _a,
405     const tvector2w     _b);
406
407 /* @brief aritmetic shift right with rounding
408  *
409  * @param[in] _a        input
410  * @param[in] _b        shift amount
411  *
412  * @return              _a >> _b
413  *
414  * If _b < 2*NUM_BITS, this function will shift _a with _b bits to the right,
415  * preserving the sign bit, and depending on the rounding mode of the core
416  * it will round to nearest or to nearest even.
417  * If _b >= 2*NUM_BITS, this function will return 0.
418  * It asserts 0 <= _b <= MAX_SHIFT_2W.
419  * The operation count for this function assumes that
420  * the shift amount is a cloned scalar input.
421  */
422 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_asrrnd(
423     const tvector2w     _a,
424     const tvector2w     _b);
425
426 /* @brief saturating aritmetic shift left
427  *
428  * @param[in] _a        input
429  * @param[in] _b        shift amount
430  *
431  * @return              _a << _b
432  *
433  * If _b < MAX_BITDEPTH, this function will shift _a with _b bits to the left,
434  * saturating at MIN_RANGE/MAX_RANGE in case of overflow.
435  * If _b >= MAX_BITDEPTH, this function will return MIN_RANGE if _a < 0,
436  * MAX_RANGE if _a > 0, 0 if _a == 0.
437  * (with MAX_BITDEPTH=64)
438  * It asserts 0 <= _b <= MAX_SHIFT_2W.
439  * The operation count for this function assumes that
440  * the shift amount is a cloned scalar input.
441  */
442 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_asl(
443     const tvector2w     _a,
444     const tvector2w     _b);
445
446 /* @brief saturating aritmetic shift left
447  *
448  * @param[in] _a        input
449  * @param[in] _b        shift amount
450  *
451  * @return              _a << _b
452  *
453  * This function is identical to OP_2w_asl( )
454  */
455 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_aslsat(
456     const tvector2w     _a,
457     const tvector2w     _b);
458
459 /* @brief logical shift left
460  *
461  * @param[in] _a        input
462  * @param[in] _b        shift amount
463  *
464  * @return              _a << _b
465  *
466  * This function will shift _a with _b bits to the left.
467  * It will insert zeroes on the right.
468  * It asserts 0 <= _b <= MAX_SHIFT_2W.
469  * The operation count for this function assumes that
470  * the shift amount is a cloned scalar input.
471  */
472 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_lsl(
473     const tvector2w     _a,
474     const tvector2w     _b);
475
476 /* @brief logical shift right
477  *
478  * @param[in] _a        input
479  * @param[in] _b        shift amount
480  *
481  * @return              _a >> _b
482  *
483  * This function will shift _a with _b bits to the right.
484  * It will insert zeroes on the left.
485  * It asserts 0 <= _b <= MAX_SHIFT_2W.
486  * The operation count for this function assumes that
487  * the shift amount is a cloned scalar input.
488  */
489 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_lsr(
490     const tvector2w     _a,
491     const tvector2w     _b);
492
493 /* clipping */
494
495 /* @brief Clip asymmetrical
496  *
497  * @param[in] _a        first argument
498  * @param[in] _b        second argument
499  *
500  * @return              _a clipped between ~_b and b
501  *
502  * This function will clip the first argument between
503  * (-_b - 1) and _b.
504  * It asserts _b >= 0.
505  */
506 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_clip_asym(
507     const tvector2w     _a,
508     const tvector2w     _b);
509
510 /* @brief Clip zero
511  *
512  * @param[in] _a        first argument
513  * @param[in] _b        second argument
514  *
515  * @return              _a clipped beteween 0 and _b
516  *
517  * This function will clip the first argument between
518  * zero and _b.
519  * It asserts _b >= 0.
520  */
521 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_clipz(
522     const tvector2w     _a,
523     const tvector2w     _b);
524
525 /* division */
526
527 /* @brief Truncated division
528  *
529  * @param[in] _a        first argument
530  * @param[in] _b        second argument
531  *
532  * @return              trunc( _a / _b )
533  *
534  * This function will divide the first argument by
535  * the second argument, with rounding toward 0.
536  * If _b == 0 and _a <  0, the function will return MIN_RANGE.
537  * If _b == 0 and _a == 0, the function will return 0.
538  * If _b == 0 and _a >  0, the function will return MAX_RANGE.
539  */
540 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_div(
541     const tvector2w     _a,
542     const tvector2w     _b);
543
544 /* @brief Saturating truncated division
545  *
546  * @param[in] _a        first argument
547  * @param[in] _b        second argument
548  *
549  * @return              CLIP( trunc( _a / _b ), MIN_RANGE1w, MAX_RANGE1w )
550  *
551  * This function will divide the first argument by
552  * the second argument, with rounding toward 0, and
553  * saturate the result to the range of single precision.
554  * If _b == 0 and _a <  0, the function will return MIN_RANGE.
555  * If _b == 0 and _a == 0, the function will return 0.
556  * If _b == 0 and _a >  0, the function will return MAX_RANGE.
557  */
558 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector1w OP_2w_divh(
559     const tvector2w     _a,
560     const tvector1w     _b);
561
562 /* @brief Modulo
563  *
564  * @param[in] _a        first argument
565  * @param[in] _b        second argument
566  *
567  * @return              n/a
568  *
569  * This function has not yet been implemented.
570  */
571 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_mod(
572     const tvector2w     _a,
573     const tvector2w     _b);
574
575 /* @brief Unsigned Integer Square root
576  *
577  * @param[in] _a        input
578  *
579  * @return              square root of _a
580  *
581  * This function will calculate the unsigned integer square root of _a
582  */
583 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector1w_unsigned OP_2w_sqrt_u(
584         const tvector2w_unsigned     _a);
585
586 /* Miscellaneous */
587
588 /* @brief Multiplexer
589  *
590  * @param[in] _a        first argument
591  * @param[in] _b        second argument
592  * @param[in] _c        condition
593  *
594  * @return              _c ? _a : _b
595  *
596  * This function will return _a if the condition _c
597  * is true and _b otherwise.
598  */
599 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_mux(
600     const tvector2w     _a,
601     const tvector2w     _b,
602     const tflags           _c);
603
604 /* @brief Average without rounding
605  *
606  * @param[in] _a        first operand
607  * @param[in] _b        second operand
608  *
609  * @return              (_a + _b) >> 1
610  *
611  * This function will add _a and _b, and right shift
612  * the result by one without rounding. No overflow
613  * will occur because addition is performed in the
614  * proper precision.
615  */
616 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w  OP_2w_avg(
617     const tvector2w     _a,
618     const tvector2w     _b);
619
620 /* @brief Average with rounding
621  *
622  * @param[in] _a        first argument
623  * @param[in] _b        second argument
624  *
625  * @return              (_a + _b) >> 1
626  *
627  * This function will add _a and _b at full precision,
628  * and right shift with rounding the result with 1 bit.
629  * Depending on the rounding mode of the core
630  * it will round to nearest or to nearest even.
631  */
632 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_avgrnd(
633     const tvector2w     _a,
634     const tvector2w     _b);
635
636 /* @brief Minimum
637  *
638  * @param[in] _a        first argument
639  * @param[in] _b        second argument
640  *
641  * @return              (_a < _b) ? _a : _b;
642  *
643  * This function will return the smallest of both
644  * input arguments.
645  */
646 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_min(
647     const tvector2w     _a,
648     const tvector2w     _b);
649
650 /* @brief Maximum
651  *
652  * @param[in] _a        first argument
653  * @param[in] _b        second argument
654  *
655  * @return              (_a > _b) ? _a : _b;
656  *
657  * This function will return the largest of both
658  * input arguments.
659  */
660 STORAGE_CLASS_ISP_OP2W_FUNC_H tvector2w OP_2w_max(
661     const tvector2w     _a,
662     const tvector2w     _b);
663
664 #ifndef INLINE_ISP_OP2W
665 #define STORAGE_CLASS_ISP_OP2W_FUNC_C
666 #define STORAGE_CLASS_ISP_OP2W_DATA_C const
667 #else /* INLINE_ISP_OP2W */
668 #define STORAGE_CLASS_ISP_OP2W_FUNC_C STORAGE_CLASS_ISP_OP2W_FUNC_H
669 #define STORAGE_CLASS_ISP_OP2W_DATA_C STORAGE_CLASS_ISP_OP2W_DATA_H
670 #include "isp_op2w.c"
671 #define ISP_OP2W_INLINED
672 #endif  /* INLINE_ISP_OP2W */
673
674 #endif /* __ISP_OP2W_H_INCLUDED__ */