Skip to content

Commit

Permalink
Add lasx instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Dec 14, 2023
1 parent f7b4f5b commit 8fac972
Show file tree
Hide file tree
Showing 81 changed files with 1,091 additions and 9 deletions.
4 changes: 4 additions & 0 deletions code/xvabsd_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for (int i = 0; i < 32; i++) {
dst.byte[i] = ((s8)a.byte[i] > (s8)b.byte[i]) ? (a.byte[i] - b.byte[i])
: (b.byte[i] - a.byte[i]);
}
4 changes: 4 additions & 0 deletions code/xvabsd_bu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for (int i = 0; i < 32; i++) {
dst.byte[i] = ((u8)a.byte[i] > (u8)b.byte[i]) ? (a.byte[i] - b.byte[i])
: (b.byte[i] - a.byte[i]);
}
5 changes: 5 additions & 0 deletions code/xvabsd_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
for (int i = 0; i < 4; i++) {
dst.dword[i] = ((s64)a.dword[i] > (s64)b.dword[i])
? (a.dword[i] - b.dword[i])
: (b.dword[i] - a.dword[i]);
}
5 changes: 5 additions & 0 deletions code/xvabsd_du.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
for (int i = 0; i < 4; i++) {
dst.dword[i] = ((u64)a.dword[i] > (u64)b.dword[i])
? (a.dword[i] - b.dword[i])
: (b.dword[i] - a.dword[i]);
}
4 changes: 4 additions & 0 deletions code/xvabsd_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for (int i = 0; i < 16; i++) {
dst.half[i] = ((s16)a.half[i] > (s16)b.half[i]) ? (a.half[i] - b.half[i])
: (b.half[i] - a.half[i]);
}
4 changes: 4 additions & 0 deletions code/xvabsd_hu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for (int i = 0; i < 16; i++) {
dst.half[i] = ((u16)a.half[i] > (u16)b.half[i]) ? (a.half[i] - b.half[i])
: (b.half[i] - a.half[i]);
}
4 changes: 4 additions & 0 deletions code/xvabsd_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for (int i = 0; i < 8; i++) {
dst.word[i] = ((s32)a.word[i] > (s32)b.word[i]) ? (a.word[i] - b.word[i])
: (b.word[i] - a.word[i]);
}
4 changes: 4 additions & 0 deletions code/xvabsd_wu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for (int i = 0; i < 8; i++) {
dst.word[i] = ((u32)a.word[i] > (u32)b.word[i]) ? (a.word[i] - b.word[i])
: (b.word[i] - a.word[i]);
}
3 changes: 3 additions & 0 deletions code/xvadd_q.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0;i < 2;i++) {
dst.qword[i] = a.qword[i] + b.qword[i];
}
3 changes: 3 additions & 0 deletions code/xvadda_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 32; i++) {
dst.byte[i] = abs((s8)a.byte[i]) + abs((s8)b.byte[i]);
}
3 changes: 3 additions & 0 deletions code/xvadda_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.dword[i] = abs((s64)a.dword[i]) + abs((s64)b.dword[i]);
}
3 changes: 3 additions & 0 deletions code/xvadda_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 16; i++) {
dst.half[i] = abs((s16)a.half[i]) + abs((s16)b.half[i]);
}
3 changes: 3 additions & 0 deletions code/xvadda_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 8; i++) {
dst.word[i] = abs((s32)a.word[i]) + abs((s32)b.word[i]);
}
3 changes: 3 additions & 0 deletions code/xvand_v.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.dword[i] = a.dword[i] & b.dword[i];
}
3 changes: 3 additions & 0 deletions code/xvandi_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 32; i++) {
dst.byte[i] = a.byte[i] & imm;
}
3 changes: 3 additions & 0 deletions code/xvandn_v.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.dword[i] = b.dword[i] & (~a.dword[i]);
}
3 changes: 3 additions & 0 deletions code/xvbsll_v.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int shift = (imm * 8) % 128;
dst.qword[0] = (u128)a.qword[0] << shift;
dst.qword[1] = (u128)a.qword[1] << shift;
3 changes: 3 additions & 0 deletions code/xvbsrl_v.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int shift = (imm * 8) % 128;
dst.qword[0] = (u128)a.qword[0] >> shift;
dst.qword[1] = (u128)a.qword[1] >> shift;
3 changes: 3 additions & 0 deletions code/xvfclass_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.dword[i] = fp_classify(a.fp64[i]);
}
3 changes: 3 additions & 0 deletions code/xvfclass_s.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 2; i++) {
dst.word[i] = fp_classify(a.fp32[i]);
}
3 changes: 3 additions & 0 deletions code/xvfmadd_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.fp64[i] = a.fp64[i] * b.fp64[i] + c.fp64[i];
}
3 changes: 3 additions & 0 deletions code/xvfmadd_s.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 8; i++) {
dst.fp32[i] = a.fp32[i] * b.fp32[i] + c.fp32[i];
}
3 changes: 3 additions & 0 deletions code/xvfmsub_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.fp64[i] = a.fp64[i] * b.fp64[i] - c.fp64[i];
}
3 changes: 3 additions & 0 deletions code/xvfmsub_s.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 8; i++) {
dst.fp32[i] = a.fp32[i] * b.fp32[i] - c.fp32[i];
}
3 changes: 3 additions & 0 deletions code/xvfnmadd_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.fp64[i] = (a.fp64[i] * b.fp64[i] + c.fp64[i]);
}
3 changes: 3 additions & 0 deletions code/xvfnmadd_s.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 8; i++) {
dst.fp32[i] = -(a.fp32[i] * b.fp32[i] + c.fp32[i]);
}
3 changes: 3 additions & 0 deletions code/xvfnmsub_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.fp64[i] = -(a.fp64[i] * b.fp64[i] - c.fp64[i]);
}
3 changes: 3 additions & 0 deletions code/xvfnmsub_s.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 8; i++) {
dst.fp32[i] = -(a.fp32[i] * b.fp32[i] - c.fp32[i]);
}
3 changes: 3 additions & 0 deletions code/xvinsgr2vr_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 32; i++) {
dst.byte[i] = (i == imm) ? b : a.byte[i];
}
3 changes: 3 additions & 0 deletions code/xvinsgr2vr_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 16; i++) {
dst.half[i] = (i == imm) ? b : a.half[i];
}
1 change: 1 addition & 0 deletions code/xvld.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dst = memory_load(256, addr + offset);
93 changes: 93 additions & 0 deletions code/xvldi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
u64 imm12_10 = (imm >> 10) & 0b111;
u64 imm12_8 = (imm >> 8) & 0b11111;
u64 imm9_0 = imm & 0x3FF;
s64 simm9_0 = ((s64)imm9_0 << 54) >> 54;
u64 imm7_0 = imm & 0xFF;
u64 imm7 = (imm >> 7) & 0x1;
u64 imm6 = (imm >> 6) & 0x1;
u64 imm5 = (imm >> 5) & 0x1;
u64 imm5_0 = imm & 0x3F;
u64 imm4 = (imm >> 4) & 0x1;
u64 imm3 = (imm >> 3) & 0x1;
u64 imm2 = (imm >> 2) & 0x1;
u64 imm1 = (imm >> 1) & 0x1;
u64 imm0 = imm & 0x1;

