Tue Jul 21 21:45:33 2009 UTC ()
flag a 64-bit integer constant as "ULL" -- this is not clean but the
code around it assumes it anyway
fixes build on 32-bit


(drochner)
diff -r1.1 -r1.2 src/tests/lib/libc/string/t_popcount.c

cvs diff -r1.1 -r1.2 src/tests/lib/libc/string/t_popcount.c (expand / switch to unified diff)

--- src/tests/lib/libc/string/t_popcount.c 2009/07/21 13:18:44 1.1
+++ src/tests/lib/libc/string/t_popcount.c 2009/07/21 21:45:33 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: t_popcount.c,v 1.1 2009/07/21 13:18:44 joerg Exp $ */ 1/* $NetBSD: t_popcount.c,v 1.2 2009/07/21 21:45:33 drochner Exp $ */
2/*- 2/*-
3 * Copyright (c) 2009 The NetBSD Foundation, Inc. 3 * Copyright (c) 2009 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Joerg Sonnenberger. 7 * by Joerg Sonnenberger.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 12 *
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.
@@ -22,27 +22,27 @@ @@ -22,27 +22,27 @@
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 25 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE. 31 * SUCH DAMAGE.
32 */ 32 */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__RCSID("$NetBSD: t_popcount.c,v 1.1 2009/07/21 13:18:44 joerg Exp $"); 35__RCSID("$NetBSD: t_popcount.c,v 1.2 2009/07/21 21:45:33 drochner Exp $");
36 36
37#include <atf-c.h> 37#include <atf-c.h>
38#include <strings.h> 38#include <strings.h>
39 39
40static unsigned int byte_count[256]; 40static unsigned int byte_count[256];
41 41
42static void 42static void
43popcount_init(void) 43popcount_init(void)
44{ 44{
45 unsigned int i, j; 45 unsigned int i, j;
46 46
47 for (i = 0; i < 256; ++i) { 47 for (i = 0; i < 256; ++i) {
48 byte_count[i] = 0; 48 byte_count[i] = 0;
@@ -166,23 +166,23 @@ ATF_TC_BODY(t_popcountll, tc) @@ -166,23 +166,23 @@ ATF_TC_BODY(t_popcountll, tc)
166 166
167 for (i = 0; i < 0xffffffff; ++i) { 167 for (i = 0; i < 0xffffffff; ++i) {
168 r = byte_count[i & 255] + byte_count[(i >> 8) & 255] 168 r = byte_count[i & 255] + byte_count[(i >> 8) & 255]
169 + byte_count[(i >> 16) & 255] 169 + byte_count[(i >> 16) & 255]
170 + byte_count[(i >> 24) & 255] + r2; 170 + byte_count[(i >> 24) & 255] + r2;
171 171
172 v = (((unsigned long long)i) << 32) + p; 172 v = (((unsigned long long)i) << 32) + p;
173 ATF_CHECK_EQ(r, popcountll(v)); 173 ATF_CHECK_EQ(r, popcountll(v));
174 v = (((unsigned long long)p) << 32) + i; 174 v = (((unsigned long long)p) << 32) + i;
175 ATF_CHECK_EQ(r, popcountll(v)); 175 ATF_CHECK_EQ(r, popcountll(v));
176 } 176 }
177 } 177 }
178 178
179 ATF_CHECK_EQ(popcountll(0xffffffffffffffff), 64); 179 ATF_CHECK_EQ(popcountll(0xffffffffffffffffULL), 64);
180} 180}
181 181
182ATF_TP_ADD_TCS(tp) 182ATF_TP_ADD_TCS(tp)
183{ 183{
184 ATF_TP_ADD_TC(tp, t_popcount); 184 ATF_TP_ADD_TC(tp, t_popcount);
185 ATF_TP_ADD_TC(tp, t_popcountll); 185 ATF_TP_ADD_TC(tp, t_popcountll);
186 186
187 return atf_no_error(); 187 return atf_no_error();
188} 188}