Skip to content

Commit

Permalink
Fix a couple of compiler warnings and compile most of the JIT code al…
Browse files Browse the repository at this point in the history
…l of the time
  • Loading branch information
cjdelisle committed Nov 14, 2022
1 parent 092b4c4 commit 1b1fb15
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 33 deletions.
3 changes: 3 additions & 0 deletions packetcrypt-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ fn main() {

cfg.define("JIT_ENABLED", "1")
.file("packetcrypt/src/JIT/JIT.posix64.c");
} else {
cfg.file("packetcrypt/src/JIT/NoJIT.c");
}

dbg!(cfg.include("packetcrypt/include")
.include("packetcrypt/src")
.flag("-Wno-implicit-function-declaration")
.flag("-Wno-implicit-fallthrough") // JIT has a bunch of these
.file("packetcrypt/src/Validate.c")
.file("packetcrypt/src/AnnMerkle.c")
.file("packetcrypt/src/AnnMiner.c")
Expand Down
43 changes: 18 additions & 25 deletions packetcrypt-sys/packetcrypt/src/AnnMiner.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,6 @@ static void populateTable(CryptoCycle_Item_t* table, Buf64_t* annHash0) {
}
}

// -1 means try again
static int populateTable2(Worker_t* w, Buf64_t* seed) {
if (Announce_createProg(w->vctx, &seed->thirtytwos[0])) {
return -1;
}
for (int i = 0; i < Announce_TABLE_SZ; i++) {
// Allow this to be interrupted in case we should stop
if (getRequestedState(w) != ThreadState_RUNNING) { return -1; }
if (Announce_mkitem2(i, &w->job.table[i], &seed->thirtytwos[1], w->vctx)) {
return -1;
}
}
return 0;
}

#ifdef JIT_ENABLED
static int populateTableJIT(Worker_t* w, Buf64_t* seed) {
if (Announce_createProg(w->vctx, &seed->thirtytwos[0])) {
return -1;
Expand All @@ -175,7 +159,24 @@ static int populateTableJIT(Worker_t* w, Buf64_t* seed) {

return 0;
}
#endif

// -1 means try again
static int populateTable2(Worker_t* w, Buf64_t* seed) {
#ifdef ENABLE_JIT
return populateTableJIT(w, seed);
#endif
if (Announce_createProg(w->vctx, &seed->thirtytwos[0])) {
return -1;
}
for (int i = 0; i < Announce_TABLE_SZ; i++) {
// Allow this to be interrupted in case we should stop
if (getRequestedState(w) != ThreadState_RUNNING) { return -1; }
if (Announce_mkitem2(i, &w->job.table[i], &seed->thirtytwos[1], w->vctx)) {
return -1;
}
}
return 0;
}

#define HASHES_PER_CYCLE 16

Expand Down Expand Up @@ -231,11 +232,7 @@ static int getNextJob(Worker_t* w) {
Hash_COMPRESS64_OBJ(&w->job.annHash0, &w->job.hah);

if (w->job.hah.annHdr.version > 0) {
#ifdef JIT_ENABLED
int pt = populateTableJIT(w, &w->job.annHash0);
#else
int pt = populateTable2(w, &w->job.annHash0);
#endif
if (pt) { return pt; }
} else {
populateTable(w->job.table, &w->job.annHash0);
Expand All @@ -254,11 +251,7 @@ static int getNextJob(Worker_t* w) {
Buf_OBJCPY(&b[0], root);
Buf_OBJCPY(&b[1], &w->job.annHash0);
Hash_COMPRESS64_OBJ(&b[0], &b);
#ifdef JIT_ENABLED
int pt = populateTableJIT(w, &b[0]);
#else
int pt = populateTable2(w, &b[0]);
#endif
if (pt) { return pt; }
}
return 0;
Expand Down
2 changes: 0 additions & 2 deletions packetcrypt-sys/packetcrypt/src/Announce.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ int Announce_mkitem2(uint64_t num, CryptoCycle_Item_t* item,
return 0;
}

#ifdef JIT_ENABLED
void rh_make_item(uint64_t num, CryptoCycle_Item_t* item, PacketCrypt_ValidateCtx_t* ctx, Buf32_t* seed, rh_jit_program_t* program) {
CryptoCycle_State_t state; // Working on a buffer of 2048 bytes
CryptoCycle_init(&state, seed, num);
Expand All @@ -71,6 +70,5 @@ void rh_make_item(uint64_t num, CryptoCycle_Item_t* item, PacketCrypt_ValidateCt

Buf_OBJCPY_LDST(item, &state); // Only copy first 1024 bytes of the state to the returned item
}
#endif


5 changes: 2 additions & 3 deletions packetcrypt-sys/packetcrypt/src/Announce.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef ANNOUNCE_H
#define ANNOUNCE_H

#include "JIT/JIT.h"
#include "packetcrypt/PacketCrypt.h"
#include "CryptoCycle.h"

Expand Down Expand Up @@ -57,9 +58,7 @@ static inline void Announce_crypt(Announce_t* ann, const CryptoCycle_State_t* st
}
}

#ifdef JIT_ENABLED
#include "JIT/JIT.h"
void rh_make_item(uint64_t num, CryptoCycle_Item_t* item, PacketCrypt_ValidateCtx_t* ctx, Buf32_t* seed, rh_jit_program_t* program);
#endif


#endif
4 changes: 2 additions & 2 deletions packetcrypt-sys/packetcrypt/src/JIT/JIT.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <sys/mman.h>
#include <linux/mman.h>

#include "luajit-2.0/dynasm/dasm_proto.h"
#include "luajit-2.0/dynasm/dasm_x86.h"
#include "luajit-vendored/dynasm/dasm_proto.h"
#include "luajit-vendored/dynasm/dasm_x86.h"

#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
#define MAP_ANONYMOUS MAP_ANON
Expand Down
16 changes: 16 additions & 0 deletions packetcrypt-sys/packetcrypt/src/JIT/NoJIT.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "JIT.h"

#include <assert.h>

rh_jit_program_t* rh_generate_program(uint32_t* programBuffer, uint32_t programLength)
{
assert(0 && "JIT not enabled");
}
void rh_run(uint32_t* programBuffer, int index, void* hashIn, void* hashOut, rh_jit_program_t* program)
{
assert(0 && "JIT not enabled");
}
void rh_free_program(rh_jit_program_t* program)
{
assert(0 && "JIT not enabled");
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async fn ann_load_config(
reqwest::StatusCode::OK => {
json = res.text().await.ok().expect("Could not read response body");
},
st => (panic!("Failed to load config.json. Status code was {:?}", st)),
st => panic!("Failed to load config.json. Status code was {:?}", st),
};
} else {
let file = path::Path::new(config_json_path.as_str());
Expand Down

0 comments on commit 1b1fb15

Please sign in to comment.