~gnome3-team/mutter/trunk

« back to all changes in this revision

Viewing changes to cogl/cogl/deprecated/cogl-fixed.h

  • Committer: Rui Matos
  • Date: 2016-04-27 16:36:25 UTC
  • mfrom: (0.87.3184)
  • Revision ID: git-v1:3fcbe1d3ec5c9208dde080f7e9dac24e4c379bc0
Merge cogl's cogl-1.22 branch into mutter

https://bugzilla.gnome.org/show_bug.cgi?id=760439

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Cogl
 
3
 *
 
4
 * A Low Level GPU Graphics and Utilities API
 
5
 *
 
6
 * Copyright (C) 2007,2008,2009 Intel Corporation.
 
7
 *
 
8
 * Permission is hereby granted, free of charge, to any person
 
9
 * obtaining a copy of this software and associated documentation
 
10
 * files (the "Software"), to deal in the Software without
 
11
 * restriction, including without limitation the rights to use, copy,
 
12
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 
13
 * of the Software, and to permit persons to whom the Software is
 
14
 * furnished to do so, subject to the following conditions:
 
15
 *
 
16
 * The above copyright notice and this permission notice shall be
 
17
 * included in all copies or substantial portions of the Software.
 
18
 *
 
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
20
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
21
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
22
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 
23
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 
24
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
25
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
26
 * SOFTWARE.
 
27
 *
 
28
 *
 
29
 */
 
30
 
 
31
#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
 
32
#error "Only <cogl/cogl.h> can be included directly."
 
33
#endif
 
34
 
 
35
#ifndef __COGL_FIXED_H__
 
36
#define __COGL_FIXED_H__
 
37
 
 
38
#include <cogl/cogl-types.h>
 
39
 
 
40
/**
 
41
 * SECTION:cogl-fixed
 
42
 * @short_description: Fixed Point API
 
43
 *
 
44
 * COGL has a fixed point API targeted at platforms without a floating
 
45
 * point unit, such as embedded devices. On such platforms this API should
 
46
 * be preferred to the floating point one as it does not trigger the slow
 
47
 * path of software emulation, relying on integer math for fixed-to-floating
 
48
 * and floating-to-fixed notations conversion.
 
49
 *
 
50
 * It is not recommened for use on platforms with a floating point unit
 
51
 * (e.g. desktop systems), nor for use in language bindings.
 
52
 *
 
53
 * Basic rules of Fixed Point arithmethic:
 
54
 * <itemizedlist>
 
55
 *   <listitem>
 
56
 *     <para>Two fixed point numbers can be directly added, subtracted and
 
57
 *     have their modulus taken.</para>
 
58
 *   </listitem>
 
59
 *   <listitem>
 
60
 *     <para>To add other numerical type to a fixed point number it has to
 
61
 *     be first converted to fixed point.</para>
 
62
 *   </listitem>
 
63
 *   <listitem>
 
64
 *     <para>A fixed point number can be directly multiplied or divided by
 
65
 *     an integer.</para>
 
66
 *   </listitem>
 
67
 *   <listitem>
 
68
 *     <para>Two fixed point numbers can only be multiplied and divided by
 
69
 *     the provided %COGL_FIXED_MUL and %COGL_FIXED_DIV macros.</para>
 
70
 *   </listitem>
 
71
 * </itemizedlist>
 
72
 *
 
73
 * The fixed point API is available since COGL 1.0.
 
74
 */
 
75
 
 
76
COGL_BEGIN_DECLS
 
77
 
 
78
/**
 
79
 * COGL_FIXED_BITS:
 
80
 *
 
81
 * Evaluates to the number of bits used by the #CoglFixed type.
 
82
 *
 
83
 * Since: 1.0
 
84
 */
 
85
#define COGL_FIXED_BITS         (32)
 
