From 741a901d8d735ce0ce2d2875eff84fd3d494f4aa Mon Sep 17 00:00:00 2001 From: Nicholas Mosier Date: Wed, 20 Sep 2023 05:09:32 +0000 Subject: [PATCH] arch-x86: fix negative overflow check bug in PACK micro-op The implementation of the x86 PACK micro-op had a logical bug that caused the `PACKSSWB` and `PACKSSDW` instructions to produce incorrect results. Specifically, due to a signedness error, the overflow check for negative integers being packed always evaluated to true, resulting in all negative integers being packed as -1 in the output. This patch fixes the signedness error that causes the bug. GitHub issue: https://github.com/gem5/gem5/issues/331 Change-Id: I44b7328a8ce31742a3c0dfaebd747f81751e8851 --- src/arch/x86/isa/microops/mediaop.isa | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arch/x86/isa/microops/mediaop.isa b/src/arch/x86/isa/microops/mediaop.isa index 599b5faef5..0b1d1fe0eb 100644 --- a/src/arch/x86/isa/microops/mediaop.isa +++ b/src/arch/x86/isa/microops/mediaop.isa @@ -393,7 +393,7 @@ let {{ // Handle saturation. if (signBit) { - if (overflow != mask(destBits - srcBits + 1)) { + if (overflow != mask(srcBits - destBits + 1)) { if (signedOp()) picked = (1ULL << (destBits - 1)); else @@ -421,7 +421,7 @@ let {{ // Handle saturation. if (signBit) { - if (overflow != mask(destBits - srcBits + 1)) { + if (overflow != mask(srcBits - destBits + 1)) { if (signedOp()) picked = (1ULL << (destBits - 1)); else