Skip to content

Commit

Permalink
correctly use no_std, get rid of macro in exchange for zips and maps,…
Browse files Browse the repository at this point in the history
… bump ver
  • Loading branch information
burgerindividual committed Apr 30, 2023
1 parent 783ed18 commit 973b879
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "fath"
authors = [ "burgerindividual", "duplexsystem" ]
version = "0.1.5"
version = "0.1.6"
edition = "2021"
license = "LGPL-3.0"
repository = "https://github.com/burgerindividual/fath"
Expand Down
10 changes: 3 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#![feature(core_intrinsics, portable_simd)]
// #![no_std]

pub extern crate std as core;

extern crate alloc;
#![feature(core_intrinsics, portable_simd, array_zip)]
#![no_std]

pub mod scalar;
pub mod shared;
// #![cfg_attr(feature = "portable_simd", feature(portable_simd))]
pub mod simd;

#[cfg(test)]
pub mod test;
pub mod test;
22 changes: 0 additions & 22 deletions src/simd/consts.rs

This file was deleted.

25 changes: 20 additions & 5 deletions src/simd/float.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::shared::float::*;
use crate::*;
use core::simd::*;

impl<const LANES: usize> FastApproxFloat for Simd<f32, LANES>
Expand All @@ -8,21 +7,37 @@ where
{
#[inline(always)]
unsafe fn sin_fast_approx<const PRECISION: usize>(self) -> Self {
wrap_auto_vectorize!(sin_fast_approx::<PRECISION, false>, LANES, self)
Simd::from_array(
self.as_array()
.map(|e| sin_fast_approx::<PRECISION, false>(e)),
)
}

#[inline(always)]
unsafe fn cos_fast_approx<const PRECISION: usize>(self) -> Self {
wrap_auto_vectorize!(sin_fast_approx::<PRECISION, true>, LANES, self)
Simd::from_array(
self.as_array()
.map(|e| sin_fast_approx::<PRECISION, true>(e)),
)
}

#[inline(always)]
unsafe fn log_fast_approx<const PRECISION: usize>(self, base: Self) -> Self {
wrap_auto_vectorize!(log_fast_approx::<PRECISION>, LANES, self, base)
Simd::from_array(
self.as_array()
.zip(*base.as_array())
.map(|(self_elem, base_elem)| log_fast_approx::<PRECISION>(self_elem, base_elem)),
)
}

#[inline(always)]
unsafe fn log_fast_approx_const_base<const PRECISION: usize>(self, base: Self) -> Self {
wrap_auto_vectorize!(log_fast_approx_const_base::<PRECISION>, LANES, self, base)
Simd::from_array(
self.as_array()
.zip(*base.as_array())
.map(|(self_elem, base_elem)| {
log_fast_approx_const_base::<PRECISION>(self_elem, base_elem)
}),
)
}
}
7 changes: 3 additions & 4 deletions src/simd/int.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::shared::int::*;
use crate::*;

use core::mem::size_of;
use core::simd::*;
use mem::size_of;
use std::mem;

macro_rules! unsigned_impl {
($u:ty,$s:ty,$f:ty,$mant_bits:expr) => {
Expand Down Expand Up @@ -31,10 +30,10 @@ macro_rules! unsigned_impl {
let unsigned_mask = Mask::from_int_unchecked(
self.cast::<$s>() >> Simd::splat(UNSIGNED_LOG2 as $s),
);

// need to get rid of bits that could cause a round-up
let adjusted = (self & !(self >> Simd::splat($mant_bits + 1))).cast::<$s>();

let exponent = (adjusted.cast::<$f>().to_bits() >> Simd::splat($mant_bits))
- Simd::splat((1 << ((size_of::<$f>() * 8) - 2 - $mant_bits)) - 1);

Expand Down
1 change: 0 additions & 1 deletion src/simd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod consts;
pub mod float;
pub mod int;
6 changes: 3 additions & 3 deletions src/test/compile.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::shared::int::*;
use crate::shared::float::FastApproxFloat;
use core::simd::*;

#[inline(never)]
#[allow(dead_code)]
pub fn test(x: u32x8) -> u32x8 {
unsafe { x.ilog_const_base_unchecked::<2>() }
pub fn test(x: f32x8, base: f32x8) -> f32x8 {
unsafe { x.log_fast_approx::<0>(base) }
}
4 changes: 3 additions & 1 deletion src/test/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#[cfg(test)]
pub mod checks;
pub mod compile;

pub mod compile;

0 comments on commit 973b879

Please sign in to comment.