// 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 #define _NEED_ARCH_I #include //----------------------------------------------------------------------------// 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; } //----------------------------------------------------------------------------// 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; } //----------------------------------------------------------------------------// 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; } 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; } 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); p3->val += !!(R(RFX)&CF); COMPARE_ADD(p2->val, p3->val); *r1 = p2->val + p3->val; return 1; } 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); p3->val += !!(R(RFX)&CF); COMPARE_SUB(p2->val, p3->val); *r1 = p2->val - p3->val; return 1; } //----------------------------------------------------------------------------// 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; } 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; } IMPL_START(div, 3) { SRCP(p2); SRCP(p3); if (!p3->val) _except(E_DIV, "DIV by 0"); *r1 = p2->val / p3->val; return 1; } 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; } IMPL_START(idiv, 3) { 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, 3) { SRCP(p2); SRCP(p3); __unsigned_multiply128(p2->val, p3->val, r1, r2); return 2; } IMPL_START(mulf, 3) { 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, 3) { SRCP(p2); SRCP(p3); __signed_multiply128(p2->val, p3->val, r1, r2); return 2; } //----------------------------------------------------------------------------//