diff options
-rw-r--r-- | epan/dissectors/packet-tpncp.c | 1 | ||||
-rw-r--r-- | epan/dissectors/packet-xml.c | 1 | ||||
-rw-r--r-- | epan/proto.c | 63 | ||||
-rw-r--r-- | epan/proto.h | 8 | ||||
-rw-r--r-- | epan/wspython/wspy_proto.c | 1 | ||||
-rw-r--r-- | plugins/opcua/opcua_simpletypes.c | 2 | ||||
-rw-r--r-- | plugins/opcua/opcua_transport_layer.c | 2 | ||||
-rw-r--r-- | ui/gtk/packet_panes.c | 2 | ||||
-rw-r--r-- | ui/gtk/packet_win.c | 8 | ||||
-rw-r--r-- | ui/qt/byte_view_tab.cpp | 2 |
10 files changed, 39 insertions, 51 deletions
diff --git a/epan/dissectors/packet-tpncp.c b/epan/dissectors/packet-tpncp.c index 92d2e17be5..e1ed09d0be 100644 --- a/epan/dissectors/packet-tpncp.c +++ b/epan/dissectors/packet-tpncp.c @@ -583,7 +583,6 @@ static gint init_tpncp_data_fields_info(tpncp_data_field_info *data_fields_info, hf_entr.hfinfo.id = 0; hf_entr.hfinfo.parent = 0; hf_entr.hfinfo.ref_type = HF_REF_TYPE_NONE; - hf_entr.hfinfo.bitshift = 0; hf_entr.hfinfo.same_name_next = NULL; hf_entr.hfinfo.same_name_prev = NULL; diff --git a/epan/dissectors/packet-xml.c b/epan/dissectors/packet-xml.c index 495b9ab2e1..9569167b38 100644 --- a/epan/dissectors/packet-xml.c +++ b/epan/dissectors/packet-xml.c @@ -816,7 +816,6 @@ static void add_xml_field(wmem_array_t *hfs, int *p_id, const gchar *name, const hfri.hfinfo.id = 0; hfri.hfinfo.parent = 0; hfri.hfinfo.ref_type = HF_REF_TYPE_NONE; - hfri.hfinfo.bitshift = 0; hfri.hfinfo.same_name_next = NULL; hfri.hfinfo.same_name_prev = NULL; diff --git a/epan/proto.c b/epan/proto.c index 280248cddf..03ee55fab6 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -71,22 +71,6 @@ struct ptvcursor { 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. @@ -3023,9 +3007,7 @@ proto_tree_set_uint(field_info *fi, guint32 value) integer &= hfinfo->bitmask; /* Shift bits */ - if (hfinfo->bitshift > 0) { - integer >>= hfinfo->bitshift; - } + integer >>= hfinfo_bitshift(hfinfo); } fvalue_set_uinteger(&fi->value, integer); @@ -3169,9 +3151,7 @@ proto_tree_set_int(field_info *fi, gint32 value) integer &= hfinfo->bitmask; /* Shift bits */ - if (hfinfo->bitshift > 0) { - integer >>= hfinfo->bitshift; - } + integer >>= hfinfo_bitshift(hfinfo); } fvalue_set_sinteger(&fi->value, integer); @@ -3572,8 +3552,7 @@ proto_tree_set_representation_value(proto_item *pi, const char *format, va_list 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); @@ -4390,7 +4369,6 @@ proto_register_protocol(const char *name, const char *short_name, 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 */ @@ -4979,11 +4957,6 @@ proto_register_field_init(header_field_info *hfinfo, const int parent) 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; @@ -5373,9 +5346,7 @@ fill_label_boolean(field_info *fi, gchar *label_str) /* 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); @@ -5453,8 +5424,8 @@ fill_label_bitfield(field_info *fi, gchar *label_str) /* 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 */ @@ -5563,6 +5534,26 @@ fill_label_number64(field_info *fi, gchar *label_str, gboolean is_signed) } 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) { int bitwidth = 0; @@ -6738,7 +6729,7 @@ proto_item_add_bitmask_tree(proto_item *item, tvbuff_t *tvb, const int offset, fields++; continue; } - tmpval = (value & hf->bitmask) >> hf->bitshift; + tmpval = (value & hf->bitmask) >> hfinfo_bitshift(hf); switch (hf->type) { case FT_INT8: diff --git a/epan/proto.h b/epan/proto.h index 378dd38ea2..8dfd85a05b 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -373,7 +373,7 @@ struct _header_field_info { 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 */ }; @@ -383,7 +383,7 @@ struct _header_field_info { * _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 { @@ -1863,8 +1863,8 @@ WS_DLL_PUBLIC void tree_expanded_set(int tree_type, gboolean value); extern int hfinfo_bitwidth(const header_field_info *hfinfo); - - +WS_DLL_PUBLIC int +hfinfo_bitshift(const header_field_info *hfinfo); #include "epan.h" diff --git a/epan/wspython/wspy_proto.c b/epan/wspython/wspy_proto.c index 10f7c07009..e315a73e2a 100644 --- a/epan/wspython/wspy_proto.c +++ b/epan/wspython/wspy_proto.c @@ -69,7 +69,6 @@ void hf_register_info_add(hf_register_info *hf, guint8 index, hf[index].hfinfo.id = 0; hf[index].hfinfo.parent = 0; hf[index].hfinfo.ref_type = HF_REF_TYPE_NONE; - hf[index].hfinfo.bitshift = 0; hf[index].hfinfo.same_name_next = NULL; hf[index].hfinfo.same_name_prev = NULL; } diff --git a/plugins/opcua/opcua_simpletypes.c b/plugins/opcua/opcua_simpletypes.c index 14a446b532..5ec23002e5 100644 --- a/plugins/opcua/opcua_simpletypes.c +++ b/plugins/opcua/opcua_simpletypes.c @@ -252,7 +252,7 @@ void registerSimpleTypes(int proto) { static hf_register_info hf[] = { - /* full name , abbreviation , type , display , strings, bitmask, blurb, id, parent, ref_count, bitshift */ + /* full name , abbreviation , type , display , strings, bitmask, blurb, id, parent, ref_count */ { &hf_opcua_diag_mask_symbolicflag, { "has symbolic id", "opcua.has_symbolic_id", FT_BOOLEAN, 8, NULL, DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID_FLAG, NULL, HFILL } }, diff --git a/plugins/opcua/opcua_transport_layer.c b/plugins/opcua/opcua_transport_layer.c index 427a1f6c41..09b3735ebe 100644 --- a/plugins/opcua/opcua_transport_layer.c +++ b/plugins/opcua/opcua_transport_layer.c @@ -60,7 +60,7 @@ void registerTransportLayerTypes(int proto) static hf_register_info hf[] = { { &hf_opcua_transport_type, - /* full name , abbreviation , type , display , strings, bitmask, blurb, id, parent, ref_count, bitshift */ + /* full name , abbreviation , type , display , strings, bitmask, blurb, id, parent, ref_count */ { "Message Type", "transport.type", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL } }, { &hf_opcua_transport_chunk, diff --git a/ui/gtk/packet_panes.c b/ui/gtk/packet_panes.c index 242cc8bb3b..9ae9888abe 100644 --- a/ui/gtk/packet_panes.c +++ b/ui/gtk/packet_panes.c @@ -933,7 +933,7 @@ packet_hex_print(GtkWidget *bv, const guint8 *pd, frame_data *fd, bstart = finfo->start; } - /* bmask = finfo->hfinfo->bitmask << finfo->hfinfo->bitshift; */ /* (value & mask) >> shift */ + /* bmask = finfo->hfinfo->bitmask << hfinfo_bitshift(finfo->hfinfo); */ /* (value & mask) >> shift */ if (finfo->hfinfo) bmask = finfo->hfinfo->bitmask; astart = finfo->appendix_start; alen = finfo->appendix_length; diff --git a/ui/gtk/packet_win.c b/ui/gtk/packet_win.c index 6e52c3438c..5c8ee53656 100644 --- a/ui/gtk/packet_win.c +++ b/ui/gtk/packet_win.c @@ -406,8 +406,8 @@ finfo_integer_changed(GtkSpinButton *spinbutton, gpointer user_data) return; } - if (hfinfo->bitmask && hfinfo->bitshift > 0) - u_val <<= hfinfo->bitshift; + if (hfinfo->bitmask) + u_val <<= hfinfo_bitshift(hfinfo); finfo_integer_common(DataPtr, u_val); } @@ -578,8 +578,8 @@ new_finfo_window(GtkWidget *w, struct FieldinfoWinData *DataPtr) if (finfo->length * 8 < bitcount) bitcount = finfo->length / 8; - if (hfinfo->bitmask && hfinfo->bitshift > 0) - bitcount -= hfinfo->bitshift; + if (hfinfo->bitmask) + bitcount -= hfinfo_bitshift(hfinfo); /* XXX, hfinfo->bitmask: Can we configure GTK_ADJUSTMENT to do custom step? (value-changed signal?) */ diff --git a/ui/qt/byte_view_tab.cpp b/ui/qt/byte_view_tab.cpp index d9fa9877de..225781681a 100644 --- a/ui/qt/byte_view_tab.cpp +++ b/ui/qt/byte_view_tab.cpp @@ -114,7 +114,7 @@ void ByteViewTab::protoTreeItemChanged(QTreeWidgetItem *current) { f_len = fi->length; } - /* bmask = finfo->hfinfo->bitmask << finfo->hfinfo->bitshift; */ /* (value & mask) >> shift */ + /* bmask = finfo->hfinfo->bitmask << hfinfo_bitshift(finfo->hfinfo); */ /* (value & mask) >> shift */ if (fi->hfinfo) bmask = fi->hfinfo->bitmask; fa_start = fi->appendix_start; fa_len = fi->appendix_length; |