blob: b9cb5a1d9ea7149caa0d04be3c12a2783eebd095 [file] [log] [blame]
Mike Kleind0ce1482017-04-19 17:19:30 -04001/*
2 * Copyright 2017 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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/core/SkRasterPipeline.h"
9#include "tests/Test.h"
Mike Kleind0ce1482017-04-19 17:19:30 -040010
11DEF_TEST(F16Stages, r) {
12 // Make sure SkRasterPipeline::load_f16 and store_f16 can handle a range of
13 // ordinary (0<=x<=1) and interesting (x<0, x>1) values.
14 float floats[16] = {
15 0.0f, 0.25f, 0.5f, 1.0f,
16 -1.25f, -0.5f, 1.25f, 2.0f,
17 0,0,0,0, 0,0,0,0, // pad a bit to make sure we qualify for platform-specific code
18 };
Mike Kleinde161cb2018-01-19 16:23:25 -050019 uint64_t halfs[4] = {0,0,0,0};
Mike Kleind0ce1482017-04-19 17:19:30 -040020
Mike Kleinb11ab572018-10-24 06:42:14 -040021 SkRasterPipeline_MemoryCtx f32 = { floats, 0 },
22 f16 = { halfs, 0 };
Mike Kleind0ce1482017-04-19 17:19:30 -040023
24 {
Mike Kleinb24704d2017-05-24 07:53:00 -040025 SkRasterPipeline_<256> p;
Mike Kleind0ce1482017-04-19 17:19:30 -040026 p.append(SkRasterPipeline:: load_f32, &f32);
27 p.append(SkRasterPipeline::store_f16, &f16);
Mike Klein45c16fa2017-07-18 18:15:13 -040028 p.run(0,0,16/4,1);
Mike Kleind0ce1482017-04-19 17:19:30 -040029 }
Mike Kleinde161cb2018-01-19 16:23:25 -050030 REPORTER_ASSERT(r, ((halfs[0] >> 0) & 0xffff) == 0x0000);
31 REPORTER_ASSERT(r, ((halfs[0] >> 16) & 0xffff) == 0x3400);
32 REPORTER_ASSERT(r, ((halfs[0] >> 32) & 0xffff) == 0x3800);
33 REPORTER_ASSERT(r, ((halfs[0] >> 48) & 0xffff) == 0x3c00);
34 REPORTER_ASSERT(r, ((halfs[1] >> 0) & 0xffff) == 0xbd00);
35 REPORTER_ASSERT(r, ((halfs[1] >> 16) & 0xffff) == 0xb800);
36 REPORTER_ASSERT(r, ((halfs[1] >> 32) & 0xffff) == 0x3d00);
37 REPORTER_ASSERT(r, ((halfs[1] >> 48) & 0xffff) == 0x4000);
Mike Kleind0ce1482017-04-19 17:19:30 -040038
39 {
Mike Kleinb24704d2017-05-24 07:53:00 -040040 SkRasterPipeline_<256> p;
Mike Kleind0ce1482017-04-19 17:19:30 -040041 p.append(SkRasterPipeline:: load_f16, &f16);
42 p.append(SkRasterPipeline::store_f32, &f32);
Mike Klein45c16fa2017-07-18 18:15:13 -040043 p.run(0,0,16/4,1);
Mike Kleind0ce1482017-04-19 17:19:30 -040044 }
Mike Klein45c16fa2017-07-18 18:15:13 -040045 REPORTER_ASSERT(r, floats[0] == 0.00f);
46 REPORTER_ASSERT(r, floats[1] == 0.25f);
47 REPORTER_ASSERT(r, floats[2] == 0.50f);
48 REPORTER_ASSERT(r, floats[3] == 1.00f);
49 REPORTER_ASSERT(r, floats[4] == -1.25f);
50 REPORTER_ASSERT(r, floats[5] == -0.50f);
51 REPORTER_ASSERT(r, floats[6] == 1.25f);
52 REPORTER_ASSERT(r, floats[7] == 2.00f);
Mike Kleind0ce1482017-04-19 17:19:30 -040053}