Libav 0.7.1
|
00001 /* 00002 * Copyright (c) 2009 Mans Rullgard <mans@mansr.com> 00003 * 00004 * This file is part of Libav. 00005 * 00006 * Libav is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * Libav is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with Libav; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #ifndef AVUTIL_MIPS_INTREADWRITE_H 00022 #define AVUTIL_MIPS_INTREADWRITE_H 00023 00024 #include <stdint.h> 00025 #include "config.h" 00026 00027 #if HAVE_INLINE_ASM 00028 00029 #define AV_RN32 AV_RN32 00030 static av_always_inline uint32_t AV_RN32(const void *p) 00031 { 00032 uint32_t v; 00033 __asm__ ("lwl %0, %1 \n\t" 00034 "lwr %0, %2 \n\t" 00035 : "=&r"(v) 00036 : "m"(*(const uint32_t *)((const uint8_t *)p+3*!HAVE_BIGENDIAN)), 00037 "m"(*(const uint32_t *)((const uint8_t *)p+3*HAVE_BIGENDIAN))); 00038 return v; 00039 } 00040 00041 #define AV_WN32 AV_WN32 00042 static av_always_inline void AV_WN32(void *p, uint32_t v) 00043 { 00044 __asm__ ("swl %2, %0 \n\t" 00045 "swr %2, %1 \n\t" 00046 : "=m"(*(uint32_t *)((uint8_t *)p+3*!HAVE_BIGENDIAN)), 00047 "=m"(*(uint32_t *)((uint8_t *)p+3*HAVE_BIGENDIAN)) 00048 : "r"(v)); 00049 } 00050 00051 #if ARCH_MIPS64 00052 00053 #define AV_RN64 AV_RN64 00054 static av_always_inline uint64_t AV_RN64(const void *p) 00055 { 00056 uint64_t v; 00057 __asm__ ("ldl %0, %1 \n\t" 00058 "ldr %0, %2 \n\t" 00059 : "=&r"(v) 00060 : "m"(*(const uint64_t *)((const uint8_t *)p+7*!HAVE_BIGENDIAN)), 00061 "m"(*(const uint64_t *)((const uint8_t *)p+7*HAVE_BIGENDIAN))); 00062 return v; 00063 } 00064 00065 #define AV_WN64 AV_WN64 00066 static av_always_inline void AV_WN64(void *p, uint64_t v) 00067 { 00068 __asm__ ("sdl %2, %0 \n\t" 00069 "sdr %2, %1 \n\t" 00070 : "=m"(*(uint64_t *)((uint8_t *)p+7*!HAVE_BIGENDIAN)), 00071 "=m"(*(uint64_t *)((uint8_t *)p+7*HAVE_BIGENDIAN)) 00072 : "r"(v)); 00073 } 00074 00075 #else 00076 00077 #define AV_RN64 AV_RN64 00078 static av_always_inline uint64_t AV_RN64(const void *p) 00079 { 00080 union { uint64_t v; uint32_t hl[2]; } v; 00081 v.hl[0] = AV_RN32(p); 00082 v.hl[1] = AV_RN32((const uint8_t *)p + 4); 00083 return v.v; 00084 } 00085 00086 #define AV_WN64 AV_WN64 00087 static av_always_inline void AV_WN64(void *p, uint64_t v) 00088 { 00089 union { uint64_t v; uint32_t hl[2]; } vv = { v }; 00090 AV_WN32(p, vv.hl[0]); 00091 AV_WN32((uint8_t *)p + 4, vv.hl[1]); 00092 } 00093 00094 #endif /* ARCH_MIPS64 */ 00095 00096 #endif /* HAVE_INLINE_ASM */ 00097 00098 #endif /* AVUTIL_MIPS_INTREADWRITE_H */