| OLD | NEW |
| 1 // Copyright 2013 Google Inc. All Rights Reserved. | 1 // Copyright 2013 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 // | 14 // |
| 15 // Helper function for bit twiddling and macros for branch prediction. | 15 // Helper function for bit twiddling and macros for branch prediction. |
| 16 | 16 |
| 17 #ifndef WOFF2_PORT_H_ | 17 #ifndef WOFF2_PORT_H_ |
| 18 #define WOFF2_PORT_H_ | 18 #define WOFF2_PORT_H_ |
| 19 | 19 |
| 20 #include <assert.h> |
| 21 |
| 20 namespace woff2 { | 22 namespace woff2 { |
| 21 | 23 |
| 22 typedef unsigned int uint32; | 24 typedef unsigned int uint32; |
| 23 | 25 |
| 24 inline int Log2Floor(uint32 n) { | 26 inline int Log2Floor(uint32 n) { |
| 25 #if defined(__GNUC__) | 27 #if defined(__GNUC__) |
| 26 return n == 0 ? -1 : 31 ^ __builtin_clz(n); | 28 return n == 0 ? -1 : 31 ^ __builtin_clz(n); |
| 27 #else | 29 #else |
| 28 if (n == 0) | 30 if (n == 0) |
| 29 return -1; | 31 return -1; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 52 #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ > 95) || \ | 54 #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ > 95) || \ |
| 53 (defined(__llvm__) && __has_builtin(__builtin_expect)) | 55 (defined(__llvm__) && __has_builtin(__builtin_expect)) |
| 54 #define PREDICT_FALSE(x) (__builtin_expect(x, 0)) | 56 #define PREDICT_FALSE(x) (__builtin_expect(x, 0)) |
| 55 #define PREDICT_TRUE(x) (__builtin_expect(!!(x), 1)) | 57 #define PREDICT_TRUE(x) (__builtin_expect(!!(x), 1)) |
| 56 #else | 58 #else |
| 57 #define PREDICT_FALSE(x) (x) | 59 #define PREDICT_FALSE(x) (x) |
| 58 #define PREDICT_TRUE(x) (x) | 60 #define PREDICT_TRUE(x) (x) |
| 59 #endif | 61 #endif |
| 60 | 62 |
| 61 #endif // WOFF2_PORT_H_ | 63 #endif // WOFF2_PORT_H_ |
| OLD | NEW |