hadamard: Add 4x4 test.
[aom.git] / aom_ports / mem.h
blob5eeed99f004c251470d4dd5e7acac5c9e1363f63
1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
12 #ifndef AOM_AOM_PORTS_MEM_H_
13 #define AOM_AOM_PORTS_MEM_H_
15 #include "aom/aom_integer.h"
16 #include "config/aom_config.h"
18 #if (defined(__GNUC__) && __GNUC__) || defined(__SUNPRO_C)
19 #define DECLARE_ALIGNED(n, typ, val) typ val __attribute__((aligned(n)))
20 #elif defined(_MSC_VER)
21 #define DECLARE_ALIGNED(n, typ, val) __declspec(align(n)) typ val
22 #else
23 #warning No alignment directives known for this compiler.
24 #define DECLARE_ALIGNED(n, typ, val) typ val
25 #endif
27 /* Indicates that the usage of the specified variable has been audited to assure
28 * that it's safe to use uninitialized. Silences 'may be used uninitialized'
29 * warnings on gcc.
31 #if defined(__GNUC__) && __GNUC__
32 #define UNINITIALIZED_IS_SAFE(x) x = x
33 #else
34 #define UNINITIALIZED_IS_SAFE(x) x
35 #endif
37 #if HAVE_NEON && defined(_MSC_VER)
38 #define __builtin_prefetch(x)
39 #endif
41 /* Shift down with rounding for use when n >= 0. Usually value >= 0, but the
42 * macro can be used with a negative value if the direction of rounding is
43 * acceptable.
45 #define ROUND_POWER_OF_TWO(value, n) (((value) + (((1 << (n)) >> 1))) >> (n))
47 /* Shift down with rounding for signed integers, for use when n >= 0 */
48 #define ROUND_POWER_OF_TWO_SIGNED(value, n) \
49 (((value) < 0) ? -ROUND_POWER_OF_TWO(-(value), (n)) \
50 : ROUND_POWER_OF_TWO((value), (n)))
52 /* Shift down with rounding for use when n >= 0 (64-bit value). Usually
53 * value >= 0, but the macro can be used with a negative value if the direction
54 * of rounding is acceptable.
56 #define ROUND_POWER_OF_TWO_64(value, n) \
57 (((value) + ((((int64_t)1 << (n)) >> 1))) >> (n))
58 /* Shift down with rounding for signed integers, for use when n >= 0 (64-bit
59 * value)
61 #define ROUND_POWER_OF_TWO_SIGNED_64(value, n) \
62 (((value) < 0) ? -ROUND_POWER_OF_TWO_64(-(value), (n)) \
63 : ROUND_POWER_OF_TWO_64((value), (n)))
65 /* shift right or left depending on sign of n */
66 #define RIGHT_SIGNED_SHIFT(value, n) \
67 ((n) < 0 ? ((value) << (-(n))) : ((value) >> (n)))
69 #define ALIGN_POWER_OF_TWO(value, n) \
70 (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1))
72 #define DIVIDE_AND_ROUND(x, y) (((x) + ((y) >> 1)) / (y))
74 #define CONVERT_TO_SHORTPTR(x) ((uint16_t *)(((uintptr_t)(x)) << 1))
75 #define CONVERT_TO_BYTEPTR(x) ((uint8_t *)(((uintptr_t)(x)) >> 1))
77 /*!\brief force enum to be unsigned 1 byte*/
78 #define UENUM1BYTE(enumvar) \
79 ; \
80 typedef uint8_t enumvar
82 /*!\brief force enum to be signed 1 byte*/
83 #define SENUM1BYTE(enumvar) \
84 ; \
85 typedef int8_t enumvar
87 /*!\brief force enum to be unsigned 2 byte*/
88 #define UENUM2BYTE(enumvar) \
89 ; \
90 typedef uint16_t enumvar
92 /*!\brief force enum to be signed 2 byte*/
93 #define SENUM2BYTE(enumvar) \
94 ; \
95 typedef int16_t enumvar
97 /*!\brief force enum to be unsigned 4 byte*/
98 #define UENUM4BYTE(enumvar) \
99 ; \
100 typedef uint32_t enumvar
102 /*!\brief force enum to be unsigned 4 byte*/
103 #define SENUM4BYTE(enumvar) \
105 typedef int32_t enumvar
107 #endif // AOM_AOM_PORTS_MEM_H_