示例#1
0
文件: uio-dma.c 项目: peper/uio-dma
struct uio_dma_mapping *uio_dma_map(int fd, struct uio_dma_area *area,
		unsigned int devid, unsigned int dir)
{
	struct uio_dma_mapping *m;
	struct {
		struct uio_dma_map_req req;
		uint64_t dmaddr[area->chunk_count];
	} mreq;

	int err, i;

	m = malloc(sizeof(*m) + sizeof(uint64_t) * area->chunk_count);
	if (!m)
		return NULL;

	mreq.req.mmap_offset = area->mmap_offset;
	mreq.req.devid = devid;
	mreq.req.direction = dir;
	mreq.req.chunk_count = area->chunk_count;
	mreq.req.flags = 0;
	for (i=0; i < area->chunk_count; i++)
		mreq.dmaddr[i] = 0;

	err = ioctl(fd, UIO_DMA_MAP, (unsigned long) &mreq);
	if (err)
		goto failed;

	m->devid = devid;
	m->direction = dir;
	m->size = area->size;
	m->chunk_count = area->chunk_count;
	m->chunk_shift = ulog2(area->chunk_size);
	m->mmap_offset = area->mmap_offset;
	m->addr = area->addr;
	for (i=0; i < m->chunk_count; i++)
		m->dmaddr[i] = mreq.dmaddr[i];

	return m;

failed:
	err = errno;
	free(m);
	errno = err;
	return NULL;
}
示例#2
0
void
table (int limb_bits, int nail_bits)
{
  int  numb_bits = limb_bits - nail_bits;
  int  base;

  printf ("/* This file generated by gen-bases.c - DO NOT EDIT. */\n");
  printf ("\n");
  printf ("#include \"mpir.h\"\n");
  printf ("#include \"gmp-impl.h\"\n");
  printf ("\n");
  printf ("#if GMP_NUMB_BITS != %d\n", numb_bits);
  printf ("Error, error, this data is for %d bits\n", numb_bits);
  printf ("#endif\n");
  printf ("\n");
  puts ("const struct bases mp_bases[257] =\n{");
  puts ("  /*   0 */ { 0, 0.0, 0 },");
  puts ("  /*   1 */ { 0, 1e37, 0 },");
  for (base = 2; base <= 256; base++)
    {
      generate (limb_bits, nail_bits, base);

      printf ("  /* %3u */ { ", base);
      if (POW2_P (base))
	{
          printf ("%u, %.16f, 0x%x },\n",
                  chars_per_limb, chars_per_bit_exactly, ulog2 (base) - 1);
	}
      else
	{
          printf ("%u, %.16f, CNST_LIMB(0x",
                  chars_per_limb, chars_per_bit_exactly);
	  mpz_out_str (stdout, 16, big_base);
          printf ("), CNST_LIMB(0x");
	  mpz_out_str (stdout, 16, big_base_inverted);
          printf (") },\n");
	}
    }

  puts ("};");
}
示例#3
0
文件: uio-dma.c 项目: peper/uio-dma
static inline unsigned long roundup_po2(unsigned long n)
{
	return 1UL << (ulog2(n - 1) + 1);
}
示例#4
0
文件: gen-bases.c 项目: Cl3Kener/gmp
void
table (int limb_bits, int nail_bits)
{
  int  numb_bits = limb_bits - nail_bits;
  int  base;
  mpz_t r, t, logb2, log2b;

  mpz_init (r);
  mpz_init (t);
  mpz_init (logb2);
  mpz_init (log2b);

  printf ("/* This file generated by gen-bases.c - DO NOT EDIT. */\n");
  printf ("\n");
  printf ("#include \"gmp.h\"\n");
  printf ("#include \"gmp-impl.h\"\n");
  printf ("\n");
  printf ("#if GMP_NUMB_BITS != %d\n", numb_bits);
  printf ("Error, error, this data is for %d bits\n", numb_bits);
  printf ("#endif\n");
  printf ("\n");
  puts ("const struct bases mp_bases[257] =\n{");
  puts ("  /*   0 */ { 0, 0, 0, 0, 0 },");
  puts ("  /*   1 */ { 0, 0, 0, 0, 0 },");
  for (base = 2; base <= 256; base++)
    {
      generate (limb_bits, nail_bits, base);
      mp_2logb (r, base, limb_bits + 8);
      mpz_tdiv_q_2exp (logb2, r, 8);
      mpz_set_ui (t, 1);
      mpz_mul_2exp (t, t, 2*limb_bits + 5);
      mpz_sub_ui (t, t, 1);
      mpz_add_ui (r, r, 1);
      mpz_tdiv_q (log2b, t, r);

      printf ("  /* %3u */ { ", base);
      if (POW2_P (base))
	{
          mpz_set_ui (big_base, ulog2 (base) - 1);
	  mpz_set_ui (big_base_inverted, 0);
	}

      printf ("%u,", chars_per_limb);
      printf (" CNST_LIMB(0x");
      mpz_out_str (stdout, 16, logb2);
      printf ("), CNST_LIMB(0x");
      mpz_out_str (stdout, 16, log2b);
      printf ("), CNST_LIMB(0x");
      mpz_out_str (stdout, 16, big_base);
      printf ("), CNST_LIMB(0x");
      mpz_out_str (stdout, 16, big_base_inverted);
      printf (") },\n");
    }

  puts ("};");

  mpz_clear (r);
  mpz_clear (t);
  mpz_clear (logb2);
  mpz_clear (log2b);

}