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

Switch to std::simd #88

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ jobs:
strategy:
matrix:
rust:
- 1.57.0
- stable
- nightly
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -23,16 +22,13 @@ jobs:
toolchain: ${{ matrix.rust }}
override: true

- name: Build with minimal features (no_std)
run: cargo build --verbose --no-default-features --features no-std-float
# - name: Build with minimal features (no_std)
# run: cargo build --verbose --no-default-features --features no-std-float

- name: Run tests for tiny-skia-path
working-directory: path
run: cargo test --verbose

- name: Run tests without SIMD
run: cargo test --verbose --no-default-features --features png-format

- name: Run tests with SSE2
env:
RUSTFLAGS: -Ctarget-feature=+sse2
Expand Down Expand Up @@ -62,7 +58,7 @@ jobs:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
override: true
target: wasm32-wasi

Expand All @@ -71,11 +67,8 @@ jobs:
curl https://wasmtime.dev/install.sh -sSf | bash
echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH

- name: Build with minimal features (no_std)
run: cargo build --target wasm32-wasi --verbose --no-default-features --features no-std-float

- name: Run tests without SIMD
run: cargo test --target wasm32-wasi --verbose --no-default-features --features png-format
# - name: Build with minimal features (no_std)
# run: cargo build --target wasm32-wasi --verbose --no-default-features --features no-std-float

- name: Run tests with SIMD128
env:
Expand All @@ -91,18 +84,15 @@ jobs:
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly
override: true
target: aarch64-unknown-linux-gnu

- name: Install cross
run: cargo install cross

- name: Build with minimal features (no_std)
run: cross build --target aarch64-unknown-linux-gnu --verbose --no-default-features --features no-std-float

- name: Run tests without SIMD
run: cross test --target aarch64-unknown-linux-gnu --verbose --no-default-features --features png-format
# - name: Build with minimal features (no_std)
# run: cross build --target aarch64-unknown-linux-gnu --verbose --no-default-features --features no-std-float

- name: Run tests with Neon
run: cross test --target aarch64-unknown-linux-gnu
Expand Down
7 changes: 1 addition & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ png = { version = "0.17", optional = true }
tiny-skia-path = { version = "0.10.0", path = "path", default-features = false }

[features]
default = ["std", "simd", "png-format"]
default = ["std", "png-format"]

# Enables the use of the standard library. Deactivate this and activate the no-std-float
# feature to compile for targets that don't have std.
std = ["tiny-skia-path/std"]
no-std-float = ["tiny-skia-path/no-std-float"]

# Enables SIMD instructions on x86 (from SSE up to AVX2), WebAssembly (SIMD128)
# and AArch64 (Neon).
# Has no effect on other targets. Present mainly for testing.
simd = []

# Allows loading and saving `Pixmap` as PNG.
png-format = ["std", "png"]
109 changes: 0 additions & 109 deletions path/src/f32x2_t.rs

This file was deleted.

80 changes: 0 additions & 80 deletions path/src/f32x4_t.rs

This file was deleted.

14 changes: 1 addition & 13 deletions path/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//!
//! Note that all types use single precision floats (`f32`), just like [Skia](https://skia.org/).

#![feature(portable_simd)]
#![no_std]
#![warn(missing_docs)]
#![warn(missing_copy_implementations)]
Expand All @@ -36,8 +37,6 @@ extern crate std;
extern crate alloc;

mod dash;
mod f32x2_t;
mod f32x4_t;
mod floating_point;
mod path;
mod path_builder;
Expand All @@ -49,7 +48,6 @@ mod stroker;
mod transform;

pub use dash::StrokeDash;
pub use f32x2_t::f32x2;
pub use floating_point::*;
pub use path::*;
pub use path_builder::*;
Expand Down Expand Up @@ -86,16 +84,6 @@ impl Point {
Point { x, y }
}

/// Creates a new `Point` from `f32x2`.
pub fn from_f32x2(r: f32x2) -> Self {
Point::from_xy(r.x(), r.y())
}

/// Converts a `Point` into a `f32x2`.
pub fn to_f32x2(&self) -> f32x2 {
f32x2::new(self.x, self.y)
}

/// Creates a point at 0x0 position.
pub fn zero() -> Self {
Point { x: 0.0, y: 0.0 }
Expand Down
18 changes: 17 additions & 1 deletion path/src/path_geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

#![allow(missing_docs)]

use core::simd::f32x2;

use crate::{Point, Transform};

use crate::f32x2_t::f32x2;
use crate::floating_point::FLOAT_PI;
use crate::scalar::{Scalar, SCALAR_NEARLY_ZERO, SCALAR_ROOT_2_OVER_2};

Expand All @@ -22,6 +23,21 @@ use crate::path_builder::PathDirection;
#[cfg(all(not(feature = "std"), feature = "no-std-float"))]
use crate::NoStdFloat;

trait PointExt {
fn from_f32x2(r: f32x2) -> Self;
fn to_f32x2(&self) -> f32x2;
}

impl PointExt for Point {
fn from_f32x2(r: f32x2) -> Self {
Point::from_xy(r.as_array()[0], r.as_array()[1])
}

fn to_f32x2(&self) -> f32x2 {
f32x2::from_array([self.x, self.y])
}
}

// use for : eval(t) == A * t^2 + B * t + C
#[derive(Clone, Copy, Default, Debug)]
pub struct QuadCoeff {
Expand Down
Loading