]> sigrok.org Git - pulseview.git/blobdiff - pv/data/logicsnapshot.cpp
Check if unportable sample pack/unpack works and in that case use it.
[pulseview.git] / pv / data / logicsnapshot.cpp
index a1beafb9c4e4e3e3c50a111077e62fd3c2d261d5..444fa9ec4ceea93194dd02ce2f8aa8cfdb8a37a1 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <boost/foreach.hpp>
 
+#include "config.h"
 #include "logicsnapshot.h"
 
 using boost::lock_guard;
@@ -64,6 +65,9 @@ LogicSnapshot::~LogicSnapshot()
 
 uint64_t LogicSnapshot::unpack_sample(const uint8_t *ptr) const
 {
+#ifdef HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS
+       return *(uint64_t*)ptr;
+#else
        uint64_t value = 0;
        switch(_unit_size) {
        default:
@@ -94,10 +98,14 @@ uint64_t LogicSnapshot::unpack_sample(const uint8_t *ptr) const
                break;
        }
        return value;
+#endif
 }
 
 void LogicSnapshot::pack_sample(uint8_t *ptr, uint64_t value)
 {
+#ifdef HAVE_UNALIGNED_LITTLE_ENDIAN_ACCESS
+       *(uint64_t*)ptr = value;
+#else
        switch(_unit_size) {
        default:
                ptr[7] = value >> 56;
@@ -126,6 +134,7 @@ void LogicSnapshot::pack_sample(uint8_t *ptr, uint64_t value)
        case 0:
                break;
        }
+#endif
 }
 
 void LogicSnapshot::append_payload(