blob: e10492977c8dd58d4fecb5cd67392b1eb8c631d7 [file] [log] [blame]
Mike Kleinb5f95cd2019-07-02 14:16:26 -05001/*
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
13void sk_abort_no_print() {
14 abort();
15}
16
17void 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
25bool SkWStream::writeDecAsText (int x) { SkDebugf("%d", x); return true; }
26bool SkWStream::writeHexAsText (unsigned x, int) { SkDebugf("%x", x); return true; }
27bool SkWStream::writeScalarAsText(float x) { SkDebugf("%g", x); return true; }
28
29using namespace skvm;
30
31static 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
41int 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}