|
Packit |
6c4009 |
/* Hardware capability support for run-time dynamic loader.
|
|
Packit |
6c4009 |
Copyright (C) 2012-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <assert.h>
|
|
Packit |
6c4009 |
#include <elf.h>
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <libintl.h>
|
|
Packit |
6c4009 |
#include <unistd.h>
|
|
Packit |
6c4009 |
#include <ldsodefs.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <dl-procinfo.h>
|
|
Packit |
6c4009 |
#include <dl-hwcaps.h>
|
|
Packit |
6c4009 |
|
|
Packit Service |
2bb319 |
/* This is the result of counting the substrings in a colon-separated
|
|
Packit Service |
2bb319 |
hwcaps string. */
|
|
Packit Service |
2bb319 |
struct hwcaps_counts
|
|
Packit Service |
2bb319 |
{
|
|
Packit Service |
2bb319 |
/* Number of substrings. */
|
|
Packit Service |
2bb319 |
size_t count;
|
|
Packit Service |
2bb319 |
|
|
Packit Service |
2bb319 |
/* Sum of the individual substring lengths (without separators or
|
|
Packit Service |
2bb319 |
null terminators). */
|
|
Packit Service |
2bb319 |
size_t total_length;
|
|
Packit Service |
2bb319 |
|
|
Packit Service |
2bb319 |
/* Maximum length of an individual substring. */
|
|
Packit Service |
2bb319 |
size_t maximum_length;
|
|
Packit Service |
2bb319 |
};
|
|
Packit Service |
2bb319 |
|
|
Packit Service |
2bb319 |
/* Update *COUNTS according to the contents of HWCAPS. Skip over
|
|
Packit Service |
2bb319 |
entries whose bit is not set in MASK. */
|
|
Packit Service |
2bb319 |
static void
|
|
Packit Service |
2bb319 |
update_hwcaps_counts (struct hwcaps_counts *counts, const char *hwcaps,
|
|
Packit Service |
2bb319 |
uint32_t bitmask, const char *mask)
|
|
Packit Service |
2bb319 |
{
|
|
Packit Service |
2bb319 |
struct dl_hwcaps_split_masked sp;
|
|
Packit Service |
2bb319 |
_dl_hwcaps_split_masked_init (&sp, hwcaps, bitmask, mask);
|
|
Packit Service |
2bb319 |
while (_dl_hwcaps_split_masked (&sp))
|
|
Packit Service |
2bb319 |
{
|
|
Packit Service |
2bb319 |
++counts->count;
|
|
Packit Service |
2bb319 |
counts->total_length += sp.split.length;
|
|
Packit Service |
2bb319 |
if (sp.split.length > counts->maximum_length)
|
|
Packit Service |
2bb319 |
counts->maximum_length = sp.split.length;
|
|
Packit Service |
2bb319 |
}
|
|
Packit Service |
2bb319 |
}
|
|
Packit Service |
2bb319 |
|
|
Packit Service |
2bb319 |
/* State for copy_hwcaps. Must be initialized to point to
|
|
Packit Service |
2bb319 |
the storage areas for the array and the strings themselves. */
|
|
Packit Service |
2bb319 |
struct copy_hwcaps
|
|
Packit Service |
2bb319 |
{
|
|
Packit Service |
2bb319 |
struct r_strlenpair *next_pair;
|
|
Packit Service |
2bb319 |
char *next_string;
|
|
Packit Service |
2bb319 |
};
|
|
Packit Service |
2bb319 |
|
|
Packit Service |
2bb319 |
/* Copy HWCAPS into the string pairs and strings, advancing *TARGET.
|
|
Packit Service |
2bb319 |
Skip over entries whose bit is not set in MASK. */
|
|
Packit Service |
2bb319 |
static void
|
|
Packit Service |
2bb319 |
copy_hwcaps (struct copy_hwcaps *target, const char *hwcaps,
|
|
Packit Service |
2bb319 |
uint32_t bitmask, const char *mask)
|
|
Packit Service |
2bb319 |
{
|
|
Packit Service |
2bb319 |
struct dl_hwcaps_split_masked sp;
|
|
Packit Service |
2bb319 |
_dl_hwcaps_split_masked_init (&sp, hwcaps, bitmask, mask);
|
|
Packit Service |
2bb319 |
while (_dl_hwcaps_split_masked (&sp))
|
|
Packit Service |
2bb319 |
{
|
|
Packit Service |
2bb319 |
target->next_pair->str = target->next_string;
|
|
Packit Service |
2bb319 |
char *slash = __mempcpy (__mempcpy (target->next_string,
|
|
Packit Service |
2bb319 |
GLIBC_HWCAPS_PREFIX,
|
|
Packit Service |
2bb319 |
strlen (GLIBC_HWCAPS_PREFIX)),
|
|
Packit Service |
2bb319 |
sp.split.segment, sp.split.length);
|
|
Packit Service |
2bb319 |
*slash = '/';
|
|
Packit Service |
2bb319 |
target->next_pair->len
|
|
Packit Service |
2bb319 |
= strlen (GLIBC_HWCAPS_PREFIX) + sp.split.length + 1;
|
|
Packit Service |
2bb319 |
++target->next_pair;
|
|
Packit Service |
2bb319 |
target->next_string = slash + 1;
|
|
Packit Service |
2bb319 |
}
|
|
Packit Service |
2bb319 |
}
|
|
Packit Service |
2bb319 |
|
|
Packit Service |
ef9500 |
struct dl_hwcaps_priority *_dl_hwcaps_priorities;
|
|
Packit Service |
ef9500 |
uint32_t _dl_hwcaps_priorities_length;
|
|
Packit Service |
ef9500 |
|
|
Packit Service |
ef9500 |
/* Allocate _dl_hwcaps_priorities and fill it with data. */
|
|
Packit Service |
ef9500 |
static void
|
|
Packit Service |
ef9500 |
compute_priorities (size_t total_count, const char *prepend,
|
|
Packit Service |
ef9500 |
uint32_t bitmask, const char *mask)
|
|
Packit Service |
ef9500 |
{
|
|
Packit Service |
ef9500 |
_dl_hwcaps_priorities = malloc (total_count
|
|
Packit Service |
ef9500 |
* sizeof (*_dl_hwcaps_priorities));
|
|
Packit Service |
ef9500 |
if (_dl_hwcaps_priorities == NULL)
|
|
Packit Service |
ef9500 |
_dl_signal_error (ENOMEM, NULL, NULL,
|
|
Packit Service |
ef9500 |
N_("cannot create HWCAP priorities"));
|
|
Packit Service |
ef9500 |
_dl_hwcaps_priorities_length = total_count;
|
|
Packit Service |
ef9500 |
|
|
Packit Service |
ef9500 |
/* First the prepended subdirectories. */
|
|
Packit Service |
ef9500 |
size_t i = 0;
|
|
Packit Service |
ef9500 |
{
|
|
Packit Service |
ef9500 |
struct dl_hwcaps_split sp;
|
|
Packit Service |
ef9500 |
_dl_hwcaps_split_init (&sp, prepend);
|
|
Packit Service |
ef9500 |
while (_dl_hwcaps_split (&sp))
|
|
Packit Service |
ef9500 |
{
|
|
Packit Service |
ef9500 |
_dl_hwcaps_priorities[i].name = sp.segment;
|
|
Packit Service |
ef9500 |
_dl_hwcaps_priorities[i].name_length = sp.length;
|
|
Packit Service |
ef9500 |
_dl_hwcaps_priorities[i].priority = i + 1;
|
|
Packit Service |
ef9500 |
++i;
|
|
Packit Service |
ef9500 |
}
|
|
Packit Service |
ef9500 |
}
|
|
Packit Service |
ef9500 |
|
|
Packit Service |
ef9500 |
/* Then the built-in subdirectories that are actually active. */
|
|
Packit Service |
ef9500 |
{
|
|
Packit Service |
ef9500 |
struct dl_hwcaps_split_masked sp;
|
|
Packit Service |
ef9500 |
_dl_hwcaps_split_masked_init (&sp, _dl_hwcaps_subdirs, bitmask, mask);
|
|
Packit Service |
ef9500 |
while (_dl_hwcaps_split_masked (&sp))
|
|
Packit Service |
ef9500 |
{
|
|
Packit Service |
ef9500 |
_dl_hwcaps_priorities[i].name = sp.split.segment;
|
|
Packit Service |
ef9500 |
_dl_hwcaps_priorities[i].name_length = sp.split.length;
|
|
Packit Service |
ef9500 |
_dl_hwcaps_priorities[i].priority = i + 1;
|
|
Packit Service |
ef9500 |
++i;
|
|
Packit Service |
ef9500 |
}
|
|
Packit Service |
ef9500 |
}
|
|
Packit Service |
ef9500 |
assert (i == total_count);
|
|
Packit Service |
ef9500 |
}
|
|
Packit Service |
ef9500 |
|
|
Packit Service |
ef9500 |
/* Sort the _dl_hwcaps_priorities array by name. */
|
|
Packit Service |
ef9500 |
static void
|
|
Packit Service |
ef9500 |
sort_priorities_by_name (void)
|
|
Packit Service |
ef9500 |
{
|
|
Packit Service |
ef9500 |
/* Insertion sort. There is no need to link qsort into the dynamic
|
|
Packit Service |
ef9500 |
loader for such a short array. */
|
|
Packit Service |
ef9500 |
for (size_t i = 1; i < _dl_hwcaps_priorities_length; ++i)
|
|
Packit Service |
ef9500 |
for (size_t j = i; j > 0; --j)
|
|
Packit Service |
ef9500 |
{
|
|
Packit Service |
ef9500 |
struct dl_hwcaps_priority *previous = _dl_hwcaps_priorities + j - 1;
|
|
Packit Service |
ef9500 |
struct dl_hwcaps_priority *current = _dl_hwcaps_priorities + j;
|
|
Packit Service |
ef9500 |
|
|
Packit Service |
ef9500 |
/* Bail out if current is greater or equal to the previous
|
|
Packit Service |
ef9500 |
value. */
|
|
Packit Service |
ef9500 |
uint32_t to_compare;
|
|
Packit Service |
ef9500 |
if (current->name_length < previous->name_length)
|
|
Packit Service |
ef9500 |
to_compare = current->name_length;
|
|
Packit Service |
ef9500 |
else
|
|
Packit Service |
ef9500 |
to_compare = previous->name_length;
|
|
Packit Service |
ef9500 |
int cmp = memcmp (current->name, previous->name, to_compare);
|
|
Packit Service |
ef9500 |
if (cmp >= 0
|
|
Packit Service |
ef9500 |
|| (cmp == 0 && current->name_length >= previous->name_length))
|
|
Packit Service |
ef9500 |
break;
|
|
Packit Service |
ef9500 |
|
|
Packit Service |
ef9500 |
/* Swap *previous and *current. */
|
|
Packit Service |
ef9500 |
struct dl_hwcaps_priority tmp = *previous;
|
|
Packit Service |
ef9500 |
*previous = *current;
|
|
Packit Service |
ef9500 |
*current = tmp;
|
|
Packit Service |
ef9500 |
}
|
|
Packit Service |
ef9500 |
}
|
|
Packit Service |
ef9500 |
|
|
Packit |
6c4009 |
/* Return an array of useful/necessary hardware capability names. */
|
|
Packit |
6c4009 |
const struct r_strlenpair *
|
|
Packit Service |
2bb319 |
_dl_important_hwcaps (const char *glibc_hwcaps_prepend,
|
|
Packit Service |
2bb319 |
const char *glibc_hwcaps_mask,
|
|
Packit Service |
2bb319 |
size_t *sz, size_t *max_capstrlen)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
uint64_t hwcap_mask = GET_HWCAP_MASK();
|
|
Packit |
6c4009 |
/* Determine how many important bits are set. */
|
|
Packit |
6c4009 |
uint64_t masked = GLRO(dl_hwcap) & hwcap_mask;
|
|
Packit Service |
2e7b30 |
size_t cnt = GLRO (dl_platform) != NULL;
|
|
Packit |
6c4009 |
size_t n, m;
|
|
Packit |
6c4009 |
struct r_strlenpair *result;
|
|
Packit |
6c4009 |
struct r_strlenpair *rp;
|
|
Packit |
6c4009 |
char *cp;
|
|
Packit |
6c4009 |
|
|
Packit Service |
2bb319 |
/* glibc-hwcaps subdirectories. These are exempted from the power
|
|
Packit Service |
2bb319 |
set construction below. */
|
|
Packit Service |
2bb319 |
uint32_t hwcaps_subdirs_active = _dl_hwcaps_subdirs_active ();
|
|
Packit Service |
2bb319 |
struct hwcaps_counts hwcaps_counts = { 0, };
|
|
Packit Service |
2bb319 |
update_hwcaps_counts (&hwcaps_counts, glibc_hwcaps_prepend, -1, NULL);
|
|
Packit Service |
2bb319 |
update_hwcaps_counts (&hwcaps_counts, _dl_hwcaps_subdirs,
|
|
Packit Service |
2bb319 |
hwcaps_subdirs_active, glibc_hwcaps_mask);
|
|
Packit Service |
ef9500 |
compute_priorities (hwcaps_counts.count, glibc_hwcaps_prepend,
|
|
Packit Service |
ef9500 |
hwcaps_subdirs_active, glibc_hwcaps_mask);
|
|
Packit Service |
ef9500 |
sort_priorities_by_name ();
|
|
Packit Service |
2bb319 |
|
|
Packit Service |
2bb319 |
/* Each hwcaps subdirectory has a GLIBC_HWCAPS_PREFIX string prefix
|
|
Packit Service |
2bb319 |
and a "/" suffix once stored in the result. */
|
|
Packit Service |
2bb319 |
size_t total = (hwcaps_counts.count * (strlen (GLIBC_HWCAPS_PREFIX) + 1)
|
|
Packit Service |
2bb319 |
+ hwcaps_counts.total_length);
|
|
Packit Service |
2bb319 |
|
|
Packit |
6c4009 |
/* Count the number of bits set in the masked value. */
|
|
Packit |
6c4009 |
for (n = 0; (~((1ULL << n) - 1) & masked) != 0; ++n)
|
|
Packit |
6c4009 |
if ((masked & (1ULL << n)) != 0)
|
|
Packit |
6c4009 |
++cnt;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* For TLS enabled builds always add 'tls'. */
|
|
Packit |
6c4009 |
++cnt;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Create temporary data structure to generate result table. */
|
|
Packit |
6c4009 |
struct r_strlenpair temp[cnt];
|
|
Packit |
6c4009 |
m = 0;
|
|
Packit |
6c4009 |
for (n = 0; masked != 0; ++n)
|
|
Packit |
6c4009 |
if ((masked & (1ULL << n)) != 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
temp[m].str = _dl_hwcap_string (n);
|
|
Packit |
6c4009 |
temp[m].len = strlen (temp[m].str);
|
|
Packit |
6c4009 |
masked ^= 1ULL << n;
|
|
Packit |
6c4009 |
++m;
|
|
Packit |
6c4009 |
}
|
|
Packit Service |
2e7b30 |
if (GLRO (dl_platform) != NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit Service |
2e7b30 |
temp[m].str = GLRO (dl_platform);
|
|
Packit Service |
2e7b30 |
temp[m].len = GLRO (dl_platformlen);
|
|
Packit |
6c4009 |
++m;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
temp[m].str = "tls";
|
|
Packit |
6c4009 |
temp[m].len = 3;
|
|
Packit |
6c4009 |
++m;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
assert (m == cnt);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Determine the total size of all strings together. */
|
|
Packit |
6c4009 |
if (cnt == 1)
|
|
Packit Service |
2bb319 |
total += temp[0].len + 1;
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit Service |
2bb319 |
total += temp[0].len + temp[cnt - 1].len + 2;
|
|
Packit |
6c4009 |
if (cnt > 2)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
total <<= 1;
|
|
Packit |
6c4009 |
for (n = 1; n + 1 < cnt; ++n)
|
|
Packit |
6c4009 |
total += temp[n].len + 1;
|
|
Packit |
6c4009 |
if (cnt > 3
|
|
Packit |
6c4009 |
&& (cnt >= sizeof (size_t) * 8
|
|
Packit |
6c4009 |
|| total + (sizeof (*result) << 3)
|
|
Packit |
6c4009 |
>= (1UL << (sizeof (size_t) * 8 - cnt + 3))))
|
|
Packit |
6c4009 |
_dl_signal_error (ENOMEM, NULL, NULL,
|
|
Packit |
6c4009 |
N_("cannot create capability list"));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
total <<= cnt - 3;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit Service |
2bb319 |
*sz = hwcaps_counts.count + (1 << cnt);
|
|
Packit Service |
2bb319 |
|
|
Packit Service |
2bb319 |
/* This is the overall result, including both glibc-hwcaps
|
|
Packit Service |
2bb319 |
subdirectories and the legacy hwcaps subdirectories using the
|
|
Packit Service |
2bb319 |
power set construction. */
|
|
Packit Service |
2bb319 |
struct r_strlenpair *overall_result
|
|
Packit Service |
2bb319 |
= malloc (*sz * sizeof (*result) + total);
|
|
Packit Service |
2bb319 |
if (overall_result == NULL)
|
|
Packit |
6c4009 |
_dl_signal_error (ENOMEM, NULL, NULL,
|
|
Packit |
6c4009 |
N_("cannot create capability list"));
|
|
Packit |
6c4009 |
|
|
Packit Service |
2bb319 |
/* Fill in the glibc-hwcaps subdirectories. */
|
|
Packit Service |
2bb319 |
{
|
|
Packit Service |
2bb319 |
struct copy_hwcaps target;
|
|
Packit Service |
2bb319 |
target.next_pair = overall_result;
|
|
Packit Service |
2bb319 |
target.next_string = (char *) (overall_result + *sz);
|
|
Packit Service |
2bb319 |
copy_hwcaps (&target, glibc_hwcaps_prepend, -1, NULL);
|
|
Packit Service |
2bb319 |
copy_hwcaps (&target, _dl_hwcaps_subdirs,
|
|
Packit Service |
2bb319 |
hwcaps_subdirs_active, glibc_hwcaps_mask);
|
|
Packit Service |
2bb319 |
/* Set up the write target for the power set construction. */
|
|
Packit Service |
2bb319 |
result = target.next_pair;
|
|
Packit Service |
2bb319 |
cp = target.next_string;
|
|
Packit Service |
2bb319 |
}
|
|
Packit Service |
2bb319 |
|
|
Packit Service |
2bb319 |
|
|
Packit Service |
2bb319 |
/* Power set construction begins here. We use a very compressed way
|
|
Packit Service |
2bb319 |
to store the various combinations of capability names. */
|
|
Packit Service |
2bb319 |
|
|
Packit |
6c4009 |
if (cnt == 1)
|
|
Packit |
6c4009 |
{
|
|
Packit Service |
2bb319 |
result[0].str = cp;
|
|
Packit |
6c4009 |
result[0].len = temp[0].len + 1;
|
|
Packit Service |
2bb319 |
result[1].str = cp;
|
|
Packit |
6c4009 |
result[1].len = 0;
|
|
Packit Service |
2bb319 |
cp = __mempcpy (cp, temp[0].str, temp[0].len);
|
|
Packit |
6c4009 |
*cp = '/';
|
|
Packit Service |
2bb319 |
if (result[0].len > hwcaps_counts.maximum_length)
|
|
Packit Service |
2bb319 |
*max_capstrlen = result[0].len;
|
|
Packit Service |
2bb319 |
else
|
|
Packit Service |
2bb319 |
*max_capstrlen = hwcaps_counts.maximum_length;
|
|
Packit |
6c4009 |
|
|
Packit Service |
2bb319 |
return overall_result;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Fill in the information. This follows the following scheme
|
|
Packit |
6c4009 |
(indices from TEMP for four strings):
|
|
Packit |
6c4009 |
entry #0: 0, 1, 2, 3 binary: 1111
|
|
Packit |
6c4009 |
#1: 0, 1, 3 1101
|
|
Packit |
6c4009 |
#2: 0, 2, 3 1011
|
|
Packit |
6c4009 |
#3: 0, 3 1001
|
|
Packit |
6c4009 |
This allows the representation of all possible combinations of
|
|
Packit |
6c4009 |
capability names in the string. First generate the strings. */
|
|
Packit Service |
2bb319 |
result[1].str = result[0].str = cp;
|
|
Packit |
6c4009 |
#define add(idx) \
|
|
Packit |
6c4009 |
cp = __mempcpy (__mempcpy (cp, temp[idx].str, temp[idx].len), "/", 1);
|
|
Packit |
6c4009 |
if (cnt == 2)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
add (1);
|
|
Packit |
6c4009 |
add (0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
n = 1 << (cnt - 1);
|
|
Packit |
6c4009 |
do
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
n -= 2;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* We always add the last string. */
|
|
Packit |
6c4009 |
add (cnt - 1);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Add the strings which have the bit set in N. */
|
|
Packit |
6c4009 |
for (m = cnt - 2; m > 0; --m)
|
|
Packit |
6c4009 |
if ((n & (1 << m)) != 0)
|
|
Packit |
6c4009 |
add (m);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Always add the first string. */
|
|
Packit |
6c4009 |
add (0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
while (n != 0);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#undef add
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Now we are ready to install the string pointers and length. */
|
|
Packit |
6c4009 |
for (n = 0; n < (1UL << cnt); ++n)
|
|
Packit |
6c4009 |
result[n].len = 0;
|
|
Packit |
6c4009 |
n = cnt;
|
|
Packit |
6c4009 |
do
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
size_t mask = 1 << --n;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
rp = result;
|
|
Packit |
6c4009 |
for (m = 1 << cnt; m > 0; ++rp)
|
|
Packit |
6c4009 |
if ((--m & mask) != 0)
|
|
Packit |
6c4009 |
rp->len += temp[n].len + 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
while (n != 0);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The first half of the strings all include the first string. */
|
|
Packit |
6c4009 |
n = (1 << cnt) - 2;
|
|
Packit |
6c4009 |
rp = &result[2];
|
|
Packit |
6c4009 |
while (n != (1UL << (cnt - 1)))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if ((--n & 1) != 0)
|
|
Packit |
6c4009 |
rp[0].str = rp[-2].str + rp[-2].len;
|
|
Packit |
6c4009 |
else
|
|
Packit |
6c4009 |
rp[0].str = rp[-1].str;
|
|
Packit |
6c4009 |
++rp;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The second half starts right after the first part of the string of
|
|
Packit |
6c4009 |
the corresponding entry in the first half. */
|
|
Packit |
6c4009 |
do
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
rp[0].str = rp[-(1 << (cnt - 1))].str + temp[cnt - 1].len + 1;
|
|
Packit |
6c4009 |
++rp;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
while (--n != 0);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* The maximum string length. */
|
|
Packit Service |
2bb319 |
if (result[0].len > hwcaps_counts.maximum_length)
|
|
Packit Service |
2bb319 |
*max_capstrlen = result[0].len;
|
|
Packit Service |
2bb319 |
else
|
|
Packit Service |
2bb319 |
*max_capstrlen = hwcaps_counts.maximum_length;
|
|
Packit |
6c4009 |
|
|
Packit Service |
2bb319 |
return overall_result;
|
|
Packit |
6c4009 |
}
|