From 482f769616b2de3eaabd9c04ae211a7c72163511 Mon Sep 17 00:00:00 2001 From: Jiajie Chen Date: Thu, 26 Dec 2024 15:59:12 +0800 Subject: [PATCH] Fix conversion integer width --- code/gen_impl.py | 28 +++++++++++++++++++++------- code/vftint_w_d.h | 4 ++-- code/vftintrm_w_d.h | 4 ++-- code/vftintrne_w_d.h | 4 ++-- code/vftintrp_w_d.h | 4 ++-- code/vftintrz_w_d.h | 4 ++-- code/xvftint_w_d.h | 8 ++++---- code/xvftintrm_w_d.h | 8 ++++---- code/xvftintrne_w_d.h | 8 ++++---- code/xvftintrp_w_d.h | 8 ++++---- code/xvftintrz_w_d.h | 8 ++++---- 11 files changed, 51 insertions(+), 37 deletions(-) diff --git a/code/gen_impl.py b/code/gen_impl.py index 5f681a2f..b3e0e50b 100644 --- a/code/gen_impl.py +++ b/code/gen_impl.py @@ -1463,12 +1463,26 @@ if width == "d": for rounding in ["", "rm", "rp", "rz", "rne"]: with open(f"{prefix}ftint{rounding}_w_{width}.h", "w") as f: - print(f"for (int i = 0;i < {vlen // w};i++) {{", file=f) - print( - f" dst.{int_m}[i] = (i < {vlen // 2 // w}) ? (s{int_w})a.{m}[i] : (s{int_w})b.{m}[i]; // rounding mode is not expressed in C", - file=f, - ) - print(f"}}", file=f) + if prefix == "v": + print(f"for (int i = 0;i < {vlen // w * 2};i++) {{", file=f) + print( + f" dst.word[i] = (i < {vlen // w}) ? (s32)b.{m}[i] : (s32)a.{m}[i - {vlen // w}]; // rounding mode is not expressed in C", + file=f, + ) + print(f"}}", file=f) + else: + print(f"for (int i = 0;i < {vlen // w};i++) {{", file=f) + print( + f" dst.word[i] = (i < {vlen // 2 // w}) ? (s32)b.{m}[i] : (s32)a.{m}[i - {vlen // 2 // w}]; // rounding mode is not expressed in C", + file=f, + ) + print(f"}}", file=f) + print(f"for (int i = {vlen // w};i < {vlen // w * 2};i++) {{", file=f) + print( + f" dst.word[i] = (i < {vlen // 2 // w + vlen // w}) ? (s32)b.{m}[i - {vlen // 2 // w}] : (s32)a.{m}[i - {vlen // w}]; // rounding mode is not expressed in C", + file=f, + ) + print(f"}}", file=f) with open(f"{prefix}ffint_{width}_{int_width}.h", "w") as f: print(f"for (int i = 0;i < {vlen // w};i++) {{", file=f) print( @@ -1488,7 +1502,7 @@ with open(f"{prefix}f{name}_{width}.h", "w") as f: print(f"for (int i = 0;i < {vlen // w};i++) {{", file=f) print( - f" dst.{m}[i] = {op}(a.{m}[i], b.{m}[i]);", + f" dst.{m}[i] = f{name}(a.{m}[i], b.{m}[i]);", file=f, ) print(f"}}", file=f) diff --git a/code/vftint_w_d.h b/code/vftint_w_d.h index 20bbde7a..00fa7ba6 100644 --- a/code/vftint_w_d.h +++ b/code/vftint_w_d.h @@ -1,5 +1,5 @@ for (int i = 0; i < 4; i++) { dst.word[i] = (i < 2) - ? (s64)b.fp64[i] - : (s64)a.fp64[i - 2]; // rounding mode is not expressed in C + ? (s32)b.fp64[i] + : (s32)a.fp64[i - 2]; // rounding mode is not expressed in C } diff --git a/code/vftintrm_w_d.h b/code/vftintrm_w_d.h index 20bbde7a..00fa7ba6 100644 --- a/code/vftintrm_w_d.h +++ b/code/vftintrm_w_d.h @@ -1,5 +1,5 @@ for (int i = 0; i < 4; i++) { dst.word[i] = (i < 2) - ? (s64)b.fp64[i] - : (s64)a.fp64[i - 2]; // rounding mode is not expressed in C + ? (s32)b.fp64[i] + : (s32)a.fp64[i - 2]; // rounding mode is not expressed in C } diff --git a/code/vftintrne_w_d.h b/code/vftintrne_w_d.h index 20bbde7a..00fa7ba6 100644 --- a/code/vftintrne_w_d.h +++ b/code/vftintrne_w_d.h @@ -1,5 +1,5 @@ for (int i = 0; i < 4; i++) { dst.word[i] = (i < 2) - ? (s64)b.fp64[i] - : (s64)a.fp64[i - 2]; // rounding mode is not expressed in C + ? (s32)b.fp64[i] + : (s32)a.fp64[i - 2]; // rounding mode is not expressed in C } diff --git a/code/vftintrp_w_d.h b/code/vftintrp_w_d.h index 20bbde7a..00fa7ba6 100644 --- a/code/vftintrp_w_d.h +++ b/code/vftintrp_w_d.h @@ -1,5 +1,5 @@ for (int i = 0; i < 4; i++) { dst.word[i] = (i < 2) - ? (s64)b.fp64[i] - : (s64)a.fp64[i - 2]; // rounding mode is not expressed in C + ? (s32)b.fp64[i] + : (s32)a.fp64[i - 2]; // rounding mode is not expressed in C } diff --git a/code/vftintrz_w_d.h b/code/vftintrz_w_d.h index 20bbde7a..00fa7ba6 100644 --- a/code/vftintrz_w_d.h +++ b/code/vftintrz_w_d.h @@ -1,5 +1,5 @@ for (int i = 0; i < 4; i++) { dst.word[i] = (i < 2) - ? (s64)b.fp64[i] - : (s64)a.fp64[i - 2]; // rounding mode is not expressed in C + ? (s32)b.fp64[i] + : (s32)a.fp64[i - 2]; // rounding mode is not expressed in C } diff --git a/code/xvftint_w_d.h b/code/xvftint_w_d.h index 1e2eab1a..9344785d 100644 --- a/code/xvftint_w_d.h +++ b/code/xvftint_w_d.h @@ -1,10 +1,10 @@ for (int i = 0; i < 4; i++) { dst.word[i] = (i < 2) - ? (s64)b.fp64[i] - : (s64)a.fp64[i - 2]; // rounding mode is not expressed in C + ? (s32)b.fp64[i] + : (s32)a.fp64[i - 2]; // rounding mode is not expressed in C } for (int i = 4; i < 8; i++) { dst.word[i] = (i < 6) - ? (s64)b.fp64[i - 2] - : (s64)a.fp64[i - 4]; // rounding mode is not expressed in C + ? (s32)b.fp64[i - 2] + : (s32)a.fp64[i - 4]; // rounding mode is not expressed in C } diff --git a/code/xvftintrm_w_d.h b/code/xvftintrm_w_d.h index 1e2eab1a..9344785d 100644 --- a/code/xvftintrm_w_d.h +++ b/code/xvftintrm_w_d.h @@ -1,10 +1,10 @@ for (int i = 0; i < 4; i++) { dst.word[i] = (i < 2) - ? (s64)b.fp64[i] - : (s64)a.fp64[i - 2]; // rounding mode is not expressed in C + ? (s32)b.fp64[i] + : (s32)a.fp64[i - 2]; // rounding mode is not expressed in C } for (int i = 4; i < 8; i++) { dst.word[i] = (i < 6) - ? (s64)b.fp64[i - 2] - : (s64)a.fp64[i - 4]; // rounding mode is not expressed in C + ? (s32)b.fp64[i - 2] + : (s32)a.fp64[i - 4]; // rounding mode is not expressed in C } diff --git a/code/xvftintrne_w_d.h b/code/xvftintrne_w_d.h index 1e2eab1a..9344785d 100644 --- a/code/xvftintrne_w_d.h +++ b/code/xvftintrne_w_d.h @@ -1,10 +1,10 @@ for (int i = 0; i < 4; i++) { dst.word[i] = (i < 2) - ? (s64)b.fp64[i] - : (s64)a.fp64[i - 2]; // rounding mode is not expressed in C + ? (s32)b.fp64[i] + : (s32)a.fp64[i - 2]; // rounding mode is not expressed in C } for (int i = 4; i < 8; i++) { dst.word[i] = (i < 6) - ? (s64)b.fp64[i - 2] - : (s64)a.fp64[i - 4]; // rounding mode is not expressed in C + ? (s32)b.fp64[i - 2] + : (s32)a.fp64[i - 4]; // rounding mode is not expressed in C } diff --git a/code/xvftintrp_w_d.h b/code/xvftintrp_w_d.h index 1e2eab1a..9344785d 100644 --- a/code/xvftintrp_w_d.h +++ b/code/xvftintrp_w_d.h @@ -1,10 +1,10 @@ for (int i = 0; i < 4; i++) { dst.word[i] = (i < 2) - ? (s64)b.fp64[i] - : (s64)a.fp64[i - 2]; // rounding mode is not expressed in C + ? (s32)b.fp64[i] + : (s32)a.fp64[i - 2]; // rounding mode is not expressed in C } for (int i = 4; i < 8; i++) { dst.word[i] = (i < 6) - ? (s64)b.fp64[i - 2] - : (s64)a.fp64[i - 4]; // rounding mode is not expressed in C + ? (s32)b.fp64[i - 2] + : (s32)a.fp64[i - 4]; // rounding mode is not expressed in C } diff --git a/code/xvftintrz_w_d.h b/code/xvftintrz_w_d.h index 1e2eab1a..9344785d 100644 --- a/code/xvftintrz_w_d.h +++ b/code/xvftintrz_w_d.h @@ -1,10 +1,10 @@ for (int i = 0; i < 4; i++) { dst.word[i] = (i < 2) - ? (s64)b.fp64[i] - : (s64)a.fp64[i - 2]; // rounding mode is not expressed in C + ? (s32)b.fp64[i] + : (s32)a.fp64[i - 2]; // rounding mode is not expressed in C } for (int i = 4; i < 8; i++) { dst.word[i] = (i < 6) - ? (s64)b.fp64[i - 2] - : (s64)a.fp64[i - 4]; // rounding mode is not expressed in C + ? (s32)b.fp64[i - 2] + : (s32)a.fp64[i - 4]; // rounding mode is not expressed in C }