Mike Klein | b5f95cd | 2019-07-02 14:16:26 -0500 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019 Google LLC |
| 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 | |
| 8 | #include "src/core/SkCpu.h" |
| 9 | #include "src/core/SkVM.h" |
| 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> |
| 12 | |
| 13 | void sk_abort_no_print() { |
| 14 | abort(); |
| 15 | } |
| 16 | |
| 17 | void SkDebugf(const char* fmt, ...) { |
| 18 | va_list args; |
| 19 | va_start(args, fmt); |
| 20 | vfprintf(stderr, fmt, args); |
| 21 | va_end(args); |
| 22 | } |
| 23 | |
| 24 | // TODO: remove SkVM dependency on SkWStream |
| 25 | bool SkWStream::writeDecAsText (int x) { SkDebugf("%d", x); return true; } |
| 26 | bool SkWStream::writeHexAsText (unsigned x, int) { SkDebugf("%x", x); return true; } |
| 27 | bool SkWStream::writeScalarAsText(float x) { SkDebugf("%g", x); return true; } |
| 28 | |
| 29 | using namespace skvm; |
| 30 | |
| 31 | static Program build() { |
| 32 | Builder b; |
| 33 | |
| 34 | Arg ptr = b.arg(0); |
| 35 | I32 v = b.load32(ptr); |
| 36 | b.store32(ptr, b.mul(v,v)); |
| 37 | |
| 38 | return b.done(); |
| 39 | } |
| 40 | |
| 41 | int main(int argc, char** argv) { |
| 42 | #if defined(__x86_64__) |
| 43 | SkCpu::CacheRuntimeFeatures(); |
| 44 | #endif |
| 45 | int loops = argc > 1 ? atoi(argv[1]) |
| 46 | : 1; |
| 47 | |
| 48 | if (loops < 0) { |
| 49 | // Benchmark program build and JIT. |
| 50 | loops = -loops; |
| 51 | while (loops --> 0) { |
| 52 | Program program = build(); |
| 53 | int x = 4; |
| 54 | program.eval(0, &x); |
| 55 | } |
| 56 | } else { |
| 57 | // Benchmark JIT code. |
| 58 | Program program = build(); |
| 59 | |
| 60 | int buf[4096]; |
| 61 | for (int i = 0; i < 4096; i++) { |
| 62 | buf[i] = 1; |
| 63 | } |
| 64 | |
| 65 | while (loops --> 0) { |
| 66 | program.eval(4096, buf); |
| 67 | } |
| 68 | } |
| 69 | return 0; |
| 70 | } |