Skip to content

Commit

Permalink
Make usage of simd in gfx optional
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Oct 12, 2017
1 parent 3d5eb82 commit a8e671c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 4 additions & 1 deletion components/gfx/Cargo.toml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ publish = false
name = "gfx" name = "gfx"
path = "lib.rs" path = "lib.rs"


[features]
unstable = ["simd"]

[dependencies] [dependencies]
app_units = "0.5" app_units = "0.5"
bitflags = "0.7" bitflags = "0.7"
Expand Down Expand Up @@ -58,7 +61,7 @@ servo-fontconfig = "0.2.1"
xml5ever = {version = "0.10"} xml5ever = {version = "0.10"}


[target.'cfg(any(target_feature = "sse2", target_feature = "neon"))'.dependencies] [target.'cfg(any(target_feature = "sse2", target_feature = "neon"))'.dependencies]
simd = "0.2.0" simd = {version = "0.2.0", optional = true}


[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]
dwrote = "0.4" dwrote = "0.4"
Expand Down
3 changes: 2 additions & 1 deletion components/gfx/lib.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


// For SIMD // For SIMD
#![cfg_attr(feature = "unstable", feature(cfg_target_feature))]
#![cfg_attr(any(target_os = "linux", target_os = "android"), feature(allocator_api))] #![cfg_attr(any(target_os = "linux", target_os = "android"), feature(allocator_api))]
#![feature(cfg_target_feature)]


#![deny(unsafe_code)] #![deny(unsafe_code)]


Expand Down Expand Up @@ -53,6 +53,7 @@ extern crate servo_arc;
extern crate servo_geometry; extern crate servo_geometry;
extern crate servo_url; extern crate servo_url;
#[macro_use] extern crate servo_atoms; #[macro_use] extern crate servo_atoms;
#[cfg(feature = "unstable")]
#[cfg(any(target_feature = "sse2", target_feature = "neon"))] #[cfg(any(target_feature = "sse2", target_feature = "neon"))]
extern crate simd; extern crate simd;
extern crate smallvec; extern crate smallvec;
Expand Down
7 changes: 5 additions & 2 deletions components/gfx/text/glyph.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use app_units::Au; use app_units::Au;
use euclid::Point2D; use euclid::Point2D;
use range::{self, EachIndex, Range, RangeIndex}; use range::{self, EachIndex, Range, RangeIndex};
#[cfg(any(target_feature = "sse2", target_feature = "neon"))] #[cfg(all(feature = "unstable", any(target_feature = "sse2", target_feature = "neon")))]
use simd::u32x4; use simd::u32x4;
use std::{fmt, mem, u16}; use std::{fmt, mem, u16};
use std::cmp::{Ordering, PartialOrd}; use std::cmp::{Ordering, PartialOrd};
Expand Down Expand Up @@ -74,6 +74,7 @@ pub type GlyphId = u32;
// TODO: make this more type-safe. // TODO: make this more type-safe.


const FLAG_CHAR_IS_SPACE: u32 = 0x40000000; const FLAG_CHAR_IS_SPACE: u32 = 0x40000000;
#[cfg(feature = "unstable")]
#[cfg(any(target_feature = "sse2", target_feature = "neon"))] #[cfg(any(target_feature = "sse2", target_feature = "neon"))]
const FLAG_CHAR_IS_SPACE_SHIFT: u32 = 30; const FLAG_CHAR_IS_SPACE_SHIFT: u32 = 30;
const FLAG_IS_SIMPLE_GLYPH: u32 = 0x80000000; const FLAG_IS_SIMPLE_GLYPH: u32 = 0x80000000;
Expand Down Expand Up @@ -591,6 +592,7 @@ impl<'a> GlyphStore {
} }


#[inline] #[inline]
#[cfg(feature = "unstable")]
#[cfg(any(target_feature = "sse2", target_feature = "neon"))] #[cfg(any(target_feature = "sse2", target_feature = "neon"))]
fn advance_for_byte_range_simple_glyphs(&self, range: &Range<ByteIndex>, extra_word_spacing: Au) -> Au { fn advance_for_byte_range_simple_glyphs(&self, range: &Range<ByteIndex>, extra_word_spacing: Au) -> Au {
let advance_mask = u32x4::splat(GLYPH_ADVANCE_MASK); let advance_mask = u32x4::splat(GLYPH_ADVANCE_MASK);
Expand Down Expand Up @@ -634,13 +636,14 @@ impl<'a> GlyphStore {


/// When SIMD isn't available, fallback to the slow path. /// When SIMD isn't available, fallback to the slow path.
#[inline] #[inline]
#[cfg(not(any(target_feature = "sse2", target_feature = "neon")))] #[cfg(not(all(feature = "unstable", any(target_feature = "sse2", target_feature = "neon"))))]
fn advance_for_byte_range_simple_glyphs(&self, range: &Range<ByteIndex>, extra_word_spacing: Au) -> Au { fn advance_for_byte_range_simple_glyphs(&self, range: &Range<ByteIndex>, extra_word_spacing: Au) -> Au {
self.advance_for_byte_range_slow_path(range, extra_word_spacing) self.advance_for_byte_range_slow_path(range, extra_word_spacing)
} }


/// Used for SIMD. /// Used for SIMD.
#[inline] #[inline]
#[cfg(feature = "unstable")]
#[cfg(any(target_feature = "sse2", target_feature = "neon"))] #[cfg(any(target_feature = "sse2", target_feature = "neon"))]
#[allow(unsafe_code)] #[allow(unsafe_code)]
fn transmute_entry_buffer_to_u32_buffer(&self) -> &[u32] { fn transmute_entry_buffer_to_u32_buffer(&self) -> &[u32] {
Expand Down
1 change: 1 addition & 0 deletions components/servo/Cargo.toml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ unstable = [
"canvas_traits/unstable", "canvas_traits/unstable",
"compositing/unstable", "compositing/unstable",
"constellation/unstable", "constellation/unstable",
"gfx/unstable",
] ]


[dependencies] [dependencies]
Expand Down

0 comments on commit a8e671c

Please sign in to comment.