2019-05-30 12:44:56 +02:00
|
|
|
// The OS/K Team licenses this file to you under the MIT license.
|
2019-05-29 16:57:22 +02:00
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
2019-06-05 12:53:09 +02:00
|
|
|
#include <in/instrs.h>
|
2019-05-29 16:57:22 +02:00
|
|
|
|
2019-06-06 22:07:34 +02:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
2019-06-07 13:38:34 +02:00
|
|
|
IMPL_START_2(sgn)
|
|
|
|
{
|
2019-06-13 22:20:35 +02:00
|
|
|
v1 = (v2 == 0 ? 0 :
|
|
|
|
((long)v2 < 0 ? (ulong)-1L : 1));
|
2019-06-07 13:38:34 +02:00
|
|
|
}
|
2019-06-12 15:30:35 +02:00
|
|
|
IMPL_OUT;
|
|
|
|
|
|
|
|
IMPL_START_2(sgnf)
|
|
|
|
{
|
|
|
|
v1 = (long)v2 < 0 ? (ulong)-1L : 1;
|
|
|
|
}
|
2019-06-07 13:38:34 +02:00
|
|
|
IMPL_OUT_ZSF;
|
|
|
|
|
|
|
|
IMPL_START_1(neg)
|
2019-06-12 15:30:35 +02:00
|
|
|
{
|
|
|
|
v1 = ~v1 + 1;
|
|
|
|
}
|
|
|
|
IMPL_OUT;
|
|
|
|
|
|
|
|
IMPL_START_1(negf)
|
2019-06-07 13:38:34 +02:00
|
|
|
{
|
|
|
|
if (v1 == 0) flg |= CF;
|
|
|
|
|
|
|
|
else {
|
|
|
|
flg &= ~CF;
|
|
|
|
|
|
|
|
if (v1 == LONG_MIN) flg |= OF;
|
|
|
|
else flg &= ~OF;
|
|
|
|
}
|
|
|
|
|
|
|
|
v1 = ~v1 + 1;
|
|
|
|
}
|
|
|
|
IMPL_OUT_ZSF;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
2019-06-06 22:07:34 +02:00
|
|
|
IMPL_START_1(inc)
|
2019-06-12 15:30:35 +02:00
|
|
|
{
|
|
|
|
v1++;
|
|
|
|
}
|
|
|
|
IMPL_OUT;
|
|
|
|
|
|
|
|
IMPL_START_1(incf)
|
2019-06-06 22:07:34 +02:00
|
|
|
{
|
|
|
|
if (v1 == LONG_MAX) flg |= OF;
|
|
|
|
else flg &= ~OF;
|
|
|
|
|
|
|
|
v1++;
|
|
|
|
}
|
|
|
|
IMPL_OUT_ZSF;
|
|
|
|
|
|
|
|
IMPL_START_1(dec)
|
2019-06-12 15:30:35 +02:00
|
|
|
{
|
|
|
|
v1--;
|
|
|
|
}
|
|
|
|
IMPL_OUT;
|
|
|
|
|
|
|
|
IMPL_START_1(decf)
|
2019-06-06 22:07:34 +02:00
|
|
|
{
|
|
|
|
if (v1 == LONG_MIN) flg |= OF;
|
|
|
|
else flg &= ~OF;
|
|
|
|
|
|
|
|
v1--;
|
|
|
|
}
|
|
|
|
IMPL_OUT_ZSF;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
2019-05-29 16:57:22 +02:00
|
|
|
|
|
|
|
IMPL_START_2(add)
|
2019-06-12 15:30:35 +02:00
|
|
|
{
|
|
|
|
v1 += v2;
|
|
|
|
}
|
|
|
|
IMPL_OUT;
|
|
|
|
|
|
|
|
IMPL_START_2(addf)
|
2019-05-29 16:57:22 +02:00
|
|
|
{
|
2019-06-06 22:07:34 +02:00
|
|
|
if (v1 + v2 < v1) flg |= OF;
|
|
|
|
else flg &= ~OF;
|
|
|
|
|
|
|
|
if ( ((v2 > 0) && (v1 > LONG_MAX - v2))
|
|
|
|
|| ((v2 < 0) && (v1 < LONG_MIN - v2)) )
|
|
|
|
flg |= CF;
|
|
|
|
else flg &= ~CF;
|
|
|
|
|
2019-05-29 16:57:22 +02:00
|
|
|
v1 += v2;
|
|
|
|
}
|
2019-06-06 22:07:34 +02:00
|
|
|
IMPL_OUT_ZSF;
|
2019-05-29 16:57:22 +02:00
|
|
|
|
|
|
|
IMPL_START_2(sub)
|
2019-06-12 15:30:35 +02:00
|
|
|
{
|
|
|
|
v1 -= v2;
|
|
|
|
}
|
|
|
|
IMPL_OUT;
|
|
|
|
|
|
|
|
IMPL_START_2(subf)
|
2019-05-29 16:57:22 +02:00
|
|
|
{
|
2019-06-13 15:47:20 +02:00
|
|
|
COMPARE(v1, v2);
|
2019-05-29 16:57:22 +02:00
|
|
|
v1 -= v2;
|
|
|
|
}
|
2019-06-13 15:47:20 +02:00
|
|
|
IMPL_OUT;
|
2019-06-06 22:07:34 +02:00
|
|
|
|
|
|
|
//
|
2019-06-12 15:30:35 +02:00
|
|
|
// i_subf but discards result
|
2019-06-06 22:07:34 +02:00
|
|
|
//
|
|
|
|
IMPL_START_2(cmp)
|
|
|
|
{
|
2019-06-13 15:47:20 +02:00
|
|
|
COMPARE(v1, v2);
|
2019-06-06 22:07:34 +02:00
|
|
|
}
|
|
|
|
IMPL_END;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
2019-05-29 16:57:22 +02:00
|
|
|
|
2019-06-07 13:38:34 +02:00
|
|
|
//
|
|
|
|
// www.codeproject.com/Tips/618570/UInt-Multiplication-Squaring
|
|
|
|
//
|
|
|
|
static void multiply(ulong u, ulong v, ulong *hi, ulong *lo)
|
|
|
|
{
|
|
|
|
ulong u1 = (u & 0xffffffff);
|
|
|
|
ulong v1 = (v & 0xffffffff);
|
|
|
|
ulong t = (u1 * v1);
|
|
|
|
ulong w3 = (t & 0xffffffff);
|
|
|
|
ulong k = (t >> 32);
|
|
|
|
|
|
|
|
u >>= 32;
|
|
|
|
t = (u * v1) + k;
|
|
|
|
k = (t & 0xffffffff);
|
|
|
|
ulong w1 = (t >> 32);
|
|
|
|
|
|
|
|
v >>= 32;
|
|
|
|
t = (u1 * v) + k;
|
|
|
|
k = (t >> 32);
|
|
|
|
|
|
|
|
*hi = (u * v) + w1 + k;
|
|
|
|
*lo = (t << 32) + w3;
|
|
|
|
}
|
|
|
|
|
2019-06-05 22:11:45 +02:00
|
|
|
IMPL_START_2(mul)
|
2019-06-12 15:30:35 +02:00
|
|
|
{
|
|
|
|
ulong hi;
|
|
|
|
multiply(v1, v2, &hi, &v1);
|
|
|
|
}
|
|
|
|
IMPL_OUT;
|
|
|
|
|
|
|
|
IMPL_START_2(mulf)
|
2019-06-05 22:11:45 +02:00
|
|
|
{
|
2019-06-07 13:38:34 +02:00
|
|
|
ulong hi;
|
|
|
|
|
|
|
|
multiply(v1, v2, &hi, &v1);
|
|
|
|
|
|
|
|
if (hi > 0) {
|
|
|
|
flg |= CF;
|
|
|
|
flg |= OF;
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
flg &= ~CF;
|
|
|
|
flg &= ~OF;
|
|
|
|
}
|
2019-06-05 22:11:45 +02:00
|
|
|
}
|
|
|
|
IMPL_OUT;
|
|
|
|
|
|
|
|
IMPL_START_1(mul2)
|
2019-06-12 15:30:35 +02:00
|
|
|
{
|
|
|
|
multiply(rax, v1, &rdx, &rax);
|
|
|
|
}
|
|
|
|
IMPL_END;
|
|
|
|
|
|
|
|
IMPL_START_1(mul2f)
|
2019-05-29 16:57:22 +02:00
|
|
|
{
|
2019-06-07 13:38:34 +02:00
|
|
|
multiply(rax, v1, &rdx, &rax);
|
2019-05-29 16:57:22 +02:00
|
|
|
|
2019-06-07 13:38:34 +02:00
|
|
|
if (rdx > 0) {
|
|
|
|
flg |= CF;
|
|
|
|
flg |= OF;
|
|
|
|
}
|
2019-05-30 12:44:56 +02:00
|
|
|
|
2019-06-07 13:38:34 +02:00
|
|
|
else {
|
|
|
|
flg &= ~CF;
|
|
|
|
flg &= ~OF;
|
|
|
|
}
|
2019-05-29 16:57:22 +02:00
|
|
|
}
|
|
|
|
IMPL_END;
|
|
|
|
|
2019-06-06 22:07:34 +02:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
2019-06-05 22:11:45 +02:00
|
|
|
IMPL_START_2(div)
|
|
|
|
{
|
|
|
|
v1 /= v2;
|
|
|
|
}
|
|
|
|
IMPL_OUT;
|
|
|
|
|
|
|
|
IMPL_START_2(mod)
|
|
|
|
{
|
|
|
|
v1 %= v2;
|
|
|
|
}
|
|
|
|
IMPL_OUT;
|
|
|
|
|
|
|
|
IMPL_START_1(div2)
|
2019-05-29 16:57:22 +02:00
|
|
|
{
|
2019-06-02 16:33:28 +02:00
|
|
|
rdx = rax % v1;
|
|
|
|
rax = rax / v1;
|
2019-05-29 16:57:22 +02:00
|
|
|
}
|
|
|
|
IMPL_END;
|
|
|
|
|