Example #1
0
/* Shuffle a block.  This can never fail. */
void shuffle(size_t bytesoftype, size_t blocksize,
             uint8_t* _src, uint8_t* _dest) {
  int unaligned_dest = (int)((uintptr_t)_dest % 16);
  int multiple_of_block = (blocksize % (16 * bytesoftype)) == 0;
  int too_small = (blocksize < 256);

  if (unaligned_dest || !multiple_of_block || too_small) {
    /* _dest buffer is not aligned, not multiple of the vectorization size
     * or is too small.  Call the non-sse2 version. */
    _shuffle(bytesoftype, blocksize, _src, _dest);
    return;
  }

  /* Optimized shuffle */
  /* The buffer must be aligned on a 16 bytes boundary, have a power */
  /* of 2 size and be larger or equal than 256 bytes. */
  if (bytesoftype == 4) {
    shuffle4(_dest, _src, blocksize);
  }
  else if (bytesoftype == 8) {
    shuffle8(_dest, _src, blocksize);
  }
  else if (bytesoftype == 16) {
    shuffle16(_dest, _src, blocksize);
  }
  else if (bytesoftype == 2) {
    shuffle2(_dest, _src, blocksize);
  }
  else {
    /* Non-optimized shuffle */
    _shuffle(bytesoftype, blocksize, _src, _dest);
  }
}
Example #2
0
void print_shuffle_sequence_retries(int k, int retries_count, const char*id, const char*sequence)
{
	int l;
	char *t=NULL;
	int i;

	l = strlen(sequence);
	if ((t = malloc(l + 1)) == NULL)
		err(1,"malloc failed");
	t[l] = '\0';

	shuffle1(sequence, l, k);

	i = 0 ;
	while ( i < retries_count ) {
		shuffle2(t);
		if (strncmp(sequence, t, l) != 0) {
			printf("%s\n", id);
			printf("%s\n", t);
			break;
		}
		i++;
	}
	if (i>=retries_count) {
		fprintf(stderr,"WARNING: failed to find new shuffle for sequence \"%s\" (%s) after %d retries\n", id, sequence, retries_count);
		printf("%s\n", id);
		printf("%s\n", t);
	}
	shuffle_reset();

	free(t);
}
static PyObject *ushuffle_shuffle2(PyObject *self, PyObject *args) {
	char *t;
	PyObject *T;

	if (l_ <= 0)
		return NULL;

	if ((t = malloc((l_ + 1) * sizeof(char))) == NULL)
		return NULL;

	shuffle2(t);
	t[l_] = '\0';
	T = Py_BuildValue("s", t);
	free(t);
	return T;
}
Example #4
0
void print_shuffle_sequence_perm(int k, int permutations_count, const char*id, const char*sequence)
{
	int l;
	char *t=NULL;
	int i;

	l = strlen(sequence);
	if ((t = malloc(l + 1)) == NULL)
		err(1,"malloc failed");
	t[l] = '\0';

	shuffle1(sequence, l, k);
	for (i = 0; i < permutations_count; i++) {
		shuffle2(t);
		printf("%s-perm%d\n", id, i+1);
		printf("%s\n", t);
	}
	shuffle_reset();

	free(t);
}
Example #5
0
void shuffle(const char *s, char *t, int l, int k) {
	shuffle1(s, l, k);
	shuffle2(t);
}
Example #6
0
int main(int argc, char **argv) {
	char *s = NULL, *t;
	int n = 1, k = 2, b = 0;
	struct rusage r1, r2;
	struct timeval t1, t2;
	struct timeval tv;
	double u1;
	unsigned long seed;
	int i, l;

	gettimeofday(&tv, NULL);
	seed = (unsigned long) tv.tv_sec;

	for (i = 1; i < argc; i++)
		if (!strcmp(argv[i], "-s")) {
			if (i + 1 < argc && argv[i + 1][0] != '-')
				s = argv[++i];
			else
				print_help_and_exit();
		} else if (!strcmp(argv[i], "-n")) {
			if (i + 1 < argc && argv[i + 1][0] != '-')
				n = atoi(argv[++i]);
			else
				print_help_and_exit();
		} else if (!strcmp(argv[i], "-k")) {
			if (i + 1 < argc && argv[i + 1][0] != '-')
				k = atoi(argv[++i]);
			else
				print_help_and_exit();
		} else if (!strcmp(argv[i], "-seed")) {
			if (i + 1 < argc && argv[i + 1][0] != '-')
				seed = atoi(argv[++i]);
			else
				print_help_and_exit();
		} else if (!strcmp(argv[i], "-b"))
			b = 1;
	if (n <= 0 || s == NULL)
		print_help_and_exit();

	l = strlen(s);
	if ((t = malloc(l + 1)) == NULL) {
		fprintf(stderr, "malloc failed\n");
		exit(1);
	}
	t[l] = '\0';
	srandom(seed);
	set_randfunc((randfunc_t) random);
	if (b)
		getrusage(RUSAGE_SELF, &r1);
	shuffle1(s, l, k);
	for (i = 0; i < n; i++) {
		shuffle2(t);
		if (!b)
			printf("%s\n", t);
	}
	if (b) {
		getrusage(RUSAGE_SELF, &r2);
		t1 = r1.ru_utime;
		t2 = r2.ru_utime;
		u1 = (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) * 0.001;
		printf("%g\n", u1);				/* time in msec */
	}
	return 0;
}