@@ -92,6 +92,47 @@ fn leading_zeros() {
92
92
} )
93
93
}
94
94
95
+ #[ cfg( any( target_pointer_width = "32" , target_pointer_width = "64" ) ) ]
96
+ #[ test]
97
+ fn bswap ( ) {
98
+ use compiler_builtins:: int:: bswap:: { __bswapdi2, __bswapsi2} ;
99
+ fuzz ( N , |x : u32 | {
100
+ let x_std = x. swap_bytes ( ) ;
101
+ let x_intr = __bswapsi2 ( x) ;
102
+ if x_std != x_intr {
103
+ panic ! ( "__bswapsi2({}): std: {}, builtins: {}" , x, x_std, x_intr) ;
104
+ }
105
+ } ) ;
106
+ fuzz ( N , |x : u64 | {
107
+ let x_std = x. swap_bytes ( ) ;
108
+ let x_intr = __bswapdi2 ( x) ;
109
+ if x_std != x_intr {
110
+ panic ! ( "__bswapdi2({}): std: {}, builtins: {}" , x, x_std, x_intr) ;
111
+ }
112
+ } ) ;
113
+
114
+ let mut x1 = 0x12345678u32 ;
115
+ let mut sw1 = __bswapsi2 ( x1) ;
116
+ if sw1 != 0x78563412u32 {
117
+ panic ! ( "__bswapsi2({}): {}" , x1, sw1) ;
118
+ }
119
+ x1 = 0x00000001u32 ;
120
+ sw1 = __bswapsi2 ( x1) ;
121
+ if sw1 != 0x01000000u32 {
122
+ panic ! ( "__bswapsi2({}): {}" , x1, sw1) ;
123
+ }
124
+ let mut x2 = 0x123456789ABCDEF0u64 ;
125
+ let mut sw2 = __bswapdi2 ( x2) ;
126
+ if sw2 != 0xF0DEBC9A78563412u64 {
127
+ panic ! ( "__bswapdi2({}): {}" , x2, sw2) ;
128
+ }
129
+ x2 = 0x0000000100000002u64 ;
130
+ sw2 = __bswapdi2 ( x2) ;
131
+ if sw2 != 0x0200000001000000u64 {
132
+ panic ! ( "__bswapdi2({}): {}" , x2, sw2) ;
133
+ }
134
+ }
135
+
95
136
// This is approximate because of issues related to
96
137
// https://github.com/rust-lang/rust/issues/73920.
97
138
// TODO how do we resolve this indeterminacy?
0 commit comments