GT-3106: Implement AVR 8 pcodetests

Updated AVR 8 to implement pcode tests and correct any issues found as a
result.
This commit is contained in:
ghidorahrex 2019-09-04 09:37:23 -04:00
parent 20ac7ece0a
commit 947b7635ce
28 changed files with 3992 additions and 3398 deletions

View file

@ -11,6 +11,7 @@ pcodetest/build||GHIDRA||||END|
pcodetest/build.py||GHIDRA||||END| pcodetest/build.py||GHIDRA||||END|
pcodetest/c_src/BIOPS.test||GHIDRA||||END| pcodetest/c_src/BIOPS.test||GHIDRA||||END|
pcodetest/c_src/BIOPS2.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_DOUBLE.test||GHIDRA||||END|
pcodetest/c_src/BIOPS_FLOAT.test||GHIDRA||||END| pcodetest/c_src/BIOPS_FLOAT.test||GHIDRA||||END|
pcodetest/c_src/BIOPS_LONGLONG.test||GHIDRA||||END| pcodetest/c_src/BIOPS_LONGLONG.test||GHIDRA||||END|

View file

@ -1,677 +1,413 @@
#include "pcode_test.h" #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); extern u1 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(u1_complexLogic(237, 210, 0, 0, 153, 76), 11);
ASSERTU1(pcode_u1_complexLogic(139, 0, 34, 0, 86, 154), 10); ASSERTU1(u1_complexLogic(139, 0, 34, 0, 86, 154), 10);
ASSERTU1(pcode_u1_complexLogic(24, 209, 254, 0, 228, 217), 15); ASSERTU1(u1_complexLogic(24, 209, 254, 0, 228, 217), 15);
ASSERTU1(pcode_u1_complexLogic(0, 9, 209, 0, 165, 150), 11); 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); extern i1 i1_complexLogic(i1 a, i1 b, i1 c, i1 d, i1 e, i1 f);
ASSERTI1(biopLei1i1(2, 1), 0); ASSERTI1(i1_complexLogic((i1) -150, 45, (i1) -232, 0, 0, 37), 15);
ASSERTI1(biopLei1i1(~2, ~1), 1); 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); extern u1 u1_compareLogic(u1 lhs, u1 rhs);
ASSERTU4(biopLogicAndu4u4(0x01010101, 0x01010101), 1); ASSERTU1(u1_compareLogic(0x1, 0x1), 1);
ASSERTU4(biopLogicAndu4u4(2, 1), 1); ASSERTU1(u1_compareLogic(0x1, 0x2), 23);
ASSERTU4(biopLogicAndu4u4(U4_MAX, U4_MAX), 1) ASSERTU1(u1_compareLogic(0x2, 0x1), 22);
} }
TEST biopGtu2u2_Main() TEST i1_compareLogic_Main()
{ {
extern u2 biopGtu2u2(u2 lhs, u2 rhs); extern i1 i1_compareLogic(i1 lhs, i1 rhs);
ASSERTU2(biopGtu2u2(2, 1), 1); ASSERTI1(i1_compareLogic(0x1, 0x1), 21);
ASSERTU2(biopGtu2u2(U2_MAX, U2_MAX), 0); ASSERTI1(i1_compareLogic(0x1, 0x2), 21);
ASSERTU2(biopGtu2u2(U2_MAX, 0), 1); ASSERTI1(i1_compareLogic(0x2, 0x1), 22);
ASSERTU2(biopGtu2u2(0, U2_MAX), 0); ASSERTI1(i1_compareLogic(-0x1, -0x1), 21);
ASSERTI1(i1_compareLogic(-0x1, -0x2), 21);
ASSERTI1(i1_compareLogic(-0x2, -0x1), 24);
} }
TEST biopEqi1i1_Main() /* Comparison operators */
{
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);
}
TEST biopLogicOri4i4_Main() TEST u1_greaterThan_Main()
{ {
extern i4 biopLogicOri4i4(i4 lhs, i4 rhs); extern u1 u1_greaterThan(u1 lhs, u1 rhs);
ASSERTI4(biopLogicOri4i4(0x01010101, 0x01010101), 1); ASSERTU1(u1_greaterThan(0x01, 0x01), 0);
ASSERTI4(biopLogicOri4i4(2, 1), 1); ASSERTU1(u1_greaterThan(U1_MAX, U1_MAX), 0);
ASSERTI4(biopLogicOri4i4(I4_MAX, I4_MAX), 1); ASSERTU1(u1_greaterThan(U1_MAX, 0), 1);
ASSERTI4(biopLogicOri4i4(I4_MIN, I4_MIN), 1); ASSERTU1(u1_greaterThan(0, U1_MAX), 0);
ASSERTI4(biopLogicOri4i4(0, 0), 0);
} }
TEST unopPlusu4_Main() TEST u1_greaterThanEquals_Main()
{ {
extern u4 unopPlusu4(u4 lhs); extern u1 u1_greaterThanEquals(u1 lhs, u1 rhs);
ASSERTU4(unopPlusu4(0x01010101), 0x01010101); ASSERTU1(u1_greaterThanEquals(0x01, 0x01), 1);
ASSERTU4(unopPlusu4(2), 2); ASSERTU1(u1_greaterThanEquals(U1_MAX, U1_MAX), 1);
ASSERTU4(unopPlusu4(U4_MAX), -1); ASSERTU1(u1_greaterThanEquals(U1_MAX, 0), 1);
ASSERTU4(unopPlusu4(~1000), 4294966295); ASSERTU1(u1_greaterThanEquals(0, U1_MAX), 0);
ASSERTU4(unopPlusu4(0), 0);
} }
TEST biopLeu2u2_Main() TEST u1_lessThan_Main()
{ {
extern u2 biopLeu2u2(u2 lhs, u2 rhs); extern u1 u1_lessThan(u1 lhs, u1 rhs);
ASSERTU2(biopLeu2u2(2, 1), 0); ASSERTU1(u1_lessThan(0x01, 0x01), 0);
ASSERTU2(biopLeu2u2(U2_MAX, U2_MAX), 1); ASSERTU1(u1_lessThan(U1_MAX, U1_MAX), 0);
ASSERTU2(biopLeu2u2(U2_MIN, U2_MIN), 1); ASSERTU1(u1_lessThan(U1_MAX, 0), 0);
ASSERTU2(biopLeu2u2(1, 2), 1);
} }
TEST biopLogicAndi4i4_Main() TEST u1_lessThanEquals_Main()
{ {
extern i4 biopLogicAndi4i4(i4 lhs, i4 rhs); extern u1 u1_lessThanEquals(u1 lhs, u1 rhs);
ASSERTI4(biopLogicAndi4i4(0x01010101, 0x01010101), 1); ASSERTU1(u1_lessThanEquals(0x01, 0x01), 1);
ASSERTI4(biopLogicAndi4i4(2, 1), 1); ASSERTU1(u1_lessThanEquals(U1_MAX, U1_MAX), 1);
ASSERTI4(biopLogicAndi4i4(0x01000101, 0x01010101), 1); ASSERTU1(u1_lessThanEquals(0, 0), 1);
ASSERTI4(biopLogicAndi4i4(0x01000101, 0x0), 0); ASSERTU1(u1_lessThanEquals(U1_MAX, 0), 0);
ASSERTI4(biopLogicAndi4i4(I4_MAX, I4_MAX), 1); ASSERTU1(u1_lessThanEquals(0, U1_MAX), 1);
ASSERTI4(biopLogicAndi4i4(I4_MIN, I4_MIN), 1);
ASSERTI4(biopLogicAndi4i4(0, 0), 0);
} }
TEST biopOri1i1_Main() TEST u1_equals_Main()
{ {
extern i1 biopOri1i1(i1 lhs, i1 rhs); extern u1 u1_equals(u1 lhs, u1 rhs);
ASSERTI1(biopOri1i1(2, 1), 3); ASSERTU1(u1_equals(0x01, 0x01), 1);
ASSERTI1(biopOri1i1(I1_MAX, I1_MAX), 127); ASSERTU1(u1_equals(U1_MAX, U1_MAX), 1);
ASSERTI1(biopOri1i1(I1_MIN, I1_MIN), -128); ASSERTU1(u1_equals(U1_MAX, 0), 0);
ASSERTI1(biopOri1i1(0, 0), 0); ASSERTU1(u1_equals(0, U1_MAX), 0);
} }
TEST biopRemainderi2i2_Main() TEST u1_notEquals_Main()
{ {
extern i2 biopRemainderi2i2(i2 lhs, i2 rhs); extern u1 u1_notEquals(u1 lhs, u1 rhs);
ASSERTI2(biopRemainderi2i2(0x0101, 0x0101), 0x0); ASSERTU1(u1_notEquals(0x01, 0x01), 0);
ASSERTI2(biopRemainderi2i2(I2_MAX, I2_MAX), 0x0); ASSERTU1(u1_notEquals(U1_MAX, U1_MAX), 0);
ASSERTI2(biopRemainderi2i2(I2_MIN, I2_MIN), 0x0); ASSERTU1(u1_notEquals(U1_MAX, 0), 1);
ASSERTI2(biopRemainderi2i2(0, I2_MIN), 0x0); ASSERTU1(u1_notEquals(0, U1_MAX), 1);
} }
TEST biopMulti2i2_Main() TEST i1_greaterThan_Main()
{ {
extern i2 biopMulti2i2(i2 lhs, i2 rhs); extern i1 i1_greaterThan(i1 lhs, i1 rhs);
ASSERTI2(biopMulti2i2(0x0101, 0x0101), 0x201); ASSERTI1(i1_greaterThan(2, 1), 1);
ASSERTI2(biopMulti2i2(0x0101, -0x0101), -513); ASSERTI1(i1_greaterThan(I1_MAX, I1_MAX), 0);
ASSERTI2(biopMulti2i2(0, -0x0101), 0); ASSERTI1(i1_greaterThan(I1_MAX, I1_MIN), 1);
ASSERTI2(biopMulti2i2(2, 1), 2); ASSERTI1(i1_greaterThan(I1_MIN, I1_MAX), 0);
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);
} }
TEST biopEqu2u2_Main() TEST i1_greaterThanEquals_Main()
{ {
extern u2 biopEqu2u2(u2 lhs, u2 rhs); extern i1 i1_greaterThanEquals(i1 lhs, i1 rhs);
ASSERTU2(biopEqu2u2(2, 1), 0); ASSERTI1(i1_greaterThanEquals(2, 1), 1);
ASSERTU2(biopEqu2u2(U2_MAX, U2_MAX), 1); ASSERTI1(i1_greaterThanEquals(I1_MAX, I1_MAX), 1);
ASSERTU2(biopEqu2u2(U2_MIN, U2_MIN), 1); ASSERTI1(i1_greaterThanEquals(I1_MAX, I1_MIN), 1);
ASSERTU2(biopEqu2u2(0, 0), 1); ASSERTI1(i1_greaterThanEquals(I1_MIN, I1_MAX), 0);
} }
TEST biopDividi2i2_Main() TEST i1_lessThan_Main()
{ {
extern i2 biopDividi2i2(i2 lhs, i2 rhs); extern i1 i1_lessThan(i1 lhs, i1 rhs);
ASSERTI2(biopDividi2i2(0x0101, 0x0101), 0x1); ASSERTI1(i1_lessThan(2, 1), 0);
ASSERTI2(biopDividi2i2(I2_MAX, I2_MAX), 0x1); ASSERTI1(i1_lessThan(I1_MAX, I1_MAX), 0);
ASSERTI2(biopDividi2i2(I2_MIN, I2_MIN), 0x1); 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); extern i1 i1_lessThanEquals(i1 lhs, i1 rhs);
ASSERTI4(unopNoti4(0x01010101), 0); ASSERTI1(i1_lessThanEquals(2, 1), 0);
ASSERTI4(unopNoti4(2), 0); ASSERTI1(i1_lessThanEquals(~2, ~1), 1);
ASSERTI4(unopNoti4(I4_MAX), 0);
ASSERTI4(unopNoti4(I4_MIN), 0);
ASSERTI4(unopNoti4(0), 1);
} }
TEST biopXOri1i1_Main() TEST i1_equals_Main()
{ {
extern i1 biopXOri1i1(i1 lhs, i1 rhs); extern i1 i1_equals(i1 lhs, i1 rhs);
ASSERTI1(biopXOri1i1(2, 1), 3); ASSERTI1(i1_equals(2, 1), 0);
ASSERTI1(biopXOri1i1(I1_MAX, I1_MAX), 0); ASSERTI1(i1_equals(I1_MAX, I1_MAX), 1);
ASSERTI1(biopXOri1i1(I1_MIN, I1_MIN), 0); ASSERTI1(i1_equals(I1_MAX, I1_MIN), 0);
ASSERTI1(biopXOri1i1(I1_MAX, 0), 127); ASSERTI1(i1_equals(I1_MIN, I1_MAX), 0);
ASSERTI1(biopXOri1i1(I1_MAX, 1), 126);
} }
TEST biopRemainderi1i1_Main() TEST i1_notEquals_Main()
{ {
extern i1 biopRemainderi1i1(i1 lhs, i1 rhs); extern i1 i1_notEquals(i1 lhs, i1 rhs);
ASSERTI1(biopRemainderi1i1(0x01, 0x01), 0); ASSERTI1(i1_notEquals(2, 1), 1);
ASSERTI1(biopRemainderi1i1(I1_MAX, I1_MAX), 0); ASSERTI1(i1_notEquals(I1_MAX, I1_MAX), 0);
ASSERTI1(biopRemainderi1i1(I1_MIN, I1_MIN), 0); ASSERTI1(i1_notEquals(I1_MIN, I1_MIN), 0);
ASSERTI1(biopRemainderi1i1(0, 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); extern u1 u1_bitwiseAnd(u1 lhs, u1 rhs);
ASSERTI2(biopSubi2i2(0x0101, 0x0100), 0x1); ASSERTU1(u1_bitwiseAnd(0x01, 0x01), 0x01);
ASSERTI2(biopSubi2i2(0x0100, 0x0101), -0x1); ASSERTU1(u1_bitwiseAnd(U1_MAX, U1_MAX), 255);
ASSERTI2(biopSubi2i2(0x0101, 0x0101), 0); ASSERTU1(u1_bitwiseAnd(U1_MAX, 0), 0);
ASSERTI2(biopSubi2i2(2, 1), 1); ASSERTU1(u1_bitwiseAnd(U1_MAX, 1), 0x01);
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);
} }
TEST biopNeu2u2_Main() TEST u1_bitwiseOr_Main()
{ {
extern u2 biopNeu2u2(u2 lhs, u2 rhs); extern u1 u1_bitwiseOr(u1 lhs, u1 rhs);
ASSERTU2(biopNeu2u2(2, 1), 1); ASSERTU1(u1_bitwiseOr(0x01, 0x01), 0x01);
ASSERTU2(biopNeu2u2(U2_MAX, U2_MAX), 0); ASSERTU1(u1_bitwiseOr(U1_MAX, U1_MAX), U1_MAX);
ASSERTU2(biopNeu2u2(0, 0), 0); ASSERTU1(u1_bitwiseOr(U1_MAX, U1_MIN), 255);
} }
TEST biopLogicOri1i1_Main() TEST u1_bitwiseXor_Main()
{ {
extern i1 biopLogicOri1i1(i1 lhs, i1 rhs); extern u1 u1_bitwiseXor(u1 lhs, u1 rhs);
ASSERTI1(biopLogicOri1i1(2, 1), 1); ASSERTU1(u1_bitwiseXor(0x01, 0x01), 0);
ASSERTI1(biopLogicOri1i1(I1_MAX, I1_MAX), 1); ASSERTU1(u1_bitwiseXor(U1_MAX, U1_MAX), 0);
ASSERTI1(biopLogicOri1i1(I1_MIN, I1_MIN), 1); ASSERTU1(u1_bitwiseXor(U1_MAX, 0), 255);
ASSERTI1(biopLogicOri1i1(0, 0), 0);
ASSERTI1(biopLogicOri1i1(0, I1_MAX), 1);
ASSERTI1(biopLogicOri1i1(I1_MAX, I1_MIN), 1);
} }
TEST biopDividi1i1_Main() TEST i1_bitwiseAnd_Main()
{ {
extern i1 biopDividi1i1(i1 lhs, i1 rhs); extern i1 i1_bitwiseAnd(i1 lhs, i1 rhs);
ASSERTI1(biopDividi1i1(0x1, 0x1), 1); ASSERTI1(i1_bitwiseAnd(2, 1), 0);
ASSERTI1(biopDividi1i1(I1_MAX, I1_MAX), 1); ASSERTI1(i1_bitwiseAnd(I1_MAX, I1_MAX), 127);
ASSERTI1(biopDividi1i1(I1_MIN, I1_MIN), 1); ASSERTI1(i1_bitwiseAnd(I1_MIN, I1_MIN), -128);
ASSERTI1(biopDividi1i1(I1_MAX, 1), I1_MAX); ASSERTI1(i1_bitwiseAnd(0, 0), 0);
} }
TEST unopNegativei4_Main() TEST i1_bitwiseOr_Main()
{ {
extern i4 unopNegativei4(i4 lhs); extern i1 i1_bitwiseOr(i1 lhs, i1 rhs);
ASSERTI4(unopNegativei4(0x01010101), -0x01010101); ASSERTI1(i1_bitwiseOr(2, 1), 3);
ASSERTI4(unopNegativei4(-0x01010101), 0x01010101); ASSERTI1(i1_bitwiseOr(I1_MAX, I1_MAX), 127);
ASSERTI4(unopNegativei4(I4_MAX), -I4_MAX); ASSERTI1(i1_bitwiseOr(I1_MIN, I1_MIN), -128);
ASSERTI4(unopNegativei4(I4_MIN), I4_MIN); ASSERTI1(i1_bitwiseOr(0, 0), 0);
ASSERTI4(unopNegativei4(0), 0);
} }
TEST biopAddi2i2_Main() TEST i1_bitwiseXor_Main()
{ {
extern i2 biopAddi2i2(i2 lhs, i2 rhs); extern i1 i1_bitwiseXor(i1 lhs, i1 rhs);
ASSERTI2(biopAddi2i2(0x0101, 0x0101), 514); ASSERTI1(i1_bitwiseXor(2, 1), 3);
ASSERTI2(biopAddi2i2(0x0101, -0x0101), 0); ASSERTI1(i1_bitwiseXor(I1_MAX, I1_MAX), 0);
ASSERTI2(biopAddi2i2(2, 1), 3); ASSERTI1(i1_bitwiseXor(I1_MIN, I1_MIN), 0);
ASSERTI2(biopAddi2i2(I2_MAX, I2_MAX), -2); ASSERTI1(i1_bitwiseXor(I1_MAX, 0), 127);
ASSERTI2(biopAddi2i2(I2_MIN, I2_MIN), 0); ASSERTI1(i1_bitwiseXor(I1_MAX, 1), 126);
ASSERTI2(biopAddi2i2(0, 0), 0);
} }
TEST biopAndu2u2_Main() /* Logical operators */
TEST u1_logicalAnd_Main()
{ {
extern u2 biopAndu2u2(u2 lhs, u2 rhs); extern u1 u1_logicalAnd(u1 lhs, u1 rhs);
ASSERTU2(biopAndu2u2(2, 1), 0); ASSERTU1(u1_logicalAnd(0x01, 0x01), 1);
ASSERTU2(biopAndu2u2(U2_MAX, U2_MAX), 65535); ASSERTU1(u1_logicalAnd(U1_MAX, U1_MAX), 1);
ASSERTU2(biopAndu2u2(U2_MIN, U2_MIN), 0); ASSERTU1(u1_logicalAnd(U1_MAX, 0), 0);
ASSERTU2(biopAndu2u2(0, U2_MAX), 0); ASSERTU1(u1_logicalAnd(U1_MAX, 1), 1);
ASSERTU2(biopAndu2u2(0, 0), 0);
} }
TEST biopLogicAndi1i1_Main() TEST u1_logicalOr_Main()
{ {
extern i1 biopLogicAndi1i1(i1 lhs, i1 rhs); extern u1 u1_logicalOr(u1 lhs, u1 rhs);
ASSERTI1(biopLogicAndi1i1(2, 1), 1); ASSERTU1(u1_logicalOr(0x01, 0x01), 1);
ASSERTI1(biopLogicAndi1i1(I1_MAX, I1_MAX), 1); ASSERTU1(u1_logicalOr(U1_MAX, U1_MAX), 1);
ASSERTI1(biopLogicAndi1i1(I1_MIN, I1_MIN), 1); ASSERTU1(u1_logicalOr(U1_MAX, 0), 1);
ASSERTI1(biopLogicAndi1i1(0, I1_MAX), 0);
ASSERTI1(biopLogicAndi1i1(0, 0), 0);
} }
TEST unopPlusi4_Main() TEST u1_logicalNot_Main()
{ {
extern i4 unopPlusi4(i4 lhs); extern u1 u1_logicalNot(u1 lhs);
ASSERTI4(unopPlusi4(0x01010101), 0x01010101); ASSERTU1(u1_logicalNot(0x01), 0);
ASSERTI4(unopPlusi4(-0x01010101), -0x01010101); ASSERTU1(u1_logicalNot(U1_MAX), 0);
ASSERTI4(unopPlusi4(2), 2); ASSERTU1(u1_logicalNot(0), 1);
ASSERTI4(unopPlusi4(I4_MAX), 2147483647);
ASSERTI4(unopPlusi4(I4_MIN), -2147483648);
ASSERTI4(unopPlusi4(0), 0);
} }
TEST biopShtLfti2i2_Main() TEST i1_logicalAnd_Main()
{ {
extern i2 biopShtLfti2i2(i2 lhs, i2 rhs); extern i1 i1_logicalAnd(i1 lhs, i1 rhs);
ASSERTI2(biopShtLfti2i2(0x0101, 15), 0x8000); ASSERTI1(i1_logicalAnd(2, 1), 1);
ASSERTI2(biopShtLfti2i2(0x0101, 8), 0x100); ASSERTI1(i1_logicalAnd(I1_MAX, I1_MAX), 1);
ASSERTI2(biopShtLfti2i2(0x0101, 0), 0x101); ASSERTI1(i1_logicalAnd(I1_MIN, I1_MIN), 1);
ASSERTI2(biopShtLfti2i2(2, 1), 4); ASSERTI1(i1_logicalAnd(0, I1_MAX), 0);
ASSERTI2(biopShtLfti2i2(I2_MAX, 4), -16); ASSERTI1(i1_logicalAnd(0, 0), 0);
ASSERTI2(biopShtLfti2i2(I2_MIN, 4), 0);
ASSERTI2(biopShtLfti2i2(0, 4), 0);
} }
TEST biopOru2u2_Main() TEST i1_logicalOr_Main()
{ {
extern u2 biopOru2u2(u2 lhs, u2 rhs); extern i1 i1_logicalOr(i1 lhs, i1 rhs);
ASSERTU2(biopOru2u2(2, 1), 3); ASSERTI1(i1_logicalOr(2, 1), 1);
ASSERTU2(biopOru2u2(U2_MAX, U2_MAX), 65535); ASSERTI1(i1_logicalOr(I1_MAX, I1_MAX), 1);
ASSERTU2(biopOru2u2(U2_MAX, 0), 65535); ASSERTI1(i1_logicalOr(I1_MIN, I1_MIN), 1);
ASSERTU2(biopOru2u2(U2_MAX, U2_MAX), 65535); 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); extern i1 i1_logicalNot(i1 lhs);
ASSERTI1(unopNoti1(2), 0); ASSERTI1(i1_logicalNot(2), 0);
ASSERTI1(unopNoti1(I1_MAX), 0); ASSERTI1(i1_logicalNot(I1_MAX), 0);
ASSERTI1(unopNoti1(I1_MIN), 0); ASSERTI1(i1_logicalNot(I1_MIN), 0);
ASSERTI1(unopNoti1(0), 1); ASSERTI1(i1_logicalNot(0), 1);
} }
TEST biopMultu4u4_Main() /* Shift operators */
TEST u1_shiftLeft_Main()
{ {
extern u4 biopMultu4u4(u4 lhs, u4 rhs); extern u1 u1_shiftLeft(u1 lhs, u1 rhs);
ASSERTU4(biopMultu4u4(0x01010101, 0x01010101), 67305985); ASSERTU1(u1_shiftLeft(0x01, 2), 0x4);
ASSERTU4(biopMultu4u4(2, 1), 2); ASSERTU1(u1_shiftLeft(U1_MAX, 2), 252);
ASSERTU4(biopMultu4u4(~2, ~1), 6); ASSERTU1(u1_shiftLeft(U1_MAX, 8-1), 128);
ASSERTU4(biopMultu4u4(U4_MAX, U4_MAX), 1); ASSERTU1(u1_shiftLeft(U1_MAX, 8), 0);
ASSERTU4(biopMultu4u4(U4_MAX, 1), U4_MAX); ASSERTU1(u1_shiftLeft(2, 1), 0x4);
ASSERTU4(biopMultu4u4(U4_MAX, 0), 0);
} }
TEST biopShtRhti2i2_Main() TEST u1_shiftRight_Main()
{ {
extern i2 biopShtRhti2i2(i2 lhs, i2 rhs); extern u1 u1_shiftRight(u1 lhs, u1 rhs);
ASSERTI2(biopShtRhti2i2(0x7fff, 15), 0x0000); ASSERTU1(u1_shiftRight(0x80, 2), 0x20);
ASSERTI2(biopShtRhti2i2(0x0101, 8), 0x1); ASSERTU1(u1_shiftRight(U1_MAX, 2), 63);
ASSERTI2(biopShtRhti2i2(0x0101, 0), 0x0101); ASSERTU1(u1_shiftRight(U1_MAX, 8-1), 1);
ASSERTI2(biopShtRhti2i2(2, 1), 1); ASSERTU1(u1_shiftRight(U1_MAX, 8), 0);
ASSERTI2(biopShtRhti2i2(I2_MAX, 4), 2047);
ASSERTI2(biopShtRhti2i2(I2_MAX, 0), 32767);
ASSERTI2(biopShtRhti2i2(I2_MIN, 4), -2048);
ASSERTI2(biopShtRhti2i2(I2_MIN, 0), -32768);
} }
TEST biopXOru2u2_Main() TEST i1_shiftLeft_Main()
{ {
extern u2 biopXOru2u2(u2 lhs, u2 rhs); extern i1 i1_shiftLeft(i1 lhs, i1 rhs);
ASSERTU2(biopXOru2u2(2, 1), 3); ASSERTI1(i1_shiftLeft(2, 1), 4);
ASSERTU2(biopXOru2u2(U2_MAX, U2_MAX), 0); ASSERTI1(i1_shiftLeft(I1_MAX, 2), -4);
ASSERTU2(biopXOru2u2(0, 0), 0); ASSERTI1(i1_shiftLeft(I1_MIN, 2), 0);
ASSERTU2(biopXOru2u2(0, U2_MAX), 65535); ASSERTI1(i1_shiftLeft(I1_MAX, 0), 127);
} }
TEST biopSubu4u4_Main() TEST i1_shiftRight_Main()
{ {
extern u4 biopSubu4u4(u4 lhs, u4 rhs); extern i1 i1_shiftRight(i1 lhs, i1 rhs);
ASSERTU4(biopSubu4u4(0x01010101, 0x01010101), 0); ASSERTI1(i1_shiftRight(2, 1), 1);
ASSERTU4(biopSubu4u4(2, 1), 1); ASSERTI1(i1_shiftRight(I1_MAX, 2), 31);
ASSERTU4(biopSubu4u4(~2, ~1), 4294967295); ASSERTI1(i1_shiftRight(16, 4), 1);
ASSERTU4(biopSubu4u4(U4_MAX, U4_MAX), 0);
ASSERTU4(biopSubu4u4(U4_MAX, 0), U4_MAX);
ASSERTU4(biopSubu4u4(0, U4_MAX), 1);
} }
TEST unopNegativei1_Main() /* Arithmetic functions */
TEST u1_unaryPlus_Main()
{ {
extern i1 unopNegativei1(i1 lhs); extern u1 u1_unaryPlus(u1 lhs);
ASSERTI1(unopNegativei1(2), -2); ASSERTU1(u1_unaryPlus(0x01), 0x01);
ASSERTI1(unopNegativei1(I1_MAX), -127); ASSERTU1(u1_unaryPlus(U1_MAX), 255);
ASSERTI1(unopNegativei1(I1_MIN), -128); ASSERTU1(u1_unaryPlus(0), 0);
ASSERTI1(unopNegativei1(0), 0);
} }
TEST biopGti2i2_Main() TEST u1_addition_Main()
{ {
extern i2 biopGti2i2(i2 lhs, i2 rhs); extern u1 u1_addition(u1 lhs, u1 rhs);
ASSERTI2(biopGti2i2(0x0101, 0x0101), 0); ASSERTU1(u1_addition(0x01, 0x01), 2);
ASSERTI2(biopGti2i2(0x0101, 0x0100), 1); ASSERTU1(u1_addition(U1_MAX, U1_MAX), 254);
ASSERTI2(biopGti2i2(0x0101, -0x0101), 1); ASSERTU1(u1_addition(U1_MAX, 0), 255);
ASSERTI2(biopGti2i2(2, 1), 1); ASSERTU1(u1_addition(U1_MAX, 1), 0);
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);
} }
TEST biopLogicOru2u2_Main() TEST u1_subtract_Main()
{ {
extern u2 biopLogicOru2u2(u2 lhs, u2 rhs); extern u1 u1_subtract(u1 lhs, u1 rhs);
ASSERTU2(biopLogicOru2u2(2, 1), 1); ASSERTU1(u1_subtract(0x01, 0x01), 0);
ASSERTU2(biopLogicOru2u2(2, 1), 1); ASSERTU1(u1_subtract(U1_MAX, U1_MAX), 0);
ASSERTU2(biopLogicOru2u2(U2_MAX, U2_MAX), 1); ASSERTU1(u1_subtract(U1_MAX, 0), U1_MAX);
ASSERTU2(biopLogicOru2u2(U2_MIN, U2_MIN), 0); ASSERTU1(u1_subtract(0, U1_MAX), 1);
ASSERTU2(biopLogicOru2u2(U2_MAX, U2_MIN), 1);
ASSERTU2(biopLogicOru2u2(U2_MAX, 0), 1);
ASSERTU2(biopLogicOru2u2(0, 0), 0);
} }
TEST biopAddu4u4_Main() TEST u1_multiply_Main()
{ {
extern u4 biopAddu4u4(u4 lhs, u4 rhs); extern u1 u1_multiply(u1 lhs, u1 rhs);
ASSERTU4(biopAddu4u4(0x01010101, 0x01010101), 33686018); ASSERTU1(u1_multiply(0x01, 0x01), 1);
ASSERTU4(biopAddu4u4(2, 1), 3); ASSERTU1(u1_multiply(U1_MAX, 1), U1_MAX);
ASSERTU4(biopAddu4u4(~2, ~1), 4294967291); ASSERTU1(u1_multiply(U1_MAX, U1_MAX), 1);
ASSERTU4(biopAddu4u4(U4_MAX, U4_MAX), -2); ASSERTU1(u1_multiply(U1_MAX, 0), 0);
ASSERTU4(biopAddu4u4(U4_MAX, 0), -1);
ASSERTU4(biopAddu4u4(0, 0), 0);
} }
TEST unopPlusi1_Main() TEST u1_divide_Main()
{ {
extern i1 unopPlusi1(i1 lhs); extern i1 u1_divide(u1 lhs, u1 rhs);
ASSERTI1(unopPlusi1(2), 2); ASSERTI1(u1_divide(0x01, 0x01), 1);
ASSERTI1(unopPlusi1(I1_MAX), 127); ASSERTI1(u1_divide(U1_MAX, U1_MAX), 1);
ASSERTI1(unopPlusi1(I1_MIN), -128); ASSERTI1(u1_divide(U1_MAX, 1), U1_MAX);
ASSERTI1(unopPlusi1(0), 0);
} }
TEST biopGei2i2_Main() TEST u1_remainder_Main()
{ {
extern i2 biopGei2i2(i2 lhs, i2 rhs); extern u1 u1_remainder(u1 lhs, u1 rhs);
ASSERTI2(biopGei2i2(2, 1), 1); ASSERTU1(u1_remainder(0x01, 0x01), 0);
ASSERTI2(biopGei2i2(I2_MAX, I2_MAX), 1); ASSERTU1(u1_remainder(U1_MAX, U1_MAX), 0);
ASSERTI2(biopGei2i2(I2_MIN, I2_MIN), 1); ASSERTU1(u1_remainder(0, I1_MIN), 0);
ASSERTI2(biopGei2i2(I2_MAX, I2_MIN), 1);
ASSERTI2(biopGei2i2(I2_MIN, I2_MAX), 0);
} }
TEST biopLogicAndu2u2_Main() TEST i1_unaryMinus_Main()
{ {
extern u2 biopLogicAndu2u2(u2 lhs, u2 rhs); extern i1 i1_unaryMinus(i1 lhs);
ASSERTU2(biopLogicAndu2u2(2, 1), 1); ASSERTI1(i1_unaryMinus(2), -2);
ASSERTU2(biopLogicAndu2u2(I2_MAX, I2_MAX), 1); ASSERTI1(i1_unaryMinus(I1_MAX), -127);
ASSERTU2(biopLogicAndu2u2(I2_MIN, I2_MIN), 1); ASSERTI1(i1_unaryMinus(I1_MIN), -128);
ASSERTU2(biopLogicAndu2u2(I2_MAX, I2_MIN), 1); ASSERTI1(i1_unaryMinus(0), 0);
ASSERTU2(biopLogicAndu2u2(I2_MAX, 0), 0);
} }
TEST biopMultu1u1_Main() TEST i1_unaryPlus_Main()
{ {
extern u1 biopMultu1u1(u1 lhs, u1 rhs); extern i1 i1_unaryPlus(i1 lhs);
ASSERTU1(biopMultu1u1(0x01, 0x01), 1); ASSERTI1(i1_unaryPlus(2), 2);
ASSERTU1(biopMultu1u1(U1_MAX, 1), U1_MAX); ASSERTI1(i1_unaryPlus(I1_MAX), 127);
ASSERTU1(biopMultu1u1(U1_MAX, U1_MAX), 1); ASSERTI1(i1_unaryPlus(I1_MIN), -128);
ASSERTU1(biopMultu1u1(U1_MAX, 0), 0); ASSERTI1(i1_unaryPlus(0), 0);
} }
TEST biopGtu1u1_Main() TEST i1_addition_Main()
{ {
extern u1 biopGtu1u1(u1 lhs, u1 rhs); extern i1 i1_addition(i1 lhs, i1 rhs);
ASSERTU1(biopGtu1u1(0x01, 0x01), 0); ASSERTI1(i1_addition(2, 1), 3);
ASSERTU1(biopGtu1u1(U1_MAX, U1_MAX), 0); ASSERTI1(i1_addition(I1_MAX, I1_MAX), -2);
ASSERTU1(biopGtu1u1(U1_MAX, 0), 1); ASSERTI1(i1_addition(I1_MAX, I1_MIN), -1);
ASSERTU1(biopGtu1u1(0, U1_MAX), 0); ASSERTI1(i1_addition(I1_MAX, 0), 127);
} }
TEST biopShtLftu4u4_Main() TEST i1_subtract_Main()
{ {
extern u4 biopShtLftu4u4(u4 lhs, u4 rhs); extern i1 i1_subtract(i1 lhs, i1 rhs);
ASSERTU4(biopShtLftu4u4(0x01010101, 16), 0x01010000); ASSERTI1(i1_subtract(2, 1), 1);
ASSERTU4(biopShtLftu4u4(2, 1), 4); ASSERTI1(i1_subtract(I1_MAX, I1_MAX), 0);
ASSERTU4(biopShtLftu4u4(U4_MAX, 4*8-1), 2147483648); ASSERTI1(i1_subtract(I1_MAX, I1_MIN), -1);
ASSERTU4(biopShtLftu4u4(U4_MAX, 4), -16); 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); extern i1 i1_multiply(i1 lhs, i1 rhs);
ASSERTI2(biopOri2i2(2, 1), 3); ASSERTI1(i1_multiply(2, 1), 2);
ASSERTI2(biopOri2i2(0x0101, 0x0101), 0x0101); ASSERTI1(i1_multiply(I1_MAX, I1_MAX), 1);
ASSERTI2(biopOri2i2(0x0101, 0x1010), 0x1111); ASSERTI1(i1_multiply(I1_MAX, I1_MIN), -128);
ASSERTI2(biopOri2i2(0x0101, 0x0), 0x0101); ASSERTI1(i1_multiply(I1_MAX, 0), 0);
ASSERTI2(biopOri2i2(I2_MAX, I2_MAX), 32767);
ASSERTI2(biopOri2i2(I2_MAX, I2_MIN), -1);
ASSERTI2(biopOri2i2(I2_MAX, 0), 32767);
} }
TEST biopLti2i2_Main() TEST i1_divide_Main()
{ {
extern i2 biopLti2i2(i2 lhs, i2 rhs); extern i1 i1_divide(i1 lhs, i1 rhs);
ASSERTI2(biopLti2i2(2, 1), 0); ASSERTI1(i1_divide(0x1, 0x1), 1);
ASSERTI2(biopLti2i2(0x0101, 0x0101), 0); ASSERTI1(i1_divide(I1_MAX, I1_MAX), 1);
ASSERTI2(biopLti2i2(0x0101, -0x0101), 0); ASSERTI1(i1_divide(I1_MIN, I1_MIN), 1);
ASSERTI2(biopLti2i2(0x0101, -0x0101), 0); ASSERTI1(i1_divide(I1_MAX, 1), I1_MAX);
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);
} }
TEST biopMulti4i4_Main() TEST i1_remainder_Main()
{ {
extern i4 biopMulti4i4(i4 lhs, i4 rhs); extern i1 i1_remainder(i1 lhs, i1 rhs);
ASSERTI4(biopMulti4i4(2, 1), 2); ASSERTI1(i1_remainder(0x01, 0x01), 0);
ASSERTI4(biopMulti4i4(0x01010101, 0x01010101), 67305985); ASSERTI1(i1_remainder(I1_MAX, I1_MAX), 0);
ASSERTI4(biopMulti4i4(0x01010101, -16843009), -67305985); ASSERTI1(i1_remainder(I1_MIN, I1_MIN), 0);
ASSERTI4(biopMulti4i4(0, -16843009), 0); ASSERTI1(i1_remainder(0, I1_MIN), 0);
ASSERTI4(biopMulti4i4(I4_MAX, I4_MAX), 1);
ASSERTI4(biopMulti4i4(I4_MAX, I4_MIN), -2147483648);
ASSERTI4(biopMulti4i4(I4_MAX, 0), 0);
} }
MAIN BIOPS_main() { } MAIN BIOPS_main() { }

