aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-01-21 16:54:08 +0000
committerUlrich Drepper <drepper@redhat.com>2001-01-21 16:54:08 +0000
commitd17c01f9fe958d9d78739d3bf7111f2c01690d0d (patch)
tree1d61abad5c2c8666a4e3a45e93ee2367c43c2c60 /stdlib
parent27cb6b28b9cf3f133f17c245dc177a148eedca04 (diff)
downloadglibc-d17c01f9fe958d9d78739d3bf7111f2c01690d0d.tar
glibc-d17c01f9fe958d9d78739d3bf7111f2c01690d0d.tar.gz
glibc-d17c01f9fe958d9d78739d3bf7111f2c01690d0d.tar.bz2
glibc-d17c01f9fe958d9d78739d3bf7111f2c01690d0d.zip
Update.
* 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.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/drand48-iter.c47
-rw-r--r--stdlib/drand48.c4
-rw-r--r--stdlib/drand48_r.c4
-rw-r--r--stdlib/erand48_r.c11
-rw-r--r--stdlib/jrand48_r.c5
-rw-r--r--stdlib/lcong48_r.c22
-rw-r--r--stdlib/lrand48.c4
-rw-r--r--stdlib/lrand48_r.c4
-rw-r--r--stdlib/mrand48.c4
-rw-r--r--stdlib/mrand48_r.c4
-rw-r--r--stdlib/seed48.c4
-rw-r--r--stdlib/seed48_r.c29
-rw-r--r--stdlib/srand48_r.c28
-rw-r--r--stdlib/stdlib.h16
14 files changed, 61 insertions, 125 deletions
diff --git a/stdlib/drand48-iter.c b/stdlib/drand48-iter.c
index 707be8e566..3e8ea0e9c6 100644
--- a/stdlib/drand48-iter.c
+++ b/stdlib/drand48-iter.c
@@ -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]);
-
- result = X * 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;
+ 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 >> 16 & 0xffffffffl;
- xsubi[1] = result << 16 & 0xffff0000l;
- }
+ xsubi[0] = result & 0xffff;
+ xsubi[1] = (result >> 16) & 0xffff;
+ xsubi[2] = (result >> 32) & 0xffff;
return 0;
}
diff --git a/stdlib/drand48.c b/stdlib/drand48.c
index 4668ead152..fe08a08696 100644
--- a/stdlib/drand48.c
+++ b/stdlib/drand48.c
@@ -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;
}
diff --git a/stdlib/drand48_r.c b/stdlib/drand48_r.c
index 066c400f9c..af52924b98 100644
--- a/stdlib/drand48_r.c
+++ b/stdlib/drand48_r.c
@@ -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);
}
diff --git a/stdlib/erand48_r.c b/stdlib/erand48_r.c
index 85393b79f6..3ce78e306e 100644
--- a/stdlib/erand48_r.c
+++ b/stdlib/erand48_r.c
@@ -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;
diff --git a/stdlib/jrand48_r.c b/stdlib/jrand48_r.c
index 9df36942f6..dae1606e95 100644
--- a/stdlib/jrand48_r.c
+++ b/stdlib/jrand48_r.c
@@ -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;
}
diff --git a/stdlib/lcong48_r.c b/stdlib/lcong48_r.c
index 32b948c946..27cab449a5 100644
--- a/stdlib/lcong48_r.c
+++ b/stdlib/lcong48_r.c
@@ -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;
}
diff --git a/stdlib/lrand48.c b/stdlib/lrand48.c
index 1857ed4291..3442549274 100644
--- a/stdlib/lrand48.c
+++ b/stdlib/lrand48.c
@@ -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;
}
diff --git a/stdlib/lrand48_r.c b/stdlib/lrand48_r.c
index 4890923a74..e1fe56cf80 100644
--- a/stdlib/lrand48_r.c
+++ b/stdlib/lrand48_r.c
@@ -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);
}
diff --git a/stdlib/mrand48.c b/stdlib/mrand48.c
index aebb9b0117..fc62fdcf57 100644
--- a/stdlib/mrand48.c
+++ b/stdlib/mrand48.c
@@ -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;
}
diff --git a/stdlib/mrand48_r.c b/stdlib/mrand48_r.c
index 3ed5643e00..32c199e324 100644
--- a/stdlib/mrand48_r.c
+++ b/stdlib/mrand48_r.c
@@ -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);
}
diff --git a/stdlib/seed48.c b/stdlib/seed48.c
index 19bb215529..b6f9a74105 100644
--- a/stdlib/seed48.c
+++ b/stdlib/seed48.c
@@ -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;
}
diff --git a/stdlib/seed48_r.c b/stdlib/seed48_r.c
index 910a2256c6..16706e9136 100644
--- a/stdlib/seed48_r.c
+++ b/stdlib/seed48_r.c
@@ -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;
}
diff --git a/stdlib/srand48_r.c b/stdlib/srand48_r.c
index abaec32e5a..9d0ca76f7c 100644
--- a/stdlib/srand48_r.c
+++ b/stdlib/srand48_r.c
@@ -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->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->__x[2] = seedval >> 16;
+ buffer->__x[1] = seedval & 0xffffl;
+ buffer->__x[0] = 0x330e;
+
+ buffer->__a = 0x5deece66dull;
+ buffer->__c = 0xb;
+ buffer->__init = 1;
return 0;
}
diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h
index de127348bc..17f19ac8d6 100644
--- a/stdlib/stdlib.h
+++ b/stdlib/stdlib.h
@@ -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;