annotate osx/include/lo/lo_endian.h @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 241db1b1eff2
children
rev   line source
matthiasmauch@114 1 /*
matthiasmauch@114 2 * Copyright (C) 2004 Steve Harris
matthiasmauch@114 3 *
matthiasmauch@114 4 * This program is free software; you can redistribute it and/or
matthiasmauch@114 5 * modify it under the terms of the GNU Lesser General Public License
matthiasmauch@114 6 * as published by the Free Software Foundation; either version 2.1
matthiasmauch@114 7 * of the License, or (at your option) any later version.
matthiasmauch@114 8 *
matthiasmauch@114 9 * This program is distributed in the hope that it will be useful,
matthiasmauch@114 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
matthiasmauch@114 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
matthiasmauch@114 12 * GNU Lesser General Public License for more details.
matthiasmauch@114 13 *
matthiasmauch@114 14 * $Id$
matthiasmauch@114 15 */
matthiasmauch@114 16
matthiasmauch@114 17 #ifndef LO_ENDIAN_H
matthiasmauch@114 18 #define LO_ENDIAN_H
matthiasmauch@114 19
matthiasmauch@114 20 #include <sys/types.h>
matthiasmauch@114 21 #include <stdint.h>
matthiasmauch@114 22
matthiasmauch@114 23 #ifdef WIN32
matthiasmauch@114 24 #include <winsock2.h>
matthiasmauch@114 25 #include <ws2tcpip.h>
matthiasmauch@114 26 #else
matthiasmauch@114 27 #include <netinet/in.h>
matthiasmauch@114 28 #endif
matthiasmauch@114 29
matthiasmauch@114 30 #ifdef __cplusplus
matthiasmauch@114 31 extern "C" {
matthiasmauch@114 32 #endif
matthiasmauch@114 33
matthiasmauch@114 34 #define lo_swap16(x) htons(x)
matthiasmauch@114 35
matthiasmauch@114 36 #define lo_swap32(x) htonl(x)
matthiasmauch@114 37
matthiasmauch@114 38 /* These macros come from the Linux kernel */
matthiasmauch@114 39
matthiasmauch@114 40 #ifndef lo_swap16
matthiasmauch@114 41 #define lo_swap16(x) \
matthiasmauch@114 42 ({ \
matthiasmauch@114 43 uint16_t __x = (x); \
matthiasmauch@114 44 ((uint16_t)( \
matthiasmauch@114 45 (((uint16_t)(__x) & (uint16_t)0x00ffU) << 8) | \
matthiasmauch@114 46 (((uint16_t)(__x) & (uint16_t)0xff00U) >> 8) )); \
matthiasmauch@114 47 })
matthiasmauch@114 48 #warning USING UNOPTIMISED ENDIAN STUFF
matthiasmauch@114 49 #endif
matthiasmauch@114 50
matthiasmauch@114 51 #ifndef lo_swap32
matthiasmauch@114 52 #define lo_swap32(x) \
matthiasmauch@114 53 ({ \
matthiasmauch@114 54 uint32_t __x = (x); \
matthiasmauch@114 55 ((uint32_t)( \
matthiasmauch@114 56 (((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
matthiasmauch@114 57 (((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
matthiasmauch@114 58 (((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
matthiasmauch@114 59 (((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
matthiasmauch@114 60 })
matthiasmauch@114 61 #endif
matthiasmauch@114 62
matthiasmauch@114 63 #if 0
matthiasmauch@114 64 #ifndef lo_swap64
matthiasmauch@114 65 #define lo_swap64(x) \
matthiasmauch@114 66 ({ \
matthiasmauch@114 67 uint64_t __x = (x); \
matthiasmauch@114 68 ((uint64_t)( \
matthiasmauch@114 69 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000000000ffULL) << 56) | \
matthiasmauch@114 70 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
matthiasmauch@114 71 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
matthiasmauch@114 72 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
matthiasmauch@114 73 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
matthiasmauch@114 74 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
matthiasmauch@114 75 (uint64_t)(((uint64_t)(__x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
matthiasmauch@114 76 (uint64_t)(((uint64_t)(__x) & (uint64_t)0xff00000000000000ULL) >> 56) )); \
matthiasmauch@114 77 })
matthiasmauch@114 78 #endif
matthiasmauch@114 79 #else
matthiasmauch@114 80
matthiasmauch@114 81 typedef union {
matthiasmauch@114 82 uint64_t all;
matthiasmauch@114 83 struct {
matthiasmauch@114 84 uint32_t a;
matthiasmauch@114 85 uint32_t b;
matthiasmauch@114 86 } part;
matthiasmauch@114 87 } lo_split64;
matthiasmauch@114 88
matthiasmauch@114 89 static inline uint64_t lo_swap64(uint64_t x)
matthiasmauch@114 90 {
matthiasmauch@114 91 lo_split64 in, out;
matthiasmauch@114 92
matthiasmauch@114 93 in.all = x;
matthiasmauch@114 94 out.part.a = lo_swap32(in.part.b);
matthiasmauch@114 95 out.part.b = lo_swap32(in.part.a);
matthiasmauch@114 96
matthiasmauch@114 97 return out.all;
matthiasmauch@114 98 }
matthiasmauch@114 99 #endif
matthiasmauch@114 100
matthiasmauch@114 101 /* Host to OSC and OSC to Host conversion macros */
matthiasmauch@114 102
matthiasmauch@114 103 #if 0
matthiasmauch@114 104 #define lo_htoo16(x) (x)
matthiasmauch@114 105 #define lo_htoo32(x) (x)
matthiasmauch@114 106 #define lo_htoo64(x) (x)
matthiasmauch@114 107 #define lo_otoh16(x) (x)
matthiasmauch@114 108 #define lo_otoh32(x) (x)
matthiasmauch@114 109 #define lo_otoh64(x) (x)
matthiasmauch@114 110 #else
matthiasmauch@114 111 #define lo_htoo16 lo_swap16
matthiasmauch@114 112 #define lo_htoo32 lo_swap32
matthiasmauch@114 113 #define lo_htoo64 lo_swap64
matthiasmauch@114 114 #define lo_otoh16 lo_swap16
matthiasmauch@114 115 #define lo_otoh32 lo_swap32
matthiasmauch@114 116 #define lo_otoh64 lo_swap64
matthiasmauch@114 117 #endif
matthiasmauch@114 118
matthiasmauch@114 119 #ifdef __cplusplus
matthiasmauch@114 120 }
matthiasmauch@114 121 #endif
matthiasmauch@114 122
matthiasmauch@114 123 #endif
matthiasmauch@114 124
matthiasmauch@114 125 /* vi:set ts=8 sts=4 sw=4: */