Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
int.h
1 /*
2  * $Id$
3  * int module interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2007-10, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_INT_H_
23 #define ELM_INT_H_
24 
25 #include <stdint.h>
26 
27 namespace elm { namespace t {
28 
29 // base types
30 typedef int8_t int8;
31 typedef uint8_t uint8;
32 typedef int16_t int16;
33 typedef uint16_t uint16;
34 typedef int32_t int32;
35 typedef uint32_t uint32;
36 typedef int64_t int64;
37 typedef uint64_t uint64;
38 
39 // other types
40 #if !defined(__LP64__) && !defined(_WIN64)
41  typedef uint32 size;
42  typedef uint32 offset;
43  typedef uint32 uint;
44  typedef uint32 intptr;
45 #else
46  typedef uint64 size;
47  typedef uint64 offset;
48  typedef uint64 uint;
49  typedef uint64 intptr;
50 #endif
51 } // t
52 
53 // prototypes
54 int msb(t::uint32 i);
55 inline int msb(t::int32 i) { return msb(t::uint32(i)); }
56 int msb(t::uint64 i);
57 inline int msb(t::int64 i) { return msb(t::uint64(i)); }
58 int ones(t::uint8 i);
59 inline int ones(t::uint16 i) { return ones(t::uint8(i)) + ones(t::uint8(i >> 8)); }
60 inline int ones(t::uint32 i) { return ones(t::uint16(i)) + ones(t::uint16(i >> 16)); }
61 inline int ones(t::uint64 i) { return ones(t::uint32(i)) + ones(t::uint32(i >> 32)); }
62 inline t::uint32 roundup(t::uint32 v, t::uint32 m) { return ((v - 1) / m + 1) * m; }
63 inline t::uint32 rounddown(t::uint32 v, t::uint32 m) { return v / m * m; }
64 inline t::uint32 abs(t::int32 v) { return v >= 0 ? v : (-v); }
67 t::uint32 mult(t::uint32 a, t::uint32, bool& over);
68 t::uint64 mult(t::uint64 a, t::uint64, bool& over);
69 
70 } // elm
71 
72 #endif /* ELM_INT_H_ */
t::uint32 mult(t::uint32 a, t::uint32, bool &over)
Definition: int.cpp:279
t::uint32 abs(t::int32 v)
Definition: int.h:64
int32_t int32
Definition: int.h:34
uint32 uint
Definition: int.h:43
uint32 size
Definition: int.h:41
int16_t int16
Definition: int.h:32
uint32 offset
Definition: int.h:42
uint8_t uint8
Definition: int.h:31
int64_t int64
Definition: int.h:36
int msb(t::uint32 i)
Definition: int.cpp:144
t::uint32 rounddown(t::uint32 v, t::uint32 m)
Definition: int.h:63
t::uint32 leastUpperPowerOf2(t::uint32 v)
Definition: int.cpp:242
int8_t int8
Definition: int.h:30
uint32 intptr
Definition: int.h:44
uint16_t uint16
Definition: int.h:33
uint32_t uint32
Definition: int.h:35
uint64_t uint64
Definition: int.h:37
t::uint32 roundup(t::uint32 v, t::uint32 m)
Definition: int.h:62
int ones(t::uint8 i)
Definition: int.cpp:187