86
 
 
87
/**
 
88
 * COGL_FIXED_Q:
 
89
 *
 
90
 * Evaluates to the number of bits used for the non-integer part
 
91
 * of the #CoglFixed type.
 
92
 *
 
93
 * Since: 1.0
 
94
 */
 
95
#define COGL_FIXED_Q            (COGL_FIXED_BITS - 16)
 
96
 
 
97
/**
 
98
 * COGL_FIXED_1:
 
99
 *
 
100
 * The number 1 expressed as a #CoglFixed number.
 
101
 *
 
102
 * Since: 1.0
 
103
 */
 
104
#define COGL_FIXED_1            (1 << COGL_FIXED_Q)
 
105
 
 
106
/**
 
107
 * COGL_FIXED_0_5:
 
108
 *
 
109
 * The number 0.5 expressed as a #CoglFixed number.
 
110
 *
 
111
 * Since: 1.0
 
112
 */
 
113
#define COGL_FIXED_0_5          (32768)
 
114
 
 
115
/**
 
116
 * COGL_FIXED_EPSILON:
 
117
 *
 
118
 * A very small number expressed as a #CoglFixed number.
 
119
 *
 
120
 * Since: 1.0
 
121
 */
 
122
#define COGL_FIXED_EPSILON      (1)
 
123
 
 
124
/**
 
125
 * COGL_FIXED_MAX:
 
126
 *
 
127
 * The biggest number representable using #CoglFixed
 
128
 *
 
129
 * Since: 1.0
 
130
 */
 
131
#define COGL_FIXED_MAX          (0x7fffffff)
 
132
 
 
133
/**
 
134
 * COGL_FIXED_MIN:
 
135
 *
 
136
 * The smallest number representable using #CoglFixed
 
137
 *
 
138
 * Since: 1.0
 
139
 */
 
140
#define COGL_FIXED_MIN          (0x80000000)
 
141
 
 
142
/**
 
143
 * COGL_FIXED_PI:
 
144
 *
 
145
 * The number pi, expressed as a #CoglFixed number.
 
146
 *
 
147
 * Since: 1.0
 
148
 */
 
149
#define COGL_FIXED_PI           (0x0003243f)
 
150
 
 
151
/**
 
152
 * COGL_FIXED_2_PI:
 
153
 *
 
154
 * Two times pi, expressed as a #CoglFixed number.
 
155
 *
 
156
 * Since: 1.0
 
157
 */
 
158
#define COGL_FIXED_2_PI         (0x0006487f)
 
159
 
 
160
/**
 
161
 * COGL_FIXED_PI_2:
 
162
 *
 
163
 * Half pi, expressed as a #CoglFixed number.
 
164
 *
 
165
 * Since: 1.0
 
166
 */
 
167
#define COGL_FIXED_PI_2         (0x00019220)
 
168
 
 
169
/**
 
170
 * COGL_FIXED_PI_4:
 
171
 *
 
172
 * pi / 4, expressed as #CoglFixed number.
 
173
 *
 
174
 * Since: 1.0
 
175
 */
 
176
#define COGL_FIXED_PI_4         (0x0000c910)
 
177
 
 
178
/**
 
179
 * COGL_FIXED_360:
 
180
 *
 
181
 * Evaluates to the number 360 in fixed point notation.
 
182
 *
 
183
 * Since: 1.0
 
184
 */
 
185
#define COGL_FIXED_360          (COGL_FIXED_FROM_INT (360))
 
186
 
 
187
/**
 
188
 * COGL_FIXED_270:
 
189
 *
 
190
 * Evaluates to the number 270 in fixed point notation.
 
191
 *
 
192
 * Since: 1.0
 
193
 */
 
194
#define COGL_FIXED_270          (COGL_FIXED_FROM_INT (270))
 
195
 
 
196
/**
 
197
 * COGL_FIXED_255:
 
198
 *
 
199
 * Evaluates to the number 255 in fixed point notation.
 
200
 *
 
201
 * Since: 1.0
 
202
 */
 
