Skip to content

[mips/mips64: msa] add add_a_b intrinsic #365

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

Merged
merged 27 commits into from
Mar 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5752cae
[mips64/msa] add add_a_b intrinsic
gnzlbg Mar 7, 2018
c0c7e1e
add make/file to mips64el's Dockerfile
gnzlbg Mar 7, 2018
a19a903
add run-time detection support for mips64
gnzlbg Mar 7, 2018
b6d7b1b
add mips64 build bot
gnzlbg Mar 7, 2018
58c6b05
generate docs for mips64
gnzlbg Mar 7, 2018
1b79b27
fix linux test
gnzlbg Mar 7, 2018
f45bbe3
cleanup rt-detection
gnzlbg Mar 8, 2018
daae3cd
support mips64/mips64el in stdsimd-test
gnzlbg Mar 8, 2018
f40d085
support asserting instructions with in their name
gnzlbg Mar 8, 2018
ca34e2c
better error msgs for the auxv_crate test
gnzlbg Mar 8, 2018
36443c5
debug auxv on mips64
gnzlbg Mar 8, 2018
fea6280
override run-time detection on mips msa tests
gnzlbg Mar 8, 2018
aa43c30
remove unused #[macro_use]
gnzlbg Mar 8, 2018
d43ef82
try another MIPS cpu
gnzlbg Mar 8, 2018
a96249c
detect default TARGET in simd-test-macro
gnzlbg Mar 9, 2018
b35c893
disable unused function in mips tests
gnzlbg Mar 9, 2018
9b13321
use mips64r2-generic
gnzlbg Mar 9, 2018
e98dc01
move msa to mips
gnzlbg Mar 9, 2018
efc89da
remove mips from ci
gnzlbg Mar 9, 2018
e7bf536
split into mips and mips64 modules
gnzlbg Mar 9, 2018
0245e50
add rt-detection for 32-bit mips
gnzlbg Mar 9, 2018
5c534b1
fmt
gnzlbg Mar 9, 2018
2fc6858
remove merge error
gnzlbg Mar 9, 2018
5b6bcdd
add norun build bots for mips
gnzlbg Mar 9, 2018
27742ac
add -p to avoid changing the cwd
gnzlbg Mar 9, 2018
701f167
fixup
gnzlbg Mar 9, 2018
a7f5eb3
refactor run-time detection module
gnzlbg Mar 9, 2018
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
22 changes: 16 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ matrix:
- env: TARGET=arm-unknown-linux-gnueabihf
- env: TARGET=armv7-unknown-linux-gnueabihf
- env: TARGET=aarch64-unknown-linux-gnu
- env: TARGET=mips-unknown-linux-gnu NORUN=1
- env: TARGET=mipsel-unknown-linux-gnu NORUN=1
- env: TARGET=mips64-unknown-linux-gnuabi64 NORUN=1
- env: TARGET=mips64el-unknown-linux-gnuabi64 NORUN=1
- env: TARGET=powerpc-unknown-linux-gnu
- env: TARGET=powerpc64-unknown-linux-gnu
- env: TARGET=powerpc64le-unknown-linux-gnu
Expand All @@ -21,11 +25,6 @@ matrix:
- os: osx
env: TARGET=x86_64-apple-darwin NO_ADD=1
script: ci/run.sh
- env: DOCUMENTATION
install: true
script: ci/dox.sh
- script: cargo test --manifest-path crates/stdsimd-verify/Cargo.toml
install: true
- env: TARGET=wasm32-unknown-unknown
before_script:
- git clone --recursive https://github.com/WebAssembly/wabt
Expand All @@ -39,6 +38,11 @@ matrix:
- cat wasm.wat
- grep current_memory wasm.wat
- grep grow_memory wasm.wat
- env: DOCUMENTATION
install: true
script: ci/dox.sh
- script: cargo test --manifest-path crates/stdsimd-verify/Cargo.toml
install: true
- env: RUSTFMT=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
before_script:
- rustup component add rustfmt-preview
Expand All @@ -60,7 +64,13 @@ install:

script:
- cargo generate-lockfile
- ci/run-docker.sh $TARGET $FEATURES
- |
if [ "$NORUN" == "1" ]; then
cargo build --target=$TARGET -p coresimd -p stdsimd --manifest-path crates/stdsimd/Cargo.toml
cargo build --release --target=$TARGET -p coresimd -p stdsimd --manifest-path crates/stdsimd/Cargo.toml
else
ci/run-docker.sh $TARGET $FEATURES
fi

