tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mem_internal.h (4301B)


      1 /*
      2 * Copyright (c) 2002 Fabrice Bellard
      3 *
      4 * This file is part of FFmpeg.
      5 *
      6 * FFmpeg is free software; you can redistribute it and/or
      7 * modify it under the terms of the GNU Lesser General Public
      8 * License as published by the Free Software Foundation; either
      9 * version 2.1 of the License, or (at your option) any later version.
     10 *
     11 * FFmpeg is distributed in the hope that it will be useful,
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14 * Lesser General Public License for more details.
     15 *
     16 * You should have received a copy of the GNU Lesser General Public
     17 * License along with FFmpeg; if not, write to the Free Software
     18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     19 */
     20 
     21 #ifndef AVUTIL_MEM_INTERNAL_H
     22 #define AVUTIL_MEM_INTERNAL_H
     23 
     24 #include "config.h"
     25 
     26 #include <stdint.h>
     27 #ifndef _MSC_VER
     28 #include <stdalign.h>
     29 #endif
     30 
     31 #include "attributes.h"
     32 #include "macros.h"
     33 
     34 /**
     35 * @def DECLARE_ALIGNED(n,t,v)
     36 * Declare a variable that is aligned in memory.
     37 *
     38 * @code{.c}
     39 * DECLARE_ALIGNED(16, uint16_t, aligned_int) = 42;
     40 * DECLARE_ALIGNED(32, uint8_t, aligned_array)[128];
     41 *
     42 * // The default-alignment equivalent would be
     43 * uint16_t aligned_int = 42;
     44 * uint8_t aligned_array[128];
     45 * @endcode
     46 *
     47 * @param n Minimum alignment in bytes
     48 * @param t Type of the variable (or array element)
     49 * @param v Name of the variable
     50 */
     51 
     52 /**
     53 * @def DECLARE_ASM_ALIGNED(n,t,v)
     54 * Declare an aligned variable appropriate for use in inline assembly code.
     55 *
     56 * @code{.c}
     57 * DECLARE_ASM_ALIGNED(16, uint64_t, pw_08) = UINT64_C(0x0008000800080008);
     58 * @endcode
     59 *
     60 * @param n Minimum alignment in bytes
     61 * @param t Type of the variable (or array element)
     62 * @param v Name of the variable
     63 */
     64 
     65 /**
     66 * @def DECLARE_ASM_CONST(n,t,v)
     67 * Declare a static constant aligned variable appropriate for use in inline
     68 * assembly code.
     69 *
     70 * @code{.c}
     71 * DECLARE_ASM_CONST(16, uint64_t, pw_08) = UINT64_C(0x0008000800080008);
     72 * @endcode
     73 *
     74 * @param n Minimum alignment in bytes
     75 * @param t Type of the variable (or array element)
     76 * @param v Name of the variable
     77 */
     78 
     79 #if defined(__DJGPP__)
     80    #define DECLARE_ALIGNED_T(n,t,v)    alignas(FFMIN(n, 16)) t v
     81    #define DECLARE_ASM_ALIGNED(n,t,v)  alignas(FFMIN(n, 16)) t av_used v
     82    #define DECLARE_ASM_CONST(n,t,v)    alignas(FFMIN(n, 16)) static const t av_used v
     83 #elif defined(_MSC_VER)
     84    #define DECLARE_ALIGNED_T(n,t,v)    __declspec(align(n)) t v
     85    #define DECLARE_ASM_ALIGNED(n,t,v)  __declspec(align(n)) t v
     86    #define DECLARE_ASM_CONST(n,t,v)    __declspec(align(n)) static const t v
     87 #else
     88    #define DECLARE_ALIGNED_T(n,t,v)    alignas(n) t v
     89    #define DECLARE_ASM_ALIGNED(n,t,v)  alignas(n) t av_used v
     90    #define DECLARE_ASM_CONST(n,t,v)    alignas(n) static const t av_used v
     91 #endif
     92 
     93 #if HAVE_SIMD_ALIGN_64
     94    #define ALIGN_64 64
     95    #define ALIGN_32 32
     96 #elif HAVE_SIMD_ALIGN_32
     97    #define ALIGN_64 32
     98    #define ALIGN_32 32
     99 #else
    100    #define ALIGN_64 16
    101    #define ALIGN_32 16
    102 #endif
    103 
    104 #define DECLARE_ALIGNED(n,t,v) DECLARE_ALIGNED_V(n,t,v)
    105 
    106 // Macro needs to be double-wrapped in order to expand
    107 // possible other macros being passed for n.
    108 #define DECLARE_ALIGNED_V(n,t,v) DECLARE_ALIGNED_##n(t,v)
    109 
    110 #define DECLARE_ALIGNED_4(t,v)  DECLARE_ALIGNED_T(       4, t, v)
    111 #define DECLARE_ALIGNED_8(t,v)  DECLARE_ALIGNED_T(       8, t, v)
    112 #define DECLARE_ALIGNED_16(t,v) DECLARE_ALIGNED_T(      16, t, v)
    113 #define DECLARE_ALIGNED_32(t,v) DECLARE_ALIGNED_T(ALIGN_32, t, v)
    114 #define DECLARE_ALIGNED_64(t,v) DECLARE_ALIGNED_T(ALIGN_64, t, v)
    115 
    116 // Some broken preprocessors need a second expansion
    117 // to be forced to tokenize __VA_ARGS__
    118 #define E1(x) x
    119 
    120 #define LOCAL_ALIGNED_D(a, t, v, s, o, ...)             \
    121    DECLARE_ALIGNED(a, t, la_##v) s o;                  \
    122    t (*v) o = la_##v
    123 
    124 #define LOCAL_ALIGNED(a, t, v, ...) LOCAL_ALIGNED_##a(t, v, __VA_ARGS__)
    125 
    126 #define LOCAL_ALIGNED_4(t, v, ...) E1(LOCAL_ALIGNED_D(4, t, v, __VA_ARGS__,,))
    127 
    128 #define LOCAL_ALIGNED_8(t, v, ...) E1(LOCAL_ALIGNED_D(8, t, v, __VA_ARGS__,,))
    129 
    130 #define LOCAL_ALIGNED_16(t, v, ...) E1(LOCAL_ALIGNED_D(16, t, v, __VA_ARGS__,,))
    131 
    132 #define LOCAL_ALIGNED_32(t, v, ...) E1(LOCAL_ALIGNED_D(32, t, v, __VA_ARGS__,,))
    133 
    134 #endif /* AVUTIL_MEM_INTERNAL_H */