mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-04 20:24:10 +00:00
Add stub code for IFMA intrinsics in Rust.
This commit is contained in:
parent
0a97f5fe8c
commit
9ed2128a10
7 changed files with 71 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
4
build.rs
4
build.rs
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
40
src/backend/vector/ifma/field.rs
Normal file
40
src/backend/vector/ifma/field.rs
Normal 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
11
src/backend/vector/ifma/mod.rs
Normal file
11
src/backend/vector/ifma/mod.rs
Normal 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;
|
||||
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue