Mike Klein | a708026 | 2017-01-09 10:20:13 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
| 2 | # |
| 3 | # Copyright 2017 Google Inc. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license that can be |
| 6 | # found in the LICENSE file. |
| 7 | |
| 8 | import re |
| 9 | import subprocess |
| 10 | import sys |
| 11 | |
Mike Klein | 8e619a2 | 2017-01-09 17:21:32 -0500 | [diff] [blame] | 12 | cflags = '-std=c++11 -Os -fomit-frame-pointer'.split() |
Mike Klein | a708026 | 2017-01-09 10:20:13 -0500 | [diff] [blame] | 13 | |
Mike Klein | 8e619a2 | 2017-01-09 17:21:32 -0500 | [diff] [blame] | 14 | hsw = '-mavx2 -mfma -mf16c'.split() |
| 15 | subprocess.check_call(['clang++'] + cflags + hsw + |
Mike Klein | a708026 | 2017-01-09 10:20:13 -0500 | [diff] [blame] | 16 | ['-c', 'src/splicer/SkSplicer_stages.cpp'] + |
Mike Klein | 8e619a2 | 2017-01-09 17:21:32 -0500 | [diff] [blame] | 17 | ['-o', 'hsw.o']) |
Mike Klein | f720098 | 2017-01-15 18:14:07 -0500 | [diff] [blame^] | 18 | subprocess.check_call(['clang++'] + cflags + hsw + |
| 19 | ['-c', 'src/splicer/SkSplicer_stages_lowp.cpp'] + |
| 20 | ['-o', 'hsw_lowp.o']) |
Mike Klein | 8e619a2 | 2017-01-09 17:21:32 -0500 | [diff] [blame] | 21 | |
| 22 | aarch64 = [ |
| 23 | '--target=aarch64-linux-android', |
| 24 | '--sysroot=' + |
| 25 | '/Users/mtklein/brew/opt/android-ndk/platforms/android-21/arch-arm64', |
| 26 | ] |
| 27 | subprocess.check_call(['clang++'] + cflags + aarch64 + |
| 28 | ['-c', 'src/splicer/SkSplicer_stages.cpp'] + |
| 29 | ['-o', 'aarch64.o']) |
Mike Klein | f720098 | 2017-01-15 18:14:07 -0500 | [diff] [blame^] | 30 | subprocess.check_call(['clang++'] + cflags + aarch64 + |
| 31 | ['-c', 'src/splicer/SkSplicer_stages_lowp.cpp'] + |
| 32 | ['-o', 'aarch64_lowp.o']) |
Mike Klein | a708026 | 2017-01-09 10:20:13 -0500 | [diff] [blame] | 33 | |
Mike Klein | 4ef8cb3 | 2017-01-12 11:36:46 -0500 | [diff] [blame] | 34 | armv7 = [ |
| 35 | '--target=arm-linux-androideabi', |
| 36 | '--sysroot=' + |
| 37 | '/Users/mtklein/brew/opt/android-ndk/platforms/android-18/arch-arm', |
| 38 | '-march=armv7-a', |
| 39 | '-mfpu=neon-vfpv4', |
| 40 | ] |
| 41 | subprocess.check_call(['clang++'] + cflags + armv7 + |
| 42 | ['-c', 'src/splicer/SkSplicer_stages.cpp'] + |
| 43 | ['-o', 'armv7.o']) |
Mike Klein | f720098 | 2017-01-15 18:14:07 -0500 | [diff] [blame^] | 44 | subprocess.check_call(['clang++'] + cflags + armv7 + |
| 45 | ['-c', 'src/splicer/SkSplicer_stages_lowp.cpp'] + |
| 46 | ['-o', 'armv7_lowp.o']) |
Mike Klein | 4ef8cb3 | 2017-01-12 11:36:46 -0500 | [diff] [blame] | 47 | |
Mike Klein | f720098 | 2017-01-15 18:14:07 -0500 | [diff] [blame^] | 48 | def parse_object_file(dst, dot_o, array_type, done, target=None): |
Mike Klein | 4ef8cb3 | 2017-01-12 11:36:46 -0500 | [diff] [blame] | 49 | cmd = ['gobjdump', '-d', dot_o] |
| 50 | if target: |
| 51 | cmd += ['--target', target] |
| 52 | for line in subprocess.check_output(cmd).split('\n'): |
Mike Klein | fb00390 | 2017-01-10 16:11:15 -0500 | [diff] [blame] | 53 | line = line.strip() |
| 54 | if not line or line.startswith(dot_o) or line.startswith('Disassembly'): |
| 55 | continue |
| 56 | |
| 57 | # E.g. 00000000000003a4 <_load_f16>: |
Mike Klein | 4ef8cb3 | 2017-01-12 11:36:46 -0500 | [diff] [blame] | 58 | m = re.match('''[0-9a-f]+ <_?(.*)>:''', line) |
Mike Klein | fb00390 | 2017-01-10 16:11:15 -0500 | [diff] [blame] | 59 | if m: |
Mike Klein | f720098 | 2017-01-15 18:14:07 -0500 | [diff] [blame^] | 60 | print >>dst,'static const', array_type, 'kSplice_' + m.group(1) + '[] = {' |
Mike Klein | fb00390 | 2017-01-10 16:11:15 -0500 | [diff] [blame] | 61 | continue |
| 62 | |
| 63 | columns = line.split('\t') |
| 64 | code = columns[1] |
Mike Klein | 4ef8cb3 | 2017-01-12 11:36:46 -0500 | [diff] [blame] | 65 | if len(columns) >= 4: |
Mike Klein | fb00390 | 2017-01-10 16:11:15 -0500 | [diff] [blame] | 66 | inst = columns[2] |
| 67 | args = columns[3] |
| 68 | else: |
| 69 | inst, args = columns[2].split(' ', 1) |
| 70 | code, inst, args = code.strip(), inst.strip(), args.strip() |
| 71 | |
| 72 | # We can't splice code that uses ip-relative addressing. |
| 73 | for arg in args: |
| 74 | assert 'rip' not in arg # TODO: detect on aarch64 too |
| 75 | |
| 76 | if code == done: |
Mike Klein | f720098 | 2017-01-15 18:14:07 -0500 | [diff] [blame^] | 77 | print >>dst,'};' |
Mike Klein | fb00390 | 2017-01-10 16:11:15 -0500 | [diff] [blame] | 78 | continue |
| 79 | |
| 80 | hexed = ''.join('0x'+x+',' for x in code.split(' ')) |
Mike Klein | f720098 | 2017-01-15 18:14:07 -0500 | [diff] [blame^] | 81 | print >>dst,' ' + hexed + ' '*(44-len(hexed)) + \ |
| 82 | '// ' + inst + ' '*(14-len(inst)) + args |
Mike Klein | fb00390 | 2017-01-10 16:11:15 -0500 | [diff] [blame] | 83 | |
Mike Klein | f720098 | 2017-01-15 18:14:07 -0500 | [diff] [blame^] | 84 | for suffix in ['', '_lowp']: |
| 85 | with open('src/splicer/SkSplicer_generated%s.h' % suffix, 'w') as f: |
| 86 | print >>f,'''/* |
Mike Klein | a708026 | 2017-01-09 10:20:13 -0500 | [diff] [blame] | 87 | * Copyright 2017 Google Inc. |
| 88 | * |
| 89 | * Use of this source code is governed by a BSD-style license that can be |
| 90 | * found in the LICENSE file. |
| 91 | */ |
| 92 | |
Mike Klein | f720098 | 2017-01-15 18:14:07 -0500 | [diff] [blame^] | 93 | #ifndef SkSplicer_generated%s_DEFINED |
| 94 | #define SkSplicer_generated%s_DEFINED |
Mike Klein | a708026 | 2017-01-09 10:20:13 -0500 | [diff] [blame] | 95 | |
| 96 | // This file is generated semi-automatically with this command: |
Mike Klein | f720098 | 2017-01-15 18:14:07 -0500 | [diff] [blame^] | 97 | // $ src/splicer/build_stages.py |
Mike Klein | 8e619a2 | 2017-01-09 17:21:32 -0500 | [diff] [blame] | 98 | |
| 99 | #if defined(__aarch64__) |
Mike Klein | f720098 | 2017-01-15 18:14:07 -0500 | [diff] [blame^] | 100 | ''' % (suffix, suffix) |
| 101 | parse_object_file(f, 'aarch64%s.o' % suffix, 'unsigned int', '14000000') |
| 102 | print >>f,'\n#elif defined(__ARM_NEON__)\n' |
| 103 | parse_object_file(f, 'armv7%s.o' % suffix, 'unsigned int', 'eafffffe', |
| 104 | target='elf32-littlearm') |
| 105 | print >>f,'\n#else\n' |
| 106 | parse_object_file(f, 'hsw%s.o' % suffix, 'unsigned char', 'e9 00 00 00 00') |
| 107 | print >>f,'\n#endif\n' |
| 108 | print >>f,'#endif//SkSplicer_generated%s_DEFINED' % suffix |