6
6
#include < support/ByteOrder.h>
7
7
8
8
namespace py = pybind11;
9
+ /*
10
+ uint64 sw_int64(uint64 arg){
11
+ #if __GNUC__ >= 4
12
+ return __builtin_bswap64(arg);
13
+ #else
14
+ return __swap_int64(arg);
15
+ }*/
9
16
17
+ #if __GNUC__ >= 4
18
+ uint64 swap_int64 (uint64 arg) {
19
+ return __builtin_bswap64 (arg);
20
+ }
21
+ uint32 swap_int32 (uint32 arg) {
22
+ return __builtin_bswap32 (arg);
23
+ }
24
+ uint16 swap_int16 (uint16 arg) {
25
+ return __builtin_bswap16 (arg);
26
+ }
27
+ #else
28
+ extern uint64 __swap_int64 (uint64 arg);
29
+ extern uint32 __swap_int32 (uint32 arg);
30
+ extern uint16 __swap_int16 (uint16 arg);
31
+ #endif
10
32
11
- void define_ByteOrder (py::module_& m)
33
+
34
+
35
+ PYBIND11_MODULE (ByteOrder, m)
12
36
{
13
37
py::enum_<swap_action>(m, " swap_action" , " " )
14
38
.value (" B_SWAP_HOST_TO_LENDIAN" , swap_action::B_SWAP_HOST_TO_LENDIAN, " " )
@@ -25,11 +49,18 @@ m.def("is_type_swapped", &is_type_swapped, "", py::arg("type"));
25
49
m.def (" __swap_double" , &__swap_double, " " , py::arg (" arg" ));
26
50
27
51
m.def (" __swap_float" , &__swap_float, " " , py::arg (" arg" ));
28
-
52
+ /*
29
53
m.def("__swap_int64", &__swap_int64, "", py::arg("arg"));
30
-
31
54
m.def("__swap_int32", &__swap_int32, "", py::arg("arg"));
32
-
33
55
m.def("__swap_int16", &__swap_int16, "", py::arg("arg"));
34
-
56
+ */
57
+ #if __GNUC__ >= 4
58
+ m.def (" __swap_int64" , &swap_int64, " Swap bytes of a 64-bit integer" );
59
+ m.def (" __swap_int32" , &swap_int32, " Swap bytes of a 32-bit integer" );
60
+ m.def (" __swap_int16" , &swap_int16, " Swap bytes of a 16-bit integer" );
61
+ #else
62
+ m.def (" __swap_int64" , &__swap_int64, " " , py::arg (" arg" ));
63
+ m.def (" __swap_int32" , &__swap_int32, " " , py::arg (" arg" ));
64
+ m.def (" __swap_int16" , &__swap_int16, " " , py::arg (" arg" ));
65
+ #endif
35
66
}
0 commit comments