203
#define COGL_FIXED_255          (COGL_FIXED_FROM_INT (255))
 
204
 
 
205
/**
 
206
 * COGL_FIXED_240:
 
207
 *
 
208
 * Evaluates to the number 240 in fixed point notation.
 
209
 *
 
210
 * Since: 1.0
 
211
 */
 
212
#define COGL_FIXED_240          (COGL_FIXED_FROM_INT (240))
 
213
 
 
214
/**
 
215
 * COGL_FIXED_180:
 
216
 *
 
217
 * Evaluates to the number 180 in fixed point notation.
 
218
 *
 
219
 * Since: 1.0
 
220
 */
 
221
#define COGL_FIXED_180          (COGL_FIXED_FROM_INT (180))
 
222
 
 
223
/**
 
224
 * COGL_FIXED_120:
 
225
 *
 
226
 * Evaluates to the number 120 in fixed point notation.
 
227
 *
 
228
 * Since: 1.0
 
229
 */
 
230
#define COGL_FIXED_120          (COGL_FIXED_FROM_INT (120))
 
231
 
 
232
/**
 
233
 * COGL_FIXED_90:
 
234
 *
 
235
 * Evaluates to the number 90 in fixed point notation.
 
236
 *
 
237
 * Since: 1.0
 
238
 */
 
239
#define COGL_FIXED_90           (COGL_FIXED_FROM_INT (90))
 
240
 
 
241
/**
 
242
 * COGL_FIXED_60:
 
243
 *
 
244
 * Evaluates to the number 60 in fixed point notation.
 
245
 *
 
246
 * Since: 1.0
 
247
 */
 
248
#define COGL_FIXED_60           (COGL_FIXED_FROM_INT (60))
 
249
 
 
250
/**
 
251
 * COGL_FIXED_45:
 
252
 *
 
253
 * Evaluates to the number 45 in fixed point notation.
 
254
 *
 
255
 * Since: 1.0
 
256
 */
 
257
#define COGL_FIXED_45           (COGL_FIXED_FROM_INT (45))
 
258
 
 
259
/**
 
260
 * COGL_FIXED_30:
 
261
 *
 
262
 * Evaluates to the number 30 in fixed point notation.
 
263
 *
 
264
 * Since: 1.0
 
265
 */
 
266
#define COGL_FIXED_30           (COGL_FIXED_FROM_INT (30))
 
267
 
 
268
/**
 
269
 * COGL_RADIANS_TO_DEGREES:
 
270
 *
 
271
 * Evaluates to 180 / pi in fixed point notation.
 
272
 *
 
273
 * Since: 1.0
 
274
 */
 
275
#define COGL_RADIANS_TO_DEGREES (0x394bb8)
 
276
 
 
277
/*
 
278
 * conversion macros
 
279
 */
 
280
 
 
281
/**
 
282
 * COGL_FIXED_FROM_FLOAT:
 
283
 * @x: a floating point number
 
284
 *
 
285
 * Converts @x from a floating point to a fixed point notation.
 
286
 *
 
287
 * Since: 1.0
 
288
 */
 
289
#define COGL_FIXED_FROM_FLOAT(x)        ((float) cogl_double_to_fixed (x))
 
290
 
 
291
/**
 
292
 * COGL_FIXED_TO_FLOAT:
 
293
 * @x: a #CoglFixed number
 
294
 *
 
295
 * Converts @x from a fixed point to a floating point notation, in
 
296
 * single precision.
 
297
 *
 
298
 * Since: 1.0
 
299
 */
 
300
#define COGL_FIXED_TO_FLOAT(x)          ((float) ((int)(x) / 65536.0))
 
301
 
 
302
/**
 
303
 * COGL_FIXED_FROM_DOUBLE:
 
304
 * @x: a floating point number
 
305
 *
 
306
 * Converts @x from a double precision, floating point to a fixed
 
307
 * point notation.
 
308
 *
 
309
 * Since: 1.0
 
310
 */
 
