Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support other architectures #56

Merged
merged 6 commits into from
Nov 23, 2021
Merged
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
5 changes: 2 additions & 3 deletions AVDump3Lib/Processing/AVD3ProcessingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public void RegisterDefaultBlockConsumers(IDictionary<string, ImmutableArray<str
addOrReplace(new BlockConsumerFactory("KECCAK-256", s => new HashCalculator(s.Name, s.Reader, new KeccakNativeHashAlgorithm(256))));
addOrReplace(new BlockConsumerFactory("KECCAK-384", s => new HashCalculator(s.Name, s.Reader, new KeccakNativeHashAlgorithm(384))));
addOrReplace(new BlockConsumerFactory("KECCAK-512", s => new HashCalculator(s.Name, s.Reader, new KeccakNativeHashAlgorithm(512))));
addOrReplace(new BlockConsumerFactory("TIGER", s => new HashCalculator(s.Name, s.Reader, new TigerNativeHashAlgorithm())));
addOrReplace(new BlockConsumerFactory("TTH", s => new HashCalculator(s.Name, s.Reader, new TigerTreeHashAlgorithm(getArgumentAt(s, 0, Math.Min(4, Environment.ProcessorCount).ToInvString()).ToInvInt32()))));

if(AvailableSIMD.HasFlag(CPUInstructions.SSE2)) {
addOrReplace(new BlockConsumerFactory("TIGER", s => new HashCalculator(s.Name, s.Reader, new TigerNativeHashAlgorithm())));
addOrReplace(new BlockConsumerFactory("TTH", s => new HashCalculator(s.Name, s.Reader, new TigerTreeHashAlgorithm(getArgumentAt(s, 0, Math.Min(4, Environment.ProcessorCount).ToInvString()).ToInvInt32()))));
addOrReplace(new BlockConsumerFactory("CRC32", s => new HashCalculator(s.Name, s.Reader, new Crc32NativeHashAlgorithm())));
}
if(AvailableSIMD.HasFlag(CPUInstructions.SSE42)) {
Expand All @@ -86,7 +86,6 @@ public void RegisterDefaultBlockConsumers(IDictionary<string, ImmutableArray<str
addOrReplace(new BlockConsumerFactory("SHA2-256", s => new HashCalculator(s.Name, s.Reader, new SHA256NativeHashAlgorithm())));
}


} catch(Exception) {
//TODO Log
}
Expand Down
12 changes: 11 additions & 1 deletion AVDump3NativeLib/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
CC=gcc
CFLAGS=-I. -Wall -Werror -fpic -O3 -lrt
OBJ = AVD3MirrorBuffer.o AVD3NativeLibApi.o InstructionCheck.o CRC32.o CRC32C.o MD4.o SHA1.o SHA3.o SHA256.o Tiger.o
OBJ = AVD3MirrorBuffer.o AVD3NativeLibApi.o InstructionCheck.o CRC32.o MD4.o SHA3.o Tiger.o

ARCH := $(shell uname -m)
$(info uname_m=$(ARCH))

SSE4_FLAGS :=
SHA_FLAGS :=

ifeq ($(ARCH),x86_64)
OBJ += SHA1.o SHA256.o CRC32C.o
OBJ_SSE4 = CRC32C.o SHA1.o SHA256.o
OBJ_SHA = SHA1.o SHA256.o

$(OBJ_SSE4): SSE4_FLAGS := -msse4
$(OBJ_SHA): SHA_FLAGS := -msha
endif

AVDump3NativeLib.so: $(OBJ)
$(CC) -shared -o $@ $^ $(CFLAGS)
Expand Down
5 changes: 4 additions & 1 deletion AVDump3NativeLib/src/AVD3NativeLibApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
#include <string.h>
#include <malloc.h>
#include <stdint.h>

#ifdef __x86_64__
#include <nmmintrin.h>
#include <immintrin.h>
#endif

#include "DLLDefines.h"

Expand Down Expand Up @@ -122,4 +125,4 @@ DLL_PUBLIC char* FreeMirrorBuffer(AVD3MirrorBufferCreateHandle* handle);

#include <byteswap.h>

#endif
#endif
14 changes: 9 additions & 5 deletions AVDump3NativeLib/src/InstructionCheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
#define cpuid(info, x) __cpuidex(info, x, 0)

#else

#ifdef __x86_64__
// GCC Intrinsics
#include <cpuid.h>

void cpuid(int info[4], int InfoType) {
__cpuid_count(InfoType, 0, info[0], info[1], info[2], info[3]);
}

#endif


uint64_t RetrieveCPUInstructions() {
// Misc.
bool HW_MMX = 0;
Expand Down Expand Up @@ -143,4 +141,10 @@ uint64_t RetrieveCPUInstructions() {
(HW_AVX512DQ ? 1 << 28 : 0) |
(HW_AVX512IFMA ? 1 << 29 : 0) |
(HW_AVX512VBMI ? 1 << 30 : 0);
}
}
#else
uint64_t RetrieveCPUInstructions() {
return 0;
}
#endif
#endif
4 changes: 3 additions & 1 deletion AVDump3NativeLib/src/Tiger.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
#include "AVD3NativeLibApi.h"
#include <assert.h>

#ifdef __x86_64__
#define CRYPTOPP_GENERATE_X64_MASM
#define CRYPTOPP_X86_ASM_AVAILABLE
#define CRYPTOPP_BOOL_X64 1
#define CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE 1
#endif

#ifdef CRYPTOPP_GENERATE_X64_MASM
#define AS1(x) x*newline*
Expand Down Expand Up @@ -90,7 +92,7 @@
#define AS_JCXZ jrcxz


#ifdef CRYPTOPP_DISABLE_X86ASM // for backwards compatibility: this macro had both meanings
#if defined(CRYPTOPP_DISABLE_X86ASM) || defined(__aarch64__) // for backwards compatibility: this macro had both meanings
#define CRYPTOPP_DISABLE_ASM
#define CRYPTOPP_DISABLE_SSE2
#endif
Expand Down