Skip to content

Commit

Permalink
Advance the port to llvm/llvm-project@2b6b8cb
Browse files Browse the repository at this point in the history
(last APFloat-related LLVM commit from 2019).
  • Loading branch information
eddyb committed Jul 18, 2023
1 parent 3015f8f commit a34d297
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
members = ["fuzz"]

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

Expand Down
18 changes: 9 additions & 9 deletions src/ieee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1866,17 +1866,18 @@ impl<S: Semantics> IeeeFloat<S> {
chars.next();
}

any_digits = false;
let mut any_exp_digits = false;
for c in chars {
if let Some(value) = c.to_digit(10) {
any_digits = true;
any_exp_digits = true;
dec_exp = dec_exp.saturating_mul(10).saturating_add(value as i32);
} else {
return Err(ParseError("Invalid character in exponent"));
}
}
if !any_digits {
return Err(ParseError("Exponent has no digits"));
// Treat no exponent as 0 to match binutils
if !any_exp_digits {
assert_eq!(dec_exp, 0);
}

if exp_minus {
Expand Down Expand Up @@ -2512,23 +2513,22 @@ mod sig {
// an addition or subtraction.
// Subtraction is more subtle than one might naively expect.
if *a_sign ^ b_sign {
let (reverse, loss);
let loss;

if bits == 0 {
reverse = cmp(a_sig, b_sig) == Ordering::Less;
loss = Loss::ExactlyZero;
} else if bits > 0 {
loss = shift_right(b_sig, &mut 0, (bits - 1) as usize);
shift_left(a_sig, a_exp, 1);
reverse = false;
} else {
loss = shift_right(a_sig, a_exp, (-bits - 1) as usize);
shift_left(b_sig, &mut 0, 1);
reverse = true;
}

let borrow = (loss != Loss::ExactlyZero) as Limb;
if reverse {

// Should we reverse the subtraction.
if cmp(a_sig, b_sig) == Ordering::Less {
// The code above is intended to ensure that no borrow is necessary.
assert_eq!(sub(b_sig, a_sig, borrow), 0);
a_sig.copy_from_slice(b_sig);
Expand Down
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Port of LLVM's APFloat software floating-point implementation from the
//! following C++ sources (please update commit hash when backporting):
//! https://github.com/llvm/llvm-project/commit/69f6098e89312b934ed87e4cd3603401a9b436b4
//! https://github.com/llvm/llvm-project/commit/2b6b8cb10c870d64f7cc29d21fc27cef3c7e0056
//! * `llvm/include/llvm/ADT/APFloat.h` -> `Float` and `FloatConvert` traits
//! * `llvm/lib/Support/APFloat.cpp` -> `ieee` and `ppc` modules
//! * `llvm/unittests/ADT/APFloatTest.cpp` -> `tests` directory
Expand Down Expand Up @@ -48,6 +48,11 @@ bitflags! {
/// IEEE-754R 7: Default exception handling.
///
/// UNDERFLOW or OVERFLOW are always returned or-ed with INEXACT.
///
/// APFloat models this behavior specified by IEEE-754:
/// "For operations producing results in floating-point format, the default
/// result of an operation that signals the invalid operation exception
/// shall be a quiet NaN."
#[must_use]
pub struct Status: u8 {
const OK = 0x00;
Expand Down Expand Up @@ -132,7 +137,7 @@ impl Neg for Round {
}

/// A signed type to represent a floating point number's unbiased exponent.
pub type ExpInt = i16;
pub type ExpInt = i32;

// \c ilogb error results.
pub const IEK_INF: ExpInt = ExpInt::max_value();
Expand Down
Loading

0 comments on commit a34d297

Please sign in to comment.