Thu Jan 28 18:52:43 2021 UTC ()
Fix sanity check to match the fixed off-by-one logic in the sizing
logic.


(joerg)
diff -r1.5 -r1.6 src/usr.bin/nbperf/graph2.c

cvs diff -r1.5 -r1.6 src/usr.bin/nbperf/graph2.c (expand / switch to unified diff)

--- src/usr.bin/nbperf/graph2.c 2021/01/07 16:03:08 1.5
+++ src/usr.bin/nbperf/graph2.c 2021/01/28 18:52:43 1.6
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: graph2.c,v 1.5 2021/01/07 16:03:08 joerg Exp $ */ 1/* $NetBSD: graph2.c,v 1.6 2021/01/28 18:52:43 joerg 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.
@@ -26,27 +26,27 @@ @@ -26,27 +26,27 @@
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#if HAVE_NBTOOL_CONFIG_H 34#if HAVE_NBTOOL_CONFIG_H
35#include "nbtool_config.h" 35#include "nbtool_config.h"
36#endif 36#endif
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39__RCSID("$NetBSD: graph2.c,v 1.5 2021/01/07 16:03:08 joerg Exp $"); 39__RCSID("$NetBSD: graph2.c,v 1.6 2021/01/28 18:52:43 joerg Exp $");
40 40
41#include <err.h> 41#include <err.h>
42#include <inttypes.h> 42#include <inttypes.h>
43#include <stdio.h> 43#include <stdio.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <string.h> 45#include <string.h>
46 46
47#include "nbperf.h" 47#include "nbperf.h"
48#include "graph2.h" 48#include "graph2.h"
49 49
50void 50void
51SIZED2(_setup)(struct SIZED(graph) *graph, uint32_t v, uint32_t e) 51SIZED2(_setup)(struct SIZED(graph) *graph, uint32_t v, uint32_t e)
52{ 52{
@@ -170,31 +170,31 @@ SIZED2(_remove_vertex)(struct SIZED(grap @@ -170,31 +170,31 @@ SIZED2(_remove_vertex)(struct SIZED(grap
170 graph->output_order[--graph->output_index] = e; 170 graph->output_order[--graph->output_index] = e;
171 SIZED2(_remove_edge)(graph, e); 171 SIZED2(_remove_edge)(graph, e);
172 } 172 }
173} 173}
174 174
175int 175int
176SIZED2(_hash)(struct nbperf *nbperf, struct SIZED(graph) *graph) 176SIZED2(_hash)(struct nbperf *nbperf, struct SIZED(graph) *graph)
177{ 177{
178 struct SIZED(edge) *e; 178 struct SIZED(edge) *e;
179 uint32_t hashes[NBPERF_MAX_HASH_SIZE]; 179 uint32_t hashes[NBPERF_MAX_HASH_SIZE];
180 size_t i, j; 180 size_t i, j;
181 181
182#if GRAPH_SIZE == 2 182#if GRAPH_SIZE == 2
183 if (nbperf->allow_hash_fudging && (graph->v & 1) != 1) 183 if (nbperf->allow_hash_fudging && (graph->v & 1) != 0)
184 errx(1, "vertex count must have lowest bit set"); 184 errx(1, "vertex count must have lowest bit clear");
185#else 185#else
186 if (nbperf->allow_hash_fudging && (graph->v & 3) != 3) 186 if (nbperf->allow_hash_fudging && (graph->v & 3) != 0)
187 errx(1, "vertex count must have lowest 2 bits set"); 187 errx(1, "vertex count must have lowest 2 bits clear");
188#endif 188#endif
189 189
190 190
191 memset(graph->verts, 0, sizeof(*graph->verts) * graph->v); 191 memset(graph->verts, 0, sizeof(*graph->verts) * graph->v);
192 graph->hash_fudge = 0; 192 graph->hash_fudge = 0;
193 193
194 for (i = 0; i < graph->e; ++i) { 194 for (i = 0; i < graph->e; ++i) {
195 (*nbperf->compute_hash)(nbperf, 195 (*nbperf->compute_hash)(nbperf,
196 nbperf->keys[i], nbperf->keylens[i], hashes); 196 nbperf->keys[i], nbperf->keylens[i], hashes);
197 e = graph->edges + i; 197 e = graph->edges + i;
198 for (j = 0; j < GRAPH_SIZE; ++j) { 198 for (j = 0; j < GRAPH_SIZE; ++j) {
199 e->vertices[j] = hashes[j] % graph->v; 199 e->vertices[j] = hashes[j] % graph->v;
200 if (j == 1 && e->vertices[0] == e->vertices[1]) { 200 if (j == 1 && e->vertices[0] == e->vertices[1]) {