From patchwork Wed Jul 3 03:33:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 1126595 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-504238-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="knsq7qdu"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WSRFQgv7"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45dmv23b9hz9s3Z for ; Wed, 3 Jul 2019 13:34:38 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; q=dns; s=default; b=OJ1 QOUScGVBkuvrQkwU79kKZcpdGXoL+qGR+Kpu2nZUSe9pv5KouQo68Q4y5oG2Uqg+ uPn9wz1VSYnkn6YaqbCR4MT9O+u86WhHvcHvI2OA0seNoS4ZvTUuCUOwIeTUZVm7 IuMV7wpJzVRdoCymszkIaDvodrcFR4r3dT9X25i0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=default; bh=fH2R+NyKX rbDTm9pP1R9Ret1Lp4=; b=knsq7qduz3YrHATqYT5jhsfczOI56XYFqYdIibW0c XBFuEDZO1TniB7RkkpOZY6iTMg64DZA1buRF5UgFt9M2sgQrsXZ6UOVArFZboZLB iNhHCuIAUys+JSAVkif6QKqwm/mbs0Zyajy/XY5egcCX0wfFooFvuoVdmAq2pn8A Ps= Received: (qmail 39119 invoked by alias); 3 Jul 2019 03:34:17 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 38465 invoked by uid 89); 3 Jul 2019 03:34:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.8 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=quotient, HX-Received:2a27, H*RU:209.85.214.193, HX-Spam-Relays-External:209.85.214.193 X-HELO: mail-pl1-f193.google.com Received: from mail-pl1-f193.google.com (HELO mail-pl1-f193.google.com) (209.85.214.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 03 Jul 2019 03:34:09 +0000 Received: by mail-pl1-f193.google.com with SMTP id e5so397164pls.13 for ; Tue, 02 Jul 2019 20:34:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M0AuKl6/tFOClcQ8E2AI6hBsJ2g1XLtBDY8c9fpA1c4=; b=WSRFQgv7FLbJh6MC27Ge+uYvLztvQLP7l2uwFLlYQHydbOL3lB+U3TPjspjMOHjeUi /vZIG0hkITu3X/pBCo9Jy2XGif0Kj+96OoCFnDQW/+hv42JNpUa2NZPibVEFKVYQSt7e /K0dOqZKK7+6bwQoNJvMcmf5lKQ5w4YYdjhKD37vosJLBMV9wizOZWGfdA0v/n1LEin1 VWvOJyn1LPaohazdti07lRYdMa39+77hhdWtmMuh0xhZKsL+HmTZq6ZqC0We99ddR7VL BR/rKl+l+LoeGKSu4dCvOCbkvdLIIw2KaM4s58Bd3MjMwRC58DFWUro0peHuYdHNK6QV teMA== Received: from localhost (g223.61-115-60.ppp.wakwak.ne.jp. [61.115.60.223]) by smtp.gmail.com with ESMTPSA id 191sm525522pfu.177.2019.07.02.20.34.07 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 02 Jul 2019 20:34:07 -0700 (PDT) From: Stafford Horne To: GCC patches Cc: Openrisc , Bernhard Reutner-Fischer , Jeff Law , Stafford Horne Subject: [PATCH v2 2/5] or1k: Fix issues with msoft-div Date: Wed, 3 Jul 2019 12:33:48 +0900 Message-Id: <20190703033351.11924-3-shorne@gmail.com> In-Reply-To: <20190703033351.11924-1-shorne@gmail.com> References: <20190703033351.11924-1-shorne@gmail.com> MIME-Version: 1.0 X-IsSubscribed: yes Fixes bad assembly logic with software divide as reported by Richard Selvaggi. Also, add a basic test to verify the soft math works when enabled. gcc/testsuite/ChangeLog: PR target/90362 * gcc.target/or1k/div-mul-3.c: New test. libgcc/ChangeLog: PR target/90362 * config/or1k/lib1funcs.S (__udivsi3): Change l.sfeqi to l.sfeq and l.sfltsi to l.sflts equivalents as the immediate instructions are not available on every processor. Change a l.bnf to l.bf to fix logic issue. --- Changes since v1: - none gcc/testsuite/gcc.target/or1k/div-mul-3.c | 31 +++++++++++++++++++++++ libgcc/config/or1k/lib1funcs.S | 6 ++--- 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/or1k/div-mul-3.c diff --git a/gcc/testsuite/gcc.target/or1k/div-mul-3.c b/gcc/testsuite/gcc.target/or1k/div-mul-3.c new file mode 100644 index 00000000000..2c4f91b7e98 --- /dev/null +++ b/gcc/testsuite/gcc.target/or1k/div-mul-3.c @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -msoft-div -msoft-mul" } */ + +struct testcase { + int a; + int b; + int c; + int expected; +}; + +struct testcase tests[] = { + {2, 200, 3, 133}, + {3, 300, 3, 300}, + {2, 500, 3, 333}, + {4, 250, 3, 333}, + {0, 0, 0, 0} +}; + +int calc (int a, int b, int c) { + return a * b / c; +} + +int main () { + int fail = 0; + struct testcase *tc; + + for (int i = 0; (tc = &tests[i], tc->c); i++) + fail |= (calc (tc->a, tc->b, tc->c) != tc->expected); + + return fail; +} diff --git a/libgcc/config/or1k/lib1funcs.S b/libgcc/config/or1k/lib1funcs.S index d2103923486..6d058977229 100644 --- a/libgcc/config/or1k/lib1funcs.S +++ b/libgcc/config/or1k/lib1funcs.S @@ -68,18 +68,18 @@ __udivmodsi3_internal: is not clobbered by this routine, and use that as to save a return address without creating a stack frame. */ - l.sfeqi r4, 0 /* division by zero; return 0. */ + l.sfeq r4, r0 /* division by zero; return 0. */ l.ori r11, r0, 0 /* initial quotient */ l.bf 9f l.ori r12, r3, 0 /* initial remainder */ /* Given X/Y, shift Y left until Y >= X. */ l.ori r6, r0, 1 /* mask = 1 */ -1: l.sfltsi r4, 0 /* y has msb set */ +1: l.sflts r4, r0 /* y has msb set */ l.bf 2f l.sfltu r4, r12 /* y < x */ l.add r4, r4, r4 /* y <<= 1 */ - l.bnf 1b + l.bf 1b l.add r6, r6, r6 /* mask <<= 1 */ /* Shift Y back to the right again, subtracting from X. */