Skip to content

Commit

Permalink
Fix conversion integer width
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 26, 2024
1 parent cf97720 commit 482f769
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 37 deletions.
28 changes: 21 additions & 7 deletions code/gen_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions code/vftint_w_d.h
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions code/vftintrm_w_d.h
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions code/vftintrne_w_d.h
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions code/vftintrp_w_d.h
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions code/vftintrz_w_d.h
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 4 additions & 4 deletions code/xvftint_w_d.h
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 4 additions & 4 deletions code/xvftintrm_w_d.h
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 4 additions & 4 deletions code/xvftintrne_w_d.h
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 4 additions & 4 deletions code/xvftintrp_w_d.h
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 4 additions & 4 deletions code/xvftintrz_w_d.h
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 482f769

Please sign in to comment.