From patchwork Sun Aug 9 20:13:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 505455 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4A1DE1401C7 for ; Mon, 10 Aug 2015 06:16:57 +1000 (AEST) Received: from localhost ([::1]:56126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZOX1b-0005kZ-Cq for incoming@patchwork.ozlabs.org; Sun, 09 Aug 2015 16:16:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZOWz1-0000Vb-KO for qemu-devel@nongnu.org; Sun, 09 Aug 2015 16:14:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZOWz0-0005P6-Ej for qemu-devel@nongnu.org; Sun, 09 Aug 2015 16:14:15 -0400 Received: from smtp4-g21.free.fr ([212.27.42.4]:40769) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZOWz0-0005Oq-95 for qemu-devel@nongnu.org; Sun, 09 Aug 2015 16:14:14 -0400 Received: from Quad.localdomain (unknown [78.238.229.36]) by smtp4-g21.free.fr (Postfix) with ESMTPS id 8797E4C806C; Sun, 9 Aug 2015 22:14:13 +0200 (CEST) From: Laurent Vivier To: qemu-devel@nongnu.org Date: Sun, 9 Aug 2015 22:13:32 +0200 Message-Id: <1439151229-27747-14-git-send-email-laurent@vivier.eu> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1439151229-27747-1-git-send-email-laurent@vivier.eu> References: <1439151229-27747-1-git-send-email-laurent@vivier.eu> X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 212.27.42.4 Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, Andreas Schwab , Laurent Vivier , gerg@uclinux.org Subject: [Qemu-devel] [PATCH for-2.5 13/30] m68k: set Z and N on divu/muls overflow as a real 68040 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This allows to compare simulation results with a real 68040. Signed-off-by: Laurent Vivier Acked-by: Richard Henderson --- target-m68k/op_helper.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/target-m68k/op_helper.c b/target-m68k/op_helper.c index 1af0ca6..71641bf 100644 --- a/target-m68k/op_helper.c +++ b/target-m68k/op_helper.c @@ -193,12 +193,19 @@ void HELPER(divu)(CPUM68KState *env, uint32_t word) quot = num / den; rem = num % den; flags = 0; - if (word && quot > 0xffff) - flags |= CCF_V; - if (quot == 0) - flags |= CCF_Z; - else if ((int32_t)quot < 0) - flags |= CCF_N; + if (word && quot > 0xffff) { + /* real 68040 keep Z and N on overflow, + * whereas documentation says "undefined" + */ + flags |= CCF_V | (env->cc_dest & (CCF_Z|CCF_N)); + } else { + if (quot == 0) { + flags |= CCF_Z; + } else if ((int16_t)quot < 0) { + flags |= CCF_N; + } + } + env->div1 = quot; env->div2 = rem; env->cc_dest = flags; @@ -220,12 +227,19 @@ void HELPER(divs)(CPUM68KState *env, uint32_t word) quot = num / den; rem = num % den; flags = 0; - if (word && quot != (int16_t)quot) - flags |= CCF_V; - if (quot == 0) - flags |= CCF_Z; - else if (quot < 0) - flags |= CCF_N; + if (word && quot != (int16_t)quot) { + /* real 68040 keep Z and N on overflow, + * whereas documentation says "undefined" + */ + flags |= CCF_V | (env->cc_dest & (CCF_Z|CCF_N)); + } else { + if (quot == 0) { + flags |= CCF_Z; + } else if ((int16_t)quot < 0) { + flags |= CCF_N; + } + } + env->div1 = quot; env->div2 = rem; env->cc_dest = flags;