mirror of git://gcc.gnu.org/git/gcc.git
* sort.c (sort_pointers): Fix endianness bugs.
From-SVN: r33368
This commit is contained in:
parent
a3fbf5c383
commit
b51024fc89
|
@ -1,5 +1,7 @@
|
||||||
2000-04-23 Mark Mitchell <mark@codesourcery.com>
|
2000-04-23 Mark Mitchell <mark@codesourcery.com>
|
||||||
|
|
||||||
|
* sort.c (sort_pointers): Fix endianness bugs.
|
||||||
|
|
||||||
* sort.c: New file.
|
* sort.c: New file.
|
||||||
* Makefile.in (CFILES): Add sort.c
|
* Makefile.in (CFILES): Add sort.c
|
||||||
(REQUIRED_OFILES): Add sort.o.
|
(REQUIRED_OFILES): Add sort.o.
|
||||||
|
|
|
@ -29,9 +29,8 @@ Boston, MA 02111-1307, USA. */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* POINTERSP and WORKP both point to arrays of N pointers. When
|
/* POINTERS and WORK are both arrays of N pointers. When this
|
||||||
this function returns POINTERSP will point to a sorted version of
|
function returns POINTERS will be sorted in ascending order. */
|
||||||
the original array pointed to by POINTERSP. */
|
|
||||||
|
|
||||||
void sort_pointers (n, pointers, work)
|
void sort_pointers (n, pointers, work)
|
||||||
size_t n;
|
size_t n;
|
||||||
|
@ -63,8 +62,11 @@ void sort_pointers (n, pointers, work)
|
||||||
abort ();
|
abort ();
|
||||||
|
|
||||||
/* Figure out the endianness of the machine. */
|
/* Figure out the endianness of the machine. */
|
||||||
for (i = 0; i < sizeof (size_t); ++i)
|
for (i = 0, j = 0; i < sizeof (size_t); ++i)
|
||||||
((char *)&j)[i] = i;
|
{
|
||||||
|
j *= (UCHAR_MAX + 1);
|
||||||
|
j += i;
|
||||||
|
}
|
||||||
big_endian_p = (((char *)&j)[0] == 0);
|
big_endian_p = (((char *)&j)[0] == 0);
|
||||||
|
|
||||||
/* Move through the pointer values from least significant to most
|
/* Move through the pointer values from least significant to most
|
||||||
|
@ -91,8 +93,8 @@ void sort_pointers (n, pointers, work)
|
||||||
/* Compute the address of the appropriate digit in the first and
|
/* Compute the address of the appropriate digit in the first and
|
||||||
one-past-the-end elements of the array. On a little-endian
|
one-past-the-end elements of the array. On a little-endian
|
||||||
machine, the least-significant digit is closest to the front. */
|
machine, the least-significant digit is closest to the front. */
|
||||||
bias = ((digit_t *) pointers) + i;
|
bias = ((digit_t *) pointers) + j;
|
||||||
top = ((digit_t *) (pointers + n)) + i;
|
top = ((digit_t *) (pointers + n)) + j;
|
||||||
|
|
||||||
/* Count how many there are of each value. At the end of this
|
/* Count how many there are of each value. At the end of this
|
||||||
loop, COUNT[K] will contain the number of pointers whose Ith
|
loop, COUNT[K] will contain the number of pointers whose Ith
|
||||||
|
@ -109,7 +111,7 @@ void sort_pointers (n, pointers, work)
|
||||||
|
|
||||||
/* Now, drop the pointers into their correct locations. */
|
/* Now, drop the pointers into their correct locations. */
|
||||||
for (pointerp = pointers + n - 1; pointerp >= pointers; --pointerp)
|
for (pointerp = pointers + n - 1; pointerp >= pointers; --pointerp)
|
||||||
work[--count[((digit_t *) pointerp)[i]]] = *pointerp;
|
work[--count[((digit_t *) pointerp)[j]]] = *pointerp;
|
||||||
|
|
||||||
/* Swap WORK and POINTERS so that POINTERS contains the sorted
|
/* Swap WORK and POINTERS so that POINTERS contains the sorted
|
||||||
array. */
|
array. */
|
||||||
|
|
Loading…
Reference in New Issue