From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 05F9B3858CDA for ; Wed, 23 Oct 2024 16:52:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 05F9B3858CDA 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 05F9B3858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729702334; cv=none; b=tHu0lO2urXSwYVcyelc/Q1cFiUQn4VKJRdSeECuw0rkN2E7qx8BOZfdy5ZEnAS4YEIVetGUtj4FR2xZXgiVTfoyTawkcXWqZ8zc1a2xsmpdWFS7mervVaGSi0a9HTQUdTgarBaGuKE58uCHlKzu3/hr+rp8NnJRiiPUMI0Fit4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729702334; c=relaxed/simple; bh=XRP4baWm0Wo33oWRFs+ceZWcx/WDseYHKggNxqpy22M=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=cX51KECAm38a51hLV+auUU2GAAwoB/8N+obnbojtVguQ31sZaRq9TqzQRutxqtDUvfiqJSfKy/yudW/NF3+WGlt9eLgxBFUP/fd4F5roVvtPwY/ww/p8lCVmw6+aEmqVHXL2zPjnJuWsHeYdNAtW3f2AodwTykN76r26m48vsPs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729702321; 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=UWmF3N7IVJJHNQbRMFZgeObxdYcP4Pj2T6RTDAC8Z7A=; b=fUg6TiOjZoY3WdtSv/N9J1K+XzkXfUkyjepRGTCnEuUXDY5wf2U9WXPMTcm9/Ej+2VYfMB oo/kNogR+NLE3eEkVvQZhcheTxyzOjyE2KT+XFMkzx/Py5VyEKh5P9+Ln21Yug+rffPoAK FraA1h9vBd7E4B27rkQdAujTbR18p8o= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-516-x-gCId_iNZ-EqeoXlt0rlw-1; Wed, 23 Oct 2024 12:51:59 -0400 X-MC-Unique: x-gCId_iNZ-EqeoXlt0rlw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D2EB61955EE6 for ; Wed, 23 Oct 2024 16:51:58 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.96.134.67]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 99258300018D; Wed, 23 Oct 2024 16:51:57 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: [PATCH v5 7/7] gdb/record: add support to vzeroupper instruction Date: Wed, 23 Oct 2024 13:51:17 -0300 Message-ID: <20241023165117.4051131-8-guinevere@redhat.com> In-Reply-To: <20241023165117.4051131-1-guinevere@redhat.com> References: <20241023165117.4051131-1-guinevere@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.4 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_H3,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 List-Id: This commit adds recording support for the AVX instruction vzeroupper, which zeroes the high bits of ymm registers 0..15. In the programmer's manual, it is explicitly states that ymm registers 16..31 won't be affected if present, so we only need to record the first 16 registers. We record ymm_h registers since only the higher bits are touched, and that reduces the memory footprint of the instruction. This instruction is tested differently as we want to confirm we're only saving the relevant registers, and we want to ensure we're saving all of them, so it makes use of "maint print record-instruction" to see exactly what was recorded. --- gdb/i386-tdep.c | 17 +++++++++ gdb/testsuite/gdb.reverse/i386-avx-reverse.c | 19 ++++++++++ .../gdb.reverse/i386-avx-reverse.exp | 37 +++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index 938a654bf39..6a919bf6473 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -4964,6 +4964,23 @@ i386_record_vex (struct i386_record_s *ir, uint8_t vex_w, uint8_t vex_r, } break; + case 0x77:/* VZEROUPPER */ + { + int num_regs = tdep->num_ymm_regs; + /* This instruction only works on ymm0..15, even if 16..31 are + available. */ + if (num_regs > 16) + num_regs = 16; + for (int i = 0; i < num_regs; i++) + { + /* We only need to record ymm_h, because the low bits + are not touched. */ + record_full_arch_list_add_reg (ir->regcache, + tdep->ymm0h_regnum + i); + } + 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 87574983c8a..b36de10ec6f 100644 --- a/gdb/testsuite/gdb.reverse/i386-avx-reverse.c +++ b/gdb/testsuite/gdb.reverse/i386-avx-reverse.c @@ -192,6 +192,24 @@ vpbroadcast_test () return 0; /* end vpbroadcast_test */ } +int +vzeroupper_test () +{ + /* start vzeroupper_test. */ + /* Using GDB, load this value onto the register, for ease of testing. + ymm0.v2_int128 = {0x0, 0x12345} + ymm1.v2_int128 = {0x1f1e1d1c1b1a1918, 0x0} + ymm2.v2_int128 = {0x0, 0xbeef} + ymm15.v2_int128 = {0x0, 0xcafeface} + this way it's easy to confirm we're undoing things correctly. */ + + asm volatile ("vzeroupper"); + + /* We have a return statement to deal with + epilogue in different compilers. */ + return 0; /* end vzeroupper_test */ +} + int main () { @@ -211,5 +229,6 @@ main () vmov_test (); vpunpck_test (); vpbroadcast_test (); + vzeroupper_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 aea5e395cf8..4aefbcdbab3 100644 --- a/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp +++ b/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp @@ -294,3 +294,40 @@ if {[record_full_function "vpbroadcast"] == true} { gdb_test "finish" "Run till exit from.*vpbroadcast_test.*" \ "leaving vpbroadcast" + +# Preparation and testing of vzeroupper +gdb_test_no_output "set \$ymm0.v2_int128 = {0x0, 0x12345}" "set ymm0 for vzeroupper" +gdb_test_no_output "set \$ymm1.v2_int128 = {0x1f1e1d1c1b1a1918, 0x0}" \ + "set ymm1 for vzeroupper" +gdb_test_no_output "set \$ymm2.v2_int128 = {0x0, 0xbeef}" "set ymm2 for vzeroupper" +gdb_test_no_output "set \$ymm15.v2_int128 = {0x0, 0xcafeface}" "set ymm15 for vpbroadcast" +if {[record_full_function "vzeroupper"] == true} { + # Since vzeroupper needs to save 8 or 16 registers, let's check what was + # actually recorded, instead of just undoing an instruction. Only + # really check the values of egisters 0, 1, 2 and 15 because those are + # the only ones we're setting. + gdb_test "maint print record-instruction" \ + [multi_line "Register ymm0h changed: 74565" \ + "Register ymm1h changed: 0" \ + "Register ymm2h changed: 48879" \ + "Register ymm3h changed: ${decimal}" \ + "Register ymm4h changed: ${decimal}" \ + "Register ymm5h changed: ${decimal}" \ + "Register ymm6h changed: ${decimal}" \ + "Register ymm7h changed: ${decimal}" \ + "Register ymm8h changed: ${decimal}" \ + "Register ymm9h changed: ${decimal}" \ + "Register ymm10h changed: ${decimal}" \ + "Register ymm11h changed: ${decimal}" \ + "Register ymm12h changed: ${decimal}" \ + "Register ymm13h changed: ${decimal}" \ + "Register ymm14h changed: ${decimal}" \ + "Register ymm15h changed: 3405707982" \ + "Register rip changed: \[^\r\n\]+" ] \ + "verify vzeroupper recording" +} else { + untested "couldn't run vzeroupper tests" +} + +gdb_test "finish" "Run till exit from.*vzeroupper_test.*" \ + "leaving vzeroupper" -- 2.47.0