Flutter Engine
WindowsUtils.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef WINDOWS_UTILS_H
18 #define WINDOWS_UTILS_H
19 
20 #if defined(_WIN32)
21 #define DISABLE_TEST_WINDOWS(TEST_NAME) DISABLED_##TEST_NAME
22 #define FRIEND_TEST_WINDOWS_DISABLED_EXPANDED(SUITE, TEST_NAME) \
23  FRIEND_TEST(SUITE, TEST_NAME)
24 #define FRIEND_TEST_WINDOWS_DISABLED(SUITE, TEST_NAME) \
25  FRIEND_TEST_WINDOWS_DISABLED_EXPANDED(SUITE, DISABLE_TEST_WINDOWS(TEST_NAME))
26 
27 #define FRIEND_TEST_WINDOWS_ONLY(SUITE, TEST_NAME) FRIEND_TEST(SUITE, TEST_NAME)
28 #define WINDOWS_ONLY(TEST_NAME) TEST_NAME
29 
30 #define NOMINMAX
31 #include <BaseTsd.h>
32 #include <intrin.h>
33 #include <windows.h>
34 
35 #undef ERROR
36 
37 inline unsigned int clz_win(unsigned int num) {
38  unsigned long r = 0;
39  _BitScanReverse(&r, num);
40  return r;
41 }
42 
43 inline unsigned int clzl_win(unsigned long num) {
44  unsigned long r = 0;
45  _BitScanReverse64(&r, num);
46  return r;
47 }
48 
49 inline unsigned int ctz_win(unsigned int num) {
50  unsigned long r = 0;
51  _BitScanForward(&r, num);
52  return r;
53 }
54 
55 typedef SSIZE_T ssize_t;
56 
57 #else
58 #define DISABLE_TEST_WINDOWS(TEST_NAME) TEST_NAME
59 #define FRIEND_TEST_WINDOWS_DISABLED(SUITE, TEST_NAME) \
60  FRIEND_TEST(SUITE, TEST_NAME)
61 
62 #define WINDOWS_ONLY(TEST_NAME) DISABLED_##TEST_NAME
63 #define FRIEND_TEST_WINDOWS_ONLY_EXPANDED(SUITE, TEST_NAME) \
64  FRIEND_TEST(SUITE, TEST_NAME)
65 #define FRIEND_TEST_WINDOWS_ONLY(SUITE, TEST_NAME) \
66  FRIEND_TEST_WINDOWS_ONLY_EXPANDED(SUITE, DISABLE_TEST_WINDOWS(TEST_NAME))
67 #endif // defined(_WIN32)
68 #endif // WINDOWS_UTILS_H