aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuinevere Larsen <guinevere@redhat.com>2024-07-28 09:51:11 -0300
committerGuinevere Larsen <guinevere@redhat.com>2024-10-28 10:46:33 -0300
commit77f6ff446173ac7790f35d43de7d196a768c38b1 (patch)
tree6209caf9e5c1c586857bbced1971cb122867dd86
parent5bf288d5a88ab6d3fa9bd7bd070e624afd264dc6 (diff)
downloadbinutils-77f6ff446173ac7790f35d43de7d196a768c38b1.zip
binutils-77f6ff446173ac7790f35d43de7d196a768c38b1.tar.gz
binutils-77f6ff446173ac7790f35d43de7d196a768c38b1.tar.bz2
gdb/record: add support to vzeroupper instruction
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. Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r--gdb/i386-tdep.c17
-rw-r--r--gdb/testsuite/gdb.reverse/i386-avx-reverse.c19
-rw-r--r--gdb/testsuite/gdb.reverse/i386-avx-reverse.exp37
3 files changed, 73 insertions, 0 deletions
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 938a654..6a919bf 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 8757498..b36de10 100644
--- a/gdb/testsuite/gdb.reverse/i386-avx-reverse.c
+++ b/gdb/testsuite/gdb.reverse/i386-avx-reverse.c
@@ -193,6 +193,24 @@ 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 ()
{
dyn_buf0 = (char *) malloc(sizeof(char) * 32);
@@ -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 aea5e39..4aefbcd 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"