311
#define COGL_FIXED_FROM_DOUBLE(x)       (cogl_double_to_fixed (x))
 
312
 
 
313
/**
 
314
 * COGL_FIXED_TO_DOUBLE:
 
315
 * @x: a #CoglFixed number
 
316
 *
 
317
 * Converts @x from a fixed point to a floating point notation, in
 
318
 * double precision.
 
319
 *
 
320
 * Since: 1.0
 
321
 */
 
322
#define COGL_FIXED_TO_DOUBLE(x)         ((double) ((int)(x) / 65536.0))
 
323
 
 
324
/**
 
325
 * COGL_FIXED_FROM_INT:
 
326
 * @x: an integer number
 
327
 *
 
328
 * Converts @x from an integer to a fixed point notation.
 
329
 *
 
330
 * Since: 1.0
 
331
 */
 
332
#define COGL_FIXED_FROM_INT(x)          ((x) << COGL_FIXED_Q)
 
333
 
 
334
/**
 
335
 * COGL_FIXED_TO_INT:
 
336
 * @x: a #CoglFixed number
 
337
 *
 
338
 * Converts @x from a fixed point notation to an integer, dropping
 
339
 * the fractional part without rounding.
 
340
 *
 
341
 * Since: 1.0
 
342
 */
 
343
#define COGL_FIXED_TO_INT(x)            ((x) >> COGL_FIXED_Q)
 
344
 
 
345
/**
 
346
 * COGL_FLOAT_TO_INT:
 
347
 * @x: a floatint point number
 
348
 *
 
349
 * Converts @x from a floating point notation to a signed integer.
 
350
 *
 
351
 * Since: 1.0
 
352
 */
 
353
#define COGL_FLOAT_TO_INT(x)            (cogl_double_to_int ((x)))
 
354
 
 
355
/**
 
356
 * COGL_FLOAT_TO_UINT:
 
357
 * @x: a floatint point number
 
358
 *
 
359
 * Converts @x from a floating point notation to an unsigned integer.
 
360
 *
 
361
 * Since: 1.0
 
362
 */
 
363
#define COGL_FLOAT_TO_UINT(x)           (cogl_double_to_uint ((x)))
 
364
 
 
365
/*
 
366
 * fixed point math functions
 
367
 */
 
368
 
 
369
/**
 
370
 * COGL_FIXED_FRACTION:
 
371
 * @x: a #CoglFixed number
 
372
 *
 
373
 * Retrieves the fractionary part of @x.
 
374
 *
 
375
 * Since: 1.0
 
376
 */
 
377
#define COGL_FIXED_FRACTION(x)          ((x) & ((1 << COGL_FIXED_Q) - 1))
 
378
 
 
379
/**
 
380
 * COGL_FIXED_FLOOR:
 
381
 * @x: a #CoglFixed number
 
382
 *
 
383
 * Rounds down a fixed point number to the previous integer.
 
384
 *
 
385
 * Since: 1.0
 
386
 */
 
387
#define COGL_FIXED_FLOOR(x)             (((x) >= 0) ? ((x) >> COGL_FIXED_Q) \
 
388
                                                    : ~((~(x)) >> COGL_FIXED_Q))
 
389
 
 
390
/**
 
391
 * COGL_FIXED_CEIL:
 
392
 * @x: a #CoglFixed number
 
393
 *
 
394
 * Rounds up a fixed point number to the next integer.
 
395
 *
 
396
 * Since: 1.0
 
397
 */
 
398
#define COGL_FIXED_CEIL(x)              (COGL_FIXED_FLOOR ((x) + 0xffff))
 
399
 
 
400
/**
 
401
 * COGL_FIXED_MUL:
 
402
 * @a: a #CoglFixed number
 
403
 * @b: a #CoglFixed number
 
404
 *
 
405
 * Computes (a * b).
 
406
 *
 
407
 * Since: 1.0
 
408
 */
 
