Skip to content

Commit bacc0a9

Browse files
committed
Advance the port to llvm/llvm-project@2b6b8cb
(last APFloat-related LLVM commit from 2019).
1 parent 45c2345 commit bacc0a9

File tree

4 files changed

+246
-52
lines changed

4 files changed

+246
-52
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
members = ["fuzz"]
33

44
[workspace.package]
5-
version = "0.0.2+llvm-69f6098e8931"
5+
version = "0.0.3+llvm-2b6b8cb10c87"
66
edition = "2021"
77
license = "Apache-2.0 WITH LLVM-exception"
88

src/ieee.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,17 +1866,18 @@ impl<S: Semantics> IeeeFloat<S> {
18661866
chars.next();
18671867
}
18681868

1869-
any_digits = false;
1869+
let mut any_exp_digits = false;
18701870
for c in chars {
18711871
if let Some(value) = c.to_digit(10) {
1872-
any_digits = true;
1872+
any_exp_digits = true;
18731873
dec_exp = dec_exp.saturating_mul(10).saturating_add(value as i32);
18741874
} else {
18751875
return Err(ParseError("Invalid character in exponent"));
18761876
}
18771877
}
1878-
if !any_digits {
1879-
return Err(ParseError("Exponent has no digits"));
1878+
// Treat no exponent as 0 to match binutils
1879+
if !any_exp_digits {
1880+
assert_eq!(dec_exp, 0);
18801881
}
18811882

18821883
if exp_minus {
@@ -2512,23 +2513,22 @@ mod sig {
25122513
// an addition or subtraction.
25132514
// Subtraction is more subtle than one might naively expect.
25142515
if *a_sign ^ b_sign {
2515-
let (reverse, loss);
2516+
let loss;
25162517

25172518
if bits == 0 {
2518-
reverse = cmp(a_sig, b_sig) == Ordering::Less;
25192519
loss = Loss::ExactlyZero;
25202520
} else if bits > 0 {
25212521
loss = shift_right(b_sig, &mut 0, (bits - 1) as usize);
25222522
shift_left(a_sig, a_exp, 1);
2523-
reverse = false;
25242523
} else {
25252524
loss = shift_right(a_sig, a_exp, (-bits - 1) as usize);
25262525
shift_left(b_sig, &mut 0, 1);
2527-
reverse = true;
25282526
}
25292527

25302528
let borrow = (loss != Loss::ExactlyZero) as Limb;
2531-
if reverse {
2529+
2530+
// Should we reverse the subtraction.
2531+
if cmp(a_sig, b_sig) == Ordering::Less {
25322532
// The code above is intended to ensure that no borrow is necessary.
25332533
assert_eq!(sub(b_sig, a_sig, borrow), 0);
25342534
a_sig.copy_from_slice(b_sig);

src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Port of LLVM's APFloat software floating-point implementation from the
22
//! following C++ sources (please update commit hash when backporting):
3-
//! https://github.com/llvm/llvm-project/commit/69f6098e89312b934ed87e4cd3603401a9b436b4
3+
//! https://github.com/llvm/llvm-project/commit/2b6b8cb10c870d64f7cc29d21fc27cef3c7e0056
44
//! * `llvm/include/llvm/ADT/APFloat.h` -> `Float` and `FloatConvert` traits
55
//! * `llvm/lib/Support/APFloat.cpp` -> `ieee` and `ppc` modules
66
//! * `llvm/unittests/ADT/APFloatTest.cpp` -> `tests` directory
@@ -48,6 +48,11 @@ bitflags! {
4848
/// IEEE-754R 7: Default exception handling.
4949
///
5050
/// UNDERFLOW or OVERFLOW are always returned or-ed with INEXACT.
51+
///
52+
/// APFloat models this behavior specified by IEEE-754:
53+
/// "For operations producing results in floating-point format, the default
54+
/// result of an operation that signals the invalid operation exception
55+
/// shall be a quiet NaN."
5156
#[must_use]
5257
pub struct Status: u8 {
5358
const OK = 0x00;
@@ -132,7 +137,7 @@ impl Neg for Round {
132137
}
133138

134139
/// A signed type to represent a floating point number's unbiased exponent.
135-
pub type ExpInt = i16;
140+
pub type ExpInt = i32;
136141

137142
// \c ilogb error results.
138143
pub const IEK_INF: ExpInt = ExpInt::max_value();

0 commit comments

Comments
 (0)