2010-05-18 17:58:33 +02:00
|
|
|
/*
|
2010-09-09 14:16:39 +02:00
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
2010-05-18 17:58:33 +02:00
|
|
|
*
|
2010-06-18 18:39:21 +02:00
|
|
|
* Use of this source code is governed by a BSD-style license
|
2010-06-04 22:19:40 +02:00
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
2010-06-18 18:39:21 +02:00
|
|
|
* in the file PATENTS. All contributing project authors may
|
2010-06-04 22:19:40 +02:00
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
|
2013-12-16 03:36:00 +01:00
|
|
|
#ifndef VPX_PORTS_MEM_OPS_ALIGNED_H_
|
|
|
|
#define VPX_PORTS_MEM_OPS_ALIGNED_H_
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2014-02-27 01:32:09 +01:00
|
|
|
#include "vpx/vpx_integer.h"
|
|
|
|
|
2011-02-17 02:54:49 +01:00
|
|
|
/* \file
|
|
|
|
* \brief Provides portable memory access primitives for operating on aligned
|
2010-05-18 17:58:33 +02:00
|
|
|
* data
|
|
|
|
*
|
2011-02-17 02:54:49 +01:00
|
|
|
* This file is split from mem_ops.h for easier maintenance. See mem_ops.h
|
|
|
|
* for a more detailed description of these primitives.
|
2010-05-18 17:58:33 +02:00
|
|
|
*/
|
|
|
|
#ifndef INCLUDED_BY_MEM_OPS_H
|
|
|
|
#error Include mem_ops.h, not mem_ops_aligned.h directly.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Architectures that provide instructions for doing this byte swapping
|
|
|
|
* could redefine these macros.
|
|
|
|
*/
|
2016-07-25 23:22:32 +02:00
|
|
|
#define swap_endian_16(val, raw) \
|
|
|
|
do { \
|
|
|
|
val = (uint16_t)(((raw >> 8) & 0x00ff) | ((raw << 8) & 0xff00)); \
|
|
|
|
} while (0)
|
|
|
|
#define swap_endian_32(val, raw) \
|
|
|
|
do { \
|
|
|
|
val = ((raw >> 24) & 0x000000ff) | ((raw >> 8) & 0x0000ff00) | \
|
|
|
|
((raw << 8) & 0x00ff0000) | ((raw << 24) & 0xff000000); \
|
|
|
|
} while (0)
|
|
|
|
#define swap_endian_16_se(val, raw) \
|
|
|
|
do { \
|
|
|
|
swap_endian_16(val, raw); \
|
|
|
|
val = ((val << 16) >> 16); \
|
|
|
|
} while (0)
|
|
|
|
#define swap_endian_32_se(val, raw) swap_endian_32(val, raw)
|
|
|
|
|
|
|
|
#define mem_get_ne_aligned_generic(end, sz) \
|
|
|
|
static VPX_INLINE unsigned MEM_VALUE_T mem_get_##end##sz##_aligned( \
|
|
|
|
const void *vmem) { \
|
|
|
|
const uint##sz##_t *mem = (const uint##sz##_t *)vmem; \
|
|
|
|
return *mem; \
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2016-07-25 23:22:32 +02:00
|
|
|
#define mem_get_sne_aligned_generic(end, sz) \
|
|
|
|
static VPX_INLINE signed MEM_VALUE_T mem_get_s##end##sz##_aligned( \
|
|
|
|
const void *vmem) { \
|
|
|
|
const int##sz##_t *mem = (const int##sz##_t *)vmem; \
|
|
|
|
return *mem; \
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2016-07-25 23:22:32 +02:00
|
|
|
#define mem_get_se_aligned_generic(end, sz) \
|
|
|
|
static VPX_INLINE unsigned MEM_VALUE_T mem_get_##end##sz##_aligned( \
|
|
|
|
const void *vmem) { \
|
|
|
|
const uint##sz##_t *mem = (const uint##sz##_t *)vmem; \
|
|
|
|
unsigned MEM_VALUE_T val, raw = *mem; \
|
|
|
|
swap_endian_##sz(val, raw); \
|
|
|
|
return val; \
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2016-07-25 23:22:32 +02:00
|
|
|
#define mem_get_sse_aligned_generic(end, sz) \
|
|
|
|
static VPX_INLINE signed MEM_VALUE_T mem_get_s##end##sz##_aligned( \
|
|
|
|
const void *vmem) { \
|
|
|
|
const int##sz##_t *mem = (const int##sz##_t *)vmem; \
|
|
|
|
unsigned MEM_VALUE_T val, raw = *mem; \
|
|
|
|
swap_endian_##sz##_se(val, raw); \
|
|
|
|
return val; \
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2016-07-25 23:22:32 +02:00
|
|
|
#define mem_put_ne_aligned_generic(end, sz) \
|
|
|
|
static VPX_INLINE void mem_put_##end##sz##_aligned(void *vmem, \
|
|
|
|
MEM_VALUE_T val) { \
|
|
|
|
uint##sz##_t *mem = (uint##sz##_t *)vmem; \
|
|
|
|
*mem = (uint##sz##_t)val; \
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2016-07-25 23:22:32 +02:00
|
|
|
#define mem_put_se_aligned_generic(end, sz) \
|
|
|
|
static VPX_INLINE void mem_put_##end##sz##_aligned(void *vmem, \
|
|
|
|
MEM_VALUE_T val) { \
|
|
|
|
uint##sz##_t *mem = (uint##sz##_t *)vmem, raw; \
|
|
|
|
swap_endian_##sz(raw, val); \
|
|
|
|
*mem = (uint##sz##_t)raw; \
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2010-05-18 17:58:33 +02:00
|
|
|
|
2012-11-02 23:39:14 +01:00
|
|
|
#include "vpx_config.h"
|
2010-05-18 17:58:33 +02:00
|
|
|
#if CONFIG_BIG_ENDIAN
|
2016-07-25 23:22:32 +02:00
|
|
|
#define mem_get_be_aligned_generic(sz) mem_get_ne_aligned_generic(be, sz)
|
|
|
|
#define mem_get_sbe_aligned_generic(sz) mem_get_sne_aligned_generic(be, sz)
|
|
|
|
#define mem_get_le_aligned_generic(sz) mem_get_se_aligned_generic(le, sz)
|
|
|
|
#define mem_get_sle_aligned_generic(sz) mem_get_sse_aligned_generic(le, sz)
|
|
|
|
#define mem_put_be_aligned_generic(sz) mem_put_ne_aligned_generic(be, sz)
|
|
|
|
#define mem_put_le_aligned_generic(sz) mem_put_se_aligned_generic(le, sz)
|
2010-05-18 17:58:33 +02:00
|
|
|
#else
|
2016-07-25 23:22:32 +02:00
|
|
|
#define mem_get_be_aligned_generic(sz) mem_get_se_aligned_generic(be, sz)
|
|
|
|
#define mem_get_sbe_aligned_generic(sz) mem_get_sse_aligned_generic(be, sz)
|
|
|
|
#define mem_get_le_aligned_generic(sz) mem_get_ne_aligned_generic(le, sz)
|
|
|
|
#define mem_get_sle_aligned_generic(sz) mem_get_sne_aligned_generic(le, sz)
|
|
|
|
#define mem_put_be_aligned_generic(sz) mem_put_se_aligned_generic(be, sz)
|
|
|
|
#define mem_put_le_aligned_generic(sz) mem_put_ne_aligned_generic(le, sz)
|
2010-05-18 17:58:33 +02:00
|
|
|
#endif
|
|
|
|
|
2016-07-25 23:22:32 +02:00
|
|
|
/* clang-format off */
|
2010-05-18 17:58:33 +02:00
|
|
|
#undef mem_get_be16_aligned
|
|
|
|
#define mem_get_be16_aligned mem_ops_wrap_symbol(mem_get_be16_aligned)
|
2012-11-02 23:39:14 +01:00
|
|
|
mem_get_be_aligned_generic(16)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#undef mem_get_be32_aligned
|
|
|
|
#define mem_get_be32_aligned mem_ops_wrap_symbol(mem_get_be32_aligned)
|
2012-11-02 23:39:14 +01:00
|
|
|
mem_get_be_aligned_generic(32)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#undef mem_get_le16_aligned
|
|
|
|
#define mem_get_le16_aligned mem_ops_wrap_symbol(mem_get_le16_aligned)
|
2012-11-02 23:39:14 +01:00
|
|
|
mem_get_le_aligned_generic(16)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#undef mem_get_le32_aligned
|
|
|
|
#define mem_get_le32_aligned mem_ops_wrap_symbol(mem_get_le32_aligned)
|
2012-11-02 23:39:14 +01:00
|
|
|
mem_get_le_aligned_generic(32)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#undef mem_get_sbe16_aligned
|
|
|
|
#define mem_get_sbe16_aligned mem_ops_wrap_symbol(mem_get_sbe16_aligned)
|
2012-11-02 23:39:14 +01:00
|
|
|
mem_get_sbe_aligned_generic(16)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#undef mem_get_sbe32_aligned
|
|
|
|
#define mem_get_sbe32_aligned mem_ops_wrap_symbol(mem_get_sbe32_aligned)
|
2012-11-02 23:39:14 +01:00
|
|
|
mem_get_sbe_aligned_generic(32)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#undef mem_get_sle16_aligned
|
|
|
|
#define mem_get_sle16_aligned mem_ops_wrap_symbol(mem_get_sle16_aligned)
|
2012-11-02 23:39:14 +01:00
|
|
|
mem_get_sle_aligned_generic(16)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#undef mem_get_sle32_aligned
|
|
|
|
#define mem_get_sle32_aligned mem_ops_wrap_symbol(mem_get_sle32_aligned)
|
2012-11-02 23:39:14 +01:00
|
|
|
mem_get_sle_aligned_generic(32)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#undef mem_put_be16_aligned
|
|
|
|
#define mem_put_be16_aligned mem_ops_wrap_symbol(mem_put_be16_aligned)
|
2012-11-02 23:39:14 +01:00
|
|
|
mem_put_be_aligned_generic(16)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#undef mem_put_be32_aligned
|
|
|
|
#define mem_put_be32_aligned mem_ops_wrap_symbol(mem_put_be32_aligned)
|
2012-11-02 23:39:14 +01:00
|
|
|
mem_put_be_aligned_generic(32)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#undef mem_put_le16_aligned
|
|
|
|
#define mem_put_le16_aligned mem_ops_wrap_symbol(mem_put_le16_aligned)
|
2012-11-02 23:39:14 +01:00
|
|
|
mem_put_le_aligned_generic(16)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#undef mem_put_le32_aligned
|
|
|
|
#define mem_put_le32_aligned mem_ops_wrap_symbol(mem_put_le32_aligned)
|
2012-11-02 23:39:14 +01:00
|
|
|
mem_put_le_aligned_generic(32)
|
2010-05-18 17:58:33 +02:00
|
|
|
|
|
|
|
#undef mem_get_ne_aligned_generic
|
|
|
|
#undef mem_get_se_aligned_generic
|
|
|
|
#undef mem_get_sne_aligned_generic
|
|
|
|
#undef mem_get_sse_aligned_generic
|
|
|
|
#undef mem_put_ne_aligned_generic
|
|
|
|
#undef mem_put_se_aligned_generic
|
|
|
|
#undef swap_endian_16
|
|
|
|
#undef swap_endian_32
|
|
|
|
#undef swap_endian_16_se
|
|
|
|
#undef swap_endian_32_se
|
2016-07-25 23:22:32 +02:00
|
|
|
/* clang-format on */
|
2013-12-16 03:36:00 +01:00
|
|
|
|
|
|
|
#endif // VPX_PORTS_MEM_OPS_ALIGNED_H_
|