Mon Jan 27 22:22:03 2020 UTC ()
Drop the alignment check if __NO_STRICT_ALIGNMENT (x86, m68k, vax).


(ad)
diff -r1.8 -r1.9 src/common/lib/libc/string/bcmp.c
diff -r1.6 -r1.7 src/common/lib/libc/string/memcmp.c

cvs diff -r1.8 -r1.9 src/common/lib/libc/string/bcmp.c (expand / switch to unified diff)

--- src/common/lib/libc/string/bcmp.c 2020/01/27 22:13:39 1.8
+++ src/common/lib/libc/string/bcmp.c 2020/01/27 22:22:03 1.9
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: bcmp.c,v 1.8 2020/01/27 22:13:39 ad Exp $ */ 1/* $NetBSD: bcmp.c,v 1.9 2020/01/27 22:22:03 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -53,27 +53,27 @@ @@ -53,27 +53,27 @@
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE. 58 * SUCH DAMAGE.
59 */ 59 */
60 60
61#include <sys/cdefs.h> 61#include <sys/cdefs.h>
62#if defined(LIBC_SCCS) && !defined(lint) 62#if defined(LIBC_SCCS) && !defined(lint)
63#if 0 63#if 0
64static char sccsid[] = "@(#)bcmp.c 8.1 (Berkeley) 6/4/93"; 64static char sccsid[] = "@(#)bcmp.c 8.1 (Berkeley) 6/4/93";
65#else 65#else
66__RCSID("$NetBSD: bcmp.c,v 1.8 2020/01/27 22:13:39 ad Exp $"); 66__RCSID("$NetBSD: bcmp.c,v 1.9 2020/01/27 22:22:03 ad Exp $");
67#endif 67#endif
68#endif /* LIBC_SCCS and not lint */ 68#endif /* LIBC_SCCS and not lint */
69 69
70 70
71#if defined(_KERNEL) || defined(_STANDALONE) 71#if defined(_KERNEL) || defined(_STANDALONE)
72#include <lib/libkern/libkern.h> 72#include <lib/libkern/libkern.h>
73#if defined(_STANDALONE) 73#if defined(_STANDALONE)
74#include <lib/libsa/stand.h> 74#include <lib/libsa/stand.h>
75#endif 75#endif
76#else 76#else
77#include <sys/types.h> 77#include <sys/types.h>
78 78
79#include <assert.h> 79#include <assert.h>
@@ -82,27 +82,30 @@ __RCSID("$NetBSD: bcmp.c,v 1.8 2020/01/2 @@ -82,27 +82,30 @@ __RCSID("$NetBSD: bcmp.c,v 1.8 2020/01/2
82 82
83/* 83/*
84 * bcmp -- vax cmpc3 instruction 84 * bcmp -- vax cmpc3 instruction
85 */ 85 */
86int 86int
87bcmp(const void *s1, const void *s2, size_t n) 87bcmp(const void *s1, const void *s2, size_t n)
88{ 88{
89 const uintptr_t *b1, *b2; 89 const uintptr_t *b1, *b2;
90 const unsigned char *c1, *c2; 90 const unsigned char *c1, *c2;
91 91
92 b1 = s1; 92 b1 = s1;
93 b2 = s2; 93 b2 = s2;
94 94
95 if ((((uintptr_t)b1 | (uintptr_t)b2) & (sizeof(uintptr_t) - 1)) == 0) { 95#ifndef __NO_STRICT_ALIGNMENT
 96 if ((((uintptr_t)b1 | (uintptr_t)b2) & (sizeof(uintptr_t) - 1)) == 0)
 97#endif
 98 {
96 while (n >= sizeof(uintptr_t)) { 99 while (n >= sizeof(uintptr_t)) {
97 if (*b1++ != *b2++) 100 if (*b1++ != *b2++)
98 return 1; 101 return 1;
99 n -= sizeof(uintptr_t); 102 n -= sizeof(uintptr_t);
100 } 103 }
101 } 104 }
102 105
103 c1 = (const unsigned char *)b1; 106 c1 = (const unsigned char *)b1;
104 c2 = (const unsigned char *)b2; 107 c2 = (const unsigned char *)b2;
105 108
106 if (n != 0) { 109 if (n != 0) {
107 do { 110 do {
108 if (*c1++ != *c2++) 111 if (*c1++ != *c2++)

cvs diff -r1.6 -r1.7 src/common/lib/libc/string/memcmp.c (expand / switch to unified diff)

--- src/common/lib/libc/string/memcmp.c 2020/01/27 22:13:39 1.6
+++ src/common/lib/libc/string/memcmp.c 2020/01/27 22:22:03 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: memcmp.c,v 1.6 2020/01/27 22:13:39 ad Exp $ */ 1/* $NetBSD: memcmp.c,v 1.7 2020/01/27 22:22:03 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran. 8 * by Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -56,53 +56,56 @@ @@ -56,53 +56,56 @@
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE. 61 * SUCH DAMAGE.
62 */ 62 */
63 63
64#include <sys/cdefs.h> 64#include <sys/cdefs.h>
65#if defined(LIBC_SCCS) && !defined(lint) 65#if defined(LIBC_SCCS) && !defined(lint)
66#if 0 66#if 0
67static char sccsid[] = "@(#)memcmp.c 8.1 (Berkeley) 6/4/93"; 67static char sccsid[] = "@(#)memcmp.c 8.1 (Berkeley) 6/4/93";
68#else 68#else
69__RCSID("$NetBSD: memcmp.c,v 1.6 2020/01/27 22:13:39 ad Exp $"); 69__RCSID("$NetBSD: memcmp.c,v 1.7 2020/01/27 22:22:03 ad Exp $");
70#endif 70#endif
71#endif /* LIBC_SCCS and not lint */ 71#endif /* LIBC_SCCS and not lint */
72 72
73#if !defined(_KERNEL) && !defined(_STANDALONE) 73#if !defined(_KERNEL) && !defined(_STANDALONE)
74#include <sys/types.h> 74#include <sys/types.h>
75 75
76#include <assert.h> 76#include <assert.h>
77#include <string.h> 77#include <string.h>
78#else 78#else
79#include <lib/libkern/libkern.h> 79#include <lib/libkern/libkern.h>
80#endif  80#endif
81 81
82#undef memcmp 82#undef memcmp
83/* 83/*
84 * Compare memory regions. 84 * Compare memory regions.
85 */ 85 */
86int 86int
87memcmp(const void *s1, const void *s2, size_t n) 87memcmp(const void *s1, const void *s2, size_t n)
88{ 88{
89 const uintptr_t *b1, *b2; 89 const uintptr_t *b1, *b2;
90 const unsigned char *c1, *c2; 90 const unsigned char *c1, *c2;
91 91
92 b1 = s1; 92 b1 = s1;
93 b2 = s2; 93 b2 = s2;
94 94
95 if ((((uintptr_t)b1 | (uintptr_t)b2) & (sizeof(uintptr_t) - 1)) == 0) { 95#ifndef __NO_STRICT_ALIGNMENT
 96 if ((((uintptr_t)b1 | (uintptr_t)b2) & (sizeof(uintptr_t) - 1)) == 0)
 97#endif
 98 {
96 while (n >= sizeof(uintptr_t)) { 99 while (n >= sizeof(uintptr_t)) {
97 if (*b1 != *b2) 100 if (*b1 != *b2)
98 break; 101 break;
99 b1++; 102 b1++;
100 b2++; 103 b2++;
101 n -= sizeof(uintptr_t); 104 n -= sizeof(uintptr_t);
102 } 105 }
103 } 106 }
104 107
105 c1 = (const unsigned char *)b1; 108 c1 = (const unsigned char *)b1;
106 c2 = (const unsigned char *)b2; 109 c2 = (const unsigned char *)b2;
107 110
108 if (n != 0) { 111 if (n != 0) {