Skip to content

Commit

Permalink
removed murmur3 as a dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugobros3 committed Oct 10, 2024
1 parent 61ff407 commit fb80fe2
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 35 deletions.
1 change: 0 additions & 1 deletion murmur3
Submodule murmur3 deleted from dae94b
4 changes: 0 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
add_library(murmur3 STATIC ../murmur3/murmur3.c)
target_include_directories(murmur3 INTERFACE ../murmur3)
set_target_properties(murmur3 PROPERTIES POSITION_INDEPENDENT_CODE ON)

add_subdirectory(common)
add_subdirectory(shady)
add_subdirectory(runtime)
Expand Down
2 changes: 1 addition & 1 deletion src/backend/spirv/spirv_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct SpvbFileBuilder_ {
struct Dict* extensions_set;
};

static KeyHash hash_u32(uint32_t* p) { return shd_hash_murmur(p, sizeof(uint32_t)); }
static KeyHash hash_u32(uint32_t* p) { return shd_hash(p, sizeof(uint32_t)); }
static bool compare_u32s(uint32_t* a, uint32_t* b) { return *a == *b; }

KeyHash shd_hash_string(const char** string);
Expand Down
1 change: 0 additions & 1 deletion src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
add_library(common list.c dict.c log.c portability.c util.c growy.c arena.c printer.c)
target_link_libraries(common PRIVATE "$<BUILD_INTERFACE:murmur3>")
set_property(TARGET common PROPERTY POSITION_INDEPENDENT_CODE ON)

# We need to export 'common' because otherwise when using static libraries we will not be able to resolve those symbols
Expand Down
27 changes: 14 additions & 13 deletions src/common/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,22 +382,23 @@ bool shd_dict_iter(struct Dict* dict, size_t* iterator_state, void* key, void* v
return true;
}

#include "murmur3.h"

