• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 NOMINMAX
28 
29 // ACE PC preivew.
30 #ifdef WINDOWS_PLATFORM
31 #include <basetsd.h>
32 #else
33 #include <BaseTsd.h>
34 #endif
35 
36 #include <intrin.h>
37 #include <windows.h>
38 
39 #undef ERROR
40 
clz_win(unsigned int num)41 inline unsigned int clz_win(unsigned int num) {
42   unsigned long r = 0;
43   _BitScanReverse(&r, num);
44   return r;
45 }
46 
clzl_win(unsigned long num)47 inline unsigned int clzl_win(unsigned long num) {
48   unsigned long r = 0;
49   _BitScanReverse64(&r, num);
50   return r;
51 }
52 
ctz_win(unsigned int num)53 inline unsigned int ctz_win(unsigned int num) {
54   unsigned long r = 0;
55   _BitScanForward(&r, num);
56   return r;
57 }
58 
59 typedef SSIZE_T ssize_t;
60 
61 #else
62 #define DISABLE_TEST_WINDOWS(TEST_NAME) TEST_NAME
63 #define FRIEND_TEST_WINDOWS_DISABLED(SUITE, TEST_NAME) \
64   FRIEND_TEST(SUITE, TEST_NAME)
65 #endif  // defined(_WIN32)
66 #endif  // WINDOWS_UTILS_H
67