From 985185f8a6487b22d328c86b9e497f8f1c603b7d Mon Sep 17 00:00:00 2001 From: Darkar25 Date: Wed, 16 Sep 2026 23:05:53 +0300 Subject: [PATCH] Fix 64-bit FMOV immediate decoding DecodeFPImm shifted the fraction nibble as a 32-bit value: `frac <<= f - 4` with f = 52 is a shift count of 48, which C# masks modulo 32, so the nibble landed at bit 16 of the result instead of bit 48. `fmov d16, #15.0` was therefore decoded as 8.000000001629815 (10.0 -> 8.000000000465661, 5.0 -> 4.000000000232831). The 32-bit and 16-bit paths were unaffected because their shifts (19 and 6) do not wrap. Shift the fraction as a 64-bit value. The expansion (sign | E | F with E = NOT(b):Replicate(b,8):c:d, F = efgh:Zeros(48), imm8 = s:b:cd:efgh) was validated against capstone for all 256 immediate encodings. --- Disarm/InternalDisassembly/Arm64CommonUtils.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Disarm/InternalDisassembly/Arm64CommonUtils.cs b/Disarm/InternalDisassembly/Arm64CommonUtils.cs index f10a6f5..fbc2595 100644 --- a/Disarm/InternalDisassembly/Arm64CommonUtils.cs +++ b/Disarm/InternalDisassembly/Arm64CommonUtils.cs @@ -330,8 +330,10 @@ public static double DecodeFPImm(uint pType, uint imm8) //Finally add bits 5 and 4 exp |= (imm8 & 0b0011_0000U) >> 4; - var frac = imm8 & 0b0000_1111U; - frac <<= f - 4; //Append f - 4 0s + // Keep the shifted fraction 64-bit: the 64-bit format needs a 48-bit shift, and shifting a + // 32-bit value would wrap the count modulo 32, parking the fraction nibble at bit 16 + // instead of bit 48 (e.g. `fmov d16, #15.0` decoded as 8.000000001629815). + var frac = (ulong)(imm8 & 0b0000_1111U) << (f - 4); //Append f - 4 0s var resultBits = (signBit ? 1UL : 0UL) << (n - 1); resultBits |= (ulong)exp << f;