■ Contents
xv
15.7.3 Accessing an External Variable ..........................................................................................................306
15.7.4 Complete Assembly Example ............................................................................................................ 307
15.7.5 Mixing C and Assembly......................................................................................................................308
15.8 Which Objects Are Linked? ...................................................................................... 310
15.9 Optimizations ........................................................................................................... 313
15.10 Code Models .......................................................................................................... 315
15.10.1 Small Code Model (No PIC) .............................................................................................................. 317
15.10.2 Large Code Model (No PIC) .............................................................................................................. 318
15.10.3 Medium Code Model (No PIC) .......................................................................................................... 318
15.10.4 Small PIC Code Model...................................................................................................................... 319
15.10.5 Large PIC Code Model ......................................................................................................................320
15.10.6 Medium PIC Code Model .................................................................................................................. 322
15.11 Summary ............................................................................................................... 324
■Chapter 16: Performance ����������������������������������������������������������������������������������� 327
16.1 Optimizations ........................................................................................................... 327
16.1.1 Myth About Fast Languages .............................................................................................................. 327
16.1.2 General Advice ................................................................................................................................... 328
16.1.3 Omit Stack Frame Pointer ..................................................................................................................329
16.1.4 Tail recursion ..................................................................................................................................... 330
16.1.5 Common Subexpressions Elimination ...............................................................................................333
16.1.6 Constant Propagation ........................................................................................................................ 334
16.1.7 (Named) Return Value Optimization ...................................................................................................336
16.1.8 Influence of Branch Prediction ..........................................................................................................338
16.1.9 Influence of Execution Units .............................................................................................................. 338
16.1.10 Grouping Reads and Writes in Code ................................................................................................ 340
16.2 Caching .................................................................................................................... 340
16.2.1 How Do We use Cache Effectively? ................................................................................................... 340
16.2.2 Prefetching ........................................................................................................................................341
16.2.3 Example: Binary Search with Prefetching .........................................................................................342
16.2.4 Bypassing Cache ...............................................................................................................................345
16.2.5 Example: Matrix Initialization ............................................................................................................. 346