Procházet zdrojové kódy

advanced instructions (AVX, RDRAND)

master
aaaaaa aaaaaaa před 7 roky
rodič
revize
d350a8ed80
5 změnil soubory, kde provedl 53 přidání a 1 odebrání
  1. +17
    -0
      hook_tests/advanced_instructions.asm
  2. +15
    -0
      hook_tests/advanced_instructions.h
  3. +3
    -0
      hook_tests/hook_tests.vcxproj
  4. +7
    -0
      hook_tests/hook_tests.vcxproj.filters
  5. +11
    -1
      hook_tests/main.cpp

+ 17
- 0
hook_tests/advanced_instructions.asm Zobrazit soubor

@@ -0,0 +1,17 @@
format ms64 coff

section '.text' code readable executable

use64

public _AVX
_AVX:
vbroadcastsd ymm0, xmm0 ; load @num into all slots
vsqrtpd ymm0, ymm0
vmovdqu [rdx], ymm0 ; store result in @res
ret

public _RDRAND
_RDRAND:
rdrand eax
ret

+ 15
- 0
hook_tests/advanced_instructions.h Zobrazit soubor

@@ -0,0 +1,15 @@
#pragma once
extern "C" {
/**
* Gets the square root of num four times and writes it to @res
*
* @param num: the number of which the square root shall be taken
* @param res: where the 4 results shall be written
*/
void _AVX(float num, void* res);

/**
* Just a wrapper around RDRAND
*/
uint32_t _RDRAND(void);
}

+ 3
- 0
hook_tests/hook_tests.vcxproj Zobrazit soubor

@@ -146,6 +146,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="advanced_instructions.h" />
<ClInclude Include="catch.hpp" />
<ClInclude Include="simple_tests.h" />
</ItemGroup>
@@ -153,10 +154,12 @@
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="advanced_instructions.asm" />
<None Include="README.md" />
<None Include="simple_tests.asm" />
</ItemGroup>
<ItemGroup>
<Object Include="advanced_instructions.obj" />
<Object Include="simple_tests.obj" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

+ 7
- 0
hook_tests/hook_tests.vcxproj.filters Zobrazit soubor

@@ -21,6 +21,9 @@
<ClInclude Include="simple_tests.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="advanced_instructions.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
@@ -32,8 +35,12 @@
<Filter>Source Files</Filter>
</None>
<None Include="README.md" />
<None Include="advanced_instructions.asm">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Object Include="simple_tests.obj" />
<Object Include="advanced_instructions.obj" />
</ItemGroup>
</Project>

+ 11
- 1
hook_tests/main.cpp Zobrazit soubor

@@ -4,8 +4,9 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "simple_tests.h"
#include "advanced_instructions.h"

TEST_CASE("Functions work as expected, unhooked") {
TEST_CASE("Simple functions work as expected, unhooked") {
REQUIRE(_small() == 0);

REQUIRE(_branch(1) == 0);
@@ -14,4 +15,13 @@ TEST_CASE("Functions work as expected, unhooked") {
for (int i = 0; i < 1000; i++) {
REQUIRE(_rip_relative() == rand());
}
}

TEST_CASE("Advanced instruction functions work as expected, unhokked") {
double result[4];
_AVX(9., static_cast<void*>(result));
REQUIRE((result[0] - result[1]) < DBL_EPSILON);
REQUIRE((result[1] - result[2]) < DBL_EPSILON);
REQUIRE((result[2] - result[3]) < DBL_EPSILON);
REQUIRE((result[0] - 3.) < DBL_EPSILON);
}

Načítá se…
Zrušit
Uložit