summaryrefslogtreecommitdiff
path: root/utils/testgen
diff options
context:
space:
mode:
authorEli Bendersky <eliben@google.com>2012-12-20 19:16:57 +0000
committerEli Bendersky <eliben@google.com>2012-12-20 19:16:57 +0000
commitb17201f1b8c35414e3bbd71c3f37ee6313d77e86 (patch)
tree05841085087574982f5c7c3916c9a3839929c2bc /utils/testgen
parent16996c4940ad4248dc2a874d060b30e94e55b672 (diff)
Add a largish auto-generated test for the aligned bundling feature, along with
the script generating it. The test should never be modified manually. If anyone needs to change it, please change the script and re-run it. The script is placed into utils/testgen - I couldn't think of a better place, and after some discussion on IRC this looked like a logical location. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170720 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/testgen')
-rw-r--r--utils/testgen/mc-bundling-x86-gen.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/utils/testgen/mc-bundling-x86-gen.py b/utils/testgen/mc-bundling-x86-gen.py
new file mode 100644
index 00000000000..2088e876af7
--- /dev/null
+++ b/utils/testgen/mc-bundling-x86-gen.py
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+
+# Auto-generates an exhaustive and repetitive test for correct bundle-locked
+# alignment on x86.
+# For every possible offset in an aligned bundle, a bundle-locked group of every
+# size in the inclusive range [1, bundle_size] is inserted. An appropriate CHECK
+# is added to verify that NOP padding occurred (or did not occur) as expected.
+
+# This script runs with Python 2.6+ (including 3.x)
+
+from __future__ import print_function
+
+BUNDLE_SIZE_POW2 = 4
+BUNDLE_SIZE = 2 ** BUNDLE_SIZE_POW2
+
+PREAMBLE = '''
+# RUN: llvm-mc -filetype=obj -triple i386-pc-linux-gnu %s -o - \\
+# RUN: | llvm-objdump -triple i386 -disassemble -no-show-raw-insn - | FileCheck %s
+
+# !!! This test is auto-generated from utils/testgen/mc-bundling-x86-gen.py !!!
+# It tests that bundle-aligned grouping works correctly in MC. Read the
+# source of the script for more details.
+
+ .text
+ .bundle_align_mode {0}
+'''.format(BUNDLE_SIZE_POW2).lstrip()
+
+ALIGNTO = ' .align {0}, 0x90'
+NOPFILL = ' .fill {0}, 1, 0x90'
+
+def print_bundle_locked_sequence(len):
+ print(' .bundle_lock')
+ print(' .rept {0}'.format(len))
+ print(' inc %eax')
+ print(' .endr')
+ print(' .bundle_unlock')
+
+def generate():
+ print(PREAMBLE)
+
+ ntest = 0
+ for instlen in range(1, BUNDLE_SIZE + 1):
+ for offset in range(0, BUNDLE_SIZE):
+ # Spread out all the instructions to not worry about cross-bundle
+ # interference.
+ print(ALIGNTO.format(2 * BUNDLE_SIZE))
+ print('INSTRLEN_{0}_OFFSET_{1}:'.format(instlen, offset))
+ if offset > 0:
+ print(NOPFILL.format(offset))
+ print_bundle_locked_sequence(instlen)
+
+ # Now generate an appropriate CHECK line
+ base_offset = ntest * 2 * BUNDLE_SIZE
+ inst_orig_offset = base_offset + offset # had it not been padded...
+
+ if offset + instlen > BUNDLE_SIZE:
+ # Padding needed
+ print('# CHECK: {0:x}: nop'.format(inst_orig_offset))
+ aligned_offset = (inst_orig_offset + instlen) & ~(BUNDLE_SIZE - 1)
+ print('# CHECK: {0:x}: incl'.format(aligned_offset))
+ else:
+ # No padding needed
+ print('# CHECK: {0:x}: incl'.format(inst_orig_offset))
+
+ print()
+ ntest += 1
+
+if __name__ == '__main__':
+ generate()
+