Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Commit 33e58aa

Browse files
authored
Merge pull request #99 from arunetm/AddSpecTests
Adding new spec tests
2 parents b4f1d81 + 72cf738 commit 33e58aa

20 files changed

+18410
-0
lines changed

test/core/simd/meta/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated SIMD Spec Tests from gen_tests.py
2+
3+
`gen_tests.py` builds partial SIMD spec tests using templates in `simd_*.py`.
4+
Currently it only support following simd test files generation.
5+
6+
- 'simd_i8x16_cmp.wast'
7+
- 'simd_i16x8_cmp.wast'
8+
- 'simd_i32x4_cmp.wast'
9+
- 'simd_f32x4_cmp.wast'
10+
11+
12+
Usage:
13+
14+
```
15+
$ python gen_tests.py -a
16+
```
17+
18+
More details documented in `gen_tests.py`.

test/core/simd/meta/gen_tests.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
This script is used for generating WebAssembly SIMD test cases.
5+
"""
6+
import sys
7+
import argparse
8+
import importlib
9+
10+
11+
SUBMODULES = (
12+
'simd_i8x16_cmp',
13+
'simd_i16x8_cmp',
14+
'simd_i32x4_cmp',
15+
'simd_f32x4_cmp',
16+
)
17+
18+
19+
def gen_group_tests(mod_name):
20+
"""mod_name is the back-end script name without the.py extension.
21+
There must be a gen_test_cases() function in each module."""
22+
mod = importlib.import_module(mod_name)
23+
mod.gen_test_cases()
24+
25+
26+
def main():
27+
parser = argparse.ArgumentParser(
28+
description='Front-end script to call other modules to generate SIMD tests')
29+
parser.add_argument('-a', '--all', dest='gen_all', action='store_true',
30+
default=False, help='Generate all the tests')
31+
parser.add_argument('-i', '--inst', dest='inst_group', choices=SUBMODULES,
32+
help='Back-end scripts that generate the SIMD tests')
33+
args = parser.parse_args()
34+
35+
if len(sys.argv) < 2:
36+
parser.print_help()
37+
38+
if args.inst_group:
39+
gen_group_tests(args.inst_group)
40+
if args.gen_all:
41+
for mod_name in SUBMODULES:
42+
gen_group_tests(mod_name)
43+
44+
45+
if __name__ == '__main__':
46+
main()
47+
print('Done.')

test/core/simd/meta/simd.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
This python file is a tool class for SIMD and
6+
currently only supports generating v128 const constant data.
7+
"""
8+
9+
10+
class SIMD(object):
11+
12+
# v128 Constant template
13+
V128_CONST = '(v128.const {} {})'
14+
15+
# Params:
16+
# val: constant data, string or list,
17+
# lane_type: lane type, [i8x16, i16x8, i32x4, f32x4]
18+
def v128_const(self, val, lane_type):
19+
20+
lane_cnt = int(lane_type[1:].split('x')[1])
21+
22+
# val is a string type, generating constant data
23+
# of val according to the number of lanes
24+
if isinstance(val, str):
25+
data_elem = [val] * lane_cnt
26+
27+
# If val is type of list, generate constant data
28+
# according to combination of list contents and number of lanes
29+
elif isinstance(val, list):
30+
31+
# If it is an empty list, generate all constant data with 0x00
32+
if len(val) == 0:
33+
return self.v128_const('0x00', lane_type)
34+
35+
data_elem = []
36+
37+
# Calculate the number of times each element in val is copied
38+
times = lane_cnt // len(val)
39+
40+
# Calculate whether the data needs to be filled according to
41+
# the number of elements in the val list and the number of lanes.
42+
complement = lane_cnt % len(val)
43+
complement_item = ''
44+
45+
# If the number of elements in the val list is greater than the number of lanes,
46+
# paste data with the number of lanes from the val list.
47+
if times == 0:
48+
times = 1
49+
complement = 0
50+
51+
val = val[0:lane_cnt]
52+
53+
# Copy data
54+
for item in val:
55+
data_elem.extend([item] * times)
56+
complement_item = item
57+
58+
# Fill in the data
59+
if complement > 0:
60+
data_elem.extend([complement_item] * complement)
61+
62+
# Get string
63+
data_elem = ' '.join(data_elem)
64+
65+
# Returns v128 constant text
66+
return self.V128_CONST.format(lane_type, data_elem)

0 commit comments

Comments
 (0)