Skip to content

Commit

Permalink
Add examples for issue #5
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 28, 2023
1 parent 3312663 commit 4549ed0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion code/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@
Expand Down
16 changes: 16 additions & 0 deletions code/examples.cpp
Original file line number Diff line number Diff line change
@@ -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}));
}
Empty file added code/examples.h
Empty file.
25 changes: 25 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -166,6 +189,8 @@ def instruction(intrinsic, instr, desc):
{desc}
{examples_text}
### Operation
```c++
Expand Down

0 comments on commit 4549ed0

Please sign in to comment.