File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ #[ cfg( test) ]
2
+ use stdsimd_test:: assert_instr;
3
+
4
+ /// Return an integer with the reversed byte order of x
5
+ #[ inline( always) ]
6
+ #[ cfg_attr( test, assert_instr( bswap) ) ]
7
+ pub unsafe fn _bswap ( x : i32 ) -> i32 {
8
+ bswap_i32 ( x)
9
+ }
10
+
11
+ /// Return an integer with the reversed byte order of x
12
+ #[ inline( always) ]
13
+ #[ cfg_attr( test, assert_instr( bswap) ) ]
14
+ pub unsafe fn _bswap64 ( x : i64 ) -> i64 {
15
+ bswap_i64 ( x)
16
+ }
17
+
18
+ #[ allow( improper_ctypes) ]
19
+ extern "C" {
20
+ #[ link_name = "llvm.bswap.i64" ]
21
+ fn bswap_i64 ( x : i64 ) -> i64 ;
22
+ #[ link_name = "llvm.bswap.i32" ]
23
+ fn bswap_i32 ( x : i32 ) -> i32 ;
24
+ }
25
+
26
+ #[ cfg( test) ]
27
+ mod tests {
28
+ use super :: * ;
29
+
30
+ #[ test]
31
+ fn test_bswap ( ) {
32
+ unsafe {
33
+ assert_eq ! ( _bswap( 0x0EADBE0F ) , 0x0FBEAD0E ) ;
34
+ assert_eq ! ( _bswap( 0x00000000 ) , 0x00000000 ) ;
35
+ }
36
+ }
37
+
38
+ #[ test]
39
+ fn test_bswap64 ( ) {
40
+ unsafe {
41
+ assert_eq ! ( _bswap64( 0x0EADBEEFFADECA0E ) , 0x0ECADEFAEFBEAD0E ) ;
42
+ assert_eq ! ( _bswap64( 0x0000000000000000 ) , 0x0000000000000000 ) ;
43
+ }
44
+ }
45
+ }
Original file line number Diff line number Diff line change 3
3
pub use self :: cpuid:: * ;
4
4
pub use self :: xsave:: * ;
5
5
6
+ pub use self :: bswap:: * ;
7
+
6
8
pub use self :: sse:: * ;
7
9
pub use self :: sse2:: * ;
8
10
pub use self :: sse3:: * ;
@@ -22,6 +24,8 @@ pub use self::tbm::*;
22
24
mod cpuid;
23
25
mod xsave;
24
26
27
+ mod bswap;
28
+
25
29
mod sse;
26
30
mod sse2;
27
31
mod sse3;
You can’t perform that action at this time.
0 commit comments