• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
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.
10  */
11 
12 #ifndef AOM_AOM_PORTS_MSVC_H_
13 #define AOM_AOM_PORTS_MSVC_H_
14 #ifdef _MSC_VER
15 
16 #include "config/aom_config.h"
17 
18 #if _MSC_VER < 1900  // VS2015 provides snprintf
19 #define snprintf _snprintf
20 #endif  // _MSC_VER < 1900
21 
22 #if _MSC_VER < 1800  // VS2013 provides round
23 #include <math.h>
round(double x)24 static INLINE double round(double x) {
25   if (x < 0)
26     return ceil(x - 0.5);
27   else
28     return floor(x + 0.5);
29 }
30 
roundf(float x)31 static INLINE float roundf(float x) {
32   if (x < 0)
33     return (float)ceil(x - 0.5f);
34   else
35     return (float)floor(x + 0.5f);
36 }
37 
lroundf(float x)38 static INLINE long lroundf(float x) {
39   if (x < 0)
40     return (long)(x - 0.5f);
41   else
42     return (long)(x + 0.5f);
43 }
44 #endif  // _MSC_VER < 1800
45 
46 #if HAVE_AVX
47 #include <immintrin.h>
48 // Note:
49 // _mm256_insert_epi16 intrinsics is available from vs2017.
50 // We define this macro for vs2015 and earlier. The
51 // intrinsics used here are in vs2015 document:
52 // https://msdn.microsoft.com/en-us/library/hh977022.aspx
53 // Input parameters:
54 // a: __m256i,
55 // d: int16_t,
56 // indx: imm8 (0 - 15)
57 #if _MSC_VER <= 1900
58 #define _mm256_insert_epi16(a, d, indx)                                      \
59   _mm256_insertf128_si256(                                                   \
60       a,                                                                     \
61       _mm_insert_epi16(_mm256_extractf128_si256(a, indx >> 3), d, indx % 8), \
62       indx >> 3)
63 
_mm256_extract_epi32(__m256i a,const int i)64 static INLINE int _mm256_extract_epi32(__m256i a, const int i) {
65   return a.m256i_i32[i & 7];
66 }
_mm256_insert_epi32(__m256i a,int b,const int i)67 static INLINE __m256i _mm256_insert_epi32(__m256i a, int b, const int i) {
68   __m256i c = a;
69   c.m256i_i32[i & 7] = b;
70   return c;
71 }
72 #endif  // _MSC_VER <= 1900
73 #endif  // HAVE_AVX
74 #endif  // _MSC_VER
75 #endif  // AOM_AOM_PORTS_MSVC_H_
76