From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id A13F53858D28 for ; Tue, 7 Dec 2021 21:10:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A13F53858D28 Received: by mail-pg1-x52c.google.com with SMTP id k4so188931pgb.8 for ; Tue, 07 Dec 2021 13:10:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=7aUXaY4OgD14n4i1Yece7SU4JGrdbdZHOdQjATI1/UM=; b=DLdX7eKjcTnNaUcTmSBG/ZTgySLaJIhoq+gVIr/SKEaIg5pQHKc699LjTmbK7rkWNa JJ+lYFYZVkzrxM7aVCh0l8+ln1aZ9ZoIec2SJISS1iFJMur8EWAWST47Tgs7iI0Y7iU6 xy9guCPPpqGMlVKeQk4q9hNpIO9ZqvwIShFhhc4JAjOirSJkuJ7tGMtvnIFgOrujMd+a H4jFRo6IbsPNslpSfuvCFHucNzZmMy5lwv42Zul6/SSpxaVG8mGb6746SMFTj9tSG+VT xS9k298ciFAeqg/JvukuUJ9WMQi2G3sDx5cvLy11GPKPTqTHKU7I++GfzW8cfMygEUOr 12pw== X-Gm-Message-State: AOAM533XsuSrPSHtqIZrdoj+Kk/9GrtaOdjPZ4Z4oOGms+PYzfb9OLin /EWBLqGQOkH30v1bsflYm2O6t2k9RtQ= X-Google-Smtp-Source: ABdhPJximjrFsKNbiVDD3tqcl1Y4HwHtpkjMdf/ICUqewzIyDaC5hInaI+nNXLOgzidBtMVTGfC0sQ== X-Received: by 2002:a62:b40a:0:b0:4ad:55cb:1766 with SMTP id h10-20020a62b40a000000b004ad55cb1766mr1541506pfn.47.1638911406591; Tue, 07 Dec 2021 13:10:06 -0800 (PST) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id o15sm416792pgk.7.2021.12.07.13.10.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Dec 2021 13:10:05 -0800 (PST) Date: Wed, 8 Dec 2021 06:10:03 +0900 From: Stafford Horne To: Noah Goldstein Cc: libc-alpha@sourceware.org Subject: Re: [PATCH v4 1/5] string: Make tests birdirectional test-memcpy.c Message-ID: References: <20211101054952.2349590-1-goldstein.w.n@gmail.com> <20211106183322.3129442-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211106183322.3129442-1-goldstein.w.n@gmail.com> X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Dec 2021 21:10:10 -0000 On Sat, Nov 06, 2021 at 01:33:18PM -0500, Noah Goldstein via Libc-alpha wrote: > This commit updates the memcpy tests to test both dst > src and dst < > src. This is because there is logic in the code based on the > Reviewed-by: H.J. Lu > --- > string/test-memcpy.c | 167 +++++++++++++++++++++++++++++++++++------- > string/test-memmove.c | 75 ++++++++++++++++++- > 2 files changed, 214 insertions(+), 28 deletions(-) > > diff --git a/string/test-memcpy.c b/string/test-memcpy.c [..] > static void > -do_test1 (size_t size) > +do_test1 (size_t align1, size_t align2, size_t size) > { > void *large_buf; > - large_buf = mmap (NULL, size * 2 + page_size, PROT_READ | PROT_WRITE, > - MAP_PRIVATE | MAP_ANON, -1, 0); > + size_t mmap_size, region_size; > + > + align1 &= (page_size - 1); > + if (align1 == 0) > + align1 = page_size; > + > + align2 &= (page_size - 1); > + if (align2 == 0) > + align2 = page_size; > + > + region_size = (size + page_size - 1) & (~(page_size - 1)); > + > + mmap_size = region_size * 2 + 3 * page_size; > + large_buf = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, > + MAP_PRIVATE | MAP_ANON, -1, 0); > if (large_buf == MAP_FAILED) > { > - puts ("Failed to allocat large_buf, skipping do_test1"); > + puts ("Failed to allocate large_buf, skipping do_test1"); > return; > } > - > - if (mprotect (large_buf + size, page_size, PROT_NONE)) > + if (mprotect (large_buf + region_size + page_size, page_size, PROT_NONE)) > error (EXIT_FAILURE, errno, "mprotect failed"); > > - size_t arrary_size = size / sizeof (uint32_t); > - uint32_t *dest = large_buf; > - uint32_t *src = large_buf + size + page_size; > + size_t array_size = size / sizeof (uint32_t); > + uint32_t *dest = large_buf + align1; > + uint32_t *src = large_buf + region_size + 2 * page_size + align2; Hello, this causes Bus errors on the new OpenRISC port I am working on. > size_t i; > size_t repeats; > for(repeats = 0; repeats < 2; repeats++) > { > - for (i = 0; i < arrary_size; i++) > + for (i = 0; i < array_size; i++) > src[i] = (uint32_t) i; The bus errors happen here caused when align2 is 1 or 2. OpenRISC (and maybe other architectures?) do not support unaligned copies of words. I fixed this by limiting the align1/align2 to 4 but I am not sure if that is what you are trying to copy here. Maybe we need to change how we setup the src array. > - > FOR_EACH_IMPL (impl, 0) > { > - printf ("\t\tRunning: %s\n", impl->name); > memset (dest, -1, size); > CALL (impl, (char *) dest, (char *) src, size); > - for (i = 0; i < arrary_size; i++) > + for (i = 0; i < array_size; i++) > if (dest[i] != src[i]) > { > error (0, 0, > "Wrong result in function %s dst \"%p\" src \"%p\" offset \"%zd\"", > impl->name, dest, src, i); > ret = 1; > - munmap ((void *) large_buf, size * 2 + page_size); > + munmap ((void *) large_buf, mmap_size); > return; > } > } > - dest = src; > - src = large_buf; > + dest = large_buf + region_size + 2 * page_size + align1; > + src = large_buf + align2; > + } > + munmap ((void *) large_buf, mmap_size); > +} > + [..] > @@ -306,8 +341,88 @@ test_main (void) > > do_random_tests (); > > - do_test1 (0x100000); > - do_test1 (0x2000000); > + do_test1 (0, 0, 0x100000); > + do_test1 (0, 0, 0x2000000); > + > + for (i = 4096; i < 32768; i += 4096) > + { > + for (j = 1; j <= 1024; j <<= 1) > + { > + do_test1 (0, j, i); > + do_test1 (4095, j, i); > + do_test1 (4096 - j, 0, i); > + > + do_test1 (0, j - 1, i); > + do_test1 (4095, j - 1, i); > + do_test1 (4096 - j - 1, 0, i); > + > + do_test1 (0, j + 1, i); > + do_test1 (4095, j + 1, i); > + do_test1 (4096 - j, 1, i); These +1, -1's cause non-aligned word access. > + } > + } > + -Stafford