FD.io VPP  v18.01.2-1-g9b554f3
Vector Packet Processing
types.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /*
16  Copyright (c) 2001-2005 Eliot Dresselhaus
17 
18  Permission is hereby granted, free of charge, to any person obtaining
19  a copy of this software and associated documentation files (the
20  "Software"), to deal in the Software without restriction, including
21  without limitation the rights to use, copy, modify, merge, publish,
22  distribute, sublicense, and/or sell copies of the Software, and to
23  permit persons to whom the Software is furnished to do so, subject to
24  the following conditions:
25 
26  The above copyright notice and this permission notice shall be
27  included in all copies or substantial portions of the Software.
28 
29  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 */
37 
38 #ifndef included_clib_types_h
39 #define included_clib_types_h
40 
41 /* Standard CLIB types. */
42 
43 /* Define signed and unsigned 8, 16, 32, and 64 bit types
44  and machine signed/unsigned word for all architectures. */
45 typedef char i8;
46 typedef short i16;
47 
48 /* Avoid conflicts with Linux asm/types.h when __KERNEL__ */
49 #if defined(CLIB_LINUX_KERNEL)
50 /* Linux also defines u8/u16/u32/u64 types. */
51 #include <asm/types.h>
52 #define CLIB_AVOID_CLASH_WITH_LINUX_TYPES
53 
54 #else /* ! CLIB_LINUX_KERNEL */
55 
56 typedef unsigned char u8;
57 typedef unsigned short u16;
58 #endif /* ! CLIB_LINUX_KERNEL */
59 
60 #if defined (__x86_64__)
61 #ifndef __COVERITY__
62 typedef int i128 __attribute__ ((mode (TI)));
63 typedef unsigned int u128 __attribute__ ((mode (TI)));
64 #endif
65 #endif
66 
67 #if (defined(i386) || defined(_mips) || defined(powerpc) || defined (__SPU__) || defined(__sparc__) || defined(__arm__) || defined (__xtensa__) || defined(__TMS320C6X__))
68 typedef int i32;
69 typedef long long i64;
70 
71 #ifndef CLIB_AVOID_CLASH_WITH_LINUX_TYPES
72 typedef unsigned int u32;
73 typedef unsigned long long u64;
74 #endif /* CLIB_AVOID_CLASH_WITH_LINUX_TYPES */
75 
76 #elif defined(_mips) && __mips == 64
77 #define log2_uword_bits 6
78 #define clib_address_bits _MIPS_SZPTR
79 
80 #elif defined(alpha) || defined(__x86_64__) || defined (__powerpc64__) || defined (__aarch64__)
81 typedef int i32;
82 typedef long i64;
83 
84 #define log2_uword_bits 6
85 #define clib_address_bits 64
86 
87 #ifndef CLIB_AVOID_CLASH_WITH_LINUX_TYPES
88 typedef unsigned int u32;
89 typedef unsigned long u64;
90 #endif /* CLIB_AVOID_CLASH_WITH_LINUX_TYPES */
91 
92 #else
93 #error "can't define types"
94 #endif
95 
96 /* Default to 32 bit machines with 32 bit addresses. */
97 #ifndef log2_uword_bits
98 #define log2_uword_bits 5
99 #endif
100 
101 /* #ifdef's above define log2_uword_bits. */
102 #define uword_bits (1 << log2_uword_bits)
103 
104 #ifndef clib_address_bits
105 #define clib_address_bits 32
106 #endif
107 
108 /* Word types. */
109 #if uword_bits == 64
110 /* 64 bit word machines. */
111 typedef i64 word;
112 typedef u64 uword;
113 #else
114 /* 32 bit word machines. */
115 typedef i32 word;
116 typedef u32 uword;
117 #endif
118 
119 /* integral type of a pointer (used to cast pointers). */
120 #if clib_address_bits == 64
121 typedef u64 clib_address_t;
122 #else
123 typedef u32 clib_address_t;
124 #endif
125 
126 /* These are needed to convert between pointers and machine words.
127  MIPS is currently the only machine that can have different sized
128  pointers and machine words (but only when compiling with 64 bit
129  registers and 32 bit pointers). */
130 static inline __attribute__ ((always_inline)) uword
131 pointer_to_uword (const void *p)
132 {
133  return (uword) (clib_address_t) p;
134 }
135 
136 #define uword_to_pointer(u,type) ((type) (clib_address_t) (u))
137 
138 /* Any type: can be either word or pointer. */
139 typedef word any;
140 
141 /* Floating point types. */
142 typedef double f64;
143 typedef float f32;
144 
145 typedef __complex__ float cf32;
146 typedef __complex__ double cf64;
147 
148 /* Floating point word size. */
149 typedef f64 fword;
150 
151 /* Can be used as either {r,l}value, e.g. these both work
152  clib_mem_unaligned (p, u64) = 99
153  clib_mem_unaligned (p, u64) += 99 */
154 
155 #define clib_mem_unaligned(pointer,type) \
156  (((struct { CLIB_PACKED (type _data); } *) (pointer))->_data)
157 
158 /* Access memory with specified alignment depending on align argument.
159  As with clib_mem_unaligned, may be used as {r,l}value. */
160 #define clib_mem_aligned(addr,type,align) \
161  (((struct { \
162  type _data \
163  __attribute__ ((aligned (align), packed)); \
164  } *) (addr))->_data)
165 
166 #endif /* included_clib_types_h */
167 
168 /*
169  * fd.io coding-style-patch-verification: ON
170  *
171  * Local Variables:
172  * eval: (c-set-style "gnu")
173  * End:
174  */
__complex__ float cf32
Definition: types.h:145
u64 clib_address_t
Definition: types.h:121
float f32
Definition: types.h:143
int i128
Definition: types.h:62
f64 fword
Definition: types.h:149
#define always_inline
Definition: clib.h:92
int i32
Definition: types.h:81
char i8
Definition: types.h:45
unsigned long u64
Definition: types.h:89
static uword pointer_to_uword(const void *p)
Definition: types.h:131
__complex__ double cf64
Definition: types.h:146
unsigned int u128
Definition: types.h:63
long i64
Definition: types.h:82
word any
Definition: types.h:139
unsigned int u32
Definition: types.h:88
u64 uword
Definition: types.h:112
unsigned short u16
Definition: types.h:57
i64 word
Definition: types.h:111
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56
short i16
Definition: types.h:46