View file

@ -1,662 +1,469 @@
#include "pcode_test.h" #include "pcode_test.h"
TEST unopNotu2_Main() TEST u2_complexLogic_Main()
{ {
extern u2 unopNotu2(u2 lhs); extern u2 u2_complexLogic(u2 a, u2 b, u2 c, u2 d, u2 e, u2 f);
ASSERTU2(unopNotu2(2), 0); ASSERTU2(u2_complexLogic(15941, 23971, 41361, 0, 43462, 0), 15);
ASSERTU2(unopNotu2(U2_MAX), 0); ASSERTU2(u2_complexLogic(52937, 43562, 0, 0, 48661, 51969), 11);
ASSERTU2(unopNotu2(0), 1); 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); extern i2 i2_complexLogic(i2 a, i2 b, i2 c, i2 d, i2 e, i2 f);
ASSERTU1(biopSubu1u1(0x01, 0x01), 0); ASSERTI2(i2_complexLogic(0, 46379, (i2) -52108, 0, (i2) -54966, 53127), 11);
ASSERTU1(biopSubu1u1(U1_MAX, U1_MAX), 0); ASSERTI2(i2_complexLogic((i2) -5607, 26256, 23643, 0, (i2) -21648, 0), 14);
ASSERTU1(biopSubu1u1(U1_MAX, 0), U1_MAX); ASSERTI2(i2_complexLogic((i2) -19816, 41002, 63272, 0, 4483, 0), 15);
ASSERTU1(biopSubu1u1(0, U1_MAX), 1); 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); extern u2 u2_compareLogic(u2 lhs, u2 rhs);
ASSERTU1(biopGeu1u1(0x01, 0x01), 1); ASSERTU2(u2_compareLogic(0x1, 0x1), 1);
ASSERTU1(biopGeu1u1(U1_MAX, U1_MAX), 1); ASSERTU2(u2_compareLogic(0x1, 0x2), 23);
ASSERTU1(biopGeu1u1(U1_MAX, 0), 1); ASSERTU2(u2_compareLogic(0x2, 0x1), 22);
ASSERTU1(biopGeu1u1(0, U1_MAX), 0);
} }
TEST biopShtRhtu4u4_Main() TEST i2_compareLogic_Main()
{ {
extern u4 biopShtRhtu4u4(u4 lhs, u4 rhs); extern i2 i2_compareLogic(i2 lhs, i2 rhs);
ASSERTU4(biopShtRhtu4u4(0x01010101, 16), 0x0101); ASSERTI2(i2_compareLogic(0x1, 0x1), 21);
ASSERTU4(biopShtRhtu4u4(2, 1), 1); ASSERTI2(i2_compareLogic(0x1, 0x2), 21);
ASSERTU4(biopShtRhtu4u4(U4_MAX, 4), 268435455); ASSERTI2(i2_compareLogic(0x2, 0x1), 22);
ASSERTU4(biopShtRhtu4u4(U4_MAX, 4*8-1), 1); ASSERTI2(i2_compareLogic(-0x1, -0x1), 21);
ASSERTU4(biopShtRhtu4u4(4, 4), 0); 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); extern u2 u2_greaterThan(u2 lhs, u2 rhs);
ASSERTI2(biopXOri2i2(2, 1), 3); ASSERTU2(u2_greaterThan(2, 1), 1);
ASSERTI2(biopXOri2i2(0x0101, 0x0101), 0); ASSERTU2(u2_greaterThan(U2_MAX, U2_MAX), 0);
ASSERTI2(biopXOri2i2(0x0101, 0x1010), 0x1111); ASSERTU2(u2_greaterThan(U2_MAX, 0), 1);
ASSERTI2(biopXOri2i2(I2_MAX, I2_MAX), 0); ASSERTU2(u2_greaterThan(0, U2_MAX), 0);
ASSERTI2(biopXOri2i2(I2_MAX, I2_MIN), -1);
ASSERTI2(biopXOri2i2(I2_MAX, 0), 32767);
ASSERTI2(biopXOri2i2(I2_MAX, -1), -32768);
} }
TEST biopLei2i2_Main() TEST u2_greaterThanEquals_Main()
{ {
extern i2 biopLei2i2(i2 lhs, i2 rhs); extern u2 u2_greaterThanEquals(u2 lhs, u2 rhs);
ASSERTI2(biopLei2i2(2, 1), 0); ASSERTU2(u2_greaterThanEquals(2, 1), 1);
ASSERTI2(biopLei2i2(0x0101, 0x0101), 1); ASSERTU2(u2_greaterThanEquals(U2_MAX, U2_MAX), 1);
ASSERTI2(biopLei2i2(0x0101, 0x0100), 0); ASSERTU2(u2_greaterThanEquals(1, 1), 1);
ASSERTI2(biopLei2i2(0x0101, -0x0101), 0); ASSERTU2(u2_greaterThanEquals(1, 2), 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);
} }
TEST biopSubi4i4_Main() TEST u2_lessThan_Main()
{ {
extern i4 biopSubi4i4(i4 lhs, i4 rhs); extern u2 u2_lessThan(u2 lhs, u2 rhs);
ASSERTI4(biopSubi4i4(2, 1), 1); ASSERTU2(u2_lessThan(2, 1), 0);
ASSERTI4(biopSubi4i4(0x01010101, 0x01010101), 0); ASSERTU2(u2_lessThan(2, 1), 0);
ASSERTI4(biopSubi4i4(0x01010101, 0x01000100), 0x00010001); ASSERTU2(u2_lessThan(U2_MAX, U2_MAX), 0);
ASSERTI4(biopSubi4i4(0x01000100, 0x01010101), -0x00010001); ASSERTU2(u2_lessThan(0, 0), 0);
ASSERTI4(biopSubi4i4(I4_MAX, I4_MAX), 0); ASSERTU2(u2_lessThan(1, 2), 1);
ASSERTI4(biopSubi4i4(I4_MAX, I4_MIN), -1);
ASSERTI4(biopSubi4i4(I4_MAX, 0), 2147483647);
ASSERTI4(biopSubi4i4(0, I4_MAX), -2147483647);
} }
TEST biopAddu1u1_Main() TEST u2_lessThanEquals_Main()
{ {
extern u1 biopAddu1u1(u1 lhs, u1 rhs); extern u2 u2_lessThanEquals(u2 lhs, u2 rhs);
ASSERTU1(biopAddu1u1(0x01, 0x01), 2); ASSERTU2(u2_lessThanEquals(2, 1), 0);
ASSERTU1(biopAddu1u1(U1_MAX, U1_MAX), 254); ASSERTU2(u2_lessThanEquals(U2_MAX, U2_MAX), 1);
ASSERTU1(biopAddu1u1(U1_MAX, 0), 255); ASSERTU2(u2_lessThanEquals(U2_MIN, U2_MIN), 1);
ASSERTU1(biopAddu1u1(U1_MAX, 1), 0); ASSERTU2(u2_lessThanEquals(1, 2), 1);
} }
TEST biopLtu1u1_Main() TEST u2_equals_Main()
{ {
extern u1 biopLtu1u1(u1 lhs, u1 rhs); extern u2 u2_equals(u2 lhs, u2 rhs);
ASSERTU1(biopLtu1u1(0x01, 0x01), 0); ASSERTU2(u2_equals(2, 1), 0);
ASSERTU1(biopLtu1u1(U1_MAX, U1_MAX), 0); ASSERTU2(u2_equals(U2_MAX, U2_MAX), 1);
ASSERTU1(biopLtu1u1(U1_MAX, 0), 0); 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); extern u2 u2_notEquals(u2 lhs, u2 rhs);
ASSERTU4(biopGtu4u4(0x01010101, 0x01010101), 0); ASSERTU2(u2_notEquals(2, 1), 1);
ASSERTU4(biopGtu4u4(2, 1), 1); ASSERTU2(u2_notEquals(U2_MAX, U2_MAX), 0);
ASSERTU4(biopGtu4u4(U4_MAX, U4_MAX), 0); ASSERTU2(u2_notEquals(0, 0), 0);
ASSERTU4(biopGtu4u4(U4_MAX, 0), 1);
ASSERTU4(biopGtu4u4(0, U4_MAX), 0);
} }
TEST biopLogicOri2i2_Main() TEST i2_greaterThan_Main()
{ {
extern i2 biopLogicOri2i2(i2 lhs, i2 rhs); extern i2 i2_greaterThan(i2 lhs, i2 rhs);
ASSERTI2(biopLogicOri2i2(0x0101, 0x0101), 1); ASSERTI2(i2_greaterThan(0x0101, 0x0101), 0);
ASSERTI2(biopLogicOri2i2(2, 1), 1); ASSERTI2(i2_greaterThan(0x0101, 0x0100), 1);
ASSERTI2(biopLogicOri2i2(I2_MAX, I2_MAX), 1); ASSERTI2(i2_greaterThan(0x0101, -0x0101), 1);
ASSERTI2(biopLogicOri2i2(I2_MAX, I2_MIN), 1); ASSERTI2(i2_greaterThan(2, 1), 1);
ASSERTI2(biopLogicOri2i2(I2_MAX, 0), 1); ASSERTI2(i2_greaterThan(I1_MAX, I1_MAX), 0);
ASSERTI2(biopLogicOri2i2(0, 0), 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); extern i2 i2_greaterThanEquals(i2 lhs, i2 rhs);
ASSERTI2(biopEqi2i2(2, 1), 0); ASSERTI2(i2_greaterThanEquals(2, 1), 1);
ASSERTI2(biopEqi2i2(0x0101, 0x0101), 1); ASSERTI2(i2_greaterThanEquals(I2_MAX, I2_MAX), 1);
ASSERTI2(biopEqi2i2(0x0101, 0x0100), 0); ASSERTI2(i2_greaterThanEquals(I2_MIN, I2_MIN), 1);
ASSERTI2(biopEqi2i2(0x0101, -0x0101), 0); ASSERTI2(i2_greaterThanEquals(I2_MAX, I2_MIN), 1);
ASSERTI2(biopEqi2i2(I2_MAX, I2_MAX), 1); ASSERTI2(i2_greaterThanEquals(I2_MIN, I2_MAX), 0);
ASSERTI2(biopEqi2i2(I2_MIN, I2_MIN), 1);
ASSERTI2(biopEqi2i2(I2_MAX-1, I2_MAX), 0);
} }
TEST unopPlusu2_Main() TEST i2_lessThan_Main()
{ {
extern u2 unopPlusu2(u2 lhs); extern i2 i2_lessThan(i2 lhs, i2 rhs);
ASSERTU2(unopPlusu2(2), 2); ASSERTI2(i2_lessThan(2, 1), 0);
ASSERTU2(unopPlusu2(U2_MAX), 65535); ASSERTI2(i2_lessThan(0x0101, 0x0101), 0);
ASSERTU2(unopPlusu2(0), 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); extern i2 i2_lessThanEquals(i2 lhs, i2 rhs);
ASSERTI4(biopAddi4i4(2, 1), 3); ASSERTI2(i2_lessThanEquals(2, 1), 0);
ASSERTI4(biopAddi4i4(0x01010101, 0x01010101), 33686018); ASSERTI2(i2_lessThanEquals(0x0101, 0x0101), 1);
ASSERTI4(biopAddi4i4(0x01010101, -0x01010101), 0); ASSERTI2(i2_lessThanEquals(0x0101, 0x0100), 0);
ASSERTI4(biopAddi4i4(I4_MAX, I4_MAX), -2); ASSERTI2(i2_lessThanEquals(0x0101, -0x0101), 0);
ASSERTI4(biopAddi4i4(I4_MAX, I4_MIN), -1); ASSERTI2(i2_lessThanEquals(I2_MAX, I2_MAX), 1);
ASSERTI4(biopAddi4i4(I4_MAX, 0), 2147483647); ASSERTI2(i2_lessThanEquals(I2_MAX, I2_MIN), 0);
ASSERTI4(biopAddi4i4(I4_MIN, I4_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); extern i2 i2_equals(i2 lhs, i2 rhs);
ASSERTU4(biopGeu4u4(2, 1), 1); ASSERTI2(i2_equals(2, 1), 0);
ASSERTU4(biopGeu4u4(U4_MAX, U4_MAX), 1); ASSERTI2(i2_equals(0x0101, 0x0101), 1);
ASSERTU4(biopGeu4u4(U4_MAX, 0), 1); ASSERTI2(i2_equals(0x0101, 0x0100), 0);
ASSERTU4(biopGeu4u4(0, U4_MAX), 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); extern i2 i2_notEquals(i2 lhs, i2 rhs);
ASSERTU1(biopShtLftu1u1(0x01, 2), 0x4); ASSERTI2(i2_notEquals(2, 1), 1);
ASSERTU1(biopShtLftu1u1(U1_MAX, 2), 252); ASSERTI2(i2_notEquals(0x0101, 0x0101), 0);
ASSERTU1(biopShtLftu1u1(U1_MAX, 8-1), 128); ASSERTI2(i2_notEquals(0x0101, 0x0100), 1);
ASSERTU1(biopShtLftu1u1(U1_MAX, 8), 0); ASSERTI2(i2_notEquals(0x0101, -0x0101), 1);
ASSERTU1(biopShtLftu1u1(2, 1), 0x4); 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); extern u2 u2_bitwiseAnd(u2 lhs, u2 rhs);
ASSERTU1(biopLeu1u1(0x01, 0x01), 1); ASSERTU2(u2_bitwiseAnd(2, 1), 0);
ASSERTU1(biopLeu1u1(U1_MAX, U1_MAX), 1); ASSERTU2(u2_bitwiseAnd(U2_MAX, U2_MAX), 65535);
ASSERTU1(biopLeu1u1(0, 0), 1); ASSERTU2(u2_bitwiseAnd(U2_MIN, U2_MIN), 0);
ASSERTU1(biopLeu1u1(U1_MAX, 0), 0); ASSERTU2(u2_bitwiseAnd(0, U2_MAX), 0);
ASSERTU1(biopLeu1u1(0, U1_MAX), 1); ASSERTU2(u2_bitwiseAnd(0, 0), 0);
} }
TEST biopLogicAndi2i2_Main() TEST u2_bitwiseOr_Main()
{ {
extern i2 biopLogicAndi2i2(i2 lhs, i2 rhs); extern u2 u2_bitwiseOr(u2 lhs, u2 rhs);
ASSERTI2(biopLogicAndi2i2(0x0101, 0x0101), 1); ASSERTU2(u2_bitwiseOr(2, 1), 3);
ASSERTI2(biopLogicAndi2i2(2, 1), 1); ASSERTU2(u2_bitwiseOr(U2_MAX, U2_MAX), 65535);
ASSERTI2(biopLogicAndi2i2(0x0101, 0x0101), 1); ASSERTU2(u2_bitwiseOr(U2_MAX, 0), 65535);
ASSERTI2(biopLogicAndi2i2(0x0101, 0x0), 0); ASSERTU2(u2_bitwiseOr(U2_MAX, U2_MAX), 65535);
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);
} }
TEST biopNei2i2_Main() TEST u2_bitwiseXor_Main()
{ {
extern i2 biopNei2i2(i2 lhs, i2 rhs); extern u2 u2_bitwiseXor(u2 lhs, u2 rhs);
ASSERTI2(biopNei2i2(2, 1), 1); ASSERTU2(u2_bitwiseXor(2, 1), 3);
ASSERTI2(biopNei2i2(0x0101, 0x0101), 0); ASSERTU2(u2_bitwiseXor(U2_MAX, U2_MAX), 0);
ASSERTI2(biopNei2i2(0x0101, 0x0100), 1); ASSERTU2(u2_bitwiseXor(0, 0), 0);
ASSERTI2(biopNei2i2(0x0101, -0x0101), 1); ASSERTU2(u2_bitwiseXor(0, U2_MAX), 65535);
ASSERTI2(biopNei2i2(I2_MAX, I2_MAX), 0);
ASSERTI2(biopNei2i2(I2_MAX, I2_MIN), 1);
ASSERTI2(biopNei2i2(I2_MIN, I2_MAX), 1);
} }
TEST biopMulti1i1_Main() TEST i2_bitwiseAnd_Main()
{ {
extern i1 biopMulti1i1(i1 lhs, i1 rhs); extern i2 i2_bitwiseAnd(i2 lhs, i2 rhs);
ASSERTI1(biopMulti1i1(2, 1), 2); ASSERTI2(i2_bitwiseAnd(2, 1), 0);
ASSERTI1(biopMulti1i1(I1_MAX, I1_MAX), 1); ASSERTI2(i2_bitwiseAnd(0x0101, 0x0101), 0x0101);
ASSERTI1(biopMulti1i1(I1_MAX, I1_MIN), -128); ASSERTI2(i2_bitwiseAnd(0x0101, 0x1010), 0x0);
ASSERTI1(biopMulti1i1(I1_MAX, 0), 0); 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); extern i2 i2_bitwiseOr(i2 lhs, i2 rhs);
ASSERTI4(biopShtLfti4i4(2, 1), 4); ASSERTI2(i2_bitwiseOr(2, 1), 3);
ASSERTI4(biopShtLfti4i4(0x01010101, 16), 0x01010000); ASSERTI2(i2_bitwiseOr(0x0101, 0x0101), 0x0101);
ASSERTI4(biopShtLfti4i4(0x01010101, 0), 0x01010101); ASSERTI2(i2_bitwiseOr(0x0101, 0x1010), 0x1111);
ASSERTI4(biopShtLfti4i4(I4_MAX, 2), -4); ASSERTI2(i2_bitwiseOr(0x0101, 0x0), 0x0101);
ASSERTI4(biopShtLfti4i4(I4_MAX, 0), 2147483647); 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); extern i2 i2_bitwiseXor(i2 lhs, i2 rhs);
ASSERTU4(biopLtu4u4(0x01010101, 0x01010101), 0); ASSERTI2(i2_bitwiseXor(2, 1), 3);
ASSERTU4(biopLtu4u4(2, 1), 0); ASSERTI2(i2_bitwiseXor(0x0101, 0x0101), 0);
ASSERTU4(biopLtu4u4(U4_MAX, U4_MAX), 0); ASSERTI2(i2_bitwiseXor(0x0101, 0x1010), 0x1111);
ASSERTU4(biopLtu4u4(U4_MAX, 0), 0); ASSERTI2(i2_bitwiseXor(I2_MAX, I2_MAX), 0);
ASSERTU4(biopLtu4u4(0, U4_MAX), 1); 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); extern u2 u2_logicalAnd(u2 lhs, u2 rhs);
ASSERTU1(biopShtRhtu1u1(0x80, 2), 0x20); ASSERTU2(u2_logicalAnd(2, 1), 1);
ASSERTU1(biopShtRhtu1u1(U1_MAX, 2), 63); ASSERTU2(u2_logicalAnd(I2_MAX, I2_MAX), 1);
ASSERTU1(biopShtRhtu1u1(U1_MAX, 8-1), 1); ASSERTU2(u2_logicalAnd(I2_MIN, I2_MIN), 1);
ASSERTU1(biopShtRhtu1u1(U1_MAX, 8), 0); 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); extern u2 u2_logicalOr(u2 lhs, u2 rhs);
ASSERTU1(biopEqu1u1(0x01, 0x01), 1); ASSERTU2(u2_logicalOr(2, 1), 1);
ASSERTU1(biopEqu1u1(U1_MAX, U1_MAX), 1); ASSERTU2(u2_logicalOr(2, 1), 1);
ASSERTU1(biopEqu1u1(U1_MAX, 0), 0); ASSERTU2(u2_logicalOr(U2_MAX, U2_MAX), 1);
ASSERTU1(biopEqu1u1(0, U1_MAX), 0); 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); extern u2 u2_logicalNot(u2 lhs);
ASSERTI2(unopNoti2(0x0101), 0); ASSERTU2(u2_logicalNot(2), 0);
ASSERTI2(unopNoti2(2), 0); ASSERTU2(u2_logicalNot(U2_MAX), 0);
ASSERTI2(unopNoti2(I2_MAX), 0); ASSERTU2(u2_logicalNot(0), 1);
ASSERTI2(unopNoti2(I2_MIN), 0);
ASSERTI2(unopNoti2(0), 1);
} }
TEST biopAndi2i2_Main() TEST i2_logicalAnd_Main()
{ {
extern i2 biopAndi2i2(i2 lhs, i2 rhs); extern i2 i2_logicalAnd(i2 lhs, i2 rhs);
ASSERTI2(biopAndi2i2(2, 1), 0); ASSERTI2(i2_logicalAnd(0x0101, 0x0101), 1);
ASSERTI2(biopAndi2i2(0x0101, 0x0101), 0x0101); ASSERTI2(i2_logicalAnd(2, 1), 1);
ASSERTI2(biopAndi2i2(0x0101, 0x1010), 0x0); ASSERTI2(i2_logicalAnd(0x0101, 0x0101), 1);
ASSERTI2(biopAndi2i2(I2_MAX, I2_MAX), 32767); ASSERTI2(i2_logicalAnd(0x0101, 0x0), 0);
ASSERTI2(biopAndi2i2(I2_MIN, I2_MIN), -32768); ASSERTI2(i2_logicalAnd(I2_MAX, I2_MAX), 1);
ASSERTI2(biopAndi2i2(I2_MAX, I2_MIN), 0); ASSERTI2(i2_logicalAnd(I2_MIN, I2_MIN), 1);
ASSERTI2(biopAndi2i2(I2_MAX, 0), 0x0); 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); extern i2 i2_logicalOr(i2 lhs, i2 rhs);
ASSERTI1(biopSubi1i1(2, 1), 1); ASSERTI2(i2_logicalOr(0x0101, 0x0101), 1);
ASSERTI1(biopSubi1i1(I1_MAX, I1_MAX), 0); ASSERTI2(i2_logicalOr(2, 1), 1);
ASSERTI1(biopSubi1i1(I1_MAX, I1_MIN), -1); ASSERTI2(i2_logicalOr(I2_MAX, I2_MAX), 1);
ASSERTI1(biopSubi1i1(I1_MIN, I1_MAX), 1); ASSERTI2(i2_logicalOr(I2_MAX, I2_MIN), 1);
ASSERTI1(biopSubi1i1(I1_MIN, I1_MIN), 0); ASSERTI2(i2_logicalOr(I2_MAX, 0), 1);
ASSERTI1(biopSubi1i1(I1_MAX, 0), 127); ASSERTI2(i2_logicalOr(0, 0), 0);
}
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);
} }
TEST biopAddu2u2_Main() TEST i2_logicalNot_Main()
{ {
extern u2 biopAddu2u2(u2 lhs, u2 rhs); extern i2 i2_logicalNot(i2 lhs);
ASSERTU2(biopAddu2u2(2, 1), 3); ASSERTI2(i2_logicalNot(0x0101), 0);
ASSERTU2(biopAddu2u2(U2_MAX, U2_MAX), 65534); ASSERTI2(i2_logicalNot(2), 0);
ASSERTU2(biopAddu2u2(U2_MAX, 0), U2_MAX); 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); extern u2 u2_shiftLeft(u2 lhs, u2 rhs);
ASSERTI1(biopGei1i1(2, 1), 1); ASSERTU2(u2_shiftLeft(2, 1), 4);
ASSERTI1(biopGei1i1(I1_MAX, I1_MAX), 1); ASSERTU2(u2_shiftLeft(2, 1), 4);
ASSERTI1(biopGei1i1(I1_MAX, I1_MIN), 1); ASSERTU2(u2_shiftLeft(U2_MAX, 2), 65532);
ASSERTI1(biopGei1i1(I1_MIN, I1_MAX), 0); ASSERTU2(u2_shiftLeft(U2_MAX, 0), 65535);
} }
TEST biopLogicAndu1u1_Main() TEST u2_shiftRight_Main()
{ {
extern u1 biopLogicAndu1u1(u1 lhs, u1 rhs); extern u2 u2_shiftRight(u2 lhs, u2 rhs);
ASSERTU1(biopLogicAndu1u1(0x01, 0x01), 1); ASSERTU2(u2_shiftRight(2, 1), 1);
ASSERTU1(biopLogicAndu1u1(U1_MAX, U1_MAX), 1); ASSERTU2(u2_shiftRight(U2_MAX, 2), 16383);
ASSERTU1(biopLogicAndu1u1(U1_MAX, 0), 0); ASSERTU2(u2_shiftRight(U2_MAX, 0), 65535);
ASSERTU1(biopLogicAndu1u1(U1_MAX, 1), 1);
} }
TEST biopEqi4i4_Main() TEST i2_shiftLeft_Main()
{ {
extern i4 biopEqi4i4(i4 lhs, i4 rhs); extern i2 i2_shiftLeft(i2 lhs, i2 rhs);
ASSERTI4(biopEqi4i4(0x01010101, -0x01010101), 0); ASSERTI2(i2_shiftLeft(0x0101, 15), 0x8000);
ASSERTI4(biopEqi4i4(2, 1), 0); ASSERTI2(i2_shiftLeft(0x0101, 8), 0x100);
ASSERTI4(biopEqi4i4(0x01010101, 0x01010101), 1); ASSERTI2(i2_shiftLeft(0x0101, 0), 0x101);
ASSERTI4(biopEqi4i4(0x01000101, 0x01010101), 0); ASSERTI2(i2_shiftLeft(2, 1), 4);
ASSERTI4(biopEqi4i4(I4_MAX, I4_MAX), 1); ASSERTI2(i2_shiftLeft(I2_MAX, 4), -16);
ASSERTI4(biopEqi4i4(I4_MAX, I4_MIN), 0); ASSERTI2(i2_shiftLeft(I2_MIN, 4), 0);
ASSERTI4(biopEqi4i4(I4_MIN, I4_MAX), 0); ASSERTI2(i2_shiftLeft(0, 4), 0);
} }
TEST biopXOru4u4_Main() TEST i2_shiftRight_Main()
{ {
extern u4 biopXOru4u4(u4 lhs, u4 rhs); extern i2 i2_shiftRight(i2 lhs, i2 rhs);
ASSERTU4(biopXOru4u4(0x01010101, 0x01010101), 0); ASSERTI2(i2_shiftRight(0x7fff, 15), 0x0000);
ASSERTU4(biopXOru4u4(2, 1), 3); ASSERTI2(i2_shiftRight(0x0101, 8), 0x1);
ASSERTU4(biopXOru4u4(U4_MAX, U4_MAX), 0); ASSERTI2(i2_shiftRight(0x0101, 0), 0x0101);
ASSERTU4(biopXOru4u4(U4_MAX, U4_MIN), -1); ASSERTI2(i2_shiftRight(2, 1), 1);
ASSERTU4(biopXOru4u4(U4_MAX, 0), -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); extern u2 u2_unaryPlus(u2 lhs);
ASSERTU2(biopShtLftu2u2(2, 1), 4); ASSERTU2(u2_unaryPlus(2), 2);
ASSERTU2(biopShtLftu2u2(2, 1), 4); ASSERTU2(u2_unaryPlus(U2_MAX), 65535);
ASSERTU2(biopShtLftu2u2(U2_MAX, 2), 65532); ASSERTU2(u2_unaryPlus(0), 0);
ASSERTU2(biopShtLftu2u2(U2_MAX, 0), 65535);
} }
TEST biopNei4i4_Main() TEST u2_addition_Main()
{ {
extern i4 biopNei4i4(i4 lhs, i4 rhs); extern u2 u2_addition(u2 lhs, u2 rhs);
ASSERTI4(biopNei4i4(0x01010101, 0x01010101), 0); ASSERTU2(u2_addition(2, 1), 3);
ASSERTI4(biopNei4i4(0x01000101, 0x01010101), 1); ASSERTU2(u2_addition(U2_MAX, U2_MAX), 65534);
ASSERTI4(biopNei4i4(0x01000101, -0x01010101), 1); ASSERTU2(u2_addition(U2_MAX, 0), U2_MAX);
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);
} }
TEST biopLti1i1_Main() TEST u2_subtract_Main()
{ {
extern i1 biopLti1i1(i1 lhs, i1 rhs); extern u2 u2_subtract(u2 lhs, u2 rhs);
ASSERTI1(biopLti1i1(2, 1), 0); ASSERTU2(u2_subtract(2, 1), 1);
ASSERTI1(biopLti1i1(I1_MAX, I1_MAX), 0); ASSERTU2(u2_subtract(2, 1), 1);
ASSERTI1(biopLti1i1(I1_MAX, I1_MIN), 0); ASSERTU2(u2_subtract(U2_MAX, U2_MAX), 0);
ASSERTI1(biopLti1i1(I1_MIN, I1_MAX), 1); 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); extern u2 u2_multiply(u2 lhs, u2 rhs);
ASSERTU1(unopNotu1(0x01), 0); ASSERTU2(u2_multiply(2, 1), 2);
ASSERTU1(unopNotu1(U1_MAX), 0); ASSERTU2(u2_multiply(U2_MAX, U2_MAX), 1);
ASSERTU1(unopNotu1(0), 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); extern i2 u2_divide(i2 lhs, i2 rhs);
ASSERTU4(biopLogicOru4u4(0x01010101, 0x01010101), 1); ASSERTI2(u2_divide(0x0101, 0x0101), 0x1);
ASSERTU4(biopLogicOru4u4(2, 1), 1); ASSERTI2(u2_divide(U2_MAX, U2_MAX), 0x1);
ASSERTU4(biopLogicOru4u4(U4_MAX, U4_MAX), 1);
ASSERTU4(biopLogicOru4u4(U4_MAX, U4_MIN), 1);
} }
TEST biopShtRhtu2u2_Main() TEST u2_remainder_Main()
{ {
extern u2 biopShtRhtu2u2(u2 lhs, u2 rhs); extern u2 u2_remainder(u2 lhs, u2 rhs);
ASSERTU2(biopShtRhtu2u2(2, 1), 1); ASSERTU2(u2_remainder(0x0101, 0x0101), 0x0);
ASSERTU2(biopShtRhtu2u2(U2_MAX, 2), 16383); ASSERTU2(u2_remainder(U2_MAX, 1), 0x0);
ASSERTU2(biopShtRhtu2u2(U2_MAX, 0), 65535); 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); extern i2 i2_unaryMinus(i2 lhs);
ASSERTI1(biopDividu1u1(0x01, 0x01), 1); ASSERTI2(i2_unaryMinus(0x0101), -0x0101);
ASSERTI1(biopDividu1u1(U1_MAX, U1_MAX), 1); ASSERTI2(i2_unaryMinus(-0x0101), 0x0101);
ASSERTI1(biopDividu1u1(U1_MAX, 1), U1_MAX); 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); extern i2 i2_unaryPlus(i2 lhs);
ASSERTI2(biopDividu2u2(0x0101, 0x0101), 0x1); ASSERTI2(i2_unaryPlus(0x0101), 0x0101);
ASSERTI2(biopDividu2u2(U2_MAX, U2_MAX), 0x1); 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); extern i2 i2_addition(i2 lhs, i2 rhs);
ASSERTU4(biopDividu4u4(0x01010101, 0x01010101), 1); ASSERTI2(i2_addition(0x0101, 0x0101), 514);
ASSERTU4(biopDividu4u4(-0x01010101, 0x01010101), 254); ASSERTI2(i2_addition(0x0101, -0x0101), 0);
ASSERTU4(biopDividu4u4(0, 0x01010101), 0); ASSERTI2(i2_addition(2, 1), 3);
ASSERTU4(biopDividu4u4(0x01010101, 2), 0x808080); ASSERTI2(i2_addition(I2_MAX, I2_MAX), -2);
ASSERTU4(biopDividu4u4(U4_MAX, U4_MAX), 1); ASSERTI2(i2_addition(I2_MIN, I2_MIN), 0);
ASSERTU4(biopDividu4u4(U4_MAX, 1), U4_MAX); ASSERTI2(i2_addition(0, 0), 0);
} }
TEST biopRemainderu1u1_Main() TEST i2_subtract_Main()
{ {
extern u1 biopRemainderu1u1(u1 lhs, u1 rhs); extern i2 i2_subtract(i2 lhs, i2 rhs);
ASSERTU1(biopRemainderu1u1(0x01, 0x01), 0); ASSERTI2(i2_subtract(0x0101, 0x0100), 0x1);
ASSERTU1(biopRemainderu1u1(U1_MAX, U1_MAX), 0); ASSERTI2(i2_subtract(0x0100, 0x0101), -0x1);
ASSERTU1(biopRemainderu1u1(0, I1_MIN), 0); 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); extern i2 i2_multiply(i2 lhs, i2 rhs);
ASSERTU2(biopRemainderu2u2(0x0101, 0x0101), 0x0); ASSERTI2(i2_multiply(0x0101, 0x0101), 0x201);
ASSERTU2(biopRemainderu2u2(U2_MAX, 1), 0x0); ASSERTI2(i2_multiply(0x0101, -0x0101), -513);
ASSERTU2(biopRemainderu2u2(U2_MAX, 2), 1); ASSERTI2(i2_multiply(0, -0x0101), 0);
ASSERTU2(biopRemainderu2u2(U2_MAX, U2_MAX), 0x0); 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); extern i2 i2_divide(i2 lhs, i2 rhs);
ASSERTU4(biopRemainderu4u4(0x01010101, 0x01010101), 0); ASSERTI2(i2_divide(0x0101, 0x0101), 0x1);
ASSERTU4(biopRemainderu4u4(U4_MAX, U4_MAX), 0); ASSERTI2(i2_divide(I2_MAX, I2_MAX), 0x1);
ASSERTU4(biopRemainderu4u4(I4_MIN, I4_MIN), 0); ASSERTI2(i2_divide(I2_MIN, I2_MIN), 0x1);
ASSERTU4(biopRemainderu4u4(~1000, ~10), 4294966295);
ASSERTU4(biopRemainderu4u4(0, U4_MAX), 0);
} }
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(){ }

