mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
137 lines
3.3 KiB
C
137 lines
3.3 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 <in/instrs.h>
|
|
|
|
#define _NEED_ARCH_I
|
|
#include <ob/arch_i.h>
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
IMPL_START(or) { SRCP(p2); SRCP(p3); *r1 = p2->val | p3->val; return 1; }
|
|
IMPL_START(and) { SRCP(p2); SRCP(p3); *r1 = p2->val & p3->val; return 1; }
|
|
IMPL_START(xor) { SRCP(p2); SRCP(p3); *r1 = p2->val ^ p3->val; return 1; }
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
IMPL_START(shl) { SRCP(p2); SRCP(p3); *r1 = p2->val << p3->val; return 1; }
|
|
IMPL_START(shr) { SRCP(p2); SRCP(p3); *r1 = p2->val >> p3->val; return 1; }
|
|
IMPL_START(sar) { SRCP(p2); SRCP(p3); *r1 = (ulong)((long)p2->val >> (long)p3->val); return 1; }
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
IMPL_START(inc) { SRCP(p1); SRCP(p2); *r1 = p1->val + p2->val; return 1; }
|
|
IMPL_START(add) { SRCP(p2); SRCP(p3); *r1 = p2->val + p3->val; return 1; }
|
|
IMPL_START(addf) { SRCP(p2); SRCP(p3); COMPARE_ADD(p2->val, p3->val); *r1 = p2->val + p3->val; return 1; }
|
|
|
|
IMPL_START(dec) { SRCP(p1); SRCP(p2); *r1 = p1->val - p2->val; return 1; }
|
|
IMPL_START(sub) { SRCP(p2); SRCP(p3); *r1 = p2->val - p3->val; return 1; }
|
|
IMPL_START(subf) { SRCP(p2); SRCP(p3); COMPARE_SUB(p2->val, p3->val); *r1 = p2->val - p3->val; return 1; }
|
|
|
|
IMPL_START(adcx)
|
|
{
|
|
SRCP(p2);
|
|
SRCP(p3);
|
|
|
|
p3->val += !!(R(RFX)&CF);
|
|
COMPARE_ADD(p2->val, p3->val);
|
|
*r1 = p2->val + p3->val;
|
|
|
|
return 1;
|
|
}
|
|
|
|
IMPL_START(sbbx)
|
|
{
|
|
SRCP(p2);
|
|
SRCP(p3);
|
|
|
|
p3->val += !!(R(RFX)&CF);
|
|
COMPARE_SUB(p2->val, p3->val);
|
|
*r1 = p2->val - p3->val;
|
|
|
|
return 1;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
IMPL_START(mul) { SRCP(p2); SRCP(p3); *r1 = p2->val * p3->val; return 1; }
|
|
IMPL_START(rem) { SRCP(p2); SRCP(p3); *r1 = p2->val % p3->val; return 1; }
|
|
|
|
IMPL_START(div)
|
|
{
|
|
SRCP(p2);
|
|
SRCP(p3);
|
|
|
|
if (!p3->val)
|
|
_except(E_DIV, "DIV by 0");
|
|
*r1 = p2->val / p3->val;
|
|
|
|
return 1;
|
|
}
|
|
|
|
IMPL_START(idiv)
|
|
{
|
|
SRCP(p2);
|
|
SRCP(p3);
|
|
|
|
if (!p3->val)
|
|
_except(E_DIV, "IDIV by 0");
|
|
|
|
*r1 = (ulong)((long)p2->val/(long)p3->val);
|
|
|
|
return 1;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
static void __unsigned_multiply128(ulong u, ulong v, ulong *hi, ulong *lo)
|
|
{
|
|
__uint128_t r = (__uint128_t)u * (__uint128_t)v;
|
|
|
|
*hi = r >> 64;
|
|
*lo = r;
|
|
}
|
|
|
|
IMPL_START(mulhi)
|
|
{
|
|
SRCP(p2);
|
|
SRCP(p3);
|
|
|
|
__unsigned_multiply128(p2->val, p3->val, r1, r2);
|
|
return 2;
|
|
}
|
|
|
|
IMPL_START(mulf)
|
|
{
|
|
SRCP(p2);
|
|
SRCP(p3);
|
|
|
|
ulong tmp;
|
|
__unsigned_multiply128(p2->val, p3->val, &tmp, r1);
|
|
R(RFX) = p2->val ? (R(RFX)|CF|OF) : R(RFX)&~(CF|OF);
|
|
|
|
return 1;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
static void __signed_multiply128(ulong u, ulong v, ulong *hi, ulong *lo)
|
|
{
|
|
__int128_t r = (__int128_t)(long)u * (__int128_t)(long)v;
|
|
|
|
*hi = r >> 64;
|
|
*lo = r;
|
|
}
|
|
|
|
IMPL_START(imulhi)
|
|
{
|
|
SRCP(p2);
|
|
SRCP(p3);
|
|
|
|
__signed_multiply128(p2->val, p3->val, r1, r2);
|
|
return 2;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|