Skip to content

Commit

Permalink
bid128ddd_fma, bid128dqd_fma and bid128qqd_fma tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosga committed Feb 11, 2024
1 parent 20b136a commit c492277
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 31 deletions.
16 changes: 8 additions & 8 deletions src/bid128_fma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub (crate) fn bid_rounding_correction(
*ptrres = res;
}

pub(crate) fn bid_add256(x: &BID_UINT256, y: &BID_UINT256) -> BID_UINT256 {
pub (crate) fn bid_add256(x: &BID_UINT256, y: &BID_UINT256) -> BID_UINT256 {
// *z = x + yl assume the sum fits in 256 bits
let mut x: BID_UINT256 = *x;
let y: BID_UINT256 = *y;
Expand Down Expand Up @@ -158,7 +158,7 @@ pub(crate) fn bid_add256(x: &BID_UINT256, y: &BID_UINT256) -> BID_UINT256 {
z
}

pub(crate) fn bid_sub256(x: &BID_UINT256, y: &BID_UINT256) -> BID_UINT256 {
pub (crate) fn bid_sub256(x: &BID_UINT256, y: &BID_UINT256) -> BID_UINT256 {
// *z = x - y; assume x >= y
let mut x: BID_UINT256 = *x;
let mut z: BID_UINT256 = BID_UINT256::default();
Expand Down Expand Up @@ -3977,13 +3977,13 @@ pub (crate) fn bid128ddq_fma(x: BID_UINT64, y: BID_UINT64, z: &BID_UINT128, rnd_
}

pub (crate) fn bid128dqd_fma(x: BID_UINT64, y: &BID_UINT128, z: BID_UINT64, rnd_mode: u32, pfpsf: &mut _IDEC_flags) -> BID_UINT128 {
let mut is_midpoint_lt_even = false;
let mut is_midpoint_gt_even = false;
let mut is_inexact_lt_midpoint = false;
let mut is_inexact_gt_midpoint = false;
let mut is_midpoint_lt_even: bool = false;
let mut is_midpoint_gt_even: bool = false;
let mut is_inexact_lt_midpoint: bool = false;
let mut is_inexact_gt_midpoint: bool = false;

let x1: BID_UINT128 = bid64_to_bid128(x, pfpsf);
let z1: BID_UINT128 = bid64_to_bid128(z, pfpsf);
let x1: BID_UINT128 = bid64_to_bid128(x, pfpsf);
let z1: BID_UINT128 = bid64_to_bid128(z, pfpsf);

bid128_ext_fma(
&mut is_midpoint_lt_even,
Expand Down
36 changes: 18 additions & 18 deletions src/bid128_noncomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,12 @@ pub (crate) fn bid128_total_order(x: &BID_UINT128, y: &BID_UINT128) -> bool {
// 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
// [0, 10^34) is the 754 supported canonical range.
// If the value exceeds that, it is interpreted as 0.
if (((sig_x.w[1] > 0x0001ed09bead87c0u64) ||
((sig_x.w[1] == 0x0001ed09bead87c0u64) &&
(sig_x.w[0] > 0x378d8e63ffffffffu64))) &&
((x.w[1] & 0x6000000000000000u64) != 0x6000000000000000u64)) ||
((x.w[1] & 0x6000000000000000u64) == 0x6000000000000000u64) ||
((sig_x.w[1] == 0) && (sig_x.w[0] == 0)) {
if (((sig_x.w[1] > 0x0001ed09bead87c0u64)
|| ((sig_x.w[1] == 0x0001ed09bead87c0u64)
&& (sig_x.w[0] > 0x378d8e63ffffffffu64)))
&& ((x.w[1] & 0x6000000000000000u64) != 0x6000000000000000u64))
|| ((x.w[1] & 0x6000000000000000u64) == 0x6000000000000000u64)
|| ((sig_x.w[1] == 0) && (sig_x.w[0] == 0)) {
x_is_zero = true;
// check for the case where the exponent is shifted right by 2 bits!
if (x.w[1] & 0x6000000000000000u64) == 0x6000000000000000u64 {
Expand All @@ -569,12 +569,12 @@ pub (crate) fn bid128_total_order(x: &BID_UINT128, y: &BID_UINT128) -> bool {
// 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
// [0, 10^34) is the 754 supported canonical range.
// If the value exceeds that, it is interpreted as 0.
if (((sig_y.w[1] > 0x0001ed09bead87c0u64) ||
((sig_y.w[1] == 0x0001ed09bead87c0u64) &&
(sig_y.w[0] > 0x378d8e63ffffffffu64))) &&
((y.w[1] & 0x6000000000000000u64) != 0x6000000000000000u64)) ||
((y.w[1] & 0x6000000000000000u64) == 0x6000000000000000u64) ||
((sig_y.w[1] == 0) && (sig_y.w[0] == 0)) {
if (((sig_y.w[1] > 0x0001ed09bead87c0u64)
|| ((sig_y.w[1] == 0x0001ed09bead87c0u64)
&& (sig_y.w[0] > 0x378d8e63ffffffffu64)))
&& ((y.w[1] & 0x6000000000000000u64) != 0x6000000000000000u64))
|| ((y.w[1] & 0x6000000000000000u64) == 0x6000000000000000u64)
|| ((sig_y.w[1] == 0) && (sig_y.w[0] == 0)) {
y_is_zero = true;
// check for the case where the exponent is shifted right by 2 bits!
if (y.w[1] & 0x6000000000000000u64) == 0x6000000000000000u64 {
Expand Down Expand Up @@ -807,12 +807,12 @@ pub (crate) fn bid128_total_order_mag(x: &BID_UINT128, y: &BID_UINT128) -> bool
// 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
// [0, 10^34) is the 754 supported canonical range.
// If the value exceeds that, it is interpreted as 0.
if (((sig_y.w[1] > 0x0001ed09bead87c0u64) ||
((sig_y.w[1] == 0x0001ed09bead87c0u64) &&
(sig_y.w[0] > 0x378d8e63ffffffffu64))) &&
((y.w[1] & 0x6000000000000000u64) != 0x6000000000000000u64)) ||
((y.w[1] & 0x6000000000000000u64) == 0x6000000000000000u64) ||
((sig_y.w[1] == 0) && (sig_y.w[0] == 0)) {
if (((sig_y.w[1] > 0x0001ed09bead87c0u64)
|| ((sig_y.w[1] == 0x0001ed09bead87c0u64)
&& (sig_y.w[0] > 0x378d8e63ffffffffu64)))
&& ((y.w[1] & 0x6000000000000000u64) != 0x6000000000000000u64))
|| ((y.w[1] & 0x6000000000000000u64) == 0x6000000000000000u64)
|| ((sig_y.w[1] == 0) && (sig_y.w[0] == 0)) {
y_is_zero = true;
// check for the case where the exponent is shifted right by 2 bits!
if (y.w[1] & 0x6000000000000000u64) == 0x6000000000000000u64 {
Expand Down
6 changes: 3 additions & 3 deletions src/bid_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,8 @@ pub (crate) fn handle_UF_128(sgn: BID_UINT64, expon: i32, CQ: &BID_UINT128, rnd_
pub (crate) fn unpack_BID128_value_BLE(psign_x: &mut BID_UINT64, pexponent_x: &mut i32, pcoefficient_x: &mut BID_UINT128, x: &BID_UINT128) -> BID_UINT64 {
let mut coeff: BID_UINT128 = BID_UINT128::default();
let mut T33: BID_UINT128 = BID_UINT128::default();
let mut T34: &BID_UINT128;
let mut ex: BID_UINT64;
let T34: &BID_UINT128;
let ex: BID_UINT64;

*psign_x = (x.w[BID_HIGH_128W]) & 0x8000000000000000u64;

Expand Down Expand Up @@ -628,7 +628,7 @@ pub (crate) fn unpack_BID128_value_BLE(psign_x: &mut BID_UINT64, pexponent_x: &m
ex = (x.w[BID_HIGH_128W]) >> 49;
*pexponent_x = (ex as i32) & EXPONENT_MASK128;

return coeff.w[BID_LOW_128W] | coeff.w[BID_HIGH_128W];
coeff.w[BID_LOW_128W] | coeff.w[BID_HIGH_128W]
}

/// BID128 unpack, input passed by value
Expand Down
20 changes: 19 additions & 1 deletion src/d128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::bid128_add::{bid128_add, bid128_sub};
use crate::bid128_compare::{bid128_quiet_equal, bid128_quiet_greater, bid128_quiet_greater_equal, bid128_quiet_less, bid128_quiet_less_equal, bid128_quiet_not_equal};
use crate::bid128_div::bid128_div;
use crate::bid128_fdim::bid128_fdim;
use crate::bid128_fma::bid128_fma;
use crate::bid128_fma::{bid128_fma, bid128ddd_fma, bid128dqd_fma, bid128qqd_fma};
use crate::bid128_fmod::bid128_fmod;
use crate::bid128_frexp::bid128_frexp;
use crate::bid128_ilogb::bid128_ilogb;
Expand Down Expand Up @@ -282,6 +282,24 @@ impl d128 {
bid128_fma(x, y, z, rnd_mode.unwrap_or(DEFAULT_ROUNDING_MODE), pfpsf)
}

/// Decimal floating-point fused multiply-add, UINT64 * UINT64 + UINT64 -> UINT128
#[must_use]
pub fn ddd_fma(x: d64, y: d64, z: d64, rnd_mode: Option<u32>, pfpsf: &mut _IDEC_flags) -> Self {
bid128ddd_fma(x.0, y.0, z.0, rnd_mode.unwrap_or(DEFAULT_ROUNDING_MODE), pfpsf)
}

/// Decimal floating-point fused multiply-add d64 * d128 + d64 -> d128
#[must_use]
pub fn dqd_fma(x: d64, y: &Self, z: d64, rnd_mode: Option<u32>, pfpsf: &mut _IDEC_flags) -> Self {
bid128dqd_fma(x.0, y, z.0, rnd_mode.unwrap_or(DEFAULT_ROUNDING_MODE), pfpsf)
}

/// Decimal floating-point fused multiply-add, UINT128 * UINT128 + UINT64
#[must_use]
pub fn qqd_fma(x: &Self, y: &Self, z: d64, rnd_mode: Option<u32>, pfpsf: &mut _IDEC_flags) -> Self {
bid128qqd_fma(x, y, z.0, rnd_mode.unwrap_or(DEFAULT_ROUNDING_MODE), pfpsf)
}

/// Computes the decimal floating point remainder of the division operation x / y.
#[must_use]
pub fn fmod(&self, rhs: &BID_UINT128, pfpsf: &mut _IDEC_flags) -> Self {
Expand Down
3 changes: 2 additions & 1 deletion src/d64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#![allow(non_camel_case_types)]

use crate::d128::BID_UINT64;

#[derive(Copy, Clone, Debug, Default)]
// #[repr(transparent)]
#[repr(transparent)]
pub struct d64(pub BID_UINT64);
15 changes: 15 additions & 0 deletions tests/bid128ddd_fma.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* ---------------------------------------------------------------------------------------------------*/
/* Port of the Intel Decimal Floating-Point Math Library decimal128 type to Rust. */
/* decmathlib-rs - Copyright (C) 2023-2024 Carlos Guzmán Álvarez */
/* -------------------------------------------------------------------------------------------------- */
/* Licensed under the MIT license. See LICENSE file in the project root for full license information. */
/* -------------------------------------------------------------------------------------------------- */
/* Intel® Decimal Floating-Point Math Library - Copyright (c) 2018, Intel Corp. */
/* -------------------------------------------------------------------------------------------------- */

mod common;

dec_test!(bid128ddd_fma_001, bid128ddd_fma, 0, 0x0000000000000200u64, 0x1a13bc50c402d5c3u64, 0x4c31067288024880u64, 0x31c2ec459ba7304fe49a4fafd2000000u128, 0x20);
dec_test!(bid128ddd_fma_002, bid128ddd_fma, 0, 0x1739a39084f14140u64, 0x926a2b0a0b343625u64, 0x0000000000000001u64, 0x2ce2314dc6448d9338c15b0a00000000u128, 0x20);
dec_test!(bid128ddd_fma_003, bid128ddd_fma, 0, 0x2000a080a0205904u64, 0xfffffffffffeffffu64, 0xc10282f50825c160u64, 0xfc000000000000000000000000000000u128, 0x01);
dec_test!(bid128ddd_fma_004, bid128ddd_fma, 0, 0xd6df8feb53d2d16eu64, 0x0080000000002000u64, 0x4589aa10001a14d1u64, 0x3158861e83b104da4f3a31e778a40000u128, 0x20);
26 changes: 26 additions & 0 deletions tests/bid128dqd_fma.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* ---------------------------------------------------------------------------------------------------*/
/* Port of the Intel Decimal Floating-Point Math Library decimal128 type to Rust. */
/* decmathlib-rs - Copyright (C) 2023-2024 Carlos Guzmán Álvarez */
/* -------------------------------------------------------------------------------------------------- */
/* Licensed under the MIT license. See LICENSE file in the project root for full license information. */
/* -------------------------------------------------------------------------------------------------- */
/* Intel® Decimal Floating-Point Math Library - Copyright (c) 2018, Intel Corp. */
/* -------------------------------------------------------------------------------------------------- */

mod common;

dec_test!(bid128dqd_fma_001, bid128dqd_fma, 0, 0x0086160000000020u64, 0xb1391009800a0042c000908a04042868u128, 0x0ffcc8873e852186u64, 0xae43d2029d2629774758ed4174e92652u128, 0x20);
dec_test!(bid128dqd_fma_002, bid128dqd_fma, 0, 0x0200000000000221u64, 0xd1b1c5c21b11c1790256eb0280101c44u128, 0x2ec6dd1e23efc638u64, 0xcebaf74c58fe2829a146690a529823e2u128, 0x20);
dec_test!(bid128dqd_fma_003, bid128dqd_fma, 0, 0x0498824b421b570bu64, 0xb0a4203090e084034c69fd547b1ee813u128, 0x8eff36f9b0984713u64, 0xadf041869773c92d493dd6ca4ccf76c8u128, 0x20);
dec_test!(bid128dqd_fma_004, bid128dqd_fma, 0, 0x29880451882a8a88u64, 0xad24beb7771757d1b64b78f5e685f47au128, 0x0030040080001001u64, 0x2d02de42f505a1157cfdf129e763ffffu128, 0x20);
dec_test!(bid128dqd_fma_005, bid128dqd_fma, 0, 0x2d1d42e928a9803au64, 0x0000000000010000ffffffffffffffffu128, 0x67ebb6ff2ff7ffffu64, 0x00000000000000000000000000000064u128, 0x30);
dec_test!(bid128dqd_fma_006, bid128dqd_fma, 0, 0x365fff6945393ad2u64, 0x4000000000000000ffdffffffff7ffffu128, 0x1fffb9ffffefffffu64, 0x404c51dfc6002a6d3a05fa77cf150718u128, 0x20);
dec_test!(bid128dqd_fma_007, bid128dqd_fma, 0, 0x4463ac7236f84442u64, 0x4800000000000200d57d1f27af3fc4bau128, 0x010cba61d9eab2a5u64, 0x4931e24aeec020234b865286e1c65ec1u128, 0x20);
dec_test!(bid128dqd_fma_008, bid128dqd_fma, 0, 0x5fc000000000000au64, 0xaffc0000000000000000000000000005u128, 0x5fe000000000000au64, 0x32e2314dc6448d9338c15b0a00000000u128, 0x20);
dec_test!(bid128dqd_fma_009, bid128dqd_fma, 0, 0x70105daa2a61403bu64, 0xafa7525a66752d34572321e3fb7b7a5cu128, 0xbaf219be0c80e664u64, 0xb0b037f1b4a14284f7f1a6cd8e7cb8a1u128, 0x20);
dec_test!(bid128dqd_fma_010, bid128dqd_fma, 0, 0xdfdafbd7757b5c75u64, 0xb0215e4da4a9882a0f71b9fddb2406ddu128, 0xddafdfeff9bff7bfu64, 0x33210a106e84676b01e6c72ef6b8af2au128, 0x20);
dec_test!(bid128dqd_fma_011, bid128dqd_fma, 0, 0xfdeffffd7afb6fdfu64, 0x04611048200040000000000000000024u128, 0x4778fe9c3de62935u64, 0xfc000000000000000000000000000000u128, 0x00);
dec_test!(bid128dqd_fma_012, bid128dqd_fma, 1, 0x5fc000000000000au64, 0xaffc0000000000000000000000000005u128, 0x5fe000000000000au64, 0x32e1ed09bead87c0378d8e63ffffffffu128, 0x20);
dec_test!(bid128dqd_fma_013, bid128dqd_fma, 2, 0x5fc000000000000au64, 0xaffc0000000000000000000000000005u128, 0x5fe000000000000au64, 0x32e2314dc6448d9338c15b0a00000000u128, 0x20);
dec_test!(bid128dqd_fma_014, bid128dqd_fma, 3, 0x5fc000000000000au64, 0xaffc0000000000000000000000000005u128, 0x5fe000000000000au64, 0x32e1ed09bead87c0378d8e63ffffffffu128, 0x20);
dec_test!(bid128dqd_fma_015, bid128dqd_fma, 4, 0x5fc000000000000au64, 0xaffc0000000000000000000000000005u128, 0x5fe000000000000au64, 0x32e2314dc6448d9338c15b0a00000000u128, 0x20);
20 changes: 20 additions & 0 deletions tests/bid128qqd_fma.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* ---------------------------------------------------------------------------------------------------*/
/* Port of the Intel Decimal Floating-Point Math Library decimal128 type to Rust. */
/* decmathlib-rs - Copyright (C) 2023-2024 Carlos Guzmán Álvarez */
/* -------------------------------------------------------------------------------------------------- */
/* Licensed under the MIT license. See LICENSE file in the project root for full license information. */
/* -------------------------------------------------------------------------------------------------- */
/* Intel® Decimal Floating-Point Math Library - Copyright (c) 2018, Intel Corp. */
/* -------------------------------------------------------------------------------------------------- */

mod common;

dec_test!(bid128qqd_fma_001, bid128qqd_fma, 0, 0x33200000000000000000000000000005u128, 0xaffa000000000000000000000000000au128, 0x5fc000000000000au64, 0x32e0314dc6448d9338c15b0a00000000u128, 0x20);
dec_test!(bid128qqd_fma_002, bid128qqd_fma, 0, 0x3e3457aafb3df933c3fee7c69c7e2cedu128, 0x9ef1afc349a9e0f7ea6eddcb5fba5f77u128, 0x0400000000000400u64, 0xad2706da8013883c784a53ea962fb9a1u128, 0x20);
dec_test!(bid128qqd_fma_003, bid128qqd_fma, 0, 0x7ebfbeccd7abf5fd59cfb7fcddf796b9u128, 0xf7ffdfcfbfffdfa76090116410408204u128, 0x5e00c510800080a5u64, 0x7c000000000000000000000000000000u128, 0x01);
dec_test!(bid128qqd_fma_004, bid128qqd_fma, 0, 0x8fb728087e5a3d6fb6ec3208b2eeef49u128, 0x5083808465200044fbfffefd7fff6eebu128, 0x2d3d531f65fdc592u64, 0xb03ce6dfd4e881d4e9a5446bfbe2bdcau128, 0x20);
dec_test!(bid128qqd_fma_005, bid128qqd_fma, 0, 0xd9fe7fffffbff7fa0000000000000000u128, 0x87a296fea05f07f10000000000000000u128, 0xc22b5a8f762025a1u64, 0x31a38801250e5648ef50d2e20648113cu128, 0x20);
dec_test!(bid128qqd_fma_006, bid128qqd_fma, 1, 0x33200000000000000000000000000005u128, 0xaffa000000000000000000000000000au128, 0x5fc000000000000au64, 0x32dfed09bead87c0378d8e63ffffffffu128, 0x20);
dec_test!(bid128qqd_fma_007, bid128qqd_fma, 2, 0x33200000000000000000000000000005u128, 0xaffa000000000000000000000000000au128, 0x5fc000000000000au64, 0x32e0314dc6448d9338c15b0a00000000u128, 0x20);
dec_test!(bid128qqd_fma_008, bid128qqd_fma, 3, 0x33200000000000000000000000000005u128, 0xaffa000000000000000000000000000au128, 0x5fc000000000000au64, 0x32dfed09bead87c0378d8e63ffffffffu128, 0x20);
dec_test!(bid128qqd_fma_009, bid128qqd_fma, 4, 0x33200000000000000000000000000005u128, 0xaffa000000000000000000000000000au128, 0x5fc000000000000au64, 0x32e0314dc6448d9338c15b0a00000000u128, 0x20);
48 changes: 48 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,4 +1046,52 @@ macro_rules! dec_test {
assert_eq!($exp, res);
}
};

($name:ident, bid128ddd_fma, $rnd_mode:expr, $input1:expr, $input2:expr, $input3:expr, $exp:expr, $exp_status:expr) => {
#[test]
fn $name() {
let mut status: decmathlib_rs::d128::_IDEC_flags = 0;
let rnd_mode = Some($rnd_mode);
let x = decmathlib_rs::d64::d64($input1);
let y = decmathlib_rs::d64::d64($input2);
let z = decmathlib_rs::d64::d64($input3);
let exp = decmathlib_rs::d128::d128::from($exp);
let res1 = decmathlib_rs::d128::d128::ddd_fma(x, y, z, rnd_mode, &mut status);

assert_eq!(exp, res1);
assert_eq!($exp_status, status)
}
};

($name:ident, bid128dqd_fma, $rnd_mode:expr, $input1:expr, $input2:expr, $input3:expr, $exp:expr, $exp_status:expr) => {
#[test]
fn $name() {
let mut status: decmathlib_rs::d128::_IDEC_flags = 0;
let rnd_mode = Some($rnd_mode);
let x = decmathlib_rs::d64::d64($input1);
let y = decmathlib_rs::d128::d128::from($input2);
let z = decmathlib_rs::d64::d64($input3);
let exp = decmathlib_rs::d128::d128::from($exp);
let res1 = decmathlib_rs::d128::d128::dqd_fma(x, &y, z, rnd_mode, &mut status);

assert_eq!(exp, res1);
assert_eq!($exp_status, status)
}
};

($name:ident, bid128qqd_fma, $rnd_mode:expr, $input1:expr, $input2:expr, $input3:expr, $exp:expr, $exp_status:expr) => {
#[test]
fn $name() {
let mut status: decmathlib_rs::d128::_IDEC_flags = 0;
let rnd_mode = Some($rnd_mode);
let x = decmathlib_rs::d128::d128::from($input1);
let y = decmathlib_rs::d128::d128::from($input2);
let z = decmathlib_rs::d64::d64($input3);
let exp = decmathlib_rs::d128::d128::from($exp);
let res1 = decmathlib_rs::d128::d128::qqd_fma(&x, &y, z, rnd_mode, &mut status);

assert_eq!(exp, res1);
assert_eq!($exp_status, status)
}
};
}

0 comments on commit c492277

Please sign in to comment.