409
#define COGL_FIXED_MUL(a,b)             (cogl_fixed_mul ((a), (b)))
 
410
 
 
411
/**
 
412
 * COGL_FIXED_DIV:
 
413
 * @a: a #CoglFixed number
 
414
 * @b: a #CoglFixed number
 
415
 *
 
416
 * Computes (a / b).
 
417
 *
 
418
 * Since: 1.0
 
419
 */
 
420
#define COGL_FIXED_DIV(a,b)             (cogl_fixed_div ((a), (b)))
 
421
 
 
422
/**
 
423
 * COGL_FIXED_MUL_DIV:
 
424
 * @a: a #CoglFixed number
 
425
 * @b: a #CoglFixed number
 
426
 * @c: a #CoglFixed number
 
427
 *
 
428
 * Computes ((a * b) / c). It is logically equivalent to:
 
429
 *
 
430
 * |[
 
431
 *   res = COGL_FIXED_DIV (COGL_FIXED_MUL (a, b), c);
 
432
 * ]|
 
433
 *
 
434
 * But it is shorter to type.
 
435
 *
 
436
 * Since: 1.0
 
437
 */
 
438
#define COGL_FIXED_MUL_DIV(a,b,c)       (cogl_fixed_mul_div ((a), (b), (c)))
 
439
 
 
440
/**
 
441
 * COGL_FIXED_FAST_MUL:
 
442
 * @a: a #CoglFixed number
 
443
 * @b: a #CoglFixed number
 
444
 *
 
445
 * Fast version of %COGL_FIXED_MUL, implemented as a macro.
 
446
 *
 
447
 * <note>This macro might lose precision. If the precision of the result
 
448
 * is important use %COGL_FIXED_MUL instead.</note>
 
449
 *
 
450
 * Since: 1.0
 
451
 */
 
452
#define COGL_FIXED_FAST_MUL(a,b)        ((a) >> 8) * ((b) >> 8)
 
453
 
 
454
/**
 
455
 * COGL_FIXED_FAST_DIV:
 
456
 * @a: a #CoglFixed number
 
457
 * @b: a #CoglFixed number
 
458
 *
 
459
 * Fast version of %COGL_FIXED_DIV, implemented as a macro.
 
460
 *
 
461
 * <note>This macro might lose precision. If the precision of the result
 
462
 * is important use %COGL_FIXED_DIV instead.</note>
 
463
 *
 
464
 * Since: 1.0
 
465
 */
 
466
#define COGL_FIXED_FAST_DIV(a,b)        ((((a) << 8) / (b)) << 8)
 
467
 
 
468
/**
 
469
 * cogl_fixed_sin:
 
470
 * @angle: a #CoglFixed number
 
471
 *
 
472
 * Computes the sine of @angle.
 
473
 *
 
474
 * Return value: the sine of the passed angle, in fixed point notation
 
475
 *
 
476
 * Since: 1.0
 
477
 */
 
478
CoglFixed
 
479
cogl_fixed_sin (CoglFixed angle);
 
480
 
 
481
/**
 
482
 * cogl_fixed_tan:
 
483
 * @angle: a #CoglFixed number
 
484
 *
 
485
 * Computes the tangent of @angle.
 
486
 *
 
487
 * Return value: the tangent of the passed angle, in fixed point notation
 
488
 *
 
489
 * Since: 1.0
 
490
 */
 
491
CoglFixed
 
492
cogl_fixed_tan (CoglFixed angle);
 
493
 
 
494
/**
 
495
 * cogl_fixed_cos:
 
496
 * @angle: a #CoglFixed number
 
497
 *
 
498
 * Computes the cosine of @angle.
 
499
 *
 
500
 * Return value: the cosine of the passed angle, in fixed point notation
 
501
 *
 
502
 * Since: 1.0
 
503
 */
 
504
CoglFixed cogl_fixed_cos (CoglFixed angle);
 