u64 broadcast_value;
u64 broadcast_width;
if (imm12_10 == 0b000) {
broadcast_value = imm7_0;
broadcast_width = 8;
} else if (imm12_10 == 0b001) {
broadcast_value = simm9_0;
broadcast_width = 16;
} else if (imm12_10 == 0b010) {
broadcast_value = simm9_0;
broadcast_width = 32;
} else if (imm12_10 == 0b011) {
broadcast_value = simm9_0;
broadcast_width = 64;
} else if (imm12_8 == 0b10000) {
broadcast_value = imm7_0;
broadcast_width = 32;
} else if (imm12_8 == 0b10001) {
broadcast_value = imm7_0 << 8;
broadcast_width = 32;
} else if (imm12_8 == 0b10010) {
broadcast_value = imm7_0 << 16;
broadcast_width = 32;
} else if (imm12_8 == 0b10011) {
broadcast_value = imm7_0 << 24;
broadcast_width = 32;
} else if (imm12_8 == 0b10100) {
broadcast_value = imm7_0;
broadcast_width = 16;
} else if (imm12_8 == 0b10101) {
broadcast_value = imm7_0 << 8;
broadcast_width = 16;
} else if (imm12_8 == 0b10110) {
broadcast_value = (imm7_0 << 8) | 0xFF;
broadcast_width = 32;
} else if (imm12_8 == 0b10111) {
broadcast_value = (imm7_0 << 16) | 0xFFFF;
broadcast_width = 32;
} else if (imm12_8 == 0b11000) {
broadcast_value = imm7_0;
broadcast_width = 8;
} else if (imm12_8 == 0b11001) {
broadcast_value = imm0 * 0xFF + imm1 * 0xFF00 + imm2 * 0xFF0000 +
imm3 * 0xFF000000 + imm4 * 0xFF00000000 +
imm5 * 0xFF0000000000 + imm6 * 0xFF000000000000 +
imm7 * 0xFF00000000000000;
broadcast_width = 64;
} else if (imm12_8 == 0b11010) {
broadcast_value = (imm7 << 31) | ((1 - imm6) << 30) | ((imm6 * 0x1F) << 25) |
(imm5_0 << 19);
broadcast_width = 32;
} else if (imm12_8 == 0b11011) {
broadcast_value = (imm7 << 31) | ((1 - imm6) << 30) | ((imm6 * 0x1F) << 25) |
(imm5_0 << 19);
broadcast_width = 64;
} else if (imm12_8 == 0b11100) {
broadcast_value = (imm7 << 63) | ((1 - imm6) << 62) | ((imm6 * 0xFF) << 54) |
(imm5_0 << 48);
broadcast_width = 64;
}

