Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions asm_lib/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <Windows.h>
#include <iostream>
#include <conio.h>

#include "asm_math.hpp"

int main()
{
getchar();
int main() {
(void)_getch();
return 0;
}
8 changes: 7 additions & 1 deletion asm_lib/asm_lib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.props" />
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
Expand Down Expand Up @@ -132,6 +133,8 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -141,13 +144,16 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="asm_math.cpp" />
<ClCompile Include="Source.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="asm_math.hpp" />
</ItemGroup>
<ItemGroup>
<MASM Include="asm_math.asm" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
</ImportGroup>
</Project>
8 changes: 5 additions & 3 deletions asm_lib/asm_lib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
<ClCompile Include="Source.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="asm_math.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="asm_math.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<MASM Include="asm_math.asm">
<Filter>Source Files</Filter>
</MASM>
</ItemGroup>
</Project>
124 changes: 124 additions & 0 deletions asm_lib/asm_math.asm
Original file line number Diff line number Diff line change
@@ -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
109 changes: 0 additions & 109 deletions asm_lib/asm_math.cpp

This file was deleted.

31 changes: 12 additions & 19 deletions asm_lib/asm_math.hpp
Original file line number Diff line number Diff line change
@@ -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);
}