aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/F16StagesTest.cpp
blob: 51cb861c89398368321fb9e1a223a34cd606e8de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkRasterPipeline.h"
#include "Test.h"

DEF_TEST(F16Stages, r) {
    // Make sure SkRasterPipeline::load_f16 and store_f16 can handle a range of
    // ordinary (0<=x<=1) and interesting (x<0, x>1) values.
    float floats[16] = {
        0.0f, 0.25f, 0.5f, 1.0f,
        -1.25f, -0.5f, 1.25f, 2.0f,
        0,0,0,0, 0,0,0,0,  // pad a bit to make sure we qualify for platform-specific code
    };
    uint16_t halfs[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};

    float*    f32 = floats;
    uint16_t* f16 = halfs;

    {
        SkRasterPipeline_<256> p;
        p.append(SkRasterPipeline:: load_f32, &f32);
        p.append(SkRasterPipeline::store_f16, &f16);
        p.run(0,0,16/4);
    }
    REPORTER_ASSERT(r, f16[0] == 0x0000);
    REPORTER_ASSERT(r, f16[1] == 0x3400);
    REPORTER_ASSERT(r, f16[2] == 0x3800);
    REPORTER_ASSERT(r, f16[3] == 0x3c00);
    REPORTER_ASSERT(r, f16[4] == 0xbd00);
    REPORTER_ASSERT(r, f16[5] == 0xb800);
    REPORTER_ASSERT(r, f16[6] == 0x3d00);
    REPORTER_ASSERT(r, f16[7] == 0x4000);

    {
        SkRasterPipeline_<256> p;
        p.append(SkRasterPipeline:: load_f16, &f16);
        p.append(SkRasterPipeline::store_f32, &f32);
        p.run(0,0,16/4);
    }
    REPORTER_ASSERT(r, f32[0] ==  0.00f);
    REPORTER_ASSERT(r, f32[1] ==  0.25f);
    REPORTER_ASSERT(r, f32[2] ==  0.50f);
    REPORTER_ASSERT(r, f32[3] ==  1.00f);
    REPORTER_ASSERT(r, f32[4] == -1.25f);
    REPORTER_ASSERT(r, f32[5] == -0.50f);
    REPORTER_ASSERT(r, f32[6] ==  1.25f);
    REPORTER_ASSERT(r, f32[7] ==  2.00f);
}