Skip to content

Commit

Permalink
Merge pull request #42 from tpn/issue41-add-_penter-hooking-support
Browse files Browse the repository at this point in the history
Issue41 add  penter hooking support
  • Loading branch information
tpn authored Jan 3, 2023
2 parents ee91729 + dedf8fd commit 672771e
Show file tree
Hide file tree
Showing 85 changed files with 3,787 additions and 266 deletions.
35 changes: 32 additions & 3 deletions include/CompiledPerfectHash.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*++
Copyright (c) 2018-2022 Trent Nelson <[email protected]>
Copyright (c) 2018-2023 Trent Nelson <[email protected]>
Module Name:
Expand Down Expand Up @@ -50,10 +50,14 @@ extern "C" {
#endif

//
// Clang doesn't appear to support the rotate intrinsics _rotr and _rotl,
// so, define some static inline versions here.
// Older versions of clang didn't appear to support the rotate intrinsics _rotr
// and _rotl, so, we used some static inline versions, below. Recent versions
// (10.0+) appear to have the intrinsics, so, disable this block for now. If
// you are compiling on an older version of clang, change the 0 to 1 to get the
// rotate intrinsics back.
//

#if 0
static inline
unsigned int
_rotl(
Expand All @@ -75,6 +79,7 @@ _rotr(
b &= 31;
return (a >> b) | (a << (32 - b));
}
#endif

#elif defined(__GNUC__)
#include <x86intrin.h>
Expand Down Expand Up @@ -264,6 +269,30 @@ Return Value:
--*/
typedef COMPILED_PERFECT_HASH_TABLE_DELETE *PCOMPILED_PERFECT_HASH_TABLE_DELETE;

typedef
CPHAPI
CPHVALUE
(CPHCALLTYPE COMPILED_PERFECT_HASH_TABLE_INTERLOCKED_INCREMENT)(
_In_ CPHKEY Key
);
/*++
Routine Description:
Increments the value associated with a key.
Arguments:
Key - Supplies the key to increment.
Return Value:
Previous value.
--*/
typedef COMPILED_PERFECT_HASH_TABLE_INTERLOCKED_INCREMENT
*PCOMPILED_PERFECT_HASH_TABLE_INTERLOCKED_INCREMENT;

//
// Typedefs of methods for testing and benchmarking.
//
Expand Down
97 changes: 83 additions & 14 deletions include/CompiledPerfectHashMacroGlue.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,18 @@

#define CPH_INDEX_ROUTINE_NAME(T) CompiledPerfectHash_##T##_Index
#define CPH_INDEX_IACA_ROUTINE_NAME(T) CompiledPerfectHash_##T##_IndexIaca
#define CPH_INDEX_BSEARCH_ROUTINE_NAME(T) CompiledPerfectHash_##T##_IndexBsearch
#define CPH_LOOKUP_ROUTINE_NAME(T) CompiledPerfectHash_##T##_Lookup
#define CPH_INSERT_ROUTINE_NAME(T) CompiledPerfectHash_##T##_Insert
#define CPH_DELETE_ROUTINE_NAME(T) CompiledPerfectHash_##T##_Delete
#define CPH_INTERLOCKED_INCREMENT_ROUTINE_NAME(T) CompiledPerfectHash_##T##_InterlockedIncrement

#define CPH_INDEX_INLINE_ROUTINE_NAME(T) CompiledPerfectHash_##T##_IndexInline
#define CPH_INDEX_BSEARCH_INLINE_ROUTINE_NAME(T) CompiledPerfectHash_##T##_IndexBsearchInline
#define CPH_LOOKUP_INLINE_ROUTINE_NAME(T) CompiledPerfectHash_##T##_LookupInline
#define CPH_INSERT_INLINE_ROUTINE_NAME(T) CompiledPerfectHash_##T##_InsertInline
#define CPH_DELETE_INLINE_ROUTINE_NAME(T) CompiledPerfectHash_##T##_DeleteInline
#define CPH_INTERLOCKED_INCREMENT_INLINE_ROUTINE_NAME(T) CompiledPerfectHash_##T##_InterlockedIncrementInline

////////////////////////////////////////////////////////////////////////////////
// Index
Expand Down Expand Up @@ -120,6 +124,16 @@ CompiledPerfectHash_##T##_IndexIaca( \
CPHKEY Key \
)

#define CPH_INDEX_BSEARCH_ROUTINE_HEADER(T) \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INDEX \
CompiledPerfectHash_##T##_IndexBsearch; \
\
_Use_decl_annotations_ \
CPHINDEX \
CompiledPerfectHash_##T##_IndexBsearch( \
CPHKEY Key \
)

