Add stub code for IFMA intrinsics in Rust.

This commit is contained in:
Henry de Valence 2018-11-11 17:38:28 -08:00
parent 0a97f5fe8c
commit 9ed2128a10
7 changed files with 71 additions and 4 deletions

View file

@ -72,6 +72,7 @@ u64_backend = []
# The AVX2 backend uses u32x8s with u64x4 products.
# It uses the u64 code for serial operations.
avx2_backend = ["nightly", "u64_backend", "packed_simd"]
ifma_backend = ["nightly", "u64_backend", "packed_simd", "yolocrypto"]
# Signals that we're in the main build stage. This is off by default,
# to signal stage 1 of the build, where build.rs loads the library

View file

@ -1,3 +1,5 @@
#![cfg_attr(feature = "ifma_backend", feature(simd_ffi))]
#![cfg_attr(feature = "ifma_backend", feature(link_llvm_intrinsics))]
#![cfg_attr(all(feature = "alloc", not(feature = "std")), feature(alloc))]
#![cfg_attr(feature = "nightly", feature(cfg_target_feature))]
#![allow(unused_variables)]
@ -13,7 +15,7 @@ extern crate digest;
extern crate rand;
extern crate subtle;
#[cfg(all(feature = "nightly", feature = "avx2_backend"))]
#[cfg(all(feature = "nightly", any(feature = "avx2_backend", feature = "ifma_backend")))]
extern crate packed_simd;
use std::env;

View file

@ -21,7 +21,11 @@
//! `32bit` since identifiers can't start with letters, and the backends
//! do use `u32`/`u64`, so this seems like a least-bad option.
#[cfg(not(any(feature = "u32_backend", feature = "u64_backend", feature = "avx2_backend")))]
#[cfg(not(any(
feature = "u32_backend",
feature = "u64_backend",
feature = "avx2_backend"
)))]
compile_error!(
"no curve25519-dalek backend cargo feature enabled! \
please enable one of: u32_backend, u64_backend, avx2_backend"
@ -29,5 +33,8 @@ compile_error!(
pub mod serial;
#[cfg(all(feature = "avx2_backend", target_feature = "avx2"))]
#[cfg(any(
all(feature = "ifma_backend", target_feature = "avx512ifma"),
all(feature = "avx2_backend", target_feature = "avx2"),
))]
pub mod vector;

View file

@ -0,0 +1,40 @@
// -*- mode: rust; coding: utf-8; -*-
//
// This file is part of curve25519-dalek.
// Copyright (c) 2018 Henry de Valence
// See LICENSE for licensing information.
//
// Authors:
// - Henry de Valence <hdevalence@hdevalence.ca>
use core::ops::{Add, Mul, Neg};
use packed_simd::{i32x8, u32x8, u64x4, IntoBits};
use backend::serial::u64::field::FieldElement51;
#[allow(improper_ctypes)]
extern "C" {
#[link_name = "llvm.x86.avx512.vpmadd52l.uq.256"]
fn madd52lo(z: u64x4, x: u64x4, y: u64x4) -> u64x4;
#[link_name = "llvm.x86.avx512.vpmadd52h.uq.256"]
fn madd52hi(z: u64x4, x: u64x4, y: u64x4) -> u64x4;
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn vpmadd52luq() {
let x = u64x4::splat(2);
let y = u64x4::splat(3);
let mut z = u64x4::splat(5);
z = unsafe { madd52lo(z, x, y) };
assert_eq!(z, u64x4::splat(5 + 2*3));
}
}

View file

@ -0,0 +1,11 @@
// -*- mode: rust; -*-
//
// This file is part of curve25519-dalek.
// Copyright (c) 2018 Henry de Valence
// See LICENSE for licensing information.
//
// Authors:
// - Henry de Valence <hdevalence@hdevalence.ca>
pub(crate) mod field;

View file

@ -28,5 +28,8 @@ pub(crate) use self::avx2::{
constants::BASEPOINT_ODD_LOOKUP_TABLE, edwards::CachedPoint, edwards::ExtendedPoint,
};
#[cfg(all(feature = "ifma_backend", target_feature = "avx512ifma"))]
pub mod ifma;
pub mod scalar_mul;

View file

@ -10,6 +10,9 @@
#![no_std]
#![cfg_attr(feature = "ifma_backend", feature(simd_ffi))]
#![cfg_attr(feature = "ifma_backend", feature(link_llvm_intrinsics))]
#![cfg_attr(all(feature = "alloc", not(feature = "std")), feature(alloc))]
#![cfg_attr(feature = "nightly", feature(cfg_target_feature))]
#![cfg_attr(feature = "nightly", feature(external_doc))]
@ -38,7 +41,7 @@ extern crate alloc;
#[macro_use]
extern crate std;
#[cfg(all(feature = "nightly", feature = "avx2_backend"))]
#[cfg(all(feature = "nightly", any(feature = "avx2_backend", feature = "ifma_backend")))]
extern crate packed_simd;
extern crate rand;