diff --git a/README.md b/README.md index ced5fd11..02806c17 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,4 @@ TODO List: ### vffintl.d.w -### vffinth.d.w - -### vftint.wu.s/lu.d - -### vftintrz.wu.s/lu.d \ No newline at end of file +### vffinth.d.w \ No newline at end of file diff --git a/code/gen_impl.py b/code/gen_impl.py index 43b70d2d..455dfadd 100644 --- a/code/gen_impl.py +++ b/code/gen_impl.py @@ -773,6 +773,12 @@ m = members_fp[width] int_m = members[width] w = widths_fp[width] + if width == "s": + int_width = "w" + int_w = 32 + else: + int_width = "l" + int_w = 64 for name, op in [("div", "/"), ("mul", "*"), ("sub", "-"), ("add", "+")]: with open(f"vf{name}_{width}.h", "w") as f: print(f"for (int i = 0;i < {128 // w};i++) {{", file=f) @@ -786,26 +792,30 @@ with open(f"vftint{rounding}l_l_{width}.h", "w") as f: print(f"for (int i = 0;i < {64 // w};i++) {{", file=f) print( - f" dst.dword[i] = a.{m}[i]; // rounding mode is not expressed in C", + f" dst.dword[i] = (s{int_w})a.{m}[i]; // rounding mode is not expressed in C", file=f, ) print(f"}}", file=f) with open(f"vftint{rounding}h_l_{width}.h", "w") as f: print(f"for (int i = 0;i < {64 // w};i++) {{", file=f) print( - f" dst.dword[i] = a.{m}[i + {64 // w}]; // rounding mode is not expressed in C", + f" dst.dword[i] = (s{int_w})a.{m}[i + {64 // w}]; // rounding mode is not expressed in C", 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", + f" dst.{int_m}[i] = (s{int_w})a.{m}[i]; // rounding mode is not expressed in C", + file=f, + ) + print(f"}}", file=f) + for rounding in ["", "rz"]: + with open(f"vftint{rounding}_{int_width}u_{width}.h", "w") as f: + print(f"for (int i = 0;i < {128 // w};i++) {{", file=f) + print( + f" dst.{int_m}[i] = (u{int_w})a.{m}[i]; // rounding mode is not expressed in C", file=f, ) print(f"}}", file=f) diff --git a/code/vftint_l_d.h b/code/vftint_l_d.h index 903ce911..8f30f40b 100644 --- a/code/vftint_l_d.h +++ b/code/vftint_l_d.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp64[i]; // rounding mode is not expressed in C + dst.dword[i] = (s64)a.fp64[i]; // rounding mode is not expressed in C } diff --git a/code/vftint_lu_d.h b/code/vftint_lu_d.h new file mode 100644 index 00000000..5a925d11 --- /dev/null +++ b/code/vftint_lu_d.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 2; i++) { + dst.dword[i] = (u64)a.fp64[i]; // rounding mode is not expressed in C +} diff --git a/code/vftint_w_s.h b/code/vftint_w_s.h index 00594112..4cc670cd 100644 --- a/code/vftint_w_s.h +++ b/code/vftint_w_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 4; i++) { - dst.word[i] = a.fp32[i]; // rounding mode is not expressed in C + dst.word[i] = (s32)a.fp32[i]; // rounding mode is not expressed in C } diff --git a/code/vftint_wu_s.h b/code/vftint_wu_s.h new file mode 100644 index 00000000..1f3ec6f5 --- /dev/null +++ b/code/vftint_wu_s.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 4; i++) { + dst.word[i] = (u32)a.fp32[i]; // rounding mode is not expressed in C +} diff --git a/code/vftinth_l_s.h b/code/vftinth_l_s.h index 973784fe..1fb80893 100644 --- a/code/vftinth_l_s.h +++ b/code/vftinth_l_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp32[i + 2]; // rounding mode is not expressed in C + dst.dword[i] = (s32)a.fp32[i + 2]; // rounding mode is not expressed in C } diff --git a/code/vftintl_l_s.h b/code/vftintl_l_s.h index d138c6e1..d1710b18 100644 --- a/code/vftintl_l_s.h +++ b/code/vftintl_l_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp32[i]; // rounding mode is not expressed in C + dst.dword[i] = (s32)a.fp32[i]; // rounding mode is not expressed in C } diff --git a/code/vftintrm_l_d.h b/code/vftintrm_l_d.h index 903ce911..8f30f40b 100644 --- a/code/vftintrm_l_d.h +++ b/code/vftintrm_l_d.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp64[i]; // rounding mode is not expressed in C + dst.dword[i] = (s64)a.fp64[i]; // rounding mode is not expressed in C } diff --git a/code/vftintrm_w_s.h b/code/vftintrm_w_s.h index 00594112..4cc670cd 100644 --- a/code/vftintrm_w_s.h +++ b/code/vftintrm_w_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 4; i++) { - dst.word[i] = a.fp32[i]; // rounding mode is not expressed in C + dst.word[i] = (s32)a.fp32[i]; // rounding mode is not expressed in C } diff --git a/code/vftintrmh_l_s.h b/code/vftintrmh_l_s.h index 973784fe..1fb80893 100644 --- a/code/vftintrmh_l_s.h +++ b/code/vftintrmh_l_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp32[i + 2]; // rounding mode is not expressed in C + dst.dword[i] = (s32)a.fp32[i + 2]; // rounding mode is not expressed in C } diff --git a/code/vftintrml_l_s.h b/code/vftintrml_l_s.h index d138c6e1..d1710b18 100644 --- a/code/vftintrml_l_s.h +++ b/code/vftintrml_l_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp32[i]; // rounding mode is not expressed in C + dst.dword[i] = (s32)a.fp32[i]; // rounding mode is not expressed in C } diff --git a/code/vftintrne_l_d.h b/code/vftintrne_l_d.h index 903ce911..8f30f40b 100644 --- a/code/vftintrne_l_d.h +++ b/code/vftintrne_l_d.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp64[i]; // rounding mode is not expressed in C + dst.dword[i] = (s64)a.fp64[i]; // rounding mode is not expressed in C } diff --git a/code/vftintrne_w_s.h b/code/vftintrne_w_s.h index 00594112..4cc670cd 100644 --- a/code/vftintrne_w_s.h +++ b/code/vftintrne_w_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 4; i++) { - dst.word[i] = a.fp32[i]; // rounding mode is not expressed in C + dst.word[i] = (s32)a.fp32[i]; // rounding mode is not expressed in C } diff --git a/code/vftintrneh_l_s.h b/code/vftintrneh_l_s.h index 973784fe..1fb80893 100644 --- a/code/vftintrneh_l_s.h +++ b/code/vftintrneh_l_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp32[i + 2]; // rounding mode is not expressed in C + dst.dword[i] = (s32)a.fp32[i + 2]; // rounding mode is not expressed in C } diff --git a/code/vftintrnel_l_s.h b/code/vftintrnel_l_s.h index d138c6e1..d1710b18 100644 --- a/code/vftintrnel_l_s.h +++ b/code/vftintrnel_l_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp32[i]; // rounding mode is not expressed in C + dst.dword[i] = (s32)a.fp32[i]; // rounding mode is not expressed in C } diff --git a/code/vftintrp_l_d.h b/code/vftintrp_l_d.h index 903ce911..8f30f40b 100644 --- a/code/vftintrp_l_d.h +++ b/code/vftintrp_l_d.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp64[i]; // rounding mode is not expressed in C + dst.dword[i] = (s64)a.fp64[i]; // rounding mode is not expressed in C } diff --git a/code/vftintrp_w_s.h b/code/vftintrp_w_s.h index 00594112..4cc670cd 100644 --- a/code/vftintrp_w_s.h +++ b/code/vftintrp_w_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 4; i++) { - dst.word[i] = a.fp32[i]; // rounding mode is not expressed in C + dst.word[i] = (s32)a.fp32[i]; // rounding mode is not expressed in C } diff --git a/code/vftintrph_l_s.h b/code/vftintrph_l_s.h index 973784fe..1fb80893 100644 --- a/code/vftintrph_l_s.h +++ b/code/vftintrph_l_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp32[i + 2]; // rounding mode is not expressed in C + dst.dword[i] = (s32)a.fp32[i + 2]; // rounding mode is not expressed in C } diff --git a/code/vftintrpl_l_s.h b/code/vftintrpl_l_s.h index d138c6e1..d1710b18 100644 --- a/code/vftintrpl_l_s.h +++ b/code/vftintrpl_l_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp32[i]; // rounding mode is not expressed in C + dst.dword[i] = (s32)a.fp32[i]; // rounding mode is not expressed in C } diff --git a/code/vftintrz_l_d.h b/code/vftintrz_l_d.h index 903ce911..8f30f40b 100644 --- a/code/vftintrz_l_d.h +++ b/code/vftintrz_l_d.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp64[i]; // rounding mode is not expressed in C + dst.dword[i] = (s64)a.fp64[i]; // rounding mode is not expressed in C } diff --git a/code/vftintrz_lu_d.h b/code/vftintrz_lu_d.h new file mode 100644 index 00000000..5a925d11 --- /dev/null +++ b/code/vftintrz_lu_d.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 2; i++) { + dst.dword[i] = (u64)a.fp64[i]; // rounding mode is not expressed in C +} diff --git a/code/vftintrz_w_s.h b/code/vftintrz_w_s.h index 00594112..4cc670cd 100644 --- a/code/vftintrz_w_s.h +++ b/code/vftintrz_w_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 4; i++) { - dst.word[i] = a.fp32[i]; // rounding mode is not expressed in C + dst.word[i] = (s32)a.fp32[i]; // rounding mode is not expressed in C } diff --git a/code/vftintrz_wu_s.h b/code/vftintrz_wu_s.h new file mode 100644 index 00000000..1f3ec6f5 --- /dev/null +++ b/code/vftintrz_wu_s.h @@ -0,0 +1,3 @@ +for (int i = 0; i < 4; i++) { + dst.word[i] = (u32)a.fp32[i]; // rounding mode is not expressed in C +} diff --git a/code/vftintrzh_l_s.h b/code/vftintrzh_l_s.h index 973784fe..1fb80893 100644 --- a/code/vftintrzh_l_s.h +++ b/code/vftintrzh_l_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp32[i + 2]; // rounding mode is not expressed in C + dst.dword[i] = (s32)a.fp32[i + 2]; // rounding mode is not expressed in C } diff --git a/code/vftintrzl_l_s.h b/code/vftintrzl_l_s.h index d138c6e1..d1710b18 100644 --- a/code/vftintrzl_l_s.h +++ b/code/vftintrzl_l_s.h @@ -1,3 +1,3 @@ for (int i = 0; i < 2; i++) { - dst.dword[i] = a.fp32[i]; // rounding mode is not expressed in C + dst.dword[i] = (s32)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 3b78c3d8..cc7e7cdb 100644 --- a/docs/lsx/float_conversion.md +++ b/docs/lsx/float_conversion.md @@ -85,3 +85,8 @@ Convert double precision floating point elements in `a` and `b` to double precis {{ vftint('rz', 'w', 's') }} {{ vftint('rne', 'l', 'd') }} {{ vftint('rne', 'w', 's') }} + +{{ vftint('', 'lu', 'd') }} +{{ vftint('', 'wu', 's') }} +{{ vftint('rz', 'lu', 'd') }} +{{ vftint('rz', 'wu', 's') }} \ No newline at end of file diff --git a/main.py b/main.py index cbfc2c3f..6cefbffb 100644 --- a/main.py +++ b/main.py @@ -1296,8 +1296,12 @@ def vftint(rounding, name, name2): precision = "single" int_width = 32 rounding_mode = get_rounding_mode(rounding) + if len(name) == 1: + signedness = "signed" + else: + signedness = "unsigned" 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}.", + desc=f"Convert {precision}-precision floating point elements in `a` to {signedness} {int_width}-bit integer, {rounding_mode}.", ) \ No newline at end of file