Code Coverage Report for src/decode/inlines.h


Hit Total Coverage
Lines: 14 14 100.0%
Branches: 0 0 -----

1 /*
2 * libnogg: a decoder library for Ogg Vorbis streams
3 * Copyright (c) 2014-2019 Andrew Church <achurch@achurch.org>
4 *
5 * This software may be copied and redistributed under certain conditions;
6 * see the file "COPYING" in the source code distribution for details.
7 * NO WARRANTY is provided with this software.
8 */
9
10 /*
11 * This header defines some simple inline functions used for various
12 * purposes that don't fit anywhere else. These functions are all
13 * declared UNUSED to prevent warnings from compilers which complain
14 * about unused static inline functions.
15 */
16
17 #ifndef NOGG_SRC_DECODE_INLINES_H
18 #define NOGG_SRC_DECODE_INLINES_H
19
20 /*************************************************************************/
21 /*************************************************************************/
22
23 /**
24 * extract_32: Extract a little-endian 32-bit value from a buffer.
25 *
26 * [Parameters]
27 * ptr: Pointer to 32-bit value in buffer.
28 * [Return value]
29 * Value read from buffer.
30 */
31 static inline UNUSED PURE_FUNCTION uint32_t extract_32(const uint8_t *ptr)
32 {
33 return (uint32_t)ptr[0] << 0
34 | (uint32_t)ptr[1] << 8
35 | (uint32_t)ptr[2] << 16
36 | (uint32_t)ptr[3] << 24;
37 }
38
39 /*-----------------------------------------------------------------------*/
40
41 /**
42 * extract_64: Extract a little-endian 64-bit value from a buffer.
43 *
44 * [Parameters]
45 * ptr: Pointer to 64-bit value in buffer.
46 * [Return value]
47 * Value read from buffer.
48 */
49 static inline UNUSED PURE_FUNCTION uint64_t extract_64(const uint8_t *ptr)
50 {
51 return (uint64_t)ptr[0] << 0
52 | (uint64_t)ptr[1] << 8
53 | (uint64_t)ptr[2] << 16
54 | (uint64_t)ptr[3] << 24
55 | (uint64_t)ptr[4] << 32
56 | (uint64_t)ptr[5] << 40
57 | (uint64_t)ptr[6] << 48
58 | (uint64_t)ptr[7] << 56;
59 }
60
61 /*-----------------------------------------------------------------------*/
62
63 /**
64 * bit_reverse: Reverse the order of the bits in a 32-bit integer.
65 */
66 static inline UNUSED CONST_FUNCTION uint32_t bit_reverse(uint32_t n)
67 {
68 n = ((n & UINT32_C(0xAAAAAAAA)) >> 1) | ((n & UINT32_C(0x55555555)) << 1);
69 n = ((n & UINT32_C(0xCCCCCCCC)) >> 2) | ((n & UINT32_C(0x33333333)) << 2);
70 n = ((n & UINT32_C(0xF0F0F0F0)) >> 4) | ((n & UINT32_C(0x0F0F0F0F)) << 4);
71 n = ((n & UINT32_C(0xFF00FF00)) >> 8) | ((n & UINT32_C(0x00FF00FF)) << 8);
72 return (n >> 16) | (n << 16);
73 }
74
75 /*-----------------------------------------------------------------------*/
76
77 /**
78 * square: Return the square of the floating-point argument.
79 */
80 static inline UNUSED CONST_FUNCTION float square(float x) {return x*x;}
81
82 /*************************************************************************/
83 /*************************************************************************/
84
85 #endif // NOGG_SRC_DECODE_INLINES_H