From 4549ed074370375b2a570bb89425730bd9736a07 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Thu, 28 Dec 2023 16:48:41 +0800 Subject: [PATCH] Add examples for issue #5 --- code/Makefile | 2 +- code/examples.cpp | 16 ++++++++++++++++ code/examples.h | 0 main.py | 25 +++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 code/examples.cpp create mode 100644 code/examples.h diff --git a/code/Makefile b/code/Makefile index 84be14fc..ab51028a 100644 --- a/code/Makefile +++ b/code/Makefile @@ -15,7 +15,7 @@ clean: rm -rf $(EXES) %: %.cpp %.h common.h - $(CXX) $(CFLAGS) $< -mlsx -mlasx -o $@ + $(CXX) -Wno-narrowing $(CFLAGS) $< -mlsx -mlasx -o $@ measure: measure.cpp measure.h $(CXX) $(CFLAGS) -O2 $< -o $@ diff --git a/code/examples.cpp b/code/examples.cpp new file mode 100644 index 00000000..a927d11f --- /dev/null +++ b/code/examples.cpp @@ -0,0 +1,16 @@ +#include "common.h" + +void test() { + PRINT(__lsx_vmsknz_b(__m128i{0x1122334455667788, 0x99aabbccddeeff00})); + PRINT(__lsx_vmsknz_b(__m128i{0x0000111100000000, 0x0011000011111111})); + PRINT(__lsx_vmskgez_b(__m128i{0x1122334455667788, 0x99aabbccddeeff00})); + PRINT(__lsx_vmskgez_b(__m128i{0x0000808000000000, 0x0081000081716151})); + PRINT(__lsx_vmskltz_b(__m128i{0x1122334455667788, 0x99aabbccddeeff00})); + PRINT(__lsx_vmskltz_b(__m128i{0x0000808000000000, 0x0081000081716151})); + PRINT(__lsx_vmskltz_h(__m128i{0x1122334455667788, 0x99aabbccddeeff00})); + PRINT(__lsx_vmskltz_h(__m128i{0x0000808000000000, 0x0081000081716151})); + PRINT(__lsx_vmskltz_w(__m128i{0x1122334455667788, 0x99aabbccddeeff00})); + PRINT(__lsx_vmskltz_w(__m128i{0x0000808000000000, 0x0081000081716151})); + PRINT(__lsx_vmskltz_d(__m128i{0x1122334455667788, 0x99aabbccddeeff00})); + PRINT(__lsx_vmskltz_d(__m128i{0x0000808000000000, 0x0081000081716151})); +} \ No newline at end of file diff --git a/code/examples.h b/code/examples.h new file mode 100644 index 00000000..e69de29b diff --git a/main.py b/main.py index 30a19df4..1d31187d 100644 --- a/main.py +++ b/main.py @@ -45,6 +45,14 @@ "throughput(cpi)": throughput_cpi, } +# read examples +examples = {} +for line in open('code/examples.md', 'r'): + if '(' in line: + name = line.split('(')[0].split(' ')[-1] + if name not in examples: + examples[name] = [] + examples[name].append(line.strip()) # depends on implementation of env.macro() def my_macro(env): @@ -103,11 +111,14 @@ def instruction(intrinsic, instr, desc): global cur_simd # try to be smart file_name = None + intrinsic_name = "" for part in intrinsic.split(" "): if part.startswith("__lsx_"): file_name = part[6:] + intrinsic_name = part elif part.startswith("__lasx_"): file_name = part[7:] + intrinsic_name = part if cur_simd == "lasx" and file_name[0] != "x": file_name = "x" + file_name instr = "x" + instr @@ -150,6 +161,18 @@ def instruction(intrinsic, instr, desc): else: latency_throughput = "" + if intrinsic_name in examples: + inner = "\n".join(examples[intrinsic_name]) + examples_text = f""" +### Examples + +```c++ +{inner} +``` +""" + else: + examples_text = "" + return f""" ## {intrinsic} @@ -166,6 +189,8 @@ def instruction(intrinsic, instr, desc): {desc} +{examples_text} + ### Operation ```c++