Fixed ASL/ASR

This commit is contained in:
Rodolphe de Saint Léger 2025-05-19 15:27:30 +02:00
parent 7daa27e15f
commit b7910339a3
8 changed files with 49 additions and 25 deletions

View file

@ -814,16 +814,25 @@ public class CoreALU {
byte res = (byte) dst;
if (shift > 0) {
int mask = -1 << (8 - Math.min(shift, 8));
int vout = res & mask;
int cx = 0;
int v = (vout == 0) || (vout == mask) ? 0 : FL_V;
int v = 0;
if (shift < 8) {
int mask = -1 << (8 - Math.min(shift + 1, 8));
int vout = res & mask;
if (shift <= 8) {
res <<= shift - 1;
v = (vout == 0) || (vout == mask) ? 0 : FL_V;
cx = (res >> 31) & (FL_C | FL_X);
res <<= 1;
} else if (shift == 8) {
cx = res & FL_C; /* set carry */
cx |= cx << 4; /* also set eXtend */
v = ((res | -res) >> 31) & FL_V;
res = 0;
} else {
v = ((res | -res) >> 31) & FL_V;
res = 0;
}
@ -847,16 +856,25 @@ public class CoreALU {
short res = (short) dst;
if (shift > 0) {
int mask = -1 << (16 - Math.min(shift, 16));
int vout = res & mask;
int cx = 0;
int v = (vout == 0) || (vout == mask) ? 0 : FL_V;
int v = 0;
if (shift < 16) {
int mask = -1 << (16 - Math.min(shift + 1, 16));
int vout = res & mask;
if (shift <= 16) {
res <<= shift - 1;
v = (vout == 0) || (vout == mask) ? 0 : FL_V;
cx = (res >> 31) & (FL_C | FL_X);
res <<= 1;
} else if (shift == 16) {
cx = res & FL_C; /* set carry */
cx |= cx << 4; /* also set eXtend */
v = ((res | -res) >> 31) & FL_V;
res = 0;
} else {
v = ((res | -res) >> 31) & FL_V;
res = 0;
}
@ -880,16 +898,25 @@ public class CoreALU {
int res = dst;
if (shift > 0) {
int mask = -1 << (32 - Math.min(shift, 32));
int vout = res & mask;
int cx = 0;
int v = (vout == 0) || (vout == mask) ? 0 : FL_V;
int v = 0;
if (shift < 32) {
int mask = -1 << (32 - Math.min(shift + 1, 32));
int vout = res & mask;
if (shift <= 32) {
res <<= shift - 1;
v = (vout == 0) || (vout == mask) ? 0 : FL_V;
cx = (res >> 31) & (FL_C | FL_X);
res <<= 1;
} else if (shift == 32) {
cx = res & FL_C; /* set carry */
cx |= cx << 4; /* also set eXtend */
v = ((res | -res) >> 31) & FL_V;
res = 0;
} else {
v = ((res | -res) >> 31) & FL_V;
res = 0;
}

View file

@ -74,6 +74,12 @@ public class InstructionTests extends TestCase {
public void testShift() {
CoreTest test = new CoreTest(0xffffff + 1, true);
test.executeBinTest("ASL.b");
test.executeBinTest("ASL.w");
test.executeBinTest("ASL.l");
test.executeBinTest("ASR.b");
test.executeBinTest("ASR.w");
test.executeBinTest("ASR.l");
test.executeBinTest("LSL.b");
test.executeBinTest("LSL.w");
test.executeBinTest("LSL.l");
@ -164,22 +170,13 @@ public class InstructionTests extends TestCase {
test.executeBinTest("MOVE.b");
/*
* 295 is not compatible (post incremented value is written by design) 342 is
* not compatible (post incremented value is written by design) 494 is not
* compatible (post incremented value is written by design) 994 is not
* compatible (pre decremented value is written by design) 1225 is not
* compatible (pre decremented value is written by design) 1846 is not
* compatible (post incremented value is written by design)
* skipped cases are incompatible (move address register to pre/post
* dec/increment with same address register)
*/
test.executeBinTest("MOVE.w", 295, 342, 494, 994, 1225, 1846);
/*
* 217 is not compatible (post incremented value is written by design) 502 is
* not compatible (post incremented value is written by design) 1152 is not
* compatible (post incremented value is written by design) 1691 is not
* compatible (post incremented value is written by design) 1830 is not
* compatible (pre decremented value is written by design) 2057 is not
* compatible (post incremented value is written by design) 2135 is not
* compatible (post incremented value is written by design)
* skipped cases are incompatible (move address register to pre/post
* dec/increment with same address register)
*/
test.executeBinTest("MOVE.l", 217, 502, 1152, 1691, 1830, 2057, 2135);
test.executeBinTest("MOVE.q");