From: Guinevere Larsen <blarsen@redhat.com>
To: gdb-patches@sourceware.org
Cc: Guinevere Larsen <blarsen@redhat.com>
Subject: [PATCH 3/3] gdb/record: add support to AVX unpack instructions
Date: Tue, 21 May 2024 17:28:00 -0300 [thread overview]
Message-ID: <20240521202800.2865871-4-blarsen@redhat.com> (raw)
In-Reply-To: <20240521202800.2865871-1-blarsen@redhat.com>
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"
--
2.45.1
next prev parent reply other threads:[~2024-05-21 20:28 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-21 20:27 [PATCH 0/3] Small step in supporting AVX instructions Guinevere Larsen
2024-05-21 20:27 ` [PATCH 1/3] gdb: Start supporting AVX instruction Guinevere Larsen
2024-06-05 16:11 ` Tom Tromey
2024-06-05 17:33 ` Guinevere Larsen
2024-06-06 17:01 ` Tom Tromey
2024-05-21 20:27 ` [PATCH 2/3] gdb/record: add support to vmovd and vmovq instructions Guinevere Larsen
2024-06-05 16:13 ` Tom Tromey
2024-06-05 18:24 ` Guinevere Larsen
2024-06-05 19:53 ` Guinevere Larsen
2024-05-21 20:28 ` Guinevere Larsen [this message]
2024-06-04 19:10 ` [PING][PATCH 0/3] Small step in supporting AVX instructions Guinevere Larsen
2024-06-05 16:13 ` Tom Tromey
2024-06-06 8:16 ` Willgerodt, Felix
2024-06-06 12:50 ` Guinevere Larsen
2024-06-06 13:36 ` Willgerodt, Felix
2024-06-06 13:45 ` Guinevere Larsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240521202800.2865871-4-blarsen@redhat.com \
--to=blarsen@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).