コード例 #1
0
int
main (int argc, char **argv)
{
  unsigned int i;
  isaac_word r[ISAAC_WORDS];
  int iterations;

  /* Seed with zeros, and discard the first buffer of output,
     as that's what the standard programs do.  */
  static struct isaac_state s;
  isaac_seed (&s);
  isaac_refill (&s, r);

  for (i = 0; i < sizeof expected / sizeof expected[0]; i++)
    {
      isaac_refill (&s, r);
      ASSERT (memcmp (r, expected[i], sizeof r) == 0);
    }

  /* If invoked with a positive argument, run a benchmark;
     if with a negative, run a do-nothing benchmark.  */
  for (iterations = argc <= 1 ? 0 : strtol (argv[1], NULL, 10);
       iterations != 0;
       iterations += (iterations < 0 ? 1 : -1))
    if (0 <= iterations)
      isaac_refill (&s, r);

  return 0;
}
コード例 #2
0
static void
readisaac (struct isaac *isaac, void *p, size_t size)
{
  size_t inbytes = isaac->buffered;

  while (true)
    {
      char *char_p = p;

      if (size <= inbytes)
        {
          memcpy (p, isaac->data.b + ISAAC_BYTES - inbytes, size);
          isaac->buffered = inbytes - size;
          return;
        }

      memcpy (p, isaac->data.b + ISAAC_BYTES - inbytes, inbytes);
      p = char_p + inbytes;
      size -= inbytes;

      /* If P is aligned, write to *P directly to avoid the overhead
         of copying from the buffer.  */
      if (ALIGNED_POINTER (p, isaac_word))
        {
          isaac_word *wp = p;
          while (ISAAC_BYTES <= size)
            {
              isaac_refill (&isaac->state, wp);
              wp += ISAAC_WORDS;
              size -= ISAAC_BYTES;
              if (size == 0)
                {
                  isaac->buffered = 0;
                  return;
                }
            }
          p = wp;
        }

      isaac_refill (&isaac->state, isaac->data.w);
      inbytes = ISAAC_BYTES;
    }
}