Skip to content

Commit

Permalink
Fix xvssran/xvssrln
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 13, 2023
1 parent 8ad20f3 commit 8f81953
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 41 deletions.
71 changes: 54 additions & 17 deletions code/gen_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,23 +239,60 @@
with open(
f"{prefix}s{name}n_{width}_{double_width_signed}.h", "w"
) as f:
print(f"for (int i = 0;i < {vlen // w};i++) {{", file=f)
print(f"if (i < {vlen // 2 // w}) {{", file=f)
print(
f" {shift_sign}{double_w} temp = ({shift_sign}{double_w})a.{double_m}[i] >> (b.{double_m}[i] & {double_w-1});",
file=f,
)
print(
f" dst.{m}[i] = clamp<{shift_sign}{double_w}>(temp, {min}, {max});",
file=f,
)
print(f"}} else {{", file=f)
print(
f" dst.{m}[i] = 0;",
file=f,
)
print(f"}}", file=f)
print(f"}}", file=f)
if prefix == "v":
print(f"for (int i = 0;i < {vlen // w};i++) {{", file=f)
print(f"if (i < {vlen // 2 // w}) {{", file=f)
print(
f" {shift_sign}{double_w} temp = ({shift_sign}{double_w})a.{double_m}[i] >> (b.{double_m}[i] & {double_w-1});",
file=f,
)
print(
f" dst.{m}[i] = clamp<{shift_sign}{double_w}>(temp, {min}, {max});",
file=f,
)
print(f"}} else {{", file=f)
print(
f" dst.{m}[i] = 0;",
file=f,
)
print(f"}}", file=f)
print(f"}}", file=f)
else:
print(f"for (int i = 0;i < {vlen // 2 // w};i++) {{", file=f)
print(f"if (i < {vlen // 4 // w}) {{", file=f)
print(
f" {shift_sign}{double_w} temp = ({shift_sign}{double_w})a.{double_m}[i] >> (b.{double_m}[i] & {double_w-1});",
file=f,
)
print(
f" dst.{m}[i] = clamp<{shift_sign}{double_w}>(temp, {min}, {max});",
file=f,
)
print(f"}} else {{", file=f)
print(
f" dst.{m}[i] = 0;",
file=f,
)
print(f"}}", file=f)
print(f"}}", file=f)

