gint offset;
};
-static int
-wrs_count_bitshift(const guint32 bitmask)
-{
-#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
- return __builtin_ctz(bitmask);
-#else
- /* From http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup */
- static const int table[32] = {
- 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
- 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
- };
-
- return table[((guint32)((bitmask & -(gint32)bitmask) * 0x077CB531U)) >> 27];
-#endif
-}
-
#define cVALS(x) (const value_string*)(x)
/** See inlined comments.
integer &= hfinfo->bitmask;
/* Shift bits */
- if (hfinfo->bitshift > 0) {
- integer >>= hfinfo->bitshift;
- }
+ integer >>= hfinfo_bitshift(hfinfo);
}
fvalue_set_uinteger(&fi->value, integer);
integer &= hfinfo->bitmask;
/* Shift bits */
- if (hfinfo->bitshift > 0) {
- integer >>= hfinfo->bitshift;
- }
+ integer >>= hfinfo_bitshift(hfinfo);
}
fvalue_set_sinteger(&fi->value, integer);
char *p;
val = fvalue_get_uinteger(&fi->value);
- if (hf->bitshift > 0)
- val <<= hf->bitshift;
+ val <<= hfinfo_bitshift(hf);
p = decode_bitfield_value(fi->rep->representation, val, hf->bitmask, hfinfo_bitwidth(hf));
ret = (int) (p - fi->rep->representation);
hfinfo->display = BASE_NONE;
hfinfo->strings = protocol;
hfinfo->bitmask = 0;
- hfinfo->bitshift = 0;
hfinfo->ref_type = HF_REF_TYPE_NONE;
hfinfo->blurb = NULL;
hfinfo->parent = -1; /* this field differentiates protos and fields */
tmp_fld_check_assert(hfinfo);
- /* if this is a bitfield, compute bitshift */
- if (hfinfo->bitmask) {
- hfinfo->bitshift = wrs_count_bitshift(hfinfo->bitmask);
- }
-
hfinfo->parent = parent;
hfinfo->same_name_next = NULL;
hfinfo->same_name_prev = NULL;
/* Un-shift bits */
unshifted_value = value;
- if (hfinfo->bitshift > 0) {
- unshifted_value <<= hfinfo->bitshift;
- }
+ unshifted_value <<= hfinfo_bitshift(hfinfo);
/* Create the bitfield first */
p = decode_bitfield_value(label_str, unshifted_value, hfinfo->bitmask, bitwidth);
/* Un-shift bits */
unshifted_value = fvalue_get_uinteger(&fi->value);
value = unshifted_value;
- if (hfinfo->bitshift > 0) {
- unshifted_value <<= hfinfo->bitshift;
+ if (hfinfo->bitmask) {
+ unshifted_value <<= hfinfo_bitshift(hfinfo);
}
/* Create the bitfield first */
}
}
+int
+hfinfo_bitshift(const header_field_info *hfinfo)
+{
+ const guint32 bitmask = hfinfo->bitmask;
+
+ g_assert(bitmask != 0);
+
+#if defined(__GNUC__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+ return __builtin_ctz(bitmask);
+#else
+ /* From http://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup */
+ static const int table[32] = {
+ 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
+ 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
+ };
+
+ return table[((guint32)((bitmask & -(gint32)bitmask) * 0x077CB531U)) >> 27];
+#endif
+}
+
int
hfinfo_bitwidth(const header_field_info *hfinfo)
{
fields++;
continue;
}
- tmpval = (value & hf->bitmask) >> hf->bitshift;
+ tmpval = (value & hf->bitmask) >> hfinfo_bitshift(hf);
switch (hf->type) {
case FT_INT8:
int id; /**< Field ID */
int parent; /**< parent protocol tree */
hf_ref_type ref_type; /**< is this field referenced by a filter */
- int bitshift; /**< bits to shift */
+ /* 4B padding */
header_field_info *same_name_next; /**< Link to next hfinfo with same abbrev */
header_field_info *same_name_prev; /**< Link to previous hfinfo with same abbrev */
};
* _header_field_info. If new fields are added or removed, it should
* be changed as necessary.
*/
-#define HFILL 0, 0, HF_REF_TYPE_NONE, 0, NULL, NULL
+#define HFILL 0, 0, HF_REF_TYPE_NONE, NULL, NULL
/** Used when registering many fields at once, using proto_register_field_array() */
typedef struct hf_register_info {
extern int
hfinfo_bitwidth(const header_field_info *hfinfo);
-
-
+WS_DLL_PUBLIC int
+hfinfo_bitshift(const header_field_info *hfinfo);
#include "epan.h"