Module Name: src Committed By: ad Date: Sat Feb 29 20:17:43 UTC 2020
Modified Files: src/common/lib/libc/gen [ad-namecache]: radixtree.c src/common/lib/libc/stdlib [ad-namecache]: random.c src/common/lib/libc/string [ad-namecache]: bcmp.c memcmp.c Removed Files: src/common/lib/libc/arch/i386/string [ad-namecache]: memcmp.S src/common/lib/libc/arch/x86_64/string [ad-namecache]: bcmp.S memcmp.S Log Message: Sync with head. To generate a diff of this commit: cvs rdiff -u -r1.3 -r0 src/common/lib/libc/arch/i386/string/memcmp.S cvs rdiff -u -r1.3 -r0 src/common/lib/libc/arch/x86_64/string/bcmp.S \ src/common/lib/libc/arch/x86_64/string/memcmp.S cvs rdiff -u -r1.20 -r1.20.2.1 src/common/lib/libc/gen/radixtree.c cvs rdiff -u -r1.5 -r1.5.20.1 src/common/lib/libc/stdlib/random.c cvs rdiff -u -r1.7 -r1.7.38.1 src/common/lib/libc/string/bcmp.c cvs rdiff -u -r1.5 -r1.5.8.1 src/common/lib/libc/string/memcmp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/common/lib/libc/gen/radixtree.c diff -u src/common/lib/libc/gen/radixtree.c:1.20 src/common/lib/libc/gen/radixtree.c:1.20.2.1 --- src/common/lib/libc/gen/radixtree.c:1.20 Thu Dec 5 19:03:39 2019 +++ src/common/lib/libc/gen/radixtree.c Sat Feb 29 20:17:43 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: radixtree.c,v 1.20 2019/12/05 19:03:39 ad Exp $ */ +/* $NetBSD: radixtree.c,v 1.20.2.1 2020/02/29 20:17:43 ad Exp $ */ /*- * Copyright (c)2011,2012,2013 YAMAMOTO Takashi, @@ -112,7 +112,7 @@ #include <sys/cdefs.h> #if defined(_KERNEL) || defined(_STANDALONE) -__KERNEL_RCSID(0, "$NetBSD: radixtree.c,v 1.20 2019/12/05 19:03:39 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: radixtree.c,v 1.20.2.1 2020/02/29 20:17:43 ad Exp $"); #include <sys/param.h> #include <sys/errno.h> #include <sys/pool.h> @@ -122,7 +122,7 @@ __KERNEL_RCSID(0, "$NetBSD: radixtree.c, #include <lib/libsa/stand.h> #endif /* defined(_STANDALONE) */ #else /* defined(_KERNEL) || defined(_STANDALONE) */ -__RCSID("$NetBSD: radixtree.c,v 1.20 2019/12/05 19:03:39 ad Exp $"); +__RCSID("$NetBSD: radixtree.c,v 1.20.2.1 2020/02/29 20:17:43 ad Exp $"); #include <assert.h> #include <errno.h> #include <stdbool.h> @@ -345,10 +345,27 @@ radix_tree_init(void) { radix_tree_node_cache = pool_cache_init(sizeof(struct radix_tree_node), - coherency_unit, 0, 0, "radixnode", NULL, IPL_NONE, + coherency_unit, 0, PR_LARGECACHE, "radixnode", NULL, IPL_NONE, radix_tree_node_ctor, NULL, NULL); KASSERT(radix_tree_node_cache != NULL); } + +/* + * radix_tree_await_memory: + * + * after an insert has failed with ENOMEM, wait for memory to become + * available, so the caller can retry. + */ + +void +radix_tree_await_memory(void) +{ + struct radix_tree_node *n; + + n = pool_cache_get(radix_tree_node_cache, PR_WAITOK); + pool_cache_put(radix_tree_node_cache, n); +} + #endif /* defined(_KERNEL) */ static bool __unused @@ -826,34 +843,16 @@ scan_siblings: break; } n = path_node(t, path, lastidx - 1); - /* - * we used to have an integer counter in the node, and this - * optimization made sense then, even though marginal. it - * no longer provides benefit with the structure cache line - * aligned and the counter replaced by an unrolled sequence - * testing the pointers in batch. - */ -#if 0 - if (*vpp != NULL && radix_tree_node_count_ptrs(n) == 1) { - /* - * optimization; if the node has only a single pointer - * and we've already visited it, there's no point to - * keep scanning in this node. - */ - goto no_siblings; - } -#endif /* 0 */ for (i = vpp - n->n_ptrs + step; i != guard; i += step) { KASSERT(i < RADIX_TREE_PTR_PER_NODE); if (entry_match_p(n->n_ptrs[i], tagmask)) { vpp = &n->n_ptrs[i]; break; + } else if (dense) { + return nfound; } } if (i == guard) { -#if 0 -no_siblings: -#endif /* 0 */ /* * not found. go to parent. */ Index: src/common/lib/libc/stdlib/random.c diff -u src/common/lib/libc/stdlib/random.c:1.5 src/common/lib/libc/stdlib/random.c:1.5.20.1 --- src/common/lib/libc/stdlib/random.c:1.5 Mon Feb 8 05:27:24 2016 +++ src/common/lib/libc/stdlib/random.c Sat Feb 29 20:17:43 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: random.c,v 1.5 2016/02/08 05:27:24 dholland Exp $ */ +/* $NetBSD: random.c,v 1.5.20.1 2020/02/29 20:17:43 ad Exp $ */ /* * Copyright (c) 1983, 1993 @@ -35,7 +35,7 @@ #if 0 static char sccsid[] = "@(#)random.c 8.2 (Berkeley) 5/19/95"; #else -__RCSID("$NetBSD: random.c,v 1.5 2016/02/08 05:27:24 dholland Exp $"); +__RCSID("$NetBSD: random.c,v 1.5.20.1 2020/02/29 20:17:43 ad Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -189,7 +189,7 @@ static const int seps[MAX_TYPES] = { SEP */ /* LINTED */ -static int randtbl[DEG_3 + 1] = { +static uint32_t randtbl[DEG_3 + 1] = { TYPE_3, #ifdef USE_BETTER_RANDOM 0x991539b1, 0x16a5bce3, 0x6774a4cd, @@ -232,8 +232,8 @@ static int randtbl[DEG_3 + 1] = { * in the initialization of randtbl) because the state table pointer is set * to point to randtbl[1] (as explained below). */ -static int *fptr = &randtbl[SEP_3 + 1]; -static int *rptr = &randtbl[1]; +static uint32_t *fptr = &randtbl[SEP_3 + 1]; +static uint32_t *rptr = &randtbl[1]; /* * The following things are the pointer to the state information table, the @@ -245,11 +245,11 @@ static int *rptr = &randtbl[1]; * this is more efficient than indexing every time to find the address of * the last element to see if the front and rear pointers have wrapped. */ -static int *state = &randtbl[1]; +static uint32_t *state = &randtbl[1]; static int rand_type = TYPE_3; static int rand_deg = DEG_3; static int rand_sep = SEP_3; -static int *end_ptr = &randtbl[DEG_3 + 1]; +static uint32_t *end_ptr = &randtbl[DEG_3 + 1]; /* * srandom: @@ -340,17 +340,17 @@ initstate( size_t n) /* # bytes of state info */ { void *ostate = (void *)(&state[-1]); - int *int_arg_state; + uint32_t *int_arg_state; _DIAGASSERT(arg_state != NULL); - int_arg_state = (int *)(void *)arg_state; + int_arg_state = (uint32_t *)(void *)arg_state; mutex_lock(&random_mutex); if (rand_type == TYPE_0) state[-1] = rand_type; else - state[-1] = MAX_TYPES * (int)(rptr - state) + rand_type; + state[-1] = MAX_TYPES * (uint32_t)(rptr - state) + rand_type; if (n < BREAK_0) { mutex_unlock(&random_mutex); return (NULL); @@ -375,13 +375,13 @@ initstate( rand_deg = DEG_4; rand_sep = SEP_4; } - state = (int *) (int_arg_state + 1); /* first location */ + state = (uint32_t *) (int_arg_state + 1); /* first location */ end_ptr = &state[rand_deg]; /* must set end_ptr before srandom */ srandom_unlocked(seed); if (rand_type == TYPE_0) int_arg_state[0] = rand_type; else - int_arg_state[0] = MAX_TYPES * (int)(rptr - state) + rand_type; + int_arg_state[0] = MAX_TYPES * (uint32_t)(rptr - state) + rand_type; mutex_unlock(&random_mutex); return((char *)ostate); } @@ -408,22 +408,22 @@ initstate( char * setstate(char *arg_state) /* pointer to state array */ { - int *new_state; - int type; - int rear; + uint32_t *new_state; + uint32_t type; + uint32_t rear; void *ostate = (void *)(&state[-1]); _DIAGASSERT(arg_state != NULL); - new_state = (int *)(void *)arg_state; - type = (int)(new_state[0] % MAX_TYPES); - rear = (int)(new_state[0] / MAX_TYPES); + new_state = (uint32_t *)(void *)arg_state; + type = (uint32_t)(new_state[0] % MAX_TYPES); + rear = (uint32_t)(new_state[0] / MAX_TYPES); mutex_lock(&random_mutex); if (rand_type == TYPE_0) state[-1] = rand_type; else - state[-1] = MAX_TYPES * (int)(rptr - state) + rand_type; + state[-1] = MAX_TYPES * (uint32_t)(rptr - state) + rand_type; switch(type) { case TYPE_0: case TYPE_1: @@ -438,7 +438,7 @@ setstate(char *arg_state) /* pointer to mutex_unlock(&random_mutex); return (NULL); } - state = (int *) (new_state + 1); + state = (uint32_t *) (new_state + 1); if (rand_type != TYPE_0) { rptr = &state[rear]; fptr = &state[(rear + rand_sep) % rand_deg]; @@ -468,8 +468,8 @@ setstate(char *arg_state) /* pointer to static long random_unlocked(void) { - int i; - int *f, *r; + uint32_t i; + uint32_t *f, *r; if (rand_type == TYPE_0) { i = state[0]; @@ -481,7 +481,7 @@ random_unlocked(void) f = fptr; r = rptr; *f += *r; /* chucking least random bit */ - i = ((unsigned int)*f >> 1) & 0x7fffffff; + i = ((uint32_t)*f >> 1) & 0x7fffffff; if (++f >= end_ptr) { f = state; ++r; Index: src/common/lib/libc/string/bcmp.c diff -u src/common/lib/libc/string/bcmp.c:1.7 src/common/lib/libc/string/bcmp.c:1.7.38.1 --- src/common/lib/libc/string/bcmp.c:1.7 Fri Mar 9 15:41:16 2012 +++ src/common/lib/libc/string/bcmp.c Sat Feb 29 20:17:43 2020 @@ -1,4 +1,33 @@ -/* $NetBSD: bcmp.c,v 1.7 2012/03/09 15:41:16 christos Exp $ */ +/* $NetBSD: bcmp.c,v 1.7.38.1 2020/02/29 20:17:43 ad Exp $ */ + +/*- + * Copyright (c) 2020 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ /* * Copyright (c) 1987, 1993 @@ -34,7 +63,7 @@ #if 0 static char sccsid[] = "@(#)bcmp.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: bcmp.c,v 1.7 2012/03/09 15:41:16 christos Exp $"); +__RCSID("$NetBSD: bcmp.c,v 1.7.38.1 2020/02/29 20:17:43 ad Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -45,6 +74,8 @@ __RCSID("$NetBSD: bcmp.c,v 1.7 2012/03/0 #include <lib/libsa/stand.h> #endif #else +#include <sys/types.h> + #include <assert.h> #include <string.h> #endif @@ -53,18 +84,40 @@ __RCSID("$NetBSD: bcmp.c,v 1.7 2012/03/0 * bcmp -- vax cmpc3 instruction */ int -bcmp(const void *b1, const void *b2, size_t length) +bcmp(const void *s1, const void *s2, size_t n) { - const char *p1 = b1, *p2 = b2; + const unsigned char *c1, *c2; + +#ifndef _STANDALONE + const uintptr_t *b1, *b2; + + b1 = s1; + b2 = s2; + +#ifndef __NO_STRICT_ALIGNMENT + if ((((uintptr_t)b1 | (uintptr_t)b2) & (sizeof(uintptr_t) - 1)) == 0) +#endif + { + while (n >= sizeof(uintptr_t)) { + if (*b1++ != *b2++) + return 1; + n -= sizeof(uintptr_t); + } + } + + c1 = (const unsigned char *)b1; + c2 = (const unsigned char *)b2; +#else + c1 = (const unsigned char *)s1; + c2 = (const unsigned char *)s2; +#endif - _DIAGASSERT(b1 != 0); - _DIAGASSERT(b2 != 0); + if (n != 0) { + do { + if (*c1++ != *c2++) + return 1; + } while (--n != 0); + } - if (length == 0) - return(0); - do - if (*p1++ != *p2++) - break; - while (--length); - return length != 0; + return 0; } Index: src/common/lib/libc/string/memcmp.c diff -u src/common/lib/libc/string/memcmp.c:1.5 src/common/lib/libc/string/memcmp.c:1.5.8.1 --- src/common/lib/libc/string/memcmp.c:1.5 Sun Feb 4 20:22:17 2018 +++ src/common/lib/libc/string/memcmp.c Sat Feb 29 20:17:43 2020 @@ -1,4 +1,33 @@ -/* $NetBSD: memcmp.c,v 1.5 2018/02/04 20:22:17 mrg Exp $ */ +/* $NetBSD: memcmp.c,v 1.5.8.1 2020/02/29 20:17:43 ad Exp $ */ + +/*- + * Copyright (c) 2020 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ /*- * Copyright (c) 1990, 1993 @@ -37,11 +66,13 @@ #if 0 static char sccsid[] = "@(#)memcmp.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: memcmp.c,v 1.5 2018/02/04 20:22:17 mrg Exp $"); +__RCSID("$NetBSD: memcmp.c,v 1.5.8.1 2020/02/29 20:17:43 ad Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #if !defined(_KERNEL) && !defined(_STANDALONE) +#include <sys/types.h> + #include <assert.h> #include <string.h> #else @@ -55,16 +86,42 @@ __RCSID("$NetBSD: memcmp.c,v 1.5 2018/02 int memcmp(const void *s1, const void *s2, size_t n) { + const unsigned char *c1, *c2; - if (n != 0) { - const unsigned char *p1 = s1, *p2 = s2; +#ifndef _STANDALONE + const uintptr_t *b1, *b2; + + b1 = s1; + b2 = s2; + +#ifndef __NO_STRICT_ALIGNMENT + if ((((uintptr_t)b1 | (uintptr_t)b2) & (sizeof(uintptr_t) - 1)) == 0) +#endif + { + while (n >= sizeof(uintptr_t)) { + if (*b1 != *b2) + break; + b1++; + b2++; + n -= sizeof(uintptr_t); + } + } + + c1 = (const unsigned char *)b1; + c2 = (const unsigned char *)b2; +#else + c1 = (const unsigned char *)s1; + c2 = (const unsigned char *)s2; +#endif + if (n != 0) { do { - if (*p1++ != *p2++) - return (*--p1 - *--p2); + if (*c1++ != *c2++) + return *--c1 - *--c2; } while (--n != 0); } - return (0); + + return 0; } #if defined(__ARM_EABI__)