1 /* 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef VPX_VPX_PORTS_MEM_H_ 12 #define VPX_VPX_PORTS_MEM_H_ 13 14 #include "vpx_config.h" 15 #include "vpx/vpx_integer.h" 16 17 #if defined(__GNUC__) || defined(__SUNPRO_C) 18 #define DECLARE_ALIGNED(n, typ, val) typ val __attribute__((aligned(n))) 19 #elif defined(_MSC_VER) 20 #define DECLARE_ALIGNED(n, typ, val) __declspec(align(n)) typ val 21 #else 22 #warning No alignment directives known for this compiler. 23 #define DECLARE_ALIGNED(n, typ, val) typ val 24 #endif 25 26 #if defined(__has_builtin) 27 #define VPX_HAS_BUILTIN(x) __has_builtin(x) 28 #else 29 #define VPX_HAS_BUILTIN(x) 0 30 #endif 31 32 #if !VPX_HAS_BUILTIN(__builtin_prefetch) && !defined(__GNUC__) 33 #define __builtin_prefetch(x) 34 #endif 35 36 /* Shift down with rounding */ 37 #define ROUND_POWER_OF_TWO(value, n) (((value) + (1 << ((n)-1))) >> (n)) 38 #define ROUND64_POWER_OF_TWO(value, n) (((value) + (1ULL << ((n)-1))) >> (n)) 39 40 #define ALIGN_POWER_OF_TWO(value, n) \ 41 (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1)) 42 43 #define CONVERT_TO_SHORTPTR(x) ((uint16_t *)(((uintptr_t)(x)) << 1)) 44 #define CAST_TO_SHORTPTR(x) ((uint16_t *)((uintptr_t)(x))) 45 #if CONFIG_VP9_HIGHBITDEPTH 46 #define CONVERT_TO_BYTEPTR(x) ((uint8_t *)(((uintptr_t)(x)) >> 1)) 47 #define CAST_TO_BYTEPTR(x) ((uint8_t *)((uintptr_t)(x))) 48 #endif // CONFIG_VP9_HIGHBITDEPTH 49 50 #endif // VPX_VPX_PORTS_MEM_H_ 51