//
// Inline
//
Expand All @@ -131,6 +145,13 @@ CompiledPerfectHash_##T##_IndexInline( \
CPHKEY Key \
)

#define CPH_INDEX_BSEARCH_INLINE_ROUTINE_HEADER(T) \
FORCEINLINE \
CPHINDEX \
CompiledPerfectHash_##T##_IndexBsearchInline( \
CPHKEY Key \
)

////////////////////////////////////////////////////////////////////////////////
// Lookup
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -221,6 +242,35 @@ CompiledPerfectHash_##T##_DeleteInline( \
CPHKEY Key \
)

////////////////////////////////////////////////////////////////////////////////
// InterlockedIncrement
////////////////////////////////////////////////////////////////////////////////

//
// Normal
//

#define CPH_INTERLOCKED_INCREMENT_ROUTINE_HEADER(T) \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INTERLOCKED_INCREMENT \
CompiledPerfectHash_##T##_InterlockedIncrement; \
\
_Use_decl_annotations_ \
CPHVALUE \
CompiledPerfectHash_##T##_InterlockedIncrement( \
CPHKEY Key \
)

//
// Inline
//

#define CPH_INTERLOCKED_INCREMENT_INLINE_ROUTINE_HEADER(T) \
FORCEINLINE \
CPHVALUE \
CompiledPerfectHash_##T##_InterlockedIncrementInline( \
CPHKEY Key \
)


////////////////////////////////////////////////////////////////////////////////
// Test and Benchmarking
Expand Down Expand Up @@ -266,9 +316,11 @@ BenchmarkIndexCompiledPerfectHashTable_##T( \
////////////////////////////////////////////////////////////////////////////////

#ifdef CPH_INDEX_ONLY
#define CPH_DEFINE_TABLE_ROUTINES(T) \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INDEX CompiledPerfectHash_##T##_Index; \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INDEX CompiledPerfectHash_##T##_IndexIaca

#define CPH_DEFINE_TABLE_ROUTINES(T) \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INDEX CompiledPerfectHash_##T##_Index; \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INDEX CompiledPerfectHash_##T##_IndexIaca; \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INDEX CompiledPerfectHash_##T##_IndexBsearch

#define CPH_INDEX_ROUTINE(T) CPH_INDEX_ROUTINE_NAME(T)
#define CPH_INDEX_IACA_ROUTINE(T) CPH_INDEX_IACA_ROUTINE_NAME(T)
Expand All @@ -279,12 +331,14 @@ extern BENCHMARK_INDEX_COMPILED_PERFECT_HASH_TABLE \
BenchmarkIndexCompiledPerfectHashTable_##T

