interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / curve25519-dalek-derive / tests / tests.rs

148 lines · 3148 bytes Raw Blame History
1#![cfg(any(target_arch = "x86", target_arch = "x86_64"))]
2#![allow(dead_code)]
3#![allow(unused_imports)]
4
5use curve25519_dalek_derive::{unsafe_target_feature, unsafe_target_feature_specialize};
6
7#[unsafe_target_feature("sse2")]
8/// A doc comment.
9fn function(a: u32, b: u32) -> u32 {
10 a - b
11}
12
13#[unsafe_target_feature("sse2")]
14fn function_with_const_arg<const N: u32>(b: u32) -> u32 {
15 N - b
16}
17
18#[unsafe_target_feature("sse2")]
19fn function_with_where_clause<T>(a: T, b: T) -> T::Output
20where
21 T: Copy + core::ops::Sub,
22{
23 a - b
24}
25
26#[unsafe_target_feature("sse2")]
27#[cfg(feature = "dummy")]
28fn function_with_cfg() {}
29
30#[unsafe_target_feature("sse2")]
31#[rustfmt::skip]
32fn function_with_rustfmt_skip() {}
33
34struct Struct {
35 a: u32,
36}
37
38#[unsafe_target_feature("sse2")]
39impl Struct {
40 #[allow(unused_mut)]
41 fn member_function(&self, mut b: u32) -> u32 {
42 self.a - b
43 }
44
45 fn member_function_with_const_arg<const N: u32>(self) -> u32 {
46 self.a - N
47 }
48
49 #[cfg(feature = "dummy")]
50 fn member_function_with_cfg() {}
51}
52
53struct StructWithGenerics<T>
54where
55 T: Copy + core::ops::Sub,
56{
57 a: T,
58}
59
60#[unsafe_target_feature("sse2")]
61impl<T> StructWithGenerics<T>
62where
63 T: Copy + core::ops::Sub,
64{
65 #[inline]
66 fn member_function(&self, b: T) -> T::Output {
67 self.a - b
68 }
69}
70
71struct StructWithGenericsNoWhere<T: Copy + core::ops::Sub> {
72 a: T,
73}
74
75#[unsafe_target_feature("sse2")]
76impl<T: Copy + core::ops::Sub> StructWithGenericsNoWhere<T> {
77 #[inline(always)]
78 fn member_function(&self, b: T) -> T::Output {
79 self.a - b
80 }
81}
82
83#[unsafe_target_feature("sse2")]
84#[allow(dead_code)]
85impl<'a> From<&'a Struct> for () {
86 fn from(_: &'a Struct) -> Self {}
87}
88
89#[unsafe_target_feature("sse2")]
90mod inner {
91 fn inner_function(a: u32, b: u32) -> u32 {
92 a - b
93 }
94}
95
96#[unsafe_target_feature_specialize("sse2", "avx2", conditional("avx512ifma", disabled))]
97mod inner_spec {
98 #[for_target_feature("sse2")]
99 const CONST: u32 = 1;
100
101 #[for_target_feature("avx2")]
102 const CONST: u32 = 2;
103
104 pub fn spec_function(a: u32, b: u32) -> u32 {
105 a - b - CONST
106 }
107
108 #[for_target_feature("sse2")]
109 const IS_AVX2: bool = false;
110
111 #[for_target_feature("avx2")]
112 const IS_AVX2: bool = true;
113
114 #[test]
115 fn test_specialized() {
116 assert!(!IS_AVX2);
117 }
118
119 #[cfg(test)]
120 mod tests {
121 #[test]
122 fn test_specialized_inner() {
123 assert!(!super::IS_AVX2);
124 }
125 }
126}
127
128#[unsafe_target_feature("sse2")]
129#[test]
130fn test_sse2_only() {}
131
132#[unsafe_target_feature("avx2")]
133#[test]
134fn test_avx2_only() {
135 compile_error!();
136}
137
138#[test]
139fn test_function() {
140 assert_eq!(function(10, 3), 7);
141 assert_eq!(function_with_where_clause(10, 3), 7);
142 assert_eq!(function_with_const_arg::<10>(3), 7);
143 assert_eq!(Struct { a: 10 }.member_function(3), 7);
144 assert_eq!(StructWithGenerics { a: 10 }.member_function(3), 7);
145 assert_eq!(StructWithGenericsNoWhere { a: 10 }.member_function(3), 7);
146 assert_eq!(inner_spec_sse2::spec_function(10, 3), 6);
147 assert_eq!(inner_spec_avx2::spec_function(10, 3), 5);
148}