Skip to content

Commit

Permalink
work-in-progress:mask mode internal candidate gen: #2
Browse files Browse the repository at this point in the history
  • Loading branch information
sayan1an committed Jan 17, 2015
1 parent 7553d25 commit ee77d8c
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 25 deletions.
2 changes: 2 additions & 0 deletions src/mask.c
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,8 @@ void mask_done()
MEM_FREE(template_key_offsets);
if (!mask_skip_ranges)
MEM_FREE(mask_skip_ranges);
if (!mask_int_cand.int_cand)
MEM_FREE(mask_int_cand.int_cand);

if (!(options.flags & FLG_MASK_STACKED)) {
if (parsed_mask.parse_ok &&
Expand Down
106 changes: 82 additions & 24 deletions src/mask_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,8 @@

int *mask_skip_ranges = NULL;
int mask_max_skip_loc = -1;
int mask_int_cand_target = 0;

static void combination_util(int *, int, int, int, int,
cpu_mask_context *, int *);

void mask_calc_combination(cpu_mask_context *ptr) {
int *data, i, n;
int delta_to_target = 0x7fffffff;
if (!mask_int_cand_target) return;

n = ptr->count;
data = (int*) malloc(n * sizeof(int));
mask_skip_ranges = (int*) malloc (MASK_FMT_INT_PLHDR * sizeof(int));

for (i = 0; i < MASK_FMT_INT_PLHDR; i++)
mask_skip_ranges[i] = -1;

/* Fix the maximum number of ranges that can be calculated on GPU to 3 */
for (i = 1; i <= MASK_FMT_INT_PLHDR; i++)
combination_util(data, 0, n - 1, 0, i, ptr,
&delta_to_target);

MEM_FREE(data);
}
int mask_int_cand_target = 100;
mask_int_cand_ctx mask_int_cand;

static void combination_util(int *data, int start, int end, int index,
int r, cpu_mask_context *ptr, int *delta) {
Expand Down Expand Up @@ -67,3 +45,83 @@ static void combination_util(int *data, int start, int end, int index,
r, ptr, delta);
}
}

static void generate_int_keys(cpu_mask_context *ptr) {
int i, repeat = 1, modulo;

#define fill_cand(t) \
for (i = 0; i < mask_int_cand.num_int_cand; i++) \
mask_int_cand.int_cand[i].x[t] = \
ptr->ranges[mask_skip_ranges[t]].chars \
[(i/repeat) % modulo];
#define cond(t) t < MASK_FMT_INT_PLHDR && mask_skip_ranges[t] != -1

for (i = 1; i < MASK_FMT_INT_PLHDR && mask_skip_ranges[i] != -1; i++)
repeat *= ptr->ranges[mask_skip_ranges[i]].count;
modulo = ptr->ranges[mask_skip_ranges[0]].count;
fill_cand(0);

if (cond(1)) {
modulo = ptr->ranges[mask_skip_ranges[1]].count;
repeat /= modulo;
fill_cand(1);
}
if (cond(2)) {
modulo = ptr->ranges[mask_skip_ranges[2]].count;
repeat /= modulo;
fill_cand(2);
}
if (cond(3)) {
repeat = 1;
modulo = ptr->ranges[mask_skip_ranges[3]].count;
fill_cand(3);
}
#undef fill_cand
#undef cond
}

void mask_calc_combination(cpu_mask_context *ptr) {
int *data, i, n;
int delta_to_target = 0x7fffffff;

mask_int_cand.num_int_cand = 0;
mask_int_cand.int_cpu_mask_ctx = NULL;
mask_int_cand.int_cand = NULL;

if (!mask_int_cand_target) return;
if (MASK_FMT_INT_PLHDR > 4) {
fprintf(stderr, "MASK_FMT_INT_PLHDR value must not exceed 4.\n");
error();
}

n = ptr->count;
data = (int*) malloc(n * sizeof(int));
mask_skip_ranges = (int*) malloc (MASK_FMT_INT_PLHDR * sizeof(int));

for (i = 0; i < MASK_FMT_INT_PLHDR; i++)
mask_skip_ranges[i] = -1;

/* Fix the maximum number of ranges that can be calculated on GPU to 3 */
for (i = 1; i <= MASK_FMT_INT_PLHDR; i++)
combination_util(data, 0, n - 1, 0, i, ptr,
&delta_to_target);

if (mask_skip_ranges[0] != -1) {
mask_int_cand.num_int_cand = 1;
for (i = 0; i < MASK_FMT_INT_PLHDR &&
mask_skip_ranges[i] != -1; i++)
mask_int_cand.num_int_cand *= ptr->
ranges[mask_skip_ranges[i]].count;
}

if (mask_int_cand.num_int_cand) {
mask_int_cand.int_cpu_mask_ctx = ptr;
mask_int_cand.int_cand = (mask_char4*)
malloc(mask_int_cand.num_int_cand * sizeof(mask_char4));
generate_int_keys(ptr);
}

for (i = 0; i < mask_int_cand.num_int_cand; i++)
fprintf(stderr, "%c%c%c%c\n", mask_int_cand.int_cand[i].x[0], mask_int_cand.int_cand[i].x[1], mask_int_cand.int_cand[i].x[2], mask_int_cand.int_cand[i].x[3]);
MEM_FREE(data);
}
13 changes: 12 additions & 1 deletion src/mask_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@

#include "mask.h"

#define MASK_FMT_INT_PLHDR 3
#define MASK_FMT_INT_PLHDR 4

typedef struct {
char x[4];
} mask_char4;

typedef struct {
mask_char4 *int_cand;
cpu_mask_context *int_cpu_mask_ctx;
int num_int_cand;
} mask_int_cand_ctx;

extern void mask_calc_combination(cpu_mask_context *);
extern int *mask_skip_ranges;
extern int mask_max_skip_loc;
extern int mask_int_cand_target;
extern mask_int_cand_ctx mask_int_cand;

#endif

0 comments on commit ee77d8c

Please sign in to comment.