Compare commits

...
Author SHA1 Message Date
zachdoxsee b1b57cf16a Merge upstream main into task/128-exact-unmasked-overflow
Conflict in CHANGELOG.md only: both new entries are kept.

Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-24 20:40:31 +01:00
sahib453 403a67747f loader: set only the overflow flag for an exact unmasked overflow (#128)
With the overflow exception unmasked, an overflow whose result is exact
before the exponent is bounded set the MXCSR precision flag as well as
the overflow flag. The Intel SDM (Vol. 1, D.4.2.3, Table D-16) reports
precision there only if rounding with an unbounded exponent is inexact.

- softfloat.rs: Control reads the overflow mask, and round() reports
  precision on an unmasked overflow only when the result was rounded.
  The masked response is unchanged.
- cpu_known_answers.rs: the five exact-overflow cases are no longer an
  ignored defect, three more cover the other rounding modes, and the
  scalar and conversion sweeps now compare the precision flag here.
- docs/cpu/instruction-registry.md: the behaviour is no longer listed
  as unasserted.

Signed-off-by: sahib453 <117431595+sahib453@users.noreply.github.com>
2026-11-24 23:25:07 +05:30
4 changed files with 22 additions and 16 deletions

No files matched your search

+1
View File
@@ -193,6 +193,7 @@ remains unsupported.
### Fixed
- Made the static probe and the binder share one bounded import parser, after the truncated-name fix for #270. Truncated, unterminated, empty or non-ASCII names, reserved bits and endless tables are reported by the probe and refused by the binder.
- Fixed the MXCSR flags of an unmasked floating-point overflow whose result is exact before the exponent is bounded, such as the largest binary32 value times two (#128). Only the overflow flag is set; the precision flag used to be set as well although nothing was rounded. A masked overflow still sets both flags and delivers infinity or the largest finite value, and an unmasked overflow that is also inexact still sets both. Five Intel SDM cases in `cpu_known_answers.rs` moved from open defect to verified on both engines, with three more for the other rounding modes, and the scalar and conversion sweeps now compare the precision flag in this case as well. Not compared with x86 hardware; awaiting independent review.
- Fixed the decoder refusing an instruction whose REX prefix is followed by a legacy prefix (#69). Such a REX is ignored, as the Intel SDM (Vol. 2A, 2.2.1) specifies, so `48 66 01 D8` now runs as `add ax, bx`; it used to stop the guest with an illegal-instruction exit. The ignored byte still counts toward the instruction's length, and a REX that directly precedes the opcode behaves as before. The interpreter, the DBT and the static probe share the decoder. One SDM-derived case in `cpu_known_answers.rs` moved from refused to verified and three were added, for an ignored REX.B, an ignored REX.W before a segment prefix, and a later REX that does apply. Two REX bytes in a row and the address-size prefix stay rejected. Not compared with x86 hardware; awaiting independent review.
- Fixed import binding writing some slots before finding an unresolved import, and service calls taking effect before an unreadable return address was noticed. A service that changes a nonvolatile register, including XMM6 to XMM15, now stops the guest (part of #201).
- Fixed older import-generator templates that reported success for unimplemented wrappers, used a nonexistent exit reason, and read floating-point arguments from integer registers.
+10
View File
@@ -35,6 +35,7 @@ pub struct Control {
pub rounding: Rounding,
pub denormals_are_zero: bool,
pub flush_to_zero: bool,
pub overflow_masked: bool,
pub underflow_masked: bool,
}
@@ -49,6 +50,7 @@ impl Control {
},
denormals_are_zero: mxcsr & 1 << 6 != 0,
flush_to_zero: mxcsr & 1 << 15 != 0,
overflow_masked: mxcsr & 1 << 10 != 0,
underflow_masked: mxcsr & 1 << 11 != 0,
}
}
@@ -263,6 +265,14 @@ fn round(
flags |= PRECISION;
}
if leading > format.bias() {
if !control.overflow_masked {
// No result is delivered. Precision is reported only if rounding
// with an unbounded exponent was inexact.
return Outcome {
bits: 0,
flags: OVERFLOW | if inexact { PRECISION } else { 0 },
};
}
let to_infinity = match control.rounding {
Rounding::Nearest => true,
Rounding::Down => sign,
+8 -14
View File
@@ -2608,12 +2608,15 @@ add_memory_crosses_contiguous_pages: rdi=D+1000 mffd=ffffffffffffffff => mffd=00
push_pop_cross_contiguous_pages: rsp=D+1004 rax=1122334455667788 => rbx=1122334455667788 mffc=8877665544332211 f=*
";
const DEFECT_EXACT_UNMASKED_OVERFLOW: &str = r"
const EXACT_UNMASKED_OVERFLOW: &str = r"
@ mulss xmm1, xmm2
!f30f59ca
SDM 1 D.4.2.3 Table D-16 (PE only if inexact); APM 1 4.10.2.8
unmasked_overflow_exact_sets_only_oe: x1=s:7f7fffff x2=s:40000000 mx=1b80 => mx=1b88 f=* ! XM
unmasked_negative_overflow_exact_sets_only_oe: x1=s:ff7fffff x2=s:40000000 mx=1b80 => mx=1b88 f=* ! XM
unmasked_overflow_exact_sets_only_oe_down: x1=s:7f7fffff x2=s:40000000 mx=3b80 => mx=3b88 f=* ! XM
unmasked_overflow_exact_sets_only_oe_up: x1=s:7f7fffff x2=s:40000000 mx=5b80 => mx=5b88 f=* ! XM
unmasked_overflow_exact_sets_only_oe_zero: x1=s:7f7fffff x2=s:40000000 mx=7b80 => mx=7b88 f=* ! XM
@ addsd xmm1, xmm2
!f20f58ca
SDM 1 D.4.2.3 Table D-16 (PE only if inexact); APM 1 4.10.2.8
@@ -2661,10 +2664,7 @@ const GROUPS: &[(&str, &str)] = &[
("fp_mxcsr_and_unmasked", FP_MXCSR_AND_UNMASKED),
("fp_beyond_sse2", FP_BEYOND_SSE2),
("defect_overlong_instruction", DEFECT_OVERLONG_INSTRUCTION),
(
"defect_exact_unmasked_overflow",
DEFECT_EXACT_UNMASKED_OVERFLOW,
),
("exact_unmasked_overflow", EXACT_UNMASKED_OVERFLOW),
("page_crossing", PAGE_CROSSING),
];
@@ -3510,9 +3510,8 @@ fn defect_overlong_instruction() {
}
#[test]
#[ignore = "known defect (#155): an exact unmasked overflow sets PE as well as OE"]
fn defect_exact_unmasked_overflow() {
check_group(DEFECT_EXACT_UNMASKED_OVERFLOW);
fn exact_unmasked_overflow() {
check_group(EXACT_UNMASKED_OVERFLOW);
}
#[test]
@@ -4731,12 +4730,7 @@ fn deliver(
}
if lowest + precision - 1 > format.max_exponent() {
if mxcsr & OM == 0 {
// PE of an exact overflow is `defect_exact_unmasked_overflow`; this
// sweep compares every other bit.
return Outcome {
open: if unbounded_exact { PE } else { 0 },
..outcome(0, OE | unbounded_inexact)
};
return outcome(0, OE | unbounded_inexact);
}
let to_infinity = match mode {
0 => true,
+3 -2
View File
@@ -40,8 +40,9 @@ XMM registers live in `CpuState::xmm`, lane 0 in the low bits, and MXCSR in `Cpu
- a denormal dividend over zero raises divide-by-zero only, not also denormal-operand;
- flush-to-zero also flushes a tiny result that is exact, raising underflow and precision;
- DAZ applies before conversion to an integer;
- an unmasked overflow also records precision.
- DAZ applies before conversion to an integer.
An unmasked overflow records precision only when rounding with an unbounded exponent is inexact (Intel SDM Vol. 1, D.4.2.3, Table D-16). The known-answer cases in `tests/cpu_known_answers.rs` assert this.
None of it has been compared with x86 hardware.