File: main.rs

package info (click to toggle)
rust-safe-arch 0.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 940 kB
  • sloc: python: 66; makefile: 2; sh: 1
file content (127 lines) | stat: -rw-r--r-- 2,922 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#![allow(bad_style)]
#![allow(unused_imports)]
#![allow(clippy::identity_op)]

use safe_arch::*;

#[cfg(target_feature = "adx")]
mod adx_tests;

#[cfg(target_feature = "avx")]
mod avx_tests;

#[cfg(target_feature = "bmi1")]
mod bmi1_tests;

#[cfg(target_feature = "bmi2")]
mod bmi2_tests;

#[cfg(target_feature = "lzcnt")]
mod lzcnt_tests;

#[cfg(target_feature = "pclmulqdq")]
mod pclmulqdq_tests;

#[cfg(target_feature = "popcnt")]
mod popcnt_tests;

#[cfg(target_feature = "rdrand")]
mod rdrand_tests;

#[cfg(target_feature = "rdseed")]
mod rdseed_tests;

#[cfg(target_feature = "sse2")]
mod sse2_tests;

#[cfg(target_feature = "sse3")]
mod sse3_tests;

#[cfg(target_feature = "ssse3")]
mod ssse3_tests;

#[cfg(target_feature = "sse4.1")]
mod sse4_1_tests;

#[cfg(target_feature = "sse4.2")]
mod sse4_2_tests;

#[test]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn test_m128_size_align() {
  assert_eq!(core::mem::size_of::<m128>(), 16);
  assert_eq!(core::mem::align_of::<m128>(), 16);
}

#[test]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn test_m128d_size_align() {
  assert_eq!(core::mem::size_of::<m128d>(), 16);
  assert_eq!(core::mem::align_of::<m128d>(), 16);
}

#[test]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn test_m128i_size_align() {
  assert_eq!(core::mem::size_of::<m128i>(), 16);
  assert_eq!(core::mem::align_of::<m128i>(), 16);
}

#[test]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn test_m256_size_align() {
  assert_eq!(core::mem::size_of::<m256>(), 32);
  assert_eq!(core::mem::align_of::<m256>(), 32);
}

#[test]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn test_m256d_size_align() {
  assert_eq!(core::mem::size_of::<m256d>(), 32);
  assert_eq!(core::mem::align_of::<m256d>(), 32);
}

#[test]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn test_m256i_size_align() {
  assert_eq!(core::mem::size_of::<m256i>(), 32);
  assert_eq!(core::mem::align_of::<m256i>(), 32);
}

#[test]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn test_m128_fmt() {
  let f = format!("{:?}", m128::default());
  assert_eq!(&f, "m128(0.0, 0.0, 0.0, 0.0)");

  let f = format!("{}", m128::default());
  assert_eq!(&f, "(0, 0, 0, 0)");

  let f = format!("{:b}", m128::default());
  assert_eq!(&f, "(0, 0, 0, 0)");

  let f = format!("{:e}", m128::default());
  assert_eq!(&f, "(0e0, 0e0, 0e0, 0e0)");

  let f = format!("{:E}", m128::default());
  assert_eq!(&f, "(0E0, 0E0, 0E0, 0E0)");

  let f = format!("{:x}", m128::default());
  assert_eq!(&f, "(0, 0, 0, 0)");

  let f = format!("{:X}", m128::default());
  assert_eq!(&f, "(0, 0, 0, 0)");

  let f = format!("{:o}", m128::default());
  assert_eq!(&f, "(0, 0, 0, 0)");
}

#[allow(dead_code)]
fn approx_eq_f32(a: f32, b: f32) -> bool {
  (a - b).abs() < 0.00000001
}

#[allow(dead_code)]
fn approx_eq_f64(a: f64, b: f64) -> bool {
  (a - b).abs() < 0.00000000001
}