#else
#define CPH_DEFINE_TABLE_ROUTINES(T) \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INDEX CompiledPerfectHash_##T##_Index; \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INDEX CompiledPerfectHash_##T##_IndexIaca; \
CPHAPI COMPILED_PERFECT_HASH_TABLE_LOOKUP CompiledPerfectHash_##T##_Lookup; \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INSERT CompiledPerfectHash_##T##_Insert; \
CPHAPI COMPILED_PERFECT_HASH_TABLE_DELETE CompiledPerfectHash_##T##_Delete
#define CPH_DEFINE_TABLE_ROUTINES(T) \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INDEX CompiledPerfectHash_##T##_Index; \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INDEX CompiledPerfectHash_##T##_IndexIaca; \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INDEX CompiledPerfectHash_##T##_IndexBsearch; \
CPHAPI COMPILED_PERFECT_HASH_TABLE_LOOKUP CompiledPerfectHash_##T##_Lookup; \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INSERT CompiledPerfectHash_##T##_Insert; \
CPHAPI COMPILED_PERFECT_HASH_TABLE_DELETE CompiledPerfectHash_##T##_Delete; \
CPHAPI COMPILED_PERFECT_HASH_TABLE_INTERLOCKED_INCREMENT CompiledPerfectHash_##T##_InterlockedIncrement

#define CPH_DEFINE_TEST_AND_BENCHMARKING_ROUTINES(T) \
extern TEST_COMPILED_PERFECT_HASH_TABLE \
Expand All @@ -298,14 +352,18 @@ extern BENCHMARK_INDEX_COMPILED_PERFECT_HASH_TABLE \

#define CPH_INDEX_ROUTINE(T) CPH_INDEX_ROUTINE_NAME(T)
#define CPH_INDEX_IACA_ROUTINE(T) CPH_INDEX_IACA_ROUTINE_NAME(T)
#define CPH_INDEX_BSEARCH_ROUTINE(T) CPH_INDEX_BSEARCH_ROUTINE_NAME(T)
#define CPH_LOOKUP_ROUTINE(T) CPH_LOOKUP_ROUTINE_NAME(T)
#define CPH_INSERT_ROUTINE(T) CPH_INSERT_ROUTINE_NAME(T)
#define CPH_DELETE_ROUTINE(T) CPH_DELETE_ROUTINE_NAME(T)
#define CPH_INTERLOCKED_INCREMENT_ROUTINE(T) CPH_INTERLOCKED_INCREMENT_ROUTINE_NAME(T)

#define CPH_INDEX_INLINE_ROUTINE(T) CPH_INDEX_INLINE_ROUTINE_NAME(T)
#define CPH_INDEX_BSEARCH_INLINE_ROUTINE(T) CPH_INDEX_BSEARCH_INLINE_ROUTINE_NAME(T)
#define CPH_LOOKUP_INLINE_ROUTINE(T) CPH_LOOKUP_INLINE_ROUTINE_NAME(T)
#define CPH_INSERT_INLINE_ROUTINE(T) CPH_INSERT_INLINE_ROUTINE_NAME(T)
#define CPH_DELETE_INLINE_ROUTINE(T) CPH_DELETE_INLINE_ROUTINE_NAME(T)
#define CPH_INTERLOCKED_INCREMENT_INLINE_ROUTINE(T) CPH_INTERLOCKED_INCREMENT_INLINE_ROUTINE_NAME(T)
#endif

#define EXPAND_SEED1(U) CPH_SEED1(U)
Expand Down Expand Up @@ -391,25 +449,34 @@ extern BENCHMARK_INDEX_COMPILED_PERFECT_HASH_TABLE \

#define EXPAND_INDEX_ROUTINE(T) CPH_INDEX_ROUTINE(T)
#define EXPAND_INDEX_IACA_ROUTINE(T) CPH_INDEX_IACA_ROUTINE(T)
#define EXPAND_INDEX_BSEARCH_ROUTINE(T) CPH_INDEX_BSEARCH_ROUTINE(T)
#define EXPAND_LOOKUP_ROUTINE(T) CPH_LOOKUP_ROUTINE(T)
#define EXPAND_INSERT_ROUTINE(T) CPH_INSERT_ROUTINE(T)
#define EXPAND_DELETE_ROUTINE(T) CPH_DELETE_ROUTINE(T)
#define EXPAND_INTERLOCKED_INCREMENT_ROUTINE(T) CPH_INTERLOCKED_INCREMENT_ROUTINE(T)

