From patchwork Tue May 21 20:28:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guinevere Larsen X-Patchwork-Id: 90636 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E7547384AB73 for ; Tue, 21 May 2024 20:29:19 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id EBF113858C60 for ; Tue, 21 May 2024 20:28:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EBF113858C60 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EBF113858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716323327; cv=none; b=TNUEnGx0FLoNrnWzj+v5oXvUnKlDNENxXlzWmfv8QXDjwZyqoGlghOC4M4kMYXFKFXiHOOCkn/3FG37TVkuC9OKYeAixVtT8JzXlEkPCZgeFnypvRm27CMLnvbnSVxqdZxhXy3NVVyBVb2DY8HBKANk+C/ZPYrbnO2gbPDNeDok= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716323327; c=relaxed/simple; bh=3l6KGDr7yuEvb4sJzqaSghBqDweh/CZZynk7Vpw1xwI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=n8kxD3Oya2vEVF85RQkbcb3pq4o6quTuIABIvNzu5aMZoBvkP+k+QfwuKtQK4481gDNWmIP8Ov5bxYw3Nk9UfCSZ8Sye28oXkxmqZCe2R+uVMriuj5IigroEiNhQkrsxWobYEfa8fF0MypEWqPvPduPBMaDJFvHpPxfNy1O7aW4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716323324; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7L2owhDu62zwJOXoO8xJcFqCUdRgwE1FhTKx7Iauprc=; b=IO3u4LfehnLv8gsC2ID1jOBd/Kk3e3IhTo/DIQdro5uEqOo2/bV05wTSy8UYGHXYTV3bf8 HiNwky7med7TTneUfe0yFLslsYF8IudUcWUnUE97mj9Xq4rZ/hvB+iLOOj4IcbyWsPWZK9 JFEo2cEMiHXx2ibV3bEBxTMZEtWQPVU= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-133-oVyarQTaOzec6T1c4vUAng-1; Tue, 21 May 2024 16:28:43 -0400 X-MC-Unique: oVyarQTaOzec6T1c4vUAng-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 134E11C05133 for ; Tue, 21 May 2024 20:28:43 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.96.134.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5F4DE40004D; Tue, 21 May 2024 20:28:42 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: [PATCH 3/3] gdb/record: add support to AVX unpack instructions Date: Tue, 21 May 2024 17:28:00 -0300 Message-ID: <20240521202800.2865871-4-blarsen@redhat.com> In-Reply-To: <20240521202800.2865871-1-blarsen@redhat.com> References: <20240521202800.2865871-1-blarsen@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This commit adds support to recording instructions to unpack high or low data from XMM registers, identified by the mnemonics in the form: VPUNPCK [L|H] [BW|WD|DQ|QDQ]. All these instructions are encoded the exact same way, and only affect the destination register, making them trivial to implement together. It also updates the test gdb.reverse/i386-avx-reverse.exp to test these new instructions. --- gdb/i386-tdep.c | 12 ++++++ gdb/testsuite/gdb.reverse/i386-avx-reverse.c | 37 +++++++++++++++++++ .../gdb.reverse/i386-avx-reverse.exp | 26 +++++++++++++ 3 files changed, 75 insertions(+) diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index d2848970ec4..250aff73389 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -5057,6 +5057,18 @@ i386_record_vex (struct i386_record_s *ir, uint8_t vex_w, uint8_t vex_r, } break; + case 0x60: /* VPUNPCKLBW */ + case 0x61: /* VPUNPCKLWD */ + case 0x62: /* VPUNPCKLDQ */ + case 0x6c: /* VPUNPCKLQDQ */ + case 0x68: /* VPUNPCKHBW */ + case 0x69: /* VPUNPCKHWD */ + case 0x6a: /* VPUNPCKHDQ */ + case 0x6d: /* VPUNPCKHQDQ */ + i386_record_modrm (ir); + record_full_arch_list_add_reg (ir->regcache, ir->regmap[X86_RECORD_XMM0_REGNUM] + ir->reg + vex_r * 8); + break; + default: gdb_printf (gdb_stderr, _("Process record does not support VEX instruction 0x%02x " diff --git a/gdb/testsuite/gdb.reverse/i386-avx-reverse.c b/gdb/testsuite/gdb.reverse/i386-avx-reverse.c index 216b593736b..4a4785ee99e 100644 --- a/gdb/testsuite/gdb.reverse/i386-avx-reverse.c +++ b/gdb/testsuite/gdb.reverse/i386-avx-reverse.c @@ -70,6 +70,40 @@ vmov_test () asm volatile ("vmovq %0, %%xmm15": "=m" (buf1)); } /* end vmov_test */ +/* Test if we can properly record (and undo) vpunpck style instructions. + Most tests will use xmm0 and xmm1 as sources. The registers xmm15 and xmm2 + are used as destination to ensure we're reading the VEX.R bit correctly. */ +void +vpunpck_test () +{ + /* Using GDB, load these values onto registers, for ease of testing. + xmm0.uint128 = 0x1f1e1d1c1b1a19181716151413121110 + xmm1.uint128 = 0x2f2e2d2c2b2a29282726252423222120 + so that's easy to confirm that the unpacking went as expected. */ + + /* 17 27 16 26 15 25 14 24 ...*/ + asm volatile ("vpunpcklbw %xmm0, %xmm1, %xmm15"); + /* 17 16 27 26 15 14 25 24 ...*/ + asm volatile ("vpunpcklwd %0, %%xmm1, %%xmm15" + : : "m" (global_buf0)); + /* 17 16 15 14 27 26 25 24 ...*/ + asm volatile ("vpunpckldq %0, %%xmm1, %%xmm2" + : : "m" (global_buf0)); + /* 17 16 15 14 13 12 11 10 ...*/ + asm volatile ("vpunpcklqdq %xmm0, %xmm1, %xmm2"); + + /* 17 27 16 26 15 25 14 24 ...*/ + asm volatile ("vpunpckhbw %xmm0, %xmm1, %xmm15"); + /* 17 16 27 26 15 14 25 24 ...*/ + asm volatile ("vpunpckhwd %0, %%xmm1, %%xmm15" + : : "m" (global_buf0)); + /* 17 16 15 14 27 26 25 24 ...*/ + asm volatile ("vpunpckhdq %0, %%xmm1, %%xmm2" + : : "m" (global_buf0)); + /* 17 16 15 14 13 12 11 10 ...*/ + asm volatile ("vpunpckhqdq %xmm0, %xmm1, %xmm2"); +} /* end vpunpck_test */ + int main () { @@ -82,9 +116,12 @@ main () } /* Zero relevant xmm registers, se we know what to look for. */ asm volatile ("vmovq %0, %%xmm0": : "m" (global_buf1)); + asm volatile ("vmovq %0, %%xmm1": : "m" (global_buf1)); + asm volatile ("vmovq %0, %%xmm2": : "m" (global_buf1)); asm volatile ("vmovq %0, %%xmm15": : "m" (global_buf1)); /* Start recording. */ vmov_test (); + vpunpck_test (); return 0; /* end of main */ } diff --git a/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp b/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp index 42ddc3a6526..c5e82eaeca6 100644 --- a/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp +++ b/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp @@ -169,3 +169,29 @@ if {[record_full_function "vmov"] == true} { gdb_test "record stop" "Process record is stopped.*" \ "delete history for vmov_test" gdb_test "finish" "Run till exit from.*vmov_test.*" "leaving vmov_test" + +# Starting vpunpck tests. +gdb_test "step" "vpunpck_test \\\(\\\) at .*" "entering vpunpck_test function" +gdb_test_no_output "set \$xmm0.v2_int64 = {0x1716151413121110, 0x1f1e1d1c1b1a1918}" +gdb_test_no_output "set \$xmm1.v2_int64 = {0x2726252423222120, 0x2f2e2d2c2b2a2928}" +gdb_test_no_output "set \$xmm2.uint128 = 0x0" +gdb_test_no_output "set \$xmm15.uint128 = 0x0" +if {[record_full_function "vpunpck"] == true} { + test_one_register "vpunpckhqdq" "xmm2" "0x" + test_one_register "vpunpckhdq" "xmm2" "0x" + test_one_register "vpunpckhwd" "xmm15" "0x" + test_one_register "vpunpckhbw" "xmm15" "0x" + + test_one_register "vpunpcklqdq" "xmm2" "0x17161514272625241312111023222120" + test_one_register "vpunpckldq" "xmm2" "0x0" + test_one_register "vpunpcklwd" "xmm15" "0x17271626152514241323122211211020" + test_one_register "vpunpcklbw" "xmm15" "0x0" +} else { + untested "couldn't test vpunpck tests" +} + +# Move to the end of vmov_test to set up next. +# Stop recording in case of recording errors. +gdb_test "record stop" "Process record is stopped.*" \ + "delete history for vpunpck_test" +gdb_test "finish" "Run till exit from.*vpunpck_test.*" "leaving vpunpck_test"