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
|
int g( int c ) { return ++c ; }
int h( int c ) { return g(c) + 1 ; }
int i( int c ) { return h(c) + 1 ; }
int j( int c ) { return i(c) + 1 ; }
static int (* const table [] )(int) { &g, &h, &i, &j } ;
int fn( int arg, unsigned int pos )
{
return table[pos%4](arg) ;
}
int foo()
{
return fn( 10, 3 ) ;
// return 14 ;
/* completely inlined, result computed at compile-time
movl $14, %eax
retq
*/
}
int bar( int a, unsigned int b )
{
return fn( a, b ) ;
// jump to table[ b&3 ]
/* fn inlined, followed by jump to the result of the table lookup
andl $3, %esi
jmpq *_ZL5table(,%rsi,8) # TAILCALL
*/
}
int baz()
{
return bar( 25, 19 ) ;
// return 29 ;
/* completely inlined, result computed at compile-time
movl $29, %eax
retq
*/
}
|