View file

@ -15,47 +15,144 @@
*/ */
#include "pcode_test.h" #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; u2 z;
z = !lhs; z = lhs > rhs;
return z; return z;
} }
u1 biopSubu1u1(u1 lhs, u1 rhs) u2 u2_greaterThanEquals(u2 lhs, u2 rhs)
{ {
u1 z; u2 z;
z = lhs - rhs;
return z;
}
u1 biopGeu1u1(u1 lhs, u1 rhs)
{
u1 z;
z = lhs >= rhs; z = lhs >= rhs;
return z; 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; 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; i2 z;
z = lhs ^ rhs; z = lhs > rhs;
return z; 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; i2 z;
@ -63,47 +160,7 @@ i2 biopLei2i2(i2 lhs, i2 rhs)
return z; return z;
} }
i4 biopSubi4i4(i4 lhs, i4 rhs) i2 i2_equals(i2 lhs, i2 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 z; i2 z;
@ -111,55 +168,7 @@ i2 biopEqi2i2(i2 lhs, i2 rhs)
return z; return z;
} }
u2 unopPlusu2(u2 lhs) i2 i2_notEquals(i2 lhs, i2 rhs)
{
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 z; i2 z;
@ -167,55 +176,32 @@ i2 biopNei2i2(i2 lhs, i2 rhs)
return z; 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; 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; 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; return z;
} }
u1 biopShtRhtu1u1(u1 lhs, u1 rhs) i2 i2_bitwiseAnd(i2 lhs, i2 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 z; i2 z;
@ -223,39 +209,154 @@ i2 biopAndi2i2(i2 lhs, i2 rhs)
return z; 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; 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; 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; z = lhs >> rhs;
return z; 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; 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; i2 z;
@ -263,39 +364,7 @@ i2 unopNegativei2(i2 lhs)
return z; return z;
} }
i4 biopGti4i4(i4 lhs, i4 rhs) i2 i2_unaryPlus(i2 lhs)
{
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 z; i2 z;
@ -303,215 +372,31 @@ i2 unopPlusi2(i2 lhs)
return z; return z;
} }
i4 biopGei4i4(i4 lhs, i4 rhs) i2 i2_addition(i2 lhs, i2 rhs)
{ {
i4 z; i2 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;
z = lhs + rhs; z = lhs + rhs;
return z; 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; 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; return z;
} }
i4 biopEqi4i4(i4 lhs, i4 rhs) i2 i2_divide(i2 lhs, i2 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 z; i2 z;
@ -519,34 +404,12 @@ i2 biopDividu2u2(i2 lhs, i2 rhs)
return z; return z;
} }
u4 biopDividu4u4(u4 lhs, u4 rhs) i2 i2_remainder(i2 lhs, i2 rhs)
{ {
u4 z; i2 z;
z = lhs / rhs;
return z;
}
u1 biopRemainderu1u1(u1 lhs, u1 rhs)
{
u1 z;
z = lhs % rhs; z = lhs % rhs;
return z; 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;
}

View file

@ -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(){ }

View file

@ -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;
}

