OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [lib/] [lib-utils.c] - Blame information for rev 658

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 393 julius
#include "lib-utils.h"
2
 
3
/* Simple C functions */
4
 
5
/* memcpy */
6
 
7
void* memcpy( void* s1, void* s2, size_t n)
8
{
9 489 julius
  char* r1 = (char *) s1;
10
  const char* r2 =  (const char*) s2;
11 393 julius
#ifdef __BCC__
12
  while (n--) {
13
    *r1++ = *r2++;
14
  }
15
#else
16
  while (n) {
17
    *r1++ = *r2++;
18
    --n;
19
  }
20
#endif
21
  return s1;
22
}
23
 
24
/* strlen */
25
size_t strlen(const char*s)
26
{
27
  const char* p;
28
  for (p=s; *p; p++);
29
  return p - s;
30
}
31
 
32
/* memchr */
33
void *memchr(const void *s, int c, size_t n)
34
{
35
         const unsigned char *r = (const unsigned char *) s;
36
#ifdef __BCC__
37
        /* bcc can optimize the counter if it thinks it is a pointer... */
38
        const char *np = (const char *) n;
39
#else
40
# define np n
41
#endif
42
 
43
        while (np) {
44
                if (*r == ((unsigned char)c)) {
45
                        return (void *) r;     /* silence the warning */
46
                }
47
                ++r;
48
                --np;
49
        }
50
 
51
        return NULL;
52
}
53
 
54
/* --------------------------------------------------------------------------*/
55
/*!Pseudo-random number generator
56
 
57
   This should return pseudo-random numbers, based on a Galois LFSR
58
 
59
   @return The next pseudo-random number                                     */
60
/* --------------------------------------------------------------------------*/
61
unsigned long int
62
rand ()
63
{
64
  static unsigned long int lfsr = RAND_LFSR_SEED;
65
  static int period = 0;
66
  /* taps: 32 31 29 1; characteristic polynomial: x^32 + x^31 + x^29 + x + 1 */
67
  lfsr = (lfsr >> 1) ^ (unsigned long int)((0 - (lfsr & 1u)) & 0xd0000001u);
68
  ++period;
69
  return lfsr;
70
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.