Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
lerp-study.cpp File Reference
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include "experimental/lowp-basic/QMath.h"

Go to the source code of this file.

Classes

struct  Stats
 

Functions

static float golden_lerp (float t, int16_t a, int16_t b)
 
template<int logPixelScale>
static int16_t saturating_lerp (float t, int16_t a, int16_t b)
 
template<int logPixelScale>
static int16_t ssse3_lerp (float t, int16_t a, int16_t b)
 
static int16_t full_res_lerp (float t, int16_t a, int16_t b)
 
template<int logPixelScale>
static int16_t balanced_lerp (float t, int16_t a, int16_t b)
 
template<typename Lerp >
static Stats check_lerp (Lerp lerp)
 
int main ()
 

Function Documentation

◆ balanced_lerp()

template<int logPixelScale>
static int16_t balanced_lerp ( float  t,
int16_t  a,
int16_t  b 
)
static

Definition at line 72 of file lerp-study.cpp.

72 {
73 const int16_t half = 1 << logPixelScale;
74 // t on [-1, 1).
75 Q15 qt (floor(t * 65536.0f - 32768.0f + 0.5f));
76 // need to pick logPixelScale to scale by addition 1/2.
77 Q15 qw ((b - a) << logPixelScale);
78 Q15 qm ((a + b) << logPixelScale);
79 Q15 answer = simulate_ssse3_mm_mulhrs_epi16(qt, qw) + qm;
80 // Extra shift to divide by 2.
81 return (answer[0] + half) >> (logPixelScale + 1);
82}
static I16 simulate_ssse3_mm_mulhrs_epi16(I16 a, I16 b)
Definition QMath.h:44
static bool b
struct MyStruct a[10]
V< 8, uint16_t > Q15
SIN Vec< N, float > floor(const Vec< N, float > &x)
Definition SkVx.h:703

◆ check_lerp()

template<typename Lerp >
static Stats check_lerp ( Lerp  lerp)
static

Definition at line 85 of file lerp-study.cpp.

85 {
87 for (float t = 0; t < 1.0f - 1.0f / 65536.0f ; t += 1.0f/65536.0f)
88 for (int a = 255; a >= 0; a--)
89 for (int b = 255; b >= 0; b--) {
90 float l = golden_lerp(t, a, b);
91 int16_t golden = floor(l + 0.5f);
92 int16_t candidate = lerp(t, a, b);
93 stats.log(golden, candidate);
94 }
95 return stats;
96}
static float golden_lerp(float t, int16_t a, int16_t b)
dict stats
Definition malisc.py:20
static SkPoint lerp(const SkPoint &a, const SkPoint &b, float T)

◆ full_res_lerp()

static int16_t full_res_lerp ( float  t,
int16_t  a,
int16_t  b 
)
static

Definition at line 62 of file lerp-study.cpp.

62 {
63 int32_t ft(floor(t * 65536.0f + 0.5f));
64
65 int32_t temp = ft * (b - a) + a * 65536;
66 int32_t rounded = temp + 32768;
67 return rounded >> 16;
68}

◆ golden_lerp()

static float golden_lerp ( float  t,
int16_t  a,
int16_t  b 
)
static

Definition at line 36 of file lerp-study.cpp.

36 {
37 return (1.0f - t) * a + t * b;
38}

◆ main()

int main ( )

Definition at line 98 of file lerp-study.cpp.

98 {
100
101 printf("\nUsing full_res_lerp...\n");
103 stats.print();
104
105 printf("\nUsing vqrdmulhq_s16...\n");
106 stats = check_lerp(saturating_lerp<7>);
107 stats.print();
108
109 printf("\nUsing mm_mulhrs_epi16...\n");
110 stats = check_lerp(ssse3_lerp<7>);
111 stats.print();
112
113 printf("\nInterval [-1, 1) mm_mulhrs_epi16...\n");
114 stats = check_lerp(balanced_lerp<7>);
115 stats.print();
116
117 printf("Done.");
118 return 0;
119}
static int16_t full_res_lerp(float t, int16_t a, int16_t b)
static Stats check_lerp(Lerp lerp)
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1

◆ saturating_lerp()

template<int logPixelScale>
static int16_t saturating_lerp ( float  t,
int16_t  a,
int16_t  b 
)
static

Definition at line 41 of file lerp-study.cpp.

41 {
42 const int16_t half = 1 << (logPixelScale - 1);
43 Q15 qt(floor(t * 32768.f + 0.5f));
44 Q15 qa(a << logPixelScale);
45 Q15 qb(b << logPixelScale);
46
47 Q15 answer = simulate_neon_vqrdmulhq_s16(qt, qb - qa) + qa;
48 return (answer[0] + half) >> logPixelScale;
49}
static Q15 simulate_neon_vqrdmulhq_s16(Q15 a, Q15 b)
Definition QMath.h:58

◆ ssse3_lerp()

template<int logPixelScale>
static int16_t ssse3_lerp ( float  t,
int16_t  a,
int16_t  b 
)
static

Definition at line 52 of file lerp-study.cpp.

52 {
53 const int16_t half = 1 << (logPixelScale - 1);
54 Q15 qt(floor(t * 32768.f + 0.5f));
55 Q15 qa(a << logPixelScale);
56 Q15 qb(b << logPixelScale);
57
58 Q15 answer = simulate_ssse3_mm_mulhrs_epi16(qt, qb - qa) + qa;
59 return (answer[0] + half) >> logPixelScale;
60}