Use iterator adapters in decl_class_parents
[hiphop-php.git] / hphp / util / cycles.h
blob5fa6be83ce04e33fd92b1a18124020c91655e10a
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #pragma once
19 #include <folly/portability/Asm.h>
21 #include "hphp/util/assertions.h"
22 #ifdef _MSC_VER
23 #include <intrin.h>
24 #endif
26 namespace HPHP {
29 * Return the underlying machine cycle counter. While this is slightly
30 * non-portable in theory, all the CPUs you're likely to care about support
31 * it in some way or another.
33 inline uint64_t cpuCycles() {
34 #ifdef __x86_64__
35 uint64_t lo, hi;
36 asm volatile("rdtsc" : "=a"((lo)),"=d"(hi));
37 return lo | (hi << 32);
38 #elif __powerpc64__
39 // This returns a time-base
40 uint64_t tb;
41 asm volatile("mfspr %0, 268" : "=r" (tb));
42 return tb;
43 #elif _MSC_VER
44 return (uint64_t)__rdtsc();
45 #elif __aarch64__
46 // FIXME: This returns the virtual timer which is not exactly
47 // the core cycles but has a different frequency.
48 uint64_t tb;
49 asm volatile("mrs %0, cntvct_el0" : "=r" (tb));
50 return tb;
51 #else
52 not_implemented();
53 #endif
56 inline void cpuRelax() {
57 folly::asm_volatile_pause();
60 inline void cycleDelay(uint32_t numCycles) {
61 auto start = cpuCycles();
62 do {
63 if (numCycles > 100) cpuRelax();
64 } while (cpuCycles() - start < numCycles);