notifications:
email:
Expand Down
2 changes: 2 additions & 0 deletions ci/dox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ dox arm armv7-unknown-linux-gnueabihf
dox aarch64 aarch64-unknown-linux-gnu
dox powerpc powerpc-unknown-linux-gnu
dox powerpc64 powerpc64-unknown-linux-gnu
dox mips mips-unknown-linux-gnu
dox mips64 mips64-unknown-linux-gnuabi64

# If we're on travis, not a PR, and on the right branch, publish!
if [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS_BRANCH" = "master" ]; then
Expand Down
4 changes: 4 additions & 0 deletions coresimd/mips/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! MIPS

mod msa;
pub use self::msa::*;
54 changes: 54 additions & 0 deletions coresimd/mips/msa.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//! MIPS SIMD Architecture intrinsics
//!
//! The reference is [MIPS Architecture for Programmers Volume IV-j: The
//! MIPS32 SIMD Architecture Module Revision 1.12][msa_ref].
//!
//! [msa_ref]: http://cdn2.imgtec.com/documentation/MD00866-2B-MSA32-AFP-01.12.pdf

#[cfg(test)]
use stdsimd_test::assert_instr;
use coresimd::simd::*;

#[allow(improper_ctypes)]
extern "C" {
#[link_name = "llvm.mips.add.a.b"]
fn msa_add_a_b(a: i8x16, b: i8x16) -> i8x16;
}

/// Vector Add Absolute Values.
///
/// Adds the absolute values of the elements in `a` and `b` into the result vector.
#[inline]
#[target_feature(enable = "msa")]
#[cfg_attr(test, assert_instr(add_a.b))]
pub unsafe fn __msa_add_a_b(a: i8x16, b: i8x16) -> i8x16 {
msa_add_a_b(a, b)
}

#[cfg(test)]
mod tests {
use simd::*;
use stdsimd_test::simd_test;
use coresimd::mips64::msa;

#[simd_test = "msa"]
unsafe fn __msa_add_a_b() {
#[cfg_attr(rustfmt, rustfmt_skip)]
let a = i8x16::new(
1, 2, 3, 4,
1, 2, 3, 4,
1, 2, 3, 4,
1, 2, 3, 4,
);
#[cfg_attr(rustfmt, rustfmt_skip)]
let b = i8x16::new(
-4, -3, -2, -1,
-4, -3, -2, -1,
-4, -3, -2, -1,
-4, -3, -2, -1,
);
let r = i8x16::splat(5);

assert_eq!(r, msa::__msa_add_a_b(a, b));
}
}
25 changes: 25 additions & 0 deletions coresimd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ pub mod simd {
/// * [`x86_64`]
/// * [`arm`]
/// * [`aarch64`]
/// * [`mips`]
/// * [`mips64`]
///
/// [`x86`]: https://rust-lang-nursery.github.io/stdsimd/x86/stdsimd/arch/index.html
/// [`x86_64`]: https://rust-lang-nursery.github.io/stdsimd/x86_64/stdsimd/arch/index.html
/// [`arm`]: https://rust-lang-nursery.github.io/stdsimd/arm/stdsimd/arch/index.html
/// [`aarch64`]: https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/arch/index.html
/// [`mips`]: https://rust-lang-nursery.github.io/stdsimd/mips/stdsimd/arch/index.html
/// [`mips64`]: https://rust-lang-nursery.github.io/stdsimd/mips64/stdsimd/arch/index.html
#[unstable(feature = "stdsimd", issue = "0")]
pub mod arch {
/// Platform-specific intrinsics for the `x86` platform.
Expand Down Expand Up @@ -81,6 +85,24 @@ pub mod arch {
pub mod wasm32 {
pub use coresimd::wasm32::*;
}

/// Platform-specific intrinsics for the `mips` platform.
///
/// See the [module documentation](../index.html) for more details.
#[cfg(any(target_arch = "mips", dox))]
#[doc(cfg(target_arch = "mips"))]
pub mod mips {
pub use coresimd::mips::*;
}

/// Platform-specific intrinsics for the `mips64` platform.
///
/// See the [module documentation](../index.html) for more details.
#[cfg(any(target_arch = "mips64", dox))]
#[doc(cfg(target_arch = "mips64"))]
pub mod mips64 {
pub use coresimd::mips::*;
}
}

mod simd_llvm;
Expand All @@ -97,4 +119,7 @@ mod aarch64;
#[cfg(target_arch = "wasm32")]
mod wasm32;

#[cfg(any(target_arch = "mips", target_arch = "mips64", dox))]
mod mips;

mod nvptx;
18 changes: 13 additions & 5 deletions crates/assert-instr-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ pub fn assert_instr(
(quote! { #[ignore] }).into()
};
let name = &func.ident;
use quote::ToTokens;
let instr_str = instr
.clone()
.into_tokens()
.to_string()
.replace('.', "_")
.replace(|c: char| c.is_whitespace(), "");
let assert_name = syn::Ident::from(
&format!("assert_{}_{}", name.as_ref(), instr.as_ref())[..],
&format!("assert_{}_{}", name.as_ref(), instr_str)[..],
);
let shim_name = syn::Ident::from(format!("{}_shim", name.as_ref()));
let mut inputs = Vec::new();
Expand Down Expand Up @@ -72,7 +79,7 @@ pub fn assert_instr(
attr.path
.segments
.first()
.unwrap()
.expect("attr.path.segments.first() failed")
.value()
.ident
.as_ref()
Expand Down Expand Up @@ -109,7 +116,8 @@ pub fn assert_instr(
}
}.into();
// why? necessary now to get tests to work?
let tts: TokenStream = tts.to_string().parse().unwrap();
let tts: TokenStream =
tts.to_string().parse().expect("cannot parse tokenstream");

let tts: TokenStream = quote! {
#item
Expand All @@ -119,13 +127,13 @@ pub fn assert_instr(
}

struct Invoc {
instr: syn::Ident,
instr: syn::Expr,
args: Vec<(syn::Ident, syn::Expr)>,
}

impl syn::synom::Synom for Invoc {
named!(parse -> Self, map!(parens!(do_parse!(
instr: syn!(syn::Ident) >>
instr: syn!(syn::Expr) >>
args: many0!(do_parse!(
syn!(syn::token::Comma) >>
name: syn!(syn::Ident) >>
Expand Down
42 changes: 38 additions & 4 deletions crates/simd-test-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,48 @@ pub fn simd_test(
let item = TokenStream::from(item);
let name = find_name(item.clone());

let name: TokenStream = name.as_str().parse().unwrap();
let name: TokenStream = name.as_str()
.parse()
.expect(&format!("failed to parse name: {}", name.clone().as_str()));

let target = env::var("TARGET").unwrap();
let macro_test = match target.split('-').next().unwrap() {
let default_target = if cfg!(target_os = "windows") {
Some("x86_64-pc-windows-msvc")
} else if cfg!(target_os = "linux") {
Some("x86_64-unknown-linux-gnu")
} else if cfg!(target_os = "macos") {
Some("x86_64-apple-darwin")
} else {
None
};

let target = env::var("TARGET").unwrap_or_else(|_| {
default_target.expect("TARGET environment variable not set and no default target known for the current target.").to_string()
});
let mut force_test = false;
let macro_test = match target
.split('-')
.next()
.expect(&format!("target triple contained no \"-\": {}", target))
{
"i686" | "x86_64" | "i586" => "is_x86_feature_detected",
"arm" => "is_arm_feature_detected",
"aarch64" => "is_aarch64_feature_detected",
"powerpc64" => "is_powerpc64_feature_detected",
"mips" | "mipsel" => {
// FIXME:
// On MIPS CI run-time feature detection always returns false due
// to this qemu bug: https://bugs.launchpad.net/qemu/+bug/1754372
//
// This is a workaround to force the MIPS tests to always run on
// CI.
force_test = true;
"is_mips_feature_detected"
}
"mips64" | "mips64el" => {
// FIXME: see above
force_test = true;
"is_mips64_feature_detected"
}
t => panic!("unknown target: {}", t),
};
let macro_test = proc_macro2::Term::intern(macro_test);
Expand All @@ -82,7 +116,7 @@ pub fn simd_test(
#[allow(non_snake_case)]
#[test]
fn #name() {
if #cfg_target_features {
if #force_test | (#cfg_target_features) {
return unsafe { #name() };
} else {
::stdsimd_test::assert_skip_test_ok(stringify!(#name));
Expand Down
3 changes: 3 additions & 0 deletions crates/stdsimd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ mod stdsimd;

pub use stdsimd::*;

#[allow(unused_imports)]
use _std::prelude;
#[allow(unused_imports)]
use _std::fs;
#[allow(unused_imports)]
use _std::io;
Loading