1 /* 2 * Copyright 2022 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 * 7 * This is an experimental (and probably temporary) solution that allows 8 * to compare performance SkVM blitters vs RasterPipeline blitters. 9 * In addition to measuring performance (which is questionable) it also produces 10 * other counts (pixels, scanlines) and more detailed traces that 11 * can explain the current results (SkVM is slower) and help improve it. 12 * The entire code is hidden under build flag skia_compare_vm_vs_rp=true 13 * and will not appear at all without it. 14 */ 15 #ifndef SkCycles_DEFINED 16 #define SkCycles_DEFINED 17 #include <cstdint> 18 #include <x86intrin.h> 19 class SkCycles { 20 public: Now()21 static uint64_t Now() { 22 #ifndef SKIA_COMPARE_VM_VS_RP 23 { 24 return 0ul; 25 } 26 #elif defined(SK_BUILD_FOR_WIN) 27 { 28 return 0ul; 29 } 30 #elif defined(SK_BUILD_FOR_IOS) 31 { 32 return 0ul; 33 } 34 #elif defined(SK_BUILD_FOR_ANDROID) 35 { 36 return 0ul; 37 } 38 #elif defined(SK_CPU_X86) 39 { 40 unsigned aux; 41 return __rdtscp(&aux); 42 } 43 #elif defined(SK_CPU_ARM64) 44 { 45 int64_t cycles; 46 asm volatile("mrs %0, cntvct_el0" : "=r"(cycles)); 47 return cycles; 48 } 49 #else 50 { 51 return 0ul; 52 } 53 #endif 54 } 55 }; 56 #endif // SkCycles_DEFINED 57