-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbitmap.h
More file actions
69 lines (56 loc) · 2.59 KB
/
bitmap.h
File metadata and controls
69 lines (56 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright (c) 2012 The Native Client Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/*
* This file contains bitmap array manipulation functions.
*/
#ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_BITMAP_H_
#define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_BITMAP_H_
#include "native_client/src/include/build_config.h"
#include "native_client/src/include/nacl_macros.h"
#include "native_client/src/include/portability.h"
#if defined(_MSC_VER)
# define FORCEINLINE __forceinline
#else
# define FORCEINLINE __inline __attribute__ ((always_inline))
#endif
typedef NACL_CONCAT(NACL_CONCAT(uint, NACL_HOST_WORDSIZE), _t) bitmap_word;
static INLINE bitmap_word *BitmapAllocate(size_t indexes) {
size_t word_count = ((indexes + NACL_HOST_WORDSIZE - 1) / NACL_HOST_WORDSIZE);
NACL_COMPILE_TIME_ASSERT((NACL_HOST_WORDSIZE / 8) == sizeof(bitmap_word));
return calloc(word_count, sizeof(bitmap_word));
}
static FORCEINLINE int BitmapIsBitSet(bitmap_word *bitmap, size_t index) {
return (bitmap[index / NACL_HOST_WORDSIZE] &
(((bitmap_word)1) << (index % NACL_HOST_WORDSIZE))) != 0;
}
static FORCEINLINE void BitmapSetBit(bitmap_word *bitmap, size_t index) {
bitmap[index / NACL_HOST_WORDSIZE] |=
((bitmap_word)1) << (index % NACL_HOST_WORDSIZE);
}
static FORCEINLINE void BitmapClearBit(bitmap_word *bitmap, size_t index) {
bitmap[index / NACL_HOST_WORDSIZE] &=
~(((bitmap_word)1) << (index % NACL_HOST_WORDSIZE));
}
/* All the bits must be in a single 32-bit bundle. */
static FORCEINLINE int BitmapIsAnyBitSet(bitmap_word *bitmap,
size_t index, size_t bits) {
return (bitmap[index / NACL_HOST_WORDSIZE] &
(((((bitmap_word)1) << bits) - 1) << (index % NACL_HOST_WORDSIZE))) != 0;
}
/* All the bits must be in a single 32-bit bundle. */
static FORCEINLINE void BitmapSetBits(bitmap_word *bitmap,
size_t index,
size_t bits) {
bitmap[index / NACL_HOST_WORDSIZE] |=
((((bitmap_word)1) << bits) - 1) << (index % NACL_HOST_WORDSIZE);
}
/* All the bits must be in a single 32-bit bundle. */
static FORCEINLINE void BitmapClearBits(bitmap_word *bitmap,
size_t index, size_t bits) {
bitmap[index / NACL_HOST_WORDSIZE] &=
~(((((bitmap_word)1) << bits) - 1) << (index % NACL_HOST_WORDSIZE));
}
#endif /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_VALIDATOR_INTERNAL_H_ */