mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
150 lines
2.4 KiB
C
150 lines
2.4 KiB
C
// The OS/K Team licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
#include "instrs.h"
|
|
#include "arch_i.h"
|
|
|
|
IMPL_COND(not);
|
|
IMPL_COND(and);
|
|
IMPL_COND(or);
|
|
IMPL_COND(xor);
|
|
IMPL_COND(shl);
|
|
IMPL_COND(shr);
|
|
|
|
#define CMP(v1, v2) \
|
|
if (v1 == v2) { \
|
|
flg |= ZF; \
|
|
flg &= ~CF; \
|
|
} \
|
|
else if (v1 < v2) { \
|
|
flg &= ~ZF; \
|
|
flg |= CF; \
|
|
} \
|
|
else { \
|
|
flg &= ~ZF; \
|
|
flg &= ~CF; \
|
|
}
|
|
|
|
//
|
|
// Comparison instructions
|
|
//
|
|
|
|
IMPL_START_2(test)
|
|
{
|
|
ulong v = v1 & v2;
|
|
|
|
CMP(v, 0);
|
|
}
|
|
IMPL_END;
|
|
|
|
IMPL_START_2(testb)
|
|
{
|
|
ulong v = v1 & v2 & 0x00000000000000FF;
|
|
|
|
CMP(v, 0);
|
|
}
|
|
IMPL_END;
|
|
|
|
IMPL_START_2(testw)
|
|
{
|
|
ulong v = v1 & v2 & 0x000000000000FFFF;
|
|
|
|
CMP(v, 0);
|
|
}
|
|
IMPL_END;
|
|
|
|
IMPL_START_2(testl)
|
|
{
|
|
ulong v = v1 & v2 & 0x00000000FFFFFFFF;
|
|
|
|
CMP(v, 0);
|
|
}
|
|
IMPL_END;
|
|
|
|
IMPL_START_2(testt)
|
|
{
|
|
ulong v = v1 & v2 & 0x0000FFFFFFFFFFFF;
|
|
|
|
CMP(v, 0);
|
|
}
|
|
IMPL_END;
|
|
|
|
IMPL_START_2(cmp)
|
|
{
|
|
CMP(v1, v2);
|
|
}
|
|
IMPL_END;
|
|
|
|
IMPL_START_2(cmpb)
|
|
{
|
|
v1 &= 0x00000000000000FF;
|
|
v2 &= 0x00000000000000FF;
|
|
CMP(v1, v2);
|
|
}
|
|
IMPL_END;
|
|
|
|
IMPL_START_2(cmpw)
|
|
{
|
|
v1 &= 0x000000000000FFFF;
|
|
v2 &= 0x000000000000FFFF;
|
|
CMP(v1, v2);
|
|
}
|
|
IMPL_END;
|
|
|
|
IMPL_START_2(cmpl)
|
|
{
|
|
v1 &= 0x00000000FFFFFFFF;
|
|
v2 &= 0x00000000FFFFFFFF;
|
|
CMP(v1, v2);
|
|
}
|
|
IMPL_END;
|
|
|
|
IMPL_START_2(cmpt)
|
|
{
|
|
v1 &= 0x0000FFFFFFFFFFFF;
|
|
v2 &= 0x0000FFFFFFFFFFFF;
|
|
CMP(v1, v2);
|
|
}
|
|
IMPL_END;
|
|
|
|
//
|
|
// Logical instructions
|
|
//
|
|
|
|
IMPL_START_2(and)
|
|
{
|
|
v1 &= v2;
|
|
}
|
|
IMPL_OUT;
|
|
|
|
IMPL_START_2(or)
|
|
{
|
|
v1 |= v2;
|
|
}
|
|
IMPL_OUT;
|
|
|
|
IMPL_START_2(xor)
|
|
{
|
|
v1 ^= v2;
|
|
}
|
|
IMPL_OUT;
|
|
|
|
IMPL_START_2(shl)
|
|
{
|
|
v1 <<= v2;
|
|
}
|
|
IMPL_OUT;
|
|
|
|
IMPL_START_2(shr)
|
|
{
|
|
v1 >>= v2;
|
|
}
|
|
IMPL_OUT;
|
|
|
|
IMPL_START_1(not)
|
|
{
|
|
v1 = ~v1;
|
|
}
|
|
IMPL_OUT;
|
|
|