Subversion Repositories Kolibri OS

Rev

Rev 4103 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4103 Rev 6336
Line 71... Line 71...
71
 
71
 
72
#define DRM_FIXED_POINT		32
72
#define DRM_FIXED_POINT		32
73
#define DRM_FIXED_ONE		(1ULL << DRM_FIXED_POINT)
73
#define DRM_FIXED_ONE		(1ULL << DRM_FIXED_POINT)
74
#define DRM_FIXED_DECIMAL_MASK	(DRM_FIXED_ONE - 1)
74
#define DRM_FIXED_DECIMAL_MASK	(DRM_FIXED_ONE - 1)
-
 
75
#define DRM_FIXED_DIGITS_MASK	(~DRM_FIXED_DECIMAL_MASK)
-
 
76
#define DRM_FIXED_EPSILON	1LL
Line 75... Line 77...
75
#define DRM_FIXED_DIGITS_MASK	(~DRM_FIXED_DECIMAL_MASK)
77
#define DRM_FIXED_ALMOST_ONE	(DRM_FIXED_ONE - DRM_FIXED_EPSILON)
76
 
78
 
77
static inline s64 drm_int2fixp(int a)
79
static inline s64 drm_int2fixp(int a)
78
{
80
{
Line 79... Line 81...
79
	return ((s64)a) << DRM_FIXED_POINT;
81
	return ((s64)a) << DRM_FIXED_POINT;
80
}
82
}
81
 
83
 
82
static inline int drm_fixp2int(int64_t a)
84
static inline int drm_fixp2int(s64 a)
Line -... Line 85...
-
 
85
{
-
 
86
	return ((s64)a) >> DRM_FIXED_POINT;
-
 
87
}
-
 
88
 
-
 
89
static inline int drm_fixp2int_ceil(s64 a)
-
 
90
{
-
 
91
	if (a > 0)
-
 
92
		return drm_fixp2int(a + DRM_FIXED_ALMOST_ONE);
83
{
93
	else
84
	return ((s64)a) >> DRM_FIXED_POINT;
94
		return drm_fixp2int(a - DRM_FIXED_ALMOST_ONE);
85
}
95
}
Line 86... Line 96...
86
 
96
 
87
static inline unsigned drm_fixp_msbset(int64_t a)
97
static inline unsigned drm_fixp_msbset(s64 a)
Line 134... Line 144...
134
		return result >> (shift - DRM_FIXED_POINT);
144
		return result >> (shift - DRM_FIXED_POINT);
Line 135... Line 145...
135
 
145
 
136
	return result;
146
	return result;
Line -... Line 147...
-
 
147
}
-
 
148
 
-
 
149
static inline s64 drm_fixp_from_fraction(s64 a, s64 b)
-
 
150
{
-
 
151
	s64 res;
-
 
152
	bool a_neg = a < 0;
-
 
153
	bool b_neg = b < 0;
-
 
154
	u64 a_abs = a_neg ? -a : a;
-
 
155
	u64 b_abs = b_neg ? -b : b;
-
 
156
	u64 rem;
-
 
157
 
-
 
158
	/* determine integer part */
-
 
159
	u64 res_abs  = div64_u64_rem(a_abs, b_abs, &rem);
-
 
160
 
-
 
161
	/* determine fractional part */
-
 
162
	{
-
 
163
		u32 i = DRM_FIXED_POINT;
-
 
164
 
-
 
165
		do {
-
 
166
			rem <<= 1;
-
 
167
			res_abs <<= 1;
-
 
168
			if (rem >= b_abs) {
-
 
169
				res_abs |= 1;
-
 
170
				rem -= b_abs;
-
 
171
			}
-
 
172
		} while (--i != 0);
-
 
173
	}
-
 
174
 
-
 
175
	/* round up LSB */
-
 
176
	{
-
 
177
		u64 summand = (rem << 1) >= b_abs;
-
 
178
 
-
 
179
		res_abs += summand;
-
 
180
	}
-
 
181
 
-
 
182
	res = (s64) res_abs;
-
 
183
	if (a_neg ^ b_neg)
-
 
184
		res = -res;
-
 
185
	return res;
137
}
186
}
138
 
187
 
139
static inline s64 drm_fixp_exp(s64 x)
188
static inline s64 drm_fixp_exp(s64 x)
140
{
189
{
141
	s64 tolerance = div64_s64(DRM_FIXED_ONE, 1000000);
190
	s64 tolerance = div64_s64(DRM_FIXED_ONE, 1000000);