Skip to content

Commit

Permalink
Almost all x86 rounding implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter committed May 12, 2024
1 parent 693d249 commit 22ff723
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
1 change: 0 additions & 1 deletion fidget/src/jit/x86_64/float_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ impl Assembler for FloatSliceAssembler {
);
}

// TODO optimize these three functions
fn build_floor(&mut self, out_reg: u8, lhs_reg: u8) {
dynasm!(self.0.ops
; vroundps Ry(reg(out_reg)), Ry(reg(lhs_reg)), 1
Expand Down
32 changes: 19 additions & 13 deletions fidget/src/jit/x86_64/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,30 @@ impl Assembler for IntervalAssembler {
);
self.0.ops.commit_local().unwrap();
}
// TODO hand-write these functions
fn build_floor(&mut self, out_reg: u8, lhs_reg: u8) {
extern "sysv64" fn interval_floor(v: Interval) -> Interval {
v.floor()
}
self.call_fn_unary(out_reg, lhs_reg, interval_floor);
dynasm!(self.0.ops
; vroundps Rx(reg(out_reg)), Rx(reg(lhs_reg)), 1
);
}
fn build_ceil(&mut self, out_reg: u8, lhs_reg: u8) {
extern "sysv64" fn interval_ceil(v: Interval) -> Interval {
v.ceil()
}
self.call_fn_unary(out_reg, lhs_reg, interval_ceil);
dynasm!(self.0.ops
; vroundps Rx(reg(out_reg)), Rx(reg(lhs_reg)), 2
);
}
fn build_round(&mut self, out_reg: u8, lhs_reg: u8) {
extern "sysv64" fn interval_round(v: Interval) -> Interval {
v.round()
}
self.call_fn_unary(out_reg, lhs_reg, interval_round);
// Shenanigans figured through Godbolt
dynasm!(self.0.ops
; mov eax, 0x80000000u32 as i32
; vmovd xmm1, eax
; vbroadcastss xmm1, xmm1
; vandps xmm1, xmm1, Rx(reg(lhs_reg))
; mov eax, 0x3effffffu32 as i32
; vmovd xmm2, eax
; vbroadcastss xmm2, xmm2
; vorps xmm1, xmm1, xmm2
; vaddps Rx(reg(out_reg)), xmm1, Rx(reg(lhs_reg))
; vroundps Rx(reg(out_reg)), Rx(reg(out_reg)), 3
);
}

fn build_add(&mut self, out_reg: u8, lhs_reg: u8, rhs_reg: u8) {
Expand Down
1 change: 0 additions & 1 deletion fidget/src/jit/x86_64/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ impl Assembler for PointAssembler {
);
}

// TODO optimize these three functions
fn build_floor(&mut self, out_reg: u8, lhs_reg: u8) {
dynasm!(self.0.ops
; vroundss Rx(reg(out_reg)), Rx(reg(lhs_reg)), Rx(reg(lhs_reg)), 1
Expand Down

0 comments on commit 22ff723

Please sign in to comment.