if (broadcast_width == 8) {
for (int i = 0; i < 32; i++) {
dst.byte[i] = broadcast_value;
}
} else if (broadcast_width == 16) {
for (int i = 0; i < 16; i++) {
dst.half[i] = broadcast_value;
}
} else if (broadcast_width == 32) {
for (int i = 0; i < 8; i++) {
dst.word[i] = broadcast_value;
}
} else if (broadcast_width == 64) {
for (int i = 0; i < 4; i++) {
dst.dword[i] = broadcast_value;
}
}
4 changes: 4 additions & 0 deletions code/xvldrepl_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
u8 data = memory_load(8, addr + offset);
for (int i = 0; i < 32; i++) {
dst.byte[i] = data;
}
4 changes: 4 additions & 0 deletions code/xvldrepl_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
u64 data = memory_load(64, addr + (offset << 3));
for (int i = 0; i < 4; i++) {
dst.dword[i] = data;
}
4 changes: 4 additions & 0 deletions code/xvldrepl_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
u16 data = memory_load(16, addr + (offset << 1));
for (int i = 0; i < 16; i++) {
dst.half[i] = data;
}
4 changes: 4 additions & 0 deletions code/xvldrepl_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
u32 data = memory_load(32, addr + (offset << 2));
for (int i = 0; i < 8; i++) {
dst.word[i] = data;
}
1 change: 1 addition & 0 deletions code/xvldx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dst = memory_load(256, addr + offset);
3 changes: 3 additions & 0 deletions code/xvnor_v.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.dword[i] = ~(a.dword[i] | b.dword[i]);
}
3 changes: 3 additions & 0 deletions code/xvnori_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 32; i++) {
dst.byte[i] = ~(a.byte[i] | imm);
}
3 changes: 3 additions & 0 deletions code/xvor_v.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.dword[i] = a.dword[i] | b.dword[i];
}
3 changes: 3 additions & 0 deletions code/xvori_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 32; i++) {
dst.byte[i] = a.byte[i] | imm;
}
3 changes: 3 additions & 0 deletions code/xvorn_v.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.dword[i] = a.dword[i] | (~b.dword[i]);
}
4 changes: 4 additions & 0 deletions code/xvpermi_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dst.dword[0] = a.dword[imm & 0x3];
dst.dword[1] = a.dword[(imm >> 2) & 0x3];
dst.dword[2] = a.dword[(imm >> 4) & 0x3];
dst.dword[3] = a.dword[(imm >> 6) & 0x3];
3 changes: 3 additions & 0 deletions code/xvreplvei_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 32; i++) {
dst.byte[i] = a.byte[idx];
}
3 changes: 3 additions & 0 deletions code/xvreplvei_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 4; i++) {
dst.dword[i] = a.dword[idx];
}
3 changes: 3 additions & 0 deletions code/xvreplvei_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 16; i++) {
dst.half[i] = a.half[idx];
}
3 changes: 3 additions & 0 deletions code/xvreplvei_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for (int i = 0; i < 8; i++) {
dst.word[i] = a.word[idx];
}
6 changes: 6 additions & 0 deletions code/xvsetallnez_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dst = 1;
for (int i = 0; i < 32; i++) {
if (a.byte[i] == 0) {
dst = 0;
}
}
6 changes: 6 additions & 0 deletions code/xvsetallnez_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dst = 1;
for (int i = 0; i < 4; i++) {
if (a.dword[i] == 0) {
dst = 0;
}
}
6 changes: 6 additions & 0 deletions code/xvsetallnez_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dst = 1;
for (int i = 0; i < 16; i++) {
if (a.half[i] == 0) {
dst = 0;
}
}
6 changes: 6 additions & 0 deletions code/xvsetallnez_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dst = 1;
for (int i = 0; i < 8; i++) {
if (a.word[i] == 0) {
dst = 0;
}
}
6 changes: 6 additions & 0 deletions code/xvsetanyeqz_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dst = 0;
for (int i = 0; i < 32; i++) {
if (a.byte[i] == 0) {
dst = 1;
}
}
6 changes: 6 additions & 0 deletions code/xvsetanyeqz_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dst = 0;
for (int i = 0; i < 4; i++) {
if (a.dword[i] == 0) {
dst = 1;
}
}
6 changes: 6 additions & 0 deletions code/xvsetanyeqz_h.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dst = 0;
for (int i = 0; i < 16; i++) {
if (a.half[i] == 0) {
dst = 1;
}
}
6 changes: 6 additions & 0 deletions code/xvsetanyeqz_w.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dst = 0;
for (int i = 0; i < 8; i++) {
if (a.word[i] == 0) {
dst = 1;
}
}
1 change: 1 addition & 0 deletions code/xvseteqz_v.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dst = a.qword[0] == 0 && a.qword[1] == 0;
1 change: 1 addition & 0 deletions code/xvsetnez_v.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dst = a.qword[0] != 0 || a.qword[1] != 0;
6 changes: 6 additions & 0 deletions code/xvshuf4i_d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dst.dword[0] = (imm & 2) ? b.dword[(imm & 1)] : a.dword[(imm & 1)];
dst.dword[1] =
(imm & 8) ? b.dword[((imm >> 2) & 1)] : a.dword[((imm >> 2) & 1)];
dst.dword[2] = (imm & 2) ? b.dword[(imm & 1) + 2] : a.dword[(imm & 1) + 2];
dst.dword[3] =
(imm & 8) ? b.dword[((imm >> 2) & 1) + 2] : a.dword[((imm >> 2) & 1) + 2];
7 changes: 7 additions & 0 deletions code/xvshuf_b.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
for (int i = 0; i < 32; i++) {
if ((c.byte[i] % 64) < 32) {
dst.byte[i] = b.byte[c.byte[i] % 32];
} else {
dst.byte[i] = a.byte[c.byte[i] % 32];
}
}
Loading

0 comments on commit 8fac972

Please sign in to comment.