Eli Bendersky | b17201f | 2012-12-20 19:16:57 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | # Auto-generates an exhaustive and repetitive test for correct bundle-locked |
| 4 | # alignment on x86. |
| 5 | # For every possible offset in an aligned bundle, a bundle-locked group of every |
| 6 | # size in the inclusive range [1, bundle_size] is inserted. An appropriate CHECK |
| 7 | # is added to verify that NOP padding occurred (or did not occur) as expected. |
| 8 | |
| 9 | # This script runs with Python 2.6+ (including 3.x) |
| 10 | |
| 11 | from __future__ import print_function |
| 12 | |
| 13 | BUNDLE_SIZE_POW2 = 4 |
| 14 | BUNDLE_SIZE = 2 ** BUNDLE_SIZE_POW2 |
| 15 | |
| 16 | PREAMBLE = ''' |
| 17 | # RUN: llvm-mc -filetype=obj -triple i386-pc-linux-gnu %s -o - \\ |
| 18 | # RUN: | llvm-objdump -triple i386 -disassemble -no-show-raw-insn - | FileCheck %s |
| 19 | |
| 20 | # !!! This test is auto-generated from utils/testgen/mc-bundling-x86-gen.py !!! |
| 21 | # It tests that bundle-aligned grouping works correctly in MC. Read the |
| 22 | # source of the script for more details. |
| 23 | |
| 24 | .text |
| 25 | .bundle_align_mode {0} |
| 26 | '''.format(BUNDLE_SIZE_POW2).lstrip() |
| 27 | |
| 28 | ALIGNTO = ' .align {0}, 0x90' |
| 29 | NOPFILL = ' .fill {0}, 1, 0x90' |
| 30 | |
| 31 | def print_bundle_locked_sequence(len): |
| 32 | print(' .bundle_lock') |
| 33 | print(' .rept {0}'.format(len)) |
| 34 | print(' inc %eax') |
| 35 | print(' .endr') |
| 36 | print(' .bundle_unlock') |
| 37 | |
| 38 | def generate(): |
| 39 | print(PREAMBLE) |
| 40 | |
| 41 | ntest = 0 |
| 42 | for instlen in range(1, BUNDLE_SIZE + 1): |
| 43 | for offset in range(0, BUNDLE_SIZE): |
| 44 | # Spread out all the instructions to not worry about cross-bundle |
| 45 | # interference. |
| 46 | print(ALIGNTO.format(2 * BUNDLE_SIZE)) |
| 47 | print('INSTRLEN_{0}_OFFSET_{1}:'.format(instlen, offset)) |
| 48 | if offset > 0: |
| 49 | print(NOPFILL.format(offset)) |
| 50 | print_bundle_locked_sequence(instlen) |
| 51 | |
| 52 | # Now generate an appropriate CHECK line |
| 53 | base_offset = ntest * 2 * BUNDLE_SIZE |
| 54 | inst_orig_offset = base_offset + offset # had it not been padded... |
| 55 | |
| 56 | if offset + instlen > BUNDLE_SIZE: |
| 57 | # Padding needed |
| 58 | print('# CHECK: {0:x}: nop'.format(inst_orig_offset)) |
| 59 | aligned_offset = (inst_orig_offset + instlen) & ~(BUNDLE_SIZE - 1) |
| 60 | print('# CHECK: {0:x}: incl'.format(aligned_offset)) |
| 61 | else: |
| 62 | # No padding needed |
| 63 | print('# CHECK: {0:x}: incl'.format(inst_orig_offset)) |
| 64 | |
| 65 | print() |
| 66 | ntest += 1 |
| 67 | |
| 68 | if __name__ == '__main__': |
| 69 | generate() |
| 70 | |