1
0
mirror of https://gitlab.os-k.eu/os-k-team/kvisc.git synced 2023-08-25 14:05:46 +02:00
This commit is contained in:
julianb0 2019-07-04 18:41:05 +02:00
parent 16a46dd8e7
commit 108faf9269
No known key found for this signature in database
GPG Key ID: 9C7ACF0C053FB8A1
11 changed files with 153 additions and 66 deletions

View File

@ -38,7 +38,7 @@ ltostr:
sgn rx8, ax1 ; extract ax1 sign
cmp rx8, -1 ; negative?
neg.z ax1
neg.z ax1, ax1
; main loop
.conv:

View File

@ -147,7 +147,7 @@ strtoq:
ret.z
; yes
neg rax
neg rax, rax
ret
.bad:

View File

@ -36,14 +36,14 @@ sgnf rm rim
#
# Arithmetical NEG operation
#
# $1 = NOT($1) + 1
# $1 = NOT($2) + 1
#
# Sets CF if $1 == 0; clears it otherwise
# Sets OF if $1 == $LONG_MIN; clears it otherwise
# Sets CF if $2 == 0; clears it otherwise
# Sets OF if $2 == $LONG_MIN; clears it otherwise
# Sets ZF and SF according to the result
#
neg rm
negf rm
neg rm rim
negf rm rim
#
# Arithmetical INC operation
@ -81,6 +81,17 @@ decf rm
add rm rim
addf rm rim
#
# Atomic exchange and add (XADD)
#
# $tmp = $1
# $1 = $1 + $2
# $2 = $1
#
# Preserves all flags
#
xadd rm rm
#
# Arithmetical ADD operation, with carry
#
@ -116,6 +127,18 @@ subf rm rim
mul rm rim
mulf rm rim
#
# Arithmetical unsigned 128-bit MUL operation
#
# $1 = HI($2 * $3)
# $2 = LO($2 * $3)
#
# Sets CF and OF if HI($2 * $3) > 0, clears them otherwise
# Preserves ZF and SF
#
mulx rm rm rim
mulfx rm rm rim
#
# Arithmetical unsigned DIV operation
#
@ -125,6 +148,16 @@ mulf rm rim
#
div rm rim
#
# Arithmetical unsigned combined DIV and MOD operations
#
# $1 = ($2 MOD $3)
# $2 = ($2 DIV $3)
#
# Preserves all flags
#
divx rm rm rim
#
# Arithmetical unsigned modulo operation (REM)
#
@ -134,25 +167,3 @@ div rm rim
#
rem rm rim
#
# Arithmetical unsigned 128-bit MUL operation
#
# RDX = HI(RAX * $1)
# RAX = LO(RAX * $1)
#
# Sets CF and OF if HI($1 * $2) > 0, clears them otherwise
# Preserves ZF and SF
#
mul2 rim
mul2f rim
#
# Arithmetical unsigned combined DIV and MOD operations
#
# RDX = (RAX MOD $1)
# RAX = (RAX DIV $1)
#
# Preserves all flags
#
div2 rim

8
vm/in/BITMP Normal file
View File

@ -0,0 +1,8 @@
# The OS/K Team licenses this file to you under the MIT license.
# See the LICENSE file in the project root for more information.
#---------------------------------------------------------------------------#
# Bit manipulation instructions #
#---------------------------------------------------------------------------#

View File

@ -11,6 +11,7 @@ include "JUMPS"
include "STACK"
include "FLAGS"
include "INOUT"
include "BITMP"
include "DEBUG"
include "STRING"
include "TERNARY"

View File

@ -18,11 +18,11 @@ test rim rim
#
# Bitwise NOT operation
#
# $1 = NOT($1)
# $1 = NOT($2)
#
# Preserves all flags
#
not rm
not rm rim
#
# Bitwise OR operation

View File

@ -5,11 +5,19 @@
# 3-operand instructions #
#---------------------------------------------------------------------------#
#
# 3-operand rotation (KROTd)
#
# $3 -> $2 -> $1 -> $3 (KROTL)
# $1 -> $2 -> $3 -> $1 (KROTR)
#
krotr rm rm rm
krotl rm rm rm
#
# 2-sources logical & arithmetical operations
#
# Preserves CF and OF
# Sets ZF and SF according to the result
# Preserves all flags
#
kor rm rim rim
kand rm rim rim
@ -22,6 +30,8 @@ kxnor rm rim rim
kxorn rm rim rim
kshl rm rim rim
kshr rm rim rim
ksal rm rim rim
ksar rm rim rim
kadd rm rim rim
kadc rm rim rim
kado rm rim rim

View File

