Move endianness header to SDK

This commit is contained in:
twinaphex 2014-10-21 08:29:05 +02:00
parent d3e16f045a
commit b1293c1b82
4 changed files with 89 additions and 83 deletions

View File

@ -1,81 +0,0 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __ENDIANNESS_H
#define __ENDIANNESS_H
#include <stdint.h>
#define SWAP32(x) ((uint32_t)( \
(((uint32_t)(x) & 0x000000ff) << 24) | \
(((uint32_t)(x) & 0x0000ff00) << 8) | \
(((uint32_t)(x) & 0x00ff0000) >> 8) | \
(((uint32_t)(x) & 0xff000000) >> 24) \
))
static inline uint8_t is_little_endian(void)
{
union
{
uint16_t x;
uint8_t y[2];
} u;
u.x = 1;
return u.y[0];
}
static inline uint32_t swap_if_big32(uint32_t val)
{
if (is_little_endian())
return val;
return (val >> 24) | ((val >> 8) & 0xFF00) |
((val << 8) & 0xFF0000) | (val << 24);
}
static inline uint32_t swap_if_little32(uint32_t val)
{
if (is_little_endian())
return (val >> 24) | ((val >> 8) & 0xFF00) |
((val << 8) & 0xFF0000) | (val << 24);
return val;
}
static inline uint16_t swap_if_big16(uint16_t val)
{
if (is_little_endian())
return val;
return (val >> 8) | (val << 8);
}
static inline uint16_t swap_if_little16(uint16_t val)
{
if (is_little_endian())
return (val >> 8) | (val << 8);
return val;
}
static inline void store32be(uint32_t *addr, uint32_t data)
{
*addr = is_little_endian() ? SWAP32(data) : data;
}
static inline uint32_t load32be(const uint32_t *addr)
{
return is_little_endian() ? SWAP32(*addr) : *addr;
}
#endif

2
hash.c
View File

@ -58,7 +58,7 @@
#include <stdio.h>
#include "hash.h"
#include "miscellaneous.h"
#include "endianness.h"
#include <retro_endianness.h>
#define LSL32(x, n) ((uint32_t)(x) << (n))
#define LSR32(x, n) ((uint32_t)(x) >> (n))

View File

@ -0,0 +1,87 @@
/* Copyright (C) 2010-2014 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (boolean.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_ENDIANNESS_H
#define __LIBRETRO_SDK_ENDIANNESS_H
#include <stdint.h>
#define SWAP32(x) ((uint32_t)( \
(((uint32_t)(x) & 0x000000ff) << 24) | \
(((uint32_t)(x) & 0x0000ff00) << 8) | \
(((uint32_t)(x) & 0x00ff0000) >> 8) | \
(((uint32_t)(x) & 0xff000000) >> 24) \
))
static inline uint8_t is_little_endian(void)
{
union
{
uint16_t x;
uint8_t y[2];
} u;
u.x = 1;
return u.y[0];
}
static inline uint32_t swap_if_big32(uint32_t val)
{
if (is_little_endian())
return val;
return (val >> 24) | ((val >> 8) & 0xFF00) |
((val << 8) & 0xFF0000) | (val << 24);
}
static inline uint32_t swap_if_little32(uint32_t val)
{
if (is_little_endian())
return (val >> 24) | ((val >> 8) & 0xFF00) |
((val << 8) & 0xFF0000) | (val << 24);
return val;
}
static inline uint16_t swap_if_big16(uint16_t val)
{
if (is_little_endian())
return val;
return (val >> 8) | (val << 8);
}
static inline uint16_t swap_if_little16(uint16_t val)
{
if (is_little_endian())
return (val >> 8) | (val << 8);
return val;
}
static inline void store32be(uint32_t *addr, uint32_t data)
{
*addr = is_little_endian() ? SWAP32(data) : data;
}
static inline uint32_t load32be(const uint32_t *addr)
{
return is_little_endian() ? SWAP32(*addr) : *addr;
}
#endif

View File

@ -38,7 +38,7 @@
#include <compat/msvc.h>
#include "retroarch_logger.h"
#include "endianness.h"
#include <retro_endianness.h>
#include <limits.h>
/* Some platforms do not set this value.