Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unimplemented intrinsic: frem_fast #810

Open
adpaco-aws opened this issue Feb 8, 2022 · 1 comment
Open

Unimplemented intrinsic: frem_fast #810

adpaco-aws opened this issue Feb 8, 2022 · 1 comment
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature. [E] Unsupported Construct Add support to an unsupported construct

Comments

@adpaco-aws
Copy link
Contributor

In #804 I made an attempt to implement frem_fast (floating-point remainder) as %, but the test I wrote was failing even though the same expression is being used to codegen both:

#![feature(core_intrinsics)]

// Unconstrained floating point values will cause performance issues in this
// operation. To avoid them, we assume values within a moderate range.
const MIN_FP_VALUE: f32 = 0.1;
const MAX_FP_VALUE: f32 = 100.0;

fn assume_fp_range(val: f32) {
    if val.is_sign_positive() {
        kani::assume(val > MIN_FP_VALUE);
        kani::assume(val < MAX_FP_VALUE);
    } else {
        kani::assume(val < -MIN_FP_VALUE);
        kani::assume(val > -MAX_FP_VALUE);
    }
}

fn main() {
    let x: f32 = kani::any();
    let y: f32 = kani::any();

    kani::assume(x.is_finite());
    kani::assume(y.is_finite());
    assume_fp_range(x);
    assume_fp_range(y);

    let z = unsafe { std::intrinsics::frem_fast(x, y) };
    let w = x % y;
    assert!(z == w);
}

Then I reflected on what this operation means in the case of floating point numbers and realized it needed more work. It is not clear to me what is the irep we should using to encode this operation, so we should find out and use that.

@adpaco-aws adpaco-aws added Area: compilation [F] Crash Kani crashed [C] Feature / Enhancement A new feature request or enhancement to an existing feature. labels Feb 8, 2022
@adpaco-aws adpaco-aws self-assigned this Feb 8, 2022
This was referenced Feb 8, 2022
@tautschnig
Copy link
Member

For floating point modulo/remainder operations, please use "floatbv_rem" as the expression id. All other binary arithmetic expressions will be rewritten from their usual operators to floating-point specific ones during GOTO conversion. This is not the case for modulo as that's not even permitted in C over floating point, and also there's no need to add a rounding mode.

@celinval celinval added [E] Unsupported Construct Add support to an unsupported construct and removed Area: compilation [F] Crash Kani crashed labels Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature. [E] Unsupported Construct Add support to an unsupported construct
Projects
None yet
Development

No branches or pull requests

3 participants