View file

@ -15,7 +15,7 @@
*/ */
#include "pcode_test.h" #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; 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; return ret;
} }
u2 pcode_u2_complexLogic(u2 a, u2 b, u2 c, u2 d, u2 e, u2 f) i1 i1_complexLogic(i1 a, i1 b, i1 c, i1 d, i1 e, i1 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 ret = 0; 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; return ret;
} }
i2 pcode_i2_complexLogic(i2 a, i2 b, i2 c, i2 d, i2 e, i2 f) u1 u1_compareLogic(u1 lhs, u1 rhs)
{
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)
{ {
if (lhs < rhs) if (lhs < rhs)
lhs += 2; lhs += 2;
@ -142,33 +66,7 @@ u1 biopCmpu1u1(u1 lhs, u1 rhs)
return lhs; return lhs;
} }
u2 biopCmpu2u2(u2 lhs, u2 rhs) i1 i1_compareLogic(i1 lhs, i1 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)
{ {
if (lhs < 0) if (lhs < 0)
lhs += 2; lhs += 2;
@ -181,145 +79,130 @@ i1 biopCmpi1i1(i1 lhs, i1 rhs)
return lhs; return lhs;
} }
i2 biopCmpi2i2(i2 lhs, i2 rhs) /* Comparison operators */
u1 u1_greaterThan(u1 lhs, u1 rhs)
{ {
if (lhs < 0) u1 z;
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;
z = lhs > rhs; z = lhs > rhs;
return z; return z;
} }
i1 biopEqi1i1(i1 lhs, i1 rhs) u1 u1_greaterThanEquals(u1 lhs, u1 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 z; u1 z;
z = +lhs;
return z;
}
u2 biopGeu2u2(u2 lhs, u2 rhs)
{
u2 z;
z = lhs >= rhs; z = lhs >= rhs;
return z; return z;
} }
i1 biopNei1i1(i1 lhs, i1 rhs) u1 u1_lessThan(u1 lhs, u1 rhs)
{ {
i1 z; u1 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;
z = lhs < rhs; z = lhs < rhs;
return z; 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; i1 z;
@ -327,39 +210,7 @@ i1 biopAndi1i1(i1 lhs, i1 rhs)
return z; return z;
} }
i4 biopLogicOri4i4(i4 lhs, i4 rhs) i1 i1_bitwiseOr(i1 lhs, i1 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 z; i1 z;
@ -367,63 +218,7 @@ i1 biopOri1i1(i1 lhs, i1 rhs)
return z; return z;
} }
i2 biopRemainderi2i2(i2 lhs, i2 rhs) i1 i1_bitwiseXor(i1 lhs, i1 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 z; i1 z;
@ -431,55 +226,32 @@ i1 biopXOri1i1(i1 lhs, i1 rhs)
return z; 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; 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; return z;
} }
i1 biopDividi1i1(i1 lhs, i1 rhs) u1 u1_logicalNot(u1 lhs)
{ {
i1 z; u1 z;
z = lhs / rhs; z = !lhs;
return z; return z;
} }
i4 unopNegativei4(i4 lhs) i1 i1_logicalAnd(i1 lhs, i1 rhs)
{
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 z; i1 z;
@ -487,31 +259,15 @@ i1 biopLogicAndi1i1(i1 lhs, i1 rhs)
return z; return z;
} }
i4 unopPlusi4(i4 lhs) i1 i1_logicalOr(i1 lhs, i1 rhs)
{ {
i4 z; i1 z;
z = +lhs; z = lhs || rhs;
return z; return z;
} }
i2 biopShtLfti2i2(i2 lhs, i2 rhs) i1 i1_logicalNot(i1 lhs)
{
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 z; i1 z;
@ -519,39 +275,89 @@ i1 unopNoti1(i1 lhs)
return z; 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; return z;
} }
i2 biopShtRhti2i2(i2 lhs, i2 rhs) u1 u1_shiftRight(u1 lhs, u1 rhs)
{ {
i2 z; u1 z;
z = lhs >> rhs; z = lhs >> rhs;
return z; 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; 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; z = lhs - rhs;
return z; 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; i1 z;
@ -559,31 +365,7 @@ i1 unopNegativei1(i1 lhs)
return z; return z;
} }
i2 biopGti2i2(i2 lhs, i2 rhs) i1 i1_unaryPlus(i1 lhs)
{
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 z; i1 z;
@ -591,66 +373,44 @@ i1 unopPlusi1(i1 lhs)
return z; 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; 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; return z;
} }
u1 biopMultu1u1(u1 lhs, u1 rhs) i1 i1_multiply(i1 lhs, i1 rhs)
{ {
u1 z; i1 z;
z = lhs * rhs; z = lhs * rhs;
return z; 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; 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; 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;
}

View file

@ -1,197 +1,199 @@
#include "pcode_test.h" #include "pcode_test.h"
/* Comparison operators */
#ifdef HAS_DOUBLE #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 lhs = 2;
f8 rhs = 1; f8 rhs = 1;
f8 retVal; 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(retVal, 0);
ASSERTF8(biopEqf8f8(PI_SHORT, PI_SHORT), 1.0); ASSERTF8(f8_lessThan(PI_SHORT, PI_SHORT), 0.0);
ASSERTF8(biopEqf8f8(PI_SHORT, 2*PI_SHORT), 0.0); ASSERTF8(f8_lessThan(PI_SHORT, 2*PI_SHORT), 1.0);
ASSERTF8(biopEqf8f8(2*PI_SHORT, PI_SHORT), 0.0); ASSERTF8(f8_lessThan(2*PI_SHORT, PI_SHORT), 0.0);
} }
#endif #endif
#ifdef HAS_DOUBLE #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 lhs = 2;
f8 rhs = 1; f8 rhs = 1;
f8 retVal; f8 retVal;
retVal = biopNef8f8(lhs, rhs); retVal = f8_lessThanEquals(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);
ASSERTF8(retVal, 0); 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 #endif
#ifdef HAS_DOUBLE #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 lhs = 2;
f8 retVal; 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(retVal, -2);
ASSERTF8(unopNegativef8(PI_SHORT), -3.14); ASSERTF8(f8_unaryMinus(PI_SHORT), -3.14);
} }
#endif #endif
#ifdef HAS_DOUBLE #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 lhs = 2;
f8 retVal; f8 retVal;
retVal = unopPlusf8(lhs); retVal = f8_unaryPlus(lhs);
ASSERTF8(retVal, 2); ASSERTF8(retVal, 2);
ASSERTF8(unopPlusf8(PI_SHORT), PI_SHORT); ASSERTF8(f8_unaryPlus(PI_SHORT), PI_SHORT);
} }
#endif #endif
#ifdef HAS_DOUBLE #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 lhs = 2;
f8 rhs = 1; f8 rhs = 1;
f8 retVal; f8 retVal;
retVal = biopMultf8f8(lhs, rhs); retVal = f8_addition(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);
ASSERTF8(retVal, 3); ASSERTF8(retVal, 3);
ASSERTF8(biopAddf8f8(PI_SHORT, PI_SHORT), 6.28); ASSERTF8(f8_addition(PI_SHORT, PI_SHORT), 6.28);
} }
#endif #endif
#ifdef HAS_DOUBLE #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 lhs = 2;
f8 rhs = 1; f8 rhs = 1;
f8 retVal; f8 retVal;
retVal = biopGtf8f8(lhs, rhs); retVal = f8_subtract(lhs, rhs);
ASSERTF8(retVal, 1); ASSERTF8(retVal, 1);
ASSERTF8(biopGtf8f8(PI_SHORT, PI_SHORT), 0.0); ASSERTF8(f8_subtract(PI_SHORT, PI_SHORT), 0.0);
ASSERTF8(biopGtf8f8(PI_SHORT, 2*PI_SHORT), 0.0);
ASSERTF8(biopGtf8f8(2*PI_SHORT, PI_SHORT), 1.0);
} }
#endif #endif
#ifdef HAS_DOUBLE #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 lhs = 2;
f8 rhs = 1; f8 rhs = 1;
f8 retVal; f8 retVal;
retVal = biopGef8f8(lhs, rhs); retVal = f8_multiply(lhs, rhs);
ASSERTF8(retVal, 1); ASSERTF8(retVal, 2);
ASSERTF8(biopGef8f8(PI_SHORT, PI_SHORT), 1.0); ASSERTF8(f8_multiply(PI_SHORT, PI_SHORT), 9.8596);
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);
} }
#endif #endif
MAIN BIOPS_DOUBLE_main() { } MAIN BIOPS_DOUBLE_main() { }

View file

