/*
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */


/* \file mem_ops.h
 * \brief Provides portable memory access primatives
 *
 * This function provides portable primatives for getting and setting of
 * signed and unsigned integers in 16, 24, and 32 bit sizes. The operations
 * can be performed on unaligned data regardless of hardware support for
 * unaligned accesses.
 *
 * The type used to pass the integral values may be changed by defining
 * MEM_VALUE_T with the appropriate type. The type given must be an integral
 * numeric type.
 *
 * The actual functions instantiated have the MEM_VALUE_T type name pasted
 * on to the symbol name. This allows the developer to instantiate these
 * operations for multiple types within the same translation unit. This is
 * of somewhat questionable utility, but the capability exists nonetheless.
 * Users not making use of this functionality should call the functions
 * without the type name appended, and the preprocessor will take care of
 * it.
 *
 * NOTE: This code is not supported on platforms where char > 1 octet ATM.
 */

#ifndef MAU_T
/* Minimum Access Unit for this target */
#define MAU_T unsigned char
#endif

#ifndef MEM_VALUE_T
#define MEM_VALUE_T int
#endif

#undef MEM_VALUE_T_SZ_BITS
#define MEM_VALUE_T_SZ_BITS (sizeof(MEM_VALUE_T) << 3)

#undef  mem_ops_wrap_symbol
#define mem_ops_wrap_symbol(fn) mem_ops_wrap_symbol2(fn, MEM_VALUE_T)
#undef  mem_ops_wrap_symbol2
#define mem_ops_wrap_symbol2(fn,typ) mem_ops_wrap_symbol3(fn,typ)
#undef  mem_ops_wrap_symbol3
#define mem_ops_wrap_symbol3(fn,typ) fn##_as_##typ

/*
 * Include aligned access routines
 */
#define INCLUDED_BY_MEM_OPS_H
#include "mem_ops_aligned.h"
#undef  INCLUDED_BY_MEM_OPS_H

#undef  mem_get_be16
#define mem_get_be16 mem_ops_wrap_symbol(mem_get_be16)
static unsigned MEM_VALUE_T mem_get_be16(const void *vmem)
{
    unsigned MEM_VALUE_T  val;
    const MAU_T          *mem = (const MAU_T *)vmem;

    val = mem[0] << 8;
    val |= mem[1];
    return val;
}

#undef  mem_get_be24
#define mem_get_be24 mem_ops_wrap_symbol(mem_get_be24)
static unsigned MEM_VALUE_T mem_get_be24(const void *vmem)
{
    unsigned MEM_VALUE_T  val;
    const MAU_T          *mem = (const MAU_T *)vmem;

    val = mem[0] << 16;
    val |= mem[1] << 8;
    val |= mem[2];
    return val;
}

#undef  mem_get_be32
#define mem_get_be32 mem_ops_wrap_symbol(mem_get_be32)
static unsigned MEM_VALUE_T mem_get_be32(const void *vmem)
{
    unsigned MEM_VALUE_T  val;
    const MAU_T          *mem = (const MAU_T *)vmem;

    val = mem[0] << 24;
    val |= mem[1] << 16;
    val |= mem[2] << 8;
    val |= mem[3];
    return val;
}

#undef  mem_get_le16
#define mem_get_le16 mem_ops_wrap_symbol(mem_get_le16)
static unsigned MEM_VALUE_T mem_get_le16(const void *vmem)
{
    unsigned MEM_VALUE_T  val;
    const MAU_T          *mem = (const MAU_T *)vmem;

    val = mem[1] << 8;
    val |= mem[0];
    return val;
}

#undef  mem_get_le24
#define mem_get_le24 mem_ops_wrap_symbol(mem_get_le24)
static unsigned MEM_VALUE_T mem_get_le24(const void *vmem)
{
    unsigned MEM_VALUE_T  val;
    const MAU_T          *mem = (const MAU_T *)vmem;

    val = mem[2] << 16;
    val |= mem[1] << 8;
    val |= mem[0];
    return val;
}

