// 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_3(or) { v1 = v2 | v3; } IMPL_OUT; IMPL_START_3(and) { v1 = v2 & v3; } IMPL_OUT; IMPL_START_3(xor) { v1 = v2 ^ v3; } IMPL_OUT; //----------------------------------------------------------------------------// IMPL_START_3(shl) { v1 = v2 << v3; } IMPL_OUT; IMPL_START_3(shr) { v1 = v2 >> v3; } IMPL_OUT; IMPL_START_3(sal) { v1 = (ulong)((long)v2 << (long)v3); } IMPL_OUT; IMPL_START_3(sar) { v1 = (ulong)((long)v2 >> (long)v3); } IMPL_OUT; //----------------------------------------------------------------------------// IMPL_START_3(add) { v1 = v2 + v3; } IMPL_OUT; IMPL_START_3(addf) { COMPARE_ADD(v2, v3); v1 = v2 + v3; } IMPL_OUT; //----------------------------------------------------------------------------// IMPL_START_2(cmp) { COMPARE_SUB(v1, v2); } IMPL_END; IMPL_START_3(sub) { v1 = v2 - v3; } IMPL_OUT; IMPL_START_3(subf){ COMPARE_SUB(v2, v3); v1 = v2 - v3; } IMPL_OUT; //----------------------------------------------------------------------------// IMPL_START_3(adcx) { v3 += !!(R(RFX)&CF); COMPARE_ADD(v2, v3); v1 = v2 + v3; } IMPL_OUT; IMPL_START_3(sbbx) { v3 += !!(R(RFX)&CF); COMPARE_SUB(v2, v3); v1 = v2 - v3; } IMPL_OUT; //----------------------------------------------------------------------------// IMPL_START_3(mul) { v1 = v2 * v3; } IMPL_OUT; IMPL_START_3(rem) { v1 = v2 % v3; } IMPL_OUT; IMPL_START_3(div) { if (!v3) _except(ctx, E_DIV, "DIV by 0"); v1 = v2 / v3; } IMPL_OUT; IMPL_START_3(idiv) { if (!v3) _except(ctx, E_DIV, "IDIV by 0"); v1 = (ulong)((long)v2/(long)v3); } IMPL_OUT; //----------------------------------------------------------------------------// 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_3(mulhi) { __unsigned_multiply128(v2, v3, &v1, &v2); } IMPL_OUT_2; IMPL_START_3(mulf) { ulong tmp; __unsigned_multiply128(v2, v3, &tmp, &v1); R(RFX) = v2 ? (R(RFX)|CF|OF) : R(RFX)&~(CF|OF); } IMPL_OUT; //----------------------------------------------------------------------------// 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_3(imulhi) { __signed_multiply128(v2, v3, &v1, &v2); } IMPL_OUT_2; //----------------------------------------------------------------------------//