505
 
 
506
/**
 
507
 * cogl_fixed_atan:
 
508
 * @a: a #CoglFixed number
 
509
 *
 
510
 * Computes the arc tangent of @a.
 
511
 *
 
512
 * Return value: the arc tangent of the passed value, in fixed point notation
 
513
 *
 
514
 * Since: 1.0
 
515
 */
 
516
CoglFixed
 
517
cogl_fixed_atan (CoglFixed a);
 
518
 
 
519
/**
 
520
 * cogl_fixed_atan2:
 
521
 * @a: the numerator as a #CoglFixed number
 
522
 * @b: the denominator as a #CoglFixed number
 
523
 *
 
524
 * Computes the arc tangent of @a / @b but uses the sign of both
 
525
 * arguments to return the angle in right quadrant.
 
526
 *
 
527
 * Return value: the arc tangent of the passed fraction, in fixed point
 
528
 *   notation
 
529
 *
 
530
 * Since: 1.0
 
531
 */
 
532
CoglFixed
 
533
cogl_fixed_atan2 (CoglFixed a,
 
534
                  CoglFixed b);
 
535
 
 
536
/*< public >*/
 
537
 
 
538
/* Fixed point math routines */
 
539
G_INLINE_FUNC CoglFixed
 
540
cogl_fixed_mul (CoglFixed a,
 
541
                CoglFixed b);
 
542
 
 
543
G_INLINE_FUNC CoglFixed
 
544
cogl_fixed_div (CoglFixed a,
 
545
                CoglFixed b);
 
546
 
 
547
G_INLINE_FUNC CoglFixed
 
548
cogl_fixed_mul_div (CoglFixed a,
 
549
                    CoglFixed b,
 
550
                    CoglFixed c);
 
551
 
 
552
/**
 
553
 * COGL_SQRTI_ARG_MAX:
 
554
 *
 
555
 * Maximum argument that can be passed to cogl_sqrti() function.
 
556
 *
 
557
 * Since: 1.0
 
558
 */
 
559
#ifndef __SSE2__
 
560
#define COGL_SQRTI_ARG_MAX 0x3fffff
 
561
#else
 
562
#define COGL_SQRTI_ARG_MAX INT_MAX
 
563
#endif
 
564
 
 
565
/**
 
566
 * COGL_SQRTI_ARG_5_PERCENT:
 
567
 *
 
568
 * Maximum argument that can be passed to cogl_sqrti() for which the
 
569
 * resulting error is < 5%
 
570
 *
 
571
 * Since: 1.0
 
572
 */
 
573
#ifndef __SSE2__
 
574
#define COGL_SQRTI_ARG_5_PERCENT 210
 
575
#else
 
576
#define COGL_SQRTI_ARG_5_PERCENT INT_MAX
 
577
#endif
 
578
 
 
579
/**
 
580
 * COGL_SQRTI_ARG_10_PERCENT:
 
581
 *
 
582
 * Maximum argument that can be passed to cogl_sqrti() for which the
 
583
 * resulting error is < 10%
 
584
 *
 
585
 * Since: 1.0
 
586
 */
 
587
#ifndef __SSE2__
 
588
#define COGL_SQRTI_ARG_10_PERCENT 5590
 
589
#else
 
590
#define COGL_SQRTI_ARG_10_PERCENT INT_MAX
 
591
#endif
 
592
 
 
593
/**
 
594
 * cogl_fixed_sqrt:
 
595
 * @x: a #CoglFixed number
 
596
 *
 
597
 * Computes the square root of @x.
 
598
 *
 
599
 * Return value: the square root of the passed value, in floating point
 
600
 *   notation
 
601
 *
 
602
 * Since: 1.0
 
603
 */
 
604
CoglFixed
 
605
cogl_fixed_sqrt (CoglFixed x);
 