#define EXPAND_INDEX_INLINE_ROUTINE(T) CPH_INDEX_INLINE_ROUTINE(T)
#define EXPAND_INDEX_BSEARCH_INLINE_ROUTINE(T) CPH_INDEX_BSEARCH_INLINE_ROUTINE(T)
#define EXPAND_LOOKUP_INLINE_ROUTINE(T) CPH_LOOKUP_INLINE_ROUTINE(T)
#define EXPAND_INSERT_INLINE_ROUTINE(T) CPH_INSERT_INLINE_ROUTINE(T)
#define EXPAND_DELETE_INLINE_ROUTINE(T) CPH_DELETE_INLINE_ROUTINE(T)
#define EXPAND_INTERLOCKED_INCREMENT_INLINE_ROUTINE(T) CPH_INTERLOCKED_INCREMENT_INLINE_ROUTINE(T)
#define EXPAND_INDEX_BSEARCH_INLINE_ROUTINE(T) CPH_INDEX_BSEARCH_INLINE_ROUTINE(T)

#define EXPAND_INDEX_ROUTINE_HEADER(T) CPH_INDEX_ROUTINE_HEADER(T)
#define EXPAND_INDEX_IACA_ROUTINE_HEADER(T) CPH_INDEX_IACA_ROUTINE_HEADER(T)
#define EXPAND_INDEX_BSEARCH_ROUTINE_HEADER(T) CPH_INDEX_BSEARCH_ROUTINE_HEADER(T)
#define EXPAND_LOOKUP_ROUTINE_HEADER(T) CPH_LOOKUP_ROUTINE_HEADER(T)
#define EXPAND_INSERT_ROUTINE_HEADER(T) CPH_INSERT_ROUTINE_HEADER(T)
#define EXPAND_DELETE_ROUTINE_HEADER(T) CPH_DELETE_ROUTINE_HEADER(T)
#define EXPAND_INTERLOCKED_INCREMENT_ROUTINE_HEADER(T) CPH_INTERLOCKED_INCREMENT_ROUTINE_HEADER(T)

#define EXPAND_INDEX_INLINE_ROUTINE_HEADER(T) CPH_INDEX_INLINE_ROUTINE_HEADER(T)
#define EXPAND_INDEX_BSEARCH_INLINE_ROUTINE_HEADER(T) CPH_INDEX_BSEARCH_INLINE_ROUTINE_HEADER(T)
#define EXPAND_LOOKUP_INLINE_ROUTINE_HEADER(T) CPH_LOOKUP_INLINE_ROUTINE_HEADER(T)
#define EXPAND_INSERT_INLINE_ROUTINE_HEADER(T) CPH_INSERT_INLINE_ROUTINE_HEADER(T)
#define EXPAND_DELETE_INLINE_ROUTINE_HEADER(T) CPH_DELETE_INLINE_ROUTINE_HEADER(T)
#define EXPAND_INTERLOCKED_INCREMENT_INLINE_ROUTINE_HEADER(T) CPH_INTERLOCKED_INCREMENT_INLINE_ROUTINE_HEADER(T)

#define EXPAND_TEST_CPH_ROUTINE_HEADER(T) TEST_CPH_ROUTINE_HEADER(T)
#define EXPAND_BENCHMARK_FULL_CPH_ROUTINE_HEADER(T) BENCHMARK_FULL_CPH_ROUTINE_HEADER(T)
Expand Down Expand Up @@ -503,20 +570,27 @@ extern BENCHMARK_INDEX_COMPILED_PERFECT_HASH_TABLE \
#define ROTATE_KEY_RIGHT EXPAND_ROTATE_KEY_RIGHT(CPH_TABLENAME_UPPER)

