Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

add mode for gas optimization #63

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions Mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ Mode Mode::leading(const char charLeading) {
return r;
}

Mode Mode::gas() {
Mode r;
r.name = "gas";
r.kernel = "profanity_score_gas";
return r;
}

Mode Mode::range(const cl_uchar min, const cl_uchar max) {
Mode r;
r.name = "range";
Expand Down
1 change: 1 addition & 0 deletions Mode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Mode {

static Mode benchmark();
static Mode zeros();
static Mode gas();
static Mode letters();
static Mode numbers();
static Mode doubles();
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ usage: ./profanity [OPTIONS]
Basic modes:
--benchmark Run without any scoring, a benchmark.
--zeros Score on zeros anywhere in hash.
--gas Score on number of zero bytes.
--letters Score on letters anywhere in hash.
--numbers Score on numbers anywhere in hash.
--mirror Score on mirroring from center.
Expand Down
1 change: 1 addition & 0 deletions help.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ usage: ./profanity [OPTIONS]
Basic modes:
--benchmark Run without any scoring, a benchmark.
--zeros Score on zeros anywhere in hash.
--gas Score on number of zero bytes.
--letters Score on letters anywhere in hash.
--numbers Score on numbers anywhere in hash.
--mirror Score on mirroring from center.
Expand Down
14 changes: 14 additions & 0 deletions profanity.cl
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,20 @@ __kernel void profanity_score_leading(__global mp_number * const pInverse, __glo
profanity_result_update(id, hash, pResult, score, scoreMax);
}

__kernel void profanity_score_gas(__global mp_number * const pInverse, __global result * const pResult, __constant const uchar * const data1, __constant const uchar * const data2, const uchar scoreMax) {
const size_t id = get_global_id(0);
__global const uchar * const hash = pInverse[id].d;
int score = 0;

for (int i = 0; i < 20; ++i) {
if (hash[i] == 0x00) {
++score;
}
}

profanity_result_update(id, hash, pResult, score, scoreMax);
}

__kernel void profanity_score_range(__global mp_number * const pInverse, __global result * const pResult, __constant const uchar * const data1, __constant const uchar * const data2, const uchar scoreMax) {
const size_t id = get_global_id(0);
__global const uchar * const hash = pInverse[id].d;
Expand Down
4 changes: 4 additions & 0 deletions profanity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ int main(int argc, char * * argv) {
bool bHelp = false;
bool bModeBenchmark = false;
bool bModeZeros = false;
bool bModeGas = false;
bool bModeLetters = false;
bool bModeNumbers = false;
std::string strModeLeading;
Expand Down Expand Up @@ -184,6 +185,7 @@ int main(int argc, char * * argv) {
argp.addSwitch('i', "inverse-size", inverseSize);
argp.addSwitch('I', "inverse-multiple", inverseMultiple);
argp.addSwitch('c', "contract", bMineContract);
argp.addSwitch('g', "gas", bModeGas);

if (!argp.parse()) {
std::cout << "error: bad arguments, try again :<" << std::endl;
Expand All @@ -200,6 +202,8 @@ int main(int argc, char * * argv) {
mode = Mode::benchmark();
} else if (bModeZeros) {
mode = Mode::zeros();
} else if (bModeGas) {
mode = Mode::gas();
} else if (bModeLetters) {
mode = Mode::letters();
} else if (bModeNumbers) {
Expand Down