Skip to content

Commit

Permalink
Fix bug in x86 interval abs
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed Mar 25, 2024
1 parent e335b53 commit 0190acf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions fidget/src/core/eval/test/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ where
);
}

pub fn test_i_add_abs() {
let mut ctx = Context::new();
let x = ctx.x();
let v = ctx.add(x, 0.5).unwrap();
let out = ctx.abs(v).unwrap();

let shape = S::new(&ctx, out).unwrap();
let tape = shape.ez_interval_tape();
let mut eval = S::new_interval_eval();

assert_eq!(eval.eval_x(&tape, [-1.0, 1.0]), [0.0, 1.5].into());
}

pub fn test_i_sqrt() {
let mut ctx = Context::new();
let x = ctx.x();
Expand Down Expand Up @@ -946,6 +959,7 @@ macro_rules! interval_tests {
($t:ty) => {
$crate::interval_test!(test_interval, $t);
$crate::interval_test!(test_i_abs, $t);
$crate::interval_test!(test_i_add_abs, $t);
$crate::interval_test!(test_i_sqrt, $t);
$crate::interval_test!(test_i_square, $t);
$crate::interval_test!(test_i_sin, $t);
Expand Down
3 changes: 2 additions & 1 deletion fidget/src/jit/x86_64/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ impl Assembler for IntervalAssembler {

// Clear the lowest value of the interval, leaving us with [0, ...]
; C:
; vpshufd Rx(reg(out_reg)), Rx(reg(out_reg)), 0b11110111u8 as i8
; mov eax, (0f32).to_bits() as i32
; vpinsrd Rx(reg(out_reg)), Rx(reg(out_reg)), eax, 0
// fallthrough to end

; E:
Expand Down

0 comments on commit 0190acf

Please sign in to comment.