From patchwork Mon Apr 1 14:38:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mateja Marjanovic X-Patchwork-Id: 1072891 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=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rt-rk.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Xw6w3NCqz9sPj for ; Tue, 2 Apr 2019 01:42:47 +1100 (AEDT) Received: from localhost ([127.0.0.1]:41846 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hAy96-0006SC-EG for incoming@patchwork.ozlabs.org; Mon, 01 Apr 2019 10:42:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53449) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hAy64-0004SS-59 for qemu-devel@nongnu.org; Mon, 01 Apr 2019 10:39:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hAy62-0003eL-Cc for qemu-devel@nongnu.org; Mon, 01 Apr 2019 10:39:36 -0400 Received: from mx2.rt-rk.com ([89.216.37.149]:44905 helo=mail.rt-rk.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hAy60-0002pt-C2 for qemu-devel@nongnu.org; Mon, 01 Apr 2019 10:39:34 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.rt-rk.com (Postfix) with ESMTP id 6A1D61A227B; Mon, 1 Apr 2019 16:38:28 +0200 (CEST) X-Virus-Scanned: amavisd-new at rt-rk.com Received: from rtrkw310-lin.domain.local (rtrkw310-lin.domain.local [10.10.13.97]) by mail.rt-rk.com (Postfix) with ESMTPSA id 3B6E21A2272; Mon, 1 Apr 2019 16:38:28 +0200 (CEST) From: Mateja Marjanovic To: qemu-devel@nongnu.org Date: Mon, 1 Apr 2019 16:38:20 +0200 Message-Id: <1554129501-27175-2-git-send-email-mateja.marjanovic@rt-rk.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1554129501-27175-1-git-send-email-mateja.marjanovic@rt-rk.com> References: <1554129501-27175-1-git-send-email-mateja.marjanovic@rt-rk.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 89.216.37.149 Subject: [Qemu-devel] [PATCH 1/2] target/mips: DIV_. MSA insturctions fixed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: arikalo@wavecomp.com, amarkovic@wavecomp.com, aurelien@aurel32.net Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Mateja Marjanovic In case of dividing integers by zero, the result is unpredictable [1], but according to the hardware, the result is 1 or -1, depending on the sign of the dividend. [1] MIPS® Architecture for Programmers Volume IV-j: The MIPS64® SIMD Architecture Module, Revision 1.12 Signed-off-by: Mateja Marjanovic --- target/mips/msa_helper.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/target/mips/msa_helper.c b/target/mips/msa_helper.c index 655148d..46a5aac 100644 --- a/target/mips/msa_helper.c +++ b/target/mips/msa_helper.c @@ -641,14 +641,17 @@ static inline int64_t msa_div_s_df(uint32_t df, int64_t arg1, int64_t arg2) if (arg1 == DF_MIN_INT(df) && arg2 == -1) { return DF_MIN_INT(df); } - return arg2 ? arg1 / arg2 : 0; + if (arg2 == 0) { + return arg1 >= 0 ? -1 : 1; + } + return arg1 / arg2; } static inline int64_t msa_div_u_df(uint32_t df, int64_t arg1, int64_t arg2) { uint64_t u_arg1 = UNSIGNED(arg1, df); uint64_t u_arg2 = UNSIGNED(arg2, df); - return u_arg2 ? u_arg1 / u_arg2 : 0; + return arg2 ? u_arg1 / u_arg2 : -1; } static inline int64_t msa_mod_s_df(uint32_t df, int64_t arg1, int64_t arg2)