~ubuntu-branches/ubuntu/saucy/qemu/saucy-proposed

« back to all changes in this revision

Viewing changes to include/qemu/host-utils.h

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-05-28 08:18:30 UTC
  • mfrom: (1.8.2) (10.1.37 sid)
  • Revision ID: package-import@ubuntu.com-20130528081830-87xl2z9fq516a814
Tags: 1.5.0+dfsg-2ubuntu1
* Merge 1.5.0+dfs-2 from debian unstable.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - Dropped patches:
    * 0001-fix-wrong-output-with-info-chardev-for-tcp-socket.patch
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * gridcentric patch - updated
    * linaro arm patches from qemu-linaro rebasing branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#define HOST_UTILS_H 1
27
27
 
28
28
#include "qemu/compiler.h"   /* QEMU_GNUC_PREREQ */
 
29
#include <limits.h>
29
30
 
30
 
#if defined(__x86_64__)
31
 
#define __HAVE_FAST_MULU64__
 
31
#ifdef CONFIG_INT128
32
32
static inline void mulu64(uint64_t *plow, uint64_t *phigh,
33
33
                          uint64_t a, uint64_t b)
34
34
{
35
 
    __asm__ ("mul %0\n\t"
36
 
             : "=d" (*phigh), "=a" (*plow)
37
 
             : "a" (a), "0" (b));
 
35
    __uint128_t r = (__uint128_t)a * b;
 
36
    *plow = r;
 
37
    *phigh = r >> 64;
38
38
}
39
 
#define __HAVE_FAST_MULS64__
 
39
 
40
40
static inline void muls64(uint64_t *plow, uint64_t *phigh,
41
41
                          int64_t a, int64_t b)
42
42
{
43
 
    __asm__ ("imul %0\n\t"
44
 
             : "=d" (*phigh), "=a" (*plow)
45
 
             : "a" (a), "0" (b));
 
43
    __int128_t r = (__int128_t)a * b;
 
44
    *plow = r;
 
45
    *phigh = r >> 64;
46
46
}
47
47
#else
48
48
void muls64(uint64_t *phigh, uint64_t *plow, int64_t a, int64_t b);
49
49
void mulu64(uint64_t *phigh, uint64_t *plow, uint64_t a, uint64_t b);
50
50
#endif
51
51
 
52
 
/* Binary search for leading zeros.  */
53
 
 
 
52
/**
 
53
 * clz32 - count leading zeros in a 32-bit value.
 
54
 * @val: The value to search
 
55
 *
 
56
 * Returns 32 if the value is zero.  Note that the GCC builtin is
 
57
 * undefined if the value is zero.
 
58
 */
