Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: sky/engine/wtf/BitwiseOperations.h

Issue 719063002: Revert "Remove support for MSVC" (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 24 matching lines...) Expand all
35 // countLeadingZeros() is a bitwise operation that counts the number of leading 35 // countLeadingZeros() is a bitwise operation that counts the number of leading
36 // zeros in a binary value, starting with the most significant bit. C does not 36 // zeros in a binary value, starting with the most significant bit. C does not
37 // have an operator to do this, but fortunately the various compilers have 37 // have an operator to do this, but fortunately the various compilers have
38 // built-ins that map to fast underlying processor instructions. 38 // built-ins that map to fast underlying processor instructions.
39 39
40 #include "wtf/CPU.h" 40 #include "wtf/CPU.h"
41 #include "wtf/Compiler.h" 41 #include "wtf/Compiler.h"
42 42
43 #include <stdint.h> 43 #include <stdint.h>
44 44
45 #if COMPILER(MSVC)
46 #include <intrin.h>
47 #endif
48
45 namespace WTF { 49 namespace WTF {
46 50
47 #if COMPILER(GCC) 51 #if COMPILER(MSVC)
52
53 ALWAYS_INLINE uint32_t countLeadingZeros32(uint32_t x)
54 {
55 unsigned long index;
56 return LIKELY(_BitScanReverse(&index, x)) ? (31 - index) : 32;
57 }
58
59 #if CPU(64BIT)
60
61 // MSVC only supplies _BitScanForward64 when building for a 64-bit target.
62 ALWAYS_INLINE uint64_t countLeadingZeros64(uint64_t x)
63 {
64 unsigned long index;
65 return LIKELY(_BitScanReverse64(&index, x)) ? (63 - index) : 64;
66 }
67
68 #endif
69
70 #elif COMPILER(GCC)
48 71
49 // This is very annoying. __builtin_clz has undefined behaviour for an input of 72 // This is very annoying. __builtin_clz has undefined behaviour for an input of
50 // 0, even though these's clearly a return value that makes sense, and even 73 // 0, even though these's clearly a return value that makes sense, and even
51 // though nascent processor clz instructions have defined behaviour for 0. 74 // though nascent processor clz instructions have defined behaviour for 0.
52 // We could drop to raw __asm__ to do better, but we'll avoid doing that unless 75 // We could drop to raw __asm__ to do better, but we'll avoid doing that unless
53 // we see proof that we need to. 76 // we see proof that we need to.
54 ALWAYS_INLINE uint32_t countLeadingZeros32(uint32_t x) 77 ALWAYS_INLINE uint32_t countLeadingZeros32(uint32_t x)
55 { 78 {
56 return LIKELY(x) ? __builtin_clz(x) : 32; 79 return LIKELY(x) ? __builtin_clz(x) : 32;
57 } 80 }
(...skipping 11 matching lines...) Expand all
69 92
70 #else 93 #else
71 94
72 ALWAYS_INLINE size_t countLeadingZerosSizet(size_t x) { return countLeadingZeros 32(x); } 95 ALWAYS_INLINE size_t countLeadingZerosSizet(size_t x) { return countLeadingZeros 32(x); }
73 96
74 #endif 97 #endif
75 98
76 } // namespace WTF 99 } // namespace WTF
77 100
78 #endif // WTF_BitwiseOperations_h 101 #endif // WTF_BitwiseOperations_h
OLDNEW
« no previous file with comments | « sky/engine/wtf/BUILD.gn ('k') | sky/engine/wtf/ByteSwap.h » ('j') | sky/engine/wtf/Compiler.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698