1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
* Copyright (C) 2018, NVIDIA CORPORATION. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef _FIXED_POINT_H
#define _FIXED_POINT_H
struct fixed_point {
unsigned int int_part;
unsigned int frac_part;
unsigned int int_prec;
unsigned int frac_prec;
unsigned int int_mask;
unsigned int frac_mask;
};
struct fixed_point fixed_point_init(
unsigned int int_part,
unsigned int frac_part,
unsigned int int_prec,
unsigned int frac_prec,
unsigned int *error);
struct fixed_point fixed_point_shift_left(
struct fixed_point fp_arg,
unsigned int places,
unsigned int *error);
struct fixed_point fixed_point_shift_right(
struct fixed_point fp_arg,
unsigned int places,
unsigned int *error);
struct fixed_point fixed_point_negate(
struct fixed_point fp_arg,
unsigned int *error);
struct fixed_point fixed_point_add(
struct fixed_point fp_arg1,
struct fixed_point fp_arg2,
unsigned int *error);
/* returns difference = minuend - subtrahend */
struct fixed_point fixed_point_sub(
struct fixed_point minuend_arg,
struct fixed_point subtrahend_arg,
unsigned int *error);
struct fixed_point fixed_point_mult(
struct fixed_point fp_arg1,
struct fixed_point fp_arg2,
unsigned int *error);
/* returns quotient = dividend / divisor*/
struct fixed_point fixed_point_div(
struct fixed_point dividend_arg,
struct fixed_point divisor_arg,
unsigned int *error);
/* Return 1 is lhs < rhs, 0 otherwise */
int fixed_point_lt(
struct fixed_point fp_lhs_arg,
struct fixed_point fp_rhs_arg,
unsigned int *error);
/* Return 1 is lhs > rhs, 0 otherwise */
int fixed_point_gt(
struct fixed_point fp_lhs_arg,
struct fixed_point fp_rhs_arg,
unsigned int *error);
/* Return 1 is lhs <= rhs, 0 otherwise */
int fixed_point_loet(
struct fixed_point fp_lhs_arg,
struct fixed_point fp_rhs_arg,
unsigned int *error);
/* Return 1 is lhs >= rhs, 0 otherwise */
int fixed_point_goet(
struct fixed_point fp_lhs_arg,
struct fixed_point fp_rhs_arg,
unsigned int *error);
/* Return 1 is lhs == rhs, 0 otherwise */
int fixed_point_eq(
struct fixed_point fp_lhs_arg,
struct fixed_point fp_rhs_arg,
unsigned int *error);
int fixed_point_to_int(
struct fixed_point fp_arg,
unsigned int *error);
int fixed_point_ceil(
struct fixed_point fp_arg,
unsigned int *error);
struct fixed_point fixed_point_min(
struct fixed_point fp_arg1,
struct fixed_point fp_arg2,
unsigned int *error);
struct fixed_point fixed_point_max(
struct fixed_point fp_arg1,
struct fixed_point fp_arg2,
unsigned int *error);
#endif /* _FIXED_POINT_H */
|