Changeset 1692 for trunk/src


Ignore:
Timestamp:
Dec 3, 2004, 5:05:02 AM (21 years ago)
Author:
bird
Message:

joined with FREEBSD_5-3

Location:
trunk/src/emx/src/lib/bsd/stdlib
Files:
2 edited

Legend:

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

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1691 r1692  
    4040#include "libc-alias.h" /* bird: Get the right mapping of libc functions. */
    4141#include <sys/cdefs.h>
    42 __FBSDID("$FreeBSD: src/lib/libc/stdlib/radixsort.c,v 1.6 2002/03/22 09:18:34 obrien Exp $");
     42__FBSDID("$FreeBSD: src/lib/libc/stdlib/radixsort.c,v 1.7 2003/11/11 04:59:23 kientzle Exp $");
    4343
    4444/*
     
    179179
    180180                /*
     181                 * Special case: if all strings have the same
     182                 * character at position i, move on to the next
     183                 * character.
     184                 */
     185                if (nc == 1 && count[bmin] == n) {
     186                        push(a, n, i+1);
     187                        nc = count[bmin] = 0;
     188                        continue;
     189                }
     190
     191                /*
    181192                 * Set top[]; push incompletely sorted bins onto stack.
    182193                 * top[] = pointers to last out-of-place element in bins.
  • trunk/src/emx/src/lib/bsd/stdlib/random.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1691 r1692  
    3535static char sccsid[] = "@(#)random.c    8.2 (Berkeley) 5/19/95";
    3636#endif /* LIBC_SCCS and not lint */
    37 #include "libc-alias.h" /* bird: Get the right mapping of libc functions. */
    3837#include <sys/cdefs.h>
    39 __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 $");
    4039
    4140#include "namespace.h"
    4241#include <sys/time.h>          /* for srandomdev() */
    4342#include <fcntl.h>             /* for srandomdev() */
     43#include <stdint.h>
    4444#include <stdio.h>
    4545#include <stdlib.h>
     
    6363 * 32 bytes, a simple linear congruential R.N.G. is used.
    6464 *
    65  * 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
    6666 * zeroeth element of the array is the type of R.N.G. being used (small
    6767 * integer); the remainder of the array is the state information for the
    68  * 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
    6969 * state information, which will allow a degree seven polynomial.  (Note:
    7070 * the zeroeth word of state information also has some other information
     
    144144#define MAX_TYPES       5               /* max number of types above */
    145145
    146 #define NSHUFF 100      /* to drop part of seed -> 1st value correlation */
    147 
    148 static long degrees[MAX_TYPES] =        { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
    149 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 };
    150154
    151155/*
     
    163167 */
    164168
    165 static long randtbl[DEG_3 + 1] = {
     169static uint32_t randtbl[DEG_3 + 1] = {
    166170        TYPE_3,
    167171#ifdef  USE_WEAK_SEEDING
     
    198202 * to point to randtbl[1] (as explained below).
    199203 */
    200 static long *fptr = &randtbl[SEP_3 + 1];
    201 static long *rptr = &randtbl[1];
     204static uint32_t *fptr = &randtbl[SEP_3 + 1];
     205static uint32_t *rptr = &randtbl[1];
    202206
    203207/*
     
    211215 * the last element to see if the front and rear pointers have wrapped.
    212216 */
    213 static long *state = &randtbl[1];
    214 static long rand_type = TYPE_3;
    215 static long rand_deg = DEG_3;
    216 static long rand_sep = SEP_3;
    217 static long *end_ptr = &randtbl[DEG_3 + 1];
    218 
    219 static inline long good_rand(long);
    220 
    221 static inline long good_rand (x)
    222         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;
    223227{
    224228#ifdef  USE_WEAK_SEEDING
     
    238242 * October 1988, p. 1195.
    239243 */
    240         long hi, lo;
     244        int32_t hi, lo;
    241245
    242246        /* Can't be initialized with 0, so use another value. */
     
    265269 */
    266270void
    267 srandom(x)
     271_STD(srandom)(x)
    268272        unsigned long x;
    269273{
    270         long i, lim;
    271 
    272         state[0] = x;
     274        int i, lim;
     275
     276        state[0] = (uint32_t)x;
    273277        if (rand_type == TYPE_0)
    274278                lim = NSHUFF;
     
    348352 * Returns a pointer to the old state.
    349353 *
    350  * 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
    351355 * word boundary; otherwise a bus error will occur. Even so, lint will
    352356 * complain about mis-alignment, but you should disregard these messages.
    353357 */
    354358char *
    355 initstate(seed, arg_state, n)
     359_STD(initstate)(seed, arg_state, n)
    356360        unsigned long seed;             /* seed for R.N.G. */
    357361        char *arg_state;                /* pointer to state array */
     
    359363{
    360364        char *ostate = (char *)(&state[-1]);
    361         long *long_arg_state = (long *) arg_state;
     365        uint32_t *int_arg_state = (uint32_t *)arg_state;
    362366
    363367        if (rand_type == TYPE_0)
     
    391395                rand_sep = SEP_4;
    392396        }
    393         state = (long *) (long_arg_state + 1); /* first location */
     397        state = int_arg_state + 1; /* first location */
    394398        end_ptr = &state[rand_deg];     /* must set end_ptr before srandom */
    395399        srandom(seed);
    396400        if (rand_type == TYPE_0)
    397                 long_arg_state[0] = rand_type;
     401                int_arg_state[0] = rand_type;
    398402        else
    399                 long_arg_state[0] = MAX_TYPES * (rptr - state) + rand_type;
     403                int_arg_state[0] = MAX_TYPES * (rptr - state) + rand_type;
    400404        return(ostate);
    401405}
     
    416420 * Returns a pointer to the old state information.
    417421 *
    418  * 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
    419423 * word boundary; otherwise a bus error will occur. Even so, lint will
    420424 * complain about mis-alignment, but you should disregard these messages.
    421425 */
    422426char *
    423 setstate(arg_state)
     427_STD(setstate)(arg_state)
    424428        char *arg_state;                /* pointer to state array */
    425429{
    426         long *new_state = (long *) arg_state;
    427         long type = new_state[0] % MAX_TYPES;
    428         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;
    429433        char *ostate = (char *)(&state[-1]);
    430434
     
    447451                    "random: state info corrupted; not changed.\n");
    448452        }
    449         state = (long *) (new_state + 1);
     453        state = new_state + 1;
    450454        if (rand_type != TYPE_0) {
    451455                rptr = &state[rear];
     
    474478 */
    475479long
    476 random()
     480_STD(random)()
    477481{
    478         long i;
    479         long *f, *r;
     482        uint32_t i;
     483        uint32_t *f, *r;
    480484
    481485        if (rand_type == TYPE_0) {
     
    499503                fptr = f; rptr = r;
    500504        }
    501         return(i);
     505        return((long)i);
    502506}
Note: See TracChangeset for help on using the changeset viewer.