XL C/C++ for AIX, V13.1.2 IBM
Total Page:16
File Type:pdf, Size:1020Kb
IBM XL C/C++ for AIX, V13.1.2 IBM Optimization and Programming Guide Version 13.1.2 SC27-4261-01 IBM XL C/C++ for AIX, V13.1.2 IBM Optimization and Programming Guide Version 13.1.2 SC27-4261-01 Note Before using this information and the product it supports, read the information in “Notices” on page 185. First edition This edition applies to IBM XL C/C++ for AIX, V13.1.2 (Program 5765-J07; 5725-C72) and to all subsequent releases and modifications until otherwise indicated in new editions. Make sure you are using the correct edition for the level of the product. © Copyright IBM Corporation 1996, 2015. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents About this document ........ vii Using a heap ............. 33 Who should read this document ....... vii Getting information about a heap ...... 34 How to use this document ......... vii Closing and destroying a heap ....... 34 How this document is organized ....... vii Changing the default heap used in a program .. 35 Conventions .............. viii Compiling and linking a program with Related information ........... xii user-created heaps ........... 35 IBM XL C/C++ information ........ xii Example of a user heap with regular memory .. 35 Standards and specifications ....... xiii Debugging memory heaps ......... 36 Other IBM information ......... xiv Functions for checking memory heaps .... 37 Other information ........... xiv Functions for debugging memory heaps .... 37 Technical support ............ xiv Using memory allocation fill patterns..... 39 How to send your comments ........ xiv Skipping heap checking ......... 39 Using stack traces ........... 40 Chapter 1. Using 32-bit and 64-bit modes ............... 1 Chapter 6. Using C++ constructors .. 41 Assigning long values ........... 2 Using delegating constructors (C++11) ..... 41 Assigning constant values to long variables ... 2 Bit-shifting long values .......... 3 Chapter 7. Using C++ templates .... 43 Assigning pointers ............ 3 Using the -qtempinc compiler option ...... 44 Aligning aggregate data .......... 4 Example of using -qtempinc ........ 45 Calling Fortran code ............ 4 Regenerating the template instantiation file ... 46 Using -qtempinc with shared libraries .... 46 Chapter 2. Using XL C/C++ with Fortran 7 Using the -qtemplateregistry compiler option ... 46 Identifiers ............... 7 Recompiling related compilation units .... 47 Corresponding data types .......... 8 Switching from -qtempinc to -qtemplateregistry 48 Character and aggregate data ........ 10 Using explicit instantiation declarations (C++11) .. 48 Function calls and parameter passing ...... 11 Pointers to functions ........... 11 Chapter 8. Constructing a library ... 51 Sample program: C/C++ calling Fortran..... 11 Compiling and linking a library ....... 51 Compiling a static library......... 51 Chapter 3. Aligning data ....... 13 Compiling a shared library ........ 51 Using alignment modes .......... 13 Exporting symbols with the CreateExportList Alignment of aggregates ......... 15 utility ............... 53 Alignment of bit-fields.......... 18 Linking a library to an application...... 54 Using alignment modifiers ......... 19 Linking a shared library to another shared library 55 Initializing static objects in libraries (C++) .... 55 Chapter 4. Handling floating-point Assigning priorities to objects ....... 55 Order of object initialization across libraries .. 57 operations ............. 23 Dynamically loading a shared library...... 60 Floating-point formats ........... 23 Loading and initializing a module with the Handling multiply-add operations....... 24 loadAndInit function .......... 60 Compiling for strict IEEE conformance ..... 24 Terminating and unloading a module with the Handling floating-point constant folding and terminateAndUnload function ....... 62 rounding ............... 25 Matching compile-time and runtime rounding Chapter 9. Replacing operator new and modes ............... 25 operator delete in applications that use Rounding modes and standard library functions 26 Handling floating-point exceptions ...... 27 shared libraries (C++) ........ 63 Compiling a decimal floating-point program ... 28 Chapter 10. Using the C++ utilities ... 65 Chapter 5. Using memory heaps.... 29 Demangling compiled C++ names ....... 65 Managing memory with multiple heaps ..... 29 Demangling compiled C++ names with c++filt 65 Functions for managing user-created heaps ... 30 Demangling compiled C++ names with the Creating a heap ............ 31 demangle class library .......... 66 Expanding a heap ........... 32 © Copyright IBM Corp. 1996, 2015 iii Creating a shared library with the Optimizing expressions and program logic ... 114 makeC++SharedLib utility ......... 68 Optimizing operations in 64-bit mode ..... 114 Linking with the linkxlC utility........ 70 Tracing functions in your code........ 115 Using rvalue references (C++11) ....... 119 Chapter 11. Optimizing your Using visibility attributes (IBM extension) .... 121 applications ............ 71 Types of visibility attributes ....... 122 Rules of visibility attributes ....... 124 Distinguishing between optimization and tuning .. 71 Propagation rules (C++ only) ....... 130 Steps in the optimization process ....... 72 Specifying visibility attributes using the Basic optimization ............ 72 -qvisibility option .......... 132 Optimizing at level 0 .......... 72 Specifying visibility attributes using pragma Optimizing at level 2 .......... 73 preprocessor directives ......... 132 Advanced optimization .......... 74 Optimizing at level 3 .......... 75 An intermediate step: adding -qhot suboptions at Chapter 14. Using the high level 3 ............... 76 performance libraries ........ 135 Optimizing at level 4 .......... 76 Using the Mathematical Acceleration Subsystem Optimizing at level 5 .......... 77 libraries (MASS) ............ 135 Tuning for your system architecture ...... 78 Using the scalar library ......... 136 Getting the most out of target machine options 79 Using the vector libraries ........ 138 Using high-order loop analysis and transformations 80 Using the SIMD libraries ........ 144 Getting the most out of -qhot ....... 81 Compiling and linking a program with MASS 147 Using shared-memory parallelism (SMP) .... 82 Using the Basic Linear Algebra Subprograms – Getting the most out of -qsmp ....... 83 BLAS ................ 148 Using interprocedural analysis ........ 84 BLAS function syntax ......... 148 Getting the most from -qipa ........ 85 Linking the libxlopt library ........ 150 Using profile-directed feedback ........ 86 Viewing profiling information with showpdf .. 90 Chapter 15. Parallelizing your Object level profile-directed feedback ..... 93 programs ............. 153 Handling table of contents (TOC) overflow .... 94 Countable loops ............ 154 Options for reducing the number of global Enabling automatic parallelization ...... 155 symbols .............. 94 Using IBM SMP directives (C only) ...... 155 Options for enlarging the TOC access range .. 95 Data sharing attribute rules......... 156 Performance considerations of handling TOC Using OpenMP directives ......... 158 overflow .............. 96 Shared and private variables in a parallel Marking variables as local or imported ..... 97 environment.............. 159 Getting the most out of -qdatalocal ..... 97 Reduction operations in parallelized loops.... 161 Using compiler reports to diagnose optimization opportunities .............. 99 Parsing compiler reports with development Chapter 16. Selecting the standard tools ............... 100 allocation method to suit performance Other optimization options ......... 101 (C++) ............... 163 Chapter 12. Debugging optimized Chapter 17. Ensuring thread safety code ............... 103 (C++) ............... 165 Understanding different results in optimized Ensuring thread safety of template objects.... 165 programs ............... 104 Ensuring thread safety of stream objects .... 165 Debugging in the presence of optimization ... 104 Using -qoptdebug to help debug optimized Chapter 18. Memory debug library programs ............... 105 functions ............. 167 Memory allocation debug functions ...... 167 Chapter 13. Coding your application _debug_calloc — Allocate and initialize memory 167 to improve performance....... 109 _debug_free — Free allocated memory .... 168 Finding faster input/output techniques..... 109 _debug_heapmin — Free unused memory in the Reducing function-call overhead ....... 109 default heap............. 169 Using delegating constructors (C++11) ..... 111 _debug_malloc — Allocate memory ..... 171 Using template explicit instantiation declarations _debug_ucalloc — Reserve and initialize (C++11) ............... 111 memory from a user-created heap ..... 172 Managing memory efficiently (C++ only) .... 112 _debug_uheapmin — Free unused memory in a Optimizing variables ........... 112 user-created heap ........... 173 Manipulating strings efficiently ....... 113 iv XL C/C++: Optimization and Programming Guide _debug_umalloc — Reserve memory blocks _debug_strncat — Concatenate strings .... 181 from a user-created heap ........ 174 _debug_strncpy — Copy strings ...... 182 _debug_realloc — Reallocate memory block .. 175 String handling debug functions ....... 176 Notices .............. 185 _debug_memcpy — Copy bytes ...... 176 Trademarks .............. 187 _debug_memset — Set bytes to value .... 178 _debug_strcat — Concatenate strings .... 179 Index ..............