606
 
 
607
/**
 
608
 * cogl_fixed_log2:
 
609
 * @x: value to calculate base 2 logarithm from
 
610
 *
 
611
 * Calculates base 2 logarithm.
 
612
 *
 
613
 * This function is some 2.5 times faster on x86, and over 12 times faster on
 
614
 * fpu-less arm, than using libc log().
 
615
 *
 
616
 * Return value: base 2 logarithm.
 
617
 *
 
618
 * Since: 1.0
 
619
 */
 
620
CoglFixed
 
621
cogl_fixed_log2 (unsigned int x);
 
622
 
 
623
/**
 
624
 * cogl_fixed_pow2:
 
625
 * @x: a #CoglFixed number
 
626
 *
 
627
 * Calculates 2 to the @x power.
 
628
 *
 
629
 * This function is around 11 times faster on x86, and around 22 times faster
 
630
 * on fpu-less arm than libc pow(2, x).
 
631
 *
 
632
 * Return value: the power of 2 to the passed value
 
633
 *
 
634
 * Since: 1.0
 
635
 */
 
636
unsigned int
 
637
cogl_fixed_pow2 (CoglFixed x);
 
638
 
 
639
/**
 
640
 * cogl_fixed_pow:
 
641
 * @x: base
 
642
 * @y: #CoglFixed exponent
 
643
 *
 
644
 * Calculates @x to the @y power.
 
645
 *
 
646
 * Return value: the power of @x to the @y
 
647
 *
 
648
 * Since: 1.0
 
649
 */
 
650
unsigned int
 
651
cogl_fixed_pow  (unsigned int x,
 
652
                 CoglFixed y);
 
653
 
 
654
/**
 
655
 * cogl_sqrti:
 
656
 * @x: integer value
 
657
 *
 
658
 * Very fast fixed point implementation of square root for integers.
 
659
 *
 
660
 * This function is at least 6x faster than clib sqrt() on x86, and (this is
 
661
 * not a typo!) about 500x faster on ARM without FPU. It's error is less than
 
662
 * 5% for arguments smaller than %COGL_SQRTI_ARG_5_PERCENT and less than 10%
 
663
 * for narguments smaller than %COGL_SQRTI_ARG_10_PERCENT. The maximum
 
664
 * argument that can be passed to this function is %COGL_SQRTI_ARG_MAX.
 
665
 *
 
666
 * Return value: integer square root.
 
667
 *
 
668
 * Since: 1.0
 
669
 */
 
670
int
 
671
cogl_sqrti (int x);
 
672
 
 
673
/**
 
674
 * COGL_ANGLE_FROM_DEG:
 
675
 * @x: an angle in degrees in floating point notation
 
676
 *
 
677
 * Converts an angle in degrees into a #CoglAngle.
 
678
 *
 
679
 * Since: 1.0
 
680
 */
 
681
#define COGL_ANGLE_FROM_DEG(x)  (COGL_FLOAT_TO_INT (((float)(x) * 1024.0f) / 360.0f))
 
682
 
 
683
/**
 
684
 * COGL_ANGLE_TO_DEG:
 
685
 * @x: a #CoglAngle
 
686
 *
 
687
 * Converts a #CoglAngle into an angle in degrees, using floatint point
 
688
 * notation.
 
689
 *
 
690
 * Since: 1.0
 
691
 */
 
692
#define COGL_ANGLE_TO_DEG(x)    (((float)(x) * 360.0) / 1024.0)
 
693
 
 
694
/**
 
695
 * COGL_ANGLE_FROM_DEGX:
 
696
 * @x: an angle in degrees in fixed point notation
 
697
 *
 
698
 * Converts an angle in degrees into a #CoglAngle.
 
699
 *
 
700
 * Since: 1.0
 
701
 */
 
702
#define COGL_ANGLE_FROM_DEGX(x) (COGL_FIXED_TO_INT ((((x) / 360) * 1024) + COGL_FIXED_0_5))
 
