diff --git a/caffe2/perfkernels/cvtsh_ss_bugfix.h b/caffe2/perfkernels/cvtsh_ss_bugfix.h index bd06681..00172b7 100644 --- a/caffe2/perfkernels/cvtsh_ss_bugfix.h +++ b/caffe2/perfkernels/cvtsh_ss_bugfix.h @@ -1,10 +1,36 @@ +/** + * Copyright (c) 2016-present, Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #pragma once -#if defined(__APPLE__) && (__clang_major__ < 8) +// Apple clang was fixed in 8.1 +#if defined(__apple_build_version__) && ((__clang_major__ < 8) || ((__clang_major__ == 8) && (__clang_minor__ < 1))) +#define __APPLE_NEED_FIX 1 +#endif + +// Regular clang was fixed in 3.9 +#if defined(__clang__) && (__clang_major__ < 4) && (__clang_minor__ < 9) +#define __CLANG_NEED_FIX 1 +#endif + +#if __APPLE_NEED_FIX || __CLANG_NEED_FIX #include -// This version of apple clang has a bug that _cvtsh_ss is not defined, see +// This version of clang has a bug that _cvtsh_ss is not defined, see // https://reviews.llvm.org/D16177 static __inline float __attribute__((__always_inline__, __nodebug__, __target__("f16c"))) @@ -15,7 +41,10 @@ _cvtsh_ss(unsigned short a) return r[0]; } -#endif // defined(__APPLE__) && (__clang_major__ < 8) +#endif // __APPLE_NEED_FIX || __CLANG_NEED_FIX + +#undef __APPLE_NEED_FIX +#undef __CLANG_NEED_FIX #ifdef _MSC_VER