LCOV - code coverage report
Current view: top level - basic - unaligned.h (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 42 42 100.0 %
Date: 2019-08-22 15:41:25 Functions: 12 12 100.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: LGPL-2.1+ */
       2             : #pragma once
       3             : 
       4             : #include <endian.h>
       5             : #include <stdint.h>
       6             : 
       7             : /* BE */
       8             : 
       9        1526 : static inline uint16_t unaligned_read_be16(const void *_u) {
      10        1526 :         const struct __attribute__((__packed__, __may_alias__)) { uint16_t x; } *u = _u;
      11             : 
      12        1526 :         return be16toh(u->x);
      13             : }
      14             : 
      15         657 : static inline uint32_t unaligned_read_be32(const void *_u) {
      16         657 :         const struct __attribute__((__packed__, __may_alias__)) { uint32_t x; } *u = _u;
      17             : 
      18         657 :         return be32toh(u->x);
      19             : }
      20             : 
      21           8 : static inline uint64_t unaligned_read_be64(const void *_u) {
      22           8 :         const struct __attribute__((__packed__, __may_alias__)) { uint64_t x; } *u = _u;
      23             : 
      24           8 :         return be64toh(u->x);
      25             : }
      26             : 
      27        1021 : static inline void unaligned_write_be16(void *_u, uint16_t a) {
      28        1021 :         struct __attribute__((__packed__, __may_alias__)) { uint16_t x; } *u = _u;
      29             : 
      30        1021 :         u->x = be16toh(a);
      31        1021 : }
      32             : 
      33         339 : static inline void unaligned_write_be32(void *_u, uint32_t a) {
      34         339 :         struct __attribute__((__packed__, __may_alias__)) { uint32_t x; } *u = _u;
      35             : 
      36         339 :         u->x = be32toh(a);
      37         339 : }
      38             : 
      39           8 : static inline void unaligned_write_be64(void *_u, uint64_t a) {
      40           8 :         struct __attribute__((__packed__, __may_alias__)) { uint64_t x; } *u = _u;
      41             : 
      42           8 :         u->x = be64toh(a);
      43           8 : }
      44             : 
      45             : /* LE */
      46             : 
      47           3 : static inline uint16_t unaligned_read_le16(const void *_u) {
      48           3 :         const struct __attribute__((__packed__, __may_alias__)) { uint16_t x; } *u = _u;
      49             : 
      50           3 :         return le16toh(u->x);
      51             : }
      52             : 
      53           5 : static inline uint32_t unaligned_read_le32(const void *_u) {
      54           5 :         const struct __attribute__((__packed__, __may_alias__)) { uint32_t x; } *u = _u;
      55             : 
      56           5 :         return le32toh(u->x);
      57             : }
      58             : 
      59     2044211 : static inline uint64_t unaligned_read_le64(const void *_u) {
      60     2044211 :         const struct __attribute__((__packed__, __may_alias__)) { uint64_t x; } *u = _u;
      61             : 
      62     2044211 :         return le64toh(u->x);
      63             : }
      64             : 
      65           3 : static inline void unaligned_write_le16(void *_u, uint16_t a) {
      66           3 :         struct __attribute__((__packed__, __may_alias__)) { uint16_t x; } *u = _u;
      67             : 
      68           3 :         u->x = le16toh(a);
      69           3 : }
      70             : 
      71          12 : static inline void unaligned_write_le32(void *_u, uint32_t a) {
      72          12 :         struct __attribute__((__packed__, __may_alias__)) { uint32_t x; } *u = _u;
      73             : 
      74          12 :         u->x = le32toh(a);
      75          12 : }
      76             : 
      77         271 : static inline void unaligned_write_le64(void *_u, uint64_t a) {
      78         271 :         struct __attribute__((__packed__, __may_alias__)) { uint64_t x; } *u = _u;
      79             : 
      80         271 :         u->x = le64toh(a);
      81         271 : }
      82             : 
      83             : #if __BYTE_ORDER == __BIG_ENDIAN
      84             : #define unaligned_read_ne16 unaligned_read_be16
      85             : #define unaligned_read_ne32 unaligned_read_be32
      86             : #define unaligned_read_ne64 unaligned_read_be64
      87             : 
      88             : #define unaligned_write_ne16 unaligned_write_be16
      89             : #define unaligned_write_ne32 unaligned_write_be32
      90             : #define unaligned_write_ne64 unaligned_write_be64
      91             : #else
      92             : #define unaligned_read_ne16 unaligned_read_le16
      93             : #define unaligned_read_ne32 unaligned_read_le32
      94             : #define unaligned_read_ne64 unaligned_read_le64
      95             : 
      96             : #define unaligned_write_ne16 unaligned_write_le16
      97             : #define unaligned_write_ne32 unaligned_write_le32
      98             : #define unaligned_write_ne64 unaligned_write_le64
      99             : #endif

Generated by: LCOV version 1.14