On Wed, 2014-02-26 at 16:10 +0000, David Laight wrote:
From: Alexander Aring
[]
quoted
diff --git a/net/ieee802154/6lowpan.h b/net/ieee802154/6lowpan.h
[]
quoted
+static inline u8 lowpan_addr_mode_size(const u8 addr_mode)
+{
+ switch (addr_mode) {
+ case LOWPAN_IPHC_ADDR_00:
+ return 16;
+ case LOWPAN_IPHC_ADDR_01:
+ return 8;
+ case LOWPAN_IPHC_ADDR_02:
+ return 2;
+ default:
+ return 0;
+ }
+}
The compiler will generate much better code if you index an array instead
of using a switch statement.
Are you sure of that?
Perhaps the compiler would inline the assignment
anyway if addr_mode is __builtin_constant_p
gcc 4.8 here does the same thing with:
static inline unsigned char f1(unsigned char a)
{
switch (a) {
case 0: return 16;
case 1: return 8;
case 2: return 2;
default: return 0;
}
}
static inline unsigned char f2(unsigned char a)
{
static const unsigned char rtns[] = { 16, 8, 2, 0 };
return rtns[a & 3];
}