703
 
 
704
/**
 
705
 * COGL_ANGLE_TO_DEGX:
 
706
 * @x: a #CoglAngle
 
707
 *
 
708
 * Converts a #CoglAngle into an angle in degrees, using fixed point notation
 
709
 *
 
710
 * Since: 1.0
 
711
 */
 
712
#define COGL_ANGLE_TO_DEGX(x)   (COGL_FIXED_FROM_INT ((x) * 45) / 128)
 
713
 
 
714
/**
 
715
 * cogl_angle_sin:
 
716
 * @angle: an angle expressed using #CoglAngle
 
717
 *
 
718
 * Computes the sine of @angle
 
719
 *
 
720
 * Return value: the sine of the passed angle
 
721
 *
 
722
 * Since: 1.0
 
723
 */
 
724
CoglFixed
 
725
cogl_angle_sin (CoglAngle angle);
 
726
 
 
727
/**
 
728
 * cogl_angle_tan:
 
729
 * @angle: an angle expressed using #CoglAngle
 
730
 *
 
731
 * Computes the tangent of @angle
 
732
 *
 
733
 * Return value: the tangent of the passed angle
 
734
 *
 
735
 * Since: 1.0
 
736
 */
 
737
CoglFixed
 
738
cogl_angle_tan (CoglAngle angle);
 
739
 
 
740
/**
 
741
 * cogl_angle_cos:
 
742
 * @angle: an angle expressed using #CoglAngle
 
743
 *
 
744
 * Computes the cosine of @angle
 
745
 *
 
746
 * Return value: the cosine of the passed angle
 
747
 *
 
748
 * Since: 1.0
 
749
 */
 
750
CoglFixed
 
751
cogl_angle_cos (CoglAngle angle);
 
752
 
 
753
/*< private >*/
 
754
 
 
755
#if defined (G_CAN_INLINE)
 
756
G_INLINE_FUNC CoglFixed
 
757
cogl_fixed_mul (CoglFixed a,
 
758
                CoglFixed b)
 
759
{
 
760
# ifdef __arm__
 
761
    int res_low, res_hi;
 
762
 
 
763
    __asm__ ("smull %0, %1, %2, %3     \n"
 
764
             "mov   %0, %0,     lsr %4 \n"
 
765
             "add   %1, %0, %1, lsl %5 \n"
 
766
             : "=r"(res_hi), "=r"(res_low)\
 
767
             : "r"(a), "r"(b), "i"(COGL_FIXED_Q), "i"(32 - COGL_FIXED_Q));
 
768
 
 
769
    return (CoglFixed) res_low;
 
770
# else
 
771
    long long r = (long long) a * (long long) b;
 
772
 
 
773
    return (unsigned int)(r >> COGL_FIXED_Q);
 
774
# endif
 
775
}
 
776
#endif
 
777
 
 
778
#if defined (G_CAN_INLINE)
 
779
G_INLINE_FUNC CoglFixed
 
780
cogl_fixed_div (CoglFixed a,
 
781
                CoglFixed b)
 
782
{
 
783
  return (CoglFixed) ((((int64_t) a) << COGL_FIXED_Q) / b);
 
784
}
 
785
#endif
 
786
 
 
787
#if defined(G_CAN_INLINE)
 
788
G_INLINE_FUNC CoglFixed
 
789
cogl_fixed_mul_div (CoglFixed a,
 
790
                    CoglFixed b,
 
791
                    CoglFixed c)
 
792
{
 
793
  CoglFixed ab = cogl_fixed_mul (a, b);
 
794
  CoglFixed quo = cogl_fixed_div (ab, c);
 
795
 
 
796
  return quo;
 
797
}
 
798
#endif
 
799
 
 
800
CoglFixed
 
801
cogl_double_to_fixed (double value);
 
802
 
 
803
int
 
804
cogl_double_to_int   (double value);
 
805
 
 
806
unsigned int
 
807
cogl_double_to_uint (double value);
 
808
 
 
809
COGL_END_DECLS
 
810
 
 
811
#endif /* __COGL_FIXED_H__ */