#undef  mem_get_le32
#define mem_get_le32 mem_ops_wrap_symbol(mem_get_le32)
static unsigned MEM_VALUE_T mem_get_le32(const void *vmem)
{
    unsigned MEM_VALUE_T  val;
    const MAU_T          *mem = (const MAU_T *)vmem;

    val = mem[3] << 24;
    val |= mem[2] << 16;
    val |= mem[1] << 8;
    val |= mem[0];
    return val;
}

#define mem_get_s_generic(end,sz) \
    static signed MEM_VALUE_T mem_get_s##end##sz(const void *vmem) {\
        const MAU_T *mem = (const MAU_T*)vmem;\
        signed MEM_VALUE_T val = mem_get_##end##sz(mem);\
        return (val << (MEM_VALUE_T_SZ_BITS - sz)) >> (MEM_VALUE_T_SZ_BITS - sz);\
    }

#undef  mem_get_sbe16
#define mem_get_sbe16 mem_ops_wrap_symbol(mem_get_sbe16)
mem_get_s_generic(be, 16);

#undef  mem_get_sbe24
#define mem_get_sbe24 mem_ops_wrap_symbol(mem_get_sbe24)
mem_get_s_generic(be, 24);

#undef  mem_get_sbe32
#define mem_get_sbe32 mem_ops_wrap_symbol(mem_get_sbe32)
mem_get_s_generic(be, 32);

#undef  mem_get_sle16
#define mem_get_sle16 mem_ops_wrap_symbol(mem_get_sle16)
mem_get_s_generic(le, 16);

#undef  mem_get_sle24
#define mem_get_sle24 mem_ops_wrap_symbol(mem_get_sle24)
mem_get_s_generic(le, 24);

#undef  mem_get_sle32
#define mem_get_sle32 mem_ops_wrap_symbol(mem_get_sle32)
mem_get_s_generic(le, 32);

#undef  mem_put_be16
#define mem_put_be16 mem_ops_wrap_symbol(mem_put_be16)
static void mem_put_be16(void *vmem, MEM_VALUE_T val)
{
    MAU_T *mem = (MAU_T *)vmem;

    mem[0] = (val >> 8) & 0xff;
    mem[1] = (val >> 0) & 0xff;
}

#undef  mem_put_be24
#define mem_put_be24 mem_ops_wrap_symbol(mem_put_be24)
static void mem_put_be24(void *vmem, MEM_VALUE_T val)
{
    MAU_T *mem = (MAU_T *)vmem;

    mem[0] = (val >> 16) & 0xff;
    mem[1] = (val >>  8) & 0xff;
    mem[2] = (val >>  0) & 0xff;
}

#undef  mem_put_be32
#define mem_put_be32 mem_ops_wrap_symbol(mem_put_be32)
static void mem_put_be32(void *vmem, MEM_VALUE_T val)
{
    MAU_T *mem = (MAU_T *)vmem;

    mem[0] = (val >> 24) & 0xff;
    mem[1] = (val >> 16) & 0xff;
    mem[2] = (val >>  8) & 0xff;
    mem[3] = (val >>  0) & 0xff;
}

#undef  mem_put_le16
#define mem_put_le16 mem_ops_wrap_symbol(mem_put_le16)
static void mem_put_le16(void *vmem, MEM_VALUE_T val)
{
    MAU_T *mem = (MAU_T *)vmem;

    mem[0] = (val >>  0) & 0xff;
    mem[1] = (val >>  8) & 0xff;
}

#undef  mem_put_le24
#define mem_put_le24 mem_ops_wrap_symbol(mem_put_le24)
static void mem_put_le24(void *vmem, MEM_VALUE_T val)
{
    MAU_T *mem = (MAU_T *)vmem;

    mem[0] = (val >>  0) & 0xff;
    mem[1] = (val >>  8) & 0xff;
    mem[2] = (val >> 16) & 0xff;
}

#undef  mem_put_le32
#define mem_put_le32 mem_ops_wrap_symbol(mem_put_le32)
static void mem_put_le32(void *vmem, MEM_VALUE_T val)
{
    MAU_T *mem = (MAU_T *)vmem;

    mem[0] = (val >>  0) & 0xff;
    mem[1] = (val >>  8) & 0xff;
    mem[2] = (val >> 16) & 0xff;
    mem[3] = (val >> 24) & 0xff;
}
