diff --git a/Ghidra/Extensions/SleighDevTools/certification.manifest b/Ghidra/Extensions/SleighDevTools/certification.manifest index b2855cc41e..07bcf00587 100644 --- a/Ghidra/Extensions/SleighDevTools/certification.manifest +++ b/Ghidra/Extensions/SleighDevTools/certification.manifest @@ -11,6 +11,7 @@ pcodetest/build||GHIDRA||||END| pcodetest/build.py||GHIDRA||||END| pcodetest/c_src/BIOPS.test||GHIDRA||||END| pcodetest/c_src/BIOPS2.test||GHIDRA||||END| +pcodetest/c_src/BIOPS4.test||GHIDRA||||END| pcodetest/c_src/BIOPS_DOUBLE.test||GHIDRA||||END| pcodetest/c_src/BIOPS_FLOAT.test||GHIDRA||||END| pcodetest/c_src/BIOPS_LONGLONG.test||GHIDRA||||END| diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS.test b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS.test index 109e1ed505..d00d15d9a4 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS.test +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS.test @@ -1,677 +1,413 @@ #include "pcode_test.h" -TEST pcode_u1_complexLogic_Main() +TEST u1_complexLogic_Main() { - extern u1 pcode_u1_complexLogic(u1 a, u1 b, u1 c, u1 d, u1 e, u1 f); - ASSERTU1(pcode_u1_complexLogic(237, 210, 0, 0, 153, 76), 11); - ASSERTU1(pcode_u1_complexLogic(139, 0, 34, 0, 86, 154), 10); - ASSERTU1(pcode_u1_complexLogic(24, 209, 254, 0, 228, 217), 15); - ASSERTU1(pcode_u1_complexLogic(0, 9, 209, 0, 165, 150), 11); + extern u1 u1_complexLogic(u1 a, u1 b, u1 c, u1 d, u1 e, u1 f); + ASSERTU1(u1_complexLogic(237, 210, 0, 0, 153, 76), 11); + ASSERTU1(u1_complexLogic(139, 0, 34, 0, 86, 154), 10); + ASSERTU1(u1_complexLogic(24, 209, 254, 0, 228, 217), 15); + ASSERTU1(u1_complexLogic(0, 9, 209, 0, 165, 150), 11); } -TEST pcode_u2_complexLogic_Main() -{ - extern u2 pcode_u2_complexLogic(u2 a, u2 b, u2 c, u2 d, u2 e, u2 f); - ASSERTU2(pcode_u2_complexLogic(15941, 23971, 41361, 0, 43462, 0), 15); - ASSERTU2(pcode_u2_complexLogic(52937, 43562, 0, 0, 48661, 51969), 11); - ASSERTU2(pcode_u2_complexLogic(54831, 59630, 16661, 0, 0, 25991), 14); - ASSERTU2(pcode_u2_complexLogic(0, 49882, 61260, 0, 8407, 16234), 10); -} - -TEST pcode_u4_complexLogic_Main() -{ - extern u4 pcode_u4_complexLogic(u4 a, u4 b, u4 c, u4 d, u4 e, u4 f); - ASSERTU4(pcode_u4_complexLogic(2016764524, 1717226057, 1748349614, 0, 1276673168, 0), 15); - ASSERTU4(pcode_u4_complexLogic(2009726312, 696947386, 0, 0, 1265204346, 1369602726), 11); - ASSERTU4(pcode_u4_complexLogic(1665204916, 1707056552, 564325578, 0, 0, 1010528946), 14); - ASSERTU4(pcode_u4_complexLogic(0, 1516266761, 1866000081, 0, 1175526309, 1586903190), 10); -} -TEST pcode_i1_complexLogic_Main() -{ - extern i1 pcode_i1_complexLogic(i1 a, i1 b, i1 c, i1 d, i1 e, i1 f); - ASSERTI1(pcode_i1_complexLogic((i1) -150, 45, (i1) -232, 0, 0, 37), 15); - ASSERTI1(pcode_i1_complexLogic((i1) -70, (i1) -39, 134, 0, 229, 63), 14); - ASSERTI1(pcode_i1_complexLogic(0, (i1) -164, (i1) -188, 0, (i1) -106, 238), 10); - ASSERTI1(pcode_i1_complexLogic(0, 43, (i1) -140, 0, (i1) -182, 135), 11); -} - -TEST pcode_i2_complexLogic_Main() -{ - extern i2 pcode_i2_complexLogic(i2 a, i2 b, i2 c, i2 d, i2 e, i2 f); - ASSERTI2(pcode_i2_complexLogic(0, 46379, (i2) -52108, 0, (i2) -54966, 53127), 11); - ASSERTI2(pcode_i2_complexLogic((i2) -5607, 26256, 23643, 0, (i2) -21648, 0), 14); - ASSERTI2(pcode_i2_complexLogic((i2) -19816, 41002, 63272, 0, 4483, 0), 15); - ASSERTI2(pcode_i2_complexLogic(0, (i2) -25128, 33393, 0, 61486, 53285), 11); -} - -TEST pcode_i4_complexLogic_Main() -{ - extern i4 pcode_i4_complexLogic(i4 a, i4 b, i4 c, i4 d, i4 e, i4 f); - ASSERTI4(pcode_i4_complexLogic((i4) -1916250774, 1528806445, (i4) -870305000, 0, 0, 1799560997), 14); - ASSERTI4(pcode_i4_complexLogic((i4) -1375179334, (i4) -1539942439, 987987334, 0, 1162088421, 12548159), 15); - ASSERTI4(pcode_i4_complexLogic(0, (i4) -750167716, (i4) -1104561852, 0, (i4) -915711850, 737703662), 11); - ASSERTI4(pcode_i4_complexLogic(0, 386839851, (i4) -771476364, 0, (i4) -942724790, 1833488263), 10); -} - -TEST biopCmpu1u1_Main() -{ - extern u1 biopCmpu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopCmpu1u1(0x1, 0x1), 1); - ASSERTU1(biopCmpu1u1(0x1, 0x2), 23); - ASSERTU1(biopCmpu1u1(0x2, 0x1), 22); -} - -TEST biopCmpu2u2_Main() -{ - extern u2 biopCmpu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopCmpu2u2(0x1, 0x1), 1); - ASSERTU2(biopCmpu2u2(0x1, 0x2), 23); - ASSERTU2(biopCmpu2u2(0x2, 0x1), 22); -} - -TEST biopCmpu4u4_Main() -{ - extern u4 biopCmpu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopCmpu4u4(0x1, 0x1), 1); - ASSERTU4(biopCmpu4u4(0x1, 0x2), 23); - ASSERTU4(biopCmpu4u4(0x2, 0x1), 22); -} - -TEST biopCmpi1i1_Main() -{ - extern i1 biopCmpi1i1(i1 lhs, i1 rhs); - ASSERTI1(biopCmpi1i1(0x1, 0x1), 21); - ASSERTI1(biopCmpi1i1(0x1, 0x2), 21); - ASSERTI1(biopCmpi1i1(0x2, 0x1), 22); - ASSERTI1(biopCmpi1i1(-0x1, -0x1), 21); - ASSERTI1(biopCmpi1i1(-0x1, -0x2), 21); - ASSERTI1(biopCmpi1i1(-0x2, -0x1), 24); -} - -TEST biopCmpi2i2_Main() -{ - extern i2 biopCmpi2i2(i2 lhs, i2 rhs); - ASSERTI2(biopCmpi2i2(0x1, 0x1), 21); - ASSERTI2(biopCmpi2i2(0x1, 0x2), 21); - ASSERTI2(biopCmpi2i2(0x2, 0x1), 22); - ASSERTI2(biopCmpi2i2(-0x1, -0x1), 21); - ASSERTI2(biopCmpi2i2(-0x1, -0x2), 21); - ASSERTI2(biopCmpi2i2(-0x2, -0x1), 24); -} - -TEST biopCmpi4i4_Main() -{ - extern i4 biopCmpi4i4(i4 lhs, i4 rhs); - ASSERTI4(biopCmpi4i4(0x1, 0x1), 21); - ASSERTI4(biopCmpi4i4(0x1, 0x2), 21); - ASSERTI4(biopCmpi4i4(0x2, 0x1), 22); - ASSERTI4(biopCmpi4i4(-0x1, -0x1), 21); - ASSERTI4(biopCmpi4i4(-0x1, -0x2), 21); - ASSERTI4(biopCmpi4i4(-0x2, -0x1), 24); -} - -TEST biopAndi4i4_Main() -{ - extern i4 biopAndi4i4(i4 lhs, i4 rhs); - ASSERTI4(biopAndi4i4(0x01010101, 0x01010101), 0x01010101); - ASSERTI4(biopAndi4i4(2, 1), 0); - ASSERTI4(/*val*/ biopAndi4i4(I4_MAX, I4_MAX), 2147483647) - ASSERTI4(/*val*/ biopAndi4i4(0, 0), 0) - ASSERTI4(/*val*/ biopAndi4i4(I4_MIN, I4_MIN), -2147483648) -} -TEST biopLei1i1_Main() +TEST i1_complexLogic_Main() { - extern i1 biopLei1i1(i1 lhs, i1 rhs); - ASSERTI1(biopLei1i1(2, 1), 0); - ASSERTI1(biopLei1i1(~2, ~1), 1); + extern i1 i1_complexLogic(i1 a, i1 b, i1 c, i1 d, i1 e, i1 f); + ASSERTI1(i1_complexLogic((i1) -150, 45, (i1) -232, 0, 0, 37), 15); + ASSERTI1(i1_complexLogic((i1) -70, (i1) -39, 134, 0, 229, 63), 14); + ASSERTI1(i1_complexLogic(0, (i1) -164, (i1) -188, 0, (i1) -106, 238), 10); + ASSERTI1(i1_complexLogic(0, 43, (i1) -140, 0, (i1) -182, 135), 11); } -TEST biopLogicAndu4u4_Main() +TEST u1_compareLogic_Main() { - extern u4 biopLogicAndu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopLogicAndu4u4(0x01010101, 0x01010101), 1); - ASSERTU4(biopLogicAndu4u4(2, 1), 1); - ASSERTU4(biopLogicAndu4u4(U4_MAX, U4_MAX), 1) + extern u1 u1_compareLogic(u1 lhs, u1 rhs); + ASSERTU1(u1_compareLogic(0x1, 0x1), 1); + ASSERTU1(u1_compareLogic(0x1, 0x2), 23); + ASSERTU1(u1_compareLogic(0x2, 0x1), 22); } -TEST biopGtu2u2_Main() +TEST i1_compareLogic_Main() { - extern u2 biopGtu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopGtu2u2(2, 1), 1); - ASSERTU2(biopGtu2u2(U2_MAX, U2_MAX), 0); - ASSERTU2(biopGtu2u2(U2_MAX, 0), 1); - ASSERTU2(biopGtu2u2(0, U2_MAX), 0); + extern i1 i1_compareLogic(i1 lhs, i1 rhs); + ASSERTI1(i1_compareLogic(0x1, 0x1), 21); + ASSERTI1(i1_compareLogic(0x1, 0x2), 21); + ASSERTI1(i1_compareLogic(0x2, 0x1), 22); + ASSERTI1(i1_compareLogic(-0x1, -0x1), 21); + ASSERTI1(i1_compareLogic(-0x1, -0x2), 21); + ASSERTI1(i1_compareLogic(-0x2, -0x1), 24); } -TEST biopEqi1i1_Main() -{ - extern i1 biopEqi1i1(i1 lhs, i1 rhs); - ASSERTI1(biopEqi1i1(2, 1), 0); - ASSERTI1(biopEqi1i1(I1_MAX, I1_MAX), 1); - ASSERTI1(biopEqi1i1(I1_MAX, I1_MIN), 0); - ASSERTI1(biopEqi1i1(I1_MIN, I1_MAX), 0); -} - -TEST biopOri4i4_Main() -{ - extern i4 biopOri4i4(i4 lhs, i4 rhs); - ASSERTI4(biopOri4i4(0x01010101, 0x01010101), 0x01010101); - ASSERTI4(biopOri4i4(0x01010101, 0x0), 0x01010101); - ASSERTI4(biopOri4i4(2, 1), 3); - ASSERTI4(biopOri4i4(I4_MAX, I4_MAX), 2147483647); - ASSERTI4(biopOri4i4(0, 0), 0); -} - -TEST unopNotu4_Main() -{ - extern u4 unopNotu4(u4 lhs); - ASSERTU4(unopNotu4(0x01010101), 0); - ASSERTU4(unopNotu4(2), 0); - ASSERTU4(unopNotu4(U4_MAX), 0); -} - -TEST unopPlusu1_Main() -{ - extern u1 unopPlusu1(u1 lhs); - ASSERTU1(unopPlusu1(0x01), 0x01); - ASSERTU1(unopPlusu1(U1_MAX), 255); - ASSERTU1(unopPlusu1(0), 0); -} - -TEST biopGeu2u2_Main() -{ - extern u2 biopGeu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopGeu2u2(2, 1), 1); - ASSERTU2(biopGeu2u2(U2_MAX, U2_MAX), 1); - ASSERTU2(biopGeu2u2(1, 1), 1); - ASSERTU2(biopGeu2u2(1, 2), 0); -} - -TEST biopNei1i1_Main() -{ - extern i1 biopNei1i1(i1 lhs, i1 rhs); - ASSERTI1(biopNei1i1(2, 1), 1); - ASSERTI1(biopNei1i1(I1_MAX, I1_MAX), 0); - ASSERTI1(biopNei1i1(I1_MIN, I1_MIN), 0); - ASSERTI1(biopNei1i1(0, 0), 0); -} - - -TEST biopXOri4i4_Main() -{ - extern i4 biopXOri4i4(i4 lhs, i4 rhs); - ASSERTI4(biopXOri4i4(0x01010101, 0x01010101), 0); - ASSERTI4(biopXOri4i4(0x01010101, 0x01000101), 0x10000); - ASSERTI4(biopXOri4i4(2, 1), 3); - ASSERTI4(biopXOri4i4(I4_MAX, I4_MAX), 0); - ASSERTI4(biopXOri4i4(I4_MAX, 0), 2147483647); - ASSERTI4(biopXOri4i4(0, 0), 0); -} - - -TEST biopDividi4i4_Main() -{ - extern i4 biopDividi4i4(i4 lhs, i4 rhs); - ASSERTI4(biopDividi4i4(0x01010101, 0x01010101), 1); - ASSERTI4(biopDividi4i4(-0x01010101, 0x01010101), -1); - ASSERTI4(biopDividi4i4(0, 0x01010101), 0); - ASSERTI4(biopDividi4i4(0x01010101, 2), 0x808080); - ASSERTI4(biopDividi4i4(I4_MAX, I4_MAX), 1); - ASSERTI4(biopDividi4i4(I4_MIN, I4_MIN), 1); - ASSERTI4(biopDividi4i4(-1, I4_MIN), 0); -} - -TEST biopRemainderi4i4_Main() -{ - extern i4 biopRemainderi4i4(i4 lhs, i4 rhs); - ASSERTI4(biopRemainderi4i4(0x01010101, 0x01010101), 0); - ASSERTI4(biopRemainderi4i4(I4_MAX, I4_MAX), 0); - ASSERTI4(biopRemainderi4i4(I4_MIN, I4_MIN), 0); - ASSERTI4(biopRemainderi4i4(0, I4_MIN), 0); - ASSERTI4(biopRemainderi4i4(0, I4_MAX), 0); -} - -TEST biopLtu2u2_Main() -{ - extern u2 biopLtu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopLtu2u2(2, 1), 0); - ASSERTU2(biopLtu2u2(2, 1), 0); - ASSERTU2(biopLtu2u2(U2_MAX, U2_MAX), 0); - ASSERTU2(biopLtu2u2(0, 0), 0); - ASSERTU2(biopLtu2u2(1, 2), 1); -} - -TEST biopAndi1i1_Main() -{ - extern i1 biopAndi1i1(i1 lhs, i1 rhs); - ASSERTI1(biopAndi1i1(2, 1), 0); - ASSERTI1(biopAndi1i1(I1_MAX, I1_MAX), 127); - ASSERTI1(biopAndi1i1(I1_MIN, I1_MIN), -128); - ASSERTI1(biopAndi1i1(0, 0), 0); -} +/* Comparison operators */ -TEST biopLogicOri4i4_Main() +TEST u1_greaterThan_Main() { - extern i4 biopLogicOri4i4(i4 lhs, i4 rhs); - ASSERTI4(biopLogicOri4i4(0x01010101, 0x01010101), 1); - ASSERTI4(biopLogicOri4i4(2, 1), 1); - ASSERTI4(biopLogicOri4i4(I4_MAX, I4_MAX), 1); - ASSERTI4(biopLogicOri4i4(I4_MIN, I4_MIN), 1); - ASSERTI4(biopLogicOri4i4(0, 0), 0); + extern u1 u1_greaterThan(u1 lhs, u1 rhs); + ASSERTU1(u1_greaterThan(0x01, 0x01), 0); + ASSERTU1(u1_greaterThan(U1_MAX, U1_MAX), 0); + ASSERTU1(u1_greaterThan(U1_MAX, 0), 1); + ASSERTU1(u1_greaterThan(0, U1_MAX), 0); } -TEST unopPlusu4_Main() +TEST u1_greaterThanEquals_Main() { - extern u4 unopPlusu4(u4 lhs); - ASSERTU4(unopPlusu4(0x01010101), 0x01010101); - ASSERTU4(unopPlusu4(2), 2); - ASSERTU4(unopPlusu4(U4_MAX), -1); - ASSERTU4(unopPlusu4(~1000), 4294966295); - ASSERTU4(unopPlusu4(0), 0); + extern u1 u1_greaterThanEquals(u1 lhs, u1 rhs); + ASSERTU1(u1_greaterThanEquals(0x01, 0x01), 1); + ASSERTU1(u1_greaterThanEquals(U1_MAX, U1_MAX), 1); + ASSERTU1(u1_greaterThanEquals(U1_MAX, 0), 1); + ASSERTU1(u1_greaterThanEquals(0, U1_MAX), 0); } -TEST biopLeu2u2_Main() +TEST u1_lessThan_Main() { - extern u2 biopLeu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopLeu2u2(2, 1), 0); - ASSERTU2(biopLeu2u2(U2_MAX, U2_MAX), 1); - ASSERTU2(biopLeu2u2(U2_MIN, U2_MIN), 1); - ASSERTU2(biopLeu2u2(1, 2), 1); + extern u1 u1_lessThan(u1 lhs, u1 rhs); + ASSERTU1(u1_lessThan(0x01, 0x01), 0); + ASSERTU1(u1_lessThan(U1_MAX, U1_MAX), 0); + ASSERTU1(u1_lessThan(U1_MAX, 0), 0); } -TEST biopLogicAndi4i4_Main() +TEST u1_lessThanEquals_Main() { - extern i4 biopLogicAndi4i4(i4 lhs, i4 rhs); - ASSERTI4(biopLogicAndi4i4(0x01010101, 0x01010101), 1); - ASSERTI4(biopLogicAndi4i4(2, 1), 1); - ASSERTI4(biopLogicAndi4i4(0x01000101, 0x01010101), 1); - ASSERTI4(biopLogicAndi4i4(0x01000101, 0x0), 0); - ASSERTI4(biopLogicAndi4i4(I4_MAX, I4_MAX), 1); - ASSERTI4(biopLogicAndi4i4(I4_MIN, I4_MIN), 1); - ASSERTI4(biopLogicAndi4i4(0, 0), 0); + extern u1 u1_lessThanEquals(u1 lhs, u1 rhs); + ASSERTU1(u1_lessThanEquals(0x01, 0x01), 1); + ASSERTU1(u1_lessThanEquals(U1_MAX, U1_MAX), 1); + ASSERTU1(u1_lessThanEquals(0, 0), 1); + ASSERTU1(u1_lessThanEquals(U1_MAX, 0), 0); + ASSERTU1(u1_lessThanEquals(0, U1_MAX), 1); } -TEST biopOri1i1_Main() +TEST u1_equals_Main() { - extern i1 biopOri1i1(i1 lhs, i1 rhs); - ASSERTI1(biopOri1i1(2, 1), 3); - ASSERTI1(biopOri1i1(I1_MAX, I1_MAX), 127); - ASSERTI1(biopOri1i1(I1_MIN, I1_MIN), -128); - ASSERTI1(biopOri1i1(0, 0), 0); + extern u1 u1_equals(u1 lhs, u1 rhs); + ASSERTU1(u1_equals(0x01, 0x01), 1); + ASSERTU1(u1_equals(U1_MAX, U1_MAX), 1); + ASSERTU1(u1_equals(U1_MAX, 0), 0); + ASSERTU1(u1_equals(0, U1_MAX), 0); } -TEST biopRemainderi2i2_Main() +TEST u1_notEquals_Main() { - extern i2 biopRemainderi2i2(i2 lhs, i2 rhs); - ASSERTI2(biopRemainderi2i2(0x0101, 0x0101), 0x0); - ASSERTI2(biopRemainderi2i2(I2_MAX, I2_MAX), 0x0); - ASSERTI2(biopRemainderi2i2(I2_MIN, I2_MIN), 0x0); - ASSERTI2(biopRemainderi2i2(0, I2_MIN), 0x0); + extern u1 u1_notEquals(u1 lhs, u1 rhs); + ASSERTU1(u1_notEquals(0x01, 0x01), 0); + ASSERTU1(u1_notEquals(U1_MAX, U1_MAX), 0); + ASSERTU1(u1_notEquals(U1_MAX, 0), 1); + ASSERTU1(u1_notEquals(0, U1_MAX), 1); } -TEST biopMulti2i2_Main() +TEST i1_greaterThan_Main() { - extern i2 biopMulti2i2(i2 lhs, i2 rhs); - ASSERTI2(biopMulti2i2(0x0101, 0x0101), 0x201); - ASSERTI2(biopMulti2i2(0x0101, -0x0101), -513); - ASSERTI2(biopMulti2i2(0, -0x0101), 0); - ASSERTI2(biopMulti2i2(2, 1), 2); - ASSERTI2(biopMulti2i2(I2_MAX, I2_MAX), 1); - ASSERTI2(biopMulti2i2(I2_MIN, I2_MIN), 0); - ASSERTI2(biopMulti2i2(1, I2_MIN), I2_MIN); - ASSERTI2(biopMulti2i2(-1, I2_MIN), -I2_MIN); + extern i1 i1_greaterThan(i1 lhs, i1 rhs); + ASSERTI1(i1_greaterThan(2, 1), 1); + ASSERTI1(i1_greaterThan(I1_MAX, I1_MAX), 0); + ASSERTI1(i1_greaterThan(I1_MAX, I1_MIN), 1); + ASSERTI1(i1_greaterThan(I1_MIN, I1_MAX), 0); } -TEST biopEqu2u2_Main() +TEST i1_greaterThanEquals_Main() { - extern u2 biopEqu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopEqu2u2(2, 1), 0); - ASSERTU2(biopEqu2u2(U2_MAX, U2_MAX), 1); - ASSERTU2(biopEqu2u2(U2_MIN, U2_MIN), 1); - ASSERTU2(biopEqu2u2(0, 0), 1); + extern i1 i1_greaterThanEquals(i1 lhs, i1 rhs); + ASSERTI1(i1_greaterThanEquals(2, 1), 1); + ASSERTI1(i1_greaterThanEquals(I1_MAX, I1_MAX), 1); + ASSERTI1(i1_greaterThanEquals(I1_MAX, I1_MIN), 1); + ASSERTI1(i1_greaterThanEquals(I1_MIN, I1_MAX), 0); } -TEST biopDividi2i2_Main() +TEST i1_lessThan_Main() { - extern i2 biopDividi2i2(i2 lhs, i2 rhs); - ASSERTI2(biopDividi2i2(0x0101, 0x0101), 0x1); - ASSERTI2(biopDividi2i2(I2_MAX, I2_MAX), 0x1); - ASSERTI2(biopDividi2i2(I2_MIN, I2_MIN), 0x1); + extern i1 i1_lessThan(i1 lhs, i1 rhs); + ASSERTI1(i1_lessThan(2, 1), 0); + ASSERTI1(i1_lessThan(I1_MAX, I1_MAX), 0); + ASSERTI1(i1_lessThan(I1_MAX, I1_MIN), 0); + ASSERTI1(i1_lessThan(I1_MIN, I1_MAX), 1); } -TEST unopNoti4_Main() +TEST i1_lessThanEquals_Main() { - extern i4 unopNoti4(i4 lhs); - ASSERTI4(unopNoti4(0x01010101), 0); - ASSERTI4(unopNoti4(2), 0); - ASSERTI4(unopNoti4(I4_MAX), 0); - ASSERTI4(unopNoti4(I4_MIN), 0); - ASSERTI4(unopNoti4(0), 1); + extern i1 i1_lessThanEquals(i1 lhs, i1 rhs); + ASSERTI1(i1_lessThanEquals(2, 1), 0); + ASSERTI1(i1_lessThanEquals(~2, ~1), 1); } -TEST biopXOri1i1_Main() +TEST i1_equals_Main() { - extern i1 biopXOri1i1(i1 lhs, i1 rhs); - ASSERTI1(biopXOri1i1(2, 1), 3); - ASSERTI1(biopXOri1i1(I1_MAX, I1_MAX), 0); - ASSERTI1(biopXOri1i1(I1_MIN, I1_MIN), 0); - ASSERTI1(biopXOri1i1(I1_MAX, 0), 127); - ASSERTI1(biopXOri1i1(I1_MAX, 1), 126); + extern i1 i1_equals(i1 lhs, i1 rhs); + ASSERTI1(i1_equals(2, 1), 0); + ASSERTI1(i1_equals(I1_MAX, I1_MAX), 1); + ASSERTI1(i1_equals(I1_MAX, I1_MIN), 0); + ASSERTI1(i1_equals(I1_MIN, I1_MAX), 0); } -TEST biopRemainderi1i1_Main() +TEST i1_notEquals_Main() { - extern i1 biopRemainderi1i1(i1 lhs, i1 rhs); - ASSERTI1(biopRemainderi1i1(0x01, 0x01), 0); - ASSERTI1(biopRemainderi1i1(I1_MAX, I1_MAX), 0); - ASSERTI1(biopRemainderi1i1(I1_MIN, I1_MIN), 0); - ASSERTI1(biopRemainderi1i1(0, I1_MIN), 0); + extern i1 i1_notEquals(i1 lhs, i1 rhs); + ASSERTI1(i1_notEquals(2, 1), 1); + ASSERTI1(i1_notEquals(I1_MAX, I1_MAX), 0); + ASSERTI1(i1_notEquals(I1_MIN, I1_MIN), 0); + ASSERTI1(i1_notEquals(0, 0), 0); } -TEST biopSubi2i2_Main() +/* Bitwise operators */ +TEST u1_bitwiseAnd_Main() { - extern i2 biopSubi2i2(i2 lhs, i2 rhs); - ASSERTI2(biopSubi2i2(0x0101, 0x0100), 0x1); - ASSERTI2(biopSubi2i2(0x0100, 0x0101), -0x1); - ASSERTI2(biopSubi2i2(0x0101, 0x0101), 0); - ASSERTI2(biopSubi2i2(2, 1), 1); - ASSERTI2(biopSubi2i2(I2_MAX, I2_MAX), 0); - ASSERTI2(biopSubi2i2(I2_MIN, I2_MIN), 0); - ASSERTI2(biopSubi2i2(I2_MAX, 0), I2_MAX); - ASSERTI2(biopSubi2i2(0, 0), 0); + extern u1 u1_bitwiseAnd(u1 lhs, u1 rhs); + ASSERTU1(u1_bitwiseAnd(0x01, 0x01), 0x01); + ASSERTU1(u1_bitwiseAnd(U1_MAX, U1_MAX), 255); + ASSERTU1(u1_bitwiseAnd(U1_MAX, 0), 0); + ASSERTU1(u1_bitwiseAnd(U1_MAX, 1), 0x01); } -TEST biopNeu2u2_Main() +TEST u1_bitwiseOr_Main() { - extern u2 biopNeu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopNeu2u2(2, 1), 1); - ASSERTU2(biopNeu2u2(U2_MAX, U2_MAX), 0); - ASSERTU2(biopNeu2u2(0, 0), 0); + extern u1 u1_bitwiseOr(u1 lhs, u1 rhs); + ASSERTU1(u1_bitwiseOr(0x01, 0x01), 0x01); + ASSERTU1(u1_bitwiseOr(U1_MAX, U1_MAX), U1_MAX); + ASSERTU1(u1_bitwiseOr(U1_MAX, U1_MIN), 255); } -TEST biopLogicOri1i1_Main() +TEST u1_bitwiseXor_Main() { - extern i1 biopLogicOri1i1(i1 lhs, i1 rhs); - ASSERTI1(biopLogicOri1i1(2, 1), 1); - ASSERTI1(biopLogicOri1i1(I1_MAX, I1_MAX), 1); - ASSERTI1(biopLogicOri1i1(I1_MIN, I1_MIN), 1); - ASSERTI1(biopLogicOri1i1(0, 0), 0); - ASSERTI1(biopLogicOri1i1(0, I1_MAX), 1); - ASSERTI1(biopLogicOri1i1(I1_MAX, I1_MIN), 1); + extern u1 u1_bitwiseXor(u1 lhs, u1 rhs); + ASSERTU1(u1_bitwiseXor(0x01, 0x01), 0); + ASSERTU1(u1_bitwiseXor(U1_MAX, U1_MAX), 0); + ASSERTU1(u1_bitwiseXor(U1_MAX, 0), 255); } -TEST biopDividi1i1_Main() +TEST i1_bitwiseAnd_Main() { - extern i1 biopDividi1i1(i1 lhs, i1 rhs); - ASSERTI1(biopDividi1i1(0x1, 0x1), 1); - ASSERTI1(biopDividi1i1(I1_MAX, I1_MAX), 1); - ASSERTI1(biopDividi1i1(I1_MIN, I1_MIN), 1); - ASSERTI1(biopDividi1i1(I1_MAX, 1), I1_MAX); + extern i1 i1_bitwiseAnd(i1 lhs, i1 rhs); + ASSERTI1(i1_bitwiseAnd(2, 1), 0); + ASSERTI1(i1_bitwiseAnd(I1_MAX, I1_MAX), 127); + ASSERTI1(i1_bitwiseAnd(I1_MIN, I1_MIN), -128); + ASSERTI1(i1_bitwiseAnd(0, 0), 0); } -TEST unopNegativei4_Main() +TEST i1_bitwiseOr_Main() { - extern i4 unopNegativei4(i4 lhs); - ASSERTI4(unopNegativei4(0x01010101), -0x01010101); - ASSERTI4(unopNegativei4(-0x01010101), 0x01010101); - ASSERTI4(unopNegativei4(I4_MAX), -I4_MAX); - ASSERTI4(unopNegativei4(I4_MIN), I4_MIN); - ASSERTI4(unopNegativei4(0), 0); + extern i1 i1_bitwiseOr(i1 lhs, i1 rhs); + ASSERTI1(i1_bitwiseOr(2, 1), 3); + ASSERTI1(i1_bitwiseOr(I1_MAX, I1_MAX), 127); + ASSERTI1(i1_bitwiseOr(I1_MIN, I1_MIN), -128); + ASSERTI1(i1_bitwiseOr(0, 0), 0); } -TEST biopAddi2i2_Main() +TEST i1_bitwiseXor_Main() { - extern i2 biopAddi2i2(i2 lhs, i2 rhs); - ASSERTI2(biopAddi2i2(0x0101, 0x0101), 514); - ASSERTI2(biopAddi2i2(0x0101, -0x0101), 0); - ASSERTI2(biopAddi2i2(2, 1), 3); - ASSERTI2(biopAddi2i2(I2_MAX, I2_MAX), -2); - ASSERTI2(biopAddi2i2(I2_MIN, I2_MIN), 0); - ASSERTI2(biopAddi2i2(0, 0), 0); + extern i1 i1_bitwiseXor(i1 lhs, i1 rhs); + ASSERTI1(i1_bitwiseXor(2, 1), 3); + ASSERTI1(i1_bitwiseXor(I1_MAX, I1_MAX), 0); + ASSERTI1(i1_bitwiseXor(I1_MIN, I1_MIN), 0); + ASSERTI1(i1_bitwiseXor(I1_MAX, 0), 127); + ASSERTI1(i1_bitwiseXor(I1_MAX, 1), 126); } -TEST biopAndu2u2_Main() +/* Logical operators */ +TEST u1_logicalAnd_Main() { - extern u2 biopAndu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopAndu2u2(2, 1), 0); - ASSERTU2(biopAndu2u2(U2_MAX, U2_MAX), 65535); - ASSERTU2(biopAndu2u2(U2_MIN, U2_MIN), 0); - ASSERTU2(biopAndu2u2(0, U2_MAX), 0); - ASSERTU2(biopAndu2u2(0, 0), 0); + extern u1 u1_logicalAnd(u1 lhs, u1 rhs); + ASSERTU1(u1_logicalAnd(0x01, 0x01), 1); + ASSERTU1(u1_logicalAnd(U1_MAX, U1_MAX), 1); + ASSERTU1(u1_logicalAnd(U1_MAX, 0), 0); + ASSERTU1(u1_logicalAnd(U1_MAX, 1), 1); } -TEST biopLogicAndi1i1_Main() +TEST u1_logicalOr_Main() { - extern i1 biopLogicAndi1i1(i1 lhs, i1 rhs); - ASSERTI1(biopLogicAndi1i1(2, 1), 1); - ASSERTI1(biopLogicAndi1i1(I1_MAX, I1_MAX), 1); - ASSERTI1(biopLogicAndi1i1(I1_MIN, I1_MIN), 1); - ASSERTI1(biopLogicAndi1i1(0, I1_MAX), 0); - ASSERTI1(biopLogicAndi1i1(0, 0), 0); + extern u1 u1_logicalOr(u1 lhs, u1 rhs); + ASSERTU1(u1_logicalOr(0x01, 0x01), 1); + ASSERTU1(u1_logicalOr(U1_MAX, U1_MAX), 1); + ASSERTU1(u1_logicalOr(U1_MAX, 0), 1); } -TEST unopPlusi4_Main() +TEST u1_logicalNot_Main() { - extern i4 unopPlusi4(i4 lhs); - ASSERTI4(unopPlusi4(0x01010101), 0x01010101); - ASSERTI4(unopPlusi4(-0x01010101), -0x01010101); - ASSERTI4(unopPlusi4(2), 2); - ASSERTI4(unopPlusi4(I4_MAX), 2147483647); - ASSERTI4(unopPlusi4(I4_MIN), -2147483648); - ASSERTI4(unopPlusi4(0), 0); + extern u1 u1_logicalNot(u1 lhs); + ASSERTU1(u1_logicalNot(0x01), 0); + ASSERTU1(u1_logicalNot(U1_MAX), 0); + ASSERTU1(u1_logicalNot(0), 1); } -TEST biopShtLfti2i2_Main() +TEST i1_logicalAnd_Main() { - extern i2 biopShtLfti2i2(i2 lhs, i2 rhs); - ASSERTI2(biopShtLfti2i2(0x0101, 15), 0x8000); - ASSERTI2(biopShtLfti2i2(0x0101, 8), 0x100); - ASSERTI2(biopShtLfti2i2(0x0101, 0), 0x101); - ASSERTI2(biopShtLfti2i2(2, 1), 4); - ASSERTI2(biopShtLfti2i2(I2_MAX, 4), -16); - ASSERTI2(biopShtLfti2i2(I2_MIN, 4), 0); - ASSERTI2(biopShtLfti2i2(0, 4), 0); + extern i1 i1_logicalAnd(i1 lhs, i1 rhs); + ASSERTI1(i1_logicalAnd(2, 1), 1); + ASSERTI1(i1_logicalAnd(I1_MAX, I1_MAX), 1); + ASSERTI1(i1_logicalAnd(I1_MIN, I1_MIN), 1); + ASSERTI1(i1_logicalAnd(0, I1_MAX), 0); + ASSERTI1(i1_logicalAnd(0, 0), 0); } -TEST biopOru2u2_Main() +TEST i1_logicalOr_Main() { - extern u2 biopOru2u2(u2 lhs, u2 rhs); - ASSERTU2(biopOru2u2(2, 1), 3); - ASSERTU2(biopOru2u2(U2_MAX, U2_MAX), 65535); - ASSERTU2(biopOru2u2(U2_MAX, 0), 65535); - ASSERTU2(biopOru2u2(U2_MAX, U2_MAX), 65535); + extern i1 i1_logicalOr(i1 lhs, i1 rhs); + ASSERTI1(i1_logicalOr(2, 1), 1); + ASSERTI1(i1_logicalOr(I1_MAX, I1_MAX), 1); + ASSERTI1(i1_logicalOr(I1_MIN, I1_MIN), 1); + ASSERTI1(i1_logicalOr(0, 0), 0); + ASSERTI1(i1_logicalOr(0, I1_MAX), 1); + ASSERTI1(i1_logicalOr(I1_MAX, I1_MIN), 1); } -TEST unopNoti1_Main() +TEST i1_logicalNot_Main() { - extern i1 unopNoti1(i1 lhs); - ASSERTI1(unopNoti1(2), 0); - ASSERTI1(unopNoti1(I1_MAX), 0); - ASSERTI1(unopNoti1(I1_MIN), 0); - ASSERTI1(unopNoti1(0), 1); + extern i1 i1_logicalNot(i1 lhs); + ASSERTI1(i1_logicalNot(2), 0); + ASSERTI1(i1_logicalNot(I1_MAX), 0); + ASSERTI1(i1_logicalNot(I1_MIN), 0); + ASSERTI1(i1_logicalNot(0), 1); } -TEST biopMultu4u4_Main() +/* Shift operators */ +TEST u1_shiftLeft_Main() { - extern u4 biopMultu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopMultu4u4(0x01010101, 0x01010101), 67305985); - ASSERTU4(biopMultu4u4(2, 1), 2); - ASSERTU4(biopMultu4u4(~2, ~1), 6); - ASSERTU4(biopMultu4u4(U4_MAX, U4_MAX), 1); - ASSERTU4(biopMultu4u4(U4_MAX, 1), U4_MAX); - ASSERTU4(biopMultu4u4(U4_MAX, 0), 0); + extern u1 u1_shiftLeft(u1 lhs, u1 rhs); + ASSERTU1(u1_shiftLeft(0x01, 2), 0x4); + ASSERTU1(u1_shiftLeft(U1_MAX, 2), 252); + ASSERTU1(u1_shiftLeft(U1_MAX, 8-1), 128); + ASSERTU1(u1_shiftLeft(U1_MAX, 8), 0); + ASSERTU1(u1_shiftLeft(2, 1), 0x4); } -TEST biopShtRhti2i2_Main() +TEST u1_shiftRight_Main() { - extern i2 biopShtRhti2i2(i2 lhs, i2 rhs); - ASSERTI2(biopShtRhti2i2(0x7fff, 15), 0x0000); - ASSERTI2(biopShtRhti2i2(0x0101, 8), 0x1); - ASSERTI2(biopShtRhti2i2(0x0101, 0), 0x0101); - ASSERTI2(biopShtRhti2i2(2, 1), 1); - ASSERTI2(biopShtRhti2i2(I2_MAX, 4), 2047); - ASSERTI2(biopShtRhti2i2(I2_MAX, 0), 32767); - ASSERTI2(biopShtRhti2i2(I2_MIN, 4), -2048); - ASSERTI2(biopShtRhti2i2(I2_MIN, 0), -32768); + extern u1 u1_shiftRight(u1 lhs, u1 rhs); + ASSERTU1(u1_shiftRight(0x80, 2), 0x20); + ASSERTU1(u1_shiftRight(U1_MAX, 2), 63); + ASSERTU1(u1_shiftRight(U1_MAX, 8-1), 1); + ASSERTU1(u1_shiftRight(U1_MAX, 8), 0); } -TEST biopXOru2u2_Main() +TEST i1_shiftLeft_Main() { - extern u2 biopXOru2u2(u2 lhs, u2 rhs); - ASSERTU2(biopXOru2u2(2, 1), 3); - ASSERTU2(biopXOru2u2(U2_MAX, U2_MAX), 0); - ASSERTU2(biopXOru2u2(0, 0), 0); - ASSERTU2(biopXOru2u2(0, U2_MAX), 65535); + extern i1 i1_shiftLeft(i1 lhs, i1 rhs); + ASSERTI1(i1_shiftLeft(2, 1), 4); + ASSERTI1(i1_shiftLeft(I1_MAX, 2), -4); + ASSERTI1(i1_shiftLeft(I1_MIN, 2), 0); + ASSERTI1(i1_shiftLeft(I1_MAX, 0), 127); } -TEST biopSubu4u4_Main() +TEST i1_shiftRight_Main() { - extern u4 biopSubu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopSubu4u4(0x01010101, 0x01010101), 0); - ASSERTU4(biopSubu4u4(2, 1), 1); - ASSERTU4(biopSubu4u4(~2, ~1), 4294967295); - ASSERTU4(biopSubu4u4(U4_MAX, U4_MAX), 0); - ASSERTU4(biopSubu4u4(U4_MAX, 0), U4_MAX); - ASSERTU4(biopSubu4u4(0, U4_MAX), 1); + extern i1 i1_shiftRight(i1 lhs, i1 rhs); + ASSERTI1(i1_shiftRight(2, 1), 1); + ASSERTI1(i1_shiftRight(I1_MAX, 2), 31); + ASSERTI1(i1_shiftRight(16, 4), 1); } -TEST unopNegativei1_Main() +/* Arithmetic functions */ +TEST u1_unaryPlus_Main() { - extern i1 unopNegativei1(i1 lhs); - ASSERTI1(unopNegativei1(2), -2); - ASSERTI1(unopNegativei1(I1_MAX), -127); - ASSERTI1(unopNegativei1(I1_MIN), -128); - ASSERTI1(unopNegativei1(0), 0); + extern u1 u1_unaryPlus(u1 lhs); + ASSERTU1(u1_unaryPlus(0x01), 0x01); + ASSERTU1(u1_unaryPlus(U1_MAX), 255); + ASSERTU1(u1_unaryPlus(0), 0); } -TEST biopGti2i2_Main() +TEST u1_addition_Main() { - extern i2 biopGti2i2(i2 lhs, i2 rhs); - ASSERTI2(biopGti2i2(0x0101, 0x0101), 0); - ASSERTI2(biopGti2i2(0x0101, 0x0100), 1); - ASSERTI2(biopGti2i2(0x0101, -0x0101), 1); - ASSERTI2(biopGti2i2(2, 1), 1); - ASSERTI2(biopGti2i2(I1_MAX, I1_MAX), 0); - ASSERTI2(biopGti2i2(I1_MIN, I1_MIN), 0); - ASSERTI2(biopGti2i2(I1_MAX-1, I1_MAX), 0); - ASSERTI2(biopGti2i2(I1_MAX, I1_MAX-1), 1); + extern u1 u1_addition(u1 lhs, u1 rhs); + ASSERTU1(u1_addition(0x01, 0x01), 2); + ASSERTU1(u1_addition(U1_MAX, U1_MAX), 254); + ASSERTU1(u1_addition(U1_MAX, 0), 255); + ASSERTU1(u1_addition(U1_MAX, 1), 0); } -TEST biopLogicOru2u2_Main() +TEST u1_subtract_Main() { - extern u2 biopLogicOru2u2(u2 lhs, u2 rhs); - ASSERTU2(biopLogicOru2u2(2, 1), 1); - ASSERTU2(biopLogicOru2u2(2, 1), 1); - ASSERTU2(biopLogicOru2u2(U2_MAX, U2_MAX), 1); - ASSERTU2(biopLogicOru2u2(U2_MIN, U2_MIN), 0); - ASSERTU2(biopLogicOru2u2(U2_MAX, U2_MIN), 1); - ASSERTU2(biopLogicOru2u2(U2_MAX, 0), 1); - ASSERTU2(biopLogicOru2u2(0, 0), 0); + extern u1 u1_subtract(u1 lhs, u1 rhs); + ASSERTU1(u1_subtract(0x01, 0x01), 0); + ASSERTU1(u1_subtract(U1_MAX, U1_MAX), 0); + ASSERTU1(u1_subtract(U1_MAX, 0), U1_MAX); + ASSERTU1(u1_subtract(0, U1_MAX), 1); } -TEST biopAddu4u4_Main() +TEST u1_multiply_Main() { - extern u4 biopAddu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopAddu4u4(0x01010101, 0x01010101), 33686018); - ASSERTU4(biopAddu4u4(2, 1), 3); - ASSERTU4(biopAddu4u4(~2, ~1), 4294967291); - ASSERTU4(biopAddu4u4(U4_MAX, U4_MAX), -2); - ASSERTU4(biopAddu4u4(U4_MAX, 0), -1); - ASSERTU4(biopAddu4u4(0, 0), 0); + extern u1 u1_multiply(u1 lhs, u1 rhs); + ASSERTU1(u1_multiply(0x01, 0x01), 1); + ASSERTU1(u1_multiply(U1_MAX, 1), U1_MAX); + ASSERTU1(u1_multiply(U1_MAX, U1_MAX), 1); + ASSERTU1(u1_multiply(U1_MAX, 0), 0); } -TEST unopPlusi1_Main() +TEST u1_divide_Main() { - extern i1 unopPlusi1(i1 lhs); - ASSERTI1(unopPlusi1(2), 2); - ASSERTI1(unopPlusi1(I1_MAX), 127); - ASSERTI1(unopPlusi1(I1_MIN), -128); - ASSERTI1(unopPlusi1(0), 0); + extern i1 u1_divide(u1 lhs, u1 rhs); + ASSERTI1(u1_divide(0x01, 0x01), 1); + ASSERTI1(u1_divide(U1_MAX, U1_MAX), 1); + ASSERTI1(u1_divide(U1_MAX, 1), U1_MAX); } -TEST biopGei2i2_Main() +TEST u1_remainder_Main() { - extern i2 biopGei2i2(i2 lhs, i2 rhs); - ASSERTI2(biopGei2i2(2, 1), 1); - ASSERTI2(biopGei2i2(I2_MAX, I2_MAX), 1); - ASSERTI2(biopGei2i2(I2_MIN, I2_MIN), 1); - ASSERTI2(biopGei2i2(I2_MAX, I2_MIN), 1); - ASSERTI2(biopGei2i2(I2_MIN, I2_MAX), 0); + extern u1 u1_remainder(u1 lhs, u1 rhs); + ASSERTU1(u1_remainder(0x01, 0x01), 0); + ASSERTU1(u1_remainder(U1_MAX, U1_MAX), 0); + ASSERTU1(u1_remainder(0, I1_MIN), 0); } -TEST biopLogicAndu2u2_Main() +TEST i1_unaryMinus_Main() { - extern u2 biopLogicAndu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopLogicAndu2u2(2, 1), 1); - ASSERTU2(biopLogicAndu2u2(I2_MAX, I2_MAX), 1); - ASSERTU2(biopLogicAndu2u2(I2_MIN, I2_MIN), 1); - ASSERTU2(biopLogicAndu2u2(I2_MAX, I2_MIN), 1); - ASSERTU2(biopLogicAndu2u2(I2_MAX, 0), 0); + extern i1 i1_unaryMinus(i1 lhs); + ASSERTI1(i1_unaryMinus(2), -2); + ASSERTI1(i1_unaryMinus(I1_MAX), -127); + ASSERTI1(i1_unaryMinus(I1_MIN), -128); + ASSERTI1(i1_unaryMinus(0), 0); } -TEST biopMultu1u1_Main() +TEST i1_unaryPlus_Main() { - extern u1 biopMultu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopMultu1u1(0x01, 0x01), 1); - ASSERTU1(biopMultu1u1(U1_MAX, 1), U1_MAX); - ASSERTU1(biopMultu1u1(U1_MAX, U1_MAX), 1); - ASSERTU1(biopMultu1u1(U1_MAX, 0), 0); + extern i1 i1_unaryPlus(i1 lhs); + ASSERTI1(i1_unaryPlus(2), 2); + ASSERTI1(i1_unaryPlus(I1_MAX), 127); + ASSERTI1(i1_unaryPlus(I1_MIN), -128); + ASSERTI1(i1_unaryPlus(0), 0); } -TEST biopGtu1u1_Main() +TEST i1_addition_Main() { - extern u1 biopGtu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopGtu1u1(0x01, 0x01), 0); - ASSERTU1(biopGtu1u1(U1_MAX, U1_MAX), 0); - ASSERTU1(biopGtu1u1(U1_MAX, 0), 1); - ASSERTU1(biopGtu1u1(0, U1_MAX), 0); + extern i1 i1_addition(i1 lhs, i1 rhs); + ASSERTI1(i1_addition(2, 1), 3); + ASSERTI1(i1_addition(I1_MAX, I1_MAX), -2); + ASSERTI1(i1_addition(I1_MAX, I1_MIN), -1); + ASSERTI1(i1_addition(I1_MAX, 0), 127); } -TEST biopShtLftu4u4_Main() +TEST i1_subtract_Main() { - extern u4 biopShtLftu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopShtLftu4u4(0x01010101, 16), 0x01010000); - ASSERTU4(biopShtLftu4u4(2, 1), 4); - ASSERTU4(biopShtLftu4u4(U4_MAX, 4*8-1), 2147483648); - ASSERTU4(biopShtLftu4u4(U4_MAX, 4), -16); + extern i1 i1_subtract(i1 lhs, i1 rhs); + ASSERTI1(i1_subtract(2, 1), 1); + ASSERTI1(i1_subtract(I1_MAX, I1_MAX), 0); + ASSERTI1(i1_subtract(I1_MAX, I1_MIN), -1); + ASSERTI1(i1_subtract(I1_MIN, I1_MAX), 1); + ASSERTI1(i1_subtract(I1_MIN, I1_MIN), 0); + ASSERTI1(i1_subtract(I1_MAX, 0), 127); } -TEST biopOri2i2_Main() +TEST i1_multiply_Main() { - extern i2 biopOri2i2(i2 lhs, i2 rhs); - ASSERTI2(biopOri2i2(2, 1), 3); - ASSERTI2(biopOri2i2(0x0101, 0x0101), 0x0101); - ASSERTI2(biopOri2i2(0x0101, 0x1010), 0x1111); - ASSERTI2(biopOri2i2(0x0101, 0x0), 0x0101); - ASSERTI2(biopOri2i2(I2_MAX, I2_MAX), 32767); - ASSERTI2(biopOri2i2(I2_MAX, I2_MIN), -1); - ASSERTI2(biopOri2i2(I2_MAX, 0), 32767); + extern i1 i1_multiply(i1 lhs, i1 rhs); + ASSERTI1(i1_multiply(2, 1), 2); + ASSERTI1(i1_multiply(I1_MAX, I1_MAX), 1); + ASSERTI1(i1_multiply(I1_MAX, I1_MIN), -128); + ASSERTI1(i1_multiply(I1_MAX, 0), 0); } -TEST biopLti2i2_Main() +TEST i1_divide_Main() { - extern i2 biopLti2i2(i2 lhs, i2 rhs); - ASSERTI2(biopLti2i2(2, 1), 0); - ASSERTI2(biopLti2i2(0x0101, 0x0101), 0); - ASSERTI2(biopLti2i2(0x0101, -0x0101), 0); - ASSERTI2(biopLti2i2(0x0101, -0x0101), 0); - ASSERTI2(biopLti2i2(I2_MAX, I2_MAX), 0); - ASSERTI2(biopLti2i2(I2_MAX, I2_MIN), 0); - ASSERTI2(biopLti2i2(I2_MAX, 0), 0); - ASSERTI2(biopLti2i2(0, I2_MAX), 1); + extern i1 i1_divide(i1 lhs, i1 rhs); + ASSERTI1(i1_divide(0x1, 0x1), 1); + ASSERTI1(i1_divide(I1_MAX, I1_MAX), 1); + ASSERTI1(i1_divide(I1_MIN, I1_MIN), 1); + ASSERTI1(i1_divide(I1_MAX, 1), I1_MAX); } -TEST biopMulti4i4_Main() +TEST i1_remainder_Main() { - extern i4 biopMulti4i4(i4 lhs, i4 rhs); - ASSERTI4(biopMulti4i4(2, 1), 2); - ASSERTI4(biopMulti4i4(0x01010101, 0x01010101), 67305985); - ASSERTI4(biopMulti4i4(0x01010101, -16843009), -67305985); - ASSERTI4(biopMulti4i4(0, -16843009), 0); - ASSERTI4(biopMulti4i4(I4_MAX, I4_MAX), 1); - ASSERTI4(biopMulti4i4(I4_MAX, I4_MIN), -2147483648); - ASSERTI4(biopMulti4i4(I4_MAX, 0), 0); + extern i1 i1_remainder(i1 lhs, i1 rhs); + ASSERTI1(i1_remainder(0x01, 0x01), 0); + ASSERTI1(i1_remainder(I1_MAX, I1_MAX), 0); + ASSERTI1(i1_remainder(I1_MIN, I1_MIN), 0); + ASSERTI1(i1_remainder(0, I1_MIN), 0); } MAIN BIOPS_main() { } diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS2.test b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS2.test index 66c04a2272..f7c575eb49 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS2.test +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS2.test @@ -1,662 +1,469 @@ #include "pcode_test.h" -TEST unopNotu2_Main() +TEST u2_complexLogic_Main() { - extern u2 unopNotu2(u2 lhs); - ASSERTU2(unopNotu2(2), 0); - ASSERTU2(unopNotu2(U2_MAX), 0); - ASSERTU2(unopNotu2(0), 1); + extern u2 u2_complexLogic(u2 a, u2 b, u2 c, u2 d, u2 e, u2 f); + ASSERTU2(u2_complexLogic(15941, 23971, 41361, 0, 43462, 0), 15); + ASSERTU2(u2_complexLogic(52937, 43562, 0, 0, 48661, 51969), 11); + ASSERTU2(u2_complexLogic(54831, 59630, 16661, 0, 0, 25991), 14); + ASSERTU2(u2_complexLogic(0, 49882, 61260, 0, 8407, 16234), 10); } -TEST biopSubu1u1_Main() +TEST i2_complexLogic_Main() { - extern u1 biopSubu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopSubu1u1(0x01, 0x01), 0); - ASSERTU1(biopSubu1u1(U1_MAX, U1_MAX), 0); - ASSERTU1(biopSubu1u1(U1_MAX, 0), U1_MAX); - ASSERTU1(biopSubu1u1(0, U1_MAX), 1); + extern i2 i2_complexLogic(i2 a, i2 b, i2 c, i2 d, i2 e, i2 f); + ASSERTI2(i2_complexLogic(0, 46379, (i2) -52108, 0, (i2) -54966, 53127), 11); + ASSERTI2(i2_complexLogic((i2) -5607, 26256, 23643, 0, (i2) -21648, 0), 14); + ASSERTI2(i2_complexLogic((i2) -19816, 41002, 63272, 0, 4483, 0), 15); + ASSERTI2(i2_complexLogic(0, (i2) -25128, 33393, 0, 61486, 53285), 11); } -TEST biopGeu1u1_Main() +TEST u2_compareLogic_Main() { - extern u1 biopGeu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopGeu1u1(0x01, 0x01), 1); - ASSERTU1(biopGeu1u1(U1_MAX, U1_MAX), 1); - ASSERTU1(biopGeu1u1(U1_MAX, 0), 1); - ASSERTU1(biopGeu1u1(0, U1_MAX), 0); + extern u2 u2_compareLogic(u2 lhs, u2 rhs); + ASSERTU2(u2_compareLogic(0x1, 0x1), 1); + ASSERTU2(u2_compareLogic(0x1, 0x2), 23); + ASSERTU2(u2_compareLogic(0x2, 0x1), 22); } -TEST biopShtRhtu4u4_Main() +TEST i2_compareLogic_Main() { - extern u4 biopShtRhtu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopShtRhtu4u4(0x01010101, 16), 0x0101); - ASSERTU4(biopShtRhtu4u4(2, 1), 1); - ASSERTU4(biopShtRhtu4u4(U4_MAX, 4), 268435455); - ASSERTU4(biopShtRhtu4u4(U4_MAX, 4*8-1), 1); - ASSERTU4(biopShtRhtu4u4(4, 4), 0); + extern i2 i2_compareLogic(i2 lhs, i2 rhs); + ASSERTI2(i2_compareLogic(0x1, 0x1), 21); + ASSERTI2(i2_compareLogic(0x1, 0x2), 21); + ASSERTI2(i2_compareLogic(0x2, 0x1), 22); + ASSERTI2(i2_compareLogic(-0x1, -0x1), 21); + ASSERTI2(i2_compareLogic(-0x1, -0x2), 21); + ASSERTI2(i2_compareLogic(-0x2, -0x1), 24); } -TEST biopXOri2i2_Main() +/* Comparison operators */ +TEST u2_greaterThan_Main() { - extern i2 biopXOri2i2(i2 lhs, i2 rhs); - ASSERTI2(biopXOri2i2(2, 1), 3); - ASSERTI2(biopXOri2i2(0x0101, 0x0101), 0); - ASSERTI2(biopXOri2i2(0x0101, 0x1010), 0x1111); - ASSERTI2(biopXOri2i2(I2_MAX, I2_MAX), 0); - ASSERTI2(biopXOri2i2(I2_MAX, I2_MIN), -1); - ASSERTI2(biopXOri2i2(I2_MAX, 0), 32767); - ASSERTI2(biopXOri2i2(I2_MAX, -1), -32768); + extern u2 u2_greaterThan(u2 lhs, u2 rhs); + ASSERTU2(u2_greaterThan(2, 1), 1); + ASSERTU2(u2_greaterThan(U2_MAX, U2_MAX), 0); + ASSERTU2(u2_greaterThan(U2_MAX, 0), 1); + ASSERTU2(u2_greaterThan(0, U2_MAX), 0); } -TEST biopLei2i2_Main() +TEST u2_greaterThanEquals_Main() { - extern i2 biopLei2i2(i2 lhs, i2 rhs); - ASSERTI2(biopLei2i2(2, 1), 0); - ASSERTI2(biopLei2i2(0x0101, 0x0101), 1); - ASSERTI2(biopLei2i2(0x0101, 0x0100), 0); - ASSERTI2(biopLei2i2(0x0101, -0x0101), 0); - ASSERTI2(biopLei2i2(I2_MAX, I2_MAX), 1); - ASSERTI2(biopLei2i2(I2_MAX, I2_MIN), 0); - ASSERTI2(biopLei2i2(I2_MIN, I2_MAX), 1); - ASSERTI2(biopLei2i2(I2_MAX, 0), 0); + extern u2 u2_greaterThanEquals(u2 lhs, u2 rhs); + ASSERTU2(u2_greaterThanEquals(2, 1), 1); + ASSERTU2(u2_greaterThanEquals(U2_MAX, U2_MAX), 1); + ASSERTU2(u2_greaterThanEquals(1, 1), 1); + ASSERTU2(u2_greaterThanEquals(1, 2), 0); } -TEST biopSubi4i4_Main() +TEST u2_lessThan_Main() { - extern i4 biopSubi4i4(i4 lhs, i4 rhs); - ASSERTI4(biopSubi4i4(2, 1), 1); - ASSERTI4(biopSubi4i4(0x01010101, 0x01010101), 0); - ASSERTI4(biopSubi4i4(0x01010101, 0x01000100), 0x00010001); - ASSERTI4(biopSubi4i4(0x01000100, 0x01010101), -0x00010001); - ASSERTI4(biopSubi4i4(I4_MAX, I4_MAX), 0); - ASSERTI4(biopSubi4i4(I4_MAX, I4_MIN), -1); - ASSERTI4(biopSubi4i4(I4_MAX, 0), 2147483647); - ASSERTI4(biopSubi4i4(0, I4_MAX), -2147483647); + extern u2 u2_lessThan(u2 lhs, u2 rhs); + ASSERTU2(u2_lessThan(2, 1), 0); + ASSERTU2(u2_lessThan(2, 1), 0); + ASSERTU2(u2_lessThan(U2_MAX, U2_MAX), 0); + ASSERTU2(u2_lessThan(0, 0), 0); + ASSERTU2(u2_lessThan(1, 2), 1); } -TEST biopAddu1u1_Main() +TEST u2_lessThanEquals_Main() { - extern u1 biopAddu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopAddu1u1(0x01, 0x01), 2); - ASSERTU1(biopAddu1u1(U1_MAX, U1_MAX), 254); - ASSERTU1(biopAddu1u1(U1_MAX, 0), 255); - ASSERTU1(biopAddu1u1(U1_MAX, 1), 0); + extern u2 u2_lessThanEquals(u2 lhs, u2 rhs); + ASSERTU2(u2_lessThanEquals(2, 1), 0); + ASSERTU2(u2_lessThanEquals(U2_MAX, U2_MAX), 1); + ASSERTU2(u2_lessThanEquals(U2_MIN, U2_MIN), 1); + ASSERTU2(u2_lessThanEquals(1, 2), 1); } -TEST biopLtu1u1_Main() +TEST u2_equals_Main() { - extern u1 biopLtu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopLtu1u1(0x01, 0x01), 0); - ASSERTU1(biopLtu1u1(U1_MAX, U1_MAX), 0); - ASSERTU1(biopLtu1u1(U1_MAX, 0), 0); + extern u2 u2_equals(u2 lhs, u2 rhs); + ASSERTU2(u2_equals(2, 1), 0); + ASSERTU2(u2_equals(U2_MAX, U2_MAX), 1); + ASSERTU2(u2_equals(U2_MIN, U2_MIN), 1); + ASSERTU2(u2_equals(0, 0), 1); } -TEST biopGtu4u4_Main() +TEST u2_notEquals_Main() { - extern u4 biopGtu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopGtu4u4(0x01010101, 0x01010101), 0); - ASSERTU4(biopGtu4u4(2, 1), 1); - ASSERTU4(biopGtu4u4(U4_MAX, U4_MAX), 0); - ASSERTU4(biopGtu4u4(U4_MAX, 0), 1); - ASSERTU4(biopGtu4u4(0, U4_MAX), 0); + extern u2 u2_notEquals(u2 lhs, u2 rhs); + ASSERTU2(u2_notEquals(2, 1), 1); + ASSERTU2(u2_notEquals(U2_MAX, U2_MAX), 0); + ASSERTU2(u2_notEquals(0, 0), 0); } -TEST biopLogicOri2i2_Main() +TEST i2_greaterThan_Main() { - extern i2 biopLogicOri2i2(i2 lhs, i2 rhs); - ASSERTI2(biopLogicOri2i2(0x0101, 0x0101), 1); - ASSERTI2(biopLogicOri2i2(2, 1), 1); - ASSERTI2(biopLogicOri2i2(I2_MAX, I2_MAX), 1); - ASSERTI2(biopLogicOri2i2(I2_MAX, I2_MIN), 1); - ASSERTI2(biopLogicOri2i2(I2_MAX, 0), 1); - ASSERTI2(biopLogicOri2i2(0, 0), 0); + extern i2 i2_greaterThan(i2 lhs, i2 rhs); + ASSERTI2(i2_greaterThan(0x0101, 0x0101), 0); + ASSERTI2(i2_greaterThan(0x0101, 0x0100), 1); + ASSERTI2(i2_greaterThan(0x0101, -0x0101), 1); + ASSERTI2(i2_greaterThan(2, 1), 1); + ASSERTI2(i2_greaterThan(I1_MAX, I1_MAX), 0); + ASSERTI2(i2_greaterThan(I1_MIN, I1_MIN), 0); + ASSERTI2(i2_greaterThan(I1_MAX-1, I1_MAX), 0); + ASSERTI2(i2_greaterThan(I1_MAX, I1_MAX-1), 1); } -TEST biopEqi2i2_Main() +TEST i2_greaterThanEquals_Main() { - extern i2 biopEqi2i2(i2 lhs, i2 rhs); - ASSERTI2(biopEqi2i2(2, 1), 0); - ASSERTI2(biopEqi2i2(0x0101, 0x0101), 1); - ASSERTI2(biopEqi2i2(0x0101, 0x0100), 0); - ASSERTI2(biopEqi2i2(0x0101, -0x0101), 0); - ASSERTI2(biopEqi2i2(I2_MAX, I2_MAX), 1); - ASSERTI2(biopEqi2i2(I2_MIN, I2_MIN), 1); - ASSERTI2(biopEqi2i2(I2_MAX-1, I2_MAX), 0); + extern i2 i2_greaterThanEquals(i2 lhs, i2 rhs); + ASSERTI2(i2_greaterThanEquals(2, 1), 1); + ASSERTI2(i2_greaterThanEquals(I2_MAX, I2_MAX), 1); + ASSERTI2(i2_greaterThanEquals(I2_MIN, I2_MIN), 1); + ASSERTI2(i2_greaterThanEquals(I2_MAX, I2_MIN), 1); + ASSERTI2(i2_greaterThanEquals(I2_MIN, I2_MAX), 0); } -TEST unopPlusu2_Main() +TEST i2_lessThan_Main() { - extern u2 unopPlusu2(u2 lhs); - ASSERTU2(unopPlusu2(2), 2); - ASSERTU2(unopPlusu2(U2_MAX), 65535); - ASSERTU2(unopPlusu2(0), 0); + extern i2 i2_lessThan(i2 lhs, i2 rhs); + ASSERTI2(i2_lessThan(2, 1), 0); + ASSERTI2(i2_lessThan(0x0101, 0x0101), 0); + ASSERTI2(i2_lessThan(0x0101, -0x0101), 0); + ASSERTI2(i2_lessThan(0x0101, -0x0101), 0); + ASSERTI2(i2_lessThan(I2_MAX, I2_MAX), 0); + ASSERTI2(i2_lessThan(I2_MAX, I2_MIN), 0); + ASSERTI2(i2_lessThan(I2_MAX, 0), 0); + ASSERTI2(i2_lessThan(0, I2_MAX), 1); } -TEST biopAddi4i4_Main() +TEST i2_lessThanEquals_Main() { - extern i4 biopAddi4i4(i4 lhs, i4 rhs); - ASSERTI4(biopAddi4i4(2, 1), 3); - ASSERTI4(biopAddi4i4(0x01010101, 0x01010101), 33686018); - ASSERTI4(biopAddi4i4(0x01010101, -0x01010101), 0); - ASSERTI4(biopAddi4i4(I4_MAX, I4_MAX), -2); - ASSERTI4(biopAddi4i4(I4_MAX, I4_MIN), -1); - ASSERTI4(biopAddi4i4(I4_MAX, 0), 2147483647); - ASSERTI4(biopAddi4i4(I4_MIN, I4_MIN), 0); + extern i2 i2_lessThanEquals(i2 lhs, i2 rhs); + ASSERTI2(i2_lessThanEquals(2, 1), 0); + ASSERTI2(i2_lessThanEquals(0x0101, 0x0101), 1); + ASSERTI2(i2_lessThanEquals(0x0101, 0x0100), 0); + ASSERTI2(i2_lessThanEquals(0x0101, -0x0101), 0); + ASSERTI2(i2_lessThanEquals(I2_MAX, I2_MAX), 1); + ASSERTI2(i2_lessThanEquals(I2_MAX, I2_MIN), 0); + ASSERTI2(i2_lessThanEquals(I2_MIN, I2_MAX), 1); + ASSERTI2(i2_lessThanEquals(I2_MAX, 0), 0); } -TEST biopGeu4u4_Main() +TEST i2_equals_Main() { - extern u4 biopGeu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopGeu4u4(2, 1), 1); - ASSERTU4(biopGeu4u4(U4_MAX, U4_MAX), 1); - ASSERTU4(biopGeu4u4(U4_MAX, 0), 1); - ASSERTU4(biopGeu4u4(0, U4_MAX), 0); + extern i2 i2_equals(i2 lhs, i2 rhs); + ASSERTI2(i2_equals(2, 1), 0); + ASSERTI2(i2_equals(0x0101, 0x0101), 1); + ASSERTI2(i2_equals(0x0101, 0x0100), 0); + ASSERTI2(i2_equals(0x0101, -0x0101), 0); + ASSERTI2(i2_equals(I2_MAX, I2_MAX), 1); + ASSERTI2(i2_equals(I2_MIN, I2_MIN), 1); + ASSERTI2(i2_equals(I2_MAX-1, I2_MAX), 0); } -TEST biopShtLftu1u1_Main() +TEST i2_notEquals_Main() { - extern u1 biopShtLftu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopShtLftu1u1(0x01, 2), 0x4); - ASSERTU1(biopShtLftu1u1(U1_MAX, 2), 252); - ASSERTU1(biopShtLftu1u1(U1_MAX, 8-1), 128); - ASSERTU1(biopShtLftu1u1(U1_MAX, 8), 0); - ASSERTU1(biopShtLftu1u1(2, 1), 0x4); + extern i2 i2_notEquals(i2 lhs, i2 rhs); + ASSERTI2(i2_notEquals(2, 1), 1); + ASSERTI2(i2_notEquals(0x0101, 0x0101), 0); + ASSERTI2(i2_notEquals(0x0101, 0x0100), 1); + ASSERTI2(i2_notEquals(0x0101, -0x0101), 1); + ASSERTI2(i2_notEquals(I2_MAX, I2_MAX), 0); + ASSERTI2(i2_notEquals(I2_MAX, I2_MIN), 1); + ASSERTI2(i2_notEquals(I2_MIN, I2_MAX), 1); } -TEST biopLeu1u1_Main() +/* Bitwise operators */ +TEST u2_bitwiseAnd_Main() { - extern u1 biopLeu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopLeu1u1(0x01, 0x01), 1); - ASSERTU1(biopLeu1u1(U1_MAX, U1_MAX), 1); - ASSERTU1(biopLeu1u1(0, 0), 1); - ASSERTU1(biopLeu1u1(U1_MAX, 0), 0); - ASSERTU1(biopLeu1u1(0, U1_MAX), 1); + extern u2 u2_bitwiseAnd(u2 lhs, u2 rhs); + ASSERTU2(u2_bitwiseAnd(2, 1), 0); + ASSERTU2(u2_bitwiseAnd(U2_MAX, U2_MAX), 65535); + ASSERTU2(u2_bitwiseAnd(U2_MIN, U2_MIN), 0); + ASSERTU2(u2_bitwiseAnd(0, U2_MAX), 0); + ASSERTU2(u2_bitwiseAnd(0, 0), 0); } -TEST biopLogicAndi2i2_Main() +TEST u2_bitwiseOr_Main() { - extern i2 biopLogicAndi2i2(i2 lhs, i2 rhs); - ASSERTI2(biopLogicAndi2i2(0x0101, 0x0101), 1); - ASSERTI2(biopLogicAndi2i2(2, 1), 1); - ASSERTI2(biopLogicAndi2i2(0x0101, 0x0101), 1); - ASSERTI2(biopLogicAndi2i2(0x0101, 0x0), 0); - ASSERTI2(biopLogicAndi2i2(I2_MAX, I2_MAX), 1); - ASSERTI2(biopLogicAndi2i2(I2_MIN, I2_MIN), 1); - ASSERTI2(biopLogicAndi2i2(I2_MAX, I2_MIN), 1); - ASSERTI2(biopLogicAndi2i2(I2_MAX, 0), 0); + extern u2 u2_bitwiseOr(u2 lhs, u2 rhs); + ASSERTU2(u2_bitwiseOr(2, 1), 3); + ASSERTU2(u2_bitwiseOr(U2_MAX, U2_MAX), 65535); + ASSERTU2(u2_bitwiseOr(U2_MAX, 0), 65535); + ASSERTU2(u2_bitwiseOr(U2_MAX, U2_MAX), 65535); } -TEST biopNei2i2_Main() +TEST u2_bitwiseXor_Main() { - extern i2 biopNei2i2(i2 lhs, i2 rhs); - ASSERTI2(biopNei2i2(2, 1), 1); - ASSERTI2(biopNei2i2(0x0101, 0x0101), 0); - ASSERTI2(biopNei2i2(0x0101, 0x0100), 1); - ASSERTI2(biopNei2i2(0x0101, -0x0101), 1); - ASSERTI2(biopNei2i2(I2_MAX, I2_MAX), 0); - ASSERTI2(biopNei2i2(I2_MAX, I2_MIN), 1); - ASSERTI2(biopNei2i2(I2_MIN, I2_MAX), 1); + extern u2 u2_bitwiseXor(u2 lhs, u2 rhs); + ASSERTU2(u2_bitwiseXor(2, 1), 3); + ASSERTU2(u2_bitwiseXor(U2_MAX, U2_MAX), 0); + ASSERTU2(u2_bitwiseXor(0, 0), 0); + ASSERTU2(u2_bitwiseXor(0, U2_MAX), 65535); } -TEST biopMulti1i1_Main() +TEST i2_bitwiseAnd_Main() { - extern i1 biopMulti1i1(i1 lhs, i1 rhs); - ASSERTI1(biopMulti1i1(2, 1), 2); - ASSERTI1(biopMulti1i1(I1_MAX, I1_MAX), 1); - ASSERTI1(biopMulti1i1(I1_MAX, I1_MIN), -128); - ASSERTI1(biopMulti1i1(I1_MAX, 0), 0); + extern i2 i2_bitwiseAnd(i2 lhs, i2 rhs); + ASSERTI2(i2_bitwiseAnd(2, 1), 0); + ASSERTI2(i2_bitwiseAnd(0x0101, 0x0101), 0x0101); + ASSERTI2(i2_bitwiseAnd(0x0101, 0x1010), 0x0); + ASSERTI2(i2_bitwiseAnd(I2_MAX, I2_MAX), 32767); + ASSERTI2(i2_bitwiseAnd(I2_MIN, I2_MIN), -32768); + ASSERTI2(i2_bitwiseAnd(I2_MAX, I2_MIN), 0); + ASSERTI2(i2_bitwiseAnd(I2_MAX, 0), 0x0); } -TEST biopShtLfti4i4_Main() +TEST i2_bitwiseOr_Main() { - extern i4 biopShtLfti4i4(i4 lhs, i4 rhs); - ASSERTI4(biopShtLfti4i4(2, 1), 4); - ASSERTI4(biopShtLfti4i4(0x01010101, 16), 0x01010000); - ASSERTI4(biopShtLfti4i4(0x01010101, 0), 0x01010101); - ASSERTI4(biopShtLfti4i4(I4_MAX, 2), -4); - ASSERTI4(biopShtLfti4i4(I4_MAX, 0), 2147483647); + extern i2 i2_bitwiseOr(i2 lhs, i2 rhs); + ASSERTI2(i2_bitwiseOr(2, 1), 3); + ASSERTI2(i2_bitwiseOr(0x0101, 0x0101), 0x0101); + ASSERTI2(i2_bitwiseOr(0x0101, 0x1010), 0x1111); + ASSERTI2(i2_bitwiseOr(0x0101, 0x0), 0x0101); + ASSERTI2(i2_bitwiseOr(I2_MAX, I2_MAX), 32767); + ASSERTI2(i2_bitwiseOr(I2_MAX, I2_MIN), -1); + ASSERTI2(i2_bitwiseOr(I2_MAX, 0), 32767); } -TEST biopLtu4u4_Main() +TEST i2_bitwiseXor_Main() { - extern u4 biopLtu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopLtu4u4(0x01010101, 0x01010101), 0); - ASSERTU4(biopLtu4u4(2, 1), 0); - ASSERTU4(biopLtu4u4(U4_MAX, U4_MAX), 0); - ASSERTU4(biopLtu4u4(U4_MAX, 0), 0); - ASSERTU4(biopLtu4u4(0, U4_MAX), 1); + extern i2 i2_bitwiseXor(i2 lhs, i2 rhs); + ASSERTI2(i2_bitwiseXor(2, 1), 3); + ASSERTI2(i2_bitwiseXor(0x0101, 0x0101), 0); + ASSERTI2(i2_bitwiseXor(0x0101, 0x1010), 0x1111); + ASSERTI2(i2_bitwiseXor(I2_MAX, I2_MAX), 0); + ASSERTI2(i2_bitwiseXor(I2_MAX, I2_MIN), -1); + ASSERTI2(i2_bitwiseXor(I2_MAX, 0), 32767); + ASSERTI2(i2_bitwiseXor(I2_MAX, -1), -32768); } -TEST biopShtRhtu1u1_Main() +/* Logical operators */ +TEST u2_logicalAnd_Main() { - extern u1 biopShtRhtu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopShtRhtu1u1(0x80, 2), 0x20); - ASSERTU1(biopShtRhtu1u1(U1_MAX, 2), 63); - ASSERTU1(biopShtRhtu1u1(U1_MAX, 8-1), 1); - ASSERTU1(biopShtRhtu1u1(U1_MAX, 8), 0); + extern u2 u2_logicalAnd(u2 lhs, u2 rhs); + ASSERTU2(u2_logicalAnd(2, 1), 1); + ASSERTU2(u2_logicalAnd(I2_MAX, I2_MAX), 1); + ASSERTU2(u2_logicalAnd(I2_MIN, I2_MIN), 1); + ASSERTU2(u2_logicalAnd(I2_MAX, I2_MIN), 1); + ASSERTU2(u2_logicalAnd(I2_MAX, 0), 0); } -TEST biopEqu1u1_Main() +TEST u2_logicalOr_Main() { - extern u1 biopEqu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopEqu1u1(0x01, 0x01), 1); - ASSERTU1(biopEqu1u1(U1_MAX, U1_MAX), 1); - ASSERTU1(biopEqu1u1(U1_MAX, 0), 0); - ASSERTU1(biopEqu1u1(0, U1_MAX), 0); + extern u2 u2_logicalOr(u2 lhs, u2 rhs); + ASSERTU2(u2_logicalOr(2, 1), 1); + ASSERTU2(u2_logicalOr(2, 1), 1); + ASSERTU2(u2_logicalOr(U2_MAX, U2_MAX), 1); + ASSERTU2(u2_logicalOr(U2_MIN, U2_MIN), 0); + ASSERTU2(u2_logicalOr(U2_MAX, U2_MIN), 1); + ASSERTU2(u2_logicalOr(U2_MAX, 0), 1); + ASSERTU2(u2_logicalOr(0, 0), 0); } -TEST unopNoti2_Main() +TEST u2_logicalNot_Main() { - extern i2 unopNoti2(i2 lhs); - ASSERTI2(unopNoti2(0x0101), 0); - ASSERTI2(unopNoti2(2), 0); - ASSERTI2(unopNoti2(I2_MAX), 0); - ASSERTI2(unopNoti2(I2_MIN), 0); - ASSERTI2(unopNoti2(0), 1); + extern u2 u2_logicalNot(u2 lhs); + ASSERTU2(u2_logicalNot(2), 0); + ASSERTU2(u2_logicalNot(U2_MAX), 0); + ASSERTU2(u2_logicalNot(0), 1); } -TEST biopAndi2i2_Main() +TEST i2_logicalAnd_Main() { - extern i2 biopAndi2i2(i2 lhs, i2 rhs); - ASSERTI2(biopAndi2i2(2, 1), 0); - ASSERTI2(biopAndi2i2(0x0101, 0x0101), 0x0101); - ASSERTI2(biopAndi2i2(0x0101, 0x1010), 0x0); - ASSERTI2(biopAndi2i2(I2_MAX, I2_MAX), 32767); - ASSERTI2(biopAndi2i2(I2_MIN, I2_MIN), -32768); - ASSERTI2(biopAndi2i2(I2_MAX, I2_MIN), 0); - ASSERTI2(biopAndi2i2(I2_MAX, 0), 0x0); + extern i2 i2_logicalAnd(i2 lhs, i2 rhs); + ASSERTI2(i2_logicalAnd(0x0101, 0x0101), 1); + ASSERTI2(i2_logicalAnd(2, 1), 1); + ASSERTI2(i2_logicalAnd(0x0101, 0x0101), 1); + ASSERTI2(i2_logicalAnd(0x0101, 0x0), 0); + ASSERTI2(i2_logicalAnd(I2_MAX, I2_MAX), 1); + ASSERTI2(i2_logicalAnd(I2_MIN, I2_MIN), 1); + ASSERTI2(i2_logicalAnd(I2_MAX, I2_MIN), 1); + ASSERTI2(i2_logicalAnd(I2_MAX, 0), 0); } -TEST biopSubi1i1_Main() +TEST i2_logicalOr_Main() { - extern i1 biopSubi1i1(i1 lhs, i1 rhs); - ASSERTI1(biopSubi1i1(2, 1), 1); - ASSERTI1(biopSubi1i1(I1_MAX, I1_MAX), 0); - ASSERTI1(biopSubi1i1(I1_MAX, I1_MIN), -1); - ASSERTI1(biopSubi1i1(I1_MIN, I1_MAX), 1); - ASSERTI1(biopSubi1i1(I1_MIN, I1_MIN), 0); - ASSERTI1(biopSubi1i1(I1_MAX, 0), 127); - -} - -TEST biopNeu1u1_Main() -{ - extern u1 biopNeu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopNeu1u1(0x01, 0x01), 0); - ASSERTU1(biopNeu1u1(U1_MAX, U1_MAX), 0); - ASSERTU1(biopNeu1u1(U1_MAX, 0), 1); - ASSERTU1(biopNeu1u1(0, U1_MAX), 1); -} - -TEST biopShtRhti4i4_Main() -{ - extern i4 biopShtRhti4i4(i4 lhs, i4 rhs); - ASSERTI4(biopShtRhti4i4(2, 1), 1); - ASSERTI4(biopShtRhti4i4(0x01010101, 16), 0x0101); - ASSERTI4(biopShtRhti4i4(0x01010101, 31), 0x0); - ASSERTI4(biopShtRhti4i4(0x01010101, 0), 0x01010101); - ASSERTI4(biopShtRhti4i4(I4_MAX, 2), 536870911); -} - -TEST biopLeu4u4_Main() -{ - extern u4 biopLeu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopLeu4u4(0x01010101, 0x01010101), 1); - ASSERTU4(biopLeu4u4(2, 1), 0); - ASSERTU4(biopLeu4u4(U4_MAX, U4_MAX), 1); - ASSERTU4(biopLeu4u4(U4_MAX, 0), 0); - ASSERTU4(biopLeu4u4(0, U4_MAX), 1); -} - -TEST unopNegativei2_Main() -{ - extern i2 unopNegativei2(i2 lhs); - ASSERTI2(unopNegativei2(0x0101), -0x0101); - ASSERTI2(unopNegativei2(-0x0101), 0x0101); - ASSERTI2(unopNegativei2(I2_MAX), -32767); - ASSERTI2(unopNegativei2(I2_MIN), I2_MIN); - ASSERTI2(unopNegativei2(0), 0); -} - -TEST biopGti4i4_Main() -{ - extern i4 biopGti4i4(i4 lhs, i4 rhs); - ASSERTI4(biopGti4i4(2, 1), 1); - ASSERTI4(biopGti4i4(0x01010101, 0x01010101), 0); - ASSERTI4(biopGti4i4(0x01000101, 0x01010101), 0); - ASSERTI4(biopGti4i4(0x01010101, -0x01010101), 1); - ASSERTI4(biopGti4i4(I4_MAX, I4_MAX), 0); - ASSERTI4(biopGti4i4(I4_MAX, I4_MIN), 1); - ASSERTI4(biopGti4i4(I4_MIN, I4_MAX), 0); -} - -TEST biopAddi1i1_Main() -{ - extern i1 biopAddi1i1(i1 lhs, i1 rhs); - ASSERTI1(biopAddi1i1(2, 1), 3); - ASSERTI1(biopAddi1i1(I1_MAX, I1_MAX), -2); - ASSERTI1(biopAddi1i1(I1_MAX, I1_MIN), -1); - ASSERTI1(biopAddi1i1(I1_MAX, 0), 127); -} - -TEST biopAndu1u1_Main() -{ - extern u1 biopAndu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopAndu1u1(0x01, 0x01), 0x01); - ASSERTU1(biopAndu1u1(U1_MAX, U1_MAX), 255); - ASSERTU1(biopAndu1u1(U1_MAX, 0), 0); - ASSERTU1(biopAndu1u1(U1_MAX, 1), 0x01); -} - -TEST biopEqu4u4_Main() -{ - extern u4 biopEqu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopEqu4u4(0x01010101, 0x01010101), 1); - ASSERTU4(biopEqu4u4(2, 1), 0); - ASSERTU4(biopEqu4u4(U4_MAX, U4_MAX), 1); - ASSERTU4(biopEqu4u4(U4_MAX, 0), 0); - ASSERTU4(biopEqu4u4(0, U4_MAX), 0); -} - -TEST unopPlusi2_Main() -{ - extern i2 unopPlusi2(i2 lhs); - ASSERTI2(unopPlusi2(0x0101), 0x0101); - ASSERTI2(unopPlusi2(-0x0101), -0x0101); - ASSERTI2(unopPlusi2(2), 2); - ASSERTI2(unopPlusi2(I2_MAX), 32767); - ASSERTI2(unopPlusi2(I2_MIN), -32768); - ASSERTI2(unopPlusi2(0), 0); -} - -TEST biopGei4i4_Main() -{ - extern i4 biopGei4i4(i4 lhs, i4 rhs); - ASSERTI4(biopGei4i4(2, 1), 1); - ASSERTI4(biopGei4i4(-2, 1), 0); - ASSERTI4(biopGei4i4(0x01010101, 0x01010100), 1); - ASSERTI4(biopGei4i4(I4_MAX, I4_MAX), 1); - ASSERTI4(biopGei4i4(I4_MAX, I4_MIN), 1); - ASSERTI4(biopGei4i4(I4_MIN, I4_MAX), 0); -} - -TEST biopShtLfti1i1_Main() -{ - extern i1 biopShtLfti1i1(i1 lhs, i1 rhs); - ASSERTI1(biopShtLfti1i1(2, 1), 4); - ASSERTI1(biopShtLfti1i1(I1_MAX, 2), -4); - ASSERTI1(biopShtLfti1i1(I1_MIN, 2), 0); - ASSERTI1(biopShtLfti1i1(I1_MAX, 0), 127); -} - -TEST biopOru1u1_Main() -{ - extern u1 biopOru1u1(u1 lhs, u1 rhs); - ASSERTU1(biopOru1u1(0x01, 0x01), 0x01); - ASSERTU1(biopOru1u1(U1_MAX, U1_MAX), U1_MAX); - ASSERTU1(biopOru1u1(U1_MAX, U1_MIN), 255); -} - -TEST biopNeu4u4_Main() -{ - extern u4 biopNeu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopNeu4u4(0x01010101, 0x01010101), 0); - ASSERTU4(biopNeu4u4(2, 1), 1); - ASSERTU4(biopNeu4u4(U4_MAX, U4_MAX), 0); - ASSERTU4(biopNeu4u4(U4_MAX, 0), 1); - ASSERTU4(biopNeu4u4(0, U4_MAX), 1); -} - -TEST biopMultu2u2_Main() -{ - extern u2 biopMultu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopMultu2u2(2, 1), 2); - ASSERTU2(biopMultu2u2(U2_MAX, U2_MAX), 1); - ASSERTU2(biopMultu2u2(U2_MAX, 0), 0); - ASSERTU2(biopMultu2u2(U2_MAX, 1), U2_MAX); -} - -TEST biopShtRhti1i1_Main() -{ - extern i1 biopShtRhti1i1(i1 lhs, i1 rhs); - ASSERTI1(biopShtRhti1i1(2, 1), 1); - ASSERTI1(biopShtRhti1i1(I1_MAX, 2), 31); - ASSERTI1(biopShtRhti1i1(16, 4), 1); -} - -TEST biopLti4i4_Main() -{ - extern i4 biopLti4i4(i4 lhs, i4 rhs); - ASSERTI4(biopLti4i4(2, 1), 0); - ASSERTI4(biopLti4i4(0x01010101, 0x01010101), 0); - ASSERTI4(biopLti4i4(0x01000101, 0x01010101), 1); - ASSERTI4(biopLti4i4(0x01010101, -0x01010101), 0); -} - -TEST biopAndu4u4_Main() -{ - extern u4 biopAndu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopAndu4u4(0x01010101, 0x01010101), 0x01010101); - ASSERTU4(biopAndu4u4(2, 1), 0); - ASSERTU4(biopAndu4u4(U4_MAX, U4_MAX), -1); - ASSERTU4(biopAndu4u4(U4_MAX, U4_MIN), 0); - ASSERTU4(biopAndu4u4(U4_MAX, 0), 0); -} - -TEST biopXOru1u1_Main() -{ - extern u1 biopXOru1u1(u1 lhs, u1 rhs); - ASSERTU1(biopXOru1u1(0x01, 0x01), 0); - ASSERTU1(biopXOru1u1(U1_MAX, U1_MAX), 0); - ASSERTU1(biopXOru1u1(U1_MAX, 0), 255); -} - -TEST biopSubu2u2_Main() -{ - extern u2 biopSubu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopSubu2u2(2, 1), 1); - ASSERTU2(biopSubu2u2(2, 1), 1); - ASSERTU2(biopSubu2u2(U2_MAX, U2_MAX), 0); - ASSERTU2(biopSubu2u2(U2_MAX, 0), U2_MAX); - ASSERTU2(biopSubu2u2(0, U2_MAX), 1); -} - -TEST biopGti1i1_Main() -{ - extern i1 biopGti1i1(i1 lhs, i1 rhs); - ASSERTI1(biopGti1i1(2, 1), 1); - ASSERTI1(biopGti1i1(I1_MAX, I1_MAX), 0); - ASSERTI1(biopGti1i1(I1_MAX, I1_MIN), 1); - ASSERTI1(biopGti1i1(I1_MIN, I1_MAX), 0); -} - -TEST biopLei4i4_Main() -{ - extern i4 biopLei4i4(i4 lhs, i4 rhs); - ASSERTI4(biopLei4i4(2, 1), 0); - ASSERTI4(biopLei4i4(0x01010101, 0x01010101), 1); - ASSERTI4(biopLei4i4(0x01000101, 0x01010101), 1); - ASSERTI4(biopLei4i4(0x01010101, -0x01010101), 0); - ASSERTI4(biopLei4i4(I4_MAX, I4_MAX), 1); - ASSERTI4(biopLei4i4(I4_MAX, I4_MIN), 0); - ASSERTI4(biopLei4i4(I4_MIN, I4_MAX), 1); -} - -TEST biopOru4u4_Main() -{ - extern u4 biopOru4u4(u4 lhs, u4 rhs); - ASSERTU4(biopOru4u4(0x01010101, 0x01010101), 0x01010101); - ASSERTU4(biopOru4u4(2, 1), 3); - ASSERTU4(biopOru4u4(U4_MAX, U4_MAX), U4_MAX); - ASSERTU4(biopOru4u4(U4_MAX, 0), U4_MAX); -} - -TEST biopLogicOru1u1_Main() -{ - extern u1 biopLogicOru1u1(u1 lhs, u1 rhs); - ASSERTU1(biopLogicOru1u1(0x01, 0x01), 1); - ASSERTU1(biopLogicOru1u1(U1_MAX, U1_MAX), 1); - ASSERTU1(biopLogicOru1u1(U1_MAX, 0), 1); + extern i2 i2_logicalOr(i2 lhs, i2 rhs); + ASSERTI2(i2_logicalOr(0x0101, 0x0101), 1); + ASSERTI2(i2_logicalOr(2, 1), 1); + ASSERTI2(i2_logicalOr(I2_MAX, I2_MAX), 1); + ASSERTI2(i2_logicalOr(I2_MAX, I2_MIN), 1); + ASSERTI2(i2_logicalOr(I2_MAX, 0), 1); + ASSERTI2(i2_logicalOr(0, 0), 0); } -TEST biopAddu2u2_Main() +TEST i2_logicalNot_Main() { - extern u2 biopAddu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopAddu2u2(2, 1), 3); - ASSERTU2(biopAddu2u2(U2_MAX, U2_MAX), 65534); - ASSERTU2(biopAddu2u2(U2_MAX, 0), U2_MAX); + extern i2 i2_logicalNot(i2 lhs); + ASSERTI2(i2_logicalNot(0x0101), 0); + ASSERTI2(i2_logicalNot(2), 0); + ASSERTI2(i2_logicalNot(I2_MAX), 0); + ASSERTI2(i2_logicalNot(I2_MIN), 0); + ASSERTI2(i2_logicalNot(0), 1); } -TEST biopGei1i1_Main() +/* Shift operators */ +TEST u2_shiftLeft_Main() { - extern i1 biopGei1i1(i1 lhs, i1 rhs); - ASSERTI1(biopGei1i1(2, 1), 1); - ASSERTI1(biopGei1i1(I1_MAX, I1_MAX), 1); - ASSERTI1(biopGei1i1(I1_MAX, I1_MIN), 1); - ASSERTI1(biopGei1i1(I1_MIN, I1_MAX), 0); + extern u2 u2_shiftLeft(u2 lhs, u2 rhs); + ASSERTU2(u2_shiftLeft(2, 1), 4); + ASSERTU2(u2_shiftLeft(2, 1), 4); + ASSERTU2(u2_shiftLeft(U2_MAX, 2), 65532); + ASSERTU2(u2_shiftLeft(U2_MAX, 0), 65535); } -TEST biopLogicAndu1u1_Main() +TEST u2_shiftRight_Main() { - extern u1 biopLogicAndu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopLogicAndu1u1(0x01, 0x01), 1); - ASSERTU1(biopLogicAndu1u1(U1_MAX, U1_MAX), 1); - ASSERTU1(biopLogicAndu1u1(U1_MAX, 0), 0); - ASSERTU1(biopLogicAndu1u1(U1_MAX, 1), 1); + extern u2 u2_shiftRight(u2 lhs, u2 rhs); + ASSERTU2(u2_shiftRight(2, 1), 1); + ASSERTU2(u2_shiftRight(U2_MAX, 2), 16383); + ASSERTU2(u2_shiftRight(U2_MAX, 0), 65535); } -TEST biopEqi4i4_Main() +TEST i2_shiftLeft_Main() { - extern i4 biopEqi4i4(i4 lhs, i4 rhs); - ASSERTI4(biopEqi4i4(0x01010101, -0x01010101), 0); - ASSERTI4(biopEqi4i4(2, 1), 0); - ASSERTI4(biopEqi4i4(0x01010101, 0x01010101), 1); - ASSERTI4(biopEqi4i4(0x01000101, 0x01010101), 0); - ASSERTI4(biopEqi4i4(I4_MAX, I4_MAX), 1); - ASSERTI4(biopEqi4i4(I4_MAX, I4_MIN), 0); - ASSERTI4(biopEqi4i4(I4_MIN, I4_MAX), 0); + extern i2 i2_shiftLeft(i2 lhs, i2 rhs); + ASSERTI2(i2_shiftLeft(0x0101, 15), 0x8000); + ASSERTI2(i2_shiftLeft(0x0101, 8), 0x100); + ASSERTI2(i2_shiftLeft(0x0101, 0), 0x101); + ASSERTI2(i2_shiftLeft(2, 1), 4); + ASSERTI2(i2_shiftLeft(I2_MAX, 4), -16); + ASSERTI2(i2_shiftLeft(I2_MIN, 4), 0); + ASSERTI2(i2_shiftLeft(0, 4), 0); } -TEST biopXOru4u4_Main() +TEST i2_shiftRight_Main() { - extern u4 biopXOru4u4(u4 lhs, u4 rhs); - ASSERTU4(biopXOru4u4(0x01010101, 0x01010101), 0); - ASSERTU4(biopXOru4u4(2, 1), 3); - ASSERTU4(biopXOru4u4(U4_MAX, U4_MAX), 0); - ASSERTU4(biopXOru4u4(U4_MAX, U4_MIN), -1); - ASSERTU4(biopXOru4u4(U4_MAX, 0), -1); + extern i2 i2_shiftRight(i2 lhs, i2 rhs); + ASSERTI2(i2_shiftRight(0x7fff, 15), 0x0000); + ASSERTI2(i2_shiftRight(0x0101, 8), 0x1); + ASSERTI2(i2_shiftRight(0x0101, 0), 0x0101); + ASSERTI2(i2_shiftRight(2, 1), 1); + ASSERTI2(i2_shiftRight(I2_MAX, 4), 2047); + ASSERTI2(i2_shiftRight(I2_MAX, 0), 32767); + ASSERTI2(i2_shiftRight(I2_MIN, 4), -2048); + ASSERTI2(i2_shiftRight(I2_MIN, 0), -32768); } -TEST biopShtLftu2u2_Main() +/* Arithmetic operators */ +TEST u2_unaryPlus_Main() { - extern u2 biopShtLftu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopShtLftu2u2(2, 1), 4); - ASSERTU2(biopShtLftu2u2(2, 1), 4); - ASSERTU2(biopShtLftu2u2(U2_MAX, 2), 65532); - ASSERTU2(biopShtLftu2u2(U2_MAX, 0), 65535); + extern u2 u2_unaryPlus(u2 lhs); + ASSERTU2(u2_unaryPlus(2), 2); + ASSERTU2(u2_unaryPlus(U2_MAX), 65535); + ASSERTU2(u2_unaryPlus(0), 0); } -TEST biopNei4i4_Main() +TEST u2_addition_Main() { - extern i4 biopNei4i4(i4 lhs, i4 rhs); - ASSERTI4(biopNei4i4(0x01010101, 0x01010101), 0); - ASSERTI4(biopNei4i4(0x01000101, 0x01010101), 1); - ASSERTI4(biopNei4i4(0x01000101, -0x01010101), 1); - ASSERTI4(biopNei4i4(2, 1), 1); - ASSERTI4(biopNei4i4(I4_MAX, I4_MAX), 0); - ASSERTI4(biopNei4i4(I4_MAX, I4_MIN), 1); - ASSERTI4(biopNei4i4(I4_MIN, I4_MAX), 1); + extern u2 u2_addition(u2 lhs, u2 rhs); + ASSERTU2(u2_addition(2, 1), 3); + ASSERTU2(u2_addition(U2_MAX, U2_MAX), 65534); + ASSERTU2(u2_addition(U2_MAX, 0), U2_MAX); } -TEST biopLti1i1_Main() +TEST u2_subtract_Main() { - extern i1 biopLti1i1(i1 lhs, i1 rhs); - ASSERTI1(biopLti1i1(2, 1), 0); - ASSERTI1(biopLti1i1(I1_MAX, I1_MAX), 0); - ASSERTI1(biopLti1i1(I1_MAX, I1_MIN), 0); - ASSERTI1(biopLti1i1(I1_MIN, I1_MAX), 1); + extern u2 u2_subtract(u2 lhs, u2 rhs); + ASSERTU2(u2_subtract(2, 1), 1); + ASSERTU2(u2_subtract(2, 1), 1); + ASSERTU2(u2_subtract(U2_MAX, U2_MAX), 0); + ASSERTU2(u2_subtract(U2_MAX, 0), U2_MAX); + ASSERTU2(u2_subtract(0, U2_MAX), 1); } -TEST unopNotu1_Main() +TEST u2_multiply_Main() { - extern u1 unopNotu1(u1 lhs); - ASSERTU1(unopNotu1(0x01), 0); - ASSERTU1(unopNotu1(U1_MAX), 0); - ASSERTU1(unopNotu1(0), 1); + extern u2 u2_multiply(u2 lhs, u2 rhs); + ASSERTU2(u2_multiply(2, 1), 2); + ASSERTU2(u2_multiply(U2_MAX, U2_MAX), 1); + ASSERTU2(u2_multiply(U2_MAX, 0), 0); + ASSERTU2(u2_multiply(U2_MAX, 1), U2_MAX); } -TEST biopLogicOru4u4_Main() +TEST u2_divide_Main() { - extern u4 biopLogicOru4u4(u4 lhs, u4 rhs); - ASSERTU4(biopLogicOru4u4(0x01010101, 0x01010101), 1); - ASSERTU4(biopLogicOru4u4(2, 1), 1); - ASSERTU4(biopLogicOru4u4(U4_MAX, U4_MAX), 1); - ASSERTU4(biopLogicOru4u4(U4_MAX, U4_MIN), 1); + extern i2 u2_divide(i2 lhs, i2 rhs); + ASSERTI2(u2_divide(0x0101, 0x0101), 0x1); + ASSERTI2(u2_divide(U2_MAX, U2_MAX), 0x1); } -TEST biopShtRhtu2u2_Main() +TEST u2_remainder_Main() { - extern u2 biopShtRhtu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopShtRhtu2u2(2, 1), 1); - ASSERTU2(biopShtRhtu2u2(U2_MAX, 2), 16383); - ASSERTU2(biopShtRhtu2u2(U2_MAX, 0), 65535); + extern u2 u2_remainder(u2 lhs, u2 rhs); + ASSERTU2(u2_remainder(0x0101, 0x0101), 0x0); + ASSERTU2(u2_remainder(U2_MAX, 1), 0x0); + ASSERTU2(u2_remainder(U2_MAX, 2), 1); + ASSERTU2(u2_remainder(U2_MAX, U2_MAX), 0x0); } -TEST biopDividu1u1_Main() +TEST i2_unaryMinus_Main() { - extern i1 biopDividu1u1(u1 lhs, u1 rhs); - ASSERTI1(biopDividu1u1(0x01, 0x01), 1); - ASSERTI1(biopDividu1u1(U1_MAX, U1_MAX), 1); - ASSERTI1(biopDividu1u1(U1_MAX, 1), U1_MAX); + extern i2 i2_unaryMinus(i2 lhs); + ASSERTI2(i2_unaryMinus(0x0101), -0x0101); + ASSERTI2(i2_unaryMinus(-0x0101), 0x0101); + ASSERTI2(i2_unaryMinus(I2_MAX), -32767); + ASSERTI2(i2_unaryMinus(I2_MIN), I2_MIN); + ASSERTI2(i2_unaryMinus(0), 0); } -TEST biopDividu2u2_Main() +TEST i2_unaryPlus_Main() { - extern i2 biopDividu2u2(i2 lhs, i2 rhs); - ASSERTI2(biopDividu2u2(0x0101, 0x0101), 0x1); - ASSERTI2(biopDividu2u2(U2_MAX, U2_MAX), 0x1); + extern i2 i2_unaryPlus(i2 lhs); + ASSERTI2(i2_unaryPlus(0x0101), 0x0101); + ASSERTI2(i2_unaryPlus(-0x0101), -0x0101); + ASSERTI2(i2_unaryPlus(2), 2); + ASSERTI2(i2_unaryPlus(I2_MAX), 32767); + ASSERTI2(i2_unaryPlus(I2_MIN), -32768); + ASSERTI2(i2_unaryPlus(0), 0); } -TEST biopDividu4u4_Main() +TEST i2_addition_Main() { - extern u4 biopDividu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopDividu4u4(0x01010101, 0x01010101), 1); - ASSERTU4(biopDividu4u4(-0x01010101, 0x01010101), 254); - ASSERTU4(biopDividu4u4(0, 0x01010101), 0); - ASSERTU4(biopDividu4u4(0x01010101, 2), 0x808080); - ASSERTU4(biopDividu4u4(U4_MAX, U4_MAX), 1); - ASSERTU4(biopDividu4u4(U4_MAX, 1), U4_MAX); + extern i2 i2_addition(i2 lhs, i2 rhs); + ASSERTI2(i2_addition(0x0101, 0x0101), 514); + ASSERTI2(i2_addition(0x0101, -0x0101), 0); + ASSERTI2(i2_addition(2, 1), 3); + ASSERTI2(i2_addition(I2_MAX, I2_MAX), -2); + ASSERTI2(i2_addition(I2_MIN, I2_MIN), 0); + ASSERTI2(i2_addition(0, 0), 0); } -TEST biopRemainderu1u1_Main() +TEST i2_subtract_Main() { - extern u1 biopRemainderu1u1(u1 lhs, u1 rhs); - ASSERTU1(biopRemainderu1u1(0x01, 0x01), 0); - ASSERTU1(biopRemainderu1u1(U1_MAX, U1_MAX), 0); - ASSERTU1(biopRemainderu1u1(0, I1_MIN), 0); + extern i2 i2_subtract(i2 lhs, i2 rhs); + ASSERTI2(i2_subtract(0x0101, 0x0100), 0x1); + ASSERTI2(i2_subtract(0x0100, 0x0101), -0x1); + ASSERTI2(i2_subtract(0x0101, 0x0101), 0); + ASSERTI2(i2_subtract(2, 1), 1); + ASSERTI2(i2_subtract(I2_MAX, I2_MAX), 0); + ASSERTI2(i2_subtract(I2_MIN, I2_MIN), 0); + ASSERTI2(i2_subtract(I2_MAX, 0), I2_MAX); + ASSERTI2(i2_subtract(0, 0), 0); } -TEST biopRemainderu2u2_Main() +TEST i2_multiply_Main() { - extern u2 biopRemainderu2u2(u2 lhs, u2 rhs); - ASSERTU2(biopRemainderu2u2(0x0101, 0x0101), 0x0); - ASSERTU2(biopRemainderu2u2(U2_MAX, 1), 0x0); - ASSERTU2(biopRemainderu2u2(U2_MAX, 2), 1); - ASSERTU2(biopRemainderu2u2(U2_MAX, U2_MAX), 0x0); + extern i2 i2_multiply(i2 lhs, i2 rhs); + ASSERTI2(i2_multiply(0x0101, 0x0101), 0x201); + ASSERTI2(i2_multiply(0x0101, -0x0101), -513); + ASSERTI2(i2_multiply(0, -0x0101), 0); + ASSERTI2(i2_multiply(2, 1), 2); + ASSERTI2(i2_multiply(I2_MAX, I2_MAX), 1); + ASSERTI2(i2_multiply(I2_MIN, I2_MIN), 0); + ASSERTI2(i2_multiply(1, I2_MIN), I2_MIN); + ASSERTI2(i2_multiply(-1, I2_MIN), -I2_MIN); } -TEST biopRemainderu4u4_Main() +TEST i2_divide_Main() { - extern u4 biopRemainderu4u4(u4 lhs, u4 rhs); - ASSERTU4(biopRemainderu4u4(0x01010101, 0x01010101), 0); - ASSERTU4(biopRemainderu4u4(U4_MAX, U4_MAX), 0); - ASSERTU4(biopRemainderu4u4(I4_MIN, I4_MIN), 0); - ASSERTU4(biopRemainderu4u4(~1000, ~10), 4294966295); - ASSERTU4(biopRemainderu4u4(0, U4_MAX), 0); + extern i2 i2_divide(i2 lhs, i2 rhs); + ASSERTI2(i2_divide(0x0101, 0x0101), 0x1); + ASSERTI2(i2_divide(I2_MAX, I2_MAX), 0x1); + ASSERTI2(i2_divide(I2_MIN, I2_MIN), 0x1); } -MAIN BIOPS2_main() +TEST i2_remainder_Main() { + extern i2 i2_remainder(i2 lhs, i2 rhs); + ASSERTI2(i2_remainder(0x0101, 0x0101), 0x0); + ASSERTI2(i2_remainder(I2_MAX, I2_MAX), 0x0); + ASSERTI2(i2_remainder(I2_MIN, I2_MIN), 0x0); + ASSERTI2(i2_remainder(0, I2_MIN), 0x0); } +MAIN BIOPS2_main(){ } diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS2_BODY.c b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS2_BODY.c index f994cb2ae0..c2b62d81e0 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS2_BODY.c +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS2_BODY.c @@ -15,47 +15,144 @@ */ #include "pcode_test.h" -u2 unopNotu2(u2 lhs) +u2 u2_complexLogic(u2 a, u2 b, u2 c, u2 d, u2 e, u2 f) +{ + u2 ret = 0; + + if (a > b && b > c || d < e && f < e) { + ret += 1; + } + if (a != b || a != c && d != e || f != e) { + ret += 2; + } + if (a && b && c || d && e && f) { + ret += 4; + } + if (a || b || c && d || e || f) { + ret += 8; + } + return ret; +} + +i2 i2_complexLogic(i2 a, i2 b, i2 c, i2 d, i2 e, i2 f) +{ + i2 ret = 0; + + if (a > b && b > c || d < e && f < e) { + ret += 1; + } + if (a != b || a != c && d != e || f != e) { + ret += 2; + } + if (a && b && c || d && e && f) { + ret += 4; + } + if (a || b || c && d || e || f) { + ret += 8; + } + return ret; +} + +u2 u2_compareLogic(u2 lhs, u2 rhs) +{ + if (lhs < rhs) + lhs += 2; + if (lhs > rhs) + lhs += 4; + if (lhs == 0) + lhs += 8; + if (lhs != rhs) + lhs += 16; + return lhs; +} + +i2 i2_compareLogic(i2 lhs, i2 rhs) +{ + if (lhs < 0) + lhs += 2; + if (lhs > 0) + lhs += 4; + if (lhs == 0) + lhs += 8; + if (lhs != rhs) + lhs += 16; + return lhs; +} + +/* Comparison operators */ +u2 u2_greaterThan(u2 lhs, u2 rhs) { u2 z; - z = !lhs; + z = lhs > rhs; return z; } -u1 biopSubu1u1(u1 lhs, u1 rhs) +u2 u2_greaterThanEquals(u2 lhs, u2 rhs) { - u1 z; - - z = lhs - rhs; - return z; -} - -u1 biopGeu1u1(u1 lhs, u1 rhs) -{ - u1 z; + u2 z; z = lhs >= rhs; return z; } -u4 biopShtRhtu4u4(u4 lhs, u4 rhs) +u2 u2_lessThan(u2 lhs, u2 rhs) { - u4 z; + u2 z; - z = lhs >> rhs; + z = lhs < rhs; return z; } -i2 biopXOri2i2(i2 lhs, i2 rhs) +u2 u2_lessThanEquals(u2 lhs, u2 rhs) +{ + u2 z; + + z = lhs <= rhs; + return z; +} + +u2 u2_equals(u2 lhs, u2 rhs) +{ + u2 z; + + z = lhs == rhs; + return z; +} + +u2 u2_notEquals(u2 lhs, u2 rhs) +{ + u2 z; + + z = lhs != rhs; + return z; +} + +i2 i2_greaterThan(i2 lhs, i2 rhs) { i2 z; - z = lhs ^ rhs; + z = lhs > rhs; return z; } -i2 biopLei2i2(i2 lhs, i2 rhs) +i2 i2_greaterThanEquals(i2 lhs, i2 rhs) +{ + i2 z; + + z = lhs >= rhs; + return z; +} + +i2 i2_lessThan(i2 lhs, i2 rhs) +{ + i2 z; + + z = lhs < rhs; + return z; +} + +i2 i2_lessThanEquals(i2 lhs, i2 rhs) { i2 z; @@ -63,47 +160,7 @@ i2 biopLei2i2(i2 lhs, i2 rhs) return z; } -i4 biopSubi4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs - rhs; - return z; -} - -u1 biopAddu1u1(u1 lhs, u1 rhs) -{ - u1 z; - - z = lhs + rhs; - return z; -} - -u1 biopLtu1u1(u1 lhs, u1 rhs) -{ - u1 z; - - z = lhs < rhs; - return z; -} - -u4 biopGtu4u4(u4 lhs, u4 rhs) -{ - u4 z; - - z = lhs > rhs; - return z; -} - -i2 biopLogicOri2i2(i2 lhs, i2 rhs) -{ - i2 z; - - z = lhs || rhs; - return z; -} - -i2 biopEqi2i2(i2 lhs, i2 rhs) +i2 i2_equals(i2 lhs, i2 rhs) { i2 z; @@ -111,55 +168,7 @@ i2 biopEqi2i2(i2 lhs, i2 rhs) return z; } -u2 unopPlusu2(u2 lhs) -{ - u2 z; - - z = +lhs; - return z; -} - -i4 biopAddi4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs + rhs; - return z; -} - -u4 biopGeu4u4(u4 lhs, u4 rhs) -{ - u4 z; - - z = lhs >= rhs; - return z; -} - -u1 biopShtLftu1u1(u1 lhs, u1 rhs) -{ - u1 z; - - z = lhs << rhs; - return z; -} - -u1 biopLeu1u1(u1 lhs, u1 rhs) -{ - u1 z; - - z = lhs <= rhs; - return z; -} - -i2 biopLogicAndi2i2(i2 lhs, i2 rhs) -{ - i2 z; - - z = lhs && rhs; - return z; -} - -i2 biopNei2i2(i2 lhs, i2 rhs) +i2 i2_notEquals(i2 lhs, i2 rhs) { i2 z; @@ -167,55 +176,32 @@ i2 biopNei2i2(i2 lhs, i2 rhs) return z; } -i1 biopMulti1i1(i1 lhs, i1 rhs) +/* Bitwise operators */ +u2 u2_bitwiseAnd(u2 lhs, u2 rhs) { - i1 z; + u2 z; - z = lhs * rhs; + z = lhs & rhs; return z; } -i4 biopShtLfti4i4(i4 lhs, i4 rhs) +u2 u2_bitwiseOr(u2 lhs, u2 rhs) { - i4 z; + u2 z; - z = lhs << rhs; + z = lhs | rhs; return z; } -u4 biopLtu4u4(u4 lhs, u4 rhs) +u2 u2_bitwiseXor(u2 lhs, u2 rhs) { - u4 z; + u2 z; - z = lhs < rhs; + z = lhs ^ rhs; return z; } -u1 biopShtRhtu1u1(u1 lhs, u1 rhs) -{ - u1 z; - - z = lhs >> rhs; - return z; -} - -u1 biopEqu1u1(u1 lhs, u1 rhs) -{ - u1 z; - - z = lhs == rhs; - return z; -} - -i2 unopNoti2(i2 lhs) -{ - i2 z; - - z = !lhs; - return z; -} - -i2 biopAndi2i2(i2 lhs, i2 rhs) +i2 i2_bitwiseAnd(i2 lhs, i2 rhs) { i2 z; @@ -223,39 +209,154 @@ i2 biopAndi2i2(i2 lhs, i2 rhs) return z; } -i1 biopSubi1i1(i1 lhs, i1 rhs) +i2 i2_bitwiseOr(i2 lhs, i2 rhs) { - i1 z; + i2 z; - z = lhs - rhs; + z = lhs | rhs; return z; } -u1 biopNeu1u1(u1 lhs, u1 rhs) +i2 i2_bitwiseXor(i2 lhs, i2 rhs) { - u1 z; + i2 z; - z = lhs != rhs; + z = lhs ^ rhs; return z; } -i4 biopShtRhti4i4(i4 lhs, i4 rhs) +/* Logical operators */ +u2 u2_logicalAnd(u2 lhs, u2 rhs) { - i4 z; + u2 z; + + z = lhs && rhs; + return z; +} + +u2 u2_logicalOr(u2 lhs, u2 rhs) +{ + u2 z; + + z = lhs || rhs; + return z; +} + +u2 u2_logicalNot(u2 lhs) +{ + u2 z; + + z = !lhs; + return z; +} + +i2 i2_logicalAnd(i2 lhs, i2 rhs) +{ + i2 z; + + z = lhs && rhs; + return z; +} + +i2 i2_logicalOr(i2 lhs, i2 rhs) +{ + i2 z; + + z = lhs || rhs; + return z; +} + +i2 i2_logicalNot(i2 lhs) +{ + i2 z; + + z = !lhs; + return z; +} + +/* Shift operators */ +u2 u2_shiftLeft(u2 lhs, u2 rhs) +{ + u2 z; + + z = lhs << rhs; + return z; +} + +u2 u2_shiftRight(u2 lhs, u2 rhs) +{ + u2 z; z = lhs >> rhs; return z; } -u4 biopLeu4u4(u4 lhs, u4 rhs) +i2 i2_shiftRight(i2 lhs, i2 rhs) { - u4 z; + i2 z; - z = lhs <= rhs; + z = lhs >> rhs; return z; } -i2 unopNegativei2(i2 lhs) +i2 i2_shiftLeft(i2 lhs, i2 rhs) +{ + i2 z; + + z = lhs << rhs; + return z; +} + +/* Arithmetic operators */ +u2 u2_unaryPlus(u2 lhs) +{ + u2 z; + + z = +lhs; + return z; +} + +u2 u2_addition(u2 lhs, u2 rhs) +{ + u2 z; + + z = lhs + rhs; + return z; +} + +u2 u2_subtract(u2 lhs, u2 rhs) +{ + u2 z; + + z = lhs - rhs; + return z; +} + +u2 u2_multiply(u2 lhs, u2 rhs) +{ + u2 z; + + z = lhs * rhs; + return z; +} + +i2 u2_divide(i2 lhs, i2 rhs) +{ + i2 z; + + z = lhs / rhs; + return z; +} + +u2 u2_remainder(u2 lhs, u2 rhs) +{ + u2 z; + + z = lhs % rhs; + return z; +} + +i2 i2_unaryMinus(i2 lhs) { i2 z; @@ -263,39 +364,7 @@ i2 unopNegativei2(i2 lhs) return z; } -i4 biopGti4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs > rhs; - return z; -} - -i1 biopAddi1i1(i1 lhs, i1 rhs) -{ - i1 z; - - z = lhs + rhs; - return z; -} - -u1 biopAndu1u1(u1 lhs, u1 rhs) -{ - u1 z; - - z = lhs & rhs; - return z; -} - -u4 biopEqu4u4(u4 lhs, u4 rhs) -{ - u4 z; - - z = lhs == rhs; - return z; -} - -i2 unopPlusi2(i2 lhs) +i2 i2_unaryPlus(i2 lhs) { i2 z; @@ -303,215 +372,31 @@ i2 unopPlusi2(i2 lhs) return z; } -i4 biopGei4i4(i4 lhs, i4 rhs) +i2 i2_addition(i2 lhs, i2 rhs) { - i4 z; - - z = lhs >= rhs; - return z; -} - -i1 biopShtLfti1i1(i1 lhs, i1 rhs) -{ - i1 z; - - z = lhs << rhs; - return z; -} - -u1 biopOru1u1(u1 lhs, u1 rhs) -{ - u1 z; - - z = lhs | rhs; - return z; -} - -u4 biopNeu4u4(u4 lhs, u4 rhs) -{ - u4 z; - - z = lhs != rhs; - return z; -} - -u2 biopMultu2u2(u2 lhs, u2 rhs) -{ - u2 z; - - z = lhs * rhs; - return z; -} - -i1 biopShtRhti1i1(i1 lhs, i1 rhs) -{ - i1 z; - - z = lhs >> rhs; - return z; -} - -i4 biopLti4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs < rhs; - return z; -} - -u4 biopAndu4u4(u4 lhs, u4 rhs) -{ - u4 z; - - z = lhs & rhs; - return z; -} - -u1 biopXOru1u1(u1 lhs, u1 rhs) -{ - u1 z; - - z = lhs ^ rhs; - return z; -} - -u2 biopSubu2u2(u2 lhs, u2 rhs) -{ - u2 z; - - z = lhs - rhs; - return z; -} - -i1 biopGti1i1(i1 lhs, i1 rhs) -{ - i1 z; - - z = lhs > rhs; - return z; -} - -i4 biopLei4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs <= rhs; - return z; -} - -u4 biopOru4u4(u4 lhs, u4 rhs) -{ - u4 z; - - z = lhs | rhs; - return z; -} - -u1 biopLogicOru1u1(u1 lhs, u1 rhs) -{ - u1 z; - - z = lhs || rhs; - return z; -} - -u2 biopAddu2u2(u2 lhs, u2 rhs) -{ - u2 z; + i2 z; z = lhs + rhs; return z; } -i1 biopGei1i1(i1 lhs, i1 rhs) +i2 i2_subtract(i2 lhs, i2 rhs) { - i1 z; + i2 z; - z = lhs >= rhs; + z = lhs - rhs; return z; } -u1 biopLogicAndu1u1(u1 lhs, u1 rhs) +i2 i2_multiply(i2 lhs, i2 rhs) { - u1 z; + i2 z; - z = lhs && rhs; + z = lhs * rhs; return z; } -i4 biopEqi4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs == rhs; - return z; -} - -u4 biopXOru4u4(u4 lhs, u4 rhs) -{ - u4 z; - - z = lhs ^ rhs; - return z; -} - -u2 biopShtLftu2u2(u2 lhs, u2 rhs) -{ - u2 z; - - z = lhs << rhs; - return z; -} - -i4 biopNei4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs != rhs; - return z; -} - -i1 biopLti1i1(i1 lhs, i1 rhs) -{ - i1 z; - - z = lhs < rhs; - return z; -} - -u1 unopNotu1(u1 lhs) -{ - u1 z; - - z = !lhs; - return z; -} - -u4 biopLogicOru4u4(u4 lhs, u4 rhs) -{ - u4 z; - - z = lhs || rhs; - return z; -} - -u2 biopShtRhtu2u2(u2 lhs, u2 rhs) -{ - u2 z; - - z = lhs >> rhs; - return z; -} - -i1 biopDividu1u1(u1 lhs, u1 rhs) -{ - i1 z; - - z = lhs / rhs; - return z; -} - -i2 biopDividu2u2(i2 lhs, i2 rhs) +i2 i2_divide(i2 lhs, i2 rhs) { i2 z; @@ -519,34 +404,12 @@ i2 biopDividu2u2(i2 lhs, i2 rhs) return z; } -u4 biopDividu4u4(u4 lhs, u4 rhs) +i2 i2_remainder(i2 lhs, i2 rhs) { - u4 z; - - z = lhs / rhs; - return z; -} - -u1 biopRemainderu1u1(u1 lhs, u1 rhs) -{ - u1 z; + i2 z; z = lhs % rhs; return z; } -u2 biopRemainderu2u2(u2 lhs, u2 rhs) -{ - u2 z; - z = lhs % rhs; - return z; -} - -u4 biopRemainderu4u4(u4 lhs, u4 rhs) -{ - u4 z; - - z = lhs % rhs; - return z; -} diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS4.test b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS4.test new file mode 100644 index 0000000000..fb7d81e732 --- /dev/null +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS4.test @@ -0,0 +1,474 @@ +#include "pcode_test.h" + +TEST u4_complexLogic_Main() +{ + extern u4 u4_complexLogic(u4 a, u4 b, u4 c, u4 d, u4 e, u4 f); + ASSERTU4(u4_complexLogic(2016764524, 1717226057, 1748349614, 0, 1276673168, 0), 15); + ASSERTU4(u4_complexLogic(2009726312, 696947386, 0, 0, 1265204346, 1369602726), 11); + ASSERTU4(u4_complexLogic(1665204916, 1707056552, 564325578, 0, 0, 1010528946), 14); + ASSERTU4(u4_complexLogic(0, 1516266761, 1866000081, 0, 1175526309, 1586903190), 10); +} + +TEST i4_complexLogic_Main() +{ + extern i4 i4_complexLogic(i4 a, i4 b, i4 c, i4 d, i4 e, i4 f); + ASSERTI4(i4_complexLogic((i4) -1916250774, 1528806445, (i4) -870305000, 0, 0, 1799560997), 14); + ASSERTI4(i4_complexLogic((i4) -1375179334, (i4) -1539942439, 987987334, 0, 1162088421, 12548159), 15); + ASSERTI4(i4_complexLogic(0, (i4) -750167716, (i4) -1104561852, 0, (i4) -915711850, 737703662), 11); + ASSERTI4(i4_complexLogic(0, 386839851, (i4) -771476364, 0, (i4) -942724790, 1833488263), 10); +} + +TEST u4_compareLogic_Main() +{ + extern u4 u4_compareLogic(u4 lhs, u4 rhs); + ASSERTU4(u4_compareLogic(0x1, 0x1), 1); + ASSERTU4(u4_compareLogic(0x1, 0x2), 23); + ASSERTU4(u4_compareLogic(0x2, 0x1), 22); +} + +TEST i4_compareLogic_Main() +{ + extern i4 i4_compareLogic(i4 lhs, i4 rhs); + ASSERTI4(i4_compareLogic(0x1, 0x1), 21); + ASSERTI4(i4_compareLogic(0x1, 0x2), 21); + ASSERTI4(i4_compareLogic(0x2, 0x1), 22); + ASSERTI4(i4_compareLogic(-0x1, -0x1), 21); + ASSERTI4(i4_compareLogic(-0x1, -0x2), 21); + ASSERTI4(i4_compareLogic(-0x2, -0x1), 24); +} + +/* Comparison operators */ +TEST u4_greaterThan_Main() +{ + extern u4 u4_greaterThan(u4 lhs, u4 rhs); + ASSERTU4(u4_greaterThan(0x01010101, 0x01010101), 0); + ASSERTU4(u4_greaterThan(2, 1), 1); + ASSERTU4(u4_greaterThan(U4_MAX, U4_MAX), 0); + ASSERTU4(u4_greaterThan(U4_MAX, 0), 1); + ASSERTU4(u4_greaterThan(0, U4_MAX), 0); +} + +TEST u4_greaterThanEquals_Main() +{ + extern u4 u4_greaterThanEquals(u4 lhs, u4 rhs); + ASSERTU4(u4_greaterThanEquals(2, 1), 1); + ASSERTU4(u4_greaterThanEquals(U4_MAX, U4_MAX), 1); + ASSERTU4(u4_greaterThanEquals(U4_MAX, 0), 1); + ASSERTU4(u4_greaterThanEquals(0, U4_MAX), 0); +} + +TEST u4_lessThan_Main() +{ + extern u4 u4_lessThan(u4 lhs, u4 rhs); + ASSERTU4(u4_lessThan(0x01010101, 0x01010101), 0); + ASSERTU4(u4_lessThan(2, 1), 0); + ASSERTU4(u4_lessThan(U4_MAX, U4_MAX), 0); + ASSERTU4(u4_lessThan(U4_MAX, 0), 0); + ASSERTU4(u4_lessThan(0, U4_MAX), 1); +} + +TEST u4_lessThanEquals_Main() +{ + extern u4 u4_lessThanEquals(u4 lhs, u4 rhs); + ASSERTU4(u4_lessThanEquals(0x01010101, 0x01010101), 1); + ASSERTU4(u4_lessThanEquals(2, 1), 0); + ASSERTU4(u4_lessThanEquals(U4_MAX, U4_MAX), 1); + ASSERTU4(u4_lessThanEquals(U4_MAX, 0), 0); + ASSERTU4(u4_lessThanEquals(0, U4_MAX), 1); +} + +TEST u4_equals_Main() +{ + extern u4 u4_equals(u4 lhs, u4 rhs); + ASSERTU4(u4_equals(0x01010101, 0x01010101), 1); + ASSERTU4(u4_equals(2, 1), 0); + ASSERTU4(u4_equals(U4_MAX, U4_MAX), 1); + ASSERTU4(u4_equals(U4_MAX, 0), 0); + ASSERTU4(u4_equals(0, U4_MAX), 0); +} + +TEST u4_notEquals_Main() +{ + extern u4 u4_notEquals(u4 lhs, u4 rhs); + ASSERTU4(u4_notEquals(0x01010101, 0x01010101), 0); + ASSERTU4(u4_notEquals(2, 1), 1); + ASSERTU4(u4_notEquals(U4_MAX, U4_MAX), 0); + ASSERTU4(u4_notEquals(U4_MAX, 0), 1); + ASSERTU4(u4_notEquals(0, U4_MAX), 1); +} + +TEST i4_greaterThan_Main() +{ + extern i4 i4_greaterThan(i4 lhs, i4 rhs); + ASSERTI4(i4_greaterThan(2, 1), 1); + ASSERTI4(i4_greaterThan(0x01010101, 0x01010101), 0); + ASSERTI4(i4_greaterThan(0x01000101, 0x01010101), 0); + ASSERTI4(i4_greaterThan(0x01010101, -0x01010101), 1); + ASSERTI4(i4_greaterThan(I4_MAX, I4_MAX), 0); + ASSERTI4(i4_greaterThan(I4_MAX, I4_MIN), 1); + ASSERTI4(i4_greaterThan(I4_MIN, I4_MAX), 0); +} + +TEST i4_greaterThanEquals_Main() +{ + extern i4 i4_greaterThanEquals(i4 lhs, i4 rhs); + ASSERTI4(i4_greaterThanEquals(2, 1), 1); + ASSERTI4(i4_greaterThanEquals(-2, 1), 0); + ASSERTI4(i4_greaterThanEquals(0x01010101, 0x01010100), 1); + ASSERTI4(i4_greaterThanEquals(I4_MAX, I4_MAX), 1); + ASSERTI4(i4_greaterThanEquals(I4_MAX, I4_MIN), 1); + ASSERTI4(i4_greaterThanEquals(I4_MIN, I4_MAX), 0); +} + +TEST i4_lessThan_Main() +{ + extern i4 i4_lessThan(i4 lhs, i4 rhs); + ASSERTI4(i4_lessThan(2, 1), 0); + ASSERTI4(i4_lessThan(0x01010101, 0x01010101), 0); + ASSERTI4(i4_lessThan(0x01000101, 0x01010101), 1); + ASSERTI4(i4_lessThan(0x01010101, -0x01010101), 0); +} + + +TEST i4_lessThanEquals_Main() +{ + extern i4 i4_lessThanEquals(i4 lhs, i4 rhs); + ASSERTI4(i4_lessThanEquals(2, 1), 0); + ASSERTI4(i4_lessThanEquals(0x01010101, 0x01010101), 1); + ASSERTI4(i4_lessThanEquals(0x01000101, 0x01010101), 1); + ASSERTI4(i4_lessThanEquals(0x01010101, -0x01010101), 0); + ASSERTI4(i4_lessThanEquals(I4_MAX, I4_MAX), 1); + ASSERTI4(i4_lessThanEquals(I4_MAX, I4_MIN), 0); + ASSERTI4(i4_lessThanEquals(I4_MIN, I4_MAX), 1); +} + +TEST i4_equals_Main() +{ + extern i4 i4_equals(i4 lhs, i4 rhs); + ASSERTI4(i4_equals(0x01010101, -0x01010101), 0); + ASSERTI4(i4_equals(2, 1), 0); + ASSERTI4(i4_equals(0x01010101, 0x01010101), 1); + ASSERTI4(i4_equals(0x01000101, 0x01010101), 0); + ASSERTI4(i4_equals(I4_MAX, I4_MAX), 1); + ASSERTI4(i4_equals(I4_MAX, I4_MIN), 0); + ASSERTI4(i4_equals(I4_MIN, I4_MAX), 0); +} + +TEST i4_notEquals_Main() +{ + extern i4 i4_notEquals(i4 lhs, i4 rhs); + ASSERTI4(i4_notEquals(0x01010101, 0x01010101), 0); + ASSERTI4(i4_notEquals(0x01000101, 0x01010101), 1); + ASSERTI4(i4_notEquals(0x01000101, -0x01010101), 1); + ASSERTI4(i4_notEquals(2, 1), 1); + ASSERTI4(i4_notEquals(I4_MAX, I4_MAX), 0); + ASSERTI4(i4_notEquals(I4_MAX, I4_MIN), 1); + ASSERTI4(i4_notEquals(I4_MIN, I4_MAX), 1); +} + +/* Bitwise operators */ +TEST u4_bitwiseAnd_Main() +{ + extern u4 u4_bitwiseAnd(u4 lhs, u4 rhs); + ASSERTU4(u4_bitwiseAnd(0x01010101, 0x01010101), 0x01010101); + ASSERTU4(u4_bitwiseAnd(2, 1), 0); + ASSERTU4(u4_bitwiseAnd(U4_MAX, U4_MAX), -1); + ASSERTU4(u4_bitwiseAnd(U4_MAX, U4_MIN), 0); + ASSERTU4(u4_bitwiseAnd(U4_MAX, 0), 0); +} + +TEST u4_bitwiseOr_Main() +{ + extern u4 u4_bitwiseOr(u4 lhs, u4 rhs); + ASSERTU4(u4_bitwiseOr(0x01010101, 0x01010101), 0x01010101); + ASSERTU4(u4_bitwiseOr(2, 1), 3); + ASSERTU4(u4_bitwiseOr(U4_MAX, U4_MAX), U4_MAX); + ASSERTU4(u4_bitwiseOr(U4_MAX, 0), U4_MAX); +} + +TEST u4_bitwiseXor_Main() +{ + extern u4 u4_bitwiseXor(u4 lhs, u4 rhs); + ASSERTU4(u4_bitwiseXor(0x01010101, 0x01010101), 0); + ASSERTU4(u4_bitwiseXor(2, 1), 3); + ASSERTU4(u4_bitwiseXor(U4_MAX, U4_MAX), 0); + ASSERTU4(u4_bitwiseXor(U4_MAX, U4_MIN), -1); + ASSERTU4(u4_bitwiseXor(U4_MAX, 0), -1); +} + +TEST i4_bitwiseAnd_Main() +{ + extern i4 i4_bitwiseAnd(i4 lhs, i4 rhs); + ASSERTI4(i4_bitwiseAnd(0x01010101, 0x01010101), 0x01010101); + ASSERTI4(i4_bitwiseAnd(2, 1), 0); + ASSERTI4(/*val*/ i4_bitwiseAnd(I4_MAX, I4_MAX), 2147483647) + ASSERTI4(/*val*/ i4_bitwiseAnd(0, 0), 0) + ASSERTI4(/*val*/ i4_bitwiseAnd(I4_MIN, I4_MIN), -2147483648) +} + +TEST i4_bitwiseOr_Main() +{ + extern i4 i4_bitwiseOr(i4 lhs, i4 rhs); + ASSERTI4(i4_bitwiseOr(0x01010101, 0x01010101), 0x01010101); + ASSERTI4(i4_bitwiseOr(0x01010101, 0x0), 0x01010101); + ASSERTI4(i4_bitwiseOr(2, 1), 3); + ASSERTI4(i4_bitwiseOr(I4_MAX, I4_MAX), 2147483647); + ASSERTI4(i4_bitwiseOr(0, 0), 0); +} + +TEST i4_bitwiseXor_Main() +{ + extern i4 i4_bitwiseXor(i4 lhs, i4 rhs); + ASSERTI4(i4_bitwiseXor(0x01010101, 0x01010101), 0); + ASSERTI4(i4_bitwiseXor(0x01010101, 0x01000101), 0x10000); + ASSERTI4(i4_bitwiseXor(2, 1), 3); + ASSERTI4(i4_bitwiseXor(I4_MAX, I4_MAX), 0); + ASSERTI4(i4_bitwiseXor(I4_MAX, 0), 2147483647); + ASSERTI4(i4_bitwiseXor(0, 0), 0); +} + +/* Logical operators */ +TEST u4_logicalAnd_Main() +{ + extern u4 u4_logicalAnd(u4 lhs, u4 rhs); + ASSERTU4(u4_logicalAnd(0x01010101, 0x01010101), 1); + ASSERTU4(u4_logicalAnd(2, 1), 1); + ASSERTU4(u4_logicalAnd(U4_MAX, U4_MAX), 1) +} + + +TEST u4_logicalOr_Main() +{ + extern u4 u4_logicalOr(u4 lhs, u4 rhs); + ASSERTU4(u4_logicalOr(0x01010101, 0x01010101), 1); + ASSERTU4(u4_logicalOr(2, 1), 1); + ASSERTU4(u4_logicalOr(U4_MAX, U4_MAX), 1); + ASSERTU4(u4_logicalOr(U4_MAX, U4_MIN), 1); +} + +TEST u4_logicalNot_Main() +{ + extern u4 u4_logicalNot(u4 lhs); + ASSERTU4(u4_logicalNot(0x01010101), 0); + ASSERTU4(u4_logicalNot(2), 0); + ASSERTU4(u4_logicalNot(U4_MAX), 0); +} + +TEST i4_logicalAnd_Main() +{ + extern i4 i4_logicalAnd(i4 lhs, i4 rhs); + ASSERTI4(i4_logicalAnd(0x01010101, 0x01010101), 1); + ASSERTI4(i4_logicalAnd(2, 1), 1); + ASSERTI4(i4_logicalAnd(0x01000101, 0x01010101), 1); + ASSERTI4(i4_logicalAnd(0x01000101, 0x0), 0); + ASSERTI4(i4_logicalAnd(I4_MAX, I4_MAX), 1); + ASSERTI4(i4_logicalAnd(I4_MIN, I4_MIN), 1); + ASSERTI4(i4_logicalAnd(0, 0), 0); +} + +TEST i4_logicalOr_Main() +{ + extern i4 i4_logicalOr(i4 lhs, i4 rhs); + ASSERTI4(i4_logicalOr(0x01010101, 0x01010101), 1); + ASSERTI4(i4_logicalOr(2, 1), 1); + ASSERTI4(i4_logicalOr(I4_MAX, I4_MAX), 1); + ASSERTI4(i4_logicalOr(I4_MIN, I4_MIN), 1); + ASSERTI4(i4_logicalOr(0, 0), 0); +} + +TEST i4_logicalNot_Main() +{ + extern i4 i4_logicalNot(i4 lhs); + ASSERTI4(i4_logicalNot(0x01010101), 0); + ASSERTI4(i4_logicalNot(2), 0); + ASSERTI4(i4_logicalNot(I4_MAX), 0); + ASSERTI4(i4_logicalNot(I4_MIN), 0); + ASSERTI4(i4_logicalNot(0), 1); +} + +/* Shift operators */ +TEST u4_shiftLeft_Main() +{ + extern u4 u4_shiftLeft(u4 lhs, u4 rhs); + ASSERTU4(u4_shiftLeft(0x01010101, 16), 0x01010000); + ASSERTU4(u4_shiftLeft(2, 1), 4); + ASSERTU4(u4_shiftLeft(U4_MAX, 4*8-1), 2147483648); + ASSERTU4(u4_shiftLeft(U4_MAX, 4), -16); +} + +TEST u4_shiftRight_Main() +{ + extern u4 u4_shiftRight(u4 lhs, u4 rhs); + ASSERTU4(u4_shiftRight(0x01010101, 16), 0x0101); + ASSERTU4(u4_shiftRight(2, 1), 1); + ASSERTU4(u4_shiftRight(U4_MAX, 4), 268435455); + ASSERTU4(u4_shiftRight(U4_MAX, 4*8-1), 1); + ASSERTU4(u4_shiftRight(4, 4), 0); +} + +TEST i4_shiftLeft_Main() +{ + extern i4 i4_shiftLeft(i4 lhs, i4 rhs); + ASSERTI4(i4_shiftLeft(2, 1), 4); + ASSERTI4(i4_shiftLeft(0x01010101, 16), 0x01010000); + ASSERTI4(i4_shiftLeft(0x01010101, 0), 0x01010101); + ASSERTI4(i4_shiftLeft(I4_MAX, 2), -4); + ASSERTI4(i4_shiftLeft(I4_MAX, 0), 2147483647); +} + +TEST i4_shiftRight_Main() +{ + extern i4 i4_shiftRight(i4 lhs, i4 rhs); + ASSERTI4(i4_shiftRight(2, 1), 1); + ASSERTI4(i4_shiftRight(0x01010101, 16), 0x0101); + ASSERTI4(i4_shiftRight(0x01010101, 31), 0x0); + ASSERTI4(i4_shiftRight(0x01010101, 0), 0x01010101); + ASSERTI4(i4_shiftRight(I4_MAX, 2), 536870911); +} + +/* Arithmetic operators */ +TEST u4_unaryPlus_Main() +{ + extern u4 u4_unaryPlus(u4 lhs); + ASSERTU4(u4_unaryPlus(0x01010101), 0x01010101); + ASSERTU4(u4_unaryPlus(2), 2); + ASSERTU4(u4_unaryPlus(U4_MAX), -1); + ASSERTU4(u4_unaryPlus(~1000), 4294966295); + ASSERTU4(u4_unaryPlus(0), 0); +} + +TEST u4_addition_Main() +{ + extern u4 u4_addition(u4 lhs, u4 rhs); + ASSERTU4(u4_addition(0x01010101, 0x01010101), 33686018); + ASSERTU4(u4_addition(2, 1), 3); + ASSERTU4(u4_addition(~2, ~1), 4294967291); + ASSERTU4(u4_addition(U4_MAX, U4_MAX), -2); + ASSERTU4(u4_addition(U4_MAX, 0), -1); + ASSERTU4(u4_addition(0, 0), 0); +} + +TEST u4_subtract_Main() +{ + extern u4 u4_subtract(u4 lhs, u4 rhs); + ASSERTU4(u4_subtract(0x01010101, 0x01010101), 0); + ASSERTU4(u4_subtract(2, 1), 1); + ASSERTU4(u4_subtract(~2, ~1), 4294967295); + ASSERTU4(u4_subtract(U4_MAX, U4_MAX), 0); + ASSERTU4(u4_subtract(U4_MAX, 0), U4_MAX); + ASSERTU4(u4_subtract(0, U4_MAX), 1); +} + +TEST u4_multiply_Main() +{ + extern u4 u4_multiply(u4 lhs, u4 rhs); + ASSERTU4(u4_multiply(0x01010101, 0x01010101), 67305985); + ASSERTU4(u4_multiply(2, 1), 2); + ASSERTU4(u4_multiply(~2, ~1), 6); + ASSERTU4(u4_multiply(U4_MAX, U4_MAX), 1); + ASSERTU4(u4_multiply(U4_MAX, 1), U4_MAX); + ASSERTU4(u4_multiply(U4_MAX, 0), 0); +} + +TEST u4_divide_Main() +{ + extern u4 u4_divide(u4 lhs, u4 rhs); + ASSERTU4(u4_divide(0x01010101, 0x01010101), 1); + ASSERTU4(u4_divide(-0x01010101, 0x01010101), 254); + ASSERTU4(u4_divide(0, 0x01010101), 0); + ASSERTU4(u4_divide(0x01010101, 2), 0x808080); + ASSERTU4(u4_divide(U4_MAX, U4_MAX), 1); + ASSERTU4(u4_divide(U4_MAX, 1), U4_MAX); +} + +TEST u4_remainder_Main() +{ + extern u4 u4_remainder(u4 lhs, u4 rhs); + ASSERTU4(u4_remainder(0x01010101, 0x01010101), 0); + ASSERTU4(u4_remainder(U4_MAX, U4_MAX), 0); + ASSERTU4(u4_remainder(I4_MIN, I4_MIN), 0); + ASSERTU4(u4_remainder(~1000, ~10), 4294966295); + ASSERTU4(u4_remainder(0, U4_MAX), 0); +} + +TEST i4_unaryMinus_Main() +{ + extern i4 i4_unaryMinus(i4 lhs); + ASSERTI4(i4_unaryMinus(0x01010101), -0x01010101); + ASSERTI4(i4_unaryMinus(-0x01010101), 0x01010101); + ASSERTI4(i4_unaryMinus(I4_MAX), -I4_MAX); + ASSERTI4(i4_unaryMinus(I4_MIN), I4_MIN); + ASSERTI4(i4_unaryMinus(0), 0); +} + +TEST i4_unaryPlus_Main() +{ + extern i4 i4_unaryPlus(i4 lhs); + ASSERTI4(i4_unaryPlus(0x01010101), 0x01010101); + ASSERTI4(i4_unaryPlus(-0x01010101), -0x01010101); + ASSERTI4(i4_unaryPlus(2), 2); + ASSERTI4(i4_unaryPlus(I4_MAX), 2147483647); + ASSERTI4(i4_unaryPlus(I4_MIN), -2147483648); + ASSERTI4(i4_unaryPlus(0), 0); +} + +TEST i4_addition_Main() +{ + extern i4 i4_addition(i4 lhs, i4 rhs); + ASSERTI4(i4_addition(2, 1), 3); + ASSERTI4(i4_addition(0x01010101, 0x01010101), 33686018); + ASSERTI4(i4_addition(0x01010101, -0x01010101), 0); + ASSERTI4(i4_addition(I4_MAX, I4_MAX), -2); + ASSERTI4(i4_addition(I4_MAX, I4_MIN), -1); + ASSERTI4(i4_addition(I4_MAX, 0), 2147483647); + ASSERTI4(i4_addition(I4_MIN, I4_MIN), 0); +} + +TEST i4_subtract_Main() +{ + extern i4 i4_subtract(i4 lhs, i4 rhs); + ASSERTI4(i4_subtract(2, 1), 1); + ASSERTI4(i4_subtract(0x01010101, 0x01010101), 0); + ASSERTI4(i4_subtract(0x01010101, 0x01000100), 0x00010001); + ASSERTI4(i4_subtract(0x01000100, 0x01010101), -0x00010001); + ASSERTI4(i4_subtract(I4_MAX, I4_MAX), 0); + ASSERTI4(i4_subtract(I4_MAX, I4_MIN), -1); + ASSERTI4(i4_subtract(I4_MAX, 0), 2147483647); + ASSERTI4(i4_subtract(0, I4_MAX), -2147483647); +} + +TEST i4_multiply_Main() +{ + extern i4 i4_multiply(i4 lhs, i4 rhs); + ASSERTI4(i4_multiply(2, 1), 2); + ASSERTI4(i4_multiply(0x01010101, 0x01010101), 67305985); + ASSERTI4(i4_multiply(0x01010101, -16843009), -67305985); + ASSERTI4(i4_multiply(0, -16843009), 0); + ASSERTI4(i4_multiply(I4_MAX, I4_MAX), 1); + ASSERTI4(i4_multiply(I4_MAX, I4_MIN), -2147483648); + ASSERTI4(i4_multiply(I4_MAX, 0), 0); +} + +TEST i4_divide_Main() +{ + extern i4 i4_divide(i4 lhs, i4 rhs); + ASSERTI4(i4_divide(0x01010101, 0x01010101), 1); + ASSERTI4(i4_divide(-0x01010101, 0x01010101), -1); + ASSERTI4(i4_divide(0, 0x01010101), 0); + ASSERTI4(i4_divide(0x01010101, 2), 0x808080); + ASSERTI4(i4_divide(I4_MAX, I4_MAX), 1); + ASSERTI4(i4_divide(I4_MIN, I4_MIN), 1); + ASSERTI4(i4_divide(-1, I4_MIN), 0); +} + +TEST i4_remainder_Main() +{ + extern i4 i4_remainder(i4 lhs, i4 rhs); + ASSERTI4(i4_remainder(0x01010101, 0x01010101), 0); + ASSERTI4(i4_remainder(I4_MAX, I4_MAX), 0); + ASSERTI4(i4_remainder(I4_MIN, I4_MIN), 0); + ASSERTI4(i4_remainder(0, I4_MIN), 0); + ASSERTI4(i4_remainder(0, I4_MAX), 0); +} + +MAIN BIOPS4_main(){ } diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS4_BODY.c b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS4_BODY.c new file mode 100644 index 0000000000..f97dd4c76e --- /dev/null +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS4_BODY.c @@ -0,0 +1,413 @@ +/* ### + * IP: GHIDRA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "pcode_test.h" + +u4 u4_complexLogic(u4 a, u4 b, u4 c, u4 d, u4 e, u4 f) +{ + u4 ret = 0; + + if (a > b && b > c || d < e && f < e) { + ret += 1; + } + if (a != b || a != c && d != e || f != e) { + ret += 2; + } + if (a && b && c || d && e && f) { + ret += 4; + } + if (a || b || c && d || e || f) { + ret += 8; + } + return ret; +} + +i4 i4_complexLogic(i4 a, i4 b, i4 c, i4 d, i4 e, i4 f) +{ + i4 ret = 0; + + if (a > b && b > c || d < e && f < e) { + ret += 1; + } + if (a != b || a != c && d != e || f != e) { + ret += 2; + } + if (a && b && c || d && e && f) { + ret += 4; + } + if (a || b || c && d || e || f) { + ret += 8; + } + return ret; +} + +u4 u4_compareLogic(u4 lhs, u4 rhs) +{ + if (lhs < rhs) + lhs += 2; + if (lhs > rhs) + lhs += 4; + if (lhs == 0) + lhs += 8; + if (lhs != rhs) + lhs += 16; + return lhs; +} + +i4 i4_compareLogic(i4 lhs, i4 rhs) +{ + if (lhs < 0) + lhs += 2; + if (lhs > 0) + lhs += 4; + if (lhs == 0) + lhs += 8; + if (lhs != rhs) + lhs += 16; + return lhs; +} +/* Comparison operators */ +u4 u4_greaterThan(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs > rhs; + return z; +} + +u4 u4_greaterThanEquals(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs >= rhs; + return z; +} + +u4 u4_lessThan(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs < rhs; + return z; +} + +u4 u4_lessThanEquals(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs <= rhs; + return z; +} + +u4 u4_equals(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs == rhs; + return z; +} + +u4 u4_notEquals(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs != rhs; + return z; +} + +i4 i4_greaterThan(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs > rhs; + return z; +} + +i4 i4_greaterThanEquals(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs >= rhs; + return z; +} + +i4 i4_lessThan(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs < rhs; + return z; +} + +i4 i4_lessThanEquals(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs <= rhs; + return z; +} + +i4 i4_equals(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs == rhs; + return z; +} + +i4 i4_notEquals(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs != rhs; + return z; +} + +/* Bitwise operators */ +u4 u4_bitwiseAnd(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs & rhs; + return z; +} + +u4 u4_bitwiseOr(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs | rhs; + return z; +} + +u4 u4_bitwiseXor(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs ^ rhs; + return z; +} + +i4 i4_bitwiseAnd(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs & rhs; + return z; +} + +i4 i4_bitwiseOr(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs | rhs; + return z; +} + +i4 i4_bitwiseXor(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs ^ rhs; + return z; +} + +/* Logical operators */ +u4 u4_logicalAnd(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs && rhs; + return z; +} + +u4 u4_logicalOr(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs || rhs; + return z; +} + +u4 u4_logicalNot(u4 lhs) +{ + u4 z; + + z = !lhs; + return z; +} + +i4 i4_logicalAnd(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs && rhs; + return z; +} + +i4 i4_logicalOr(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs || rhs; + return z; +} + +i4 i4_logicalNot(i4 lhs) +{ + i4 z; + + z = !lhs; + return z; +} + +/* Shift operators */ +u4 u4_shiftLeft(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs << rhs; + return z; +} + +u4 u4_shiftRight(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs >> rhs; + return z; +} + +i4 i4_shiftLeft(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs << rhs; + return z; +} + +i4 i4_shiftRight(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs >> rhs; + return z; +} + +/* Arithmetic operators */ +u4 u4_unaryPlus(u4 lhs) +{ + u4 z; + + z = +lhs; + return z; +} + +u4 u4_addition(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs + rhs; + return z; +} + +u4 u4_subtract(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs - rhs; + return z; +} + +u4 u4_multiply(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs * rhs; + return z; +} + +u4 u4_divide(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs / rhs; + return z; +} + +u4 u4_remainder(u4 lhs, u4 rhs) +{ + u4 z; + + z = lhs % rhs; + return z; +} + +i4 i4_unaryMinus(i4 lhs) +{ + i4 z; + + z = -lhs; + return z; +} + +i4 i4_unaryPlus(i4 lhs) +{ + i4 z; + + z = +lhs; + return z; +} + +i4 i4_addition(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs + rhs; + return z; +} + +i4 i4_subtract(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs - rhs; + return z; +} + +i4 i4_multiply(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs * rhs; + return z; +} + +i4 i4_divide(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs / rhs; + return z; +} + +i4 i4_remainder(i4 lhs, i4 rhs) +{ + i4 z; + + z = lhs % rhs; + return z; +} + diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_BODY.c b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_BODY.c index 69bcdfbafe..715abeccdb 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_BODY.c +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_BODY.c @@ -15,7 +15,7 @@ */ #include "pcode_test.h" -u1 pcode_u1_complexLogic(u1 a, u1 b, u1 c, u1 d, u1 e, u1 f) +u1 u1_complexLogic(u1 a, u1 b, u1 c, u1 d, u1 e, u1 f) { u1 ret = 0; @@ -34,45 +34,7 @@ u1 pcode_u1_complexLogic(u1 a, u1 b, u1 c, u1 d, u1 e, u1 f) return ret; } -u2 pcode_u2_complexLogic(u2 a, u2 b, u2 c, u2 d, u2 e, u2 f) -{ - u2 ret = 0; - - if (a > b && b > c || d < e && f < e) { - ret += 1; - } - if (a != b || a != c && d != e || f != e) { - ret += 2; - } - if (a && b && c || d && e && f) { - ret += 4; - } - if (a || b || c && d || e || f) { - ret += 8; - } - return ret; -} - -u4 pcode_u4_complexLogic(u4 a, u4 b, u4 c, u4 d, u4 e, u4 f) -{ - u4 ret = 0; - - if (a > b && b > c || d < e && f < e) { - ret += 1; - } - if (a != b || a != c && d != e || f != e) { - ret += 2; - } - if (a && b && c || d && e && f) { - ret += 4; - } - if (a || b || c && d || e || f) { - ret += 8; - } - return ret; -} - -i1 pcode_i1_complexLogic(i1 a, i1 b, i1 c, i1 d, i1 e, i1 f) +i1 i1_complexLogic(i1 a, i1 b, i1 c, i1 d, i1 e, i1 f) { i1 ret = 0; @@ -91,45 +53,7 @@ i1 pcode_i1_complexLogic(i1 a, i1 b, i1 c, i1 d, i1 e, i1 f) return ret; } -i2 pcode_i2_complexLogic(i2 a, i2 b, i2 c, i2 d, i2 e, i2 f) -{ - i2 ret = 0; - - if (a > b && b > c || d < e && f < e) { - ret += 1; - } - if (a != b || a != c && d != e || f != e) { - ret += 2; - } - if (a && b && c || d && e && f) { - ret += 4; - } - if (a || b || c && d || e || f) { - ret += 8; - } - return ret; -} - -i4 pcode_i4_complexLogic(i4 a, i4 b, i4 c, i4 d, i4 e, i4 f) -{ - i4 ret = 0; - - if (a > b && b > c || d < e && f < e) { - ret += 1; - } - if (a != b || a != c && d != e || f != e) { - ret += 2; - } - if (a && b && c || d && e && f) { - ret += 4; - } - if (a || b || c && d || e || f) { - ret += 8; - } - return ret; -} - -u1 biopCmpu1u1(u1 lhs, u1 rhs) +u1 u1_compareLogic(u1 lhs, u1 rhs) { if (lhs < rhs) lhs += 2; @@ -142,33 +66,7 @@ u1 biopCmpu1u1(u1 lhs, u1 rhs) return lhs; } -u2 biopCmpu2u2(u2 lhs, u2 rhs) -{ - if (lhs < rhs) - lhs += 2; - if (lhs > rhs) - lhs += 4; - if (lhs == 0) - lhs += 8; - if (lhs != rhs) - lhs += 16; - return lhs; -} - -u4 biopCmpu4u4(u4 lhs, u4 rhs) -{ - if (lhs < rhs) - lhs += 2; - if (lhs > rhs) - lhs += 4; - if (lhs == 0) - lhs += 8; - if (lhs != rhs) - lhs += 16; - return lhs; -} - -i1 biopCmpi1i1(i1 lhs, i1 rhs) +i1 i1_compareLogic(i1 lhs, i1 rhs) { if (lhs < 0) lhs += 2; @@ -181,145 +79,130 @@ i1 biopCmpi1i1(i1 lhs, i1 rhs) return lhs; } -i2 biopCmpi2i2(i2 lhs, i2 rhs) +/* Comparison operators */ +u1 u1_greaterThan(u1 lhs, u1 rhs) { - if (lhs < 0) - lhs += 2; - if (lhs > 0) - lhs += 4; - if (lhs == 0) - lhs += 8; - if (lhs != rhs) - lhs += 16; - return lhs; -} - -i4 biopCmpi4i4(i4 lhs, i4 rhs) -{ - if (lhs < 0) - lhs += 2; - if (lhs > 0) - lhs += 4; - if (lhs == 0) - lhs += 8; - if (lhs != rhs) - lhs += 16; - return lhs; -} - -i4 biopAndi4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs & rhs; - return z; -} - -i1 biopLei1i1(i1 lhs, i1 rhs) -{ - i1 z; - - z = lhs <= rhs; - return z; -} - -u4 biopLogicAndu4u4(u4 lhs, u4 rhs) -{ - u4 z; - - z = lhs && rhs; - return z; -} - -u2 biopGtu2u2(u2 lhs, u2 rhs) -{ - u2 z; + u1 z; z = lhs > rhs; return z; } -i1 biopEqi1i1(i1 lhs, i1 rhs) -{ - i1 z; - - z = lhs == rhs; - return z; -} - -i4 biopOri4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs | rhs; - return z; -} - -u4 unopNotu4(u4 lhs) -{ - u4 z; - - z = !lhs; - return z; -} - -u1 unopPlusu1(u1 lhs) +u1 u1_greaterThanEquals(u1 lhs, u1 rhs) { u1 z; - z = +lhs; - return z; -} - -u2 biopGeu2u2(u2 lhs, u2 rhs) -{ - u2 z; - z = lhs >= rhs; return z; } -i1 biopNei1i1(i1 lhs, i1 rhs) +u1 u1_lessThan(u1 lhs, u1 rhs) { - i1 z; - - z = lhs != rhs; - return z; -} - -i4 biopXOri4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs ^ rhs; - return z; -} - -i4 biopDividi4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs / rhs; - return z; -} - -i4 biopRemainderi4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs % rhs; - return z; -} - -u2 biopLtu2u2(u2 lhs, u2 rhs) -{ - u2 z; + u1 z; z = lhs < rhs; return z; } -i1 biopAndi1i1(i1 lhs, i1 rhs) +u1 u1_lessThanEquals(u1 lhs, u1 rhs) +{ + u1 z; + + z = lhs <= rhs; + return z; +} + +u1 u1_equals(u1 lhs, u1 rhs) +{ + u1 z; + + z = lhs == rhs; + return z; +} + +u1 u1_notEquals(u1 lhs, u1 rhs) +{ + u1 z; + + z = lhs != rhs; + return z; +} + +i1 i1_greaterThan(i1 lhs, i1 rhs) +{ + i1 z; + + z = lhs > rhs; + return z; +} + +i1 i1_greaterThanEquals(i1 lhs, i1 rhs) +{ + i1 z; + + z = lhs >= rhs; + return z; +} + +i1 i1_lessThan(i1 lhs, i1 rhs) +{ + i1 z; + + z = lhs < rhs; + return z; +} + +i1 i1_lessThanEquals(i1 lhs, i1 rhs) +{ + i1 z; + + z = lhs <= rhs; + return z; +} + +i1 i1_equals(i1 lhs, i1 rhs) +{ + i1 z; + + z = lhs == rhs; + return z; +} + +i1 i1_notEquals(i1 lhs, i1 rhs) +{ + i1 z; + + z = lhs != rhs; + return z; +} + +/* Bitwise operators */ +u1 u1_bitwiseAnd(u1 lhs, u1 rhs) +{ + u1 z; + + z = lhs & rhs; + return z; +} + + +u1 u1_bitwiseOr(u1 lhs, u1 rhs) +{ + u1 z; + + z = lhs | rhs; + return z; +} + +u1 u1_bitwiseXor(u1 lhs, u1 rhs) +{ + u1 z; + + z = lhs ^ rhs; + return z; +} + +i1 i1_bitwiseAnd(i1 lhs, i1 rhs) { i1 z; @@ -327,39 +210,7 @@ i1 biopAndi1i1(i1 lhs, i1 rhs) return z; } -i4 biopLogicOri4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs || rhs; - return z; -} - -u4 unopPlusu4(u4 lhs) -{ - u4 z; - - z = +lhs; - return z; -} - -u2 biopLeu2u2(u2 lhs, u2 rhs) -{ - u2 z; - - z = lhs <= rhs; - return z; -} - -i4 biopLogicAndi4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs && rhs; - return z; -} - -i1 biopOri1i1(i1 lhs, i1 rhs) +i1 i1_bitwiseOr(i1 lhs, i1 rhs) { i1 z; @@ -367,63 +218,7 @@ i1 biopOri1i1(i1 lhs, i1 rhs) return z; } -i2 biopRemainderi2i2(i2 lhs, i2 rhs) -{ - i2 z; - - z = lhs % rhs; - return z; -} - -i2 biopMulti2i2(i2 lhs, i2 rhs) -{ - i2 z; - - z = lhs * rhs; - return z; -} - -u2 biopEqu2u2(u2 lhs, u2 rhs) -{ - u2 z; - - z = lhs == rhs; - return z; -} - -i2 biopDividi2i2(i2 lhs, i2 rhs) -{ - i2 z; - - z = lhs / rhs; - return z; -} - -i4 unopNoti4(i4 lhs) -{ - i4 z; - - z = !lhs; - return z; -} - -u2 biopNeu2u2(u2 lhs, u2 rhs) -{ - u2 z; - - z = lhs != rhs; - return z; -} - -i1 biopLogicOri1i1(i1 lhs, i1 rhs) -{ - i1 z; - - z = lhs || rhs; - return z; -} - -i1 biopXOri1i1(i1 lhs, i1 rhs) +i1 i1_bitwiseXor(i1 lhs, i1 rhs) { i1 z; @@ -431,55 +226,32 @@ i1 biopXOri1i1(i1 lhs, i1 rhs) return z; } -i1 biopRemainderi1i1(i1 lhs, i1 rhs) +/* Logical operators */ +u1 u1_logicalAnd(u1 lhs, u1 rhs) { - i1 z; + u1 z; - z = lhs % rhs; + z = lhs && rhs; return z; } -i2 biopSubi2i2(i2 lhs, i2 rhs) +u1 u1_logicalOr(u1 lhs, u1 rhs) { - i2 z; + u1 z; - z = lhs - rhs; + z = lhs || rhs; return z; } -i1 biopDividi1i1(i1 lhs, i1 rhs) +u1 u1_logicalNot(u1 lhs) { - i1 z; + u1 z; - z = lhs / rhs; + z = !lhs; return z; } -i4 unopNegativei4(i4 lhs) -{ - i4 z; - - z = -lhs; - return z; -} - -i2 biopAddi2i2(i2 lhs, i2 rhs) -{ - i2 z; - - z = lhs + rhs; - return z; -} - -u2 biopAndu2u2(u2 lhs, u2 rhs) -{ - u2 z; - - z = lhs & rhs; - return z; -} - -i1 biopLogicAndi1i1(i1 lhs, i1 rhs) +i1 i1_logicalAnd(i1 lhs, i1 rhs) { i1 z; @@ -487,31 +259,15 @@ i1 biopLogicAndi1i1(i1 lhs, i1 rhs) return z; } -i4 unopPlusi4(i4 lhs) +i1 i1_logicalOr(i1 lhs, i1 rhs) { - i4 z; + i1 z; - z = +lhs; + z = lhs || rhs; return z; } -i2 biopShtLfti2i2(i2 lhs, i2 rhs) -{ - i2 z; - - z = lhs << rhs; - return z; -} - -u2 biopOru2u2(u2 lhs, u2 rhs) -{ - u2 z; - - z = lhs | rhs; - return z; -} - -i1 unopNoti1(i1 lhs) +i1 i1_logicalNot(i1 lhs) { i1 z; @@ -519,39 +275,89 @@ i1 unopNoti1(i1 lhs) return z; } -u4 biopMultu4u4(u4 lhs, u4 rhs) +/* Shift operators */ +u1 u1_shiftLeft(u1 lhs, u1 rhs) { - u4 z; + u1 z; - z = lhs * rhs; + z = lhs << rhs; return z; } -i2 biopShtRhti2i2(i2 lhs, i2 rhs) +u1 u1_shiftRight(u1 lhs, u1 rhs) { - i2 z; + u1 z; z = lhs >> rhs; return z; } -u2 biopXOru2u2(u2 lhs, u2 rhs) +i1 i1_shiftLeft(i1 lhs, i1 rhs) { - u2 z; + i1 z; - z = lhs ^ rhs; + z = lhs << rhs; return z; } -u4 biopSubu4u4(u4 lhs, u4 rhs) +i1 i1_shiftRight(i1 lhs, i1 rhs) { - u4 z; + i1 z; + + z = lhs >> rhs; + return z; +} + +/* Arithmetic operators */ +u1 u1_unaryPlus(u1 lhs) +{ + u1 z; + + z = +lhs; + return z; +} + +u1 u1_addition(u1 lhs, u1 rhs) +{ + u1 z; + + z = lhs + rhs; + return z; +} + +u1 u1_subtract(u1 lhs, u1 rhs) +{ + u1 z; z = lhs - rhs; return z; } -i1 unopNegativei1(i1 lhs) +u1 u1_multiply(u1 lhs, u1 rhs) +{ + u1 z; + + z = lhs * rhs; + return z; +} + +i1 u1_divide(u1 lhs, u1 rhs) +{ + i1 z; + + z = lhs / rhs; + return z; +} + +u1 u1_remainder(u1 lhs, u1 rhs) +{ + u1 z; + + z = lhs % rhs; + return z; +} + +i1 i1_unaryMinus(i1 lhs) { i1 z; @@ -559,31 +365,7 @@ i1 unopNegativei1(i1 lhs) return z; } -i2 biopGti2i2(i2 lhs, i2 rhs) -{ - i2 z; - - z = lhs > rhs; - return z; -} - -u2 biopLogicOru2u2(u2 lhs, u2 rhs) -{ - u2 z; - - z = lhs || rhs; - return z; -} - -u4 biopAddu4u4(u4 lhs, u4 rhs) -{ - u4 z; - - z = lhs + rhs; - return z; -} - -i1 unopPlusi1(i1 lhs) +i1 i1_unaryPlus(i1 lhs) { i1 z; @@ -591,66 +373,44 @@ i1 unopPlusi1(i1 lhs) return z; } -i2 biopGei2i2(i2 lhs, i2 rhs) +i1 i1_addition(i1 lhs, i1 rhs) { - i2 z; + i1 z; - z = lhs >= rhs; + z = lhs + rhs; return z; } -u2 biopLogicAndu2u2(u2 lhs, u2 rhs) +i1 i1_subtract(i1 lhs, i1 rhs) { - u2 z; + i1 z; - z = lhs && rhs; + z = lhs - rhs; return z; } -u1 biopMultu1u1(u1 lhs, u1 rhs) +i1 i1_multiply(i1 lhs, i1 rhs) { - u1 z; + i1 z; z = lhs * rhs; return z; } -u1 biopGtu1u1(u1 lhs, u1 rhs) +i1 i1_divide(i1 lhs, i1 rhs) { - u1 z; + i1 z; - z = lhs > rhs; + z = lhs / rhs; return z; } -u4 biopShtLftu4u4(u4 lhs, u4 rhs) +i1 i1_remainder(i1 lhs, i1 rhs) { - u4 z; + i1 z; - z = lhs << rhs; + z = lhs % rhs; return z; } -i2 biopOri2i2(i2 lhs, i2 rhs) -{ - i2 z; - z = lhs | rhs; - return z; -} - -i2 biopLti2i2(i2 lhs, i2 rhs) -{ - i2 z; - - z = lhs < rhs; - return z; -} - -i4 biopMulti4i4(i4 lhs, i4 rhs) -{ - i4 z; - - z = lhs * rhs; - return z; -} diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_DOUBLE.test b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_DOUBLE.test index 99415587f0..5738519d20 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_DOUBLE.test +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_DOUBLE.test @@ -1,197 +1,199 @@ #include "pcode_test.h" +/* Comparison operators */ #ifdef HAS_DOUBLE -TEST biopEqf8f8_Main() +TEST f8_greaterThan_Main() { - extern f8 biopEqf8f8(f8 lhs, f8 rhs); + extern f8 f8_greaterThan(f8 lhs, f8 rhs); f8 lhs = 2; f8 rhs = 1; f8 retVal; - retVal = biopEqf8f8(lhs, rhs); + retVal = f8_greaterThan(lhs, rhs); + ASSERTF8(retVal, 1); + ASSERTF8(f8_greaterThan(PI_SHORT, PI_SHORT), 0.0); + ASSERTF8(f8_greaterThan(PI_SHORT, 2*PI_SHORT), 0.0); + ASSERTF8(f8_greaterThan(2*PI_SHORT, PI_SHORT), 1.0); +} +#endif + +#ifdef HAS_DOUBLE +TEST f8_greaterThanEquals_Main() +{ + extern f8 f8_greaterThanEquals(f8 lhs, f8 rhs); + f8 lhs = 2; + f8 rhs = 1; + f8 retVal; + retVal = f8_greaterThanEquals(lhs, rhs); + ASSERTF8(retVal, 1); + ASSERTF8(f8_greaterThanEquals(PI_SHORT, PI_SHORT), 1.0); + ASSERTF8(f8_greaterThanEquals(PI_SHORT, 2*PI_SHORT), 0.0); + ASSERTF8(f8_greaterThanEquals(2*PI_SHORT, PI_SHORT), 1.0); +} +#endif + +#ifdef HAS_DOUBLE +TEST f8_lessThan_Main() +{ + extern f8 f8_lessThan(f8 lhs, f8 rhs); + f8 lhs = 2; + f8 rhs = 1; + f8 retVal; + retVal = f8_lessThan(lhs, rhs); ASSERTF8(retVal, 0); - ASSERTF8(biopEqf8f8(PI_SHORT, PI_SHORT), 1.0); - ASSERTF8(biopEqf8f8(PI_SHORT, 2*PI_SHORT), 0.0); - ASSERTF8(biopEqf8f8(2*PI_SHORT, PI_SHORT), 0.0); + ASSERTF8(f8_lessThan(PI_SHORT, PI_SHORT), 0.0); + ASSERTF8(f8_lessThan(PI_SHORT, 2*PI_SHORT), 1.0); + ASSERTF8(f8_lessThan(2*PI_SHORT, PI_SHORT), 0.0); } #endif #ifdef HAS_DOUBLE -TEST biopNef8f8_Main() +TEST f8_lessThanEquals_Main() { - extern f8 biopNef8f8(f8 lhs, f8 rhs); + extern f8 f8_lessThanEquals(f8 lhs, f8 rhs); f8 lhs = 2; f8 rhs = 1; f8 retVal; - retVal = biopNef8f8(lhs, rhs); - ASSERTF8(retVal, 1); - ASSERTF8(biopNef8f8(PI_SHORT, PI_SHORT), 0.0); - ASSERTF8(biopNef8f8(PI_SHORT, 2*PI_SHORT), 1.0); - ASSERTF8(biopNef8f8(2*PI_SHORT, PI_SHORT), 1.0); -} -#endif - -#ifdef HAS_DOUBLE -TEST biopLogicOrf8f8_Main() -{ - extern f8 biopLogicOrf8f8(f8 lhs, f8 rhs); - f8 lhs = 2; - f8 rhs = 1; - f8 retVal; - retVal = biopLogicOrf8f8(lhs, rhs); - ASSERTF8(retVal, 1); - ASSERTF8(biopLogicOrf8f8(PI_SHORT, PI_SHORT), 1); - ASSERTF8(biopLogicOrf8f8(PI_SHORT, 0), 1); -} -#endif - -#ifdef HAS_DOUBLE -TEST biopLogicAndf8f8_Main() -{ - extern f8 biopLogicAndf8f8(f8 lhs, f8 rhs); - f8 lhs = 2; - f8 rhs = 1; - f8 retVal; - retVal = biopLogicAndf8f8(lhs, rhs); - ASSERTF8(retVal, 1); - ASSERTF8(biopLogicAndf8f8(PI_SHORT, PI_SHORT), 1); - ASSERTF8(biopLogicAndf8f8(PI_SHORT, 0), 0.0); -} -#endif - -#ifdef HAS_DOUBLE -TEST unopNotf8_Main() -{ - extern f8 unopNotf8(f8 lhs); - f8 lhs = 2; - f8 retVal; - retVal = unopNotf8(lhs); + retVal = f8_lessThanEquals(lhs, rhs); ASSERTF8(retVal, 0); - ASSERTF8(unopNotf8(PI_SHORT), 0); + ASSERTF8(f8_lessThanEquals(PI_SHORT, PI_SHORT), 1.0); + ASSERTF8(f8_lessThanEquals(PI_SHORT, 2*PI_SHORT), 1.0); + ASSERTF8(f8_lessThanEquals(2*PI_SHORT, PI_SHORT), 0.0); } #endif #ifdef HAS_DOUBLE -TEST unopNegativef8_Main() +TEST f8_equals_Main() { - extern f8 unopNegativef8(f8 lhs); + extern f8 f8_equals(f8 lhs, f8 rhs); + f8 lhs = 2; + f8 rhs = 1; + f8 retVal; + retVal = f8_equals(lhs, rhs); + ASSERTF8(retVal, 0); + ASSERTF8(f8_equals(PI_SHORT, PI_SHORT), 1.0); + ASSERTF8(f8_equals(PI_SHORT, 2*PI_SHORT), 0.0); + ASSERTF8(f8_equals(2*PI_SHORT, PI_SHORT), 0.0); +} +#endif + +#ifdef HAS_DOUBLE +TEST f8_notEquals_Main() +{ + extern f8 f8_notEquals(f8 lhs, f8 rhs); + f8 lhs = 2; + f8 rhs = 1; + f8 retVal; + retVal = f8_notEquals(lhs, rhs); + ASSERTF8(retVal, 1); + ASSERTF8(f8_notEquals(PI_SHORT, PI_SHORT), 0.0); + ASSERTF8(f8_notEquals(PI_SHORT, 2*PI_SHORT), 1.0); + ASSERTF8(f8_notEquals(2*PI_SHORT, PI_SHORT), 1.0); +} +#endif + +/* Logical operators */ +#ifdef HAS_DOUBLE +TEST f8_logicalAnd_Main() +{ + extern f8 f8_logicalAnd(f8 lhs, f8 rhs); + f8 lhs = 2; + f8 rhs = 1; + f8 retVal; + retVal = f8_logicalAnd(lhs, rhs); + ASSERTF8(retVal, 1); + ASSERTF8(f8_logicalAnd(PI_SHORT, PI_SHORT), 1); + ASSERTF8(f8_logicalAnd(PI_SHORT, 0), 0.0); +} +#endif + +#ifdef HAS_DOUBLE +TEST f8_logicalOr_Main() +{ + extern f8 f8_logicalOr(f8 lhs, f8 rhs); + f8 lhs = 2; + f8 rhs = 1; + f8 retVal; + retVal = f8_logicalOr(lhs, rhs); + ASSERTF8(retVal, 1); + ASSERTF8(f8_logicalOr(PI_SHORT, PI_SHORT), 1); + ASSERTF8(f8_logicalOr(PI_SHORT, 0), 1); +} +#endif + +#ifdef HAS_DOUBLE +TEST f8_logicalNot_Main() +{ + extern f8 f8_logicalNot(f8 lhs); f8 lhs = 2; f8 retVal; - retVal = unopNegativef8(lhs); + retVal = f8_logicalNot(lhs); + ASSERTF8(retVal, 0); + ASSERTF8(f8_logicalNot(PI_SHORT), 0); +} +#endif + +/* Arithmetic operators */ +#ifdef HAS_DOUBLE +TEST f8_unaryMinus_Main() +{ + extern f8 f8_unaryMinus(f8 lhs); + f8 lhs = 2; + f8 retVal; + retVal = f8_unaryMinus(lhs); ASSERTF8(retVal, -2); - ASSERTF8(unopNegativef8(PI_SHORT), -3.14); + ASSERTF8(f8_unaryMinus(PI_SHORT), -3.14); } #endif #ifdef HAS_DOUBLE -TEST unopPlusf8_Main() +TEST f8_unaryPlus_Main() { - extern f8 unopPlusf8(f8 lhs); + extern f8 f8_unaryPlus(f8 lhs); f8 lhs = 2; f8 retVal; - retVal = unopPlusf8(lhs); + retVal = f8_unaryPlus(lhs); ASSERTF8(retVal, 2); - ASSERTF8(unopPlusf8(PI_SHORT), PI_SHORT); + ASSERTF8(f8_unaryPlus(PI_SHORT), PI_SHORT); } #endif #ifdef HAS_DOUBLE -TEST biopMultf8f8_Main() +TEST f8_addition_Main() { - extern f8 biopMultf8f8(f8 lhs, f8 rhs); + extern f8 f8_addition(f8 lhs, f8 rhs); f8 lhs = 2; f8 rhs = 1; f8 retVal; - retVal = biopMultf8f8(lhs, rhs); - ASSERTF8(retVal, 2); - ASSERTF8(biopMultf8f8(PI_SHORT, PI_SHORT), 9.8596); -} -#endif - -#ifdef HAS_DOUBLE -TEST biopSubf8f8_Main() -{ - extern f8 biopSubf8f8(f8 lhs, f8 rhs); - f8 lhs = 2; - f8 rhs = 1; - f8 retVal; - retVal = biopSubf8f8(lhs, rhs); - ASSERTF8(retVal, 1); - ASSERTF8(biopSubf8f8(PI_SHORT, PI_SHORT), 0.0); -} -#endif - -#ifdef HAS_DOUBLE -TEST biopAddf8f8_Main() -{ - extern f8 biopAddf8f8(f8 lhs, f8 rhs); - f8 lhs = 2; - f8 rhs = 1; - f8 retVal; - retVal = biopAddf8f8(lhs, rhs); + retVal = f8_addition(lhs, rhs); ASSERTF8(retVal, 3); - ASSERTF8(biopAddf8f8(PI_SHORT, PI_SHORT), 6.28); + ASSERTF8(f8_addition(PI_SHORT, PI_SHORT), 6.28); } #endif #ifdef HAS_DOUBLE -TEST biopGtf8f8_Main() +TEST f8_subtract_Main() { - extern f8 biopGtf8f8(f8 lhs, f8 rhs); + extern f8 f8_subtract(f8 lhs, f8 rhs); f8 lhs = 2; f8 rhs = 1; f8 retVal; - retVal = biopGtf8f8(lhs, rhs); + retVal = f8_subtract(lhs, rhs); ASSERTF8(retVal, 1); - ASSERTF8(biopGtf8f8(PI_SHORT, PI_SHORT), 0.0); - ASSERTF8(biopGtf8f8(PI_SHORT, 2*PI_SHORT), 0.0); - ASSERTF8(biopGtf8f8(2*PI_SHORT, PI_SHORT), 1.0); + ASSERTF8(f8_subtract(PI_SHORT, PI_SHORT), 0.0); } #endif #ifdef HAS_DOUBLE -TEST biopGef8f8_Main() +TEST f8_multiply_Main() { - extern f8 biopGef8f8(f8 lhs, f8 rhs); + extern f8 f8_multiply(f8 lhs, f8 rhs); f8 lhs = 2; f8 rhs = 1; f8 retVal; - retVal = biopGef8f8(lhs, rhs); - ASSERTF8(retVal, 1); - ASSERTF8(biopGef8f8(PI_SHORT, PI_SHORT), 1.0); - ASSERTF8(biopGef8f8(PI_SHORT, 2*PI_SHORT), 0.0); - ASSERTF8(biopGef8f8(2*PI_SHORT, PI_SHORT), 1.0); -} -#endif - -#ifdef HAS_DOUBLE -TEST biopLtf8f8_Main() -{ - extern f8 biopLtf8f8(f8 lhs, f8 rhs); - f8 lhs = 2; - f8 rhs = 1; - f8 retVal; - retVal = biopLtf8f8(lhs, rhs); - ASSERTF8(retVal, 0); - ASSERTF8(biopLtf8f8(PI_SHORT, PI_SHORT), 0.0); - ASSERTF8(biopLtf8f8(PI_SHORT, 2*PI_SHORT), 1.0); - ASSERTF8(biopLtf8f8(2*PI_SHORT, PI_SHORT), 0.0); -} -#endif - -#ifdef HAS_DOUBLE -TEST biopLef8f8_Main() -{ - extern f8 biopLef8f8(f8 lhs, f8 rhs); - f8 lhs = 2; - f8 rhs = 1; - f8 retVal; - retVal = biopLef8f8(lhs, rhs); - ASSERTF8(retVal, 0); - ASSERTF8(biopLef8f8(PI_SHORT, PI_SHORT), 1.0); - ASSERTF8(biopLef8f8(PI_SHORT, 2*PI_SHORT), 1.0); - ASSERTF8(biopLef8f8(2*PI_SHORT, PI_SHORT), 0.0); + retVal = f8_multiply(lhs, rhs); + ASSERTF8(retVal, 2); + ASSERTF8(f8_multiply(PI_SHORT, PI_SHORT), 9.8596); } #endif MAIN BIOPS_DOUBLE_main() { } - diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_DOUBLE_BODY.c b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_DOUBLE_BODY.c index 520a26df05..cf6839ac21 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_DOUBLE_BODY.c +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_DOUBLE_BODY.c @@ -14,89 +14,10 @@ * limitations under the License. */ #include "pcode_test.h" - #ifdef HAS_DOUBLE -f8 biopEqf8f8(f8 lhs, f8 rhs) -{ - f8 z; - z = lhs == rhs; - return z; -} - -f8 biopNef8f8(f8 lhs, f8 rhs) -{ - f8 z; - - z = lhs != rhs; - return z; -} - -f8 biopLogicOrf8f8(f8 lhs, f8 rhs) -{ - f8 z; - - z = lhs || rhs; - return z; -} - -f8 biopLogicAndf8f8(f8 lhs, f8 rhs) -{ - f8 z; - - z = lhs && rhs; - return z; -} - -f8 unopNotf8(f8 lhs) -{ - f8 z; - - z = !lhs; - return z; -} - -f8 unopNegativef8(f8 lhs) -{ - f8 z; - - z = -lhs; - return z; -} - -f8 unopPlusf8(f8 lhs) -{ - f8 z; - - z = +lhs; - return z; -} - -f8 biopMultf8f8(f8 lhs, f8 rhs) -{ - f8 z; - - z = lhs * rhs; - return z; -} - -f8 biopSubf8f8(f8 lhs, f8 rhs) -{ - f8 z; - - z = lhs - rhs; - return z; -} - -f8 biopAddf8f8(f8 lhs, f8 rhs) -{ - f8 z; - - z = lhs + rhs; - return z; -} - -f8 biopGtf8f8(f8 lhs, f8 rhs) +/* Comparison operators */ +f8 f8_greaterThan(f8 lhs, f8 rhs) { f8 z; @@ -104,7 +25,7 @@ f8 biopGtf8f8(f8 lhs, f8 rhs) return z; } -f8 biopGef8f8(f8 lhs, f8 rhs) +f8 f8_greaterThanEquals(f8 lhs, f8 rhs) { f8 z; @@ -112,7 +33,7 @@ f8 biopGef8f8(f8 lhs, f8 rhs) return z; } -f8 biopLtf8f8(f8 lhs, f8 rhs) +f8 f8_lessThan(f8 lhs, f8 rhs) { f8 z; @@ -120,7 +41,7 @@ f8 biopLtf8f8(f8 lhs, f8 rhs) return z; } -f8 biopLef8f8(f8 lhs, f8 rhs) +f8 f8_lessThanEquals(f8 lhs, f8 rhs) { f8 z; @@ -128,4 +49,88 @@ f8 biopLef8f8(f8 lhs, f8 rhs) return z; } +f8 f8_equals(f8 lhs, f8 rhs) +{ + f8 z; + + z = lhs == rhs; + return z; +} + +f8 f8_notEquals(f8 lhs, f8 rhs) +{ + f8 z; + + z = lhs != rhs; + return z; +} + +/* Bitwise operators */ + +/* Logical operators */ +f8 f8_logicalAnd(f8 lhs, f8 rhs) +{ + f8 z; + + z = lhs && rhs; + return z; +} + +f8 f8_logicalOr(f8 lhs, f8 rhs) +{ + f8 z; + + z = lhs || rhs; + return z; +} + +f8 f8_logicalNot(f8 lhs) +{ + f8 z; + + z = !lhs; + return z; +} + +/* Arithmetic operators */ +f8 f8_unaryMinus(f8 lhs) +{ + f8 z; + + z = -lhs; + return z; +} + +f8 f8_unaryPlus(f8 lhs) +{ + f8 z; + + z = +lhs; + return z; +} + +f8 f8_addition(f8 lhs, f8 rhs) +{ + f8 z; + + z = lhs + rhs; + return z; +} + +f8 f8_subtract(f8 lhs, f8 rhs) +{ + f8 z; + + z = lhs - rhs; + return z; +} + +f8 f8_multiply(f8 lhs, f8 rhs) +{ + f8 z; + + z = lhs * rhs; + return z; +} + #endif /* #ifdef HAS_DOUBLE */ diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_FLOAT.test b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_FLOAT.test index d85e4d502c..20f2e7a4a9 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_FLOAT.test +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_FLOAT.test @@ -1,168 +1,171 @@ #include "pcode_test.h" #ifdef HAS_FLOAT -TEST biopCmpf4f4_Main() +TEST f4_compareLogic_Main() { - extern f4 biopCmpf4f4(f4 lhs, f4 rhs); - ASSERTF4(biopCmpf4f4(0x1, 0x1), 21); - ASSERTF4(biopCmpf4f4(0x1, 0x2), 21); - ASSERTF4(biopCmpf4f4(0x2, 0x1), 22); - ASSERTF4(biopCmpf4f4(-0x1, -0x1), 21); - ASSERTF4(biopCmpf4f4(-0x1, -0x2), 21); - ASSERTF4(biopCmpf4f4(-0x2, -0x1), 24); + extern f4 f4_compareLogic(f4 lhs, f4 rhs); + ASSERTF4(f4_compareLogic(0x1, 0x1), 21); + ASSERTF4(f4_compareLogic(0x1, 0x2), 21); + ASSERTF4(f4_compareLogic(0x2, 0x1), 22); + ASSERTF4(f4_compareLogic(-0x1, -0x1), 21); + ASSERTF4(f4_compareLogic(-0x1, -0x2), 21); + ASSERTF4(f4_compareLogic(-0x2, -0x1), 24); } #endif #ifdef HAS_DOUBLE -TEST biopCmpf8f8_Main() +TEST f8_compareLogic_Main() { - extern f8 biopCmpf8f8(f8 lhs, f8 rhs); - ASSERTF8(biopCmpf8f8(0x1, 0x1), 21); - ASSERTF8(biopCmpf8f8(0x1, 0x2), 21); - ASSERTF8(biopCmpf8f8(0x2, 0x1), 22); - ASSERTF8(biopCmpf8f8(-0x1, -0x1), 21); - ASSERTF8(biopCmpf8f8(-0x1, -0x2), 21); - ASSERTF8(biopCmpf8f8(-0x2, -0x1), 24); + extern f8 f8_compareLogic(f8 lhs, f8 rhs); + ASSERTF8(f8_compareLogic(0x1, 0x1), 21); + ASSERTF8(f8_compareLogic(0x1, 0x2), 21); + ASSERTF8(f8_compareLogic(0x2, 0x1), 22); + ASSERTF8(f8_compareLogic(-0x1, -0x1), 21); + ASSERTF8(f8_compareLogic(-0x1, -0x2), 21); + ASSERTF8(f8_compareLogic(-0x2, -0x1), 24); +} +#endif + +/* Comparison operators */ +#ifdef HAS_FLOAT +TEST f4_greaterThan_Main() +{ + extern f4 f4_greaterThan(f4 lhs, f4 rhs); + ASSERTF4(f4_greaterThan(2, 1), 1); + ASSERTF4(f4_greaterThan(PI_SHORT, PI_SHORT), 0.0); + ASSERTF4(f4_greaterThan(PI_SHORT, 2*PI_SHORT), 0.0); + ASSERTF4(f4_greaterThan(2*PI_SHORT, PI_SHORT), 1.0); } #endif #ifdef HAS_FLOAT -TEST biopLtf4f4_Main() +TEST f4_greaterThanEquals_Main() { - extern f4 biopLtf4f4(f4 lhs, f4 rhs); + extern f4 f4_greaterThanEquals(f4 lhs, f4 rhs); + ASSERTF4(f4_greaterThanEquals(2, 1), 1); + ASSERTF4(f4_greaterThanEquals(PI_SHORT, PI_SHORT), 1.0); + ASSERTF4(f4_greaterThanEquals(PI_SHORT, 2*PI_SHORT), 0.0); + ASSERTF4(f4_greaterThanEquals(2*PI_SHORT, PI_SHORT), 1.0); +} +#endif + +#ifdef HAS_FLOAT +TEST f4_lessThan_Main() +{ + extern f4 f4_lessThan(f4 lhs, f4 rhs); f4 lhs = 2; f4 rhs = 1; f4 retVal; - ASSERTF4(biopLtf4f4(lhs, rhs), 0); + ASSERTF4(f4_lessThan(lhs, rhs), 0); } #endif #ifdef HAS_FLOAT -TEST biopLef4f4_Main() +TEST f4_lessThanEquals_Main() { - extern f4 biopLef4f4(f4 lhs, f4 rhs); - ASSERTF4(biopLef4f4(2, 1), 0); - ASSERTF4(biopLef4f4(PI_SHORT, 2*PI_SHORT), 1.0); - ASSERTF4(biopLef4f4(PI_SHORT, PI_SHORT), 1.0); - ASSERTF4(biopLef4f4(2*PI_SHORT, PI_SHORT), 0.0); + extern f4 f4_lessThanEquals(f4 lhs, f4 rhs); + ASSERTF4(f4_lessThanEquals(2, 1), 0); + ASSERTF4(f4_lessThanEquals(PI_SHORT, 2*PI_SHORT), 1.0); + ASSERTF4(f4_lessThanEquals(PI_SHORT, PI_SHORT), 1.0); + ASSERTF4(f4_lessThanEquals(2*PI_SHORT, PI_SHORT), 0.0); } #endif #ifdef HAS_FLOAT -TEST biopEqf4f4_Main() +TEST f4_equals_Main() { - extern f4 biopEqf4f4(f4 lhs, f4 rhs); - ASSERTF4(biopEqf4f4(2, 1), 0); - ASSERTF4(biopEqf4f4(PI_SHORT, PI_SHORT), 1.0); - ASSERTF4(biopEqf4f4(PI_SHORT, 2*PI_SHORT), 0.0); - ASSERTF4(biopEqf4f4(2*PI_SHORT, PI_SHORT), 0.0); + extern f4 f4_equals(f4 lhs, f4 rhs); + ASSERTF4(f4_equals(2, 1), 0); + ASSERTF4(f4_equals(PI_SHORT, PI_SHORT), 1.0); + ASSERTF4(f4_equals(PI_SHORT, 2*PI_SHORT), 0.0); + ASSERTF4(f4_equals(2*PI_SHORT, PI_SHORT), 0.0); } #endif #ifdef HAS_FLOAT -TEST biopNef4f4_Main() +TEST f4_notEquals_Main() { - extern f4 biopNef4f4(f4 lhs, f4 rhs); - ASSERTF4(biopNef4f4(2, 1), 1); - ASSERTF4(biopNef4f4(PI_SHORT, PI_SHORT), 0.0); - ASSERTF4(biopNef4f4(PI_SHORT, 2*PI_SHORT), 1.0); - ASSERTF4(biopNef4f4(2*PI_SHORT, PI_SHORT), 1.0); + extern f4 f4_notEquals(f4 lhs, f4 rhs); + ASSERTF4(f4_notEquals(2, 1), 1); + ASSERTF4(f4_notEquals(PI_SHORT, PI_SHORT), 0.0); + ASSERTF4(f4_notEquals(PI_SHORT, 2*PI_SHORT), 1.0); + ASSERTF4(f4_notEquals(2*PI_SHORT, PI_SHORT), 1.0); +} +#endif + +/* Logical operators */ +#ifdef HAS_FLOAT +TEST f4_logicalAnd_Main() +{ + extern f4 f4_logicalAnd(f4 lhs, f4 rhs); + ASSERTF4(f4_logicalAnd(2, 1), 1); + ASSERTF4(f4_logicalAnd(PI_SHORT, PI_SHORT), 1); + ASSERTF4(f4_logicalAnd(PI_SHORT, 0), 0.0); } #endif #ifdef HAS_FLOAT -TEST biopLogicOrf4f4_Main() +TEST f4_logicalOr_Main() { - extern f4 biopLogicOrf4f4(f4 lhs, f4 rhs); - ASSERTF4(biopLogicOrf4f4(2, 1), 1); - ASSERTF4(biopLogicOrf4f4(PI_SHORT, PI_SHORT), 1); - ASSERTF4(biopLogicOrf4f4(PI_SHORT, 0), 1); + extern f4 f4_logicalOr(f4 lhs, f4 rhs); + ASSERTF4(f4_logicalOr(2, 1), 1); + ASSERTF4(f4_logicalOr(PI_SHORT, PI_SHORT), 1); + ASSERTF4(f4_logicalOr(PI_SHORT, 0), 1); } #endif #ifdef HAS_FLOAT -TEST biopLogicAndf4f4_Main() +TEST f4_logicalNot_Main() { - extern f4 biopLogicAndf4f4(f4 lhs, f4 rhs); - ASSERTF4(biopLogicAndf4f4(2, 1), 1); - ASSERTF4(biopLogicAndf4f4(PI_SHORT, PI_SHORT), 1); - ASSERTF4(biopLogicAndf4f4(PI_SHORT, 0), 0.0); + extern f4 f4_logicalNot(f4 lhs); + ASSERTF4(f4_logicalNot(2), 0); + ASSERTF4(f4_logicalNot(PI_SHORT), 0); +} +#endif + +/* Arithmetic operators */ +#ifdef HAS_FLOAT +TEST f4_unaryMinus_Main() +{ + extern f4 f4_unaryMinus(f4 lhs); + ASSERTF4(f4_unaryMinus(2), -2); + ASSERTF4(f4_unaryMinus(PI_SHORT), -3.14); } #endif #ifdef HAS_FLOAT -TEST unopNotf4_Main() +TEST f4_unaryPlus_Main() { - extern f4 unopNotf4(f4 lhs); - ASSERTF4(unopNotf4(2), 0); - ASSERTF4(unopNotf4(PI_SHORT), 0); + extern f4 f4_unaryPlus(f4 lhs); + ASSERTF4(f4_unaryPlus(2), 2); + ASSERTF4(f4_unaryPlus(PI_SHORT), PI_SHORT); } #endif #ifdef HAS_FLOAT -TEST unopNegativef4_Main() +TEST f4_addition_Main() { - extern f4 unopNegativef4(f4 lhs); - ASSERTF4(unopNegativef4(2), -2); - ASSERTF4(unopNegativef4(PI_SHORT), -3.14); + extern f4 f4_addition(f4 lhs, f4 rhs); + ASSERTF4(f4_addition(2, 1), 3); + ASSERTF4(f4_addition(PI_SHORT, PI_SHORT), 6.280000); } #endif #ifdef HAS_FLOAT -TEST unopPlusf4_Main() +TEST f4_subtract_Main() { - extern f4 unopPlusf4(f4 lhs); - ASSERTF4(unopPlusf4(2), 2); - ASSERTF4(unopPlusf4(PI_SHORT), PI_SHORT); + extern f4 f4_subtract(f4 lhs, f4 rhs); + ASSERTF4(f4_subtract(2, 1), 1); + ASSERTF4(f4_subtract(PI_SHORT, PI_SHORT), 0.0); } #endif #ifdef HAS_FLOAT -TEST biopMultf4f4_Main() +TEST f4_multiply_Main() { - extern f4 biopMultf4f4(f4 lhs, f4 rhs); - ASSERTF4(biopMultf4f4(2, 1), 2); - ASSERTF4(biopMultf4f4(PI_SHORT, PI_SHORT), 9.859601); -} -#endif - -#ifdef HAS_FLOAT -TEST biopSubf4f4_Main() -{ - extern f4 biopSubf4f4(f4 lhs, f4 rhs); - ASSERTF4(biopSubf4f4(2, 1), 1); - ASSERTF4(biopSubf4f4(PI_SHORT, PI_SHORT), 0.0); -} -#endif - -#ifdef HAS_FLOAT -TEST biopAddf4f4_Main() -{ - extern f4 biopAddf4f4(f4 lhs, f4 rhs); - ASSERTF4(biopAddf4f4(2, 1), 3); - ASSERTF4(biopAddf4f4(PI_SHORT, PI_SHORT), 6.280000); -} -#endif - -#ifdef HAS_FLOAT -TEST biopGtf4f4_Main() -{ - extern f4 biopGtf4f4(f4 lhs, f4 rhs); - ASSERTF4(biopGtf4f4(2, 1), 1); - ASSERTF4(biopGtf4f4(PI_SHORT, PI_SHORT), 0.0); - ASSERTF4(biopGtf4f4(PI_SHORT, 2*PI_SHORT), 0.0); - ASSERTF4(biopGtf4f4(2*PI_SHORT, PI_SHORT), 1.0); -} -#endif - -#ifdef HAS_FLOAT -TEST biopGef4f4_Main() -{ - extern f4 biopGef4f4(f4 lhs, f4 rhs); - ASSERTF4(biopGef4f4(2, 1), 1); - ASSERTF4(biopGef4f4(PI_SHORT, PI_SHORT), 1.0); - ASSERTF4(biopGef4f4(PI_SHORT, 2*PI_SHORT), 0.0); - ASSERTF4(biopGef4f4(2*PI_SHORT, PI_SHORT), 1.0); + extern f4 f4_multiply(f4 lhs, f4 rhs); + ASSERTF4(f4_multiply(2, 1), 2); + ASSERTF4(f4_multiply(PI_SHORT, PI_SHORT), 9.859601); } #endif diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_FLOAT_BODY.c b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_FLOAT_BODY.c index be762c9c47..e4bb5dac78 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_FLOAT_BODY.c +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_FLOAT_BODY.c @@ -16,7 +16,7 @@ #include "pcode_test.h" #ifdef HAS_FLOAT -f4 biopCmpf4f4(f4 lhs, f4 rhs) +f4 f4_compareLogic(f4 lhs, f4 rhs) { if (lhs < 0) lhs += 2; @@ -29,7 +29,7 @@ f4 biopCmpf4f4(f4 lhs, f4 rhs) return lhs; } -f8 biopCmpf8f8(f8 lhs, f8 rhs) +f8 f8_compareLogic(f8 lhs, f8 rhs) { if (lhs < 0) lhs += 2; @@ -42,103 +42,8 @@ f8 biopCmpf8f8(f8 lhs, f8 rhs) return lhs; } -f4 biopLtf4f4(f4 lhs, f4 rhs) -{ - f4 z; - - z = lhs < rhs; - return z; -} - -f4 biopLef4f4(f4 lhs, f4 rhs) -{ - f4 z; - - z = lhs <= rhs; - return z; -} - -f4 biopEqf4f4(f4 lhs, f4 rhs) -{ - f4 z; - - z = lhs == rhs; - return z; -} - -f4 biopNef4f4(f4 lhs, f4 rhs) -{ - f4 z; - - z = lhs != rhs; - return z; -} - -f4 biopLogicOrf4f4(f4 lhs, f4 rhs) -{ - f4 z; - - z = lhs || rhs; - return z; -} - -f4 biopLogicAndf4f4(f4 lhs, f4 rhs) -{ - f4 z; - - z = lhs && rhs; - return z; -} - -f4 unopNotf4(f4 lhs) -{ - f4 z; - - z = !lhs; - return z; -} - -f4 unopNegativef4(f4 lhs) -{ - f4 z; - - z = -lhs; - return z; -} - -f4 unopPlusf4(f4 lhs) -{ - f4 z; - - z = +lhs; - return z; -} - -f4 biopMultf4f4(f4 lhs, f4 rhs) -{ - f4 z; - - z = lhs * rhs; - return z; -} - -f4 biopSubf4f4(f4 lhs, f4 rhs) -{ - f4 z; - - z = lhs - rhs; - return z; -} - -f4 biopAddf4f4(f4 lhs, f4 rhs) -{ - f4 z; - - z = lhs + rhs; - return z; -} - -f4 biopGtf4f4(f4 lhs, f4 rhs) +/* Comparison operators */ +f4 f4_greaterThan(f4 lhs, f4 rhs) { f4 z; @@ -146,7 +51,7 @@ f4 biopGtf4f4(f4 lhs, f4 rhs) return z; } -f4 biopGef4f4(f4 lhs, f4 rhs) +f4 f4_greaterThanEquals(f4 lhs, f4 rhs) { f4 z; @@ -154,4 +59,102 @@ f4 biopGef4f4(f4 lhs, f4 rhs) return z; } +f4 f4_lessThan(f4 lhs, f4 rhs) +{ + f4 z; + + z = lhs < rhs; + return z; +} + +f4 f4_lessThanEquals(f4 lhs, f4 rhs) +{ + f4 z; + + z = lhs <= rhs; + return z; +} + +f4 f4_equals(f4 lhs, f4 rhs) +{ + f4 z; + + z = lhs == rhs; + return z; +} + +f4 f4_notEquals(f4 lhs, f4 rhs) +{ + f4 z; + + z = lhs != rhs; + return z; +} + +/* Logical operators */ +f4 f4_logicalAnd(f4 lhs, f4 rhs) +{ + f4 z; + + z = lhs && rhs; + return z; +} + +f4 f4_logicalOr(f4 lhs, f4 rhs) +{ + f4 z; + + z = lhs || rhs; + return z; +} + +f4 f4_logicalNot(f4 lhs) +{ + f4 z; + + z = !lhs; + return z; +} + +/* Arithmetic operators */ +f4 f4_unaryMinus(f4 lhs) +{ + f4 z; + + z = -lhs; + return z; +} + +f4 f4_unaryPlus(f4 lhs) +{ + f4 z; + + z = +lhs; + return z; +} + +f4 f4_addition(f4 lhs, f4 rhs) +{ + f4 z; + + z = lhs + rhs; + return z; +} + +f4 f4_subtract(f4 lhs, f4 rhs) +{ + f4 z; + + z = lhs - rhs; + return z; +} + +f4 f4_multiply(f4 lhs, f4 rhs) +{ + f4 z; + + z = lhs * rhs; + return z; +} + #endif /* #ifdef HAS_FLOAT */ diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_LONGLONG.test b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_LONGLONG.test index c82168fb36..af259a99ed 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_LONGLONG.test +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_LONGLONG.test @@ -1,530 +1,532 @@ #include "pcode_test.h" #ifdef HAS_LONGLONG -TEST pcode_i8_complexLogic_Main() +TEST i8_complexLogic_Main() { - extern i8 pcode_i8_complexLogic(i8 a, i8 b, i8 c, i8 d, i8 e, i8 f); - ASSERTI8(pcode_i8_complexLogic(-1916250774LL, 1528806445LL, -870305000LL, 0, 0, 1799560997LL), 14); - ASSERTI8(pcode_i8_complexLogic(-1375179334LL, -1539942439LL, 987987334LL, 0, 1162088421LL, 12548159LL), 15); - ASSERTI8(pcode_i8_complexLogic(0, -750167716LL, -1104561852LL, 0, -915711850LL, 737703662LL), 11); - ASSERTI8(pcode_i8_complexLogic(0, 386839851LL, -771476364LL, 0, -942724790LL, 1833488263LL), 10); + extern i8 i8_complexLogic(i8 a, i8 b, i8 c, i8 d, i8 e, i8 f); + ASSERTI8(i8_complexLogic(-1916250774LL, 1528806445LL, -870305000LL, 0, 0, 1799560997LL), 14); + ASSERTI8(i8_complexLogic(-1375179334LL, -1539942439LL, 987987334LL, 0, 1162088421LL, 12548159LL), 15); + ASSERTI8(i8_complexLogic(0, -750167716LL, -1104561852LL, 0, -915711850LL, 737703662LL), 11); + ASSERTI8(i8_complexLogic(0, 386839851LL, -771476364LL, 0, -942724790LL, 1833488263LL), 10); } #endif #ifdef HAS_LONGLONG -TEST pcode_u8_complexLogic_Main() +TEST u8_complexLogic_Main() { - extern u8 pcode_u8_complexLogic(u8 a, u8 b, u8 c, u8 d, u8 e, u8 f); - ASSERTU8(pcode_u8_complexLogic(2016764524ULL, 1717226057ULL, 1748349614ULL, 0, 1276673168ULL, 0), 15); - ASSERTU8(pcode_u8_complexLogic(2009726312ULL, 696947386ULL, 0, 0, 1265204346ULL, 1369602726ULL), 11); - ASSERTU8(pcode_u8_complexLogic(1665204916ULL, 1707056552ULL, 564325578ULL, 0, 0, 1010528946ULL), 14); - ASSERTU8(pcode_u8_complexLogic(0, 1516266761ULL, 1866000081ULL, 0, 1175526309ULL, 1586903190ULL), 10); + extern u8 u8_complexLogic(u8 a, u8 b, u8 c, u8 d, u8 e, u8 f); + ASSERTU8(u8_complexLogic(2016764524ULL, 1717226057ULL, 1748349614ULL, 0, 1276673168ULL, 0), 15); + ASSERTU8(u8_complexLogic(2009726312ULL, 696947386ULL, 0, 0, 1265204346ULL, 1369602726ULL), 11); + ASSERTU8(u8_complexLogic(1665204916ULL, 1707056552ULL, 564325578ULL, 0, 0, 1010528946ULL), 14); + ASSERTU8(u8_complexLogic(0, 1516266761ULL, 1866000081ULL, 0, 1175526309ULL, 1586903190ULL), 10); } #endif #ifdef HAS_LONGLONG -TEST biopCmpi8i8_Main() +TEST i8_compareLogic_Main() { - extern i8 biopCmpi8i8(i8 lhs, i8 rhs); - ASSERTI8(biopCmpi8i8(0x1, 0x1), 21); - ASSERTI8(biopCmpi8i8(0x1, 0x2), 21); - ASSERTI8(biopCmpi8i8(0x2, 0x1), 22); - ASSERTI8(biopCmpi8i8(-0x1, -0x1), 21); - ASSERTI8(biopCmpi8i8(-0x1, -0x2), 21); - ASSERTI8(biopCmpi8i8(-0x2, -0x1), 24); + extern i8 i8_compareLogic(i8 lhs, i8 rhs); + ASSERTI8(i8_compareLogic(0x1, 0x1), 21); + ASSERTI8(i8_compareLogic(0x1, 0x2), 21); + ASSERTI8(i8_compareLogic(0x2, 0x1), 22); + ASSERTI8(i8_compareLogic(-0x1, -0x1), 21); + ASSERTI8(i8_compareLogic(-0x1, -0x2), 21); + ASSERTI8(i8_compareLogic(-0x2, -0x1), 24); } #endif #ifdef HAS_LONGLONG -TEST biopCmpu8u8_Main() +TEST u8_compareLogic_Main() { - extern u8 biopCmpu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopCmpu8u8(0x1, 0x1), 1); - ASSERTU8(biopCmpu8u8(0x1, 0x2), 23); - ASSERTU8(biopCmpu8u8(0x2, 0x1), 22); + extern u8 u8_compareLogic(u8 lhs, u8 rhs); + ASSERTU8(u8_compareLogic(0x1, 0x1), 1); + ASSERTU8(u8_compareLogic(0x1, 0x2), 23); + ASSERTU8(u8_compareLogic(0x2, 0x1), 22); +} +#endif +/* Comparison operators */ +#ifdef HAS_LONGLONG +TEST u8_greaterThan_Main() +{ + extern u8 u8_greaterThan(u8 lhs, u8 rhs); + ASSERTU8(u8_greaterThan(2, 1), 1); + ASSERTU8(u8_greaterThan(U8_MAX, 0), 1); + ASSERTU8(u8_greaterThan(U8_MAX, U8_MAX), 0); + ASSERTU8(u8_greaterThan(0, U8_MAX), 0); } #endif #ifdef HAS_LONGLONG -TEST biopNei8i8_Main() +TEST u8_greaterThanEquals_Main() { - extern i8 biopNei8i8(i8 lhs, i8 rhs); - ASSERTI8(biopNei8i8(2, 1), 1); - ASSERTI8(biopNei8i8(0x0101010101010101LL, 0x0101010101010101LL), 0); - ASSERTI8(biopNei8i8(0x0101010101010101LL, -0x0101010101010101LL), 1); - ASSERTI8(biopNei8i8(I8_MAX, I8_MAX), 0); - ASSERTI8(biopNei8i8(I8_MAX, I8_MIN), 1); - ASSERTI8(biopNei8i8(I8_MIN, I8_MAX), 1); + extern u8 u8_greaterThanEquals(u8 lhs, u8 rhs); + ASSERTU8(u8_greaterThanEquals(2, 1), 1); + ASSERTU8(u8_greaterThanEquals(U8_MAX, U8_MAX), 1); + ASSERTU8(u8_greaterThanEquals(U8_MAX, U8_MIN), 1); + ASSERTU8(u8_greaterThanEquals(U8_MIN, U8_MAX), 0); } #endif #ifdef HAS_LONGLONG -TEST biopAndu8u8_Main() +TEST u8_lessThan_Main() { - extern u8 biopAndu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopAndu8u8(2, 1), 0); - ASSERTU8(biopAndu8u8(U8_MAX, U8_MAX), U8_MAX); - ASSERTU8(biopAndu8u8(U8_MAX, 0), 0); - ASSERTU8(biopAndu8u8(U8_MAX, 1), 1); + extern u8 u8_lessThan(u8 lhs, u8 rhs); + ASSERTU8(u8_lessThan(2, 1), 0); + ASSERTU8(u8_lessThan(U8_MAX, U8_MAX), 0); + ASSERTU8(u8_lessThan(U8_MAX, U8_MIN), 0); + ASSERTU8(u8_lessThan(U8_MIN, U8_MAX), 1); } #endif #ifdef HAS_LONGLONG -TEST biopAndi8i8_Main() +TEST u8_lessThanEquals_Main() { - extern i8 biopAndi8i8(i8 lhs, i8 rhs); - ASSERTI8(biopAndi8i8(2, 1), 0); - ASSERTI8(biopAndi8i8(0x0101010101010101LL, 0x0101010101010101LL), 0x0101010101010101); - ASSERTI8(biopAndi8i8(I8_MAX, I8_MAX), I8_MAX); - ASSERTI8(biopAndi8i8(I8_MAX, I8_MIN), 0); - ASSERTI8(biopAndi8i8(I8_MAX, 0), 0); + extern u8 u8_lessThanEquals(u8 lhs, u8 rhs); + ASSERTU8(u8_lessThanEquals(2, 1), 0); + ASSERTU8(u8_lessThanEquals(U8_MAX, U8_MAX), 1); + ASSERTU8(u8_lessThanEquals(U8_MAX, U8_MIN), 0); + ASSERTU8(u8_lessThanEquals(U8_MIN, U8_MAX), 1); } #endif #ifdef HAS_LONGLONG -TEST biopOru8u8_Main() +TEST u8_equals_Main() { - extern u8 biopOru8u8(u8 lhs, u8 rhs); - ASSERTU8(biopOru8u8(2, 1), 3); - ASSERTU8(biopOru8u8(U8_MAX, U8_MAX), U8_MAX); - ASSERTU8(biopOru8u8(U8_MAX, U8_MIN), 18446744073709551615ULL); - ASSERTU8(biopOru8u8(U8_MAX, 0), 18446744073709551615ULL); + extern u8 u8_equals(u8 lhs, u8 rhs); + ASSERTU8(u8_equals(2, 1), 0); + ASSERTU8(u8_equals(U8_MAX, U8_MAX), 1); + ASSERTU8(u8_equals(U8_MAX, U8_MIN), 0); + ASSERTU8(u8_equals(U8_MIN, U8_MAX), 0); } #endif #ifdef HAS_LONGLONG -TEST biopXOru8u8_Main() +TEST u8_notEquals_Main() { - extern u8 biopXOru8u8(u8 lhs, u8 rhs); - ASSERTU8(biopXOru8u8(2, 1), 3); - ASSERTU8(biopXOru8u8(U8_MAX, U8_MAX), 0); - ASSERTU8(biopXOru8u8(U8_MAX, 0), U8_MAX); - ASSERTU8(biopXOru8u8(U8_MAX, 2), 18446744073709551613ULL); + extern u8 u8_notEquals(u8 lhs, u8 rhs); + ASSERTU8(u8_notEquals(2, 1), 1); + ASSERTU8(u8_notEquals(U8_MAX, U8_MAX), 0); + ASSERTU8(u8_notEquals(U8_MAX, U8_MIN), 1); + ASSERTU8(u8_notEquals(U8_MIN, U8_MAX), 1); } #endif #ifdef HAS_LONGLONG -TEST biopOri8i8_Main() +TEST i8_greaterThan_Main() { - extern i8 biopOri8i8(i8 lhs, i8 rhs); - ASSERTI8(biopOri8i8(2, 1), 3); - ASSERTI8(biopOri8i8(0x0101010101010101LL, 0x0101010101010101LL), 0x0101010101010101LL); - ASSERTI8(biopOri8i8(0x0101010101010101LL, 0x0), 0x0101010101010101LL); - ASSERTI8(biopOri8i8(U8_MAX, U8_MAX), -1); - ASSERTI8(biopOri8i8(U8_MAX, U8_MIN), -1); - ASSERTI8(biopOri8i8(U8_MAX, 0), -1); - ASSERTI8(biopOri8i8(U8_MAX, 4), -1); + extern i8 i8_greaterThan(i8 lhs, i8 rhs); + ASSERTI8(i8_greaterThan(0x0101010101010101LL, 0x0101010101010101LL), 0); + ASSERTI8(i8_greaterThan(0x0101010101010101LL, -0x0101010101010101LL), 1); + ASSERTI8(i8_greaterThan(2, 1), 1); + ASSERTI8(i8_greaterThan(I8_MAX, I8_MAX), 0); + ASSERTI8(i8_greaterThan(I8_MAX, I8_MIN), 1); + ASSERTI8(i8_greaterThan(I8_MIN, I8_MAX), 0); } #endif #ifdef HAS_LONGLONG -TEST biopLogicOru8u8_Main() +TEST i8_greaterThanEquals_Main() { - extern u8 biopLogicOru8u8(u8 lhs, u8 rhs); - ASSERTU8(biopLogicOru8u8(2, 1), 1); - ASSERTU8(biopLogicOru8u8(U8_MAX, U8_MAX), 1); - ASSERTU8(biopLogicOru8u8(U8_MIN, U8_MIN), 0); - ASSERTU8(biopLogicOru8u8(U8_MIN, 0), 0); + extern i8 i8_greaterThanEquals(i8 lhs, i8 rhs); + ASSERTI8(i8_greaterThanEquals(2, 1), 1); + ASSERTI8(i8_greaterThanEquals(I8_MAX, I8_MAX), 1); + ASSERTI8(i8_greaterThanEquals(I8_MAX, I8_MIN), 1); + ASSERTI8(i8_greaterThanEquals(I8_MIN, I8_MAX), 0); } #endif #ifdef HAS_LONGLONG -TEST biopXOri8i8_Main() +TEST i8_lessThan_Main() { - extern i8 biopXOri8i8(i8 lhs, i8 rhs); - ASSERTI8(biopXOri8i8(2, 1), 3); - ASSERTI8(biopXOri8i8(0x0101010101010101LL, 0x0101010101010101LL), 0); - ASSERTI8(biopXOri8i8(0x0101010101010101LL, 0x0101010101010101LL), 0x0); - ASSERTI8(biopXOri8i8(U8_MAX, U8_MAX), 0x0); - ASSERTI8(biopXOri8i8(U8_MAX, U8_MIN), -1); - ASSERTI8(biopXOri8i8(U8_MAX, 0), -1); - ASSERTI8(biopXOri8i8(U8_MAX, 5), -6); + extern i8 i8_lessThan(i8 lhs, i8 rhs); + ASSERTI8(i8_lessThan(0x0101010101010101LL, 0x0101010101010101LL), 0); + ASSERTI8(i8_lessThan(0x0101010101010101LL, -0x0101010101010101LL), 0); + ASSERTI8(i8_lessThan(2, 1), 0); + ASSERTI8(i8_lessThan(I8_MAX, I8_MAX), 0); + ASSERTI8(i8_lessThan(I8_MAX, I8_MIN), 0); + ASSERTI8(i8_lessThan(I8_MIN, I8_MAX), 1); } #endif #ifdef HAS_LONGLONG -TEST biopRemainderi8i8_Main() +TEST i8_lessThanEquals_Main() { - extern i8 biopRemainderi8i8(i8 lhs, i8 rhs); - ASSERTI8(biopRemainderi8i8(0x0101010101010101LL, 0x0101010101010101LL), 0x0); - ASSERTI8(biopRemainderi8i8(0x0101010101010101LL, 0x0001010101010101LL), 0x1); - ASSERTI8(biopRemainderi8i8(0x0101010101010101LL, 0x0001010101010100LL), 0x101); - ASSERTI8(biopRemainderi8i8(I8_MAX, I8_MAX), 0); - ASSERTI8(biopRemainderi8i8(I8_MAX, 1), 0); - ASSERTI8(biopRemainderi8i8(I8_MAX, I8_MIN), 9223372036854775807); - ASSERTI8(biopRemainderi8i8(I8_MAX, 0xFFFF), 32767); + extern i8 i8_lessThanEquals(i8 lhs, i8 rhs); + ASSERTI8(i8_lessThanEquals(2, 1), 0); + ASSERTI8(i8_lessThanEquals(0x0101010101010101LL, 0x0101010101010101LL), 1); + ASSERTI8(i8_lessThanEquals(0x0101010101010101LL, -0x0101010101010101LL), 0); + ASSERTI8(i8_lessThanEquals(I8_MAX, I8_MAX), 1); + ASSERTI8(i8_lessThanEquals(I8_MAX, I8_MIN), 0); + ASSERTI8(i8_lessThanEquals(I8_MIN, I8_MAX), 1); } #endif #ifdef HAS_LONGLONG -TEST biopLogicOri8i8_Main() +TEST i8_equals_Main() { - extern i8 biopLogicOri8i8(i8 lhs, i8 rhs); - ASSERTI8(biopLogicOri8i8(2, 1), 1); - ASSERTI8(biopLogicOri8i8(0x0101010101010101LL, 0x0101010101010101LL), 1); - ASSERTI8(biopLogicOri8i8(I8_MAX, I8_MAX), 1); - ASSERTI8(biopLogicOri8i8(I8_MAX, I8_MIN), 1); - ASSERTI8(biopLogicOri8i8(I8_MAX, 0), 1); - ASSERTI8(biopLogicOri8i8(I8_MAX, 5), 1); + extern i8 i8_equals(i8 lhs, i8 rhs); + ASSERTI8(i8_equals(2, 1), 0); + ASSERTI8(i8_equals(0x0101010101010101LL, 0x0101010101010101LL), 1); + ASSERTI8(i8_equals(0x0101010101010101LL, -0x0101010101010101LL), 0); + ASSERTI8(i8_equals(I8_MAX, I8_MAX), 1); + ASSERTI8(i8_equals(I8_MAX, I8_MIN), 0); + ASSERTI8(i8_equals(I8_MIN, I8_MAX), 0); } #endif #ifdef HAS_LONGLONG -TEST biopLogicAndu8u8_Main() +TEST i8_notEquals_Main() { - extern u8 biopLogicAndu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopLogicAndu8u8(2, 1), 1); - ASSERTU8(biopLogicAndu8u8(U8_MAX, U8_MAX), 1); - ASSERTU8(biopLogicAndu8u8(U8_MAX, 0), 0); - ASSERTU8(biopLogicAndu8u8(U8_MAX, 5), 1); + extern i8 i8_notEquals(i8 lhs, i8 rhs); + ASSERTI8(i8_notEquals(2, 1), 1); + ASSERTI8(i8_notEquals(0x0101010101010101LL, 0x0101010101010101LL), 0); + ASSERTI8(i8_notEquals(0x0101010101010101LL, -0x0101010101010101LL), 1); + ASSERTI8(i8_notEquals(I8_MAX, I8_MAX), 0); + ASSERTI8(i8_notEquals(I8_MAX, I8_MIN), 1); + ASSERTI8(i8_notEquals(I8_MIN, I8_MAX), 1); +} +#endif + +/* Bitwise operators */ +#ifdef HAS_LONGLONG +TEST u8_bitwiseAnd_Main() +{ + extern u8 u8_bitwiseAnd(u8 lhs, u8 rhs); + ASSERTU8(u8_bitwiseAnd(2, 1), 0); + ASSERTU8(u8_bitwiseAnd(U8_MAX, U8_MAX), U8_MAX); + ASSERTU8(u8_bitwiseAnd(U8_MAX, 0), 0); + ASSERTU8(u8_bitwiseAnd(U8_MAX, 1), 1); } #endif #ifdef HAS_LONGLONG -TEST biopDividi8i8_Main() +TEST u8_bitwiseOr_Main() { - extern i8 biopDividi8i8(i8 lhs, i8 rhs); - ASSERTI8(biopDividi8i8(0x0101010101010101LL, 0x0101010101010101LL), 0x1); - ASSERTI8(biopDividi8i8(-0x0101010101010101LL, 0x0101010101010101LL), -0x1); - ASSERTI8(biopDividi8i8(0, 0x0101010101010101LL), 0); - ASSERTI8(biopDividi8i8(0x0101010101010101LL, 2), 0x80808080808080); - ASSERTI8(biopDividi8i8(I8_MAX, I8_MAX), 1); - ASSERTI8(biopDividi8i8(I8_MAX, I8_MIN), 0); - ASSERTI8(biopDividi8i8(0, I8_MAX), 0); - ASSERTI8(biopDividi8i8(I8_MAX, 5), 1844674407370955161LL); + extern u8 u8_bitwiseOr(u8 lhs, u8 rhs); + ASSERTU8(u8_bitwiseOr(2, 1), 3); + ASSERTU8(u8_bitwiseOr(U8_MAX, U8_MAX), U8_MAX); + ASSERTU8(u8_bitwiseOr(U8_MAX, U8_MIN), 18446744073709551615ULL); + ASSERTU8(u8_bitwiseOr(U8_MAX, 0), 18446744073709551615ULL); } #endif #ifdef HAS_LONGLONG -TEST biopDividu8u8_Main() +TEST u8_bitwiseXor_Main() { - extern u8 biopDividu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopDividu8u8(0x0101010101010101ULL, 0x0101010101010101ULL), 0x1); - ASSERTU8(biopDividu8u8(-0x0101010101010101ULL, 0x0101010101010101ULL), 254); - ASSERTU8(biopDividu8u8(0, 0x0101010101010101ULL), 0); - ASSERTU8(biopDividu8u8(0x0101010101010101ULL, 2), 0x80808080808080); - ASSERTU8(biopDividu8u8(U8_MAX, U8_MAX), 1); - ASSERTU8(biopDividu8u8(0, U8_MAX), 0); - ASSERTU8(biopDividu8u8(U8_MAX, 5), 3689348814741910323ULL); + extern u8 u8_bitwiseXor(u8 lhs, u8 rhs); + ASSERTU8(u8_bitwiseXor(2, 1), 3); + ASSERTU8(u8_bitwiseXor(U8_MAX, U8_MAX), 0); + ASSERTU8(u8_bitwiseXor(U8_MAX, 0), U8_MAX); + ASSERTU8(u8_bitwiseXor(U8_MAX, 2), 18446744073709551613ULL); } #endif #ifdef HAS_LONGLONG -TEST biopLogicAndi8i8_Main() +TEST i8_bitwiseAnd_Main() { - extern i8 biopLogicAndi8i8(i8 lhs, i8 rhs); - ASSERTI8(biopLogicAndi8i8(0x0101010101010101LL, 0x0101010101010101LL), 1); - ASSERTI8(biopLogicAndi8i8(0x0101010101010101LL, 0x0), 0); - ASSERTI8(biopLogicAndi8i8(2, 1), 1); - ASSERTI8(biopLogicAndi8i8(I8_MAX, I8_MAX), 1); - ASSERTI8(biopLogicAndi8i8(I8_MAX, I8_MIN), 1); - ASSERTI8(biopLogicAndi8i8(I8_MAX, 0), 0); + extern i8 i8_bitwiseAnd(i8 lhs, i8 rhs); + ASSERTI8(i8_bitwiseAnd(2, 1), 0); + ASSERTI8(i8_bitwiseAnd(0x0101010101010101LL, 0x0101010101010101LL), 0x0101010101010101); + ASSERTI8(i8_bitwiseAnd(I8_MAX, I8_MAX), I8_MAX); + ASSERTI8(i8_bitwiseAnd(I8_MAX, I8_MIN), 0); + ASSERTI8(i8_bitwiseAnd(I8_MAX, 0), 0); } #endif #ifdef HAS_LONGLONG -TEST unopNotu8_Main() +TEST i8_bitwiseOr_Main() { - extern u8 unopNotu8(u8 lhs); - ASSERTU8(unopNotu8(2), 0); + extern i8 i8_bitwiseOr(i8 lhs, i8 rhs); + ASSERTI8(i8_bitwiseOr(2, 1), 3); + ASSERTI8(i8_bitwiseOr(0x0101010101010101LL, 0x0101010101010101LL), 0x0101010101010101LL); + ASSERTI8(i8_bitwiseOr(0x0101010101010101LL, 0x0), 0x0101010101010101LL); + ASSERTI8(i8_bitwiseOr(U8_MAX, U8_MAX), -1); + ASSERTI8(i8_bitwiseOr(U8_MAX, U8_MIN), -1); + ASSERTI8(i8_bitwiseOr(U8_MAX, 0), -1); + ASSERTI8(i8_bitwiseOr(U8_MAX, 4), -1); } #endif #ifdef HAS_LONGLONG -TEST unopNoti8_Main() +TEST i8_bitwiseXor_Main() { - extern i8 unopNoti8(i8 lhs); - ASSERTI8(unopNoti8(0x0101010101010101LL), 0); - ASSERTI8(unopNoti8(2), 0); - ASSERTI8(unopNoti8(I8_MAX), 0); - ASSERTI8(unopNoti8(I8_MIN), 0); - ASSERTI8(unopNoti8(0), 1); + extern i8 i8_bitwiseXor(i8 lhs, i8 rhs); + ASSERTI8(i8_bitwiseXor(2, 1), 3); + ASSERTI8(i8_bitwiseXor(0x0101010101010101LL, 0x0101010101010101LL), 0); + ASSERTI8(i8_bitwiseXor(0x0101010101010101LL, 0x0101010101010101LL), 0x0); + ASSERTI8(i8_bitwiseXor(U8_MAX, U8_MAX), 0x0); + ASSERTI8(i8_bitwiseXor(U8_MAX, U8_MIN), -1); + ASSERTI8(i8_bitwiseXor(U8_MAX, 0), -1); + ASSERTI8(i8_bitwiseXor(U8_MAX, 5), -6); +} +#endif + +/* Logical operators */ +#ifdef HAS_LONGLONG +TEST u8_logicalAnd_Main() +{ + extern u8 u8_logicalAnd(u8 lhs, u8 rhs); + ASSERTU8(u8_logicalAnd(2, 1), 1); + ASSERTU8(u8_logicalAnd(U8_MAX, U8_MAX), 1); + ASSERTU8(u8_logicalAnd(U8_MAX, 0), 0); + ASSERTU8(u8_logicalAnd(U8_MAX, 5), 1); } #endif #ifdef HAS_LONGLONG -TEST unopPlusu8_Main() +TEST u8_logicalOr_Main() { - extern u8 unopPlusu8(u8 lhs); - ASSERTU8(unopPlusu8(2), 2); - ASSERTU8(unopPlusu8(U8_MAX), U8_MAX); - ASSERTU8(unopPlusu8(0), 0); + extern u8 u8_logicalOr(u8 lhs, u8 rhs); + ASSERTU8(u8_logicalOr(2, 1), 1); + ASSERTU8(u8_logicalOr(U8_MAX, U8_MAX), 1); + ASSERTU8(u8_logicalOr(U8_MIN, U8_MIN), 0); + ASSERTU8(u8_logicalOr(U8_MIN, 0), 0); } #endif #ifdef HAS_LONGLONG -TEST unopNegativei8_Main() +TEST u8_logicalNot_Main() { - extern i8 unopNegativei8(i8 lhs); - ASSERTI8(unopNegativei8(2), -2); - ASSERTI8(unopNegativei8(0x0101010101010101LL), -0x0101010101010101LL); - ASSERTI8(unopNegativei8(-0x0101010101010101LL), 0x0101010101010101LL); - ASSERTI8(unopNegativei8(I8_MAX), I8_MIN+1); - ASSERTI8(unopNegativei8(I8_MIN), I8_MIN); - ASSERTI8(unopNegativei8(0), 0); + extern u8 u8_logicalNot(u8 lhs); + ASSERTU8(u8_logicalNot(2), 0); } #endif #ifdef HAS_LONGLONG -TEST unopPlusi8_Main() +TEST i8_logicalAnd_Main() { - extern i8 unopPlusi8(i8 lhs); - ASSERTI8(unopPlusi8(2), 2); - ASSERTI8(unopPlusi8(0x0101010101010101LL), 0x0101010101010101LL); - ASSERTI8(unopPlusi8(-0x0101010101010101LL), -0x0101010101010101LL); - ASSERTI8(unopPlusi8(I8_MAX), I8_MAX); - ASSERTI8(unopPlusi8(I8_MIN), I8_MIN); - ASSERTI8(unopPlusi8(0), 0); + extern i8 i8_logicalAnd(i8 lhs, i8 rhs); + ASSERTI8(i8_logicalAnd(0x0101010101010101LL, 0x0101010101010101LL), 1); + ASSERTI8(i8_logicalAnd(0x0101010101010101LL, 0x0), 0); + ASSERTI8(i8_logicalAnd(2, 1), 1); + ASSERTI8(i8_logicalAnd(I8_MAX, I8_MAX), 1); + ASSERTI8(i8_logicalAnd(I8_MAX, I8_MIN), 1); + ASSERTI8(i8_logicalAnd(I8_MAX, 0), 0); } #endif #ifdef HAS_LONGLONG -TEST biopMultu8u8_Main() +TEST i8_logicalOr_Main() { - extern u8 biopMultu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopMultu8u8(2, 1), 2); - ASSERTU8(biopMultu8u8(U8_MAX, U8_MAX), 1); - ASSERTU8(biopMultu8u8(U8_MAX, U8_MIN), 0); - ASSERTU8(biopMultu8u8(U8_MAX, 0), 0); + extern i8 i8_logicalOr(i8 lhs, i8 rhs); + ASSERTI8(i8_logicalOr(2, 1), 1); + ASSERTI8(i8_logicalOr(0x0101010101010101LL, 0x0101010101010101LL), 1); + ASSERTI8(i8_logicalOr(I8_MAX, I8_MAX), 1); + ASSERTI8(i8_logicalOr(I8_MAX, I8_MIN), 1); + ASSERTI8(i8_logicalOr(I8_MAX, 0), 1); + ASSERTI8(i8_logicalOr(I8_MAX, 5), 1); } #endif #ifdef HAS_LONGLONG -TEST biopMulti8i8_Main() +TEST i8_logicalNot_Main() { - extern i8 biopMulti8i8(i8 lhs, i8 rhs); - ASSERTI8(biopMulti8i8(2, 1), 2); - ASSERTI8(biopMulti8i8(0x0101010101010101LL, 0x0101010101010101LL), 0x807060504030201LL); - ASSERTI8(biopMulti8i8(0, -0x0101010101010101LL), 0); - ASSERTI8(biopMulti8i8(0x0101010101010101LL, -0x0101010101010101LL), -0x807060504030201LL); - ASSERTI8(biopMulti8i8(I8_MAX, I8_MAX), 1); - ASSERTI8(biopMulti8i8(I8_MAX, I8_MIN), 0x8000000000000000LL); - - ASSERTI8(biopMulti8i8(I8_MAX, 0), 0); + extern i8 i8_logicalNot(i8 lhs); + ASSERTI8(i8_logicalNot(0x0101010101010101LL), 0); + ASSERTI8(i8_logicalNot(2), 0); + ASSERTI8(i8_logicalNot(I8_MAX), 0); + ASSERTI8(i8_logicalNot(I8_MIN), 0); + ASSERTI8(i8_logicalNot(0), 1); } #endif - - +/* Shift operators */ #ifdef HAS_LONGLONG -TEST biopSubu8u8_Main() +TEST u8_shiftLeft_Main() { - extern u8 biopSubu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopSubu8u8(2, 1), 1); - ASSERTU8(biopSubu8u8(U8_MAX, U8_MAX), 0); - ASSERTU8(biopSubu8u8(U8_MAX, 0), U8_MAX); - ASSERTU8(biopSubu8u8(0, U8_MAX), 1); + extern u8 u8_shiftLeft(u8 lhs, u8 rhs); + ASSERTU8(u8_shiftLeft(2, 1), 4); + ASSERTU8(u8_shiftLeft(U8_MAX, 0), U8_MAX); + ASSERTU8(u8_shiftLeft(0, 4), 0); } #endif #ifdef HAS_LONGLONG -TEST biopSubi8i8_Main() +TEST u8_shiftRight_Main() { - extern i8 biopSubi8i8(i8 lhs, i8 rhs); - ASSERTI8(biopSubi8i8(0x0101010101010101LL, 0x0101010101010100LL), 0x1); - ASSERTI8(biopSubi8i8(0x0001010101010100LL, 0x0101010101010101LL), -72057594037927937LL); - ASSERTI8(biopSubi8i8(2, 1), 1); - ASSERTI8(biopSubi8i8(0x0101010101010101LL, 0x0101010101010101LL), 0); - ASSERTI8(biopSubi8i8(I8_MAX, I8_MAX), 0); - ASSERTI8(biopSubi8i8(I8_MAX, I8_MIN), -1); - ASSERTI8(biopSubi8i8(I8_MAX, 0), I8_MAX); - ASSERTI8(biopSubi8i8(0, I8_MAX), -I8_MAX); + extern u8 u8_shiftRight(u8 lhs, u8 rhs); + ASSERTU8(u8_shiftRight(2, 1), 1); + ASSERTU8(u8_shiftRight(U8_MAX, 0), U8_MAX); + ASSERTU8(u8_shiftRight(0, 2), 0); + ASSERTU8(u8_shiftRight(2, 2), 0); } #endif #ifdef HAS_LONGLONG -TEST biopAddu8u8_Main() +TEST i8_shiftLeft_Main() { - extern u8 biopAddu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopAddu8u8(2, 1), 3); - ASSERTU8(biopAddu8u8(U8_MAX, U8_MAX), 18446744073709551614ULL); - ASSERTU8(biopAddu8u8(U8_MAX, 0), U8_MAX); + extern i8 i8_shiftLeft(i8 lhs, i8 rhs); + ASSERTI8(i8_shiftLeft(0x0101010101010101LL, 16), 0x101010101010000LL); + ASSERTI8(i8_shiftLeft(0x0101010101010101LL, 8), 0x101010101010100LL); + ASSERTI8(i8_shiftLeft(0x0101010101010101LL, 0), 0x101010101010101LL); + ASSERTI8(i8_shiftLeft(2, 1), 4); + ASSERTI8(i8_shiftLeft(I8_MAX, 0), I8_MAX); } #endif #ifdef HAS_LONGLONG -TEST biopShtLftu8u8_Main() +TEST i8_shiftRight_Main() { - extern u8 biopShtLftu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopShtLftu8u8(2, 1), 4); - ASSERTU8(biopShtLftu8u8(U8_MAX, 0), U8_MAX); - ASSERTU8(biopShtLftu8u8(0, 4), 0); + extern i8 i8_shiftRight(i8 lhs, i8 rhs); + ASSERTI8(i8_shiftRight(0x0101010101010101LL, 8), 0x1010101010101LL); + ASSERTI8(i8_shiftRight(0x0101010101010101LL, 16), 0x10101010101LL); + ASSERTI8(i8_shiftRight(0x0101010101010101LL, 0), 0x0101010101010101LL); + ASSERTI8(i8_shiftRight(2, 1), 1); + ASSERTI8(i8_shiftRight(I8_MAX, 0), I8_MAX); +} +#endif + +/* Arithmetic operators */ +#ifdef HAS_LONGLONG +TEST u8_unaryPlus_Main() +{ + extern u8 u8_unaryPlus(u8 lhs); + ASSERTU8(u8_unaryPlus(2), 2); + ASSERTU8(u8_unaryPlus(U8_MAX), U8_MAX); + ASSERTU8(u8_unaryPlus(0), 0); } #endif #ifdef HAS_LONGLONG -TEST biopAddi8i8_Main() +TEST u8_addition_Main() { - extern i8 biopAddi8i8(i8 lhs, i8 rhs); - ASSERTI8(biopAddi8i8(0x0101010101010101LL, 0x0101010101010101LL), 0x202020202020202LL); - ASSERTI8(biopAddi8i8(2, 1), 3); - ASSERTI8(biopAddi8i8(I8_MAX, I8_MAX), -2); - ASSERTI8(biopAddi8i8(I8_MAX, I8_MIN), -1); - ASSERTI8(biopAddi8i8(I8_MAX, 0), I8_MAX); + extern u8 u8_addition(u8 lhs, u8 rhs); + ASSERTU8(u8_addition(2, 1), 3); + ASSERTU8(u8_addition(U8_MAX, U8_MAX), 18446744073709551614ULL); + ASSERTU8(u8_addition(U8_MAX, 0), U8_MAX); } #endif #ifdef HAS_LONGLONG -TEST biopShtRhtu8u8_Main() +TEST u8_subtract_Main() { - extern u8 biopShtRhtu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopShtRhtu8u8(2, 1), 1); - ASSERTU8(biopShtRhtu8u8(U8_MAX, 0), U8_MAX); - ASSERTU8(biopShtRhtu8u8(0, 2), 0); - ASSERTU8(biopShtRhtu8u8(2, 2), 0); + extern u8 u8_subtract(u8 lhs, u8 rhs); + ASSERTU8(u8_subtract(2, 1), 1); + ASSERTU8(u8_subtract(U8_MAX, U8_MAX), 0); + ASSERTU8(u8_subtract(U8_MAX, 0), U8_MAX); + ASSERTU8(u8_subtract(0, U8_MAX), 1); } #endif #ifdef HAS_LONGLONG -TEST biopShtLfti8i8_Main() +TEST u8_multiply_Main() { - extern i8 biopShtLfti8i8(i8 lhs, i8 rhs); - ASSERTI8(biopShtLfti8i8(0x0101010101010101LL, 16), 0x101010101010000LL); - ASSERTI8(biopShtLfti8i8(0x0101010101010101LL, 8), 0x101010101010100LL); - ASSERTI8(biopShtLfti8i8(0x0101010101010101LL, 0), 0x101010101010101LL); - ASSERTI8(biopShtLfti8i8(2, 1), 4); - ASSERTI8(biopShtLfti8i8(I8_MAX, 0), I8_MAX); + extern u8 u8_multiply(u8 lhs, u8 rhs); + ASSERTU8(u8_multiply(2, 1), 2); + ASSERTU8(u8_multiply(U8_MAX, U8_MAX), 1); + ASSERTU8(u8_multiply(U8_MAX, U8_MIN), 0); + ASSERTU8(u8_multiply(U8_MAX, 0), 0); } #endif #ifdef HAS_LONGLONG -TEST biopShtRhti8i8_Main() +TEST u8_divide_Main() { - extern i8 biopShtRhti8i8(i8 lhs, i8 rhs); - ASSERTI8(biopShtRhti8i8(0x0101010101010101LL, 8), 0x1010101010101LL); - ASSERTI8(biopShtRhti8i8(0x0101010101010101LL, 16), 0x10101010101LL); - ASSERTI8(biopShtRhti8i8(0x0101010101010101LL, 0), 0x0101010101010101LL); - ASSERTI8(biopShtRhti8i8(2, 1), 1); - ASSERTI8(biopShtRhti8i8(I8_MAX, 0), I8_MAX); + extern u8 u8_divide(u8 lhs, u8 rhs); + ASSERTU8(u8_divide(0x0101010101010101ULL, 0x0101010101010101ULL), 0x1); + ASSERTU8(u8_divide(-0x0101010101010101ULL, 0x0101010101010101ULL), 254); + ASSERTU8(u8_divide(0, 0x0101010101010101ULL), 0); + ASSERTU8(u8_divide(0x0101010101010101ULL, 2), 0x80808080808080); + ASSERTU8(u8_divide(U8_MAX, U8_MAX), 1); + ASSERTU8(u8_divide(0, U8_MAX), 0); + ASSERTU8(u8_divide(U8_MAX, 5), 3689348814741910323ULL); } #endif #ifdef HAS_LONGLONG -TEST biopGtu8u8_Main() +TEST i8_unaryMinus_Main() { - extern u8 biopGtu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopGtu8u8(2, 1), 1); - ASSERTU8(biopGtu8u8(U8_MAX, 0), 1); - ASSERTU8(biopGtu8u8(U8_MAX, U8_MAX), 0); - ASSERTU8(biopGtu8u8(0, U8_MAX), 0); + extern i8 i8_unaryMinus(i8 lhs); + ASSERTI8(i8_unaryMinus(2), -2); + ASSERTI8(i8_unaryMinus(0x0101010101010101LL), -0x0101010101010101LL); + ASSERTI8(i8_unaryMinus(-0x0101010101010101LL), 0x0101010101010101LL); + ASSERTI8(i8_unaryMinus(I8_MAX), I8_MIN+1); + ASSERTI8(i8_unaryMinus(I8_MIN), I8_MIN); + ASSERTI8(i8_unaryMinus(0), 0); } #endif #ifdef HAS_LONGLONG -TEST biopGti8i8_Main() +TEST i8_unaryPlus_Main() { - extern i8 biopGti8i8(i8 lhs, i8 rhs); - ASSERTI8(biopGti8i8(0x0101010101010101LL, 0x0101010101010101LL), 0); - ASSERTI8(biopGti8i8(0x0101010101010101LL, -0x0101010101010101LL), 1); - ASSERTI8(biopGti8i8(2, 1), 1); - ASSERTI8(biopGti8i8(I8_MAX, I8_MAX), 0); - ASSERTI8(biopGti8i8(I8_MAX, I8_MIN), 1); - ASSERTI8(biopGti8i8(I8_MIN, I8_MAX), 0); + extern i8 i8_unaryPlus(i8 lhs); + ASSERTI8(i8_unaryPlus(2), 2); + ASSERTI8(i8_unaryPlus(0x0101010101010101LL), 0x0101010101010101LL); + ASSERTI8(i8_unaryPlus(-0x0101010101010101LL), -0x0101010101010101LL); + ASSERTI8(i8_unaryPlus(I8_MAX), I8_MAX); + ASSERTI8(i8_unaryPlus(I8_MIN), I8_MIN); + ASSERTI8(i8_unaryPlus(0), 0); } #endif #ifdef HAS_LONGLONG -TEST biopGeu8u8_Main() +TEST i8_addition_Main() { - extern u8 biopGeu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopGeu8u8(2, 1), 1); - ASSERTU8(biopGeu8u8(U8_MAX, U8_MAX), 1); - ASSERTU8(biopGeu8u8(U8_MAX, U8_MIN), 1); - ASSERTU8(biopGeu8u8(U8_MIN, U8_MAX), 0); + extern i8 i8_addition(i8 lhs, i8 rhs); + ASSERTI8(i8_addition(0x0101010101010101LL, 0x0101010101010101LL), 0x202020202020202LL); + ASSERTI8(i8_addition(2, 1), 3); + ASSERTI8(i8_addition(I8_MAX, I8_MAX), -2); + ASSERTI8(i8_addition(I8_MAX, I8_MIN), -1); + ASSERTI8(i8_addition(I8_MAX, 0), I8_MAX); } #endif #ifdef HAS_LONGLONG -TEST biopGei8i8_Main() +TEST i8_subtract_Main() { - extern i8 biopGei8i8(i8 lhs, i8 rhs); - ASSERTI8(biopGei8i8(2, 1), 1); - ASSERTI8(biopGei8i8(I8_MAX, I8_MAX), 1); - ASSERTI8(biopGei8i8(I8_MAX, I8_MIN), 1); - ASSERTI8(biopGei8i8(I8_MIN, I8_MAX), 0); + extern i8 i8_subtract(i8 lhs, i8 rhs); + ASSERTI8(i8_subtract(0x0101010101010101LL, 0x0101010101010100LL), 0x1); + ASSERTI8(i8_subtract(0x0001010101010100LL, 0x0101010101010101LL), -72057594037927937LL); + ASSERTI8(i8_subtract(2, 1), 1); + ASSERTI8(i8_subtract(0x0101010101010101LL, 0x0101010101010101LL), 0); + ASSERTI8(i8_subtract(I8_MAX, I8_MAX), 0); + ASSERTI8(i8_subtract(I8_MAX, I8_MIN), -1); + ASSERTI8(i8_subtract(I8_MAX, 0), I8_MAX); + ASSERTI8(i8_subtract(0, I8_MAX), -I8_MAX); } #endif #ifdef HAS_LONGLONG -TEST biopLtu8u8_Main() +TEST i8_multiply_Main() { - extern u8 biopLtu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopLtu8u8(2, 1), 0); - ASSERTU8(biopLtu8u8(U8_MAX, U8_MAX), 0); - ASSERTU8(biopLtu8u8(U8_MAX, U8_MIN), 0); - ASSERTU8(biopLtu8u8(U8_MIN, U8_MAX), 1); + extern i8 i8_multiply(i8 lhs, i8 rhs); + ASSERTI8(i8_multiply(2, 1), 2); + ASSERTI8(i8_multiply(0x0101010101010101LL, 0x0101010101010101LL), 0x807060504030201LL); + ASSERTI8(i8_multiply(0, -0x0101010101010101LL), 0); + ASSERTI8(i8_multiply(0x0101010101010101LL, -0x0101010101010101LL), -0x807060504030201LL); + ASSERTI8(i8_multiply(I8_MAX, I8_MAX), 1); + ASSERTI8(i8_multiply(I8_MAX, I8_MIN), 0x8000000000000000LL); + + ASSERTI8(i8_multiply(I8_MAX, 0), 0); } #endif #ifdef HAS_LONGLONG -TEST biopLeu8u8_Main() +TEST i8_divide_Main() { - extern u8 biopLeu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopLeu8u8(2, 1), 0); - ASSERTU8(biopLeu8u8(U8_MAX, U8_MAX), 1); - ASSERTU8(biopLeu8u8(U8_MAX, U8_MIN), 0); - ASSERTU8(biopLeu8u8(U8_MIN, U8_MAX), 1); + extern i8 i8_divide(i8 lhs, i8 rhs); + ASSERTI8(i8_divide(0x0101010101010101LL, 0x0101010101010101LL), 0x1); + ASSERTI8(i8_divide(-0x0101010101010101LL, 0x0101010101010101LL), -0x1); + ASSERTI8(i8_divide(0, 0x0101010101010101LL), 0); + ASSERTI8(i8_divide(0x0101010101010101LL, 2), 0x80808080808080); + ASSERTI8(i8_divide(I8_MAX, I8_MAX), 1); + ASSERTI8(i8_divide(I8_MAX, I8_MIN), 0); + ASSERTI8(i8_divide(0, I8_MAX), 0); + ASSERTI8(i8_divide(I8_MAX, 5), 1844674407370955161LL); } #endif #ifdef HAS_LONGLONG -TEST biopLti8i8_Main() +TEST i8_remainder_Main() { - extern i8 biopLti8i8(i8 lhs, i8 rhs); - ASSERTI8(biopLti8i8(0x0101010101010101LL, 0x0101010101010101LL), 0); - ASSERTI8(biopLti8i8(0x0101010101010101LL, -0x0101010101010101LL), 0); - ASSERTI8(biopLti8i8(2, 1), 0); - ASSERTI8(biopLti8i8(I8_MAX, I8_MAX), 0); - ASSERTI8(biopLti8i8(I8_MAX, I8_MIN), 0); - ASSERTI8(biopLti8i8(I8_MIN, I8_MAX), 1); -} -#endif - -#ifdef HAS_LONGLONG -TEST biopEqu8u8_Main() -{ - extern u8 biopEqu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopEqu8u8(2, 1), 0); - ASSERTU8(biopEqu8u8(U8_MAX, U8_MAX), 1); - ASSERTU8(biopEqu8u8(U8_MAX, U8_MIN), 0); - ASSERTU8(biopEqu8u8(U8_MIN, U8_MAX), 0); -} -#endif - -#ifdef HAS_LONGLONG -TEST biopLei8i8_Main() -{ - extern i8 biopLei8i8(i8 lhs, i8 rhs); - ASSERTI8(biopLei8i8(2, 1), 0); - ASSERTI8(biopLei8i8(0x0101010101010101LL, 0x0101010101010101LL), 1); - ASSERTI8(biopLei8i8(0x0101010101010101LL, -0x0101010101010101LL), 0); - ASSERTI8(biopLei8i8(I8_MAX, I8_MAX), 1); - ASSERTI8(biopLei8i8(I8_MAX, I8_MIN), 0); - ASSERTI8(biopLei8i8(I8_MIN, I8_MAX), 1); -} -#endif - -#ifdef HAS_LONGLONG -TEST biopEqi8i8_Main() -{ - extern i8 biopEqi8i8(i8 lhs, i8 rhs); - ASSERTI8(biopEqi8i8(2, 1), 0); - ASSERTI8(biopEqi8i8(0x0101010101010101LL, 0x0101010101010101LL), 1); - ASSERTI8(biopEqi8i8(0x0101010101010101LL, -0x0101010101010101LL), 0); - ASSERTI8(biopEqi8i8(I8_MAX, I8_MAX), 1); - ASSERTI8(biopEqi8i8(I8_MAX, I8_MIN), 0); - ASSERTI8(biopEqi8i8(I8_MIN, I8_MAX), 0); -} -#endif - -#ifdef HAS_LONGLONG -TEST biopNeu8u8_Main() -{ - extern u8 biopNeu8u8(u8 lhs, u8 rhs); - ASSERTU8(biopNeu8u8(2, 1), 1); - ASSERTU8(biopNeu8u8(U8_MAX, U8_MAX), 0); - ASSERTU8(biopNeu8u8(U8_MAX, U8_MIN), 1); - ASSERTU8(biopNeu8u8(U8_MIN, U8_MAX), 1); + extern i8 i8_remainder(i8 lhs, i8 rhs); + ASSERTI8(i8_remainder(0x0101010101010101LL, 0x0101010101010101LL), 0x0); + ASSERTI8(i8_remainder(0x0101010101010101LL, 0x0001010101010101LL), 0x1); + ASSERTI8(i8_remainder(0x0101010101010101LL, 0x0001010101010100LL), 0x101); + ASSERTI8(i8_remainder(I8_MAX, I8_MAX), 0); + ASSERTI8(i8_remainder(I8_MAX, 1), 0); + ASSERTI8(i8_remainder(I8_MAX, I8_MIN), 9223372036854775807); + ASSERTI8(i8_remainder(I8_MAX, 0xFFFF), 32767); } #endif diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_LONGLONG_BODY.c b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_LONGLONG_BODY.c index 92628a7ff3..53593be742 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_LONGLONG_BODY.c +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/BIOPS_LONGLONG_BODY.c @@ -16,7 +16,7 @@ #include "pcode_test.h" #ifdef HAS_LONGLONG -i8 pcode_i8_complexLogic(i8 a, i8 b, i8 c, i8 d, i8 e, i8 f) +i8 i8_complexLogic(i8 a, i8 b, i8 c, i8 d, i8 e, i8 f) { i8 ret = 0; @@ -35,7 +35,7 @@ i8 pcode_i8_complexLogic(i8 a, i8 b, i8 c, i8 d, i8 e, i8 f) return ret; } -u8 pcode_u8_complexLogic(u8 a, u8 b, u8 c, u8 d, u8 e, u8 f) +u8 u8_complexLogic(u8 a, u8 b, u8 c, u8 d, u8 e, u8 f) { u8 ret = 0; @@ -54,7 +54,7 @@ u8 pcode_u8_complexLogic(u8 a, u8 b, u8 c, u8 d, u8 e, u8 f) return ret; } -i8 biopCmpi8i8(i8 lhs, i8 rhs) +i8 i8_compareLogic(i8 lhs, i8 rhs) { if (lhs < 0) lhs += 2; @@ -67,7 +67,7 @@ i8 biopCmpi8i8(i8 lhs, i8 rhs) return lhs; } -u8 biopCmpu8u8(u8 lhs, u8 rhs) +u8 u8_compareLogic(u8 lhs, u8 rhs) { if (lhs < rhs) lhs += 2; @@ -79,8 +79,96 @@ u8 biopCmpu8u8(u8 lhs, u8 rhs) lhs += 16; return lhs; } +/* Comparison operators */ +u8 u8_greaterThan(u8 lhs, u8 rhs) +{ + u8 z; -i8 biopNei8i8(i8 lhs, i8 rhs) + z = lhs > rhs; + return z; +} + +u8 u8_greaterThanEquals(u8 lhs, u8 rhs) +{ + u8 z; + + z = lhs >= rhs; + return z; +} + +u8 u8_lessThan(u8 lhs, u8 rhs) +{ + u8 z; + + z = lhs < rhs; + return z; +} + +u8 u8_lessThanEquals(u8 lhs, u8 rhs) +{ + u8 z; + + z = lhs <= rhs; + return z; +} + +u8 u8_equals(u8 lhs, u8 rhs) +{ + u8 z; + + z = lhs == rhs; + return z; +} + +u8 u8_notEquals(u8 lhs, u8 rhs) +{ + u8 z; + + z = lhs != rhs; + return z; +} + +i8 i8_greaterThan(i8 lhs, i8 rhs) +{ + i8 z; + + z = lhs > rhs; + return z; +} + +i8 i8_greaterThanEquals(i8 lhs, i8 rhs) +{ + i8 z; + + z = lhs >= rhs; + return z; +} + +i8 i8_lessThan(i8 lhs, i8 rhs) +{ + i8 z; + + z = lhs < rhs; + return z; +} + +i8 i8_lessThanEquals(i8 lhs, i8 rhs) +{ + i8 z; + + z = lhs <= rhs; + return z; +} + +i8 i8_equals(i8 lhs, i8 rhs) +{ + i8 z; + + z = lhs == rhs; + return z; +} + +i8 i8_notEquals(i8 lhs, i8 rhs) { i8 z; @@ -88,7 +176,8 @@ i8 biopNei8i8(i8 lhs, i8 rhs) return z; } -u8 biopAndu8u8(u8 lhs, u8 rhs) +/* Bitwise operators */ +u8 u8_bitwiseAnd(u8 lhs, u8 rhs) { u8 z; @@ -96,7 +185,23 @@ u8 biopAndu8u8(u8 lhs, u8 rhs) return z; } -i8 biopAndi8i8(i8 lhs, i8 rhs) +u8 u8_bitwiseOr(u8 lhs, u8 rhs) +{ + u8 z; + + z = lhs | rhs; + return z; +} + +u8 u8_bitwiseXor(u8 lhs, u8 rhs) +{ + u8 z; + + z = lhs ^ rhs; + return z; +} + +i8 i8_bitwiseAnd(i8 lhs, i8 rhs) { i8 z; @@ -104,23 +209,7 @@ i8 biopAndi8i8(i8 lhs, i8 rhs) return z; } -u8 biopOru8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs | rhs; - return z; -} - -u8 biopXOru8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs ^ rhs; - return z; -} - -i8 biopOri8i8(i8 lhs, i8 rhs) +i8 i8_bitwiseOr(i8 lhs, i8 rhs) { i8 z; @@ -128,15 +217,7 @@ i8 biopOri8i8(i8 lhs, i8 rhs) return z; } -u8 biopLogicOru8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs || rhs; - return z; -} - -i8 biopXOri8i8(i8 lhs, i8 rhs) +i8 i8_bitwiseXor(i8 lhs, i8 rhs) { i8 z; @@ -144,15 +225,40 @@ i8 biopXOri8i8(i8 lhs, i8 rhs) return z; } -i8 biopRemainderi8i8(i8 lhs, i8 rhs) +/* Logical operators */ +u8 u8_logicalAnd(u8 lhs, u8 rhs) { - i8 z; + u8 z; - z = lhs % rhs; + z = lhs && rhs; return z; } -i8 biopLogicOri8i8(i8 lhs, i8 rhs) +u8 u8_logicalOr(u8 lhs, u8 rhs) +{ + u8 z; + + z = lhs || rhs; + return z; +} + +u8 u8_logicalNot(u8 lhs) +{ + u8 z; + + z = !lhs; + return z; +} + +i8 i8_logicalAnd(i8 lhs, i8 rhs) +{ + i8 z; + + z = lhs && rhs; + return z; +} + +i8 i8_logicalOr(i8 lhs, i8 rhs) { i8 z; @@ -160,47 +266,7 @@ i8 biopLogicOri8i8(i8 lhs, i8 rhs) return z; } -u8 biopLogicAndu8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs && rhs; - return z; -} - -i8 biopDividi8i8(i8 lhs, i8 rhs) -{ - i8 z; - - z = lhs / rhs; - return z; -} - -u8 biopDividu8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs / rhs; - return z; -} - -i8 biopLogicAndi8i8(i8 lhs, i8 rhs) -{ - i8 z; - - z = lhs && rhs; - return z; -} - -u8 unopNotu8(u8 lhs) -{ - u8 z; - - z = !lhs; - return z; -} - -i8 unopNoti8(i8 lhs) +i8 i8_logicalNot(i8 lhs) { i8 z; @@ -208,7 +274,41 @@ i8 unopNoti8(i8 lhs) return z; } -u8 unopPlusu8(u8 lhs) +/* Shift operators */ +u8 u8_shiftLeft(u8 lhs, u8 rhs) +{ + u8 z; + + z = lhs << rhs; + return z; +} + +u8 u8_shiftRight(u8 lhs, u8 rhs) +{ + u8 z; + + z = lhs >> rhs; + return z; +} + +i8 i8_shiftLeft(i8 lhs, i8 rhs) +{ + i8 z; + + z = lhs << rhs; + return z; +} + +i8 i8_shiftRight(i8 lhs, i8 rhs) +{ + i8 z; + + z = lhs >> rhs; + return z; +} + +/* Arithmetic operators */ +u8 u8_unaryPlus(u8 lhs) { u8 z; @@ -216,7 +316,40 @@ u8 unopPlusu8(u8 lhs) return z; } -i8 unopNegativei8(i8 lhs) +u8 u8_addition(u8 lhs, u8 rhs) +{ + u8 z; + + z = lhs + rhs; + return z; +} + +u8 u8_subtract(u8 lhs, u8 rhs) +{ + u8 z; + + z = lhs - rhs; + return z; +} + +u8 u8_multiply(u8 lhs, u8 rhs) +{ + u8 z; + + z = lhs * rhs; + return z; +} + +u8 u8_divide(u8 lhs, u8 rhs) +{ + u8 z; + + z = lhs / rhs; + return z; +} + + +i8 i8_unaryMinus(i8 lhs) { i8 z; @@ -224,7 +357,7 @@ i8 unopNegativei8(i8 lhs) return z; } -i8 unopPlusi8(i8 lhs) +i8 i8_unaryPlus(i8 lhs) { i8 z; @@ -232,55 +365,7 @@ i8 unopPlusi8(i8 lhs) return z; } -u8 biopMultu8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs * rhs; - return z; -} - -i8 biopMulti8i8(i8 lhs, i8 rhs) -{ - i8 z; - - z = lhs * rhs; - return z; -} - -u8 biopSubu8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs - rhs; - return z; -} - -i8 biopSubi8i8(i8 lhs, i8 rhs) -{ - i8 z; - - z = lhs - rhs; - return z; -} - -u8 biopAddu8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs + rhs; - return z; -} - -u8 biopShtLftu8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs << rhs; - return z; -} - -i8 biopAddi8i8(i8 lhs, i8 rhs) +i8 i8_addition(i8 lhs, i8 rhs) { i8 z; @@ -288,116 +373,37 @@ i8 biopAddi8i8(i8 lhs, i8 rhs) return z; } -u8 biopShtRhtu8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs >> rhs; - return z; -} - -i8 biopShtLfti8i8(i8 lhs, i8 rhs) +i8 i8_subtract(i8 lhs, i8 rhs) { i8 z; - z = lhs << rhs; + z = lhs - rhs; return z; } -i8 biopShtRhti8i8(i8 lhs, i8 rhs) +i8 i8_multiply(i8 lhs, i8 rhs) { i8 z; - z = lhs >> rhs; + z = lhs * rhs; return z; } -u8 biopGtu8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs > rhs; - return z; -} - -i8 biopGti8i8(i8 lhs, i8 rhs) +i8 i8_divide(i8 lhs, i8 rhs) { i8 z; - z = lhs > rhs; + z = lhs / rhs; return z; } -u8 biopGeu8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs >= rhs; - return z; -} - -i8 biopGei8i8(i8 lhs, i8 rhs) +i8 i8_remainder(i8 lhs, i8 rhs) { i8 z; - z = lhs >= rhs; + z = lhs % rhs; return z; } -u8 biopLtu8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs < rhs; - return z; -} - -u8 biopLeu8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs <= rhs; - return z; -} - -i8 biopLti8i8(i8 lhs, i8 rhs) -{ - i8 z; - - z = lhs < rhs; - return z; -} - -u8 biopEqu8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs == rhs; - return z; -} - -i8 biopLei8i8(i8 lhs, i8 rhs) -{ - i8 z; - - z = lhs <= rhs; - return z; -} - -i8 biopEqi8i8(i8 lhs, i8 rhs) -{ - i8 z; - - z = lhs == rhs; - return z; -} - -u8 biopNeu8u8(u8 lhs, u8 rhs) -{ - u8 z; - - z = lhs != rhs; - return z; -} #endif /* #ifdef HAS_LONGLONG */ diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/misc_BODY.c b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/misc_BODY.c index db314540b3..131404c87f 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/misc_BODY.c +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/c_src/misc_BODY.c @@ -121,13 +121,13 @@ i4 nalign_struct(big_struct_type * in) u4 pcode_memset(u1 *lhs, u1 val, u4 len) { - memset(lhs, val, len); + memset(lhs, val, (size_t) len); return *(u4 *) lhs; } void *pcode_memcpy(u1 * lhs, u1 * rhs, u4 len) { - return memcpy(lhs, rhs, len); + return memcpy(lhs, rhs, (size_t) len); } u4 pcode_memcmp_u4(u4 lhs, u4 rhs) @@ -137,7 +137,7 @@ u4 pcode_memcmp_u4(u4 lhs, u4 rhs) u4 pcode_memcmp_n(u1 * lhs, u1 * rhs, u4 len) { - return (u4) (memcmp(lhs, rhs, len) == 0 ? 0 : 1); + return (u4) (memcmp(lhs, rhs, (size_t) len) == 0 ? 0 : 1); } #if defined(HAS_FLOAT) && defined(HAS_DOUBLE) && defined(HAS_LONGLONG) diff --git a/Ghidra/Extensions/SleighDevTools/pcodetest/pcode_defs.py b/Ghidra/Extensions/SleighDevTools/pcodetest/pcode_defs.py index 6cf0021d4f..4a8e096ec6 100644 --- a/Ghidra/Extensions/SleighDevTools/pcodetest/pcode_defs.py +++ b/Ghidra/Extensions/SleighDevTools/pcodetest/pcode_defs.py @@ -159,9 +159,9 @@ PCodeTest({ }) PCodeTest({ - 'name': 'AVR8_X5', + 'name': 'AVR8_6', 'toolchain': 'AVR/avr-elf', - 'ccflags': '-mmcu=avrxmega5 -lgcc', + 'ccflags': '-mmcu=avr6 -lgcc', 'language_id': 'avr8:LE:16:atmega256', 'has_float': 0, 'has_double': 0, diff --git a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.java b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.java index 16df91fe48..7f7f5c49a5 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/test/processors/support/ProcessorEmulatorTestAdapter.java @@ -2170,6 +2170,10 @@ public abstract class ProcessorEmulatorTestAdapter extends TestCase implements E // stub } + public final void test_BIOPS4() { + // stub + } + public final void test_BitManipulation() { // stub } diff --git a/Ghidra/Processors/Atmel/data/languages/avr8.ldefs b/Ghidra/Processors/Atmel/data/languages/avr8.ldefs index 75e2b52d99..4931dd5fcf 100644 --- a/Ghidra/Processors/Atmel/data/languages/avr8.ldefs +++ b/Ghidra/Processors/Atmel/data/languages/avr8.ldefs @@ -37,7 +37,7 @@ - - + + + + + + diff --git a/Ghidra/Processors/Atmel/data/languages/avr8.sinc b/Ghidra/Processors/Atmel/data/languages/avr8.sinc index 2717b642c5..e0663ffed8 100644 --- a/Ghidra/Processors/Atmel/data/languages/avr8.sinc +++ b/Ghidra/Processors/Atmel/data/languages/avr8.sinc @@ -8,44 +8,43 @@ # pointer would be three bytes instead define endian=little; + # Declaring space to be wordsized... alternative is to do byte sized define alignment=2; # Force fusion of two byte operations in a row by decoding as words #@define FUSION "" - # mem space should really be the default, but the loading scripts will # prefer the code space as the default. By being explicit for every # instruction, we can eliminate the ambiguity for at least the # decompiler. None-the-less, other than when loading the binary into # Ghidra, it's still preferable to see the name of IO locations used, # rather than code addresses, so leave mem space as the default. - -define space code type=ram_space size=3 wordsize=2 default; -define space register type=ram_space size=1; -define space mem type=ram_space size=2 wordsize=1; +define space code type=ram_space size=$(PCBYTESIZE) wordsize=2 default; +define space register type=ram_space size=2; +define space mem type=ram_space size=2 wordsize=1; # Using decimal rather than hex to match specs # TODO: These general purpose registers should reside with the 'mem' space from 0x00-0x1f #define register offset=0 size=1 [ define mem offset=0 size=1 [ - R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 - R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 - R20 R21 R22 R23 Wlo Whi Xlo Xhi Ylo Yhi - Zlo Zhi + R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 + R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 + R20 R21 R22 R23 Wlo Whi Xlo Xhi Ylo Yhi + Zlo Zhi ]; #define register offset=0 size=2 [ define mem offset=0 size=2 [ - R1R0 R3R2 R5R4 R7R6 R9R8 - R11R10 R13R12 R15R14 R17R16 R19R18 - R21R20 R23R22 W # Technically, manual has R25R24 instead of W. - X Y Z + R1R0 R3R2 R5R4 R7R6 R9R8 + R11R10 R13R12 R15R14 R17R16 R19R18 + R21R20 R23R22 W # Technically, manual has R25R24 instead of W. + X Y Z ]; #define register offset=0x10 size=4 [ define mem offset=0x10 size=4 [ - R19R18R17R16 R23R22R21R20 + R19R18R17R16 R23R22R21R20 ]; # Techinically, the stack pointer is in the i/o space so should be addressable with the @@ -57,17 +56,25 @@ define register offset=0x3D size=2 [ SP ]; define register offset=0x42 size=$(PCBYTESIZE) [ PC ]; define register offset=0x80 size=1 [ - Cflg Zflg Nflg Vflg Sflg Hflg Tflg Iflg SKIP + Cflg Zflg Nflg Vflg Sflg Hflg Tflg Iflg SKIP ]; ##################################### - -# I discovered different parts have different io layouts not just different io -define mem offset=0x5B size=1 [ RAMPZ ]; +# Some AVR processors may have different io layouts not just different io. +# This could necessitate modification to this section. +# AVR processors with more than 64 KiB of RAM make use of the RAMP- registers +# to act as the high bits where the X, Y, or Z registers are used, or in direct +# addressing instructions. +# TODO: Incorporate the RAMPD register in the LDS instruction. +define mem offset=0x58 size=1 [ RAMPD RAMPX RAMPY RAMPZ ]; define mem offset=0x5F size=1 [ SREG ]; + +# If the AVR processor has more than 128 KiB of ROM, the processor will support the EIND +# register along with the EIJMP and EICALL extended instructions. @if HASEIND == "1" define mem offset=0x5C size=1 [ EIND ]; + @endif ############################## @@ -76,10 +83,9 @@ define mem offset=0x5C size=1 [ EIND ]; define register offset=0x90 size=4 contextreg; define context contextreg - useSkipCond=(0,0) noflow # =1 skip instruction if SKIP register is true - - # transient context - phase=(1,1) # =0 check for useSkipCond, =1 parse instruction + useSkipCond = (0,0) noflow # =1 skip instruction if SKIP register is true + # transient context + phase = (1,1) # =0 check for useSkipCond, =1 parse instruction ; ## Following 8051 example rather than define bitrange @@ -272,143 +278,217 @@ attach variables [ op1RrPairHi op1RdPairHi f3op1RdPairHi ] [ X Y Z ]; - -RrFull: RrHi is RrHiLowSel=1 & RrHi { tmp:1 = RrHi; export tmp; } -RrFull: RrLow is RrHiLowSel=0 & RrLow { tmp:1 = RrLow; export tmp; } +RrFull: RrHi is RrHiLowSel=1 & RrHi { tmp:1 = RrHi; export tmp; } +RrFull: RrLow is RrHiLowSel=0 & RrLow { tmp:1 = RrLow; export tmp; } # Alternative: try using some subcontructors -op1RrPair: op1RrPairHi is op1RrPairSel=1 & op1RrPairHi { tmp:2 = op1RrPairHi; export tmp; } -op1RrPair: op1RrPairLow is op1RrPairSel=0 & op1RrPairLow { tmp:2 = op1RrPairLow; export tmp; } - +op1RrPair: op1RrPairHi is op1RrPairSel=1 & op1RrPairHi { tmp:2 = op1RrPairHi; export tmp; } +op1RrPair: op1RrPairLow is op1RrPairSel=0 & op1RrPairLow { tmp:2 = op1RrPairLow; export tmp; } # I'm uneasy at these... as they require the top of the stack # to know what size element to reserve before the push. # The docs should probably say that the top of the stack byte is unused... +# +# The processor is post-decremented, and because of the way the compiler +# manipulates the stack pointer it's important to get this correct. +@if PCBYTESIZE == "2" macro pushPC(val) { - SP = SP - $(PCBYTESIZE); - *[mem]:$(PCBYTESIZE) SP = val; + local valb:1 = val(0); + *[mem]:1 SP = valb; + SP = SP - 1; + valb = val(1); + *[mem]:1 SP = valb; + SP = SP - 1; } + macro popPC(val) { - val = *[mem]:$(PCBYTESIZE) SP; - SP = SP + $(PCBYTESIZE); + local valb:1 = 0; + SP = SP + 1; + val = *[mem]:1 SP; + SP = SP + 1; + valb = *[mem]:1 SP; + val = (val << 8) + zext(valb); } + +@else # PCBYTESIZE == 3 +macro pushPC(val) { + local valb:1 = val(0); + *[mem]:1 SP = valb; + SP = SP - 1; + valb = val(1); + *[mem]:1 SP = valb; + SP = SP - 1; + valb = val(2); + *[mem]:1 SP = valb; + SP = SP - 1; +} + +macro popPC(val) { + SP = SP + 1; + val = *[mem]:1 SP; + SP = SP + 1; + local valb = *[mem]:1 SP; + val = (val << 8) + zext(valb); + SP = SP + 1; + valb = *[mem]:1 SP; + val = (val << 8) + zext(valb); +} + +@endif + macro push8(val) { - SP = SP -1; - *[mem]:1 SP = val; + *[mem]:1 SP = val; + SP = SP -1; } + macro pop8(val) { - val = *[mem]:1 SP; - SP = SP + 1; + SP = SP + 1; + val = *[mem]:1 SP; } + + + # .slaspec shortcoming: Hflag isn't computed for most results macro setSflag() { - $(Sflag) = $(Nflag) ^ $(Vflag); + $(Sflag) = $(Nflag) ^ $(Vflag); } -macro setResultFlags(result){ - $(Nflag) = (result & 0x80) == 0x80; - $(Zflag) = (result == 0x0); - setSflag(); + +macro setResultFlags(result) { + $(Nflag) = (result & 0x80) == 0x80; + $(Zflag) = (result == 0x0); + setSflag(); } + macro setResult16Flags(result) { - $(Nflag) = (result & 0x8000) == 0x8000; - $(Zflag) = (result == 0x0); - setSflag(); + $(Nflag) = (result & 0x8000) == 0x8000; + $(Zflag) = (result == 0x0); + setSflag(); } -macro setSubCarry(pre,sub){ # pre - sub - $(Cflag) = (pre < sub); + +macro setSubCarry(pre,sub) { # pre - sub + $(Cflag) = (pre < sub); } + # The decompilation looks better when the pcode comparision is used, # rather than walking though the bit examples in the manual. # todo: consolidate these -macro setVflagForSub(pre,sub,res){ # res = pre - sub - $(Vflag) = scarry(pre,sub); +macro setVflagForSub(pre,sub,res) { # res = pre - sub + $(Vflag) = sborrow(pre,sub); } -macro setVflagForSub16(pre,sub){ # pre - sub - $(Vflag) = scarry(pre,sub); + +macro setVflagForSub16(pre,sub) { # pre - sub + $(Vflag) = sborrow(pre,sub); } -macro setVflagForAdd(arg1,arg2,res){ - local a = (res & 0x80) >> 7; - local b = (arg1 & 0x80) >> 7; - local c = (arg2 & 0x80) >> 7; - local V = (b & c & (~a)) ^ ((~b) & (~c) & a); - $(Vflag) = V & 0x01; + +macro setVflagForAdd(arg1,arg2,res) { + local a = (arg1 & 0x80) >> 7; + local b = (arg2 & 0x80) >> 7; + local c = (res & 0x80) >> 7; + local V = (a & b & (~c)) | ((~a) & (~b) & c); + $(Vflag) = V & 0x01; } -macro setCflagForAdd(arg1,arg2,res){ - # pcode has a two form version... but not one taking carry in - $(Cflag) = carry(arg1,arg2); + +macro setCflagForAdd(arg1,arg2,res) { + local a = (arg1 & 0x80) >> 7; + local b = (arg2 & 0x80) >> 7; + local c = (res & 0x80) >> 7; + local V = (a & b) | (a & (~c)) | (b & (~c)); + $(Cflag) = V & 0x01; } -macro doSubtract(pre,sub,res){ - local x = pre - sub; - setVflagForSub(pre,sub,x); - res = x; - setSubCarry(pre, sub); - setResultFlags(res); - $(Sflag) = pre s< sub; + +macro doSubtract(pre,sub,res) { + local x = pre - sub; + setVflagForSub(pre,sub,x); + setSubCarry(pre, sub); + setResultFlags(x); + $(Sflag) = pre s< sub; + res = x; } -macro doSubtractWithCarry(pre,subNoCarry,res){ - local sub = subNoCarry + $(Cflag); - local oldZflag = $(Zflag); - doSubtract(pre,sub,res); - $(Zflag) = oldZflag & $(Zflag); - $(Sflag) = pre s< sub; + +macro doSubtractWithCarry(pre,subNoCarry,res) { + local sub = subNoCarry + $(Cflag); + local x = pre - sub; + local oldZflag = $(Zflag); + setVflagForSub(pre,subNoCarry,x); + $(Cflag) = ((pre < sub) | (sub == 0 & $(Cflag) == 1)); + setResultFlags(x); + $(Sflag) = $(Nflag)^$(Vflag); + $(Zflag) = oldZflag & $(Zflag); + res = x; } + macro setMulFlags(res) { - $(Cflag) = ((res & 0x8000) != 0); - $(Zflag) = (res == 0); + $(Cflag) = ((res & 0x8000) != 0); + $(Zflag) = (res == 0); } # Handle possible skip instruction # This next line is a NOP except for the phase, which is never really checked. # A better fix may be to use -l, and ensure phase=1 is checked on the base constructors. -:^instruction is phase=0 & useSkipCond=0 & instruction [ phase=1; ] { build instruction; } -:^instruction is phase=0 & useSkipCond=1 & instruction [ phase=1; ] { +:^instruction is phase=0 & useSkipCond=0 & instruction [ phase=1; ] { build instruction; } +:^instruction is phase=0 & useSkipCond=1 & instruction [ phase=1; ] { if (SKIP) goto inst_next; - build instruction; + build instruction; } # K8 is immediate for Rd,K8 forms -K8: val is op0to3 & op8to11 [ val = (op8to11 << 4) | op0to3; ] { tmp:1 = val; export tmp; } +K8: val is op0to3 & op8to11 [ val = (op8to11 << 4) | op0to3; ] { tmp:1 = val; export tmp; } @ifdef FUSION -K16fuse: val is op1bits0to3 & op1bits8to11 & op2bits0to3 & op2bits8to11 [ val = (((op2bits8to11 << 4) | op2bits0to3) << 8) | ((op1bits8to11 << 4) | op1bits0to3); ] { tmp:2 = val; export tmp; } -f3cmpK16: val is f3op1bits0to3 & f3op1bits8to11 & f3op2bits0to3 & f3op2bits8to11 [ val = (((f3op2bits8to11 << 4) | f3op2bits0to3) << 8) | ((f3op1bits8to11 << 4) | f3op1bits0to3); ] { tmp:2 = val; export tmp; } -f3cmpK8: val is f3op2bits0to3 & f3op2bits8to11 [ val = (f3op2bits8to11 << 4) | f3op2bits0to3; ] { tmp:1 = val; export tmp; } + +K16fuse: val is op1bits0to3 & op1bits8to11 & op2bits0to3 & op2bits8to11 [ val = (((op2bits8to11 << 4) | op2bits0to3) << 8) | ((op1bits8to11 << 4) | op1bits0to3); ] { tmp:2 = val; export tmp; } + +f3cmpK16: val is f3op1bits0to3 & f3op1bits8to11 & f3op2bits0to3 & f3op2bits8to11 [ val = (((f3op2bits8to11 << 4) | f3op2bits0to3) << 8) | ((f3op1bits8to11 << 4) | f3op1bits0to3); ] { tmp:2 = val; export tmp; } +f3cmpK8: val is f3op2bits0to3 & f3op2bits8to11 [ val = (f3op2bits8to11 << 4) | f3op2bits0to3; ] { tmp:1 = val; export tmp; } + @endif -rel7addr: rel is op3to9signed [ rel = (op3to9signed + inst_next);] { +rel7addr: rel is op3to9signed [ rel = (op3to9signed + inst_next);] { export *[code]:2 rel; } -rel7dst: byteOffset is op3to9signed & rel7addr [ byteOffset = (op3to9signed + inst_next) << 1;] { + +rel7dst: byteOffset is op3to9signed & rel7addr [ byteOffset = (op3to9signed + inst_next) << 1;] { export rel7addr; } -rel12addr: rel is oplow12signed [ rel = oplow12signed + inst_start + 1; ] { - export *[code]:2 rel; -} -rel12dst: byteOffset is oplow12signed & rel12addr [ byteOffset = (oplow12signed + inst_start + 1) << 1; ] { - export rel12addr; +rel12addr: rel is oplow12signed [ rel = oplow12signed + inst_start + 1; ] { + export *[code]:2 rel; } -abs22addr: loc is op4to8 & opbit0; next16 [ loc = (op4to8 << 17) | (opbit0 << 16) | next16; ] { - export *[code]:2 loc; -} -abs22dst: byteOffset is (op4to8 & opbit0; next16) & abs22addr [ byteOffset = ((op4to8 << 17) | (opbit0 << 16) | next16) << 1; ] { - export abs22addr; +rel12dst: byteOffset is oplow12signed & rel12addr [ byteOffset = (oplow12signed + inst_start + 1) << 1; ] { + export rel12addr; } -next16memPtrVal1: next16 is next16 { export *[mem]:1 next16; } +abs22addr: loc is op4to8 & opbit0; next16 [ loc = (op4to8 << 17) | (opbit0 << 16) | next16; ] { + export *[code]:2 loc; +} + +abs22dst: byteOffset is (op4to8 & opbit0; next16) & abs22addr [ byteOffset = ((op4to8 << 17) | (opbit0 << 16) | next16) << 1; ] { + export abs22addr; +} + +next16memPtrVal1: next16 is next16 { export *[mem]:1 next16; } + +@if PCBYTESIZE == "3" +next24memPtrVal1: next24 is next16 [next24 = (RAMPD << 16) | next16;] { export *[mem]:1 next24; } +@endif @ifdef FUSION -ldswMemPtrVal2: ldswop1imm16 is ldswop1imm16 { export *[mem]:2 ldswop1imm16; } -stswMemPtrVal2: ldswop2imm16 is ldswop2imm16 { export *[mem]:2 ldswop2imm16; } + +ldswMemPtrVal2: ldswop1imm16 is ldswop1imm16 { export *[mem]:2 ldswop1imm16; } + +stswMemPtrVal2: ldswop2imm16 is ldswop2imm16 { export *[mem]:2 ldswop2imm16; } + @endif # K6 is used in dword operation -K6: val is oplow4 & op6to7 [ val = (op6to7 << 4) | oplow4; ] { tmp:1 = val; export tmp; } +K6: val is oplow4 & op6to7 [ val = (op6to7 << 4) | oplow4; ] { tmp:1 = val; export tmp; } + # K7 is used by lds -K7addr: val is oplow4 & op9to10 & opbit8 [ val = ((1 ^ opbit8) << 7) | (opbit8 << 6) | (op9to10 << 4) | oplow4; ] { - tmp:1 = val; export tmp; +K7addr: val is oplow4 & op9to10 & opbit8 [ val = ((1 ^ opbit8) << 7) | (opbit8 << 6) | (op9to10 << 4) | oplow4; ] { + tmp:1 = val; export tmp; } + # Join against various spaces for dataspace... # ##################################################################################### # COMMENTING OUT BECAUSE "Subtable symbol K7addr is not allowed in context block" @@ -416,24 +496,34 @@ K7addr: val is oplow4 & op9to10 & opbit8 [ val = ((1 ^ opbit8) << 7) | (opbit8 < # ##################################################################################### # COMMENTING OUT BECAUSE "Subtable symbol K7Ioaddr is not allowed in context block" #A7Ioaddr: val is K7Ioaddr [ val = (K7Ioaddr | 0x00) + 0x20 ; ] { export *[mem]:1 val; } -Aio6: val is oplow4 & op9to10 [ val = ((op9to10 << 4) | oplow4) + 0x20; ] { export *[mem]:1 val; } -Aio5: val is op3to7 [ val = (op3to7 | 0x00) + 0x20; ] { export *[mem]:1 val; } -q6: val is oplow3 & op10to11 & opbit13 [ val = (opbit13 << 5) | (op10to11 << 3) | oplow3; ] { tmp:1 = val; export tmp; } +Aio6: val is oplow4 & op9to10 [ val = ((op9to10 << 4) | oplow4) + 0x20; ] { export *[mem]:1 val; } +Aio5: val is op3to7 [ val = (op3to7 | 0x00) + 0x20; ] { export *[mem]:1 val; } + +q6: val is oplow3 & op10to11 & opbit13 [ val = (opbit13 << 5) | (op10to11 << 3) | oplow3; ] { tmp:1 = val; export tmp; } @ifdef FUSION + # Predicates to verify that fusion will be valid here. # We just want to construct these. The rules are not null to avoid a NOP bug with sleigh -fusion16rrrrPred: val is op1bit0=0 & op2bit0=1 & op1bit4=0 & op2bit4=1 & op1bit9=op2bit9 & op1bits5to8=op2bits5to8 & op1bits1to3=op2bits1to3 [ val = 0; ] { tmp:2=val; export tmp; } -fusion16rkrkPred: val is op1bits5to7=op2bits5to7 & op1bit4=0 & op2bit4=1 [ val=0; ] { tmp:2 = val; export tmp; } -f3cmpPairPred: val is f3op1bits5to7=f3op3bits5to7 & f3op1bit4=0 & f3op3bit4=1 & f3op3bit8=1 [ val=0; ] { tmp:2 = val; export tmp; } -f3cmpLdiPred: val is f3op3bit9=1 & f3op3bits0to3=f3op2bits4to7 [ val=0; ] { tmp:2 = val; export tmp; } -ldswPairPred: val is ldswop1bit4=0 & ldswop2bit4=1 & ldswop1bits5to8=ldswop2bits5to8 [ val=0; ] { tmp:2 = val; export tmp; } -stswPairPred: val is ldswop1bit4=1 & ldswop2bit4=0 & ldswop1bits5to8=ldswop2bits5to8 [ val=0; ] { tmp:2 = val; export tmp; } +fusion16rrrrPred: val is op1bit0=0 & op2bit0=1 & op1bit4=0 & op2bit4=1 & op1bit9=op2bit9 & op1bits5to8=op2bits5to8 & op1bits1to3=op2bits1to3 [ val = 0; ] { tmp:2=val; export tmp; } + +fusion16rkrkPred: val is op1bits5to7=op2bits5to7 & op1bit4=0 & op2bit4=1 [ val=0; ] { tmp:2 = val; export tmp; } + +f3cmpPairPred: val is f3op1bits5to7=f3op3bits5to7 & f3op1bit4=0 & f3op3bit4=1 & f3op3bit8=1 [ val=0; ] { tmp:2 = val; export tmp; } + +f3cmpLdiPred: val is f3op3bit9=1 & f3op3bits0to3=f3op2bits4to7 [ val=0; ] { tmp:2 = val; export tmp; } + +ldswPairPred: val is ldswop1bit4=0 & ldswop2bit4=1 & ldswop1bits5to8=ldswop2bits5to8 [ val=0; ] { tmp:2 = val; export tmp; } + +stswPairPred: val is ldswop1bit4=1 & ldswop2bit4=0 & ldswop1bits5to8=ldswop2bits5to8 [ val=0; ] { tmp:2 = val; export tmp; } + # would like to check this for const pair, but hangs sleigh compiler: ldswop1imm15=ldswop2imm15 # So check as a few in a row # Not any better & ldswop1imm5b=ldswop2imm5b & ldswop1imm5c=ldswop2imm5c -ldswConstPairPred: val is ldswop1bit16=0 & ldswop2bit16=1 & ldswop1imm6=ldswop2imm6 [ val=0; ] { tmp:2 = val; export tmp; } -stswConstPairPred: val is ldswop1bit16=1 & ldswop2bit16=0 & ldswop1imm6=ldswop2imm6 [ val=0; ] { tmp:2 = val; export tmp; } +ldswConstPairPred: val is ldswop1bit16=0 & ldswop2bit16=1 & ldswop1imm6=ldswop2imm6 [ val=0; ] { tmp:2 = val; export tmp; } + +stswConstPairPred: val is ldswop1bit16=1 & ldswop2bit16=0 & ldswop1imm6=ldswop2imm6 [ val=0; ] { tmp:2 = val; export tmp; } + @endif define pcodeop todo; @@ -445,220 +535,219 @@ define pcodeop break; @ifdef FUSION # add followed by adc -:addw op1RdPair,op1RrPair is phase=1 & op1hi6=0x3 & op2hi6=0x7 & op1RdPair & op1RrPair & fusion16rrrrPred { - $(Cflag) = carry(op1RdPair,op1RrPair); - local pre = op1RdPair; - local post = op1RdPair + op1RrPair; - op1RdPair = post; - $(Vflag) = (0x0000 == (pre & 0x8000)) & ((post & 0x8000) == 0x8000); - setResult16Flags(post); +:addw op1RdPair,op1RrPair is phase=1 & op1hi6=0x3 & op2hi6=0x7 & op1RdPair & op1RrPair & fusion16rrrrPred { + $(Cflag) = carry(op1RdPair,op1RrPair); + local pre = op1RdPair; + local post = op1RdPair + op1RrPair; + op1RdPair = post; + $(Vflag) = (0x0000 == (pre & 0x8000)) & ((post & 0x8000) == 0x8000); + setResult16Flags(post); } + @endif # Rd,Rr -:adc RdFull,RrFull is phase=1 & ophi6=0x7 & RdFull & RrFull { - local res = RdFull + RrFull + $(Cflag); - setCflagForAdd(RdFull,RrFull,res); - setResultFlags(res); - RdFull = res; +:adc RdFull,RrFull is phase=1 & ophi6=0x7 & RdFull & RrFull { + local res = RdFull + RrFull + $(Cflag); + setCflagForAdd(RdFull,RrFull,res); + setResultFlags(res); + RdFull = res; } # Rd,Rr -:add RdFull,RrFull is phase=1 & ophi6=0x3 & RdFull & RrFull { - local res = RdFull + RrFull; - setCflagForAdd(RdFull,RrFull,res); - setResultFlags(res); - RdFull = res; +:add RdFull,RrFull is phase=1 & ophi6=0x3 & RdFull & RrFull { + local res = RdFull + RrFull; + setCflagForAdd(RdFull,RrFull,res); + setResultFlags(res); + RdFull = res; } # adiw Rd+1:Rd,K6 -:adiw Rdw2,K6 is phase=1 & ophi8=0x96 & Rdw2 & K6 { - local pre = Rdw2; - Rdw2 = Rdw2 + zext(K6); - $(Cflag) = carry(pre,zext(K6)); - $(Vflag) = (0x0000 == (pre & 0x8000)) & ((Rdw2 & 0x8000) == 0x8000); - setResult16Flags(Rdw2); +:adiw Rdw2,K6 is phase=1 & ophi8=0x96 & Rdw2 & K6 { + local pre = Rdw2; + Rdw2 = Rdw2 + zext(K6); + $(Cflag) = carry(pre,zext(K6)); + $(Vflag) = scarry(Rdw2,zext(K6)); #(0x0000 == (pre & 0x8000)) & ((Rdw2 & 0x8000) == 0x8000); + setResult16Flags(Rdw2); } # and Rd,Rr -:and RdFull,RrFull is phase=1 & ophi6=8 & RdFull & RrFull { - RdFull = RdFull & RrFull; - $(Vflag) = 0; - setResultFlags(RdFull); +:and RdFull,RrFull is phase=1 & ophi6=8 & RdFull & RrFull { + RdFull = RdFull & RrFull; + $(Vflag) = 0; + setResultFlags(RdFull); } # andi Rd,K -:andi RdHi,K8 is phase=1 & ophi4=7 & RdHi & K8 { - RdHi = RdHi & K8; - $(Vflag) = 0; - setResultFlags(RdHi); +:andi RdHi,K8 is phase=1 & ophi4=7 & RdHi & K8 { + RdHi = RdHi & K8; + $(Vflag) = 0; + setResultFlags(RdHi); } # asr Rd -:asr RdFull is phase=1 & ophi7=0x4a & oplow4=0x5 & RdFull { #done - $(Cflag) = RdFull & 0x01; - RdFull = RdFull s>> 1; - $(Nflag) = (RdFull & 0x80) == 0x80; - $(Vflag) = $(Nflag) ^ $(Cflag); - setResultFlags(RdFull); +:asr RdFull is phase=1 & ophi7=0x4a & oplow4=0x5 & RdFull { #done + $(Cflag) = RdFull & 0x01; + RdFull = RdFull s>> 1; + $(Nflag) = (RdFull & 0x80) == 0x80; + $(Vflag) = $(Nflag) ^ $(Cflag); + setResultFlags(RdFull); } + # bclr s -:bclr op4to6_flag is phase=1 & ophi9=0x129 & oplow4=0x4 & op4to6_flag { #done - op4to6_flag = 0; +:bclr op4to6_flag is phase=1 & ophi9=0x129 & oplow4=0x4 & op4to6_flag { #done + op4to6_flag = 0; } + # bld Rd,b -:bld RdFull,oplow3 is phase=1 & ophi7=0x7c & opbit3=0 & RdFull & oplow3 { - local b = $(Tflag) << oplow3; - local mask = 0xff ^ (1 << oplow3); - RdFull = (RdFull & mask) | b; +:bld RdFull,oplow3 is phase=1 & ophi7=0x7c & opbit3=0 & RdFull & oplow3 { + local b = $(Tflag) << oplow3; + local mask = 0xff ^ (1 << oplow3); + RdFull = (RdFull & mask) | b; } # brbc s,k -:brbc rel7dst,oplow3_flag is phase=1 & ophi6=0x3d & rel7dst & oplow3_flag { - if (!oplow3_flag) +:brbc rel7dst,oplow3_flag is phase=1 & ophi6=0x3d & rel7dst & oplow3_flag { + if (!oplow3_flag) goto rel7dst; } # brbs s,k (see prev instruction) -:brbs rel7dst,oplow3_flag is phase=1 & ophi6=0x3c & rel7dst & oplow3_flag { - if (oplow3_flag) +:brbs rel7dst,oplow3_flag is phase=1 & ophi6=0x3c & rel7dst & oplow3_flag { + if (oplow3_flag) goto rel7dst; } # brcs and brcc seem to be special cases of brbs -:break is phase=1 & ophi16=0x9598 { - break(); +:break is phase=1 & ophi16=0x9598 { + break(); } # Probably want to check for various decode logic for conditional branches... # ... specifically BRBS 1,k # breq k - really is BRBS 1,k # bset s -:bset op4to6_flag is phase=1 & ophi9=(0x94<<1) & oplow4=0x8 & op4to6_flag { - op4to6_flag = 1; +:bset op4to6_flag is phase=1 & ophi9=(0x94<<1) & oplow4=0x8 & op4to6_flag { + op4to6_flag = 1; } # bst Rd,b -:bst RdFull,oplow3 is phase=1 & ophi7=0x7d & opbit3=0 & RdFull & oplow3 { - $(Tflag) = (RdFull >> oplow3) & 0x01; +:bst RdFull,oplow3 is phase=1 & ophi7=0x7d & opbit3=0 & RdFull & oplow3 { + $(Tflag) = (RdFull >> oplow3) & 0x01; } # call k - todo - handle upper bits for 24 bit architecture -:call abs22dst is phase=1 & (ophi7=0x4a & op1to3=0x7) ... & abs22dst { - tmp:3 = inst_next >> 1; -@if PCBYTESIZE == "2" - ptr:2 = tmp:2; -@else - ptr:3 = tmp; -@endif - pushPC(ptr); - PC = &abs22dst; - call abs22dst; +:call abs22dst is phase=1 & (ophi7=0x4a & op1to3=0x7) ... & abs22dst { + tmp:$(PCBYTESIZE) = inst_next >> 1; + pushPC(tmp); + PC = &abs22dst; + call abs22dst; } # cbi A,b -:cbi Aio5,oplow3 is phase=1 & ophi8=0x98 & Aio5 & oplow3 { - local x = Aio5; - x = x & (0xff ^ (1 << oplow3)); - Aio5 = x; +:cbi Aio5,oplow3 is phase=1 & ophi8=0x98 & Aio5 & oplow3 { + local x = Aio5; + x = x & (0xff ^ (1 << oplow3)); + Aio5 = x; } # cbr - not actual instruction # clc, clh, cli, cln ... variants on register clearing # sub bits give which bits in SREG to clear -:clc is phase=1 & ophi16=0x9488 { - $(Cflag) = 0; +:clc is phase=1 & ophi16=0x9488 { + $(Cflag) = 0; } -:clh is phase=1 & ophi16=0x94d8 { - $(Hflag) = 0; +:clh is phase=1 & ophi16=0x94d8 { + $(Hflag) = 0; } -:cli is phase=1 & ophi16=0x94f8 { - $(Iflag) = 0; +:cli is phase=1 & ophi16=0x94f8 { + $(Iflag) = 0; } -:cln is phase=1 & ophi16=0x94a8 { - $(Nflag) = 0; +:cln is phase=1 & ophi16=0x94a8 { + $(Nflag) = 0; } -:cls is phase=1 & ophi16=0x94c8 { - $(Sflag) = 0; +:cls is phase=1 & ophi16=0x94c8 { + $(Sflag) = 0; } -:clt is phase=1 & ophi16=0x94e8 { - $(Tflag) = 0; +:clt is phase=1 & ophi16=0x94e8 { + $(Tflag) = 0; } -:clv is phase=1 & ophi16=0x94b8 { - $(Vflag) = 0; +:clv is phase=1 & ophi16=0x94b8 { + $(Vflag) = 0; } -:clz is phase=1 & ophi16=0x9498 { - $(Zflag) = 0; +:clz is phase=1 & ophi16=0x9498 { + $(Zflag) = 0; } # clr Rd - really is EOR Rd, Rd -:com RdFull is phase=1 & ophi7=0x4a & RdFull { - RdFull = 0xff - RdFull; - $(Vflag) = 0; - $(Cflag) = 1; - setResultFlags(RdFull); +:com RdFull is phase=1 & ophi7=0x4a & RdFull { + RdFull = ~RdFull; + $(Vflag) = 0; + $(Cflag) = 1; + setResultFlags(RdFull); } -:cp RdFull,RrFull is phase=1 & ophi6=0x05 & RdFull & RrFull { - local x = RdFull - RrFull; - setSubCarry(RdFull,RrFull); - setVflagForSub(RdFull,RrFull,x); - setResultFlags(x); - # but doesn't set result into a register +:cp RdFull,RrFull is phase=1 & ophi6=0x05 & RdFull & RrFull { + local x = RdFull - RrFull; + setSubCarry(RdFull,RrFull); + setVflagForSub(RdFull,RrFull,x); + setResultFlags(x); +# but doesn't set result into a register } -:cpc RdFull,RrFull is phase=1 & ophi6=0x1 & RdFull & RrFull { - local res = 3; - doSubtractWithCarry(RdFull,RrFull,res); +:cpc RdFull,RrFull is phase=1 & ophi6=0x1 & RdFull & RrFull { + local res = 0; + doSubtractWithCarry(RdFull,RrFull,res); } -:cpi RdHi,K8 is phase=1 & ophi4=0x3 & RdHi & K8 { - local res = 3; - doSubtract(RdHi,K8,res); +:cpi RdHi,K8 is phase=1 & ophi4=0x3 & RdHi & K8 { + local res = 0; + doSubtract(RdHi,K8,res); } + @ifdef FUSION # cpi; ldi; cpc sequence -:cpiw f3op1RdPairHi,f3cmpK16" ;ldi "f3op2RdHi,f3cmpK8 is phase=1 & f3op1hi4=0x3 & f3op2hi4=0xe & f3op3hi6=0x1 & f3cmpPairPred & f3cmpLdiPred & f3op1RdPairHi & f3op2RdHi & f3cmpK16 & f3cmpK8 { - local res = 3; - doSubtract(f3op1RdPairHi,f3cmpK16,res); - f3op2RdHi = f3cmpK8; +:cpiw f3op1RdPairHi,f3cmpK16" ;ldi "f3op2RdHi,f3cmpK8 is phase=1 & f3op1hi4=0x3 & f3op2hi4=0xe & f3op3hi6=0x1 & f3cmpPairPred & f3cmpLdiPred & f3op1RdPairHi & f3op2RdHi & f3cmpK16 & f3cmpK8 { + local res = 3; + doSubtract(f3op1RdPairHi,f3cmpK16,res); + f3op2RdHi = f3cmpK8; } # cp; cpc sequence -:cpw op1RdPair,op1RrPair phase=1 & is op1hi6=0x5 & op2hi6=0x1 & fusion16rrrrPred & op1RdPair & op1RrPair { - local res = op1RdPair - op1RrPair; - setVflagForSub16(op1RdPair,op1RrPair); - setSubCarry(op1RdPair, op1RrPair); - setResult16Flags(res); - $(Sflag) = op1RdPair s< op1RrPair; +:cpw op1RdPair,op1RrPair phase=1 & is op1hi6=0x5 & op2hi6=0x1 & fusion16rrrrPred & op1RdPair & op1RrPair { + local res = op1RdPair - op1RrPair; + setVflagForSub16(op1RdPair,op1RrPair); + setSubCarry(op1RdPair, op1RrPair); + setResult16Flags(res); + $(Sflag) = op1RdPair s< op1RrPair; } + @endif -:cpse RdFull,RrFull is phase=1 & ophi6=0x4 & RdFull & RrFull [ useSkipCond=1; globalset(inst_next,useSkipCond); ] { - SKIP = (RdFull == RrFull); +:cpse RdFull,RrFull is phase=1 & ophi6=0x4 & RdFull & RrFull [ useSkipCond=1; globalset(inst_next,useSkipCond); ] { + SKIP = (RdFull == RrFull); } -:dec RdFull is phase=1 & ophi7=0x4a & oplow4=0xa & RdFull { - # doesn't set the C flag - $(Vflag) = RdFull == 0x80; - RdFull = RdFull - 1; - setResultFlags(RdFull); +:dec RdFull is phase=1 & ophi7=0x4a & oplow4=0xa & RdFull { + # doesn't set the C flag + $(Vflag) = (RdFull == 0x80); + RdFull = RdFull - 1; + setResultFlags(RdFull); } -:des op4to7 is phase=1 & ophi8=0x94 & oplow4=0xb & op4to7 { todo(); } +:des op4to7 is phase=1 & ophi8=0x94 & oplow4=0xb & op4to7 { todo(); } -# I discovered some parts where PCBYTESIZE would be 3 don't have the EIND reg (Atmega128). -# To handle that, need another flag @if HASEIND == "1" -:eicall is phase=1 & ophi16=0x9519 { - ptr:3 = inst_next >> 1; - pushPC(ptr); - PC = zext(Z) | (zext(EIND) << 16); - call [PC]; +:eicall is phase=1 & ophi16=0x9519 { + ptr:$(PCBYTESIZE) = inst_next >> 1; + pushPC(ptr); + PC = zext(Z) | (zext(EIND) << 16); + call [PC]; } -:eijmp is phase=1 & ophi16=0x9419 { - PC = zext(Z) | (zext(EIND) << 16); - goto [PC]; +:eijmp is phase=1 & ophi16=0x9419 { + PC = zext(Z) | (zext(EIND) << 16); + goto [PC]; } + @endif @if PCBYTESIZE == "3" -:elpm is phase=1 & ophi16=0x95d8 { +:elpm is phase=1 & ophi16=0x95d8 { ptr:3 = zext(Z) | (zext(RAMPZ) << 16); tmp:2 = *[code]:2 (ptr >> 1); val:2 = (tmp >> (Z & 0x1)); - R0 = val:1; + R0 = val:1; } -:elpm RdFull, Z is phase=1 & ophi7=0x48 & oplow4=0x6 & RdFull & Z { +:elpm RdFull, Z is phase=1 & ophi7=0x48 & oplow4=0x6 & RdFull & Z { ptr:3 = zext(Z) | (zext(RAMPZ) << 16); tmp:2 = *[code]:2 (ptr >> 1); val:2 = (tmp >> (Z & 0x1)); RdFull = val:1; } -:elpm RdFull, Z^"+" is phase=1 & ophi7=0x48 & oplow4=0x7 & RdFull & Z { +:elpm RdFull, Z^"+" is phase=1 & ophi7=0x48 & oplow4=0x7 & RdFull & Z { ptr:3 = zext(Z) | (zext(RAMPZ) << 16); tmp:2 = *[code]:2 (ptr >> 1); val:2 = (tmp >> (Z & 0x1)); @@ -667,120 +756,130 @@ define pcodeop break; Z = ptr:2; RAMPZ = ptr[16,8]; } + @endif -:eor RdFull,RrFull is phase=1 & ophi6=0x9 & RdFull & RrFull { - RdFull = RdFull ^ RrFull; - $(Vflag) = 0; - setResultFlags(RdFull); +:eor RdFull,RrFull is phase=1 & ophi6=0x9 & RdFull & RrFull { + RdFull = RdFull ^ RrFull; + $(Vflag) = 0; + setResultFlags(RdFull); } # Manual uses fmul. I prefer fracmul to distinguish from floating point -:fracmul RdHi,RrHi is phase=1 & ophi9=0x6 & opbit3=1 & RdHi & RrHi { todo(); } -:fracmuls RdHi,RrHi is phase=1 & ophi9=0x7 & opbit3=0 & RdHi & RrHi { todo(); } -:fracmulsu RdHi,RrHi is phase=1 & ophi9=0x7 & opbit3=1 & RdHi & RrHi { todo(); } +:fracmul RdHi,RrHi is phase=1 & ophi9=0x6 & opbit3=1 & RdHi & RrHi { todo(); } +:fracmuls RdHi,RrHi is phase=1 & ophi9=0x7 & opbit3=0 & RdHi & RrHi { todo(); } +:fracmulsu RdHi,RrHi is phase=1 & ophi9=0x7 & opbit3=1 & RdHi & RrHi { todo(); } -:icall is phase=1 & ophi16=0x9509 { - tmp:3 = inst_next >> 1; -@if PCBYTESIZE == "2" - ptr:2 = tmp:2; -@else - ptr:3 = tmp; -@endif - pushPC(ptr); - PC = zext(Z); - call [PC]; +:icall is phase=1 & ophi16=0x9509 { + ptr:$(PCBYTESIZE) = inst_next >> 1; + pushPC(ptr); + PC = zext(Z); + call [PC]; } -:ijmp is phase=1 & ophi16=0x9409 { - PC = zext(Z); - goto [PC]; +:ijmp is phase=1 & ophi16=0x9409 { + PC = zext(Z); + goto [PC]; } # in Rd,A -:in RdFull,Aio6 is phase=1 & ophi5=0x16 & RdFull & Aio6 { - RdFull = Aio6; +:in RdFull,Aio6 is phase=1 & ophi5=0x16 & RdFull & Aio6 { + RdFull = Aio6; } -:in RdFull,SPL is phase=1 & ophi5=0x16 & RdFull & op9to10=3 & oplow4=0xd & SPL { - RdFull = SPL; +:in RdFull,SPL is phase=1 & ophi5=0x16 & RdFull & op9to10=3 & oplow4=0xd & SPL { + RdFull = SPL; } -:in RdFull,SPH is phase=1 & ophi5=0x16 & RdFull & op9to10=3 & oplow4=0xe & SPH { - RdFull = SPH; +:in RdFull,SPH is phase=1 & ophi5=0x16 & RdFull & op9to10=3 & oplow4=0xe & SPH { + RdFull = SPH; } -:inc RdFull is phase=1 & ophi7=0x4a & oplow4=0x3 & RdFull { - # inc doesn't set the C flag. - $(Vflag) = RdFull == 0x7f; - RdFull = RdFull + 1; - setResultFlags(RdFull); +:inc RdFull is phase=1 & ophi7=0x4a & oplow4=0x3 & RdFull { + # inc doesn't set the C flag. + $(Vflag) = RdFull == 0x7f; + RdFull = RdFull + 1; + setResultFlags(RdFull); } -:jmp abs22dst is phase=1 & (ophi7=0x4a & op1to3=0x6) ... & abs22dst { - PC = &abs22dst; - goto abs22dst; +:jmp abs22dst is phase=1 & (ophi7=0x4a & op1to3=0x6) ... & abs22dst { + PC = &abs22dst; + goto abs22dst; } -:lac Z,RdFull is phase=1 & ophi7=0x49 & oplow4=0x6 & Z & RdFull { - tmp:1 = *[mem]:1 Z; - tmp = tmp & (0xff - RdFull); - *[mem]:1 Z = tmp; +:lac Z,RdFull is phase=1 & ophi7=0x49 & oplow4=0x6 & Z & RdFull { + tmp:1 = *[mem]:1 Z; + tmp = tmp & (0xff - RdFull); + *[mem]:1 Z = tmp; + RdFull = tmp; } -:las Z,RdFull is phase=1 & ophi7=0x49 & oplow4=0x5 & Z & RdFull { - tmp:1 = *[mem]:1 Z; - tmp = tmp | RdFull; - *[mem]:1 Z = tmp; +:las Z,RdFull is phase=1 & ophi7=0x49 & oplow4=0x5 & Z & RdFull { + tmp:1 = *[mem]:1 Z; + tmp = tmp | RdFull; + *[mem]:1 Z = tmp; + RdFull = tmp; } -:lat Z,RdFull is phase=1 & ophi7=0x49 & oplow4=0x7 & Z & RdFull { - tmp:1 = *[mem]:1 Z; - tmp = tmp ^ RdFull; - *[mem]:1 Z = tmp; +:lat Z,RdFull is phase=1 & ophi7=0x49 & oplow4=0x7 & Z & RdFull { + tmp:1 = *[mem]:1 Z; + tmp = tmp ^ RdFull; + *[mem]:1 Z = tmp; + RdFull = tmp; } # three forms, really just specifying the increment mode # ld Rd,X -:ld RdFull,X is phase=1 & ophi7=0x48 & oplow4=0xc & X & RdFull { - tmp:2 = X; - RdFull = *[mem]:1 tmp; +:ld RdFull,X is phase=1 & ophi7=0x48 & oplow4=0xc & X & RdFull { + tmp:2 = X; + RdFull = *[mem]:1 tmp; } # ld Rd,Y; ld Rd,Z -:ld RdFull,RstPtr is phase=1 & ophi7=0x40 & oplow3=0x0 & RdFull & RstPtr { - tmp:2 = RstPtr; - RdFull = *[mem]:1 tmp; +:ld RdFull,RstPtr is phase=1 & ophi7=0x40 & oplow3=0x0 & RdFull & RstPtr { + tmp:2 = RstPtr; + RdFull = *[mem]:1 tmp; } # ld Rd,Y+ ; ld Rd, X+; ld Rd, Z+ -:ld RdFull,RstPtr"+" is phase=1 & ophi7=0x48 & oplow2=0x01 & RdFull & RstPtr { - tmp:2 = RstPtr; - RdFull = *[mem]:1 tmp; - RstPtr = RstPtr + 0x01; +:ld RdFull,RstPtr"+" is phase=1 & ophi7=0x48 & oplow2=0x01 & RdFull & RstPtr { + tmp:2 = RstPtr; + RdFull = *[mem]:1 tmp; + RstPtr = RstPtr + 0x01; } + # ld Rd,-Y ; ld Rd, -X; ld Rd, -Z LdPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; } -:ld RdFull,LdPredec is phase=1 & ophi7=0x48 & oplow2=0x02 & RdFull & LdPredec { - tmp:2 = LdPredec; - RdFull = *[mem]:1 tmp; + +:ld RdFull,LdPredec is phase=1 & ophi7=0x48 & oplow2=0x02 & RdFull & LdPredec { + tmp:2 = LdPredec; + RdFull = *[mem]:1 tmp; } # ldd Rd,Y+q # ldd Rd,Z+q -:ldd RdFull,Rstq"+"q6 is phase=1 & ophi2=0x2 & opbit12=0 & opbit9=0 & Rstq & RdFull & q6 { - local ptr = Rstq + zext(q6); - RdFull = *[mem]:1 ptr; +:ldd RdFull,Rstq"+"q6 is phase=1 & ophi2=0x2 & opbit12=0 & opbit9=0 & Rstq & RdFull & q6 { + local ptr = Rstq + zext(q6); + RdFull = *[mem]:1 ptr; } # Rd,K -:ldi RdHi,K8 is phase=1 & ophi4=0xe & RdHi & K8 { - RdHi = K8; +:ldi RdHi,K8 is phase=1 & ophi4=0xe & RdHi & K8 { + RdHi = K8; } + +@if PCBYTESIZE == "2" # lds Rd,k -:lds RdFull,next16memPtrVal1 is phase=1 & ophi7=0x48 & oplow4=0 & RdFull; next16memPtrVal1 { - RdFull = next16memPtrVal1; +:lds RdFull,next16memPtrVal1 is phase=1 & ophi7=0x48 & oplow4=0 & RdFull; next16memPtrVal1 { + RdFull = next16memPtrVal1; } +@else +:lds RdFull,next24memPtrVal1 is phase=1 & ophi7=0x48 & oplow4=0 & RdFull; next24memPtrVal1 { + RdFull = next24memPtrVal1; +} +@endif + @ifdef FUSION # Fuse together consecuitive lds ; lds # -:ldsw ldswop1RdPair,ldswMemPtrVal2 is phase=1 & ldswop1hi7=0x48 & ldswop2hi7=0x48 & ldswop1low4=0 & ldswop2low4=0 & ldswMemPtrVal2 & ldswop1RdPair & ldswPairPred & ldswConstPairPred { - ldswop1RdPair = ldswMemPtrVal2; +:ldsw ldswop1RdPair,ldswMemPtrVal2 is phase=1 & ldswop1hi7=0x48 & ldswop2hi7=0x48 & ldswop1low4=0 & ldswop2low4=0 & ldswMemPtrVal2 & ldswop1RdPair & ldswPairPred & ldswConstPairPred { + ldswop1RdPair = ldswMemPtrVal2; } + @endif # lds Rd,k Seem to get some problems here... but 16-bit instruction isn't available on all atmega64. # Furthermore, it will sometimes conflict with ldd Z+q for q=0x2_ @@ -790,255 +889,275 @@ LdPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; } #} # TODO: lpm semantic behavior needs verification ! # lpm R0 -:lpm R0 is phase=1 & ophi16=0x95c8 & R0 { - ptr:3 = zext(Z); - tmp:2 = *[code]:2 (ptr >> 1); - val:2 = (tmp >> (Z & 0x1)); - R0 = val:1; +:lpm R0 is phase=1 & ophi16=0x95c8 & R0 { + ptr:$(PCBYTESIZE) = zext(Z); + tmp:$(PCBYTESIZE) = *[code]:$(PCBYTESIZE) (ptr >> 1); + val:$(PCBYTESIZE) = (tmp >> (Z & 0x1)); + R0 = val:1; } # lpm Rd,Z -:lpm RdFull,Z is phase=1 & ophi7=0x48 & op1to3=0x2 & RdFull & Z & opbit0=0 { - ptr:3 = zext(Z); - tmp:2 = *[code]:2 (ptr >> 1); - val:2 = (tmp >> (Z & 0x1)); - RdFull = val:1; +:lpm RdFull,Z is phase=1 & ophi7=0x48 & op1to3=0x2 & RdFull & Z & opbit0=0 { + ptr:$(PCBYTESIZE) = zext(Z); + tmp:$(PCBYTESIZE) = *[code]:$(PCBYTESIZE) (ptr >> 1); + val:$(PCBYTESIZE) = (tmp >> (Z & 0x1)); + RdFull = val:1; } # lpm Rd,Z+ -:lpm RdFull,Z"+" is phase=1 & ophi7=0x48 & op1to3=0x2 & RdFull & Z & opbit0=1 { - ptr:3 = zext(Z); - tmp:2 = *[code]:2 (ptr >> 1); - val:2 = (tmp >> (Z & 0x1)); - RdFull = val:1; - Z = Z + 1; +:lpm RdFull,Z"+" is phase=1 & ophi7=0x48 & op1to3=0x2 & RdFull & Z & opbit0=1 { + ptr:$(PCBYTESIZE) = zext(Z); + tmp:$(PCBYTESIZE) = *[code]:$(PCBYTESIZE) (ptr >> 1); + val:$(PCBYTESIZE) = (tmp >> (Z & 0x1)); + RdFull = val:1; + Z = Z + 1; } -# lsl - just an assembly mnenoic for add -:lsr RdFull is phase=1 & ophi7=0x4a & oplow4=0x6 & RdFull { - $(Cflag) = RdFull & 0x01; - RdFull = (RdFull >> 1); - $(Vflag) = $(Cflag); - setResultFlags(RdFull); +# lsl - just an assembly mnemonic for add +:lsr RdFull is phase=1 & ophi7=0x4a & oplow4=0x6 & RdFull { + $(Cflag) = RdFull & 0x01; + RdFull = (RdFull >> 1); + $(Vflag) = $(Cflag); + setResultFlags(RdFull); } # mov Rd,Rr -:mov RdFull,RrFull is phase=1 & ophi6=0xb & RdFull & RrFull { - RdFull = RrFull; +:mov RdFull,RrFull is phase=1 & ophi6=0xb & RdFull & RrFull { + RdFull = RrFull; } # movw Rd+1:Rd,Rr+1Rr -:movw Rdw4,Rrw4 is phase=1 & ophi8=0x1 & Rdw4 & Rrw4 { - Rdw4 = Rrw4; +:movw Rdw4,Rrw4 is phase=1 & ophi8=0x1 & Rdw4 & Rrw4 { + Rdw4 = Rrw4; } -:mul RdFull,RrFull is phase=1 & ophi6=0x27 & RdFull & RrFull { - a:2 = zext(RdFull); - b:2 = zext(RrFull); - R1R0 = a * b; - setMulFlags(R1R0); +:mul RdFull,RrFull is phase=1 & ophi6=0x27 & RdFull & RrFull { + a:2 = zext(RdFull); + b:2 = zext(RrFull); + R1R0 = a * b; + setMulFlags(R1R0); } -:muls RdHi,RrHi is phase=1 & ophi8=0x2 & RdHi & RrHi { - a:2 = sext(RdHi); - b:2 = sext(RrHi); - R1R0 = a * b; - setMulFlags(R1R0); +:muls RdHi,RrHi is phase=1 & ophi8=0x2 & RdHi & RrHi { + a:2 = sext(RdHi); + b:2 = sext(RrHi); + R1R0 = a * b; + setMulFlags(R1R0); } -:mulsu RdHi3,RrHi3 is phase=1 & ophi8=0x3 & opbit7=0 & opbit3=0 & RdHi3 & RrHi3 { - a:2 = sext(RdHi3); - b:2 = zext(RrHi3); - R1R0 = a * b; - setMulFlags(R1R0); +:mulsu RdHi3,RrHi3 is phase=1 & ophi8=0x3 & opbit7=0 & opbit3=0 & RdHi3 & RrHi3 { + a:2 = sext(RdHi3); + b:2 = zext(RrHi3); + R1R0 = a * b; + setMulFlags(R1R0); } -:neg RdFull is phase=1 & ophi7=0x4a & oplow4=1 & RdFull { - $(Vflag) = (RdFull == 0x80); - RdFull = 0 - RdFull; - $(Cflag) = (RdFull != 0); - setResultFlags(RdFull); +:neg RdFull is phase=1 & ophi7=0x4a & oplow4=1 & RdFull { + RdFull = -RdFull; + $(Vflag) = (RdFull == 0x80); + $(Cflag) = (RdFull != 0); + setResultFlags(RdFull); } -:nop is phase=1 & ophi16=0x0 { +:nop is phase=1 & ophi16=0x0 { } -:or RdFull,RrFull is phase=1 & ophi6=0xa & RdFull & RrFull { - RdFull = RdFull | RrFull; - $(Vflag) = 0; - setResultFlags(RdFull); +:or RdFull,RrFull is phase=1 & ophi6=0xa & RdFull & RrFull { + RdFull = RdFull | RrFull; + $(Vflag) = 0; + setResultFlags(RdFull); } -:ori RdHi,K8 is phase=1 & ophi4=0x6 & RdHi & K8 { - RdHi = RdHi | K8; - $(Vflag) = 0; - setResultFlags(RdHi); +:ori RdHi,K8 is phase=1 & ophi4=0x6 & RdHi & K8 { + RdHi = RdHi | K8; + $(Vflag) = 0; + setResultFlags(RdHi); } # out A,Rr # Note: Rr occupies the normal Rd position -:out Aio6,RdFull is phase=1 & ophi5=0x17 & Aio6 & RdFull { - Aio6 = RdFull; +:out Aio6,RdFull is phase=1 & ophi5=0x17 & Aio6 & RdFull { + Aio6 = RdFull; } -:out SPL,RdFull is phase=1 & ophi5=0x17 & RdFull & op9to10=3 & oplow4=0xd & SPL { - SPL = RdFull; +:out SPL,RdFull is phase=1 & ophi5=0x17 & RdFull & op9to10=3 & oplow4=0xd & SPL { + SPL = RdFull; } -:out SPH,RdFull is phase=1 & ophi5=0x17 & RdFull & op9to10=3 & oplow4=0xe & SPH { - SPH = RdFull; +:out SPH,RdFull is phase=1 & ophi5=0x17 & RdFull & op9to10=3 & oplow4=0xe & SPH { + SPH = RdFull; } -:pop RdFull is phase=1 & ophi7=0x48 & oplow4=0xf & RdFull { - pop8(RdFull); +:pop RdFull is phase=1 & ophi7=0x48 & oplow4=0xf & RdFull { + pop8(RdFull); } # push Rf # Note: Rr occupies the normal Rd position -:push RdFull is phase=1 & ophi7=0x49 & oplow4=0xf & RdFull { - push8(RdFull); +:push RdFull is phase=1 & ophi7=0x49 & oplow4=0xf & RdFull { + push8(RdFull); } -:rcall rel12dst is phase=1 & ophi4=0xd & rel12dst { - tmp:3 = inst_next >> 1; -@if PCBYTESIZE == "2" - ptr:2 = tmp:2; -@else - ptr:3 = tmp; -@endif - pushPC(ptr); - PC = &rel12dst; - call rel12dst; + +# rcall . is used by the compiler to create space on the stack +:rcall "." is phase=1 & ophi4=0xd & oplow12=0 { + ptr:$(PCBYTESIZE) = inst_next >> 1; + pushPC(ptr); } -:ret is phase=1 & ophi16=0x9508 { - # Could also handle word size options here - popPC(PC); - return [PC]; + +:rcall rel12dst is phase=1 & ophi4=0xd & rel12dst { + ptr:$(PCBYTESIZE) = inst_next >> 1; + pushPC(ptr); + PC = &rel12dst; + call rel12dst; } -:reti is phase=1 & ophi16=0x9518 { - $(Iflag) = 1; - popPC(PC); - return [PC]; + +:ret is phase=1 & ophi16=0x9508 { + # Could also handle word size options here + popPC(PC); + return [PC]; +} +:reti is phase=1 & ophi16=0x9518 { + $(Iflag) = 1; + popPC(PC); + return [PC]; } # rjmp k -:rjmp rel12dst is phase=1 & ophi4=0xc & rel12dst { - goto rel12dst; +:rjmp rel12dst is phase=1 & ophi4=0xc & rel12dst { + goto rel12dst; } # ROL is ADC Rd,Rd -:ror RdFull is phase=1 & ophi7=0x4a & oplow4=0x7 & RdFull { - local c = $(Cflag); - local cnew = RdFull & 0x01; - RdFull = (c << 7) | (RdFull >> 1); - $(Cflag) = cnew; - $(Nflag) = (RdFull & 0x80) == 0x80; - $(Vflag) = $(Cflag) ^ $(Nflag); - setResultFlags(RdFull); +:ror RdFull is phase=1 & ophi7=0x4a & oplow4=0x7 & RdFull { + local c = $(Cflag); + local cnew = RdFull & 0x01; + RdFull = (c << 7) | (RdFull >> 1); + $(Cflag) = cnew; + $(Nflag) = (RdFull & 0x80) == 0x80; + $(Vflag) = $(Cflag) ^ $(Nflag); + setResultFlags(RdFull); } -:sbc RdFull,RrFull is phase=1 & ophi6=0x2 & RdFull & RrFull { - doSubtractWithCarry(RdFull,RrFull,RdFull); + +:sbc RdFull,RrFull is phase=1 & ophi6=0x2 & RdFull & RrFull { + doSubtractWithCarry(RdFull,RrFull,RdFull); } -:sbci RdHi,K8 is phase=1 & ophi4=4 & RdHi & K8 { - doSubtractWithCarry(RdHi,K8,RdHi); + +:sbci RdHi,K8 is phase=1 & ophi4=4 & RdHi & K8 { + doSubtractWithCarry(RdHi,K8,RdHi); } + @ifdef FUSION # subi sbci -:subiw op1RdPairHi,K16fuse is phase=1 & op1hi4=0x5 & op2hi4=0x4 & K16fuse & fusion16rkrkPred & op1RdPairHi { - # doSubtract(op1RdPairHi,K16fuse,op1RdPairHi); - local res = op1RdPairHi - K16fuse; - local pre = op1RdPairHi; - setVflagForSub16(pre,K16fuse); - setSubCarry(op1RdPairHi, K16fuse); - op1RdPairHi = res; - setResult16Flags(res); - $(Sflag) = pre s< K16fuse; +:subiw op1RdPairHi,K16fuse is phase=1 & op1hi4=0x5 & op2hi4=0x4 & K16fuse & fusion16rkrkPred & op1RdPairHi { + # doSubtract(op1RdPairHi,K16fuse,op1RdPairHi); + local res = op1RdPairHi - K16fuse; + local pre = op1RdPairHi; + setVflagForSub16(pre,K16fuse); + setSubCarry(op1RdPairHi, K16fuse); + op1RdPairHi = res; + setResult16Flags(res); + $(Sflag) = pre s< K16fuse; } + @endif -:sbi Aio5,oplow3 is phase=1 & ophi8=0x9a & Aio5 & oplow3 { - Aio5 = Aio5 | (1 << oplow3); +:sbi Aio5,oplow3 is phase=1 & ophi8=0x9a & Aio5 & oplow3 { + Aio5 = Aio5 | (1 << oplow3); } -:sbic Aio5,oplow3 is phase=1 & ophi8=0x99 & Aio5 & oplow3 [ useSkipCond=1; globalset(inst_next,useSkipCond); ] { - SKIP = ((Aio5 & (1 << oplow3)) == 0); +:sbic Aio5,oplow3 is phase=1 & ophi8=0x99 & Aio5 & oplow3 [ useSkipCond=1; globalset(inst_next,useSkipCond); ] { + SKIP = ((Aio5 & (1 << oplow3)) == 0); } -:sbis Aio5,oplow3 is phase=1 & ophi8=0x9b & Aio5 & oplow3 [ useSkipCond=1; globalset(inst_next,useSkipCond); ] { - SKIP = ((Aio5 & (1 << oplow3)) != 0); +:sbis Aio5,oplow3 is phase=1 & ophi8=0x9b & Aio5 & oplow3 [ useSkipCond=1; globalset(inst_next,useSkipCond); ] { + SKIP = ((Aio5 & (1 << oplow3)) != 0); } -:sbiw Rdw2,K6 is phase=1 & ophi8=0x97 & Rdw2 & K6 { - local pre = Rdw2; - Rdw2 = Rdw2 - zext(K6); - $(Cflag) = Rdw2 < zext(K6); - $(Vflag) = (0x8000 == (pre & 0x8000)) & ((Rdw2 & 0x8000) == 0x0000); - setResult16Flags(Rdw2); +:sbiw Rdw2,K6 is phase=1 & ophi8=0x97 & Rdw2 & K6 { + local pre = Rdw2; + Rdw2 = Rdw2 - zext(K6); + $(Cflag) = zext(K6) > pre; + $(Vflag) = (0x8000 == (pre & 0x8000)) & ((Rdw2 & 0x8000) == 0x0000); + setResult16Flags(Rdw2); } # sbr is an alias for ori -:sbrc RdFull,oplow3 is phase=1 & ophi7=0x7e & opbit3=0 & RdFull & oplow3 [ useSkipCond=1; globalset(inst_next,useSkipCond); ] { - SKIP = ((RdFull & (1 << oplow3)) == 0); +:sbrc RdFull,oplow3 is phase=1 & ophi7=0x7e & opbit3=0 & RdFull & oplow3 [ useSkipCond=1; globalset(inst_next,useSkipCond); ] { + SKIP = ((RdFull & (1 << oplow3)) == 0); } -:sbrs RdFull,oplow3 is phase=1 & ophi7=0x7f & opbit3=0 & RdFull & oplow3 [ useSkipCond=1; globalset(inst_next,useSkipCond); ] { - SKIP = ((RdFull & (1 << oplow3)) != 0); +:sbrs RdFull,oplow3 is phase=1 & ophi7=0x7f & opbit3=0 & RdFull & oplow3 [ useSkipCond=1; globalset(inst_next,useSkipCond); ] { + SKIP = ((RdFull & (1 << oplow3)) != 0); } # More flag setting sec, seh, sei, sen, ses, set, sev, sez # Implemented as bset -:ser RdHi is phase=1 & ophi8=0xef & oplow4=0xf & RdHi { - RdHi = 0xff; +:ser RdHi is phase=1 & ophi8=0xef & oplow4=0xf & RdHi { + RdHi = 0xff; } + define pcodeop sleep; -:sleep is phase=1 & ophi16=0x9588 { - sleep(); + +:sleep is phase=1 & ophi16=0x9588 { + sleep(); } -define pcodeop store_program_mem; # make this stand out. -:spm Z is phase=1 & ophi16=0x95e8 & Z { - ptr:3 = zext(Z) << 1; - *[code]:2 ptr = R1R0; - store_program_mem(); + +define pcodeop store_program_mem; # make this stand out. + +:spm Z is phase=1 & ophi16=0x95e8 & Z { + ptr:$(PCBYTESIZE) = zext(Z) << 1; + *[code]:$(PCBYTESIZE) ptr = R1R0; + store_program_mem(); } -:spm Z^"+" is phase=1 & ophi16=0x95f8 & Z { - ptr:3 = zext(Z) << 1; - *[code]:2 ptr = R1R0; - Z = Z + 1; - store_program_mem(); +:spm Z^"+" is phase=1 & ophi16=0x95f8 & Z { + ptr:$(PCBYTESIZE) = zext(Z) << 1; + *[code]:$(PCBYTESIZE) ptr = R1R0; + Z = Z + 1; + store_program_mem(); } # For stores, see the ld code (just flip bit 9) -:st X, RdFull is phase=1 & ophi7=0x49 & oplow4=0xc & X & RdFull { - tmp:2 = X; - *[mem]:1 tmp = RdFull; +:st X, RdFull is phase=1 & ophi7=0x49 & oplow4=0xc & X & RdFull { + tmp:2 = X; + *[mem]:1 tmp = RdFull; } # st Rd,Y; st Rd,Z -:st RstPtr, RdFull is phase=1 & ophi7=0x41 & oplow3=0x0 & RdFull & RstPtr { - tmp:2 = RstPtr; - *[mem]:1 tmp = RdFull; +:st RstPtr, RdFull is phase=1 & ophi7=0x41 & oplow3=0x0 & RdFull & RstPtr { + tmp:2 = RstPtr; + *[mem]:1 tmp = RdFull; } # st Rd,Y+ ; st Rd, X+; st Rd, Z+ -StPlus: RstPtr^"+" is RstPtr { tmp:2 = RstPtr; RstPtr = RstPtr + 0x01; export tmp; } -:st StPlus, RdFull is phase=1 & ophi7=0x49 & oplow2=0x01 & RdFull & StPlus { - *[mem]:1 StPlus = RdFull; -} -# st Rd,-Y ; st Rd, -X; st Rd, -Z -StPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; } -:st StPredec, RdFull is phase=1 & ophi7=0x49 & oplow2=0x02 & RdFull & StPredec { - tmp:2 = StPredec; - *[mem]:1 tmp = RdFull; -} -# std Rd,Y+q; std Rd,Z+q -StdYq: Rstq^"+"^q6 is Rstq & q6 { local ptr = Rstq + zext(q6); export ptr; } -:std StdYq, RdFull is phase=1 & ophi2=0x2 & opbit12=0 & opbit9=1 & RdFull & StdYq { - *[mem]:1 StdYq = RdFull; +StPlus: RstPtr^"+" is RstPtr { tmp:2 = RstPtr; RstPtr = RstPtr + 0x01; export tmp; } + +:st StPlus, RdFull is phase=1 & ophi7=0x49 & oplow2=0x01 & RdFull & StPlus { + *[mem]:1 StPlus = RdFull; } -:sts next16memPtrVal1,RdFull is phase=1 & ophi7=0x49 & oplow4=0 & RdFull; next16memPtrVal1 { - next16memPtrVal1 = RdFull; +# st Rd,-Y ; st Rd, -X; st Rd, -Z +StPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; } + +:st StPredec, RdFull is phase=1 & ophi7=0x49 & oplow2=0x02 & RdFull & StPredec { + tmp:2 = StPredec; + *[mem]:1 tmp = RdFull; } + +# std Rd,Y+q; std Rd,Z+q +StdYq: Rstq^"+"^q6 is Rstq & q6 { local ptr = Rstq + zext(q6); export ptr; } + +:std StdYq, RdFull is phase=1 & ophi2=0x2 & opbit12=0 & opbit9=1 & RdFull & StdYq { + *[mem]:1 StdYq = RdFull; +} + +:sts next16memPtrVal1,RdFull is phase=1 & ophi7=0x49 & oplow4=0 & RdFull; next16memPtrVal1 { + next16memPtrVal1 = RdFull; +} + @ifdef FUSION # sts ; sts emits backwards with respect to lds; lds -:stsw stswMemPtrVal2,stswop2RdPair is phase=1 & ldswop1hi7=0x49 & ldswop2hi7=0x49 & ldswop1low4=0 & ldswop2low4=0 & stswMemPtrVal2 & stswop2RdPair & stswPairPred & stswConstPairPred { - stswMemPtrVal2 = stswop2RdPair; +:stsw stswMemPtrVal2,stswop2RdPair is phase=1 & ldswop1hi7=0x49 & ldswop2hi7=0x49 & ldswop1low4=0 & ldswop2low4=0 & stswMemPtrVal2 & stswop2RdPair & stswPairPred & stswConstPairPred { + stswMemPtrVal2 = stswop2RdPair; } + @endif # see manual for computation of address for 16-bit STS -:sts RdHi is phase=1 & ophi5=0x15 & RdHi { todo(); } -:sub RdFull,RrFull is phase=1 & ophi6=0x6 & RdFull & RrFull { - doSubtract(RdFull,RrFull,RdFull); +:sts RdHi is phase=1 & ophi5=0x15 & RdHi { todo(); } +:sub RdFull,RrFull is phase=1 & ophi6=0x6 & RdFull & RrFull { + doSubtract(RdFull,RrFull,RdFull); } # Rd,K -:subi RdHi,K8 is phase=1 & ophi4=5 & RdHi & K8 { - doSubtract(RdHi,K8,RdHi); +:subi RdHi,K8 is phase=1 & ophi4=5 & RdHi & K8 { + doSubtract(RdHi,K8,RdHi); } -:swap RdFull is phase=1 & ophi7=0x4a & oplow4=2 & RdFull { - RdFull = (RdFull >> 4) | (RdFull << 4); +:swap RdFull is phase=1 & ophi7=0x4a & oplow4=2 & RdFull { + RdFull = (RdFull >> 4) | (RdFull << 4); } + # tst is AND Rd,Rd define pcodeop watchdog_reset; -:wdr is phase=1 & ophi16=0x95a8 { - watchdog_reset(); + +:wdr is phase=1 & ophi16=0x95a8 { + watchdog_reset(); } -:xch RdFull is phase=1 & ophi7=0x49 & oplow4=0x4 & RdFull { - ptr:2 = Z; - local tmp = *[mem]:1 ptr; - *[mem]:1 ptr = RdFull; - RdFull = tmp; +:xch RdFull is phase=1 & ophi7=0x49 & oplow4=0x4 & RdFull { + ptr:2 = Z; + local tmp = *[mem]:1 ptr; + *[mem]:1 ptr = RdFull; + RdFull = tmp; } diff --git a/Ghidra/Processors/Atmel/data/languages/avr8e.slaspec b/Ghidra/Processors/Atmel/data/languages/avr8e.slaspec index e24e44a14d..7895d5a6d1 100644 --- a/Ghidra/Processors/Atmel/data/languages/avr8e.slaspec +++ b/Ghidra/Processors/Atmel/data/languages/avr8e.slaspec @@ -1,7 +1,7 @@ -# AVR8 with 22-bit addressable code space +# AVR8 with 16-bit addressable code space and support for -@define PCBYTESIZE "3" -@define HASEIND "0" +@define PCBYTESIZE "2" +@define HASEIND "1" @include "avr8.sinc" diff --git a/Ghidra/Processors/Atmel/data/languages/avr8egcc.cspec b/Ghidra/Processors/Atmel/data/languages/avr8egcc.cspec index 3c9b3d7222..2887d0e7d4 100644 --- a/Ghidra/Processors/Atmel/data/languages/avr8egcc.cspec +++ b/Ghidra/Processors/Atmel/data/languages/avr8egcc.cspec @@ -18,7 +18,7 @@ - + @@ -40,18 +40,24 @@ - + + + + + + + @@ -72,6 +78,9 @@ + + + @@ -103,32 +112,32 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Ghidra/Processors/Atmel/data/languages/avr8gcc.cspec b/Ghidra/Processors/Atmel/data/languages/avr8gcc.cspec index 7c62f5cb38..1d9b809ece 100644 --- a/Ghidra/Processors/Atmel/data/languages/avr8gcc.cspec +++ b/Ghidra/Processors/Atmel/data/languages/avr8gcc.cspec @@ -18,7 +18,7 @@ - + @@ -45,12 +45,18 @@ + + + + + + @@ -71,6 +77,9 @@ + + + diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_31_GCC_O0_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_31_GCC_O0_EmulatorTest.java new file mode 100644 index 0000000000..84b8b46890 --- /dev/null +++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_31_GCC_O0_EmulatorTest.java @@ -0,0 +1,59 @@ +/* ### + * IP: GHIDRA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ghidra.test.processors; + +import ghidra.framework.options.Options; +import ghidra.program.model.listing.Program; +import ghidra.test.processors.support.EmulatorTestRunner; +import ghidra.test.processors.support.ProcessorEmulatorTestAdapter; +import junit.framework.Test; + +public class AVR8_31_GCC_O0_EmulatorTest extends ProcessorEmulatorTestAdapter { + + private static final String LANGUAGE_ID = "avr8:LE:16:default"; + private static final String COMPILER_SPEC_ID = "gcc"; + + private static final String[] REG_DUMP_SET = new String[] {}; + + public AVR8_31_GCC_O0_EmulatorTest(String name) throws Exception { + super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET); + } + + @Override + protected String getProcessorDesignator() { + return "AVR8_31_GCC_O0"; + } + + protected void initializeState(EmulatorTestRunner testRunner, Program program) throws Exception { + // These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems. + testRunner.setRegister("SP", 0x0); + testRunner.setRegister("R1", 0x0); + testRunner.setRegister("Y", 0x0); + testRunner.setRegister("W", 0x0); + testRunner.setRegister("SREG", 0x0); + } + + @Override + protected void setAnalysisOptions(Options analysisOptions) { + super.setAnalysisOptions(analysisOptions); + analysisOptions.setBoolean("Reference", false); // too many bad disassemblies + analysisOptions.setBoolean("Data Reference", false); + } + + public static Test suite() { + return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(AVR8_31_GCC_O0_EmulatorTest.class); + } +} diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_31_GCC_O3_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_31_GCC_O3_EmulatorTest.java new file mode 100644 index 0000000000..b47f4efcf5 --- /dev/null +++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_31_GCC_O3_EmulatorTest.java @@ -0,0 +1,59 @@ +/* ### + * IP: GHIDRA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ghidra.test.processors; + +import ghidra.framework.options.Options; +import ghidra.program.model.listing.Program; +import ghidra.test.processors.support.EmulatorTestRunner; +import ghidra.test.processors.support.ProcessorEmulatorTestAdapter; +import junit.framework.Test; + +public class AVR8_31_GCC_O3_EmulatorTest extends ProcessorEmulatorTestAdapter { + + private static final String LANGUAGE_ID = "avr8:LE:16:default"; + private static final String COMPILER_SPEC_ID = "gcc"; + + private static final String[] REG_DUMP_SET = new String[] {}; + + public AVR8_31_GCC_O3_EmulatorTest(String name) throws Exception { + super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET); + } + + @Override + protected String getProcessorDesignator() { + return "AVR8_31_GCC_O3"; + } + + protected void initializeState(EmulatorTestRunner testRunner, Program program) throws Exception { + // These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems. + testRunner.setRegister("SP", 0x0); + testRunner.setRegister("R1", 0x0); + testRunner.setRegister("Y", 0x0); + testRunner.setRegister("W", 0x0); + testRunner.setRegister("SREG", 0x0); + } + + @Override + protected void setAnalysisOptions(Options analysisOptions) { + super.setAnalysisOptions(analysisOptions); + analysisOptions.setBoolean("Reference", false); // too many bad disassemblies + analysisOptions.setBoolean("Data Reference", false); + } + + public static Test suite() { + return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(AVR8_31_GCC_O3_EmulatorTest.class); + } +} diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_51_GCC_O0_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_51_GCC_O0_EmulatorTest.java new file mode 100644 index 0000000000..baa871efa8 --- /dev/null +++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_51_GCC_O0_EmulatorTest.java @@ -0,0 +1,59 @@ +/* ### + * IP: GHIDRA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ghidra.test.processors; + +import ghidra.framework.options.Options; +import ghidra.program.model.listing.Program; +import ghidra.test.processors.support.EmulatorTestRunner; +import ghidra.test.processors.support.ProcessorEmulatorTestAdapter; +import junit.framework.Test; + +public class AVR8_51_GCC_O0_EmulatorTest extends ProcessorEmulatorTestAdapter { + + private static final String LANGUAGE_ID = "avr8:LE:16:extended"; + private static final String COMPILER_SPEC_ID = "gcc"; + + private static final String[] REG_DUMP_SET = new String[] {}; + + public AVR8_51_GCC_O0_EmulatorTest(String name) throws Exception { + super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET); + } + + @Override + protected String getProcessorDesignator() { + return "AVR8_51_GCC_O0"; + } + + protected void initializeState(EmulatorTestRunner testRunner, Program program) throws Exception { + // These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems. + testRunner.setRegister("SP", 0x0); + testRunner.setRegister("R1", 0x0); + testRunner.setRegister("Y", 0x0); + testRunner.setRegister("W", 0x0); + testRunner.setRegister("SREG", 0x0); + } + + @Override + protected void setAnalysisOptions(Options analysisOptions) { + super.setAnalysisOptions(analysisOptions); + analysisOptions.setBoolean("Reference", false); // too many bad disassemblies + analysisOptions.setBoolean("Data Reference", false); + } + + public static Test suite() { + return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(AVR8_51_GCC_O0_EmulatorTest.class); + } +} diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_51_GCC_O3_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_51_GCC_O3_EmulatorTest.java new file mode 100644 index 0000000000..68618ed63d --- /dev/null +++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_51_GCC_O3_EmulatorTest.java @@ -0,0 +1,59 @@ +/* ### + * IP: GHIDRA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ghidra.test.processors; + +import ghidra.framework.options.Options; +import ghidra.program.model.listing.Program; +import ghidra.test.processors.support.EmulatorTestRunner; +import ghidra.test.processors.support.ProcessorEmulatorTestAdapter; +import junit.framework.Test; + +public class AVR8_51_GCC_O3_EmulatorTest extends ProcessorEmulatorTestAdapter { + + private static final String LANGUAGE_ID = "avr8:LE:16:extended"; + private static final String COMPILER_SPEC_ID = "gcc"; + + private static final String[] REG_DUMP_SET = new String[] {}; + + public AVR8_51_GCC_O3_EmulatorTest(String name) throws Exception { + super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET); + } + + @Override + protected String getProcessorDesignator() { + return "AVR8_51_GCC_O3"; + } + + protected void initializeState(EmulatorTestRunner testRunner, Program program) throws Exception { + // These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems. + testRunner.setRegister("SP", 0x0); + testRunner.setRegister("R1", 0x0); + testRunner.setRegister("Y", 0x0); + testRunner.setRegister("W", 0x0); + testRunner.setRegister("SREG", 0x0); + } + + @Override + protected void setAnalysisOptions(Options analysisOptions) { + super.setAnalysisOptions(analysisOptions); + analysisOptions.setBoolean("Reference", false); // too many bad disassemblies + analysisOptions.setBoolean("Data Reference", false); + } + + public static Test suite() { + return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(AVR8_51_GCC_O3_EmulatorTest.class); + } +} diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_6_GCC_O0_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_6_GCC_O0_EmulatorTest.java new file mode 100644 index 0000000000..06b348a6a0 --- /dev/null +++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_6_GCC_O0_EmulatorTest.java @@ -0,0 +1,59 @@ +/* ### + * IP: GHIDRA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ghidra.test.processors; + +import ghidra.framework.options.Options; +import ghidra.program.model.listing.Program; +import ghidra.test.processors.support.EmulatorTestRunner; +import ghidra.test.processors.support.ProcessorEmulatorTestAdapter; +import junit.framework.Test; + +public class AVR8_6_GCC_O0_EmulatorTest extends ProcessorEmulatorTestAdapter { + + private static final String LANGUAGE_ID = "avr8:LE:16:atmega256"; + private static final String COMPILER_SPEC_ID = "gcc"; + + private static final String[] REG_DUMP_SET = new String[] {}; + + public AVR8_6_GCC_O0_EmulatorTest(String name) throws Exception { + super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET); + } + + @Override + protected String getProcessorDesignator() { + return "AVR8_6_GCC_O0"; + } + + protected void initializeState(EmulatorTestRunner testRunner, Program program) throws Exception { + // These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems. + testRunner.setRegister("SP", 0x0); + testRunner.setRegister("R1", 0x0); + testRunner.setRegister("Y", 0x0); + testRunner.setRegister("W", 0x0); + testRunner.setRegister("SREG", 0x0); + } + + @Override + protected void setAnalysisOptions(Options analysisOptions) { + super.setAnalysisOptions(analysisOptions); + analysisOptions.setBoolean("Reference", false); // too many bad disassemblies + analysisOptions.setBoolean("Data Reference", false); + } + + public static Test suite() { + return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(AVR8_6_GCC_O0_EmulatorTest.class); + } +} diff --git a/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_6_GCC_O3_EmulatorTest.java b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_6_GCC_O3_EmulatorTest.java new file mode 100644 index 0000000000..cf648b1c99 --- /dev/null +++ b/Ghidra/Processors/Atmel/src/test.processors/java/ghidra/test/processors/AVR8_6_GCC_O3_EmulatorTest.java @@ -0,0 +1,59 @@ +/* ### + * IP: GHIDRA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ghidra.test.processors; + +import ghidra.framework.options.Options; +import ghidra.program.model.listing.Program; +import ghidra.test.processors.support.EmulatorTestRunner; +import ghidra.test.processors.support.ProcessorEmulatorTestAdapter; +import junit.framework.Test; + +public class AVR8_6_GCC_O3_EmulatorTest extends ProcessorEmulatorTestAdapter { + + private static final String LANGUAGE_ID = "avr8:LE:16:atmega256"; + private static final String COMPILER_SPEC_ID = "gcc"; + + private static final String[] REG_DUMP_SET = new String[] {}; + + public AVR8_6_GCC_O3_EmulatorTest(String name) throws Exception { + super(name, LANGUAGE_ID, COMPILER_SPEC_ID, REG_DUMP_SET); + } + + @Override + protected String getProcessorDesignator() { + return "AVR8_6_GCC_O3"; + } + + protected void initializeState(EmulatorTestRunner testRunner, Program program) throws Exception { + // These eliminate "uninitialized register" errors. Not strictly needed, but helps find actual problems. + testRunner.setRegister("SP", 0x0); + testRunner.setRegister("R1", 0x0); + testRunner.setRegister("Y", 0x0); + testRunner.setRegister("W", 0x0); + testRunner.setRegister("SREG", 0x0); + } + + @Override + protected void setAnalysisOptions(Options analysisOptions) { + super.setAnalysisOptions(analysisOptions); + analysisOptions.setBoolean("Reference", false); // too many bad disassemblies + analysisOptions.setBoolean("Data Reference", false); + } + + public static Test suite() { + return ProcessorEmulatorTestAdapter.buildEmulatorTestSuite(AVR8_6_GCC_O3_EmulatorTest.class); + } +}