@ -3,7 +3,7 @@
#include <in/instrs.h>
//--------------------------------------------------------------------------
//----------------------------------------------------------------------------//
IMPL_START_2(sgn)
{
@ -18,28 +18,31 @@ IMPL_START_2(sgnf)
}
IMPL_OUT_ZSF;
IMPL_START_1(neg)
IMPL_START_2(neg)
{
v1 = ~v1 + 1;
v1 = ~v2 + 1;
}
IMPL_OUT;
IMPL_START_1(negf)
IMPL_START_2(negf)
{
if (v1 == 0) flg |= CF;
if (v2 == 0) {
flg |= CF;
flg &= ~OF;
}
else {
flg &= ~CF;
if (v1 == LONG_MIN) flg |= OF;
if (v2 == LONG_MIN) flg |= OF;
else flg &= ~OF;
}
v1 = ~v1 + 1;
v1 = ~v2 + 1;
}
IMPL_OUT_ZSF;
//--------------------------------------------------------------------------
//----------------------------------------------------------------------------//
IMPL_START_1(inc)
{
@ -71,7 +74,7 @@ IMPL_START_1(decf)
}
IMPL_OUT_ZSF;
//--------------------------------------------------------------------------
//----------------------------------------------------------------------------//
IMPL_START_2(add)
{
@ -79,6 +82,14 @@ IMPL_START_2(add)
}
IMPL_OUT;
IMPL_START_2(xadd)
{
ulong tmp = v1;
v1 += v2;
v2 = tmp;
}
IMPL_OUT_2;
IMPL_START_2(addf)
{
if (v1 + v2 < v1) flg |= OF;
@ -115,7 +126,7 @@ IMPL_START_2(adcf)
}
IMPL_OUT_ZSF;
//--------------------------------------------------------------------------
//----------------------------------------------------------------------------//
IMPL_START_2(sub)
{
@ -139,7 +150,7 @@ IMPL_START_2(cmp)
}
IMPL_END;
//--------------------------------------------------------------------------
//----------------------------------------------------------------------------//
//
// www.codeproject.com/Tips/618570/UInt-Multiplication-Squaring
@ -190,17 +201,17 @@ IMPL_START_2(mulf)
}
IMPL_OUT;
IMPL_START_1(mul2)
IMPL_START_3(mulx)
{
multiply(rax, v1, &rdx, &rax);
multiply(v2, v3, &v1, &v2);
}
IMPL_END;
IMPL_OUT_2;
IMPL_START_1(mul2f)
IMPL_START_3(mulfx)
{
multiply(rax, v1, &rdx, &rax);
multiply(v2, v3, &v1, &v2);
if (rdx > 0) {
if (v1 > 0) {
flg |= CF;
flg |= OF;
}
@ -210,9 +221,9 @@ IMPL_START_1(mul2f)
flg &= ~OF;
}
}
IMPL_END;
IMPL_OUT_2;
//--------------------------------------------------------------------------
//----------------------------------------------------------------------------//
IMPL_START_2(div)
{
@ -226,10 +237,12 @@ IMPL_START_2(rem)
}
IMPL_OUT;
IMPL_START_1(div2)
IMPL_START_3(divx)
{
rdx = rax % v1;
rax = rax / v1;
v1 = v2 % v3;
v2 = v2 / v3;
}
IMPL_END;
IMPL_OUT_2;
//----------------------------------------------------------------------------//

0
vm/in/bitmp.c Normal file
View File

View File

@ -3,13 +3,15 @@
#include <in/instrs.h>
IMPL_START_1(not)
//----------------------------------------------------------------------------//
IMPL_START_2(not)
{
v1 = ~v1;
v1 = ~v2;
}
IMPL_OUT;
//--------------------------------------------------------------------------
//----------------------------------------------------------------------------//
IMPL_START_2(test)
{
@ -33,7 +35,7 @@ IMPL_START_2(andf)
}
IMPL_OUT_ZSF;
//--------------------------------------------------------------------------
//----------------------------------------------------------------------------//
IMPL_START_2(or)
{
@ -63,7 +65,7 @@ IMPL_START_2(xorf)
}
IMPL_OUT_ZSF;
//--------------------------------------------------------------------------
//----------------------------------------------------------------------------//
IMPL_START_2(shl)
{
@ -135,5 +137,5 @@ IMPL_START_2(sarf)
}
IMPL_OUT_ZSF;
//--------------------------------------------------------------------------
//----------------------------------------------------------------------------//

View File

@ -5,23 +5,43 @@
//----------------------------------------------------------------------------//
IMPL_START_3(krotl)
{
ulong tmp = v1;
v1 = v2;
v2 = v3;
v3 = tmp;
}
IMPL_OUT_3;
IMPL_START_3(krotr)
{
ulong tmp = v3;
v3 = v2;
v2 = v1;
v1 = tmp;
}
IMPL_OUT_3;
//----------------------------------------------------------------------------//
#define K_IMPL_ALU(name, expr) \
IMPL_START_3(k##name) \
{ \
v1 = (expr); \
} \
IMPL_OUT_ZSF
IMPL_OUT
K_IMPL_ALU(or, v2 | v3);
K_IMPL_ALU(and, v2 & v3);
K_IMPL_ALU(xor, v2 ^ v3);
K_IMPL_ALU(nor, ~(v2 | v3));
K_IMPL_ALU(orn, ~v2 | v3);
K_IMPL_ALU(orn, v2 | ~v3);
K_IMPL_ALU(nand, ~(v2 & v3));
K_IMPL_ALU(andn, ~v2 & v3);
K_IMPL_ALU(andn, v2 & ~v3);
K_IMPL_ALU(xnor, ~(v2 ^ v3));
K_IMPL_ALU(xorn, ~v2 ^ v3);
K_IMPL_ALU(xorn, v2 ^ ~v3);
K_IMPL_ALU(shl, v2 << v3);
K_IMPL_ALU(shr, v2 >> v3);
@ -38,3 +58,25 @@ K_IMPL_ALU(rem, v2 % v3);
//----------------------------------------------------------------------------//
IMPL_START_3(ksal)
{
long w2 = v2;
long w3 = v3;
w2 <<= w3;
v1 = (ulong)w2;
}
IMPL_OUT;
IMPL_START_3(ksar)
{
long w2 = v2;
long w3 = v3;
w2 >>= w3;
v1 = (ulong)w2;
}
IMPL_OUT;
//----------------------------------------------------------------------------//