2019-07-17 20:26:03 +02:00
|
|
|
// 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
|
2019-07-18 22:49:31 +02:00
|
|
|
#include <ob/arch_i.h>
|
2019-07-17 20:26:03 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
IMPL_START(or, 2) { SRCP(p1); SRCP(p2); *r1 = p1->val | p2->val; return 1; }
|
|
|
|
IMPL_START(and, 2) { SRCP(p1); SRCP(p2); *r1 = p1->val & p2->val; return 1; }
|
|
|
|
IMPL_START(xor, 2) { SRCP(p1); SRCP(p2); *r1 = p1->val ^ p2->val; return 1; }
|
|
|
|
|
|
|
|
IMPL_START(or, 3) { SRCP(p2); SRCP(p3); *r1 = p2->val | p3->val; return 1; }
|
|
|
|
IMPL_START(and, 3) { SRCP(p2); SRCP(p3); *r1 = p2->val & p3->val; return 1; }
|
|
|
|
IMPL_START(xor, 3) { SRCP(p2); SRCP(p3); *r1 = p2->val ^ p3->val; return 1; }
|
2019-07-17 20:26:03 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
IMPL_START(shl, 2) { SRCP(p1); SRCP(p2); *r1 = p1->val << p2->val; return 1; }
|
|
|
|
IMPL_START(shr, 2) { SRCP(p1); SRCP(p2); *r1 = p1->val >> p2->val; return 1; }
|
|
|
|
IMPL_START(sar, 2) { SRCP(p1); SRCP(p2); *r1 = (ulong)((long)p1->val >> (long)p2->val); return 1; }
|
|
|
|
|
|
|
|
IMPL_START(shl, 3) { SRCP(p2); SRCP(p3); *r1 = p2->val << p3->val; return 1; }
|
|
|
|
IMPL_START(shr, 3) { SRCP(p2); SRCP(p3); *r1 = p2->val >> p3->val; return 1; }
|
|
|
|
IMPL_START(sar, 3) { SRCP(p2); SRCP(p3); *r1 = (ulong)((long)p2->val >> (long)p3->val); return 1; }
|
2019-07-17 20:26:03 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
IMPL_START(add, 2) { SRCP(p1); SRCP(p2); *r1 = p1->val + p2->val; return 1; }
|
|
|
|
IMPL_START(add, 3) { SRCP(p2); SRCP(p3); *r1 = p2->val + p3->val; return 1; }
|
|
|
|
IMPL_START(addf, 3) { SRCP(p2); SRCP(p3); COMPARE_ADD(p2->val, p3->val); *r1 = p2->val + p3->val; return 1; }
|
2019-07-17 20:26:03 +02:00
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
IMPL_START(sub, 2) { SRCP(p1); SRCP(p2); *r1 = p1->val - p2->val; return 1; }
|
|
|
|
IMPL_START(sub, 3) { SRCP(p2); SRCP(p3); *r1 = p2->val - p3->val; return 1; }
|
|
|
|
IMPL_START(subf, 3) { SRCP(p2); SRCP(p3); COMPARE_SUB(p2->val, p3->val); *r1 = p2->val - p3->val; return 1; }
|
2019-07-17 20:26:03 +02:00
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
IMPL_START(adcx, 2) {
|
|
|
|
SRCP(p1); SRCP(p2);
|
|
|
|
|
|
|
|
p2->val += !!(R(RFX)&CF);
|
|
|
|
COMPARE_ADD(p1->val, p2->val);
|
|
|
|
*r1 = p1->val + p2->val;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_START(adcx, 3) {
|
|
|
|
SRCP(p2); SRCP(p3);
|
2019-08-03 17:41:44 +02:00
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
p3->val += !!(R(RFX)&CF);
|
|
|
|
COMPARE_ADD(p2->val, p3->val);
|
|
|
|
*r1 = p2->val + p3->val;
|
2019-07-17 20:26:03 +02:00
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
IMPL_START(sbbx, 2) {
|
|
|
|
SRCP(p1); SRCP(p2);
|
|
|
|
|
|
|
|
p2->val += !!(R(RFX)&CF);
|
|
|
|
COMPARE_SUB(p1->val, p2->val);
|
|
|
|
*r1 = p1->val - p2->val;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_START(sbbx, 3) {
|
|
|
|
SRCP(p2); SRCP(p3);
|
2019-08-03 17:41:44 +02:00
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
p3->val += !!(R(RFX)&CF);
|
|
|
|
COMPARE_SUB(p2->val, p3->val);
|
|
|
|
*r1 = p2->val - p3->val;
|
2019-07-17 20:26:03 +02:00
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2019-07-17 20:26:03 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
IMPL_START(mul, 2) { SRCP(p1); SRCP(p2); *r1 = p1->val * p2->val; return 1; }
|
|
|
|
IMPL_START(mul, 3) { SRCP(p2); SRCP(p3); *r1 = p2->val * p3->val; return 1; }
|
2019-07-24 16:52:26 +02:00
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
IMPL_START(rem, 2) { SRCP(p1); SRCP(p2); *r1 = p1->val % p2->val; return 1; }
|
|
|
|
IMPL_START(rem, 3) { SRCP(p2); SRCP(p3); *r1 = p2->val % p3->val; return 1; }
|
|
|
|
|
|
|
|
IMPL_START(div, 2) {
|
|
|
|
SRCP(p1); SRCP(p2);
|
|
|
|
|
|
|
|
if (!p2->val) _except(E_DIV, "DIV by 0");
|
|
|
|
*r1 = p1->val / p2->val;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2019-08-03 17:41:44 +02:00
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
IMPL_START(div, 3) {
|
|
|
|
SRCP(p2); SRCP(p3);
|
|
|
|
|
|
|
|
if (!p3->val) _except(E_DIV, "DIV by 0");
|
2019-07-24 16:52:26 +02:00
|
|
|
*r1 = p2->val / p3->val;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
IMPL_START(idiv, 2) {
|
|
|
|
SRCP(p1); SRCP(p2);
|
|
|
|
|
|
|
|
if (!p3->val) _except(E_DIV, "IDIV by 0");
|
|
|
|
*r1 = (ulong)((long)p1->val/(long)p2->val);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2019-08-03 17:41:44 +02:00
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
IMPL_START(idiv, 3) {
|
|
|
|
SRCP(p2); SRCP(p3);
|
2019-07-24 16:52:26 +02:00
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
if (!p3->val) _except(E_DIV, "IDIV by 0");
|
2019-07-24 16:52:26 +02:00
|
|
|
*r1 = (ulong)((long)p2->val/(long)p3->val);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2019-07-17 20:26:03 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-07-18 22:49:31 +02:00
|
|
|
static void __unsigned_multiply128(ulong u, ulong v, ulong *hi, ulong *lo)
|
2019-07-17 20:26:03 +02:00
|
|
|
{
|
2019-07-18 22:49:31 +02:00
|
|
|
__uint128_t r = (__uint128_t)u * (__uint128_t)v;
|
|
|
|
|
|
|
|
*hi = r >> 64;
|
|
|
|
*lo = r;
|
2019-07-17 20:26:03 +02:00
|
|
|
}
|
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
IMPL_START(mulhi, 3)
|
2019-07-24 16:52:26 +02:00
|
|
|
{
|
2019-08-03 17:41:44 +02:00
|
|
|
SRCP(p2);
|
|
|
|
SRCP(p3);
|
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
__unsigned_multiply128(p2->val, p3->val, r1, r2);
|
|
|
|
return 2;
|
|
|
|
}
|
2019-07-17 20:26:03 +02:00
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
IMPL_START(mulf, 3)
|
2019-07-24 16:52:26 +02:00
|
|
|
{
|
2019-08-03 17:41:44 +02:00
|
|
|
SRCP(p2);
|
|
|
|
SRCP(p3);
|
|
|
|
|
2019-07-17 20:26:03 +02:00
|
|
|
ulong tmp;
|
2019-07-24 16:52:26 +02:00
|
|
|
__unsigned_multiply128(p2->val, p3->val, &tmp, r1);
|
|
|
|
R(RFX) = p2->val ? (R(RFX)|CF|OF) : R(RFX)&~(CF|OF);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2019-07-17 20:26:03 +02:00
|
|
|
|
2019-07-18 22:49:31 +02:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-08-08 18:39:12 +02:00
|
|
|
IMPL_START(imulhi, 3)
|
2019-07-24 16:52:26 +02:00
|
|
|
{
|
2019-08-03 17:41:44 +02:00
|
|
|
SRCP(p2);
|
|
|
|
SRCP(p3);
|
|
|
|
|
2019-07-24 16:52:26 +02:00
|
|
|
__signed_multiply128(p2->val, p3->val, r1, r2);
|
|
|
|
return 2;
|
|
|
|
}
|
2019-07-17 20:26:03 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|