Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 1 | // Copyright 2020 Google LLC. |
Mike Klein | a67d1ae | 2020-03-09 17:36:00 -0500 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 3 | |
| 4 | #ifndef SkVM_opts_DEFINED |
| 5 | #define SkVM_opts_DEFINED |
| 6 | |
| 7 | #include "include/private/SkVx.h" |
| 8 | #include "src/core/SkVM.h" |
| 9 | |
Mike Klein | 2e69a13 | 2020-09-18 08:02:46 -0500 | [diff] [blame] | 10 | template <int N> |
| 11 | static inline skvx::Vec<N,int> gather32(const int* ptr, const skvx::Vec<N,int>& ix) { |
| 12 | #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2 |
| 13 | if constexpr (N == 8) { |
| 14 | return skvx::bit_pun<skvx::Vec<N,int>>( |
| 15 | _mm256_i32gather_epi32(ptr, skvx::bit_pun<__m256i>(ix), 4)); |
| 16 | } |
| 17 | #endif |
| 18 | // Try to recurse on specializations, falling back on standard scalar map()-based impl. |
| 19 | if constexpr (N > 8) { |
| 20 | return join(gather32(ptr, ix.lo), |
| 21 | gather32(ptr, ix.hi)); |
| 22 | } |
Mike Klein | 840e8ea | 2020-10-12 12:38:10 -0500 | [diff] [blame] | 23 | return map([&](int i) { return ptr[i]; }, ix); |
Mike Klein | 2e69a13 | 2020-09-18 08:02:46 -0500 | [diff] [blame] | 24 | } |
| 25 | |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 26 | namespace SK_OPTS_NS { |
| 27 | |
| 28 | inline void interpret_skvm(const skvm::InterpreterInstruction insts[], const int ninsts, |
| 29 | const int nregs, const int loop, |
| 30 | const int strides[], const int nargs, |
| 31 | int n, void* args[]) { |
| 32 | using namespace skvm; |
| 33 | |
| 34 | // We'll operate in SIMT style, knocking off K-size chunks from n while possible. |
Mike Klein | 51d35ed | 2020-04-24 08:16:22 -0500 | [diff] [blame] | 35 | #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2 |
Mike Klein | 394a6d5 | 2020-09-18 14:04:19 -0500 | [diff] [blame] | 36 | constexpr int K = 32; // 1024-bit: 4 ymm or 2 zmm at a time |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 37 | #else |
Mike Klein | 394a6d5 | 2020-09-18 14:04:19 -0500 | [diff] [blame] | 38 | constexpr int K = 8; // 256-bit: 2 xmm, 2 v-registers, etc. |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 39 | #endif |
| 40 | using I32 = skvx::Vec<K, int>; |
Mike Klein | 6b72d3a | 2020-09-24 11:17:22 -0500 | [diff] [blame] | 41 | using I16 = skvx::Vec<K, int16_t>; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 42 | using F32 = skvx::Vec<K, float>; |
Mike Klein | 6732da0 | 2020-07-16 13:03:18 -0500 | [diff] [blame] | 43 | using U64 = skvx::Vec<K, uint64_t>; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 44 | using U32 = skvx::Vec<K, uint32_t>; |
| 45 | using U16 = skvx::Vec<K, uint16_t>; |
| 46 | using U8 = skvx::Vec<K, uint8_t>; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 47 | union Slot { |
| 48 | F32 f32; |
| 49 | I32 i32; |
| 50 | U32 u32; |
Mike Klein | 6b72d3a | 2020-09-24 11:17:22 -0500 | [diff] [blame] | 51 | I16 i16; |
| 52 | U16 u16; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | Slot few_regs[16]; |
| 56 | std::unique_ptr<char[]> many_regs; |
| 57 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 58 | Slot* r = few_regs; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 59 | |
| 60 | if (nregs > (int)SK_ARRAY_COUNT(few_regs)) { |
| 61 | // Annoyingly we can't trust that malloc() or new will work with Slot because |
| 62 | // the skvx::Vec types may have alignment greater than what they provide. |
| 63 | // We'll overallocate one extra register so we can align manually. |
| 64 | many_regs.reset(new char[ sizeof(Slot) * (nregs + 1) ]); |
| 65 | |
| 66 | uintptr_t addr = (uintptr_t)many_regs.get(); |
| 67 | addr += alignof(Slot) - |
| 68 | (addr & (alignof(Slot) - 1)); |
| 69 | SkASSERT((addr & (alignof(Slot) - 1)) == 0); |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 70 | r = (Slot*)addr; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 74 | // Step each argument pointer ahead by its stride a number of times. |
| 75 | auto step_args = [&](int times) { |
| 76 | for (int i = 0; i < nargs; i++) { |
| 77 | args[i] = (void*)( (char*)args[i] + times * strides[i] ); |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | int start = 0, |
| 82 | stride; |
| 83 | for ( ; n > 0; start = loop, n -= stride, step_args(stride)) { |
| 84 | stride = n >= K ? K : 1; |
| 85 | |
| 86 | for (int i = start; i < ninsts; i++) { |
| 87 | InterpreterInstruction inst = insts[i]; |
| 88 | |
Mike Klein | f3087d8 | 2021-01-19 11:36:25 -0600 | [diff] [blame^] | 89 | // d = op(x,y,z,w, immA,immB) |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 90 | Reg d = inst.d, |
| 91 | x = inst.x, |
| 92 | y = inst.y, |
Mike Klein | f3087d8 | 2021-01-19 11:36:25 -0600 | [diff] [blame^] | 93 | z = inst.z, |
| 94 | w = inst.w; |
| 95 | (void)w; // TODO: use in store128 |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 96 | int immA = inst.immA, |
| 97 | immB = inst.immB; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 98 | |
| 99 | // Ops that interact with memory need to know whether we're stride=1 or K, |
| 100 | // but all non-memory ops can run the same code no matter the stride. |
| 101 | switch (2*(int)inst.op + (stride == K ? 1 : 0)) { |
| 102 | default: SkUNREACHABLE; |
| 103 | |
| 104 | #define STRIDE_1(op) case 2*(int)op |
| 105 | #define STRIDE_K(op) case 2*(int)op + 1 |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 106 | STRIDE_1(Op::store8 ): memcpy(args[immA], &r[x].i32, 1); break; |
| 107 | STRIDE_1(Op::store16): memcpy(args[immA], &r[x].i32, 2); break; |
| 108 | STRIDE_1(Op::store32): memcpy(args[immA], &r[x].i32, 4); break; |
| 109 | STRIDE_1(Op::store64): memcpy((char*)args[immA]+0, &r[x].i32, 4); |
| 110 | memcpy((char*)args[immA]+4, &r[y].i32, 4); break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 111 | |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 112 | STRIDE_K(Op::store8 ): skvx::cast<uint8_t> (r[x].i32).store(args[immA]); break; |
| 113 | STRIDE_K(Op::store16): skvx::cast<uint16_t>(r[x].i32).store(args[immA]); break; |
| 114 | STRIDE_K(Op::store32): (r[x].i32).store(args[immA]); break; |
Mike Klein | 6732da0 | 2020-07-16 13:03:18 -0500 | [diff] [blame] | 115 | STRIDE_K(Op::store64): (skvx::cast<uint64_t>(r[x].u32) << 0 | |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 116 | skvx::cast<uint64_t>(r[y].u32) << 32).store(args[immA]); |
Mike Klein | 6732da0 | 2020-07-16 13:03:18 -0500 | [diff] [blame] | 117 | break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 118 | |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 119 | STRIDE_1(Op::load8 ): r[d].i32 = 0; memcpy(&r[d].i32, args[immA], 1); break; |
| 120 | STRIDE_1(Op::load16): r[d].i32 = 0; memcpy(&r[d].i32, args[immA], 2); break; |
| 121 | STRIDE_1(Op::load32): r[d].i32 = 0; memcpy(&r[d].i32, args[immA], 4); break; |
Mike Klein | 3136789 | 2020-07-30 08:19:12 -0500 | [diff] [blame] | 122 | STRIDE_1(Op::load64): |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 123 | r[d].i32 = 0; memcpy(&r[d].i32, (char*)args[immA] + 4*immB, 4); break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 124 | |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 125 | STRIDE_K(Op::load8 ): r[d].i32= skvx::cast<int>(U8 ::Load(args[immA])); break; |
| 126 | STRIDE_K(Op::load16): r[d].i32= skvx::cast<int>(U16::Load(args[immA])); break; |
| 127 | STRIDE_K(Op::load32): r[d].i32= I32::Load(args[immA]) ; break; |
Mike Klein | 3136789 | 2020-07-30 08:19:12 -0500 | [diff] [blame] | 128 | STRIDE_K(Op::load64): |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 129 | // Low 32 bits if immB=0, or high 32 bits if immB=1. |
| 130 | r[d].i32 = skvx::cast<int>(U64::Load(args[immA]) >> (32*immB)); break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 131 | |
| 132 | // The pointer we base our gather on is loaded indirectly from a uniform: |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 133 | // - args[immA] is the uniform holding our gather base pointer somewhere; |
| 134 | // - (const uint8_t*)args[immA] + immB points to the gather base pointer; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 135 | // - memcpy() loads the gather base and into a pointer of the right type. |
| 136 | // After all that we have an ordinary (uniform) pointer `ptr` to load from, |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 137 | // and we then gather from it using the varying indices in r[x]. |
Mike Klein | feb4d10 | 2020-09-17 08:54:08 -0500 | [diff] [blame] | 138 | STRIDE_1(Op::gather8): { |
| 139 | const uint8_t* ptr; |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 140 | memcpy(&ptr, (const uint8_t*)args[immA] + immB, sizeof(ptr)); |
Mike Klein | feb4d10 | 2020-09-17 08:54:08 -0500 | [diff] [blame] | 141 | r[d].i32 = ptr[ r[x].i32[0] ]; |
| 142 | } break; |
| 143 | STRIDE_1(Op::gather16): { |
| 144 | const uint16_t* ptr; |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 145 | memcpy(&ptr, (const uint8_t*)args[immA] + immB, sizeof(ptr)); |
Mike Klein | feb4d10 | 2020-09-17 08:54:08 -0500 | [diff] [blame] | 146 | r[d].i32 = ptr[ r[x].i32[0] ]; |
| 147 | } break; |
| 148 | STRIDE_1(Op::gather32): { |
| 149 | const int* ptr; |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 150 | memcpy(&ptr, (const uint8_t*)args[immA] + immB, sizeof(ptr)); |
Mike Klein | feb4d10 | 2020-09-17 08:54:08 -0500 | [diff] [blame] | 151 | r[d].i32 = ptr[ r[x].i32[0] ]; |
| 152 | } break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 153 | |
Mike Klein | feb4d10 | 2020-09-17 08:54:08 -0500 | [diff] [blame] | 154 | STRIDE_K(Op::gather8): { |
| 155 | const uint8_t* ptr; |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 156 | memcpy(&ptr, (const uint8_t*)args[immA] + immB, sizeof(ptr)); |
Mike Klein | 840e8ea | 2020-10-12 12:38:10 -0500 | [diff] [blame] | 157 | r[d].i32 = map([&](int ix) { return (int)ptr[ix]; }, r[x].i32); |
Mike Klein | feb4d10 | 2020-09-17 08:54:08 -0500 | [diff] [blame] | 158 | } break; |
| 159 | STRIDE_K(Op::gather16): { |
| 160 | const uint16_t* ptr; |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 161 | memcpy(&ptr, (const uint8_t*)args[immA] + immB, sizeof(ptr)); |
Mike Klein | 840e8ea | 2020-10-12 12:38:10 -0500 | [diff] [blame] | 162 | r[d].i32 = map([&](int ix) { return (int)ptr[ix]; }, r[x].i32); |
Mike Klein | feb4d10 | 2020-09-17 08:54:08 -0500 | [diff] [blame] | 163 | } break; |
| 164 | STRIDE_K(Op::gather32): { |
| 165 | const int* ptr; |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 166 | memcpy(&ptr, (const uint8_t*)args[immA] + immB, sizeof(ptr)); |
Mike Klein | 2e69a13 | 2020-09-18 08:02:46 -0500 | [diff] [blame] | 167 | r[d].i32 = gather32(ptr, r[x].i32); |
Mike Klein | feb4d10 | 2020-09-17 08:54:08 -0500 | [diff] [blame] | 168 | } break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 169 | |
| 170 | #undef STRIDE_1 |
| 171 | #undef STRIDE_K |
| 172 | |
| 173 | // Ops that don't interact with memory should never care about the stride. |
| 174 | #define CASE(op) case 2*(int)op: /*fallthrough*/ case 2*(int)op+1 |
| 175 | |
Mike Klein | 89b3c1f | 2020-07-29 16:45:05 -0500 | [diff] [blame] | 176 | // These 128-bit ops are implemented serially for simplicity. |
Mike Klein | 3136789 | 2020-07-30 08:19:12 -0500 | [diff] [blame] | 177 | CASE(Op::store128): { |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 178 | int ptr = immA, |
| 179 | lane = immB; |
Mike Klein | 89b3c1f | 2020-07-29 16:45:05 -0500 | [diff] [blame] | 180 | U64 src = (skvx::cast<uint64_t>(r[x].u32) << 0 | |
| 181 | skvx::cast<uint64_t>(r[y].u32) << 32); |
| 182 | for (int i = 0; i < stride; i++) { |
Mike Klein | 3136789 | 2020-07-30 08:19:12 -0500 | [diff] [blame] | 183 | memcpy((char*)args[ptr] + 16*i + 8*lane, &src[i], 8); |
Mike Klein | 89b3c1f | 2020-07-29 16:45:05 -0500 | [diff] [blame] | 184 | } |
| 185 | } break; |
| 186 | |
Mike Klein | 3136789 | 2020-07-30 08:19:12 -0500 | [diff] [blame] | 187 | CASE(Op::load128): |
Mike Klein | 89b3c1f | 2020-07-29 16:45:05 -0500 | [diff] [blame] | 188 | r[d].i32 = 0; |
| 189 | for (int i = 0; i < stride; i++) { |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 190 | memcpy(&r[d].i32[i], (const char*)args[immA] + 16*i+ 4*immB, 4); |
Mike Klein | 89b3c1f | 2020-07-29 16:45:05 -0500 | [diff] [blame] | 191 | } break; |
| 192 | |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 193 | CASE(Op::assert_true): |
| 194 | #ifdef SK_DEBUG |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 195 | if (!all(r[x].i32)) { |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 196 | SkDebugf("inst %d, register %d\n", i, y); |
| 197 | for (int i = 0; i < K; i++) { |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 198 | SkDebugf("\t%2d: %08x (%g)\n", i, r[y].i32[i], r[y].f32[i]); |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 199 | } |
Mike Klein | 51a7f95 | 2020-09-16 16:00:33 -0500 | [diff] [blame] | 200 | SkASSERT(false); |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 201 | } |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 202 | #endif |
| 203 | break; |
| 204 | |
| 205 | CASE(Op::index): { |
| 206 | const int iota[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15, |
Mike Klein | 394a6d5 | 2020-09-18 14:04:19 -0500 | [diff] [blame] | 207 | 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, |
| 208 | 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, |
| 209 | 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63 }; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 210 | static_assert(K <= SK_ARRAY_COUNT(iota), ""); |
| 211 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 212 | r[d].i32 = n - I32::Load(iota); |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 213 | } break; |
| 214 | |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 215 | CASE(Op::uniform32): |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 216 | r[d].i32 = *(const int*)( (const char*)args[immA] + immB ); |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 217 | break; |
| 218 | |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 219 | CASE(Op::splat): r[d].i32 = immA; break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 220 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 221 | CASE(Op::add_f32): r[d].f32 = r[x].f32 + r[y].f32; break; |
| 222 | CASE(Op::sub_f32): r[d].f32 = r[x].f32 - r[y].f32; break; |
| 223 | CASE(Op::mul_f32): r[d].f32 = r[x].f32 * r[y].f32; break; |
| 224 | CASE(Op::div_f32): r[d].f32 = r[x].f32 / r[y].f32; break; |
| 225 | CASE(Op::min_f32): r[d].f32 = min(r[x].f32, r[y].f32); break; |
| 226 | CASE(Op::max_f32): r[d].f32 = max(r[x].f32, r[y].f32); break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 227 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 228 | CASE(Op::fma_f32): r[d].f32 = fma( r[x].f32, r[y].f32, r[z].f32); break; |
| 229 | CASE(Op::fms_f32): r[d].f32 = fma( r[x].f32, r[y].f32, -r[z].f32); break; |
| 230 | CASE(Op::fnma_f32): r[d].f32 = fma(-r[x].f32, r[y].f32, r[z].f32); break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 231 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 232 | CASE(Op::sqrt_f32): r[d].f32 = sqrt(r[x].f32); break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 233 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 234 | CASE(Op::add_i32): r[d].i32 = r[x].i32 + r[y].i32; break; |
| 235 | CASE(Op::sub_i32): r[d].i32 = r[x].i32 - r[y].i32; break; |
| 236 | CASE(Op::mul_i32): r[d].i32 = r[x].i32 * r[y].i32; break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 237 | |
Mike Klein | aad9719 | 2021-01-19 11:04:37 -0600 | [diff] [blame] | 238 | CASE(Op::shl_i32): r[d].i32 = r[x].i32 << immA; break; |
| 239 | CASE(Op::sra_i32): r[d].i32 = r[x].i32 >> immA; break; |
| 240 | CASE(Op::shr_i32): r[d].u32 = r[x].u32 >> immA; break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 241 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 242 | CASE(Op:: eq_f32): r[d].i32 = r[x].f32 == r[y].f32; break; |
| 243 | CASE(Op::neq_f32): r[d].i32 = r[x].f32 != r[y].f32; break; |
| 244 | CASE(Op:: gt_f32): r[d].i32 = r[x].f32 > r[y].f32; break; |
| 245 | CASE(Op::gte_f32): r[d].i32 = r[x].f32 >= r[y].f32; break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 246 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 247 | CASE(Op:: eq_i32): r[d].i32 = r[x].i32 == r[y].i32; break; |
| 248 | CASE(Op:: gt_i32): r[d].i32 = r[x].i32 > r[y].i32; break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 249 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 250 | CASE(Op::bit_and ): r[d].i32 = r[x].i32 & r[y].i32; break; |
| 251 | CASE(Op::bit_or ): r[d].i32 = r[x].i32 | r[y].i32; break; |
| 252 | CASE(Op::bit_xor ): r[d].i32 = r[x].i32 ^ r[y].i32; break; |
| 253 | CASE(Op::bit_clear): r[d].i32 = r[x].i32 & ~r[y].i32; break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 254 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 255 | CASE(Op::select): r[d].i32 = skvx::if_then_else(r[x].i32, r[y].i32, r[z].i32); |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 256 | break; |
| 257 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 258 | CASE(Op::ceil): r[d].f32 = skvx::ceil(r[x].f32) ; break; |
| 259 | CASE(Op::floor): r[d].f32 = skvx::floor(r[x].f32) ; break; |
| 260 | CASE(Op::to_f32): r[d].f32 = skvx::cast<float>( r[x].i32 ); break; |
| 261 | CASE(Op::trunc): r[d].i32 = skvx::cast<int> ( r[x].f32 ); break; |
| 262 | CASE(Op::round): r[d].i32 = skvx::cast<int> (skvx::lrint(r[x].f32)); break; |
Mike Klein | 4d680cd | 2020-07-15 09:58:51 -0500 | [diff] [blame] | 263 | |
Mike Klein | 42d67a6 | 2020-12-01 10:14:55 -0600 | [diff] [blame] | 264 | CASE(Op::to_fp16): |
Mike Klein | 4d680cd | 2020-07-15 09:58:51 -0500 | [diff] [blame] | 265 | r[d].i32 = skvx::cast<int>(skvx::to_half(r[x].f32)); |
| 266 | break; |
Mike Klein | 42d67a6 | 2020-12-01 10:14:55 -0600 | [diff] [blame] | 267 | CASE(Op::from_fp16): |
Mike Klein | 4d680cd | 2020-07-15 09:58:51 -0500 | [diff] [blame] | 268 | r[d].f32 = skvx::from_half(skvx::cast<uint16_t>(r[x].i32)); |
| 269 | break; |
Mike Klein | 98c512c | 2020-09-15 10:00:27 -0500 | [diff] [blame] | 270 | |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 271 | #undef CASE |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | } |
| 276 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 277 | } // namespace SK_OPTS_NS |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 278 | |
| 279 | #endif//SkVM_opts_DEFINED |