[HB] Simplify refcounting functions
[profile/ivi/org.tizen.video-player.git] / src / hb-private.h
1 /*
2  * Copyright (C) 2007,2008,2009  Red Hat, Inc.
3  *
4  *  This is part of HarfBuzz, an OpenType Layout engine library.
5  *
6  * Permission is hereby granted, without written agreement and without
7  * license or royalty fees, to use, copy, modify, and distribute this
8  * software and its documentation for any purpose, provided that the
9  * above copyright notice and the following two paragraphs appear in
10  * all copies of this software.
11  *
12  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16  * DAMAGE.
17  *
18  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  *
24  * Red Hat Author(s): Behdad Esfahbod
25  */
26
27 #ifndef HB_PRIVATE_H
28 #define HB_PRIVATE_H
29
30 #include "hb-common.h"
31
32 #include <glib.h>
33
34 /* Macros to convert to/from BigEndian */
35 #define hb_be_uint8_t
36 #define hb_be_int8_t
37 #define hb_be_uint16_t  GUINT16_TO_BE
38 #define hb_be_int16_t   GINT16_TO_BE
39 #define hb_be_uint32_t  GUINT32_TO_BE
40 #define hb_be_int32_t   GINT32_TO_BE
41 #define hb_be_uint64_t  GUINT64_TO_BE
42 #define hb_be_int64_t   GINT64_TO_BE
43
44 #define HB_LIKELY       G_LIKELY
45 #define HB_UNLIKELY     G_UNLIKELY
46 #define HB_UNUSED(arg) ((arg) = (arg))
47 #define HB_GNUC_UNUSED  G_GNUC_UNUSED
48
49
50 #include <stdlib.h>
51 #include <stdio.h> /* XXX */
52 #include <string.h>
53 #include <assert.h>
54
55 /* Basics */
56
57 #undef MIN
58 #define MIN(a,b) ((a) < (b) ? (a) : (b))
59
60 #ifndef HB_INTERNAL
61 # define HB_INTERNAL
62 #endif
63
64 #ifndef NULL
65 # define NULL ((void *)0)
66 #endif
67
68 #ifndef FALSE
69 # define FALSE 0
70 #endif
71
72 #ifndef TRUE
73 # define TRUE 1
74 #endif
75
76 #define HB_STMT_START do
77 #define HB_STMT_END   while (0)
78
79 #define _ASSERT_STATIC1(_line, _cond) typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1]
80 #define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond))
81 #define ASSERT_STATIC(_cond) _ASSERT_STATIC0 (__LINE__, (_cond))
82
83 #define ASSERT_SIZE(_type, _size) ASSERT_STATIC (sizeof (_type) == (_size))
84
85
86 /* Return the number of 1 bits in mask.
87  *
88  * GCC 3.4 supports a "population count" builtin, which on many targets is
89  * implemented with a single instruction. There is a fallback definition
90  * in libgcc in case a target does not have one, which should be just as
91  * good as the open-coded solution below, (which is "HACKMEM 169").
92  */
93 static inline unsigned int
94 _hb_popcount32 (uint32_t mask)
95 {
96 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
97     return __builtin_popcount (mask);
98 #else
99     register int y;
100
101     y = (mask >> 1) &033333333333;
102     y = mask - y - ((y >>1) & 033333333333);
103     return (((y + (y >> 3)) & 030707070707) % 077);
104 #endif
105 }
106
107 #endif /* HB_PRIVATE_H */