print(f"for (int i = {vlen // 2 // w};i < {vlen // w};i++) {{", file=f)
print(f"if (i < {3 * vlen // 4 // w}) {{", file=f)
print(
f" {shift_sign}{double_w} temp = ({shift_sign}{double_w})a.{double_m}[i - {vlen // 4 // w}] >> (b.{double_m}[i - {vlen // 4 // w}] & {double_w-1});",
file=f,
)
print(
f" dst.{m}[i] = clamp<{shift_sign}{double_w}>(temp, {min}, {max});",
file=f,
)
print(f"}} else {{", file=f)
print(
f" dst.{m}[i] = 0;",
file=f,
)
print(f"}}", file=f)
print(f"}}", file=f)
with open(
f"{prefix}s{name}rn_{width}_{double_width_signed}.h", "w"
) as f:
Expand Down
12 changes: 10 additions & 2 deletions code/xvssran_b_h.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
for (int i = 0; i < 32; i++) {
if (i < 16) {
for (int i = 0; i < 16; i++) {
if (i < 8) {
s16 temp = (s16)a.half[i] >> (b.half[i] & 15);
dst.byte[i] = clamp<s16>(temp, -128, 127);
} else {
dst.byte[i] = 0;
}
}
for (int i = 16; i < 32; i++) {
if (i < 24) {
s16 temp = (s16)a.half[i - 8] >> (b.half[i - 8] & 15);
dst.byte[i] = clamp<s16>(temp, -128, 127);
} else {
dst.byte[i] = 0;
}
}
12 changes: 10 additions & 2 deletions code/xvssran_bu_h.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
for (int i = 0; i < 32; i++) {
if (i < 16) {
for (int i = 0; i < 16; i++) {
if (i < 8) {
s16 temp = (s16)a.half[i] >> (b.half[i] & 15);
dst.byte[i] = clamp<s16>(temp, 0, 255);
} else {
dst.byte[i] = 0;
}
}
for (int i = 16; i < 32; i++) {
if (i < 24) {
s16 temp = (s16)a.half[i - 8] >> (b.half[i - 8] & 15);
dst.byte[i] = clamp<s16>(temp, 0, 255);
} else {
dst.byte[i] = 0;
}
}
12 changes: 10 additions & 2 deletions code/xvssran_h_w.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
for (int i = 0; i < 16; i++) {
if (i < 8) {
for (int i = 0; i < 8; i++) {
if (i < 4) {
s32 temp = (s32)a.word[i] >> (b.word[i] & 31);
dst.half[i] = clamp<s32>(temp, -32768, 32767);
} else {
dst.half[i] = 0;
}
}
for (int i = 8; i < 16; i++) {
if (i < 12) {
s32 temp = (s32)a.word[i - 4] >> (b.word[i - 4] & 31);
dst.half[i] = clamp<s32>(temp, -32768, 32767);
} else {
dst.half[i] = 0;
}
}
12 changes: 10 additions & 2 deletions code/xvssran_hu_w.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
for (int i = 0; i < 16; i++) {
if (i < 8) {
for (int i = 0; i < 8; i++) {
if (i < 4) {
s32 temp = (s32)a.word[i] >> (b.word[i] & 31);
dst.half[i] = clamp<s32>(temp, 0, 65535);
} else {
dst.half[i] = 0;
}
}
for (int i = 8; i < 16; i++) {
if (i < 12) {
s32 temp = (s32)a.word[i - 4] >> (b.word[i - 4] & 31);
dst.half[i] = clamp<s32>(temp, 0, 65535);
} else {
dst.half[i] = 0;
}
}
12 changes: 10 additions & 2 deletions code/xvssran_w_d.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
for (int i = 0; i < 8; i++) {
if (i < 4) {
for (int i = 0; i < 4; i++) {
if (i < 2) {
s64 temp = (s64)a.dword[i] >> (b.dword[i] & 63);
dst.word[i] = clamp<s64>(temp, -2147483648, 2147483647);
} else {
dst.word[i] = 0;
}
}
for (int i = 4; i < 8; i++) {
if (i < 6) {
s64 temp = (s64)a.dword[i - 2] >> (b.dword[i - 2] & 63);
dst.word[i] = clamp<s64>(temp, -2147483648, 2147483647);
} else {
dst.word[i] = 0;
}
}
12 changes: 10 additions & 2 deletions code/xvssran_wu_d.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
for (int i = 0; i < 8; i++) {
if (i < 4) {
for (int i = 0; i < 4; i++) {
if (i < 2) {
s64 temp = (s64)a.dword[i] >> (b.dword[i] & 63);
dst.word[i] = clamp<s64>(temp, 0, 4294967295);
} else {
dst.word[i] = 0;
}
}
for (int i = 4; i < 8; i++) {
if (i < 6) {
s64 temp = (s64)a.dword[i - 2] >> (b.dword[i - 2] & 63);
dst.word[i] = clamp<s64>(temp, 0, 4294967295);
} else {
dst.word[i] = 0;
}
}
12 changes: 10 additions & 2 deletions code/xvssrln_b_h.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
for (int i = 0; i < 32; i++) {
if (i < 16) {
for (int i = 0; i < 16; i++) {
if (i < 8) {
u16 temp = (u16)a.half[i] >> (b.half[i] & 15);
dst.byte[i] = clamp<u16>(temp, 0, 127);
} else {
dst.byte[i] = 0;
}
}
for (int i = 16; i < 32; i++) {
if (i < 24) {
u16 temp = (u16)a.half[i - 8] >> (b.half[i - 8] & 15);
dst.byte[i] = clamp<u16>(temp, 0, 127);
} else {
dst.byte[i] = 0;
}
}
12 changes: 10 additions & 2 deletions code/xvssrln_bu_h.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
for (int i = 0; i < 32; i++) {
if (i < 16) {
for (int i = 0; i < 16; i++) {
if (i < 8) {
u16 temp = (u16)a.half[i] >> (b.half[i] & 15);
dst.byte[i] = clamp<u16>(temp, 0, 255);
} else {
dst.byte[i] = 0;
}
}
for (int i = 16; i < 32; i++) {
if (i < 24) {
u16 temp = (u16)a.half[i - 8] >> (b.half[i - 8] & 15);
dst.byte[i] = clamp<u16>(temp, 0, 255);
} else {
dst.byte[i] = 0;
}
}
12 changes: 10 additions & 2 deletions code/xvssrln_h_w.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
for (int i = 0; i < 16; i++) {
if (i < 8) {
for (int i = 0; i < 8; i++) {
if (i < 4) {
u32 temp = (u32)a.word[i] >> (b.word[i] & 31);
dst.half[i] = clamp<u32>(temp, 0, 32767);
} else {
dst.half[i] = 0;
}
}
for (int i = 8; i < 16; i++) {
if (i < 12) {
u32 temp = (u32)a.word[i - 4] >> (b.word[i - 4] & 31);
dst.half[i] = clamp<u32>(temp, 0, 32767);
} else {
dst.half[i] = 0;
}
}
12 changes: 10 additions & 2 deletions code/xvssrln_hu_w.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
for (int i = 0; i < 16; i++) {
if (i < 8) {
for (int i = 0; i < 8; i++) {
if (i < 4) {
u32 temp = (u32)a.word[i] >> (b.word[i] & 31);
dst.half[i] = clamp<u32>(temp, 0, 65535);
} else {
dst.half[i] = 0;
}
}
for (int i = 8; i < 16; i++) {
if (i < 12) {
u32 temp = (u32)a.word[i - 4] >> (b.word[i - 4] & 31);
dst.half[i] = clamp<u32>(temp, 0, 65535);
} else {
dst.half[i] = 0;
}
}
12 changes: 10 additions & 2 deletions code/xvssrln_w_d.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
for (int i = 0; i < 8; i++) {
if (i < 4) {
for (int i = 0; i < 4; i++) {
if (i < 2) {
u64 temp = (u64)a.dword[i] >> (b.dword[i] & 63);
dst.word[i] = clamp<u64>(temp, 0, 2147483647);
} else {
dst.word[i] = 0;
}
}
for (int i = 4; i < 8; i++) {
if (i < 6) {
u64 temp = (u64)a.dword[i - 2] >> (b.dword[i - 2] & 63);
dst.word[i] = clamp<u64>(temp, 0, 2147483647);
} else {
dst.word[i] = 0;
}
}
12 changes: 10 additions & 2 deletions code/xvssrln_wu_d.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
for (int i = 0; i < 8; i++) {
if (i < 4) {
for (int i = 0; i < 4; i++) {
if (i < 2) {
u64 temp = (u64)a.dword[i] >> (b.dword[i] & 63);
dst.word[i] = clamp<u64>(temp, 0, 4294967295);
} else {
dst.word[i] = 0;
}
}
for (int i = 4; i < 8; i++) {
if (i < 6) {
u64 temp = (u64)a.dword[i - 2] >> (b.dword[i - 2] & 63);
dst.word[i] = clamp<u64>(temp, 0, 4294967295);
} else {
dst.word[i] = 0;
}
}

0 comments on commit 8f81953

Please sign in to comment.