diff --git a/asm_lib/Source.cpp b/asm_lib/Source.cpp index 156d095..55ac962 100644 --- a/asm_lib/Source.cpp +++ b/asm_lib/Source.cpp @@ -1,9 +1,10 @@ #include #include +#include + #include "asm_math.hpp" -int main() -{ - getchar(); +int main() { + (void)_getch(); return 0; } \ No newline at end of file diff --git a/asm_lib/asm_lib.vcxproj b/asm_lib/asm_lib.vcxproj index 4c628b0..76d1ecf 100644 --- a/asm_lib/asm_lib.vcxproj +++ b/asm_lib/asm_lib.vcxproj @@ -55,6 +55,7 @@ + @@ -132,6 +133,8 @@ true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + stdcpp20 + stdc17 Console @@ -141,13 +144,16 @@ - + + + + \ No newline at end of file diff --git a/asm_lib/asm_lib.vcxproj.filters b/asm_lib/asm_lib.vcxproj.filters index 0b24f95..f6289d8 100644 --- a/asm_lib/asm_lib.vcxproj.filters +++ b/asm_lib/asm_lib.vcxproj.filters @@ -18,13 +18,15 @@ Source Files - - Source Files - Header Files + + + Source Files + + \ No newline at end of file diff --git a/asm_lib/asm_math.asm b/asm_lib/asm_math.asm new file mode 100644 index 0000000..819d462 --- /dev/null +++ b/asm_lib/asm_math.asm @@ -0,0 +1,124 @@ +.code + +abs proc + sub rsp, 16 + + movups [rsp], xmm0 + + fld dword ptr [rsp] + + fabs + + fstp dword ptr [rsp] + + mov rax, [rsp] + + add rsp, 16 + ret +abs endp + +modulo proc + sub rsp, 32 + + movups dword ptr [rsp], xmm0 + movups dword ptr [rsp+16], xmm1 + + fld dword ptr [rsp+16] + fld dword ptr [rsp] + + fprem + + fstp dword ptr [rsp] + fstp ST(0) + + movups xmm0, dword ptr [rsp] + + add rsp, 32 + + ret +modulo endp + +ceil proc + vroundss xmm0, xmm0, xmm0, 2h + ret +ceil endp + +floor proc + vroundss xmm0, xmm0, xmm0, 1h + ret +floor endp + +round proc + vroundss xmm0, xmm0, xmm0, 0h + ret +round endp + +sqrt proc + vsqrtss xmm0, xmm0, xmm0 + ret +sqrt endp + +pow proc + mov rcx, rdx + dec rcx + movss xmm1, xmm0 + asm_loop: + mulss xmm0, xmm1 + loop asm_loop + ret +pow endp + +sin proc + sub rsp, 16 + movups dword ptr [rsp], xmm0 + fld dword ptr [rsp] + fsin + fstp dword ptr [rsp] + movups xmm0, [rsp] + add rsp, 16 + ret +sin endp + +cos proc + sub rsp, 16 + movups dword ptr [rsp], xmm0 + fld dword ptr [rsp] + fcos + fstp dword ptr [rsp] + movups xmm0, [rsp] + add rsp, 16 + ret +cos endp + +tan proc + sub rsp, 16 + movups dword ptr [rsp], xmm0 + fld dword ptr [rsp] + fptan + fstp ST(0) + fstp dword ptr [rsp] + movups xmm0, [rsp] + add rsp, 16 + ret +tan endp + +atan proc + sub rsp, 16 + + movups dword ptr [rsp], xmm0 + + fld1 + fld dword ptr [rsp] + + fpatan + + fstp dword ptr [rsp] + fstp ST(0) + + movups xmm0, [rsp] + + add rsp, 16 + ret +atan endp + +end diff --git a/asm_lib/asm_math.cpp b/asm_lib/asm_math.cpp deleted file mode 100644 index 72eca80..0000000 --- a/asm_lib/asm_math.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include "asm_math.hpp" - -float asm_math::asm_abs(float x) -{ - __asm - { - fld x - fabs - fstp x - } - return x; -} - -float asm_math::asm_mod(float x, float y) -{ - __asm - { - fld y - fld x - fprem - fstp x - fstp y - } - return x; -} - -float asm_math::asm_floor(float x) -{ - __asm - { - fld x - frndint - fstp x - } - return x; -} - -float asm_math::asm_sqrt(float x) -{ - __asm - { - fld x - fsqrt - fstp x - } - return x; -} - -float asm_math::asm_pow(float x, int y) -{ - __asm - { - mov eax, y - fld x - - asm_loop: - fmul x - dec eax - cmp eax, 1 - jne asm_loop - - fstp x - } - return x; -} - -float asm_math::asm_sin(float x) -{ - __asm - { - fld x - fsin - fstp x - } - return x; -} - -float asm_math::asm_cos(float x) -{ - __asm - { - fld x - fcos - fstp x - } - return x; -} - -float asm_math::asm_tan(float x) -{ - __asm - { - fld x - fptan - fstp x - } - return x; -} - -float asm_math::asm_atan(float x) -{ - __asm - { - fld x - fpatan - fstp x - } - return x; -} diff --git a/asm_lib/asm_math.hpp b/asm_lib/asm_math.hpp index 21d9cbe..1e71880 100644 --- a/asm_lib/asm_math.hpp +++ b/asm_lib/asm_math.hpp @@ -1,22 +1,15 @@ #pragma once -namespace asm_math -{ - float asm_abs(float x); - - float asm_mod(float x, float y); - - float asm_floor(float x); - - float asm_sqrt(float x); - - float asm_pow(float x, int y); - - float asm_sin(float x); - - float asm_cos(float x); - - float asm_tan(float x); - - float asm_atan(float x); +extern "C" namespace asm_math { + int abs(float x); + double modulo(float x, float y); + double ceil(float x); + double floor(float x); + double round(float x); + double sqrt(float x); + double pow(float x, int y); + double sin(float x); + double cos(float x); + double tan(float x); + double atan(float x); } \ No newline at end of file