* stdlib/stdlib.h (drand48_data): Make available only for
	__USE_MISC.  Rename elements to protect namespace.  Change type
	and position of a and init element.
	* stdlib/drand48-iter.c: Don't handle unsigned short > 16 bit
	differently.  Adjust for drand48_data change.  Don't compute a here,
	it comes from drand48_data.
	* stdlib/lcong48_r.c: Don't handle unsigned short > 16 bit
	differently.  Adjust for drand48_data change.  Compute a here.
	* stdlib/srand48_r.c: Likewise.
	* stdlib/drand48.c: Adjust for drand48_data change.
	* stdlib/lrand48.c: Likewise.
	* stdlib/mrand48.c: Likewise.
	* stdlib/seek48.c: Likewise.
	* stdlib/drand48_r.c: Likewise.
	* stdlib/lrand48_r.c: Likewise.
	* stdlib/mrand48_r.c: Likewise.
	* stdlib/seed48_r.c: Likewise.  Don't handle unsigned short > 16 bit
	differently.
	* stdlib/erand48_r.c: Don't handle unsigned short > 16 bit differently.
	* stdlib/jrand48_r.c: Likewise.
This commit is contained in:
Ulrich Drepper 2001-01-21 16:54:08 +00:00
parent 27cb6b28b9
commit d17c01f9fe
16 changed files with 635 additions and 632 deletions

View File

