Skip to contentSkip to conversation

: Avoid expensive divides

VLAN Applied Eric Dumazet 2 participants 2 messages Jan 8, 2008 – Jan 9, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

We can avoid divides (as seen with CONFIG_CC_OPTIMIZE_FOR_SIZE=y on x86) changing vlan_group_get_device()/vlan_group_set_device() id parameter from signed to unsigned.

include/linux/if_vlan.h +4 -2
index 976d4b1..4562105 100644
@@ -81,14 +81,16 @@ struct vlan_group {
 	struct rcu_head		rcu;
 };
 
-static inline struct net_device *vlan_group_get_device(struct vlan_group *vg, int vlan_id)
+static inline struct net_device *vlan_group_get_device(struct vlan_group *vg,
+						       unsigned int vlan_id)
 {
 	struct net_device **array;
 	array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
 	return array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN];
 }
 
-static inline void vlan_group_set_device(struct vlan_group *vg, int vlan_id,
+static inline void vlan_group_set_device(struct vlan_group *vg,
+					 unsigned int vlan_id,
 					 struct net_device *dev)
 {
 	struct net_device **array;
maintainer Applied
#1 lore raw

From: Eric Dumazet <[email protected]>
Date: Tue, 08 Jan 2008 12:28:52 +0100

Quoted 6 lines

We can avoid divides (as seen with CONFIG_CC_OPTIMIZE_FOR_SIZE=y on x86) changing vlan_group_get_device()/vlan_group_set_device() id parameter from signed to
unsigned.

Applied, thanks Eric.