Skip to content

Commit 973b879

Browse files
correctly use no_std, get rid of macro in exchange for zips and maps, bump ver
1 parent 783ed18 commit 973b879

File tree

8 files changed

+33
-44
lines changed

8 files changed

+33
-44
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "fath"
33
authors = [ "burgerindividual", "duplexsystem" ]
4-
version = "0.1.5"
4+
version = "0.1.6"
55
edition = "2021"
66
license = "LGPL-3.0"
77
repository = "https://github.com/burgerindividual/fath"

src/lib.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
#![feature(core_intrinsics, portable_simd)]
2-
// #![no_std]
3-
4-
pub extern crate std as core;
5-
6-
extern crate alloc;
1+
#![feature(core_intrinsics, portable_simd, array_zip)]
2+
#![no_std]
73

84
pub mod scalar;
95
pub mod shared;
106
// #![cfg_attr(feature = "portable_simd", feature(portable_simd))]
117
pub mod simd;
128

139
#[cfg(test)]
14-
pub mod test;
10+
pub mod test;

src/simd/consts.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/simd/float.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::shared::float::*;
2-
use crate::*;
32
use core::simd::*;
43

54
impl<const LANES: usize> FastApproxFloat for Simd<f32, LANES>
@@ -8,21 +7,37 @@ where
87
{
98
#[inline(always)]
109
unsafe fn sin_fast_approx<const PRECISION: usize>(self) -> Self {
11-
wrap_auto_vectorize!(sin_fast_approx::<PRECISION, false>, LANES, self)
10+
Simd::from_array(
11+
self.as_array()
12+
.map(|e| sin_fast_approx::<PRECISION, false>(e)),
13+
)
1214
}
1315

1416
#[inline(always)]
1517
unsafe fn cos_fast_approx<const PRECISION: usize>(self) -> Self {
16-
wrap_auto_vectorize!(sin_fast_approx::<PRECISION, true>, LANES, self)
18+
Simd::from_array(
19+
self.as_array()
20+
.map(|e| sin_fast_approx::<PRECISION, true>(e)),
21+
)
1722
}
1823

1924
#[inline(always)]
2025
unsafe fn log_fast_approx<const PRECISION: usize>(self, base: Self) -> Self {
21-
wrap_auto_vectorize!(log_fast_approx::<PRECISION>, LANES, self, base)
26+
Simd::from_array(
27+
self.as_array()
28+
.zip(*base.as_array())
29+
.map(|(self_elem, base_elem)| log_fast_approx::<PRECISION>(self_elem, base_elem)),
30+
)
2231
}
2332

2433
#[inline(always)]
2534
unsafe fn log_fast_approx_const_base<const PRECISION: usize>(self, base: Self) -> Self {
26-
wrap_auto_vectorize!(log_fast_approx_const_base::<PRECISION>, LANES, self, base)
35+
Simd::from_array(
36+
self.as_array()
37+
.zip(*base.as_array())
38+
.map(|(self_elem, base_elem)| {
39+
log_fast_approx_const_base::<PRECISION>(self_elem, base_elem)
40+
}),
41+
)
2742
}
2843
}

src/simd/int.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use crate::shared::int::*;
22
use crate::*;
33

4+
use core::mem::size_of;
45
use core::simd::*;
5-
use mem::size_of;
6-
use std::mem;
76

87
macro_rules! unsigned_impl {
98
($u:ty,$s:ty,$f:ty,$mant_bits:expr) => {
@@ -31,10 +30,10 @@ macro_rules! unsigned_impl {
3130
let unsigned_mask = Mask::from_int_unchecked(
3231
self.cast::<$s>() >> Simd::splat(UNSIGNED_LOG2 as $s),
3332
);
34-
33+
3534
// need to get rid of bits that could cause a round-up
3635
let adjusted = (self & !(self >> Simd::splat($mant_bits + 1))).cast::<$s>();
37-
36+
3837
let exponent = (adjusted.cast::<$f>().to_bits() >> Simd::splat($mant_bits))
3938
- Simd::splat((1 << ((size_of::<$f>() * 8) - 2 - $mant_bits)) - 1);
4039

src/simd/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
pub mod consts;
21
pub mod float;
32
pub mod int;

src/test/compile.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::shared::int::*;
1+
use crate::shared::float::FastApproxFloat;
22
use core::simd::*;
33

44
#[inline(never)]
55
#[allow(dead_code)]
6-
pub fn test(x: u32x8) -> u32x8 {
7-
unsafe { x.ilog_const_base_unchecked::<2>() }
6+
pub fn test(x: f32x8, base: f32x8) -> f32x8 {
7+
unsafe { x.log_fast_approx::<0>(base) }
88
}

src/test/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
#[cfg(test)]
12
pub mod checks;
2-
pub mod compile;
3+
4+
pub mod compile;

0 commit comments

Comments
 (0)