skia2/bench/HalfBench.cpp
mtklein a525cb151b skeleton for float <-> half optimized procs
Nothing fancy yet, just calls the serial code in a loop.

I will try to folow this up with at least some of:
   - SSE2 version of serial code
   - NEON version of serial code
   - NEON version using vcvt.f32.f16/vcvt.f16.f32
   - F16C (between AVX and AVX2) version using vcvtph2ps/vcvtps2ph
The last two are fastest but need runtime detection.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1686543003

Review URL: https://codereview.chromium.org/1686543003
2016-02-09 08:18:10 -08:00

49 lines
1.3 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Benchmark.h"
#include "SkOpts.h"
#include "SkRandom.h"
struct FloatToHalfBench : public Benchmark {
const char* onGetName() override { return "float_to_half"; }
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
void onDraw(int loops, SkCanvas* canvas) override {
SkRandom rand;
float fs[1023];
for (float& f : fs) {
f = rand.nextF();
}
uint16_t hs[1023];
while (loops --> 0) {
SkOpts::float_to_half(hs, fs, 1023);
}
}
};
DEF_BENCH(return new FloatToHalfBench;)
struct HalfToFloatBench : public Benchmark {
const char* onGetName() override { return "half_to_float"; }
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
void onDraw(int loops, SkCanvas* canvas) override {
SkRandom rand;
uint16_t hs[1023];
for (uint16_t& h : hs) {
h = rand.nextU16();
}
float fs[1023];
while (loops --> 0) {
SkOpts::half_to_float(fs, hs, 1023);
}
}
};
DEF_BENCH(return new HalfToFloatBench;)