KeyHash shd_hash_murmur(const void* data, size_t size) {
int32_t out[4];
MurmurHash3_x64_128(data, (int) size, 0x1234567, &out);

uint32_t final = 0;
final ^= out[0];
final ^= out[1];
final ^= out[2];
final ^= out[3];
return final;
KeyHash shd_hash(const void* data, size_t size) {
const char* data_chars = (const char*) data;
const unsigned int fnv_prime = 0x811C9DC5;
unsigned int hash = 0;
unsigned int i = 0;

for (i = 0; i < size; data++, i++)
{
hash *= fnv_prime;
hash ^= (*data_chars);
}

return hash;
}

KeyHash shd_hash_ptr(void** p) {
return shd_hash_murmur(p, sizeof(void*));
return shd_hash(p, sizeof(void*));
}

bool shd_compare_ptrs(void** a, void** b) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void* shd_dict_insert_get_key_impl(struct Dict*, void* key, void* value);
#define shd_set_insert_get_result(K, dict, key) shd_dict_insert_impl(dict, (void*) (&(key)), NULL)
bool shd_dict_insert_impl(struct Dict*, void* key, void* value);

KeyHash shd_hash_murmur(const void* data, size_t size);
KeyHash shd_hash(const void* data, size_t size);

KeyHash shd_hash_ptr(void**);
bool shd_compare_ptrs(void**, void**);
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/llvm/l2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static KeyHash hash_opaque_ptr(OpaqueRef* pvalue) {
if (!pvalue)
return 0;
size_t ptr = *(size_t*) pvalue;
return shd_hash_murmur(&ptr, sizeof(size_t));
return shd_hash(&ptr, sizeof(size_t));
}

static bool cmp_opaque_ptr(OpaqueRef* a, OpaqueRef* b) {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/spirv/s2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ SpvDef* get_definition_by_id(SpvParser* parser, size_t id) {
}

KeyHash hash_spvid(SpvId* p) {
return shd_hash_murmur(p, sizeof(SpvId));
return shd_hash(p, sizeof(SpvId));
}

bool compare_spvid(SpvId* pa, SpvId* pb) {
Expand Down
1 change: 0 additions & 1 deletion src/runtime/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ if (SHADY_ENABLE_RUNTIME_CUDA)
add_library(cuda_runtime STATIC cuda_runtime.c cuda_runtime_buffer.c cuda_runtime_program.c)
target_link_libraries(cuda_runtime PRIVATE api)
target_link_libraries(cuda_runtime PRIVATE "$<BUILD_INTERFACE:common>")
target_link_libraries(cuda_runtime PRIVATE "$<BUILD_INTERFACE:murmur3>")
target_link_libraries(cuda_runtime PRIVATE CUDA::cudart CUDA::cuda_driver CUDA::nvrtc)

target_link_libraries(runtime PRIVATE "$<BUILD_INTERFACE:cuda_runtime>")
Expand Down
1 change: 0 additions & 1 deletion src/runtime/vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ if (SHADY_ENABLE_RUNTIME_VULKAN)
add_library(vk_runtime STATIC vk_runtime.c vk_runtime_device.c vk_runtime_program.c vk_runtime_dispatch.c vk_runtime_buffer.c)
target_link_libraries(vk_runtime PRIVATE api)
target_link_libraries(vk_runtime PRIVATE "$<BUILD_INTERFACE:common>")
target_link_libraries(vk_runtime PRIVATE "$<BUILD_INTERFACE:murmur3>")
target_link_libraries(vk_runtime PRIVATE Vulkan::Headers Vulkan::Vulkan)

target_compile_definitions(runtime PUBLIC VK_BACKEND_PRESENT=1)
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/vulkan/vk_runtime_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ KeyHash shd_hash_string(const char** string);
bool shd_compare_string(const char** a, const char** b);

static KeyHash hash_spec_program_key(SpecProgramKey* ptr) {
return shd_hash_murmur(ptr->base, sizeof(Program*)) ^ shd_hash_string(&ptr->entry_point);
return shd_hash(ptr->base, sizeof(Program*)) ^ shd_hash_string(&ptr->entry_point);
}

static bool cmp_spec_program_keys(SpecProgramKey* a, SpecProgramKey* b) {
Expand Down
2 changes: 1 addition & 1 deletion src/shady/analysis/callgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ KeyHash shd_hash_node(const Node**);
bool shd_compare_node(const Node**, const Node**);

KeyHash hash_cgedge(CGEdge* n) {
return shd_hash_murmur(n, sizeof(CGEdge));
return shd_hash(n, sizeof(CGEdge));

}
bool compare_cgedge(CGEdge* a, CGEdge* b) {
Expand Down
2 changes: 1 addition & 1 deletion src/shady/generator_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static void generate_node_payload_hash_fn(Growy* g, json_object* src, json_objec
String op_name = json_object_get_string(json_object_object_get(op, "name"));
bool ignore = json_object_get_boolean(json_object_object_get(op, "ignore"));
if (!ignore) {
shd_growy_append_formatted(g, "\t\thash = hash ^ shd_hash_murmur(&payload.%s, sizeof(payload.%s));\n", op_name, op_name);
shd_growy_append_formatted(g, "\t\thash = hash ^ shd_hash(&payload.%s, sizeof(payload.%s));\n", op_name, op_name);
}
}
shd_growy_append_formatted(g, "\t\tbreak;\n");
Expand Down
6 changes: 3 additions & 3 deletions src/shady/ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ const char* unique_name(IrArena* arena, const char* str) {
}

KeyHash shd_hash_nodes(Nodes* nodes) {
return shd_hash_murmur(nodes->nodes, sizeof(const Node*) * nodes->count);
return shd_hash(nodes->nodes, sizeof(const Node*) * nodes->count);
}

bool shd_compare_nodes(Nodes* a, Nodes* b) {
Expand All @@ -243,7 +243,7 @@ bool shd_compare_nodes(Nodes* a, Nodes* b) {
}

KeyHash shd_hash_strings(Strings* strings) {
return shd_hash_murmur(strings->strings, sizeof(char*) * strings->count);
return shd_hash(strings->strings, sizeof(char*) * strings->count);
}

bool shd_compare_strings(Strings* a, Strings* b) {
Expand All @@ -256,7 +256,7 @@ bool shd_compare_strings(Strings* a, Strings* b) {
KeyHash shd_hash_string(const char** string) {
if (!*string)
return 0;
return shd_hash_murmur(*string, strlen(*string));
return shd_hash(*string, strlen(*string));
}

bool shd_compare_string(const char** a, const char** b) {
Expand Down
2 changes: 1 addition & 1 deletion src/shady/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ KeyHash shd_hash_node(Node** pnode) {
goto end;
}

KeyHash tag_hash = shd_hash_murmur(&node->tag, sizeof(NodeTag));
KeyHash tag_hash = shd_hash(&node->tag, sizeof(NodeTag));
KeyHash payload_hash = 0;

if (node_type_has_payload[node->tag]) {
Expand Down
4 changes: 2 additions & 2 deletions vcc/vcc_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define STRINGIFY(x) STRINGIFY2(x)
#define VCC_CLANG STRINGIFY(VCC_CLANG_EXECUTABLE_NAME)

uint32_t shd_hash_murmur(const void* data, size_t size);
uint32_t shd_hash(const void* data, size_t size);

void cli_parse_vcc_args(VccConfig* options, int* pargc, char** argv) {
int argc = *pargc;
Expand Down Expand Up @@ -98,7 +98,7 @@ void vcc_run_clang(VccConfig* vcc_options, size_t num_source_files, String* inpu
uint32_t hash = 0;
for (size_t i = 0; i < num_source_files; i++) {
String filename = input_filenames[i];
hash ^= shd_hash_murmur(filename, strlen(filename));
hash ^= shd_hash(filename, strlen(filename));
}
srand(hash);
for (size_t i = 0; i < 32; i++) {
Expand Down

0 comments on commit fb80fe2

Please sign in to comment.