@ -14,89 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
#include "pcode_test.h" #include "pcode_test.h"
#ifdef HAS_DOUBLE #ifdef HAS_DOUBLE
f8 biopEqf8f8(f8 lhs, f8 rhs)
{
f8 z;
z = lhs == rhs; /* Comparison operators */
return z; f8 f8_greaterThan(f8 lhs, f8 rhs)
}
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)
{ {
f8 z; f8 z;
@ -104,7 +25,7 @@ f8 biopGtf8f8(f8 lhs, f8 rhs)
return z; return z;
} }
f8 biopGef8f8(f8 lhs, f8 rhs) f8 f8_greaterThanEquals(f8 lhs, f8 rhs)
{ {
f8 z; f8 z;
@ -112,7 +33,7 @@ f8 biopGef8f8(f8 lhs, f8 rhs)
return z; return z;
} }
f8 biopLtf8f8(f8 lhs, f8 rhs) f8 f8_lessThan(f8 lhs, f8 rhs)
{ {
f8 z; f8 z;
@ -120,7 +41,7 @@ f8 biopLtf8f8(f8 lhs, f8 rhs)
return z; return z;
} }
f8 biopLef8f8(f8 lhs, f8 rhs) f8 f8_lessThanEquals(f8 lhs, f8 rhs)
{ {
f8 z; f8 z;
@ -128,4 +49,88 @@ f8 biopLef8f8(f8 lhs, f8 rhs)
return z; 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 */ #endif /* #ifdef HAS_DOUBLE */

View file

@ -1,168 +1,171 @@
#include "pcode_test.h" #include "pcode_test.h"
#ifdef HAS_FLOAT #ifdef HAS_FLOAT
TEST biopCmpf4f4_Main() TEST f4_compareLogic_Main()
{ {
extern f4 biopCmpf4f4(f4 lhs, f4 rhs); extern f4 f4_compareLogic(f4 lhs, f4 rhs);
ASSERTF4(biopCmpf4f4(0x1, 0x1), 21); ASSERTF4(f4_compareLogic(0x1, 0x1), 21);
ASSERTF4(biopCmpf4f4(0x1, 0x2), 21); ASSERTF4(f4_compareLogic(0x1, 0x2), 21);
ASSERTF4(biopCmpf4f4(0x2, 0x1), 22); ASSERTF4(f4_compareLogic(0x2, 0x1), 22);
ASSERTF4(biopCmpf4f4(-0x1, -0x1), 21); ASSERTF4(f4_compareLogic(-0x1, -0x1), 21);
ASSERTF4(biopCmpf4f4(-0x1, -0x2), 21); ASSERTF4(f4_compareLogic(-0x1, -0x2), 21);
ASSERTF4(biopCmpf4f4(-0x2, -0x1), 24); ASSERTF4(f4_compareLogic(-0x2, -0x1), 24);
} }
#endif #endif
#ifdef HAS_DOUBLE #ifdef HAS_DOUBLE
TEST biopCmpf8f8_Main() TEST f8_compareLogic_Main()
{ {
extern f8 biopCmpf8f8(f8 lhs, f8 rhs); extern f8 f8_compareLogic(f8 lhs, f8 rhs);
ASSERTF8(biopCmpf8f8(0x1, 0x1), 21); ASSERTF8(f8_compareLogic(0x1, 0x1), 21);
ASSERTF8(biopCmpf8f8(0x1, 0x2), 21); ASSERTF8(f8_compareLogic(0x1, 0x2), 21);
ASSERTF8(biopCmpf8f8(0x2, 0x1), 22); ASSERTF8(f8_compareLogic(0x2, 0x1), 22);
ASSERTF8(biopCmpf8f8(-0x1, -0x1), 21); ASSERTF8(f8_compareLogic(-0x1, -0x1), 21);
ASSERTF8(biopCmpf8f8(-0x1, -0x2), 21); ASSERTF8(f8_compareLogic(-0x1, -0x2), 21);
ASSERTF8(biopCmpf8f8(-0x2, -0x1), 24); 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 #endif
#ifdef HAS_FLOAT #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 lhs = 2;
f4 rhs = 1; f4 rhs = 1;
f4 retVal; f4 retVal;
ASSERTF4(biopLtf4f4(lhs, rhs), 0); ASSERTF4(f4_lessThan(lhs, rhs), 0);
} }
#endif #endif
#ifdef HAS_FLOAT #ifdef HAS_FLOAT
TEST biopLef4f4_Main() TEST f4_lessThanEquals_Main()
{ {
extern f4 biopLef4f4(f4 lhs, f4 rhs); extern f4 f4_lessThanEquals(f4 lhs, f4 rhs);
ASSERTF4(biopLef4f4(2, 1), 0); ASSERTF4(f4_lessThanEquals(2, 1), 0);
ASSERTF4(biopLef4f4(PI_SHORT, 2*PI_SHORT), 1.0); ASSERTF4(f4_lessThanEquals(PI_SHORT, 2*PI_SHORT), 1.0);
ASSERTF4(biopLef4f4(PI_SHORT, PI_SHORT), 1.0); ASSERTF4(f4_lessThanEquals(PI_SHORT, PI_SHORT), 1.0);
ASSERTF4(biopLef4f4(2*PI_SHORT, PI_SHORT), 0.0); ASSERTF4(f4_lessThanEquals(2*PI_SHORT, PI_SHORT), 0.0);
} }
#endif #endif
#ifdef HAS_FLOAT #ifdef HAS_FLOAT
TEST biopEqf4f4_Main() TEST f4_equals_Main()
{ {
extern f4 biopEqf4f4(f4 lhs, f4 rhs); extern f4 f4_equals(f4 lhs, f4 rhs);
ASSERTF4(biopEqf4f4(2, 1), 0); ASSERTF4(f4_equals(2, 1), 0);
ASSERTF4(biopEqf4f4(PI_SHORT, PI_SHORT), 1.0); ASSERTF4(f4_equals(PI_SHORT, PI_SHORT), 1.0);
ASSERTF4(biopEqf4f4(PI_SHORT, 2*PI_SHORT), 0.0); ASSERTF4(f4_equals(PI_SHORT, 2*PI_SHORT), 0.0);
ASSERTF4(biopEqf4f4(2*PI_SHORT, PI_SHORT), 0.0); ASSERTF4(f4_equals(2*PI_SHORT, PI_SHORT), 0.0);
} }
#endif #endif
#ifdef HAS_FLOAT #ifdef HAS_FLOAT
TEST biopNef4f4_Main() TEST f4_notEquals_Main()
{ {
extern f4 biopNef4f4(f4 lhs, f4 rhs); extern f4 f4_notEquals(f4 lhs, f4 rhs);
ASSERTF4(biopNef4f4(2, 1), 1); ASSERTF4(f4_notEquals(2, 1), 1);
ASSERTF4(biopNef4f4(PI_SHORT, PI_SHORT), 0.0); ASSERTF4(f4_notEquals(PI_SHORT, PI_SHORT), 0.0);
ASSERTF4(biopNef4f4(PI_SHORT, 2*PI_SHORT), 1.0); ASSERTF4(f4_notEquals(PI_SHORT, 2*PI_SHORT), 1.0);
ASSERTF4(biopNef4f4(2*PI_SHORT, 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 #endif
#ifdef HAS_FLOAT #ifdef HAS_FLOAT
TEST biopLogicOrf4f4_Main() TEST f4_logicalOr_Main()
{ {
extern f4 biopLogicOrf4f4(f4 lhs, f4 rhs); extern f4 f4_logicalOr(f4 lhs, f4 rhs);
ASSERTF4(biopLogicOrf4f4(2, 1), 1); ASSERTF4(f4_logicalOr(2, 1), 1);
ASSERTF4(biopLogicOrf4f4(PI_SHORT, PI_SHORT), 1); ASSERTF4(f4_logicalOr(PI_SHORT, PI_SHORT), 1);
ASSERTF4(biopLogicOrf4f4(PI_SHORT, 0), 1); ASSERTF4(f4_logicalOr(PI_SHORT, 0), 1);
} }
#endif #endif
#ifdef HAS_FLOAT #ifdef HAS_FLOAT
TEST biopLogicAndf4f4_Main() TEST f4_logicalNot_Main()
{ {
extern f4 biopLogicAndf4f4(f4 lhs, f4 rhs); extern f4 f4_logicalNot(f4 lhs);
ASSERTF4(biopLogicAndf4f4(2, 1), 1); ASSERTF4(f4_logicalNot(2), 0);
ASSERTF4(biopLogicAndf4f4(PI_SHORT, PI_SHORT), 1); ASSERTF4(f4_logicalNot(PI_SHORT), 0);
ASSERTF4(biopLogicAndf4f4(PI_SHORT, 0), 0.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 #endif
#ifdef HAS_FLOAT #ifdef HAS_FLOAT
TEST unopNotf4_Main() TEST f4_unaryPlus_Main()
{ {
extern f4 unopNotf4(f4 lhs); extern f4 f4_unaryPlus(f4 lhs);
ASSERTF4(unopNotf4(2), 0); ASSERTF4(f4_unaryPlus(2), 2);
ASSERTF4(unopNotf4(PI_SHORT), 0); ASSERTF4(f4_unaryPlus(PI_SHORT), PI_SHORT);
} }
#endif #endif
#ifdef HAS_FLOAT #ifdef HAS_FLOAT
TEST unopNegativef4_Main() TEST f4_addition_Main()
{ {
extern f4 unopNegativef4(f4 lhs); extern f4 f4_addition(f4 lhs, f4 rhs);
ASSERTF4(unopNegativef4(2), -2); ASSERTF4(f4_addition(2, 1), 3);
ASSERTF4(unopNegativef4(PI_SHORT), -3.14); ASSERTF4(f4_addition(PI_SHORT, PI_SHORT), 6.280000);
} }
#endif #endif
#ifdef HAS_FLOAT #ifdef HAS_FLOAT
TEST unopPlusf4_Main() TEST f4_subtract_Main()
{ {
extern f4 unopPlusf4(f4 lhs); extern f4 f4_subtract(f4 lhs, f4 rhs);
ASSERTF4(unopPlusf4(2), 2); ASSERTF4(f4_subtract(2, 1), 1);
ASSERTF4(unopPlusf4(PI_SHORT), PI_SHORT); ASSERTF4(f4_subtract(PI_SHORT, PI_SHORT), 0.0);
} }
#endif #endif
#ifdef HAS_FLOAT #ifdef HAS_FLOAT
TEST biopMultf4f4_Main() TEST f4_multiply_Main()
{ {
extern f4 biopMultf4f4(f4 lhs, f4 rhs); extern f4 f4_multiply(f4 lhs, f4 rhs);
ASSERTF4(biopMultf4f4(2, 1), 2); ASSERTF4(f4_multiply(2, 1), 2);
ASSERTF4(biopMultf4f4(PI_SHORT, PI_SHORT), 9.859601); ASSERTF4(f4_multiply(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);
} }
#endif #endif

View file

@ -16,7 +16,7 @@
#include "pcode_test.h" #include "pcode_test.h"
#ifdef HAS_FLOAT #ifdef HAS_FLOAT
f4 biopCmpf4f4(f4 lhs, f4 rhs) f4 f4_compareLogic(f4 lhs, f4 rhs)
{ {
if (lhs < 0) if (lhs < 0)
lhs += 2; lhs += 2;
@ -29,7 +29,7 @@ f4 biopCmpf4f4(f4 lhs, f4 rhs)
return lhs; return lhs;
} }
f8 biopCmpf8f8(f8 lhs, f8 rhs) f8 f8_compareLogic(f8 lhs, f8 rhs)
{ {
if (lhs < 0) if (lhs < 0)
lhs += 2; lhs += 2;
@ -42,103 +42,8 @@ f8 biopCmpf8f8(f8 lhs, f8 rhs)
return lhs; return lhs;
} }
f4 biopLtf4f4(f4 lhs, f4 rhs) /* Comparison operators */
{ f4 f4_greaterThan(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)
{ {
f4 z; f4 z;
@ -146,7 +51,7 @@ f4 biopGtf4f4(f4 lhs, f4 rhs)
return z; return z;
} }
f4 biopGef4f4(f4 lhs, f4 rhs) f4 f4_greaterThanEquals(f4 lhs, f4 rhs)
{ {
f4 z; f4 z;
@ -154,4 +59,102 @@ f4 biopGef4f4(f4 lhs, f4 rhs)
return z; 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 */ #endif /* #ifdef HAS_FLOAT */

View file

@ -1,530 +1,532 @@
#include "pcode_test.h" #include "pcode_test.h"
#ifdef HAS_LONGLONG #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); extern i8 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(i8_complexLogic(-1916250774LL, 1528806445LL, -870305000LL, 0, 0, 1799560997LL), 14);
ASSERTI8(pcode_i8_complexLogic(-1375179334LL, -1539942439LL, 987987334LL, 0, 1162088421LL, 12548159LL), 15); ASSERTI8(i8_complexLogic(-1375179334LL, -1539942439LL, 987987334LL, 0, 1162088421LL, 12548159LL), 15);
ASSERTI8(pcode_i8_complexLogic(0, -750167716LL, -1104561852LL, 0, -915711850LL, 737703662LL), 11); ASSERTI8(i8_complexLogic(0, -750167716LL, -1104561852LL, 0, -915711850LL, 737703662LL), 11);
ASSERTI8(pcode_i8_complexLogic(0, 386839851LL, -771476364LL, 0, -942724790LL, 1833488263LL), 10); ASSERTI8(i8_complexLogic(0, 386839851LL, -771476364LL, 0, -942724790LL, 1833488263LL), 10);
} }
#endif #endif
#ifdef HAS_LONGLONG #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); extern u8 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(u8_complexLogic(2016764524ULL, 1717226057ULL, 1748349614ULL, 0, 1276673168ULL, 0), 15);
ASSERTU8(pcode_u8_complexLogic(2009726312ULL, 696947386ULL, 0, 0, 1265204346ULL, 1369602726ULL), 11); ASSERTU8(u8_complexLogic(2009726312ULL, 696947386ULL, 0, 0, 1265204346ULL, 1369602726ULL), 11);
ASSERTU8(pcode_u8_complexLogic(1665204916ULL, 1707056552ULL, 564325578ULL, 0, 0, 1010528946ULL), 14); ASSERTU8(u8_complexLogic(1665204916ULL, 1707056552ULL, 564325578ULL, 0, 0, 1010528946ULL), 14);
ASSERTU8(pcode_u8_complexLogic(0, 1516266761ULL, 1866000081ULL, 0, 1175526309ULL, 1586903190ULL), 10); ASSERTU8(u8_complexLogic(0, 1516266761ULL, 1866000081ULL, 0, 1175526309ULL, 1586903190ULL), 10);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopCmpi8i8_Main() TEST i8_compareLogic_Main()
{ {
extern i8 biopCmpi8i8(i8 lhs, i8 rhs); extern i8 i8_compareLogic(i8 lhs, i8 rhs);
ASSERTI8(biopCmpi8i8(0x1, 0x1), 21); ASSERTI8(i8_compareLogic(0x1, 0x1), 21);
ASSERTI8(biopCmpi8i8(0x1, 0x2), 21); ASSERTI8(i8_compareLogic(0x1, 0x2), 21);
ASSERTI8(biopCmpi8i8(0x2, 0x1), 22); ASSERTI8(i8_compareLogic(0x2, 0x1), 22);
ASSERTI8(biopCmpi8i8(-0x1, -0x1), 21); ASSERTI8(i8_compareLogic(-0x1, -0x1), 21);
ASSERTI8(biopCmpi8i8(-0x1, -0x2), 21); ASSERTI8(i8_compareLogic(-0x1, -0x2), 21);
ASSERTI8(biopCmpi8i8(-0x2, -0x1), 24); ASSERTI8(i8_compareLogic(-0x2, -0x1), 24);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopCmpu8u8_Main() TEST u8_compareLogic_Main()
{ {
extern u8 biopCmpu8u8(u8 lhs, u8 rhs); extern u8 u8_compareLogic(u8 lhs, u8 rhs);
ASSERTU8(biopCmpu8u8(0x1, 0x1), 1); ASSERTU8(u8_compareLogic(0x1, 0x1), 1);
ASSERTU8(biopCmpu8u8(0x1, 0x2), 23); ASSERTU8(u8_compareLogic(0x1, 0x2), 23);
ASSERTU8(biopCmpu8u8(0x2, 0x1), 22); 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 #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopNei8i8_Main() TEST u8_greaterThanEquals_Main()
{ {
extern i8 biopNei8i8(i8 lhs, i8 rhs); extern u8 u8_greaterThanEquals(u8 lhs, u8 rhs);
ASSERTI8(biopNei8i8(2, 1), 1); ASSERTU8(u8_greaterThanEquals(2, 1), 1);
ASSERTI8(biopNei8i8(0x0101010101010101LL, 0x0101010101010101LL), 0); ASSERTU8(u8_greaterThanEquals(U8_MAX, U8_MAX), 1);
ASSERTI8(biopNei8i8(0x0101010101010101LL, -0x0101010101010101LL), 1); ASSERTU8(u8_greaterThanEquals(U8_MAX, U8_MIN), 1);
ASSERTI8(biopNei8i8(I8_MAX, I8_MAX), 0); ASSERTU8(u8_greaterThanEquals(U8_MIN, U8_MAX), 0);
ASSERTI8(biopNei8i8(I8_MAX, I8_MIN), 1);
ASSERTI8(biopNei8i8(I8_MIN, I8_MAX), 1);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopAndu8u8_Main() TEST u8_lessThan_Main()
{ {
extern u8 biopAndu8u8(u8 lhs, u8 rhs); extern u8 u8_lessThan(u8 lhs, u8 rhs);
ASSERTU8(biopAndu8u8(2, 1), 0); ASSERTU8(u8_lessThan(2, 1), 0);
ASSERTU8(biopAndu8u8(U8_MAX, U8_MAX), U8_MAX); ASSERTU8(u8_lessThan(U8_MAX, U8_MAX), 0);
ASSERTU8(biopAndu8u8(U8_MAX, 0), 0); ASSERTU8(u8_lessThan(U8_MAX, U8_MIN), 0);
ASSERTU8(biopAndu8u8(U8_MAX, 1), 1); ASSERTU8(u8_lessThan(U8_MIN, U8_MAX), 1);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopAndi8i8_Main() TEST u8_lessThanEquals_Main()
{ {
extern i8 biopAndi8i8(i8 lhs, i8 rhs); extern u8 u8_lessThanEquals(u8 lhs, u8 rhs);
ASSERTI8(biopAndi8i8(2, 1), 0); ASSERTU8(u8_lessThanEquals(2, 1), 0);
ASSERTI8(biopAndi8i8(0x0101010101010101LL, 0x0101010101010101LL), 0x0101010101010101); ASSERTU8(u8_lessThanEquals(U8_MAX, U8_MAX), 1);
ASSERTI8(biopAndi8i8(I8_MAX, I8_MAX), I8_MAX); ASSERTU8(u8_lessThanEquals(U8_MAX, U8_MIN), 0);
ASSERTI8(biopAndi8i8(I8_MAX, I8_MIN), 0); ASSERTU8(u8_lessThanEquals(U8_MIN, U8_MAX), 1);
ASSERTI8(biopAndi8i8(I8_MAX, 0), 0);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopOru8u8_Main() TEST u8_equals_Main()
{ {
extern u8 biopOru8u8(u8 lhs, u8 rhs); extern u8 u8_equals(u8 lhs, u8 rhs);
ASSERTU8(biopOru8u8(2, 1), 3); ASSERTU8(u8_equals(2, 1), 0);
ASSERTU8(biopOru8u8(U8_MAX, U8_MAX), U8_MAX); ASSERTU8(u8_equals(U8_MAX, U8_MAX), 1);
ASSERTU8(biopOru8u8(U8_MAX, U8_MIN), 18446744073709551615ULL); ASSERTU8(u8_equals(U8_MAX, U8_MIN), 0);
ASSERTU8(biopOru8u8(U8_MAX, 0), 18446744073709551615ULL); ASSERTU8(u8_equals(U8_MIN, U8_MAX), 0);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopXOru8u8_Main() TEST u8_notEquals_Main()
{ {
extern u8 biopXOru8u8(u8 lhs, u8 rhs); extern u8 u8_notEquals(u8 lhs, u8 rhs);
ASSERTU8(biopXOru8u8(2, 1), 3); ASSERTU8(u8_notEquals(2, 1), 1);
ASSERTU8(biopXOru8u8(U8_MAX, U8_MAX), 0); ASSERTU8(u8_notEquals(U8_MAX, U8_MAX), 0);
ASSERTU8(biopXOru8u8(U8_MAX, 0), U8_MAX); ASSERTU8(u8_notEquals(U8_MAX, U8_MIN), 1);
ASSERTU8(biopXOru8u8(U8_MAX, 2), 18446744073709551613ULL); ASSERTU8(u8_notEquals(U8_MIN, U8_MAX), 1);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopOri8i8_Main() TEST i8_greaterThan_Main()
{ {
extern i8 biopOri8i8(i8 lhs, i8 rhs); extern i8 i8_greaterThan(i8 lhs, i8 rhs);
ASSERTI8(biopOri8i8(2, 1), 3); ASSERTI8(i8_greaterThan(0x0101010101010101LL, 0x0101010101010101LL), 0);
ASSERTI8(biopOri8i8(0x0101010101010101LL, 0x0101010101010101LL), 0x0101010101010101LL); ASSERTI8(i8_greaterThan(0x0101010101010101LL, -0x0101010101010101LL), 1);
ASSERTI8(biopOri8i8(0x0101010101010101LL, 0x0), 0x0101010101010101LL); ASSERTI8(i8_greaterThan(2, 1), 1);
ASSERTI8(biopOri8i8(U8_MAX, U8_MAX), -1); ASSERTI8(i8_greaterThan(I8_MAX, I8_MAX), 0);
ASSERTI8(biopOri8i8(U8_MAX, U8_MIN), -1); ASSERTI8(i8_greaterThan(I8_MAX, I8_MIN), 1);
ASSERTI8(biopOri8i8(U8_MAX, 0), -1); ASSERTI8(i8_greaterThan(I8_MIN, I8_MAX), 0);
ASSERTI8(biopOri8i8(U8_MAX, 4), -1);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopLogicOru8u8_Main() TEST i8_greaterThanEquals_Main()
{ {
extern u8 biopLogicOru8u8(u8 lhs, u8 rhs); extern i8 i8_greaterThanEquals(i8 lhs, i8 rhs);
ASSERTU8(biopLogicOru8u8(2, 1), 1); ASSERTI8(i8_greaterThanEquals(2, 1), 1);
ASSERTU8(biopLogicOru8u8(U8_MAX, U8_MAX), 1); ASSERTI8(i8_greaterThanEquals(I8_MAX, I8_MAX), 1);
ASSERTU8(biopLogicOru8u8(U8_MIN, U8_MIN), 0); ASSERTI8(i8_greaterThanEquals(I8_MAX, I8_MIN), 1);
ASSERTU8(biopLogicOru8u8(U8_MIN, 0), 0); ASSERTI8(i8_greaterThanEquals(I8_MIN, I8_MAX), 0);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopXOri8i8_Main() TEST i8_lessThan_Main()
{ {
extern i8 biopXOri8i8(i8 lhs, i8 rhs); extern i8 i8_lessThan(i8 lhs, i8 rhs);
ASSERTI8(biopXOri8i8(2, 1), 3); ASSERTI8(i8_lessThan(0x0101010101010101LL, 0x0101010101010101LL), 0);
ASSERTI8(biopXOri8i8(0x0101010101010101LL, 0x0101010101010101LL), 0); ASSERTI8(i8_lessThan(0x0101010101010101LL, -0x0101010101010101LL), 0);
ASSERTI8(biopXOri8i8(0x0101010101010101LL, 0x0101010101010101LL), 0x0); ASSERTI8(i8_lessThan(2, 1), 0);
ASSERTI8(biopXOri8i8(U8_MAX, U8_MAX), 0x0); ASSERTI8(i8_lessThan(I8_MAX, I8_MAX), 0);
ASSERTI8(biopXOri8i8(U8_MAX, U8_MIN), -1); ASSERTI8(i8_lessThan(I8_MAX, I8_MIN), 0);
ASSERTI8(biopXOri8i8(U8_MAX, 0), -1); ASSERTI8(i8_lessThan(I8_MIN, I8_MAX), 1);
ASSERTI8(biopXOri8i8(U8_MAX, 5), -6);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopRemainderi8i8_Main() TEST i8_lessThanEquals_Main()
{ {
extern i8 biopRemainderi8i8(i8 lhs, i8 rhs); extern i8 i8_lessThanEquals(i8 lhs, i8 rhs);
ASSERTI8(biopRemainderi8i8(0x0101010101010101LL, 0x0101010101010101LL), 0x0); ASSERTI8(i8_lessThanEquals(2, 1), 0);
ASSERTI8(biopRemainderi8i8(0x0101010101010101LL, 0x0001010101010101LL), 0x1); ASSERTI8(i8_lessThanEquals(0x0101010101010101LL, 0x0101010101010101LL), 1);
ASSERTI8(biopRemainderi8i8(0x0101010101010101LL, 0x0001010101010100LL), 0x101); ASSERTI8(i8_lessThanEquals(0x0101010101010101LL, -0x0101010101010101LL), 0);
ASSERTI8(biopRemainderi8i8(I8_MAX, I8_MAX), 0); ASSERTI8(i8_lessThanEquals(I8_MAX, I8_MAX), 1);
ASSERTI8(biopRemainderi8i8(I8_MAX, 1), 0); ASSERTI8(i8_lessThanEquals(I8_MAX, I8_MIN), 0);
ASSERTI8(biopRemainderi8i8(I8_MAX, I8_MIN), 9223372036854775807); ASSERTI8(i8_lessThanEquals(I8_MIN, I8_MAX), 1);
ASSERTI8(biopRemainderi8i8(I8_MAX, 0xFFFF), 32767);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopLogicOri8i8_Main() TEST i8_equals_Main()
{ {
extern i8 biopLogicOri8i8(i8 lhs, i8 rhs); extern i8 i8_equals(i8 lhs, i8 rhs);
ASSERTI8(biopLogicOri8i8(2, 1), 1); ASSERTI8(i8_equals(2, 1), 0);
ASSERTI8(biopLogicOri8i8(0x0101010101010101LL, 0x0101010101010101LL), 1); ASSERTI8(i8_equals(0x0101010101010101LL, 0x0101010101010101LL), 1);
ASSERTI8(biopLogicOri8i8(I8_MAX, I8_MAX), 1); ASSERTI8(i8_equals(0x0101010101010101LL, -0x0101010101010101LL), 0);
ASSERTI8(biopLogicOri8i8(I8_MAX, I8_MIN), 1); ASSERTI8(i8_equals(I8_MAX, I8_MAX), 1);
ASSERTI8(biopLogicOri8i8(I8_MAX, 0), 1); ASSERTI8(i8_equals(I8_MAX, I8_MIN), 0);
ASSERTI8(biopLogicOri8i8(I8_MAX, 5), 1); ASSERTI8(i8_equals(I8_MIN, I8_MAX), 0);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopLogicAndu8u8_Main() TEST i8_notEquals_Main()
{ {
extern u8 biopLogicAndu8u8(u8 lhs, u8 rhs); extern i8 i8_notEquals(i8 lhs, i8 rhs);
ASSERTU8(biopLogicAndu8u8(2, 1), 1); ASSERTI8(i8_notEquals(2, 1), 1);
ASSERTU8(biopLogicAndu8u8(U8_MAX, U8_MAX), 1); ASSERTI8(i8_notEquals(0x0101010101010101LL, 0x0101010101010101LL), 0);
ASSERTU8(biopLogicAndu8u8(U8_MAX, 0), 0); ASSERTI8(i8_notEquals(0x0101010101010101LL, -0x0101010101010101LL), 1);
ASSERTU8(biopLogicAndu8u8(U8_MAX, 5), 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 #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopDividi8i8_Main() TEST u8_bitwiseOr_Main()
{ {
extern i8 biopDividi8i8(i8 lhs, i8 rhs); extern u8 u8_bitwiseOr(u8 lhs, u8 rhs);
ASSERTI8(biopDividi8i8(0x0101010101010101LL, 0x0101010101010101LL), 0x1); ASSERTU8(u8_bitwiseOr(2, 1), 3);
ASSERTI8(biopDividi8i8(-0x0101010101010101LL, 0x0101010101010101LL), -0x1); ASSERTU8(u8_bitwiseOr(U8_MAX, U8_MAX), U8_MAX);
ASSERTI8(biopDividi8i8(0, 0x0101010101010101LL), 0); ASSERTU8(u8_bitwiseOr(U8_MAX, U8_MIN), 18446744073709551615ULL);
ASSERTI8(biopDividi8i8(0x0101010101010101LL, 2), 0x80808080808080); ASSERTU8(u8_bitwiseOr(U8_MAX, 0), 18446744073709551615ULL);
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);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopDividu8u8_Main() TEST u8_bitwiseXor_Main()
{ {
extern u8 biopDividu8u8(u8 lhs, u8 rhs); extern u8 u8_bitwiseXor(u8 lhs, u8 rhs);
ASSERTU8(biopDividu8u8(0x0101010101010101ULL, 0x0101010101010101ULL), 0x1); ASSERTU8(u8_bitwiseXor(2, 1), 3);
ASSERTU8(biopDividu8u8(-0x0101010101010101ULL, 0x0101010101010101ULL), 254); ASSERTU8(u8_bitwiseXor(U8_MAX, U8_MAX), 0);
ASSERTU8(biopDividu8u8(0, 0x0101010101010101ULL), 0); ASSERTU8(u8_bitwiseXor(U8_MAX, 0), U8_MAX);
ASSERTU8(biopDividu8u8(0x0101010101010101ULL, 2), 0x80808080808080); ASSERTU8(u8_bitwiseXor(U8_MAX, 2), 18446744073709551613ULL);
ASSERTU8(biopDividu8u8(U8_MAX, U8_MAX), 1);
ASSERTU8(biopDividu8u8(0, U8_MAX), 0);
ASSERTU8(biopDividu8u8(U8_MAX, 5), 3689348814741910323ULL);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopLogicAndi8i8_Main() TEST i8_bitwiseAnd_Main()
{ {
extern i8 biopLogicAndi8i8(i8 lhs, i8 rhs); extern i8 i8_bitwiseAnd(i8 lhs, i8 rhs);
ASSERTI8(biopLogicAndi8i8(0x0101010101010101LL, 0x0101010101010101LL), 1); ASSERTI8(i8_bitwiseAnd(2, 1), 0);
ASSERTI8(biopLogicAndi8i8(0x0101010101010101LL, 0x0), 0); ASSERTI8(i8_bitwiseAnd(0x0101010101010101LL, 0x0101010101010101LL), 0x0101010101010101);
ASSERTI8(biopLogicAndi8i8(2, 1), 1); ASSERTI8(i8_bitwiseAnd(I8_MAX, I8_MAX), I8_MAX);
ASSERTI8(biopLogicAndi8i8(I8_MAX, I8_MAX), 1); ASSERTI8(i8_bitwiseAnd(I8_MAX, I8_MIN), 0);
ASSERTI8(biopLogicAndi8i8(I8_MAX, I8_MIN), 1); ASSERTI8(i8_bitwiseAnd(I8_MAX, 0), 0);
ASSERTI8(biopLogicAndi8i8(I8_MAX, 0), 0);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST unopNotu8_Main() TEST i8_bitwiseOr_Main()
{ {
extern u8 unopNotu8(u8 lhs); extern i8 i8_bitwiseOr(i8 lhs, i8 rhs);
ASSERTU8(unopNotu8(2), 0); 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 #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST unopNoti8_Main() TEST i8_bitwiseXor_Main()
{ {
extern i8 unopNoti8(i8 lhs); extern i8 i8_bitwiseXor(i8 lhs, i8 rhs);
ASSERTI8(unopNoti8(0x0101010101010101LL), 0); ASSERTI8(i8_bitwiseXor(2, 1), 3);
ASSERTI8(unopNoti8(2), 0); ASSERTI8(i8_bitwiseXor(0x0101010101010101LL, 0x0101010101010101LL), 0);
ASSERTI8(unopNoti8(I8_MAX), 0); ASSERTI8(i8_bitwiseXor(0x0101010101010101LL, 0x0101010101010101LL), 0x0);
ASSERTI8(unopNoti8(I8_MIN), 0); ASSERTI8(i8_bitwiseXor(U8_MAX, U8_MAX), 0x0);
ASSERTI8(unopNoti8(0), 1); 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 #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST unopPlusu8_Main() TEST u8_logicalOr_Main()
{ {
extern u8 unopPlusu8(u8 lhs); extern u8 u8_logicalOr(u8 lhs, u8 rhs);
ASSERTU8(unopPlusu8(2), 2); ASSERTU8(u8_logicalOr(2, 1), 1);
ASSERTU8(unopPlusu8(U8_MAX), U8_MAX); ASSERTU8(u8_logicalOr(U8_MAX, U8_MAX), 1);
ASSERTU8(unopPlusu8(0), 0); ASSERTU8(u8_logicalOr(U8_MIN, U8_MIN), 0);
ASSERTU8(u8_logicalOr(U8_MIN, 0), 0);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST unopNegativei8_Main() TEST u8_logicalNot_Main()
{ {
extern i8 unopNegativei8(i8 lhs); extern u8 u8_logicalNot(u8 lhs);
ASSERTI8(unopNegativei8(2), -2); ASSERTU8(u8_logicalNot(2), 0);
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);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST unopPlusi8_Main() TEST i8_logicalAnd_Main()
{ {
extern i8 unopPlusi8(i8 lhs); extern i8 i8_logicalAnd(i8 lhs, i8 rhs);
ASSERTI8(unopPlusi8(2), 2); ASSERTI8(i8_logicalAnd(0x0101010101010101LL, 0x0101010101010101LL), 1);
ASSERTI8(unopPlusi8(0x0101010101010101LL), 0x0101010101010101LL); ASSERTI8(i8_logicalAnd(0x0101010101010101LL, 0x0), 0);
ASSERTI8(unopPlusi8(-0x0101010101010101LL), -0x0101010101010101LL); ASSERTI8(i8_logicalAnd(2, 1), 1);
ASSERTI8(unopPlusi8(I8_MAX), I8_MAX); ASSERTI8(i8_logicalAnd(I8_MAX, I8_MAX), 1);
ASSERTI8(unopPlusi8(I8_MIN), I8_MIN); ASSERTI8(i8_logicalAnd(I8_MAX, I8_MIN), 1);
ASSERTI8(unopPlusi8(0), 0); ASSERTI8(i8_logicalAnd(I8_MAX, 0), 0);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopMultu8u8_Main() TEST i8_logicalOr_Main()
{ {
extern u8 biopMultu8u8(u8 lhs, u8 rhs); extern i8 i8_logicalOr(i8 lhs, i8 rhs);
ASSERTU8(biopMultu8u8(2, 1), 2); ASSERTI8(i8_logicalOr(2, 1), 1);
ASSERTU8(biopMultu8u8(U8_MAX, U8_MAX), 1); ASSERTI8(i8_logicalOr(0x0101010101010101LL, 0x0101010101010101LL), 1);
ASSERTU8(biopMultu8u8(U8_MAX, U8_MIN), 0); ASSERTI8(i8_logicalOr(I8_MAX, I8_MAX), 1);
ASSERTU8(biopMultu8u8(U8_MAX, 0), 0); ASSERTI8(i8_logicalOr(I8_MAX, I8_MIN), 1);
ASSERTI8(i8_logicalOr(I8_MAX, 0), 1);
ASSERTI8(i8_logicalOr(I8_MAX, 5), 1);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopMulti8i8_Main() TEST i8_logicalNot_Main()
{ {
extern i8 biopMulti8i8(i8 lhs, i8 rhs); extern i8 i8_logicalNot(i8 lhs);
ASSERTI8(biopMulti8i8(2, 1), 2); ASSERTI8(i8_logicalNot(0x0101010101010101LL), 0);
ASSERTI8(biopMulti8i8(0x0101010101010101LL, 0x0101010101010101LL), 0x807060504030201LL); ASSERTI8(i8_logicalNot(2), 0);
ASSERTI8(biopMulti8i8(0, -0x0101010101010101LL), 0); ASSERTI8(i8_logicalNot(I8_MAX), 0);
ASSERTI8(biopMulti8i8(0x0101010101010101LL, -0x0101010101010101LL), -0x807060504030201LL); ASSERTI8(i8_logicalNot(I8_MIN), 0);
ASSERTI8(biopMulti8i8(I8_MAX, I8_MAX), 1); ASSERTI8(i8_logicalNot(0), 1);
ASSERTI8(biopMulti8i8(I8_MAX, I8_MIN), 0x8000000000000000LL);
ASSERTI8(biopMulti8i8(I8_MAX, 0), 0);
} }
#endif #endif
/* Shift operators */
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopSubu8u8_Main() TEST u8_shiftLeft_Main()
{ {
extern u8 biopSubu8u8(u8 lhs, u8 rhs); extern u8 u8_shiftLeft(u8 lhs, u8 rhs);
ASSERTU8(biopSubu8u8(2, 1), 1); ASSERTU8(u8_shiftLeft(2, 1), 4);
ASSERTU8(biopSubu8u8(U8_MAX, U8_MAX), 0); ASSERTU8(u8_shiftLeft(U8_MAX, 0), U8_MAX);
ASSERTU8(biopSubu8u8(U8_MAX, 0), U8_MAX); ASSERTU8(u8_shiftLeft(0, 4), 0);
ASSERTU8(biopSubu8u8(0, U8_MAX), 1);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopSubi8i8_Main() TEST u8_shiftRight_Main()
{ {
extern i8 biopSubi8i8(i8 lhs, i8 rhs); extern u8 u8_shiftRight(u8 lhs, u8 rhs);
ASSERTI8(biopSubi8i8(0x0101010101010101LL, 0x0101010101010100LL), 0x1); ASSERTU8(u8_shiftRight(2, 1), 1);
ASSERTI8(biopSubi8i8(0x0001010101010100LL, 0x0101010101010101LL), -72057594037927937LL); ASSERTU8(u8_shiftRight(U8_MAX, 0), U8_MAX);
ASSERTI8(biopSubi8i8(2, 1), 1); ASSERTU8(u8_shiftRight(0, 2), 0);
ASSERTI8(biopSubi8i8(0x0101010101010101LL, 0x0101010101010101LL), 0); ASSERTU8(u8_shiftRight(2, 2), 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);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopAddu8u8_Main() TEST i8_shiftLeft_Main()
{ {
extern u8 biopAddu8u8(u8 lhs, u8 rhs); extern i8 i8_shiftLeft(i8 lhs, i8 rhs);
ASSERTU8(biopAddu8u8(2, 1), 3); ASSERTI8(i8_shiftLeft(0x0101010101010101LL, 16), 0x101010101010000LL);
ASSERTU8(biopAddu8u8(U8_MAX, U8_MAX), 18446744073709551614ULL); ASSERTI8(i8_shiftLeft(0x0101010101010101LL, 8), 0x101010101010100LL);
ASSERTU8(biopAddu8u8(U8_MAX, 0), U8_MAX); ASSERTI8(i8_shiftLeft(0x0101010101010101LL, 0), 0x101010101010101LL);
ASSERTI8(i8_shiftLeft(2, 1), 4);
ASSERTI8(i8_shiftLeft(I8_MAX, 0), I8_MAX);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopShtLftu8u8_Main() TEST i8_shiftRight_Main()
{ {
extern u8 biopShtLftu8u8(u8 lhs, u8 rhs); extern i8 i8_shiftRight(i8 lhs, i8 rhs);
ASSERTU8(biopShtLftu8u8(2, 1), 4); ASSERTI8(i8_shiftRight(0x0101010101010101LL, 8), 0x1010101010101LL);
ASSERTU8(biopShtLftu8u8(U8_MAX, 0), U8_MAX); ASSERTI8(i8_shiftRight(0x0101010101010101LL, 16), 0x10101010101LL);
ASSERTU8(biopShtLftu8u8(0, 4), 0); 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 #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopAddi8i8_Main() TEST u8_addition_Main()
{ {
extern i8 biopAddi8i8(i8 lhs, i8 rhs); extern u8 u8_addition(u8 lhs, u8 rhs);
ASSERTI8(biopAddi8i8(0x0101010101010101LL, 0x0101010101010101LL), 0x202020202020202LL); ASSERTU8(u8_addition(2, 1), 3);
ASSERTI8(biopAddi8i8(2, 1), 3); ASSERTU8(u8_addition(U8_MAX, U8_MAX), 18446744073709551614ULL);
ASSERTI8(biopAddi8i8(I8_MAX, I8_MAX), -2); ASSERTU8(u8_addition(U8_MAX, 0), U8_MAX);
ASSERTI8(biopAddi8i8(I8_MAX, I8_MIN), -1);
ASSERTI8(biopAddi8i8(I8_MAX, 0), I8_MAX);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopShtRhtu8u8_Main() TEST u8_subtract_Main()
{ {
extern u8 biopShtRhtu8u8(u8 lhs, u8 rhs); extern u8 u8_subtract(u8 lhs, u8 rhs);
ASSERTU8(biopShtRhtu8u8(2, 1), 1); ASSERTU8(u8_subtract(2, 1), 1);
ASSERTU8(biopShtRhtu8u8(U8_MAX, 0), U8_MAX); ASSERTU8(u8_subtract(U8_MAX, U8_MAX), 0);
ASSERTU8(biopShtRhtu8u8(0, 2), 0); ASSERTU8(u8_subtract(U8_MAX, 0), U8_MAX);
ASSERTU8(biopShtRhtu8u8(2, 2), 0); ASSERTU8(u8_subtract(0, U8_MAX), 1);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopShtLfti8i8_Main() TEST u8_multiply_Main()
{ {
extern i8 biopShtLfti8i8(i8 lhs, i8 rhs); extern u8 u8_multiply(u8 lhs, u8 rhs);
ASSERTI8(biopShtLfti8i8(0x0101010101010101LL, 16), 0x101010101010000LL); ASSERTU8(u8_multiply(2, 1), 2);
ASSERTI8(biopShtLfti8i8(0x0101010101010101LL, 8), 0x101010101010100LL); ASSERTU8(u8_multiply(U8_MAX, U8_MAX), 1);
ASSERTI8(biopShtLfti8i8(0x0101010101010101LL, 0), 0x101010101010101LL); ASSERTU8(u8_multiply(U8_MAX, U8_MIN), 0);
ASSERTI8(biopShtLfti8i8(2, 1), 4); ASSERTU8(u8_multiply(U8_MAX, 0), 0);
ASSERTI8(biopShtLfti8i8(I8_MAX, 0), I8_MAX);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopShtRhti8i8_Main() TEST u8_divide_Main()
{ {
extern i8 biopShtRhti8i8(i8 lhs, i8 rhs); extern u8 u8_divide(u8 lhs, u8 rhs);
ASSERTI8(biopShtRhti8i8(0x0101010101010101LL, 8), 0x1010101010101LL); ASSERTU8(u8_divide(0x0101010101010101ULL, 0x0101010101010101ULL), 0x1);
ASSERTI8(biopShtRhti8i8(0x0101010101010101LL, 16), 0x10101010101LL); ASSERTU8(u8_divide(-0x0101010101010101ULL, 0x0101010101010101ULL), 254);
ASSERTI8(biopShtRhti8i8(0x0101010101010101LL, 0), 0x0101010101010101LL); ASSERTU8(u8_divide(0, 0x0101010101010101ULL), 0);
ASSERTI8(biopShtRhti8i8(2, 1), 1); ASSERTU8(u8_divide(0x0101010101010101ULL, 2), 0x80808080808080);
ASSERTI8(biopShtRhti8i8(I8_MAX, 0), I8_MAX); ASSERTU8(u8_divide(U8_MAX, U8_MAX), 1);
ASSERTU8(u8_divide(0, U8_MAX), 0);
ASSERTU8(u8_divide(U8_MAX, 5), 3689348814741910323ULL);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopGtu8u8_Main() TEST i8_unaryMinus_Main()
{ {
extern u8 biopGtu8u8(u8 lhs, u8 rhs); extern i8 i8_unaryMinus(i8 lhs);
ASSERTU8(biopGtu8u8(2, 1), 1); ASSERTI8(i8_unaryMinus(2), -2);
ASSERTU8(biopGtu8u8(U8_MAX, 0), 1); ASSERTI8(i8_unaryMinus(0x0101010101010101LL), -0x0101010101010101LL);
ASSERTU8(biopGtu8u8(U8_MAX, U8_MAX), 0); ASSERTI8(i8_unaryMinus(-0x0101010101010101LL), 0x0101010101010101LL);
ASSERTU8(biopGtu8u8(0, U8_MAX), 0); ASSERTI8(i8_unaryMinus(I8_MAX), I8_MIN+1);
ASSERTI8(i8_unaryMinus(I8_MIN), I8_MIN);
ASSERTI8(i8_unaryMinus(0), 0);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopGti8i8_Main() TEST i8_unaryPlus_Main()
{ {
extern i8 biopGti8i8(i8 lhs, i8 rhs); extern i8 i8_unaryPlus(i8 lhs);
ASSERTI8(biopGti8i8(0x0101010101010101LL, 0x0101010101010101LL), 0); ASSERTI8(i8_unaryPlus(2), 2);
ASSERTI8(biopGti8i8(0x0101010101010101LL, -0x0101010101010101LL), 1); ASSERTI8(i8_unaryPlus(0x0101010101010101LL), 0x0101010101010101LL);
ASSERTI8(biopGti8i8(2, 1), 1); ASSERTI8(i8_unaryPlus(-0x0101010101010101LL), -0x0101010101010101LL);
ASSERTI8(biopGti8i8(I8_MAX, I8_MAX), 0); ASSERTI8(i8_unaryPlus(I8_MAX), I8_MAX);
ASSERTI8(biopGti8i8(I8_MAX, I8_MIN), 1); ASSERTI8(i8_unaryPlus(I8_MIN), I8_MIN);
ASSERTI8(biopGti8i8(I8_MIN, I8_MAX), 0); ASSERTI8(i8_unaryPlus(0), 0);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopGeu8u8_Main() TEST i8_addition_Main()
{ {
extern u8 biopGeu8u8(u8 lhs, u8 rhs); extern i8 i8_addition(i8 lhs, i8 rhs);
ASSERTU8(biopGeu8u8(2, 1), 1); ASSERTI8(i8_addition(0x0101010101010101LL, 0x0101010101010101LL), 0x202020202020202LL);
ASSERTU8(biopGeu8u8(U8_MAX, U8_MAX), 1); ASSERTI8(i8_addition(2, 1), 3);
ASSERTU8(biopGeu8u8(U8_MAX, U8_MIN), 1); ASSERTI8(i8_addition(I8_MAX, I8_MAX), -2);
ASSERTU8(biopGeu8u8(U8_MIN, U8_MAX), 0); ASSERTI8(i8_addition(I8_MAX, I8_MIN), -1);
ASSERTI8(i8_addition(I8_MAX, 0), I8_MAX);
} }
#endif #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopGei8i8_Main() TEST i8_subtract_Main()
{ {
extern i8 biopGei8i8(i8 lhs, i8 rhs); extern i8 i8_subtract(i8 lhs, i8 rhs);
ASSERTI8(biopGei8i8(2, 1), 1); ASSERTI8(i8_subtract(0x0101010101010101LL, 0x0101010101010100LL), 0x1);
ASSERTI8(biopGei8i8(I8_MAX, I8_MAX), 1); ASSERTI8(i8_subtract(0x0001010101010100LL, 0x0101010101010101LL), -72057594037927937LL);
ASSERTI8(biopGei8i8(I8_MAX, I8_MIN), 1); ASSERTI8(i8_subtract(2, 1), 1);
ASSERTI8(biopGei8i8(I8_MIN, I8_MAX), 0); 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 #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopLtu8u8_Main() TEST i8_multiply_Main()
{ {
extern u8 biopLtu8u8(u8 lhs, u8 rhs); extern i8 i8_multiply(i8 lhs, i8 rhs);
ASSERTU8(biopLtu8u8(2, 1), 0); ASSERTI8(i8_multiply(2, 1), 2);
ASSERTU8(biopLtu8u8(U8_MAX, U8_MAX), 0); ASSERTI8(i8_multiply(0x0101010101010101LL, 0x0101010101010101LL), 0x807060504030201LL);
ASSERTU8(biopLtu8u8(U8_MAX, U8_MIN), 0); ASSERTI8(i8_multiply(0, -0x0101010101010101LL), 0);
ASSERTU8(biopLtu8u8(U8_MIN, U8_MAX), 1); 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 #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopLeu8u8_Main() TEST i8_divide_Main()
{ {
extern u8 biopLeu8u8(u8 lhs, u8 rhs); extern i8 i8_divide(i8 lhs, i8 rhs);
ASSERTU8(biopLeu8u8(2, 1), 0); ASSERTI8(i8_divide(0x0101010101010101LL, 0x0101010101010101LL), 0x1);
ASSERTU8(biopLeu8u8(U8_MAX, U8_MAX), 1); ASSERTI8(i8_divide(-0x0101010101010101LL, 0x0101010101010101LL), -0x1);
ASSERTU8(biopLeu8u8(U8_MAX, U8_MIN), 0); ASSERTI8(i8_divide(0, 0x0101010101010101LL), 0);
ASSERTU8(biopLeu8u8(U8_MIN, U8_MAX), 1); 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 #endif
#ifdef HAS_LONGLONG #ifdef HAS_LONGLONG
TEST biopLti8i8_Main() TEST i8_remainder_Main()
{ {
extern i8 biopLti8i8(i8 lhs, i8 rhs); extern i8 i8_remainder(i8 lhs, i8 rhs);
ASSERTI8(biopLti8i8(0x0101010101010101LL, 0x0101010101010101LL), 0); ASSERTI8(i8_remainder(0x0101010101010101LL, 0x0101010101010101LL), 0x0);
ASSERTI8(biopLti8i8(0x0101010101010101LL, -0x0101010101010101LL), 0); ASSERTI8(i8_remainder(0x0101010101010101LL, 0x0001010101010101LL), 0x1);
ASSERTI8(biopLti8i8(2, 1), 0); ASSERTI8(i8_remainder(0x0101010101010101LL, 0x0001010101010100LL), 0x101);
ASSERTI8(biopLti8i8(I8_MAX, I8_MAX), 0); ASSERTI8(i8_remainder(I8_MAX, I8_MAX), 0);
ASSERTI8(biopLti8i8(I8_MAX, I8_MIN), 0); ASSERTI8(i8_remainder(I8_MAX, 1), 0);
ASSERTI8(biopLti8i8(I8_MIN, I8_MAX), 1); ASSERTI8(i8_remainder(I8_MAX, I8_MIN), 9223372036854775807);
} ASSERTI8(i8_remainder(I8_MAX, 0xFFFF), 32767);
#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);
} }
#endif #endif

View file

@ -16,7 +16,7 @@
#include "pcode_test.h" #include "pcode_test.h"
#ifdef HAS_LONGLONG #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; 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; 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; 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; return ret;
} }
i8 biopCmpi8i8(i8 lhs, i8 rhs) i8 i8_compareLogic(i8 lhs, i8 rhs)
{ {
if (lhs < 0) if (lhs < 0)
lhs += 2; lhs += 2;
@ -67,7 +67,7 @@ i8 biopCmpi8i8(i8 lhs, i8 rhs)
return lhs; return lhs;
} }
u8 biopCmpu8u8(u8 lhs, u8 rhs) u8 u8_compareLogic(u8 lhs, u8 rhs)
{ {
if (lhs < rhs) if (lhs < rhs)
lhs += 2; lhs += 2;
@ -79,8 +79,96 @@ u8 biopCmpu8u8(u8 lhs, u8 rhs)
lhs += 16; lhs += 16;
return lhs; 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; i8 z;
@ -88,7 +176,8 @@ i8 biopNei8i8(i8 lhs, i8 rhs)
return z; return z;
} }
u8 biopAndu8u8(u8 lhs, u8 rhs) /* Bitwise operators */
u8 u8_bitwiseAnd(u8 lhs, u8 rhs)
{ {
u8 z; u8 z;
@ -96,7 +185,23 @@ u8 biopAndu8u8(u8 lhs, u8 rhs)
return z; 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; i8 z;
@ -104,23 +209,7 @@ i8 biopAndi8i8(i8 lhs, i8 rhs)
return z; return z;
} }
u8 biopOru8u8(u8 lhs, u8 rhs) i8 i8_bitwiseOr(i8 lhs, i8 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 z; i8 z;
@ -128,15 +217,7 @@ i8 biopOri8i8(i8 lhs, i8 rhs)
return z; return z;
} }
u8 biopLogicOru8u8(u8 lhs, u8 rhs) i8 i8_bitwiseXor(i8 lhs, i8 rhs)
{
u8 z;
z = lhs || rhs;
return z;
}
i8 biopXOri8i8(i8 lhs, i8 rhs)
{ {
i8 z; i8 z;
@ -144,15 +225,40 @@ i8 biopXOri8i8(i8 lhs, i8 rhs)
return z; 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; 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; i8 z;
@ -160,47 +266,7 @@ i8 biopLogicOri8i8(i8 lhs, i8 rhs)
return z; return z;
} }
u8 biopLogicAndu8u8(u8 lhs, u8 rhs) i8 i8_logicalNot(i8 lhs)
{
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 z; i8 z;
@ -208,7 +274,41 @@ i8 unopNoti8(i8 lhs)
return z; 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; u8 z;
@ -216,7 +316,40 @@ u8 unopPlusu8(u8 lhs)
return z; 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; i8 z;
@ -224,7 +357,7 @@ i8 unopNegativei8(i8 lhs)
return z; return z;
} }
i8 unopPlusi8(i8 lhs) i8 i8_unaryPlus(i8 lhs)
{ {
i8 z; i8 z;
@ -232,55 +365,7 @@ i8 unopPlusi8(i8 lhs)
return z; return z;
} }
u8 biopMultu8u8(u8 lhs, u8 rhs) i8 i8_addition(i8 lhs, i8 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 z; i8 z;
@ -288,116 +373,37 @@ i8 biopAddi8i8(i8 lhs, i8 rhs)
return z; return z;
} }
u8 biopShtRhtu8u8(u8 lhs, u8 rhs) i8 i8_subtract(i8 lhs, i8 rhs)
{
u8 z;
z = lhs >> rhs;
return z;
}
i8 biopShtLfti8i8(i8 lhs, i8 rhs)
{ {
i8 z; i8 z;
z = lhs << rhs; z = lhs - rhs;
return z; return z;
} }
i8 biopShtRhti8i8(i8 lhs, i8 rhs) i8 i8_multiply(i8 lhs, i8 rhs)
{ {
i8 z; i8 z;
z = lhs >> rhs; z = lhs * rhs;
return z; return z;
} }
u8 biopGtu8u8(u8 lhs, u8 rhs) i8 i8_divide(i8 lhs, i8 rhs)
{
u8 z;
z = lhs > rhs;
return z;
}
i8 biopGti8i8(i8 lhs, i8 rhs)
{ {
i8 z; i8 z;
z = lhs > rhs; z = lhs / rhs;
return z; return z;
} }
u8 biopGeu8u8(u8 lhs, u8 rhs) i8 i8_remainder(i8 lhs, i8 rhs)
{
u8 z;
z = lhs >= rhs;
return z;
}
i8 biopGei8i8(i8 lhs, i8 rhs)
{ {
i8 z; i8 z;
z = lhs >= rhs; z = lhs % rhs;
return z; 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 */ #endif /* #ifdef HAS_LONGLONG */

View file

@ -121,13 +121,13 @@ i4 nalign_struct(big_struct_type * in)
u4 pcode_memset(u1 *lhs, u1 val, u4 len) u4 pcode_memset(u1 *lhs, u1 val, u4 len)
{ {
memset(lhs, val, len); memset(lhs, val, (size_t) len);
return *(u4 *) lhs; return *(u4 *) lhs;
} }
void *pcode_memcpy(u1 * lhs, u1 * rhs, u4 len) 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) 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) 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) #if defined(HAS_FLOAT) && defined(HAS_DOUBLE) && defined(HAS_LONGLONG)

View file

@ -159,9 +159,9 @@ PCodeTest({
}) })
PCodeTest({ PCodeTest({
'name': 'AVR8_X5', 'name': 'AVR8_6',
'toolchain': 'AVR/avr-elf', 'toolchain': 'AVR/avr-elf',
'ccflags': '-mmcu=avrxmega5 -lgcc', 'ccflags': '-mmcu=avr6 -lgcc',
'language_id': 'avr8:LE:16:atmega256', 'language_id': 'avr8:LE:16:atmega256',
'has_float': 0, 'has_float': 0,
'has_double': 0, 'has_double': 0,

View file

@ -2170,6 +2170,10 @@ public abstract class ProcessorEmulatorTestAdapter extends TestCase implements E
// stub // stub
} }
public final void test_BIOPS4() {
// stub
}
public final void test_BitManipulation() { public final void test_BitManipulation() {
// stub // stub
} }

View file

@ -37,7 +37,7 @@
<language processor="AVR8" <language processor="AVR8"
endian="little" endian="little"
size="16" size="16"
variant="Atmega256" variant="avr6"
version="1.3" version="1.3"
slafile="avr8eind.sla" slafile="avr8eind.sla"
processorspec="atmega256.pspec" processorspec="atmega256.pspec"

View file

@ -1,5 +1,29 @@
<opinions> <opinions>
<constraint loader="Executable and Linking Format (ELF)" compilerSpecID="gcc"> <constraint loader="Executable and Linking Format (ELF)" compilerSpecID="gcc">
<constraint primary="83" processor="AVR8" endian="little" /> <constraint primary="83" processor="AVR8" endian="little" />
<!--
Elf e_flags are used for the secondary attribute, the following are pulled from binutils include/elf/avr.h
#define E_AVR_MACH_AVR1 1
#define E_AVR_MACH_AVR2 2
#define E_AVR_MACH_AVR25 25
#define E_AVR_MACH_AVR3 3
#define E_AVR_MACH_AVR31 31
#define E_AVR_MACH_AVR35 35
#define E_AVR_MACH_AVR4 4
#define E_AVR_MACH_AVR5 5
#define E_AVR_MACH_AVR51 51
#define E_AVR_MACH_AVR6 6
#define E_AVR_MACH_AVRTINY 100
#define E_AVR_MACH_XMEGA1 101
#define E_AVR_MACH_XMEGA2 102
#define E_AVR_MACH_XMEGA3 103
#define E_AVR_MACH_XMEGA4 104
#define E_AVR_MACH_XMEGA5 105
#define E_AVR_MACH_XMEGA6 106
#define E_AVR_MACH_XMEGA7 107
-->
<constraint primary="83" secondary= "31" processor="AVR8" size="16" variant="default"/>
<constraint primary="83" secondary= "51" processor="AVR8" size="16" variant="extended"/>
<constraint primary="83" secondary= "6" processor="AVR8" size="24"" variant="atmega256"/>
</constraint> </constraint>
</opinions> </opinions>

View file

@ -8,21 +8,20 @@
# pointer would be three bytes instead # pointer would be three bytes instead
define endian=little; define endian=little;
# Declaring space to be wordsized... alternative is to do byte sized # Declaring space to be wordsized... alternative is to do byte sized
define alignment=2; define alignment=2;
# Force fusion of two byte operations in a row by decoding as words # Force fusion of two byte operations in a row by decoding as words
#@define FUSION "" #@define FUSION ""
# mem space should really be the default, but the loading scripts will # mem space should really be the default, but the loading scripts will
# prefer the code space as the default. By being explicit for every # prefer the code space as the default. By being explicit for every
# instruction, we can eliminate the ambiguity for at least the # instruction, we can eliminate the ambiguity for at least the
# decompiler. None-the-less, other than when loading the binary into # decompiler. None-the-less, other than when loading the binary into
# Ghidra, it's still preferable to see the name of IO locations used, # Ghidra, it's still preferable to see the name of IO locations used,
# rather than code addresses, so leave mem space as the default. # rather than code addresses, so leave mem space as the default.
define space code type=ram_space size=$(PCBYTESIZE) wordsize=2 default;
define space code type=ram_space size=3 wordsize=2 default; define space register type=ram_space size=2;
define space register type=ram_space size=1;
define space mem type=ram_space size=2 wordsize=1; define space mem type=ram_space size=2 wordsize=1;
# Using decimal rather than hex to match specs # Using decimal rather than hex to match specs
@ -61,13 +60,21 @@ define register offset=0x80 size=1 [
]; ];
##################################### #####################################
# Some AVR processors may have different io layouts not just different io.
# I discovered different parts have different io layouts not just different io # This could necessitate modification to this section.
define mem offset=0x5B size=1 [ RAMPZ ]; # 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 ]; 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" @if HASEIND == "1"
define mem offset=0x5C size=1 [ EIND ]; define mem offset=0x5C size=1 [ EIND ];
@endif @endif
############################## ##############################
@ -76,10 +83,9 @@ define mem offset=0x5C size=1 [ EIND ];
define register offset=0x90 size=4 contextreg; define register offset=0x90 size=4 contextreg;
define context contextreg define context contextreg
useSkipCond=(0,0) noflow # =1 skip instruction if SKIP register is true useSkipCond = (0,0) noflow # =1 skip instruction if SKIP register is true
# transient context # transient context
phase=(1,1) # =0 check for useSkipCond, =1 parse instruction phase = (1,1) # =0 check for useSkipCond, =1 parse instruction
; ;
## Following 8051 example rather than define bitrange ## Following 8051 example rather than define bitrange
@ -272,7 +278,6 @@ attach variables [ op1RrPairHi op1RdPairHi f3op1RdPairHi ] [
X Y Z X Y Z
]; ];
RrFull: RrHi is RrHiLowSel=1 & RrHi { tmp:1 = RrHi; export tmp; } RrFull: RrHi is RrHiLowSel=1 & RrHi { tmp:1 = RrHi; export tmp; }
RrFull: RrLow is RrHiLowSel=0 & RrLow { tmp:1 = RrLow; export tmp; } RrFull: RrLow is RrHiLowSel=0 & RrLow { tmp:1 = RrLow; export tmp; }
@ -280,78 +285,138 @@ RrFull: RrLow is RrHiLowSel=0 & RrLow { tmp:1 = RrLow; export tmp; }
op1RrPair: op1RrPairHi is op1RrPairSel=1 & op1RrPairHi { tmp:2 = op1RrPairHi; export tmp; } op1RrPair: op1RrPairHi is op1RrPairSel=1 & op1RrPairHi { tmp:2 = op1RrPairHi; export tmp; }
op1RrPair: op1RrPairLow is op1RrPairSel=0 & op1RrPairLow { tmp:2 = op1RrPairLow; 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 # I'm uneasy at these... as they require the top of the stack
# to know what size element to reserve before the push. # 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 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) { macro pushPC(val) {
SP = SP - $(PCBYTESIZE); local valb:1 = val(0);
*[mem]:$(PCBYTESIZE) SP = val; *[mem]:1 SP = valb;
SP = SP - 1;
valb = val(1);
*[mem]:1 SP = valb;
SP = SP - 1;
} }
macro popPC(val) { macro popPC(val) {
val = *[mem]:$(PCBYTESIZE) SP; local valb:1 = 0;
SP = SP + $(PCBYTESIZE); SP = SP + 1;
}
macro push8(val) {
SP = SP -1;
*[mem]:1 SP = val;
}
macro pop8(val) {
val = *[mem]:1 SP; val = *[mem]:1 SP;
SP = SP + 1; 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) {
*[mem]:1 SP = val;
SP = SP -1;
}
macro pop8(val) {
SP = SP + 1;
val = *[mem]:1 SP;
}
# .slaspec shortcoming: Hflag isn't computed for most results # .slaspec shortcoming: Hflag isn't computed for most results
macro setSflag() { macro setSflag() {
$(Sflag) = $(Nflag) ^ $(Vflag); $(Sflag) = $(Nflag) ^ $(Vflag);
} }
macro setResultFlags(result){
macro setResultFlags(result) {
$(Nflag) = (result & 0x80) == 0x80; $(Nflag) = (result & 0x80) == 0x80;
$(Zflag) = (result == 0x0); $(Zflag) = (result == 0x0);
setSflag(); setSflag();
} }
macro setResult16Flags(result) { macro setResult16Flags(result) {
$(Nflag) = (result & 0x8000) == 0x8000; $(Nflag) = (result & 0x8000) == 0x8000;
$(Zflag) = (result == 0x0); $(Zflag) = (result == 0x0);
setSflag(); setSflag();
} }
macro setSubCarry(pre,sub){ # pre - sub
macro setSubCarry(pre,sub) { # pre - sub
$(Cflag) = (pre < sub); $(Cflag) = (pre < sub);
} }
# The decompilation looks better when the pcode comparision is used, # The decompilation looks better when the pcode comparision is used,
# rather than walking though the bit examples in the manual. # rather than walking though the bit examples in the manual.
# todo: consolidate these # todo: consolidate these
macro setVflagForSub(pre,sub,res){ # res = pre - sub macro setVflagForSub(pre,sub,res) { # res = pre - sub
$(Vflag) = scarry(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; macro setVflagForAdd(arg1,arg2,res) {
local b = (arg1 & 0x80) >> 7; local a = (arg1 & 0x80) >> 7;
local c = (arg2 & 0x80) >> 7; local b = (arg2 & 0x80) >> 7;
local V = (b & c & (~a)) ^ ((~b) & (~c) & a); local c = (res & 0x80) >> 7;
local V = (a & b & (~c)) | ((~a) & (~b) & c);
$(Vflag) = V & 0x01; $(Vflag) = V & 0x01;
} }
macro setCflagForAdd(arg1,arg2,res){
# pcode has a two form version... but not one taking carry in macro setCflagForAdd(arg1,arg2,res) {
$(Cflag) = carry(arg1,arg2); 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){
macro doSubtract(pre,sub,res) {
local x = pre - sub; local x = pre - sub;
setVflagForSub(pre,sub,x); setVflagForSub(pre,sub,x);
res = x;
setSubCarry(pre, sub); setSubCarry(pre, sub);
setResultFlags(res); setResultFlags(x);
$(Sflag) = pre s< sub; $(Sflag) = pre s< sub;
res = x;
} }
macro doSubtractWithCarry(pre,subNoCarry,res){
macro doSubtractWithCarry(pre,subNoCarry,res) {
local sub = subNoCarry + $(Cflag); local sub = subNoCarry + $(Cflag);
local x = pre - sub;
local oldZflag = $(Zflag); local oldZflag = $(Zflag);
doSubtract(pre,sub,res); setVflagForSub(pre,subNoCarry,x);
$(Cflag) = ((pre < sub) | (sub == 0 & $(Cflag) == 1));
setResultFlags(x);
$(Sflag) = $(Nflag)^$(Vflag);
$(Zflag) = oldZflag & $(Zflag); $(Zflag) = oldZflag & $(Zflag);
$(Sflag) = pre s< sub; res = x;
} }
macro setMulFlags(res) { macro setMulFlags(res) {
$(Cflag) = ((res & 0x8000) != 0); $(Cflag) = ((res & 0x8000) != 0);
$(Zflag) = (res == 0); $(Zflag) = (res == 0);
@ -370,14 +435,18 @@ macro setMulFlags(res) {
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 @ifdef FUSION
K16fuse: val is op1bits0to3 & op1bits8to11 & op2bits0to3 & op2bits8to11 [ val = (((op2bits8to11 << 4) | op2bits0to3) << 8) | ((op1bits8to11 << 4) | op1bits0to3); ] { tmp:2 = 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; } 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; } f3cmpK8: val is f3op2bits0to3 & f3op2bits8to11 [ val = (f3op2bits8to11 << 4) | f3op2bits0to3; ] { tmp:1 = val; export tmp; }
@endif @endif
rel7addr: rel is op3to9signed [ rel = (op3to9signed + inst_next);] { rel7addr: rel is op3to9signed [ rel = (op3to9signed + inst_next);] {
export *[code]:2 rel; 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; export rel7addr;
} }
@ -385,6 +454,7 @@ rel7dst: byteOffset is op3to9signed & rel7addr [ byteOffset = (op3to9signed + in
rel12addr: rel is oplow12signed [ rel = oplow12signed + inst_start + 1; ] { rel12addr: rel is oplow12signed [ rel = oplow12signed + inst_start + 1; ] {
export *[code]:2 rel; export *[code]:2 rel;
} }
rel12dst: byteOffset is oplow12signed & rel12addr [ byteOffset = (oplow12signed + inst_start + 1) << 1; ] { rel12dst: byteOffset is oplow12signed & rel12addr [ byteOffset = (oplow12signed + inst_start + 1) << 1; ] {
export rel12addr; export rel12addr;
} }
@ -392,23 +462,33 @@ rel12dst: byteOffset is oplow12signed & rel12addr [ byteOffset = (oplow12signed
abs22addr: loc is op4to8 & opbit0; next16 [ loc = (op4to8 << 17) | (opbit0 << 16) | next16; ] { abs22addr: loc is op4to8 & opbit0; next16 [ loc = (op4to8 << 17) | (opbit0 << 16) | next16; ] {
export *[code]:2 loc; export *[code]:2 loc;
} }
abs22dst: byteOffset is (op4to8 & opbit0; next16) & abs22addr [ byteOffset = ((op4to8 << 17) | (opbit0 << 16) | next16) << 1; ] { abs22dst: byteOffset is (op4to8 & opbit0; next16) & abs22addr [ byteOffset = ((op4to8 << 17) | (opbit0 << 16) | next16) << 1; ] {
export abs22addr; export abs22addr;
} }
next16memPtrVal1: next16 is next16 { export *[mem]:1 next16; } 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 @ifdef FUSION
ldswMemPtrVal2: ldswop1imm16 is ldswop1imm16 { export *[mem]:2 ldswop1imm16; } ldswMemPtrVal2: ldswop1imm16 is ldswop1imm16 { export *[mem]:2 ldswop1imm16; }
stswMemPtrVal2: ldswop2imm16 is ldswop2imm16 { export *[mem]:2 ldswop2imm16; } stswMemPtrVal2: ldswop2imm16 is ldswop2imm16 { export *[mem]:2 ldswop2imm16; }
@endif @endif
# K6 is used in dword operation # 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 # K7 is used by lds
K7addr: val is oplow4 & op9to10 & opbit8 [ val = ((1 ^ opbit8) << 7) | (opbit8 << 6) | (op9to10 << 4) | oplow4; ] { K7addr: val is oplow4 & op9to10 & opbit8 [ val = ((1 ^ opbit8) << 7) | (opbit8 << 6) | (op9to10 << 4) | oplow4; ] {
tmp:1 = val; export tmp; tmp:1 = val; export tmp;
} }
# Join against various spaces for dataspace... # Join against various spaces for dataspace...
# ##################################################################################### # #####################################################################################
# COMMENTING OUT BECAUSE "Subtable symbol K7addr is not allowed in context block" # COMMENTING OUT BECAUSE "Subtable symbol K7addr is not allowed in context block"
@ -418,22 +498,32 @@ K7addr: val is oplow4 & op9to10 & opbit8 [ val = ((1 ^ opbit8) << 7) | (opbit8 <
#A7Ioaddr: val is K7Ioaddr [ val = (K7Ioaddr | 0x00) + 0x20 ; ] { export *[mem]:1 val; } #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; } 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; } 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; } q6: val is oplow3 & op10to11 & opbit13 [ val = (opbit13 << 5) | (op10to11 << 3) | oplow3; ] { tmp:1 = val; export tmp; }
@ifdef FUSION @ifdef FUSION
# Predicates to verify that fusion will be valid here. # 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 # 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; } 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; } 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; } 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; } 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; } 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; } 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 # would like to check this for const pair, but hangs sleigh compiler: ldswop1imm15=ldswop2imm15
# So check as a few in a row # So check as a few in a row
# Not any better & ldswop1imm5b=ldswop2imm5b & ldswop1imm5c=ldswop2imm5c # Not any better & ldswop1imm5b=ldswop2imm5b & ldswop1imm5c=ldswop2imm5c
ldswConstPairPred: val is ldswop1bit16=0 & ldswop2bit16=1 & 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; } stswConstPairPred: val is ldswop1bit16=1 & ldswop2bit16=0 & ldswop1imm6=ldswop2imm6 [ val=0; ] { tmp:2 = val; export tmp; }
@endif @endif
define pcodeop todo; define pcodeop todo;
@ -453,6 +543,7 @@ define pcodeop break;
$(Vflag) = (0x0000 == (pre & 0x8000)) & ((post & 0x8000) == 0x8000); $(Vflag) = (0x0000 == (pre & 0x8000)) & ((post & 0x8000) == 0x8000);
setResult16Flags(post); setResult16Flags(post);
} }
@endif @endif
# Rd,Rr # Rd,Rr
:adc RdFull,RrFull is phase=1 & ophi6=0x7 & RdFull & RrFull { :adc RdFull,RrFull is phase=1 & ophi6=0x7 & RdFull & RrFull {
@ -473,7 +564,7 @@ define pcodeop break;
local pre = Rdw2; local pre = Rdw2;
Rdw2 = Rdw2 + zext(K6); Rdw2 = Rdw2 + zext(K6);
$(Cflag) = carry(pre,zext(K6)); $(Cflag) = carry(pre,zext(K6));
$(Vflag) = (0x0000 == (pre & 0x8000)) & ((Rdw2 & 0x8000) == 0x8000); $(Vflag) = scarry(Rdw2,zext(K6)); #(0x0000 == (pre & 0x8000)) & ((Rdw2 & 0x8000) == 0x8000);
setResult16Flags(Rdw2); setResult16Flags(Rdw2);
} }
# and Rd,Rr # and Rd,Rr
@ -496,10 +587,12 @@ define pcodeop break;
$(Vflag) = $(Nflag) ^ $(Cflag); $(Vflag) = $(Nflag) ^ $(Cflag);
setResultFlags(RdFull); setResultFlags(RdFull);
} }
# bclr s # bclr s
:bclr op4to6_flag is phase=1 & ophi9=0x129 & oplow4=0x4 & op4to6_flag { #done :bclr op4to6_flag is phase=1 & ophi9=0x129 & oplow4=0x4 & op4to6_flag { #done
op4to6_flag = 0; op4to6_flag = 0;
} }
# bld Rd,b # bld Rd,b
:bld RdFull,oplow3 is phase=1 & ophi7=0x7c & opbit3=0 & RdFull & oplow3 { :bld RdFull,oplow3 is phase=1 & ophi7=0x7c & opbit3=0 & RdFull & oplow3 {
local b = $(Tflag) << oplow3; local b = $(Tflag) << oplow3;
@ -533,13 +626,8 @@ define pcodeop break;
} }
# call k - todo - handle upper bits for 24 bit architecture # call k - todo - handle upper bits for 24 bit architecture
:call abs22dst is phase=1 & (ophi7=0x4a & op1to3=0x7) ... & abs22dst { :call abs22dst is phase=1 & (ophi7=0x4a & op1to3=0x7) ... & abs22dst {
tmp:3 = inst_next >> 1; tmp:$(PCBYTESIZE) = inst_next >> 1;
@if PCBYTESIZE == "2" pushPC(tmp);
ptr:2 = tmp:2;
@else
ptr:3 = tmp;
@endif
pushPC(ptr);
PC = &abs22dst; PC = &abs22dst;
call abs22dst; call abs22dst;
} }
@ -579,7 +667,7 @@ define pcodeop break;
} }
# clr Rd - really is EOR Rd, Rd # clr Rd - really is EOR Rd, Rd
:com RdFull is phase=1 & ophi7=0x4a & RdFull { :com RdFull is phase=1 & ophi7=0x4a & RdFull {
RdFull = 0xff - RdFull; RdFull = ~RdFull;
$(Vflag) = 0; $(Vflag) = 0;
$(Cflag) = 1; $(Cflag) = 1;
setResultFlags(RdFull); setResultFlags(RdFull);
@ -589,16 +677,17 @@ define pcodeop break;
setSubCarry(RdFull,RrFull); setSubCarry(RdFull,RrFull);
setVflagForSub(RdFull,RrFull,x); setVflagForSub(RdFull,RrFull,x);
setResultFlags(x); setResultFlags(x);
# but doesn't set result into a register # but doesn't set result into a register
} }
:cpc RdFull,RrFull is phase=1 & ophi6=0x1 & RdFull & RrFull { :cpc RdFull,RrFull is phase=1 & ophi6=0x1 & RdFull & RrFull {
local res = 3; local res = 0;
doSubtractWithCarry(RdFull,RrFull,res); doSubtractWithCarry(RdFull,RrFull,res);
} }
:cpi RdHi,K8 is phase=1 & ophi4=0x3 & RdHi & K8 { :cpi RdHi,K8 is phase=1 & ophi4=0x3 & RdHi & K8 {
local res = 3; local res = 0;
doSubtract(RdHi,K8,res); doSubtract(RdHi,K8,res);
} }
@ifdef FUSION @ifdef FUSION
# cpi; ldi; cpc sequence # 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 { :cpiw f3op1RdPairHi,f3cmpK16" ;ldi "f3op2RdHi,f3cmpK8 is phase=1 & f3op1hi4=0x3 & f3op2hi4=0xe & f3op3hi6=0x1 & f3cmpPairPred & f3cmpLdiPred & f3op1RdPairHi & f3op2RdHi & f3cmpK16 & f3cmpK8 {
@ -614,6 +703,7 @@ define pcodeop break;
setResult16Flags(res); setResult16Flags(res);
$(Sflag) = op1RdPair s< op1RrPair; $(Sflag) = op1RdPair s< op1RrPair;
} }
@endif @endif
:cpse RdFull,RrFull is phase=1 & ophi6=0x4 & RdFull & RrFull [ useSkipCond=1; globalset(inst_next,useSkipCond); ] { :cpse RdFull,RrFull is phase=1 & ophi6=0x4 & RdFull & RrFull [ useSkipCond=1; globalset(inst_next,useSkipCond); ] {
@ -622,17 +712,15 @@ define pcodeop break;
:dec RdFull is phase=1 & ophi7=0x4a & oplow4=0xa & RdFull { :dec RdFull is phase=1 & ophi7=0x4a & oplow4=0xa & RdFull {
# doesn't set the C flag # doesn't set the C flag
$(Vflag) = RdFull == 0x80; $(Vflag) = (RdFull == 0x80);
RdFull = RdFull - 1; RdFull = RdFull - 1;
setResultFlags(RdFull); 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" @if HASEIND == "1"
:eicall is phase=1 & ophi16=0x9519 { :eicall is phase=1 & ophi16=0x9519 {
ptr:3 = inst_next >> 1; ptr:$(PCBYTESIZE) = inst_next >> 1;
pushPC(ptr); pushPC(ptr);
PC = zext(Z) | (zext(EIND) << 16); PC = zext(Z) | (zext(EIND) << 16);
call [PC]; call [PC];
@ -642,6 +730,7 @@ define pcodeop break;
PC = zext(Z) | (zext(EIND) << 16); PC = zext(Z) | (zext(EIND) << 16);
goto [PC]; goto [PC];
} }
@endif @endif
@if PCBYTESIZE == "3" @if PCBYTESIZE == "3"
@ -667,6 +756,7 @@ define pcodeop break;
Z = ptr:2; Z = ptr:2;
RAMPZ = ptr[16,8]; RAMPZ = ptr[16,8];
} }
@endif @endif
:eor RdFull,RrFull is phase=1 & ophi6=0x9 & RdFull & RrFull { :eor RdFull,RrFull is phase=1 & ophi6=0x9 & RdFull & RrFull {
@ -681,12 +771,7 @@ define pcodeop break;
:fracmulsu RdHi,RrHi is phase=1 & ophi9=0x7 & opbit3=1 & RdHi & RrHi { todo(); } :fracmulsu RdHi,RrHi is phase=1 & ophi9=0x7 & opbit3=1 & RdHi & RrHi { todo(); }
:icall is phase=1 & ophi16=0x9509 { :icall is phase=1 & ophi16=0x9509 {
tmp:3 = inst_next >> 1; ptr:$(PCBYTESIZE) = inst_next >> 1;
@if PCBYTESIZE == "2"
ptr:2 = tmp:2;
@else
ptr:3 = tmp;
@endif
pushPC(ptr); pushPC(ptr);
PC = zext(Z); PC = zext(Z);
call [PC]; call [PC];
@ -721,18 +806,21 @@ define pcodeop break;
tmp:1 = *[mem]:1 Z; tmp:1 = *[mem]:1 Z;
tmp = tmp & (0xff - RdFull); tmp = tmp & (0xff - RdFull);
*[mem]:1 Z = tmp; *[mem]:1 Z = tmp;
RdFull = tmp;
} }
:las Z,RdFull is phase=1 & ophi7=0x49 & oplow4=0x5 & Z & RdFull { :las Z,RdFull is phase=1 & ophi7=0x49 & oplow4=0x5 & Z & RdFull {
tmp:1 = *[mem]:1 Z; tmp:1 = *[mem]:1 Z;
tmp = tmp | RdFull; tmp = tmp | RdFull;
*[mem]:1 Z = tmp; *[mem]:1 Z = tmp;
RdFull = tmp;
} }
:lat Z,RdFull is phase=1 & ophi7=0x49 & oplow4=0x7 & Z & RdFull { :lat Z,RdFull is phase=1 & ophi7=0x49 & oplow4=0x7 & Z & RdFull {
tmp:1 = *[mem]:1 Z; tmp:1 = *[mem]:1 Z;
tmp = tmp ^ RdFull; tmp = tmp ^ RdFull;
*[mem]:1 Z = tmp; *[mem]:1 Z = tmp;
RdFull = tmp;
} }
# three forms, really just specifying the increment mode # three forms, really just specifying the increment mode
@ -753,8 +841,10 @@ define pcodeop break;
RdFull = *[mem]:1 tmp; RdFull = *[mem]:1 tmp;
RstPtr = RstPtr + 0x01; RstPtr = RstPtr + 0x01;
} }
# ld Rd,-Y ; ld Rd, -X; ld Rd, -Z # ld Rd,-Y ; ld Rd, -X; ld Rd, -Z
LdPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; } LdPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; }
:ld RdFull,LdPredec is phase=1 & ophi7=0x48 & oplow2=0x02 & RdFull & LdPredec { :ld RdFull,LdPredec is phase=1 & ophi7=0x48 & oplow2=0x02 & RdFull & LdPredec {
tmp:2 = LdPredec; tmp:2 = LdPredec;
RdFull = *[mem]:1 tmp; RdFull = *[mem]:1 tmp;
@ -771,16 +861,25 @@ LdPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; }
:ldi RdHi,K8 is phase=1 & ophi4=0xe & RdHi & K8 { :ldi RdHi,K8 is phase=1 & ophi4=0xe & RdHi & K8 {
RdHi = K8; RdHi = K8;
} }
@if PCBYTESIZE == "2"
# lds Rd,k # lds Rd,k
:lds RdFull,next16memPtrVal1 is phase=1 & ophi7=0x48 & oplow4=0 & RdFull; next16memPtrVal1 { :lds RdFull,next16memPtrVal1 is phase=1 & ophi7=0x48 & oplow4=0 & RdFull; next16memPtrVal1 {
RdFull = next16memPtrVal1; RdFull = next16memPtrVal1;
} }
@else
:lds RdFull,next24memPtrVal1 is phase=1 & ophi7=0x48 & oplow4=0 & RdFull; next24memPtrVal1 {
RdFull = next24memPtrVal1;
}
@endif
@ifdef FUSION @ifdef FUSION
# Fuse together consecuitive lds ; lds # Fuse together consecuitive lds ; lds
# #
:ldsw ldswop1RdPair,ldswMemPtrVal2 is phase=1 & ldswop1hi7=0x48 & ldswop2hi7=0x48 & ldswop1low4=0 & ldswop2low4=0 & ldswMemPtrVal2 & ldswop1RdPair & ldswPairPred & ldswConstPairPred { :ldsw ldswop1RdPair,ldswMemPtrVal2 is phase=1 & ldswop1hi7=0x48 & ldswop2hi7=0x48 & ldswop1low4=0 & ldswop2low4=0 & ldswMemPtrVal2 & ldswop1RdPair & ldswPairPred & ldswConstPairPred {
ldswop1RdPair = ldswMemPtrVal2; ldswop1RdPair = ldswMemPtrVal2;
} }
@endif @endif
# lds Rd,k Seem to get some problems here... but 16-bit instruction isn't available on all atmega64. # 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_ # Furthermore, it will sometimes conflict with ldd Z+q for q=0x2_
@ -791,27 +890,27 @@ LdPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; }
# TODO: lpm semantic behavior needs verification ! # TODO: lpm semantic behavior needs verification !
# lpm R0 # lpm R0
:lpm R0 is phase=1 & ophi16=0x95c8 & R0 { :lpm R0 is phase=1 & ophi16=0x95c8 & R0 {
ptr:3 = zext(Z); ptr:$(PCBYTESIZE) = zext(Z);
tmp:2 = *[code]:2 (ptr >> 1); tmp:$(PCBYTESIZE) = *[code]:$(PCBYTESIZE) (ptr >> 1);
val:2 = (tmp >> (Z & 0x1)); val:$(PCBYTESIZE) = (tmp >> (Z & 0x1));
R0 = val:1; R0 = val:1;
} }
# lpm Rd,Z # lpm Rd,Z
:lpm RdFull,Z is phase=1 & ophi7=0x48 & op1to3=0x2 & RdFull & Z & opbit0=0 { :lpm RdFull,Z is phase=1 & ophi7=0x48 & op1to3=0x2 & RdFull & Z & opbit0=0 {
ptr:3 = zext(Z); ptr:$(PCBYTESIZE) = zext(Z);
tmp:2 = *[code]:2 (ptr >> 1); tmp:$(PCBYTESIZE) = *[code]:$(PCBYTESIZE) (ptr >> 1);
val:2 = (tmp >> (Z & 0x1)); val:$(PCBYTESIZE) = (tmp >> (Z & 0x1));
RdFull = val:1; RdFull = val:1;
} }
# lpm Rd,Z+ # lpm Rd,Z+
:lpm RdFull,Z"+" is phase=1 & ophi7=0x48 & op1to3=0x2 & RdFull & Z & opbit0=1 { :lpm RdFull,Z"+" is phase=1 & ophi7=0x48 & op1to3=0x2 & RdFull & Z & opbit0=1 {
ptr:3 = zext(Z); ptr:$(PCBYTESIZE) = zext(Z);
tmp:2 = *[code]:2 (ptr >> 1); tmp:$(PCBYTESIZE) = *[code]:$(PCBYTESIZE) (ptr >> 1);
val:2 = (tmp >> (Z & 0x1)); val:$(PCBYTESIZE) = (tmp >> (Z & 0x1));
RdFull = val:1; RdFull = val:1;
Z = Z + 1; Z = Z + 1;
} }
# lsl - just an assembly mnenoic for add # lsl - just an assembly mnemonic for add
:lsr RdFull is phase=1 & ophi7=0x4a & oplow4=0x6 & RdFull { :lsr RdFull is phase=1 & ophi7=0x4a & oplow4=0x6 & RdFull {
$(Cflag) = RdFull & 0x01; $(Cflag) = RdFull & 0x01;
RdFull = (RdFull >> 1); RdFull = (RdFull >> 1);
@ -845,8 +944,8 @@ LdPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; }
setMulFlags(R1R0); setMulFlags(R1R0);
} }
:neg RdFull is phase=1 & ophi7=0x4a & oplow4=1 & RdFull { :neg RdFull is phase=1 & ophi7=0x4a & oplow4=1 & RdFull {
RdFull = -RdFull;
$(Vflag) = (RdFull == 0x80); $(Vflag) = (RdFull == 0x80);
RdFull = 0 - RdFull;
$(Cflag) = (RdFull != 0); $(Cflag) = (RdFull != 0);
setResultFlags(RdFull); setResultFlags(RdFull);
} }
@ -880,17 +979,20 @@ LdPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; }
:push RdFull is phase=1 & ophi7=0x49 & oplow4=0xf & RdFull { :push RdFull is phase=1 & ophi7=0x49 & oplow4=0xf & RdFull {
push8(RdFull); push8(RdFull);
} }
# 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);
}
:rcall rel12dst is phase=1 & ophi4=0xd & rel12dst { :rcall rel12dst is phase=1 & ophi4=0xd & rel12dst {
tmp:3 = inst_next >> 1; ptr:$(PCBYTESIZE) = inst_next >> 1;
@if PCBYTESIZE == "2"
ptr:2 = tmp:2;
@else
ptr:3 = tmp;
@endif
pushPC(ptr); pushPC(ptr);
PC = &rel12dst; PC = &rel12dst;
call rel12dst; call rel12dst;
} }
:ret is phase=1 & ophi16=0x9508 { :ret is phase=1 & ophi16=0x9508 {
# Could also handle word size options here # Could also handle word size options here
popPC(PC); popPC(PC);
@ -915,12 +1017,15 @@ LdPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; }
$(Vflag) = $(Cflag) ^ $(Nflag); $(Vflag) = $(Cflag) ^ $(Nflag);
setResultFlags(RdFull); setResultFlags(RdFull);
} }
:sbc RdFull,RrFull is phase=1 & ophi6=0x2 & RdFull & RrFull { :sbc RdFull,RrFull is phase=1 & ophi6=0x2 & RdFull & RrFull {
doSubtractWithCarry(RdFull,RrFull,RdFull); doSubtractWithCarry(RdFull,RrFull,RdFull);
} }
:sbci RdHi,K8 is phase=1 & ophi4=4 & RdHi & K8 { :sbci RdHi,K8 is phase=1 & ophi4=4 & RdHi & K8 {
doSubtractWithCarry(RdHi,K8,RdHi); doSubtractWithCarry(RdHi,K8,RdHi);
} }
@ifdef FUSION @ifdef FUSION
# subi sbci # subi sbci
:subiw op1RdPairHi,K16fuse is phase=1 & op1hi4=0x5 & op2hi4=0x4 & K16fuse & fusion16rkrkPred & op1RdPairHi { :subiw op1RdPairHi,K16fuse is phase=1 & op1hi4=0x5 & op2hi4=0x4 & K16fuse & fusion16rkrkPred & op1RdPairHi {
@ -933,6 +1038,7 @@ LdPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; }
setResult16Flags(res); setResult16Flags(res);
$(Sflag) = pre s< K16fuse; $(Sflag) = pre s< K16fuse;
} }
@endif @endif
:sbi Aio5,oplow3 is phase=1 & ophi8=0x9a & Aio5 & oplow3 { :sbi Aio5,oplow3 is phase=1 & ophi8=0x9a & Aio5 & oplow3 {
Aio5 = Aio5 | (1 << oplow3); Aio5 = Aio5 | (1 << oplow3);
@ -948,7 +1054,7 @@ LdPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; }
:sbiw Rdw2,K6 is phase=1 & ophi8=0x97 & Rdw2 & K6 { :sbiw Rdw2,K6 is phase=1 & ophi8=0x97 & Rdw2 & K6 {
local pre = Rdw2; local pre = Rdw2;
Rdw2 = Rdw2 - zext(K6); Rdw2 = Rdw2 - zext(K6);
$(Cflag) = Rdw2 < zext(K6); $(Cflag) = zext(K6) > pre;
$(Vflag) = (0x8000 == (pre & 0x8000)) & ((Rdw2 & 0x8000) == 0x0000); $(Vflag) = (0x8000 == (pre & 0x8000)) & ((Rdw2 & 0x8000) == 0x0000);
setResult16Flags(Rdw2); setResult16Flags(Rdw2);
} }
@ -966,19 +1072,23 @@ LdPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; }
:ser RdHi is phase=1 & ophi8=0xef & oplow4=0xf & RdHi { :ser RdHi is phase=1 & ophi8=0xef & oplow4=0xf & RdHi {
RdHi = 0xff; RdHi = 0xff;
} }
define pcodeop sleep; define pcodeop sleep;
:sleep is phase=1 & ophi16=0x9588 { :sleep is phase=1 & ophi16=0x9588 {
sleep(); sleep();
} }
define pcodeop store_program_mem; # make this stand out. define pcodeop store_program_mem; # make this stand out.
:spm Z is phase=1 & ophi16=0x95e8 & Z { :spm Z is phase=1 & ophi16=0x95e8 & Z {
ptr:3 = zext(Z) << 1; ptr:$(PCBYTESIZE) = zext(Z) << 1;
*[code]:2 ptr = R1R0; *[code]:$(PCBYTESIZE) ptr = R1R0;
store_program_mem(); store_program_mem();
} }
:spm Z^"+" is phase=1 & ophi16=0x95f8 & Z { :spm Z^"+" is phase=1 & ophi16=0x95f8 & Z {
ptr:3 = zext(Z) << 1; ptr:$(PCBYTESIZE) = zext(Z) << 1;
*[code]:2 ptr = R1R0; *[code]:$(PCBYTESIZE) ptr = R1R0;
Z = Z + 1; Z = Z + 1;
store_program_mem(); store_program_mem();
} }
@ -995,17 +1105,22 @@ define pcodeop store_program_mem; # make this stand out.
# st Rd,Y+ ; st Rd, X+; st Rd, Z+ # st Rd,Y+ ; st Rd, X+; st Rd, Z+
StPlus: RstPtr^"+" is RstPtr { tmp:2 = RstPtr; RstPtr = RstPtr + 0x01; export tmp; } StPlus: RstPtr^"+" is RstPtr { tmp:2 = RstPtr; RstPtr = RstPtr + 0x01; export tmp; }
:st StPlus, RdFull is phase=1 & ophi7=0x49 & oplow2=0x01 & RdFull & StPlus { :st StPlus, RdFull is phase=1 & ophi7=0x49 & oplow2=0x01 & RdFull & StPlus {
*[mem]:1 StPlus = RdFull; *[mem]:1 StPlus = RdFull;
} }
# st Rd,-Y ; st Rd, -X; st Rd, -Z # st Rd,-Y ; st Rd, -X; st Rd, -Z
StPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; } StPredec: "-"^RstPtr is RstPtr { RstPtr = RstPtr - 0x01; export RstPtr; }
:st StPredec, RdFull is phase=1 & ophi7=0x49 & oplow2=0x02 & RdFull & StPredec { :st StPredec, RdFull is phase=1 & ophi7=0x49 & oplow2=0x02 & RdFull & StPredec {
tmp:2 = StPredec; tmp:2 = StPredec;
*[mem]:1 tmp = RdFull; *[mem]:1 tmp = RdFull;
} }
# std Rd,Y+q; std Rd,Z+q # std Rd,Y+q; std Rd,Z+q
StdYq: Rstq^"+"^q6 is Rstq & q6 { local ptr = Rstq + zext(q6); export ptr; } 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 { :std StdYq, RdFull is phase=1 & ophi2=0x2 & opbit12=0 & opbit9=1 & RdFull & StdYq {
*[mem]:1 StdYq = RdFull; *[mem]:1 StdYq = RdFull;
} }
@ -1013,11 +1128,13 @@ StdYq: Rstq^"+"^q6 is Rstq & q6 { local ptr = Rstq + zext(q6); export ptr; }
:sts next16memPtrVal1,RdFull is phase=1 & ophi7=0x49 & oplow4=0 & RdFull; next16memPtrVal1 { :sts next16memPtrVal1,RdFull is phase=1 & ophi7=0x49 & oplow4=0 & RdFull; next16memPtrVal1 {
next16memPtrVal1 = RdFull; next16memPtrVal1 = RdFull;
} }
@ifdef FUSION @ifdef FUSION
# sts ; sts emits backwards with respect to lds; lds # 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 { :stsw stswMemPtrVal2,stswop2RdPair is phase=1 & ldswop1hi7=0x49 & ldswop2hi7=0x49 & ldswop1low4=0 & ldswop2low4=0 & stswMemPtrVal2 & stswop2RdPair & stswPairPred & stswConstPairPred {
stswMemPtrVal2 = stswop2RdPair; stswMemPtrVal2 = stswop2RdPair;
} }
@endif @endif
# see manual for computation of address for 16-bit STS # see manual for computation of address for 16-bit STS
:sts RdHi is phase=1 & ophi5=0x15 & RdHi { todo(); } :sts RdHi is phase=1 & ophi5=0x15 & RdHi { todo(); }
@ -1031,8 +1148,10 @@ StdYq: Rstq^"+"^q6 is Rstq & q6 { local ptr = Rstq + zext(q6); export ptr; }
:swap RdFull is phase=1 & ophi7=0x4a & oplow4=2 & RdFull { :swap RdFull is phase=1 & ophi7=0x4a & oplow4=2 & RdFull {
RdFull = (RdFull >> 4) | (RdFull << 4); RdFull = (RdFull >> 4) | (RdFull << 4);
} }
# tst is AND Rd,Rd # tst is AND Rd,Rd
define pcodeop watchdog_reset; define pcodeop watchdog_reset;
:wdr is phase=1 & ophi16=0x95a8 { :wdr is phase=1 & ophi16=0x95a8 {
watchdog_reset(); watchdog_reset();
} }

View file

@ -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 PCBYTESIZE "2"
@define HASEIND "0" @define HASEIND "1"
@include "avr8.sinc" @include "avr8.sinc"

View file

@ -18,7 +18,7 @@
<long_size value="4" /> <long_size value="4" />
<long_long_size value="8" /> <long_long_size value="8" />
<float_size value="4" /> <float_size value="4" />
<double_size value="4" /> <double_size value="4" /> <!-- non-standard -->
<long_double_size value="4" /> <long_double_size value="4" />
<size_alignment_map> <size_alignment_map>
@ -46,12 +46,18 @@
<pentry minsize="1" maxsize="2"> <pentry minsize="1" maxsize="2">
<register name="R23R22"/> <register name="R23R22"/>
</pentry> </pentry>
<pentry minsize="3" maxsize="4">
<addr space="join" piece1="W" piece2="R23R22"/>
</pentry>
<pentry minsize="1" maxsize="2"> <pentry minsize="1" maxsize="2">
<register name="R21R20"/> <register name="R21R20"/>
</pentry> </pentry>
<pentry minsize="1" maxsize="2"> <pentry minsize="1" maxsize="2">
<register name="R19R18"/> <register name="R19R18"/>
</pentry> </pentry>
<pentry minsize="3" maxsize="4">
<addr space="join" piece1="R21R20" piece2="R19R18"/>
</pentry>
<pentry minsize="1" maxsize="2"> <pentry minsize="1" maxsize="2">
<register name="R17R16"/> <register name="R17R16"/>
</pentry> </pentry>
@ -72,6 +78,9 @@
<pentry minsize="1" maxsize="2"> <pentry minsize="1" maxsize="2">
<register name="W"/> <register name="W"/>
</pentry> </pentry>
<pentry minsize="3" maxsize="4">
<addr space="join" piece1="W" piece2="R23R22"/>
</pentry>
</output> </output>
<unaffected> <unaffected>
<register name="SP"/> <register name="SP"/>

View file

@ -18,7 +18,7 @@
<long_size value="4" /> <long_size value="4" />
<long_long_size value="8" /> <long_long_size value="8" />
<float_size value="4" /> <float_size value="4" />
<double_size value="4" /> <double_size value="4" /> <!-- non-standard -->
<long_double_size value="4" /> <long_double_size value="4" />
<size_alignment_map> <size_alignment_map>
@ -45,12 +45,18 @@
<pentry minsize="1" maxsize="2"> <pentry minsize="1" maxsize="2">
<register name="R23R22"/> <register name="R23R22"/>
</pentry> </pentry>
<pentry minsize="3" maxsize="4">
<addr space="join" piece1="W" piece2="R23R22"/>
</pentry>
<pentry minsize="1" maxsize="2"> <pentry minsize="1" maxsize="2">
<register name="R21R20"/> <register name="R21R20"/>
</pentry> </pentry>
<pentry minsize="1" maxsize="2"> <pentry minsize="1" maxsize="2">
<register name="R19R18"/> <register name="R19R18"/>
</pentry> </pentry>
<pentry minsize="3" maxsize="4">
<addr space="join" piece1="R21R20" piece2="R19R18"/>
</pentry>
<pentry minsize="1" maxsize="2"> <pentry minsize="1" maxsize="2">
<register name="R17R16"/> <register name="R17R16"/>
</pentry> </pentry>
@ -71,6 +77,9 @@
<pentry minsize="1" maxsize="2"> <pentry minsize="1" maxsize="2">
<register name="W"/> <register name="W"/>
</pentry> </pentry>
<pentry minsize="3" maxsize="4">
<addr space="join" piece1="W" piece2="R23R22"/>
</pentry>
</output> </output>
<unaffected> <unaffected>
<register name="SP"/> <register name="SP"/>

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}