mem.h 1.97 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
John Koleszar's avatar
John Koleszar committed
3
 *
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
John Koleszar's avatar
John Koleszar committed
10 11
 */

Adrian Grange's avatar
Adrian Grange committed
12 13
#ifndef AOM_PORTS_MEM_H_
#define AOM_PORTS_MEM_H_
Dmitry Kovalev's avatar
Dmitry Kovalev committed
14

Adrian Grange's avatar
Adrian Grange committed
15 16
#include "aom_config.h"
#include "aom/aom_integer.h"
John Koleszar's avatar
John Koleszar committed
17

John Koleszar's avatar
John Koleszar committed
18
#if (defined(__GNUC__) && __GNUC__) || defined(__SUNPRO_C)
clang-format's avatar
clang-format committed
19
#define DECLARE_ALIGNED(n, typ, val) typ val __attribute__((aligned(n)))
John Koleszar's avatar
John Koleszar committed
20
#elif defined(_MSC_VER)
clang-format's avatar
clang-format committed
21
#define DECLARE_ALIGNED(n, typ, val) __declspec(align(n)) typ val
John Koleszar's avatar
John Koleszar committed
22 23
#else
#warning No alignment directives known for this compiler.
clang-format's avatar
clang-format committed
24
#define DECLARE_ALIGNED(n, typ, val) typ val
John Koleszar's avatar
John Koleszar committed
25 26 27 28 29 30 31
#endif

/* Indicates that the usage of the specified variable has been audited to assure
 * that it's safe to use uninitialized. Silences 'may be used uninitialized'
 * warnings on gcc.
 */
#if defined(__GNUC__) && __GNUC__
clang-format's avatar
clang-format committed
32
#define UNINITIALIZED_IS_SAFE(x) x = x
John Koleszar's avatar
John Koleszar committed
33 34
#else
#define UNINITIALIZED_IS_SAFE(x) x
35 36 37 38 39 40
#endif

#if HAVE_NEON && defined(_MSC_VER)
#define __builtin_prefetch(x)
#endif

41
/* Shift down with rounding */
clang-format's avatar
clang-format committed
42
#define ROUND_POWER_OF_TWO(value, n) (((value) + (1 << ((n)-1))) >> (n))
43

44 45 46 47 48
/* Shift down with rounding for signed integers, for use when n >= 0 */
#define ROUND_POWER_OF_TWO_SIGNED(value, n)           \
  (((value) < 0) ? -ROUND_POWER_OF_TWO(-(value), (n)) \
                 : ROUND_POWER_OF_TWO((value), (n)))

49
#define ALIGN_POWER_OF_TWO(value, n) \
clang-format's avatar
clang-format committed
50
  (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1))
51

52
#define CONVERT_TO_SHORTPTR(x) ((uint16_t *)(((uintptr_t)(x)) << 1))
53
#if CONFIG_AOM_HIGHBITDEPTH
54
#define CONVERT_TO_BYTEPTR(x) ((uint8_t *)(((uintptr_t)(x)) >> 1))
55
#endif  // CONFIG_AOM_HIGHBITDEPTH
56

Adrian Grange's avatar
Adrian Grange committed
57
#endif  // AOM_PORTS_MEM_H_