From patchwork Sun May 26 19:42:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 799093 Delivered-To: patch@linaro.org Received: by 2002:a5d:6a47:0:b0:354:fb4b:99cd with SMTP id t7csp1595696wrw; Sun, 26 May 2024 12:43:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVs9awAcZFRnrBevaHAj67++B+HsJDxUvy7WHWrIv4Gqk0B/UjOmlzKLSMaX0EspUpuD/PP8165/fzEwGRCmTgK X-Google-Smtp-Source: AGHT+IF9HtAbDuoRDCQSWyH+XWO6xXJvm55xJOqR/qzWJTe4mgDxFan6flWC9wumow2kejACeZ0B X-Received: by 2002:a05:620a:205d:b0:794:99d3:d223 with SMTP id af79cd13be357-794ab110762mr821031285a.65.1716752629149; Sun, 26 May 2024 12:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716752629; cv=none; d=google.com; s=arc-20160816; b=hZSYRCpISLeZbd36z7ywZv9iTKZjg2hTrjREfHRlDs1Iv2jDCOpXh9Xw/XfZ9K4Dmb qFqjP5hHQXdWT/GsDjerAFw5cJckxdXNF7iulCl8op+LzWmnc80GfZ8w/Zy/WrWSkbMD CDoAjRfqHyFxzCTvZf+/ltCasirVBxfySC1JMUezbJ/QIrt7dyJzUzKoMFvTWNjV74nx 5H+meQJc60o04JDuhiD7KZtuy44tlrXK9jGYF2/suKzEe0U7gRipoiImW8aM+WZNyTd/ jsBkYdakaZGWTxXUvQUqq4LiJwKHnmRSJ2bEiLbQX5MRMlE6XG/JAOBsD2Obb3b7E3Yl R8Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QyfYhcDz9GxZwfZD6zLLHvsedkNWvuKT9dIKJJP5Q0E=; fh=TYrED6TOMxGX0VC4GtjviASLbYyJe19+7/tKWjN44KQ=; b=U3JeapAtRv2gsOflAUvQPniZdMQIPGKL38eJdP8n706TjAA08nXax9g58oT48+tU1y LI2tF0MYjPuIkXHruM7LYQ2lf/pBgjqlYIiN4dQBpDuPa6SXi3pZ4iNqj4KV85kYuJDY ugvFK+kt6rtl8+YAfWU5fNkD/6xQgxFkDTg1rsPlXGUEdaCan4OFioHsCw4C5yraoFZj 5k/5eVly9QjY52/wFp93aAtjnAXbGg/Dj7sNkj2DJQAh+QcnNQQ9hLQHrB1cQ/ShGNlu TEWqGzn+myPvBU41tnj74X3xKttBjB0qv4CK4PIDz2e0dUQY7gMz2slEcBQXf3gmqCQ5 4FCA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NW5SmKS+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-794abd1a88fsi685578585a.357.2024.05.26.12.43.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 26 May 2024 12:43:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NW5SmKS+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBJlk-0008A4-Oe; Sun, 26 May 2024 15:43:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBJlj-00089h-Lg for qemu-devel@nongnu.org; Sun, 26 May 2024 15:42:59 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sBJlh-0007cX-Ry for qemu-devel@nongnu.org; Sun, 26 May 2024 15:42:59 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1f4a0050b9aso1324795ad.2 for ; Sun, 26 May 2024 12:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716752576; x=1717357376; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QyfYhcDz9GxZwfZD6zLLHvsedkNWvuKT9dIKJJP5Q0E=; b=NW5SmKS+mx3nr8EF/p2dXGCHrz7oyxF+p/XM5q1XAkwpmTeAEI2AmISN2WmGc10YBe uOna6uh7HjN0B95zIylg0AbJLIJYdoMudwR6TWzN+NKc/QIUnnhIqsP6JkF5mIu1HryG kw7NPxrPPSwwnSn9m/OGEP4RrFm+iS3pHxMmR2ZCoqZE7WFWo/IYRDO2F2WAmdsvra8N CG7qHTNn4jFJYIHDTFf80by6Rpgy5yoWQrPPh0YXCnKbE2FWqV0IQ1gqzZP2fXBjmUTF pTMPV+NpWZ1Dl/Xm2mKX7N/ulWhyZ5U1epHlphOlg79KEpoyu1q+BohKZmHK6JrqOSGj 8ifg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716752576; x=1717357376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QyfYhcDz9GxZwfZD6zLLHvsedkNWvuKT9dIKJJP5Q0E=; b=bhPlh3uUVa6/AnysUXPJa/tvuVDE0srvzdUNN8050HBSGeLyVpxP84hkOwMzoQs/2s b7VNbDrwtlTdoC/RkGfxwNYLcPBEYTxAcFC8HOhMbs9nC7kWOLl529NulNyzLS7wV3Mn t4Sxm+7id3vWCPoW5R4uhc/cY2eVK6er4gHElJC7tayfG0PBy8EtQLTyoMPDaRKf55Oe e2W3N0P4Anma2uElXjmdYcgChgGKKjB05+OFc598ZHfpc68SpaFn0plxrFFDyqS2P7hT yRhwJAj/agqynbQfi9CohfU50BAFR/a0WjXD1+IeSDOBZKg41kccg0R1LsE8rkC8NKk/ ElAA== X-Gm-Message-State: AOJu0YxWhI3ap21EDj4wAi0iCZy6k3WXwDZWiJAu5NT363YpE1XKXnGZ EHtcVN8ok2Ocx+iCUiUsYKurxL3txUUBB77YNjH1l1RBu69fApyM4o9pDGLdz1DSiWyWAf/s83J H X-Received: by 2002:a17:903:245:b0:1f3:903:5c9a with SMTP id d9443c01a7336-1f4497e5d05mr85622535ad.58.1716752576243; Sun, 26 May 2024 12:42:56 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f46ad93c2esm28165935ad.263.2024.05.26.12.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 12:42:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: mark.cave-ayland@ilande.co.uk Subject: [PATCH v2 01/37] target/sparc: Fix ARRAY8 Date: Sun, 26 May 2024 12:42:18 -0700 Message-Id: <20240526194254.459395-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240526194254.459395-1-richard.henderson@linaro.org> References: <20240526194254.459395-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Follow the Oracle Sparc 2015 implementation note and bound the input value of N to 5 from the lower 3 bits of rs2. Spell out all of the intermediate values, matching the diagram in the manual. Fix extraction of upper_x and upper_y for N=0. Signed-off-by: Richard Henderson --- target/sparc/vis_helper.c | 53 ++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/target/sparc/vis_helper.c b/target/sparc/vis_helper.c index e15c6bb34e..f46fcf1f6a 100644 --- a/target/sparc/vis_helper.c +++ b/target/sparc/vis_helper.c @@ -21,25 +21,42 @@ #include "cpu.h" #include "exec/helper-proto.h" -/* This function uses non-native bit order */ -#define GET_FIELD(X, FROM, TO) \ - ((X) >> (63 - (TO)) & ((1ULL << ((TO) - (FROM) + 1)) - 1)) - -/* This function uses the order in the manuals, i.e. bit 0 is 2^0 */ -#define GET_FIELD_SP(X, FROM, TO) \ - GET_FIELD(X, 63 - (TO), 63 - (FROM)) - -target_ulong helper_array8(target_ulong pixel_addr, target_ulong cubesize) +target_ulong helper_array8(target_ulong rs1, target_ulong rs2) { - return (GET_FIELD_SP(pixel_addr, 60, 63) << (17 + 2 * cubesize)) | - (GET_FIELD_SP(pixel_addr, 39, 39 + cubesize - 1) << (17 + cubesize)) | - (GET_FIELD_SP(pixel_addr, 17 + cubesize - 1, 17) << 17) | - (GET_FIELD_SP(pixel_addr, 56, 59) << 13) | - (GET_FIELD_SP(pixel_addr, 35, 38) << 9) | - (GET_FIELD_SP(pixel_addr, 13, 16) << 5) | - (((pixel_addr >> 55) & 1) << 4) | - (GET_FIELD_SP(pixel_addr, 33, 34) << 2) | - GET_FIELD_SP(pixel_addr, 11, 12); + /* + * From Oracle SPARC Architecture 2015: + * Architecturally, an illegal R[rs2] value (>5) causes the array + * instructions to produce undefined results. For historic reference, + * past implementations of these instructions have ignored R[rs2]{63:3} + * and have treated R[rs2] values of 6 and 7 as if they were 5. + */ + target_ulong n = MIN(rs2 & 7, 5); + + target_ulong x_int = (rs1 >> 11) & 0x7ff; + target_ulong y_int = (rs1 >> 33) & 0x7ff; + target_ulong z_int = rs1 >> 55; + + target_ulong lower_x = x_int & 3; + target_ulong lower_y = y_int & 3; + target_ulong lower_z = z_int & 1; + + target_ulong middle_x = (x_int >> 2) & 15; + target_ulong middle_y = (y_int >> 2) & 15; + target_ulong middle_z = (z_int >> 1) & 15; + + target_ulong upper_x = (x_int >> 6) & ((1 << n) - 1); + target_ulong upper_y = (y_int >> 6) & ((1 << n) - 1); + target_ulong upper_z = z_int >> 5; + + return (upper_z << (17 + 2 * n)) + | (upper_y << (17 + n)) + | (upper_x << 17) + | (middle_z << 13) + | (middle_y << 9) + | (middle_x << 5) + | (lower_z << 4) + | (lower_y << 2) + | lower_x; } #if HOST_BIG_ENDIAN