Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 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. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AOM_PORTS_MEM_H_ |
| 13 | #define AOM_PORTS_MEM_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "aom_config.h" |
| 16 | #include "aom/aom_integer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 17 | |
| 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 |
| 26 | |
| 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. |
| 30 | */ |
| 31 | #if defined(__GNUC__) && __GNUC__ |
| 32 | #define UNINITIALIZED_IS_SAFE(x) x = x |
| 33 | #else |
| 34 | #define UNINITIALIZED_IS_SAFE(x) x |
| 35 | #endif |
| 36 | |
| 37 | #if HAVE_NEON && defined(_MSC_VER) |
| 38 | #define __builtin_prefetch(x) |
| 39 | #endif |
| 40 | |
| 41 | /* Shift down with rounding for use when n >= 0, value >= 0 */ |
| 42 | #define ROUND_POWER_OF_TWO(value, n) (((value) + (((1 << (n)) >> 1))) >> (n)) |
| 43 | |
| 44 | /* Shift down with rounding for signed integers, for use when n >= 0 */ |
| 45 | #define ROUND_POWER_OF_TWO_SIGNED(value, n) \ |
| 46 | (((value) < 0) ? -ROUND_POWER_OF_TWO(-(value), (n)) \ |
| 47 | : ROUND_POWER_OF_TWO((value), (n))) |
| 48 | |
Debargha Mukherjee | 9310553 | 2017-03-01 10:44:46 -0800 | [diff] [blame] | 49 | /* Shift down with rounding for use when n >= 0, value >= 0 for (64 bit) */ |
| 50 | #define ROUND_POWER_OF_TWO_64(value, n) \ |
| 51 | (((value) + ((((int64_t)1 << (n)) >> 1))) >> (n)) |
| 52 | /* Shift down with rounding for signed integers, for use when n >= 0 (64 bit) */ |
| 53 | #define ROUND_POWER_OF_TWO_SIGNED_64(value, n) \ |
| 54 | (((value) < 0) ? -ROUND_POWER_OF_TWO_64(-(value), (n)) \ |
| 55 | : ROUND_POWER_OF_TWO_64((value), (n))) |
| 56 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 57 | #define ALIGN_POWER_OF_TWO(value, n) \ |
| 58 | (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1)) |
| 59 | |
| 60 | #define CONVERT_TO_SHORTPTR(x) ((uint16_t *)(((uintptr_t)(x)) << 1)) |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 61 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 62 | #define CONVERT_TO_BYTEPTR(x) ((uint8_t *)(((uintptr_t)(x)) >> 1)) |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 63 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 64 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 65 | #endif // AOM_PORTS_MEM_H_ |