54
59
static inline int clz32(uint32_t val)
55
60
{
56
61
#if QEMU_GNUC_PREREQ(3, 4)
57
 
    if (val)
58
 
        return __builtin_clz(val);
59
 
    else
60
 
        return 32;
 
62
    return val ? __builtin_clz(val) : 32;
61
63
#else
 
64
    /* Binary search for the leading one bit.  */
62
65
    int cnt = 0;
63
66
 
64
67
    if (!(val & 0xFFFF0000U)) {
88
91
#endif
89
92
}
90
93
 
 
94
/**
 
95
 * clo32 - count leading ones in a 32-bit value.
 
96
 * @val: The value to search
 
97
 *
 
98
 * Returns 32 if the value is -1.
 
99
 */
91
100
static inline int clo32(uint32_t val)
92
101
{
93
102
    return clz32(~val);
94
103
}
95
104
 
 
105
/**
 
106
 * clz64 - count leading zeros in a 64-bit value.
 
107
 * @val: The value to search
 
108
 *
 
109
 * Returns 64 if the value is zero.  Note that the GCC builtin is
 
110
 * undefined if the value is zero.
 
111
 */
96
112
static inline int clz64(uint64_t val)
97
113
{
98
114
#if QEMU_GNUC_PREREQ(3, 4)
99
 
    if (val)
100
 
        return __builtin_clzll(val);
101
 
    else
102
 
        return 64;
 
115
    return val ? __builtin_clzll(val) : 64;
103
116
#else
104
117
    int cnt = 0;
105
118
 
113
126
#endif
114
127
}
115
128
 
 
129
/**
 
130
 * clo64 - count leading ones in a 64-bit value.
 
131
 * @val: The value to search
 
132
 *
 
133
 * Returns 64 if the value is -1.
 
134
 */
116
135
static inline int clo64(uint64_t val)
117
136
{
118
137
    return clz64(~val);
119
138
}
120
139
 
 
140
/**
 
141
 * ctz32 - count trailing zeros in a 32-bit value.
 
142
 * @val: The value to search
 
143
 *
 
144
 * Returns 32 if the value is zero.  Note that the GCC builtin is
 
145
 * undefined if the value is zero.
 
146
 */
121
147
static inline int ctz32(uint32_t val)
122
148
{
123
149
#if QEMU_GNUC_PREREQ(3, 4)
124
 
    if (val)
125
 
        return __builtin_ctz(val);
126
 
    else
127
 
        return 32;
 
150
    return val ? __builtin_ctz(val) : 32;
128
151
#else
 
152
    /* Binary search for the trailing one bit.  */
129
153
    int cnt;
130
154
 
131
155
    cnt = 0;
157
181
#endif
158
182
}
159
183
 
 
184
/**
 
185
 * cto32 - count trailing ones in a 32-bit value.
 
186
 * @val: The value to search
 
187
 *
 
188
 * Returns 32 if the value is -1.
 
189
 */
160
190
static inline int cto32(uint32_t val)
161
191
{
162
192
    return ctz32(~val);
163
193
}
164
194
 
 
195
/**
 
196
 * ctz64 - count trailing zeros in a 64-bit value.
 
197
 * @val: The value to search
 
198
 *
 
199
 * Returns 64 if the value is zero.  Note that the GCC builtin is
 
200
 * undefined if the value is zero.
 
201
 */
165
202
static inline int ctz64(uint64_t val)
166
203
{
167
204
#if QEMU_GNUC_PREREQ(3, 4)
168
 
    if (val)
169
 
        return __builtin_ctzll(val);
170
 
    else
171
 
        return 64;
 
205
    return val ? __builtin_ctzll(val) : 64;
172
206
#else
173
207
    int cnt;
174
208
 
182
216
#endif
183
217
}
184
218
 
 
219
/**
 
220
 * ctz64 - count trailing ones in a 64-bit value.
 
221
 * @val: The value to search
 
222
 *
 
223
 * Returns 64 if the value is -1.
 
224
 */
185
225
static inline int cto64(uint64_t val)
186
226
{
187
227
    return ctz64(~val);
188
228
}
189
229
 
 
230
/**
 
231
 * ctpop8 - count the population of one bits in an 8-bit value.
 
232
 * @val: The value to search
 
233
 */
190
234
static inline int ctpop8(uint8_t val)
191
235
{
 
236
#if QEMU_GNUC_PREREQ(3, 4)
 
237
    return __builtin_popcount(val);
 
238
#else
192
239
    val = (val & 0x55) + ((val >> 1) & 0x55);
193
240
    val = (val & 0x33) + ((val >> 2) & 0x33);
194
241
    val = (val & 0x0f) + ((val >> 4) & 0x0f);
195
242
 
196
243
    return val;
 
244
#endif
197
245
}
198
246
 
 
247
/**
 
248
 * ctpop16 - count the population of one bits in a 16-bit value.
 
249
 * @val: The value to search
 
250
 */
199
251
static inline int ctpop16(uint16_t val)
200
252
{
 
253
#if QEMU_GNUC_PREREQ(3, 4)
 
254
    return __builtin_popcount(val);
 
255
#else
201
256
    val = (val & 0x5555) + ((val >> 1) & 0x5555);
202
257
    val = (val & 0x3333) + ((val >> 2) & 0x3333);
203
258
    val = (val & 0x0f0f) + ((val >> 4) & 0x0f0f);
204
259
    val = (val & 0x00ff) + ((val >> 8) & 0x00ff);
205
260
 
206
261
    return val;
 
262
#endif
207
263
}
208
264
 
 
265
/**
 
266
 * ctpop32 - count the population of one bits in a 32-bit value.
 
267
 * @val: The value to search
 
268
 */
209
269
static inline int ctpop32(uint32_t val)
210
270
{
211
271
#if QEMU_GNUC_PREREQ(3, 4)
221
281
#endif
222
282
}
223
283
 
 
284
/**
 
285
 * ctpop64 - count the population of one bits in a 64-bit value.
 
286
 * @val: The value to search
 
287
 */
224
288
static inline int ctpop64(uint64_t val)
225
289
{
226
290
#if QEMU_GNUC_PREREQ(3, 4)
237
301
#endif
238
302
}
239
303
 
 
304
/* Host type specific sizes of these routines.  */
 
305
 
 
306
#if ULONG_MAX == UINT32_MAX
 
307
# define clzl   clz32
 
308
# define ctzl   ctz32
 
309
# define clol   clo32
 
310
# define ctol   cto32
 
311
# define ctpopl ctpop32
 
312
#elif ULONG_MAX == UINT64_MAX
 
313
# define clzl   clz64
 
314
# define ctzl   ctz64
 
315
# define clol   clo64
 
316
# define ctol   cto64
 
317
# define ctpopl ctpop64
 
318
#else
 
319
# error Unknown sizeof long
 
320
#endif
 
321
 
240
322
#endif