From d4b75ba0843d43e78ebc003c61f1c06c70c4d15e Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Wed, 13 Dec 2023 16:23:51 +0800 Subject: [PATCH] Add vftint.l.d/vftint.w.s --- README.md | 8 -------- code/gen_impl.py | 12 ++++++++++++ code/vftint_l_d.h | 3 +++ code/vftint_w_s.h | 3 +++ code/vftintrm_l_d.h | 3 +++ code/vftintrm_w_s.h | 3 +++ code/vftintrne_l_d.h | 3 +++ code/vftintrne_w_s.h | 3 +++ code/vftintrp_l_d.h | 3 +++ code/vftintrp_w_s.h | 3 +++ code/vftintrz_l_d.h | 3 +++ code/vftintrz_w_s.h | 3 +++ docs/lsx/float_conversion.md | 11 +++++++++++ main.py | 35 ++++++++++++++++++++++++++++------- 14 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 code/vftint_l_d.h create mode 100644 code/vftint_w_s.h create mode 100644 code/vftintrm_l_d.h create mode 100644 code/vftintrm_w_s.h create mode 100644 code/vftintrne_l_d.h create mode 100644 code/vftintrne_w_s.h create mode 100644 code/vftintrp_l_d.h create mode 100644 code/vftintrp_w_s.h create mode 100644 code/vftintrz_l_d.h create mode 100644 code/vftintrz_w_s.h diff --git a/README.md b/README.md index a1b310a7..ced5fd11 100644 --- a/README.md +++ b/README.md @@ -56,14 +56,6 @@ TODO List: ### vffinth.d.w -### vftint.w.s/l.d - -### vftintrm.w.s/l.d - -### vftintrz.w.s/l.d - -### vftintrne.w.s/l.d - ### vftint.wu.s/lu.d ### vftintrz.wu.s/lu.d \ No newline at end of file diff --git a/code/gen_impl.py b/code/gen_impl.py index 32b6eb66..43b70d2d 100644 --- a/code/gen_impl.py +++ b/code/gen_impl.py @@ -797,6 +797,18 @@ file=f, ) print(f"}}", file=f) + for rounding in ["", "rm", "rp", "rz", "rne"]: + if width == "s": + int_width = "w" + else: + int_width = "l" + with open(f"vftint{rounding}_{int_width}_{width}.h", "w") as f: + print(f"for (int i = 0;i < {128 // w};i++) {{", file=f) + print( + f" dst.{int_m}[i] = a.{m}[i]; // rounding mode is not expressed in C", + file=f, + ) + print(f"}}", file=f) for name in ["max", "min"]: with open(f"vf{name}_{width}.h", "w") as f: diff --git a/code/vftint_l_d.h b/code/vftint_l_d.h new file mode 100644 index 00000000..903ce911 --- /dev/null +++ b/code/vftint_l_d.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 2; i++) { + dst.dword[i] = a.fp64[i]; // rounding mode is not expressed in C +} diff --git a/code/vftint_w_s.h b/code/vftint_w_s.h new file mode 100644 index 00000000..00594112 --- /dev/null +++ b/code/vftint_w_s.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 4; i++) { + dst.word[i] = a.fp32[i]; // rounding mode is not expressed in C +} diff --git a/code/vftintrm_l_d.h b/code/vftintrm_l_d.h new file mode 100644 index 00000000..903ce911 --- /dev/null +++ b/code/vftintrm_l_d.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 2; i++) { + dst.dword[i] = a.fp64[i]; // rounding mode is not expressed in C +} diff --git a/code/vftintrm_w_s.h b/code/vftintrm_w_s.h new file mode 100644 index 00000000..00594112 --- /dev/null +++ b/code/vftintrm_w_s.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 4; i++) { + dst.word[i] = a.fp32[i]; // rounding mode is not expressed in C +} diff --git a/code/vftintrne_l_d.h b/code/vftintrne_l_d.h new file mode 100644 index 00000000..903ce911 --- /dev/null +++ b/code/vftintrne_l_d.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 2; i++) { + dst.dword[i] = a.fp64[i]; // rounding mode is not expressed in C +} diff --git a/code/vftintrne_w_s.h b/code/vftintrne_w_s.h new file mode 100644 index 00000000..00594112 --- /dev/null +++ b/code/vftintrne_w_s.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 4; i++) { + dst.word[i] = a.fp32[i]; // rounding mode is not expressed in C +} diff --git a/code/vftintrp_l_d.h b/code/vftintrp_l_d.h new file mode 100644 index 00000000..903ce911 --- /dev/null +++ b/code/vftintrp_l_d.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 2; i++) { + dst.dword[i] = a.fp64[i]; // rounding mode is not expressed in C +} diff --git a/code/vftintrp_w_s.h b/code/vftintrp_w_s.h new file mode 100644 index 00000000..00594112 --- /dev/null +++ b/code/vftintrp_w_s.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 4; i++) { + dst.word[i] = a.fp32[i]; // rounding mode is not expressed in C +} diff --git a/code/vftintrz_l_d.h b/code/vftintrz_l_d.h new file mode 100644 index 00000000..903ce911 --- /dev/null +++ b/code/vftintrz_l_d.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 2; i++) { + dst.dword[i] = a.fp64[i]; // rounding mode is not expressed in C +} diff --git a/code/vftintrz_w_s.h b/code/vftintrz_w_s.h new file mode 100644 index 00000000..00594112 --- /dev/null +++ b/code/vftintrz_w_s.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 4; i++) { + dst.word[i] = a.fp32[i]; // rounding mode is not expressed in C +} diff --git a/docs/lsx/float_conversion.md b/docs/lsx/float_conversion.md index e70e9370..3b78c3d8 100644 --- a/docs/lsx/float_conversion.md +++ b/docs/lsx/float_conversion.md @@ -74,3 +74,14 @@ Convert double precision floating point elements in `a` and `b` to double precis {{ vftint_l_s('rz', 'h') }} {{ vftint_l_s('rne', 'l') }} {{ vftint_l_s('rne', 'h') }} + +{{ vftint('', 'l', 'd') }} +{{ vftint('', 'w', 's') }} +{{ vftint('rm', 'l', 'd') }} +{{ vftint('rm', 'w', 's') }} +{{ vftint('rp', 'l', 'd') }} +{{ vftint('rp', 'w', 's') }} +{{ vftint('rz', 'l', 'd') }} +{{ vftint('rz', 'w', 's') }} +{{ vftint('rne', 'l', 'd') }} +{{ vftint('rne', 'w', 's') }} diff --git a/main.py b/main.py index 86ad5f95..cbfc2c3f 100644 --- a/main.py +++ b/main.py @@ -1257,12 +1257,7 @@ def vsat(name): desc=f"Clamp {signedness} {width}-bit elements in `a` to range specified by `imm`.", ) - @env.macro - def vftint_l_s(rounding, low_high): - if low_high == "l": - half = "lower" - else: - half = "higher" + def get_rounding_mode(rounding): if rounding == "": rounding_mode = "using current rounding mode specified in `fscr`" elif rounding == "rm": @@ -1275,8 +1270,34 @@ def vftint_l_s(rounding, low_high): rounding_mode = "rounding towards nearest even" else: assert False + return rounding_mode + + @env.macro + def vftint_l_s(rounding, low_high): + if low_high == "l": + half = "lower" + else: + half = "higher" + rounding_mode = get_rounding_mode(rounding) return instruction( - intrinsic=f"__m128i __lsx_vftint{rounding}{low_high}_l_s (__m128i a)", + intrinsic=f"__m128i __lsx_vftint{rounding}{low_high}_l_s (__m128 a)", instr=f"vftint{rounding}{low_high}.l.s vr, vr", desc=f"Convert single-precision floating point elements in {half} part of `a` to 64-bit integer, {rounding_mode}.", + ) + + @env.macro + def vftint(rounding, name, name2): + if name2 == "d": + arg_type = "__m128d" + precision = "double" + int_width = 64 + else: + arg_type = "__m128" + precision = "single" + int_width = 32 + rounding_mode = get_rounding_mode(rounding) + return instruction( + intrinsic=f"__m128i __lsx_vftint{rounding}_{name}_{name2} ({arg_type} a)", + instr=f"vftint{rounding}.{name}.{name2} vr, vr", + desc=f"Convert {precision}-precision floating point elements in `a` to {int_width}-bit integer, {rounding_mode}.", ) \ No newline at end of file