| 1 | |
|---|
| 2 | ARB compiles with vectorization (enabled by -O3 in NDEBUG or RELEASE mode). |
|---|
| 3 | The vectorization check is automatically activated for gcc versions >= 4.9.0 |
|---|
| 4 | Compiler output of earlier versions is not suitable for automated checks. |
|---|
| 5 | |
|---|
| 6 | To ensure that code does not degrade (i.e. does not fail to vectorize), the |
|---|
| 7 | compiler output is searched for successful vectorizations and the result is |
|---|
| 8 | checked against special comments in code. |
|---|
| 9 | |
|---|
| 10 | Currently there are 2 types of comments for vectorization-checks: |
|---|
| 11 | |
|---|
| 12 | IRRELEVANT_LOOP |
|---|
| 13 | LOOP_VECTORIZED[[<count>][<conditions>]]* |
|---|
| 14 | |
|---|
| 15 | Use IRRELEVANT_LOOP to mark a loop where vectorization occurs (maybe only |
|---|
| 16 | sometimes) and where it isn't mandatory. No error or warning will show if |
|---|
| 17 | vectorization fails. |
|---|
| 18 | |
|---|
| 19 | Note: You have to use IRRELEVANT_LOOP for conditional code (e.g. unittest code) |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | Use LOOP_VECTORIZED for loops that SHALL get vectorized (i.e. loops with |
|---|
| 23 | relevant impact on performance). If vectorization fails for a loop commented |
|---|
| 24 | with LOOP_VECTORIZED, compilation will fail with an error. |
|---|
| 25 | |
|---|
| 26 | The optional argument <count> allows to specify the amount of performed |
|---|
| 27 | vectorizations. This is relevant if the loop is part of a template, gets |
|---|
| 28 | vectorized multiple times and it shall be ensured that the vectorizations |
|---|
| 29 | happens for each instanciation of that template. |
|---|
| 30 | |
|---|
| 31 | The standard syntax of the <count> argument is "=<num>". |
|---|
| 32 | This requires that <num> vectorizations take place. |
|---|
| 33 | The default for <count> is "=1" (if not specified; only directly after LOOP_VECTORIZED). |
|---|
| 34 | |
|---|
| 35 | Sometimes the count depends on optimization level (esp. whether a |
|---|
| 36 | function gets inlined or not). You may specify '=<num>|<num>' to allow |
|---|
| 37 | several different amounts of accepted vectorizations. |
|---|
| 38 | (Hint: test with DEBUG=0 and UNIT_TEST=0 to check under RELEASE conditions) |
|---|
| 39 | |
|---|
| 40 | Sometimes the count depends on whether UNIT_TESTS are active or not. |
|---|
| 41 | |
|---|
| 42 | The 2nd optional argument <conditions> allows to include/exclude compiler |
|---|
| 43 | versions that succeed/fail to vectorize that loop with the specified count. |
|---|
| 44 | |
|---|
| 45 | The syntax is "["<cond>[","<cond>]*"]". |
|---|
| 46 | <cond> has the following syntax: |
|---|
| 47 | ["!"]("<"|">")["="]<version> |
|---|
| 48 | |
|---|
| 49 | <version> is a specific compiler version (e.g. "4.9.3" or "493" or "5"). |
|---|
| 50 | |
|---|
| 51 | Multiple conditions can be specified in one <cond>, e.g. "!>=5<7" excludes |
|---|
| 52 | all compilers of 5.x and 6.x series. |
|---|
| 53 | |
|---|
| 54 | Examples for <cond>: |
|---|
| 55 | |
|---|
| 56 | 493 only version 4.9.3 |
|---|
| 57 | !493 all but 4.9.3 |
|---|
| 58 | >493 all versions after 4.9.3 |
|---|
| 59 | >=5<7 5.x and 6.x-series |
|---|
| 60 | !>=8<9 all but 8.x series |
|---|
| 61 | |
|---|
| 62 | Example: // LOOP_VECTORIZED[!493,!531] |
|---|
| 63 | => expects vectorization occurs for all compiler versions but 4.9.3 and 5.3.1 |
|---|
| 64 | |
|---|
| 65 | Warning: <conditions> reports true only if ALL <cond> are true! |
|---|
| 66 | => // LOOP_VECTORIZED[493,531] |
|---|
| 67 | will NEVER be true!!! |
|---|
| 68 | |
|---|
| 69 | To chain conditions by OR operator, use |
|---|
| 70 | // LOOP_VECTORIZED[493][531] |
|---|
| 71 | |
|---|
| 72 | Included code: |
|---|
| 73 | |
|---|
| 74 | Vectorization checks do not work very well with included code (e.g. inline |
|---|
| 75 | code from headers): IRRELEVANT_LOOP behaves normal, but LOOP_VECTORIZED may |
|---|
| 76 | differ for different includers. 'LOOP_VECTORIZED=*' might work, but is not |
|---|
| 77 | recommended, because if code starts to fail vectorization, no warning will |
|---|
| 78 | show up! If possible better move code from header into source. |
|---|
| 79 | |
|---|
| 80 | Recompilation needed for complete check: |
|---|
| 81 | |
|---|
| 82 | To force a complete check of expected vectorizations call target |
|---|
| 83 | 'clean_checked_vect' before build! Previous failures (only) in |
|---|
| 84 | vectorization-check will not delete the generated object file, i.e. w/o |
|---|
| 85 | change of the affected source file no re-compilation will happen. |
|---|
| 86 | |
|---|
| 87 | Alternative ways to use vectorization checker: |
|---|
| 88 | |
|---|
| 89 | Set ../Makefile@TRACE_MISSED_VECTORIZATIONS |
|---|
| 90 | to 1 to dump details about performed and failed vectorizations. |
|---|
| 91 | |
|---|
| 92 | Set ../Makefile@VECTORIZATION_CHECK_CANDIDATES |
|---|
| 93 | to 1 to dump candidates from unchecked files. |
|---|
| 94 | |
|---|
| 95 | Related stuff: |
|---|
| 96 | |
|---|
| 97 | If you encounter problems caused by vectorization, you may use |
|---|
| 98 | ../TEMPLATES/attributes.h@__ATTR__DONT_VECTORIZE |
|---|
| 99 | |
|---|
| 100 | Some pointers (if you need to adapt vectorization checking): |
|---|
| 101 | |
|---|
| 102 | - global vectorization toggles: |
|---|
| 103 | ../Makefile@DISABLE_VECTORIZE_CHECK |
|---|
| 104 | (automatically disabled if sanitizer enabled) |
|---|
| 105 | ../Makefile@TRACE_MISSED_VECTORIZATIONS |
|---|
| 106 | ../Makefile@VECTORIZATION_CHECK_CANDIDATES |
|---|
| 107 | |
|---|
| 108 | - the build maintains a list of source-files to be checked using |
|---|
| 109 | target 'vectorize_checks' (called via target 'depends'). |
|---|
| 110 | The list is stored in ./vectorized.source |
|---|
| 111 | and is generated by ./Makefile@vectorize_checks |
|---|
| 112 | |
|---|
| 113 | - the actual check is performed by ./postcompile.pl@parse_expected_vectorizations |
|---|