#define DECLARE_INDEX_ROUTINE_HEADER() EXPAND_INDEX_ROUTINE_HEADER(CPH_TABLENAME)
#define DECLARE_INDEX_BSEARCH_ROUTINE_HEADER() EXPAND_INDEX_BSEARCH_ROUTINE_HEADER(CPH_TABLENAME)
#define DECLARE_INDEX_IACA_ROUTINE_HEADER() EXPAND_INDEX_IACA_ROUTINE_HEADER(CPH_TABLENAME)
#define DECLARE_LOOKUP_ROUTINE_HEADER() EXPAND_LOOKUP_ROUTINE_HEADER(CPH_TABLENAME)
#define DECLARE_INSERT_ROUTINE_HEADER() EXPAND_INSERT_ROUTINE_HEADER(CPH_TABLENAME)
#define DECLARE_DELETE_ROUTINE_HEADER() EXPAND_DELETE_ROUTINE_HEADER(CPH_TABLENAME)
#define DECLARE_INTERLOCKED_INCREMENT_ROUTINE_HEADER() EXPAND_INTERLOCKED_INCREMENT_ROUTINE_HEADER(CPH_TABLENAME)

#define DECLARE_INDEX_INLINE_ROUTINE_HEADER() EXPAND_INDEX_INLINE_ROUTINE_HEADER(CPH_TABLENAME)
#define DECLARE_INDEX_BSEARCH_ROUTINE_HEADER() EXPAND_INDEX_BSEARCH_ROUTINE_HEADER(CPH_TABLENAME)
#define DECLARE_LOOKUP_INLINE_ROUTINE_HEADER() EXPAND_LOOKUP_INLINE_ROUTINE_HEADER(CPH_TABLENAME)
#define DECLARE_INSERT_INLINE_ROUTINE_HEADER() EXPAND_INSERT_INLINE_ROUTINE_HEADER(CPH_TABLENAME)
#define DECLARE_DELETE_INLINE_ROUTINE_HEADER() EXPAND_DELETE_INLINE_ROUTINE_HEADER(CPH_TABLENAME)
#define DECLARE_INTERLOCKED_INCREMENT_INLINE_ROUTINE_HEADER() \
EXPAND_INTERLOCKED_INCREMENT_INLINE_ROUTINE_HEADER(CPH_TABLENAME)

#define INDEX_INLINE_ROUTINE EXPAND_INDEX_INLINE_ROUTINE(CPH_TABLENAME)
#define INDEX_BSEARCH_INLINE_ROUTINE EXPAND_INDEX_BSEARCH_INLINE_ROUTINE(CPH_TABLENAME)
#define LOOKUP_INLINE_ROUTINE EXPAND_LOOKUP_INLINE_ROUTINE(CPH_TABLENAME)
#define INSERT_INLINE_ROUTINE EXPAND_INSERT_INLINE_ROUTINE(CPH_TABLENAME)
#define DELETE_INLINE_ROUTINE EXPAND_DELETE_INLINE_ROUTINE(CPH_TABLENAME)
#define INTERLOCKED_INCREMENT_INLINE_ROUTINE EXPAND_INTERLOCKED_INCREMENT_INLINE_ROUTINE(CPH_TABLENAME)

#define TEST_CPH_ROUTINE EXPAND_TEST_CPH_ROUTINE_NAME(CPH_TABLENAME)
#define BENCHMARK_FULL_CPH_ROUTINE EXPAND_BENCHMARK_FULL_CPH_ROUTINE_NAME(CPH_TABLENAME)
Expand All @@ -529,8 +603,3 @@ extern BENCHMARK_INDEX_COMPILED_PERFECT_HASH_TABLE \
#define DEFINE_TABLE_ROUTINES() EXPAND_DEFINE_TABLE_ROUTINES(CPH_TABLENAME)
#define DEFINE_TEST_AND_BENCHMARKING_ROUTINES() EXPAND_DEFINE_TEST_AND_BENCHMARKING_ROUTINES(CPH_TABLENAME)


//
// End CompiledPerfectHashMacroGlue.h.
//

Loading

0 comments on commit 672771e

Please sign in to comment.