OLD | NEW |
1 // Copyright (c) 2004, Google Inc. | 1 // Copyright (c) 2004, Google Inc. |
2 // All rights reserved. | 2 // 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 #endif | 52 #endif |
53 // For MSVC, we want the __rdtsc intrinsic, declared in <intrin.h>. | 53 // For MSVC, we want the __rdtsc intrinsic, declared in <intrin.h>. |
54 // Unfortunately, in some environments, <windows.h> and <intrin.h> have | 54 // Unfortunately, in some environments, <windows.h> and <intrin.h> have |
55 // conflicting declarations of some other intrinsics, breaking compilation. | 55 // conflicting declarations of some other intrinsics, breaking compilation. |
56 // Therefore, we simply declare __rdtsc ourselves. See also | 56 // Therefore, we simply declare __rdtsc ourselves. See also |
57 // http://connect.microsoft.com/VisualStudio/feedback/details/262047 | 57 // http://connect.microsoft.com/VisualStudio/feedback/details/262047 |
58 #if defined(_MSC_VER) | 58 #if defined(_MSC_VER) |
59 extern "C" uint64 __rdtsc(); | 59 extern "C" uint64 __rdtsc(); |
60 #pragma intrinsic(__rdtsc) | 60 #pragma intrinsic(__rdtsc) |
61 #endif | 61 #endif |
| 62 #ifdef HAVE_SYS_TIME_H |
62 #include <sys/time.h> | 63 #include <sys/time.h> |
| 64 #endif |
63 | 65 |
64 // NOTE: only i386 and x86_64 have been well tested. | 66 // NOTE: only i386 and x86_64 have been well tested. |
65 // PPC, sparc, alpha, and ia64 are based on | 67 // PPC, sparc, alpha, and ia64 are based on |
66 // http://peter.kuscsik.com/wordpress/?p=14 | 68 // http://peter.kuscsik.com/wordpress/?p=14 |
67 // with modifications by m3b. See also | 69 // with modifications by m3b. See also |
68 // https://setisvn.ssl.berkeley.edu/svn/lib/fftw-3.0.1/kernel/cycle.h | 70 // https://setisvn.ssl.berkeley.edu/svn/lib/fftw-3.0.1/kernel/cycle.h |
69 struct CycleClock { | 71 struct CycleClock { |
70 // This should return the number of cycles since power-on. Thread-safe. | 72 // This should return the number of cycles since power-on. Thread-safe. |
71 static inline int64 Now() { | 73 static inline int64 Now() { |
72 #if defined(__MACH__) && defined(__APPLE__) | 74 #if defined(__MACH__) && defined(__APPLE__) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // The soft failover to a generic implementation is automatic only for ARM. | 133 // The soft failover to a generic implementation is automatic only for ARM. |
132 // For other platforms the developer is expected to make an attempt to create | 134 // For other platforms the developer is expected to make an attempt to create |
133 // a fast implementation and use generic version if nothing better is available. | 135 // a fast implementation and use generic version if nothing better is available. |
134 #error You need to define CycleTimer for your O/S and CPU | 136 #error You need to define CycleTimer for your O/S and CPU |
135 #endif | 137 #endif |
136 } | 138 } |
137 }; | 139 }; |
138 | 140 |
139 | 141 |
140 #endif // GOOGLE_BASE_CYCLECLOCK_H_ | 142 #endif // GOOGLE_BASE_CYCLECLOCK_H_ |
OLD | NEW |