Changeset 1691 for branches/FREEBSD/src


Ignore:
Timestamp:
Dec 3, 2004, 4:59:13 AM (21 years ago)
Author:
bird
Message:

FreeBSD 5.3 libc sources.

Location:
branches/FREEBSD/src/emx/src/lib/bsd/stdlib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/FREEBSD/src/emx/src/lib/bsd/stdlib/radixsort.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r1690 r1691  
    3939#endif /* LIBC_SCCS and not lint */
    4040#include <sys/cdefs.h>
    41 __FBSDID("$FreeBSD: src/lib/libc/stdlib/radixsort.c,v 1.6 2002/03/22 09:18:34 obrien Exp $");
     41__FBSDID("$FreeBSD: src/lib/libc/stdlib/radixsort.c,v 1.7 2003/11/11 04:59:23 kientzle Exp $");
    4242
    4343/*
     
    178178
    179179                /*
     180                 * Special case: if all strings have the same
     181                 * character at position i, move on to the next
     182                 * character.
     183                 */
     184                if (nc == 1 && count[bmin] == n) {
     185                        push(a, n, i+1);
     186                        nc = count[bmin] = 0;
     187                        continue;
     188                }
     189
     190                /*
    180191                 * Set top[]; push incompletely sorted bins onto stack.
    181192                 * top[] = pointers to last out-of-place element in bins.
  • branches/FREEBSD/src/emx/src/lib/bsd/stdlib/random.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r1690 r1691  
    3636#endif /* LIBC_SCCS and not lint */
    3737#include <sys/cdefs.h>
    38 __FBSDID("$FreeBSD: src/lib/libc/stdlib/random.c,v 1.22 2003/02/04 11:24:08 ache Exp $");
     38__FBSDID("$FreeBSD: src/lib/libc/stdlib/random.c,v 1.24 2004/01/20 03:02:18 das Exp $");
    3939
    4040#include "namespace.h"
    4141#include <sys/time.h>          /* for srandomdev() */
    4242#include <fcntl.h>             /* for srandomdev() */
     43#include <stdint.h>
    4344#include <stdio.h>
    4445#include <stdlib.h>
     
    6263 * 32 bytes, a simple linear congruential R.N.G. is used.
    6364 *
    64  * Internally, the state information is treated as an array of longs; the
     65 * Internally, the state information is treated as an array of uint32_t's; the
    6566 * zeroeth element of the array is the type of R.N.G. being used (small
    6667 * integer); the remainder of the array is the state information for the
    67  * R.N.G.  Thus, 32 bytes of state information will give 7 longs worth of
     68 * R.N.G.  Thus, 32 bytes of state information will give 7 ints worth of
    6869 * state information, which will allow a degree seven polynomial.  (Note:
    6970 * the zeroeth word of state information also has some other information
     
    143144#define MAX_TYPES       5               /* max number of types above */
    144145
    145 #define NSHUFF 100      /* to drop part of seed -> 1st value correlation */
    146 
    147 static long degrees[MAX_TYPES] =        { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
    148 static long seps [MAX_TYPES] =  { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
     146#ifdef  USE_WEAK_SEEDING
     147#define NSHUFF 0
     148#else   /* !USE_WEAK_SEEDING */
     149#define NSHUFF 50       /* to drop some "seed -> 1st value" linearity */
     150#endif  /* !USE_WEAK_SEEDING */
     151
     152static const int degrees[MAX_TYPES] =   { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
     153static const int seps [MAX_TYPES] =     { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
    149154
    150155/*
     
    162167 */
    163168
    164 static long randtbl[DEG_3 + 1] = {
     169static uint32_t randtbl[DEG_3 + 1] = {
    165170        TYPE_3,
    166171#ifdef  USE_WEAK_SEEDING
     
    197202 * to point to randtbl[1] (as explained below).
    198203 */
    199 static long *fptr = &randtbl[SEP_3 + 1];
    200 static long *rptr = &randtbl[1];
     204static uint32_t *fptr = &randtbl[SEP_3 + 1];
     205static uint32_t *rptr = &randtbl[1];
    201206
    202207/*
     
    210215 * the last element to see if the front and rear pointers have wrapped.
    211216 */
    212 static long *state = &randtbl[1];
    213 static long rand_type = TYPE_3;
    214 static long rand_deg = DEG_3;
    215 static long rand_sep = SEP_3;
    216 static long *end_ptr = &randtbl[DEG_3 + 1];
    217 
    218 static inline long good_rand(long);
    219 
    220 static inline long good_rand (x)
    221         long x;
     217static uint32_t *state = &randtbl[1];
     218static int rand_type = TYPE_3;
     219static int rand_deg = DEG_3;
     220static int rand_sep = SEP_3;
     221static uint32_t *end_ptr = &randtbl[DEG_3 + 1];
     222
     223static inline uint32_t good_rand(int32_t);
     224
     225static inline uint32_t good_rand (x)
     226        int32_t x;
    222227{
    223228#ifdef  USE_WEAK_SEEDING
     
    237242 * October 1988, p. 1195.
    238243 */
    239         long hi, lo;
     244        int32_t hi, lo;
    240245
    241246        /* Can't be initialized with 0, so use another value. */
     
    267272        unsigned long x;
    268273{
    269         long i, lim;
    270 
    271         state[0] = x;
     274        int i, lim;
     275
     276        state[0] = (uint32_t)x;
    272277        if (rand_type == TYPE_0)
    273278                lim = NSHUFF;
     
    347352 * Returns a pointer to the old state.
    348353 *
    349  * Note: The Sparc platform requires that arg_state begin on a long
     354 * Note: The Sparc platform requires that arg_state begin on an int
    350355 * word boundary; otherwise a bus error will occur. Even so, lint will
    351356 * complain about mis-alignment, but you should disregard these messages.
     
    358363{
    359364        char *ostate = (char *)(&state[-1]);
    360         long *long_arg_state = (long *) arg_state;
     365        uint32_t *int_arg_state = (uint32_t *)arg_state;
    361366
    362367        if (rand_type == TYPE_0)
     
    390395                rand_sep = SEP_4;
    391396        }
    392         state = (long *) (long_arg_state + 1); /* first location */
     397        state = int_arg_state + 1; /* first location */
    393398        end_ptr = &state[rand_deg];     /* must set end_ptr before srandom */
    394399        srandom(seed);
    395400        if (rand_type == TYPE_0)
    396                 long_arg_state[0] = rand_type;
     401                int_arg_state[0] = rand_type;
    397402        else
    398                 long_arg_state[0] = MAX_TYPES * (rptr - state) + rand_type;
     403                int_arg_state[0] = MAX_TYPES * (rptr - state) + rand_type;
    399404        return(ostate);
    400405}
     
    415420 * Returns a pointer to the old state information.
    416421 *
    417  * Note: The Sparc platform requires that arg_state begin on a long
     422 * Note: The Sparc platform requires that arg_state begin on an int
    418423 * word boundary; otherwise a bus error will occur. Even so, lint will
    419424 * complain about mis-alignment, but you should disregard these messages.
     
    423428        char *arg_state;                /* pointer to state array */
    424429{
    425         long *new_state = (long *) arg_state;
    426         long type = new_state[0] % MAX_TYPES;
    427         long rear = new_state[0] / MAX_TYPES;
     430        uint32_t *new_state = (uint32_t *)arg_state;
     431        uint32_t type = new_state[0] % MAX_TYPES;
     432        uint32_t rear = new_state[0] / MAX_TYPES;
    428433        char *ostate = (char *)(&state[-1]);
    429434
     
    446451                    "random: state info corrupted; not changed.\n");
    447452        }
    448         state = (long *) (new_state + 1);
     453        state = new_state + 1;
    449454        if (rand_type != TYPE_0) {
    450455                rptr = &state[rear];
     
    475480random()
    476481{
    477         long i;
    478         long *f, *r;
     482        uint32_t i;
     483        uint32_t *f, *r;
    479484
    480485        if (rand_type == TYPE_0) {
     
    498503                fptr = f; rptr = r;
    499504        }
    500         return(i);
     505        return((long)i);
    501506}
Note: See TracChangeset for help on using the changeset viewer.