Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions test/core/simd/meta/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated SIMD Spec Tests from gen_tests.py

`gen_tests.py` builds partial SIMD spec tests using templates in `simd_*.py`.
Currently it only support following simd test files generation.

- 'simd_i8x16_cmp.wast'
- 'simd_i16x8_cmp.wast'
- 'simd_i32x4_cmp.wast'
- 'simd_f32x4_cmp.wast'


Usage:

```
$ python gen_tests.py -a
```

More details documented in `gen_tests.py`.
47 changes: 47 additions & 0 deletions test/core/simd/meta/gen_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3

"""
This script is used for generating WebAssembly SIMD test cases.
"""
import sys
import argparse
import importlib


SUBMODULES = (
'simd_i8x16_cmp',
'simd_i16x8_cmp',
'simd_i32x4_cmp',
'simd_f32x4_cmp',
)


def gen_group_tests(mod_name):
"""mod_name is the back-end script name without the.py extension.
There must be a gen_test_cases() function in each module."""
mod = importlib.import_module(mod_name)
mod.gen_test_cases()


def main():
parser = argparse.ArgumentParser(
description='Front-end script to call other modules to generate SIMD tests')
parser.add_argument('-a', '--all', dest='gen_all', action='store_true',
default=False, help='Generate all the tests')
parser.add_argument('-i', '--inst', dest='inst_group', choices=SUBMODULES,
help='Back-end scripts that generate the SIMD tests')
args = parser.parse_args()

if len(sys.argv) < 2:
parser.print_help()

if args.inst_group:
gen_group_tests(args.inst_group)
if args.gen_all:
for mod_name in SUBMODULES:
gen_group_tests(mod_name)


if __name__ == '__main__':
main()
print('Done.')
66 changes: 66 additions & 0 deletions test/core/simd/meta/simd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
This python file is a tool class for SIMD and
currently only supports generating v128 const constant data.
"""


class SIMD(object):

# v128 Constant template
V128_CONST = '(v128.const {} {})'

# Params:
# val: constant data, string or list,
# lane_type: lane type, [i8x16, i16x8, i32x4, f32x4]
def v128_const(self, val, lane_type):

lane_cnt = int(lane_type[1:].split('x')[1])

# val is a string type, generating constant data
# of val according to the number of lanes
if isinstance(val, str):
data_elem = [val] * lane_cnt

# If val is type of list, generate constant data
# according to combination of list contents and number of lanes
elif isinstance(val, list):

# If it is an empty list, generate all constant data with 0x00
if len(val) == 0:
return self.v128_const('0x00', lane_type)

data_elem = []

# Calculate the number of times each element in val is copied
times = lane_cnt // len(val)

# Calculate whether the data needs to be filled according to
# the number of elements in the val list and the number of lanes.
complement = lane_cnt % len(val)
complement_item = ''

# If the number of elements in the val list is greater than the number of lanes,
# paste data with the number of lanes from the val list.
if times == 0:
times = 1
complement = 0

val = val[0:lane_cnt]

# Copy data
for item in val:
data_elem.extend([item] * times)
complement_item = item

# Fill in the data
if complement > 0:
data_elem.extend([complement_item] * complement)

# Get string
data_elem = ' '.join(data_elem)

# Returns v128 constant text
return self.V128_CONST.format(lane_type, data_elem)
Loading