annotate src/liblo-0.26/build/lo_endian-msvc.h @ 4:e13257ea84a4

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