@ -1,5 +1,26 @@
2001-01-21 Ulrich Drepper <drepper@redhat.com>
* stdlib/stdlib.h (drand48_data): Make available only for
__USE_MISC. Rename elements to protect namespace. Change type
and position of a and init element.
* stdlib/drand48-iter.c: Don't handle unsigned short > 16 bit
differently. Adjust for drand48_data change. Don't compute a here,
it comes from drand48_data.
* stdlib/lcong48_r.c: Don't handle unsigned short > 16 bit
differently. Adjust for drand48_data change. Compute a here.
* stdlib/srand48_r.c: Likewise.
* stdlib/drand48.c: Adjust for drand48_data change.
* stdlib/lrand48.c: Likewise.
* stdlib/mrand48.c: Likewise.
* stdlib/seek48.c: Likewise.
* stdlib/drand48_r.c: Likewise.
* stdlib/lrand48_r.c: Likewise.
* stdlib/mrand48_r.c: Likewise.
* stdlib/seed48_r.c: Likewise. Don't handle unsigned short > 16 bit
differently.
* stdlib/erand48_r.c: Don't handle unsigned short > 16 bit differently.
* stdlib/jrand48_r.c: Likewise.
* po/sv.po: Update from translation team.
2001-01-21 Andreas Jaeger <aj@suse.de>

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
@ -20,6 +20,7 @@
#include <errno.h>
#include <stdlib.h>
#include <limits.h>
#include <stdint.h>
#include <sys/types.h>
/* Global state for non-reentrant functions. */
@ -31,50 +32,28 @@ __drand48_iterate (xsubi, buffer)
unsigned short int xsubi[3];
struct drand48_data *buffer;
{
u_int64_t X, a, result;
uint64_t X;
uint64_t result;
/* Initialize buffer, if not yet done. */
if (!buffer->init)
if (__builtin_expect (!buffer->__init, 0))
{
#if (USHRT_MAX == 0xffffU)
buffer->a[2] = 0x5;
buffer->a[1] = 0xdeec;
buffer->a[0] = 0xe66d;
#else
buffer->a[2] = 0x5deecUL;
buffer->a[1] = 0xe66d0000UL;
buffer->a[0] = 0;
#endif
buffer->c = 0xb;
buffer->init = 1;
buffer->__a = 0x5deece66dull;
buffer->__c = 0xb;
buffer->__init = 1;
}
/* Do the real work. We choose a data type which contains at least
48 bits. Because we compute the modulus it does not care how
many bits really are computed. */
if (sizeof (unsigned short int) == 2)
{
X = (u_int64_t)xsubi[2] << 32 | (u_int64_t)xsubi[1] << 16 | xsubi[0];
a = ((u_int64_t)buffer->a[2] << 32 | (u_int64_t)buffer->a[1] << 16
| buffer->a[0]);
X = (uint64_t) xsubi[2] << 32 | (uint32_t) xsubi[1] << 16 | xsubi[0];
result = X * a + buffer->c;
result = X * buffer->__a + buffer->__c;
xsubi[0] = result & 0xffff;
xsubi[1] = (result >> 16) & 0xffff;
xsubi[2] = (result >> 32) & 0xffff;
}
else
{
X = (u_int64_t)xsubi[2] << 16 | xsubi[1] >> 16;
a = (u_int64_t)buffer->a[2] << 16 | buffer->a[1] >> 16;
result = X * a + buffer->c;
xsubi[0] = result >> 16 & 0xffffffffl;
xsubi[1] = result << 16 & 0xffff0000l;
}
xsubi[0] = result & 0xffff;
xsubi[1] = (result >> 16) & 0xffff;
xsubi[2] = (result >> 32) & 0xffff;
return 0;
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
@ -27,7 +27,7 @@ drand48 ()
{
double result;
(void) __erand48_r (__libc_drand48_data.x, &__libc_drand48_data, &result);
(void) __erand48_r (__libc_drand48_data.__x, &__libc_drand48_data, &result);
return result;
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
@ -26,5 +26,5 @@ drand48_r (buffer, result)
struct drand48_data *buffer;
double *result;
{
return __erand48_r (buffer->x, buffer, result);
return __erand48_r (buffer->__x, buffer, result);
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1995, 1997 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1997, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
@ -37,19 +37,10 @@ __erand48_r (xsubi, buffer, result)
/* Construct a positive double with the 48 random bits distributed over
its fractional part so the resulting FP number is [0.0,1.0). */
#if USHRT_MAX == 65535
temp.ieee.negative = 0;
temp.ieee.exponent = IEEE754_DOUBLE_BIAS;
temp.ieee.mantissa0 = (xsubi[2] << 4) | (xsubi[1] >> 12);
temp.ieee.mantissa1 = ((xsubi[1] & 0xfff) << 20) | (xsubi[0] << 4);
#elif USHRT_MAX == 2147483647
temp.ieee.negative = 0;
temp.ieee.exponent = IEEE754_DOUBLE_BIAS;
temp.ieee.mantissa0 = (xsubi[1] << 4) | (xsubi[0] >> 28);
temp.ieee.mantissa1 = ((xsubi[0] & 0xfffffff) << 4);
#else
# error Unsupported size of short int
#endif
/* Please note the lower 4 bits of mantissa1 are always 0. */
*result = temp.d - 1.0;

View File

@ -30,10 +30,7 @@ __jrand48_r (xsubi, buffer, result)
return -1;
/* Store the result. */
if (sizeof (unsigned short int) == 2)
*result = ((xsubi[2] << 16) | xsubi[1]) & 0xffffffffl;
else
*result = xsubi[2] & 0xffffffffl;
*result = ((xsubi[2] << 16) | xsubi[1]) & 0xffffffffl;
return 0;
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1995, 1997, 1998 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
@ -17,6 +17,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
@ -27,20 +28,11 @@ __lcong48_r (param, buffer)
struct drand48_data *buffer;
{
/* Store the given values. */
#if USHRT_MAX == 0xffffU
memcpy (buffer->x, &param[0], sizeof (buffer->x));
memcpy (buffer->a, &param[3], sizeof (buffer->a));
#else
buffer->x[2] = (param[2] << 16) | param[1];
buffer->x[1] = param[0] << 16;
buffer->x[0] = 0;
buffer->a[2] = (param[5] << 16) | param[4];
buffer->a[1] = param[3] << 16;
buffer->a[0] = 0;
#endif
buffer->c = param[6];
buffer->init = 1;
memcpy (buffer->__x, &param[0], sizeof (buffer->__x));
buffer->__a = ((uint64_t) param[5] << 32 | (uint32_t) param[4] << 16
| param[3]);
buffer->__c = param[6];
buffer->__init = 1;
return 0;
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
@ -27,7 +27,7 @@ lrand48 ()
{
long int result;
(void) __nrand48_r (__libc_drand48_data.x, &__libc_drand48_data, &result);
(void) __nrand48_r (__libc_drand48_data.__x, &__libc_drand48_data, &result);
return result;
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1995, 1997, 1998 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
@ -28,5 +28,5 @@ lrand48_r (buffer, result)
if (buffer == NULL)
return -1;
return __nrand48_r (buffer->x, buffer, result);
return __nrand48_r (buffer->__x, buffer, result);
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
@ -27,7 +27,7 @@ mrand48 ()
{
long int result;
(void) __jrand48_r (__libc_drand48_data.x, &__libc_drand48_data, &result);
(void) __jrand48_r (__libc_drand48_data.__x, &__libc_drand48_data, &result);
return result;
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1995, 1997, 1998 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
@ -28,5 +28,5 @@ mrand48_r (buffer, result)
if (buffer == NULL)
return -1;
return __jrand48_r (buffer->x, buffer, result);
return __jrand48_r (buffer->__x, buffer, result);
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
@ -28,5 +28,5 @@ seed48 (seed16v)
{
(void) __seed48_r (seed16v, &__libc_drand48_data);
return __libc_drand48_data.old_x;
return __libc_drand48_data.__old_x;
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1995, 1997, 1998 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
@ -27,28 +27,15 @@ __seed48_r (seed16v, buffer)
struct drand48_data *buffer;
{
/* Save old value at a private place to be used as return value. */
memcpy (buffer->old_x, buffer->x, sizeof (buffer->x));
memcpy (buffer->__old_x, buffer->__x, sizeof (buffer->__x));
/* Install new state. */
#if USHRT_MAX == 0xffffU
buffer->x[2] = seed16v[2];
buffer->x[1] = seed16v[1];
buffer->x[0] = seed16v[0];
buffer->a[2] = 0x5;
buffer->a[1] = 0xdeec;
buffer->a[0] = 0xe66d;
#else
buffer->x[2] = (seed16v[2] << 16) | seed16v[1];
buffer->x[1] = seed16v[0] << 16;
buffer->x[0] = 0;
buffer->a[2] = 0x5deecUL;
buffer->a[1] = 0xe66d0000UL;
buffer->a[0] = 0;
#endif
buffer->c = 0xb;
buffer->init = 1;
buffer->__x[2] = seed16v[2];
buffer->__x[1] = seed16v[1];
buffer->__x[0] = seed16v[0];
buffer->__a = 0x5deece66dull;
buffer->__c = 0xb;
buffer->__init = 1;
return 0;
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
/* Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
@ -29,25 +29,13 @@ __srand48_r (seedval, buffer)
if (sizeof (long int) > 4)
seedval &= 0xffffffffl;
#if USHRT_MAX == 0xffffU
buffer->x[2] = seedval >> 16;
buffer->x[1] = seedval & 0xffffl;
buffer->x[0] = 0x330e;
buffer->__x[2] = seedval >> 16;
buffer->__x[1] = seedval & 0xffffl;
buffer->__x[0] = 0x330e;
buffer->a[2] = 0x5;
buffer->a[1] = 0xdeec;
buffer->a[0] = 0xe66d;
#else
buffer->x[2] = seedval;
buffer->x[1] = 0x330e0000UL;
buffer->x[0] = 0;
buffer->a[2] = 0x5deecUL;
buffer->a[1] = 0xe66d0000UL;
buffer->a[0] = 0;
#endif
buffer->c = 0xb;
buffer->init = 1;
buffer->__a = 0x5deece66dull;
buffer->__c = 0xb;
buffer->__init = 1;
return 0;
}

View File

@ -474,17 +474,19 @@ extern void srand48 (long int __seedval) __THROW;
extern unsigned short int *seed48 (unsigned short int __seed16v[3]) __THROW;
extern void lcong48 (unsigned short int __param[7]) __THROW;
/* Data structure for communication with thread safe versions. */
# ifdef __USE_MISC
/* Data structure for communication with thread safe versions. This
type is to be regarded as opaque. It's only exported because users
have to allocate objects of this type. */
struct drand48_data
{
unsigned short int x[3]; /* Current state. */
unsigned short int a[3]; /* Factor in congruential formula. */
unsigned short int c; /* Additive const. in congruential formula. */
unsigned short int old_x[3]; /* Old state. */
int init; /* Flag for initializing. */
unsigned short int __x[3]; /* Current state. */
unsigned short int __old_x[3]; /* Old state. */
unsigned short int __c; /* Additive const. in congruential formula. */
unsigned short int __init; /* Flag for initializing. */
unsigned long long int __a; /* Factor in congruential formula. */
};
# ifdef __USE_MISC
/* Return non-negative, double-precision floating-point value in [0.0,1.0). */
extern int drand48_r (struct drand48_data *__restrict __buffer,
double *__restrict __result) __THROW;