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 | 6d94b65 | 2020-09-16 11:37:03 -0500 | [diff] [blame] | 10 | // Ideally this is (x*y + 0x2000)>>14, |
| 11 | // but to let use vpmulhrsw we'll approximate that as ((x*y + 0x4000)>>15)<<1. |
| 12 | template <int N> |
| 13 | static inline skvx::Vec<N,int16_t> mul_q14(const skvx::Vec<N,int16_t>& x, |
| 14 | const skvx::Vec<N,int16_t>& y) { |
| 15 | #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2 |
| 16 | if constexpr (N == 16) { |
| 17 | return skvx::bit_pun<skvx::Vec<N,int16_t>>(_mm256_mulhrs_epi16(skvx::bit_pun<__m256i>(x), |
| 18 | skvx::bit_pun<__m256i>(y))) |
| 19 | << 1; |
| 20 | } |
| 21 | #endif |
| 22 | #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 |
| 23 | if constexpr (N == 8) { |
| 24 | return skvx::bit_pun<skvx::Vec<N,int16_t>>(_mm_mulhrs_epi16(skvx::bit_pun<__m128i>(x), |
| 25 | skvx::bit_pun<__m128i>(y))) |
| 26 | << 1; |
| 27 | } |
| 28 | #endif |
| 29 | // TODO: NEON specialization with vqrdmulh.s16? |
| 30 | |
| 31 | // Try to recurse onto the specializations above. |
| 32 | if constexpr (N > 8) { |
| 33 | return join(mul_q14(x.lo, y.lo), |
| 34 | mul_q14(x.hi, y.hi)); |
| 35 | } |
| 36 | return skvx::cast<int16_t>((skvx::cast<int>(x) * |
| 37 | skvx::cast<int>(y) + 0x4000)>>15 ) <<1; |
| 38 | } |
| 39 | |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 40 | namespace SK_OPTS_NS { |
| 41 | |
| 42 | inline void interpret_skvm(const skvm::InterpreterInstruction insts[], const int ninsts, |
| 43 | const int nregs, const int loop, |
| 44 | const int strides[], const int nargs, |
| 45 | int n, void* args[]) { |
| 46 | using namespace skvm; |
| 47 | |
| 48 | // We'll operate in SIMT style, knocking off K-size chunks from n while possible. |
| 49 | // We noticed quad-pumping is slower than single-pumping and both were slower than double. |
Mike Klein | 51d35ed | 2020-04-24 08:16:22 -0500 | [diff] [blame] | 50 | #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX2 |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 51 | constexpr int K = 16; |
| 52 | #else |
| 53 | constexpr int K = 8; |
| 54 | #endif |
| 55 | using I32 = skvx::Vec<K, int>; |
| 56 | using F32 = skvx::Vec<K, float>; |
Mike Klein | 6732da0 | 2020-07-16 13:03:18 -0500 | [diff] [blame] | 57 | using U64 = skvx::Vec<K, uint64_t>; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 58 | using U32 = skvx::Vec<K, uint32_t>; |
| 59 | using U16 = skvx::Vec<K, uint16_t>; |
| 60 | using U8 = skvx::Vec<K, uint8_t>; |
| 61 | |
Mike Klein | 9791e50 | 2020-09-15 12:43:38 -0500 | [diff] [blame] | 62 | using I16x2 = skvx::Vec<2*K, int16_t>; |
| 63 | using U16x2 = skvx::Vec<2*K, uint16_t>; |
| 64 | |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 65 | union Slot { |
| 66 | F32 f32; |
| 67 | I32 i32; |
| 68 | U32 u32; |
Mike Klein | 9791e50 | 2020-09-15 12:43:38 -0500 | [diff] [blame] | 69 | I16x2 i16x2; |
| 70 | U16x2 u16x2; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | Slot few_regs[16]; |
| 74 | std::unique_ptr<char[]> many_regs; |
| 75 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 76 | Slot* r = few_regs; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 77 | |
| 78 | if (nregs > (int)SK_ARRAY_COUNT(few_regs)) { |
| 79 | // Annoyingly we can't trust that malloc() or new will work with Slot because |
| 80 | // the skvx::Vec types may have alignment greater than what they provide. |
| 81 | // We'll overallocate one extra register so we can align manually. |
| 82 | many_regs.reset(new char[ sizeof(Slot) * (nregs + 1) ]); |
| 83 | |
| 84 | uintptr_t addr = (uintptr_t)many_regs.get(); |
| 85 | addr += alignof(Slot) - |
| 86 | (addr & (alignof(Slot) - 1)); |
| 87 | SkASSERT((addr & (alignof(Slot) - 1)) == 0); |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 88 | r = (Slot*)addr; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 92 | // Step each argument pointer ahead by its stride a number of times. |
| 93 | auto step_args = [&](int times) { |
| 94 | for (int i = 0; i < nargs; i++) { |
| 95 | args[i] = (void*)( (char*)args[i] + times * strides[i] ); |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | int start = 0, |
| 100 | stride; |
| 101 | for ( ; n > 0; start = loop, n -= stride, step_args(stride)) { |
| 102 | stride = n >= K ? K : 1; |
| 103 | |
| 104 | for (int i = start; i < ninsts; i++) { |
| 105 | InterpreterInstruction inst = insts[i]; |
| 106 | |
| 107 | // d = op(x,y/imm,z/imm) |
| 108 | Reg d = inst.d, |
| 109 | x = inst.x, |
| 110 | y = inst.y, |
| 111 | z = inst.z; |
| 112 | int immy = inst.immy, |
| 113 | immz = inst.immz; |
| 114 | |
| 115 | // Ops that interact with memory need to know whether we're stride=1 or K, |
| 116 | // but all non-memory ops can run the same code no matter the stride. |
| 117 | switch (2*(int)inst.op + (stride == K ? 1 : 0)) { |
| 118 | default: SkUNREACHABLE; |
| 119 | |
| 120 | #define STRIDE_1(op) case 2*(int)op |
| 121 | #define STRIDE_K(op) case 2*(int)op + 1 |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 122 | STRIDE_1(Op::store8 ): memcpy(args[immy], &r[x].i32, 1); break; |
| 123 | STRIDE_1(Op::store16): memcpy(args[immy], &r[x].i32, 2); break; |
| 124 | STRIDE_1(Op::store32): memcpy(args[immy], &r[x].i32, 4); break; |
Mike Klein | 6732da0 | 2020-07-16 13:03:18 -0500 | [diff] [blame] | 125 | STRIDE_1(Op::store64): memcpy((char*)args[immz]+0, &r[x].i32, 4); |
| 126 | memcpy((char*)args[immz]+4, &r[y].i32, 4); break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 127 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 128 | STRIDE_K(Op::store8 ): skvx::cast<uint8_t> (r[x].i32).store(args[immy]); break; |
| 129 | STRIDE_K(Op::store16): skvx::cast<uint16_t>(r[x].i32).store(args[immy]); break; |
| 130 | STRIDE_K(Op::store32): (r[x].i32).store(args[immy]); break; |
Mike Klein | 6732da0 | 2020-07-16 13:03:18 -0500 | [diff] [blame] | 131 | STRIDE_K(Op::store64): (skvx::cast<uint64_t>(r[x].u32) << 0 | |
| 132 | skvx::cast<uint64_t>(r[y].u32) << 32).store(args[immz]); |
| 133 | break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 134 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 135 | STRIDE_1(Op::load8 ): r[d].i32 = 0; memcpy(&r[d].i32, args[immy], 1); break; |
| 136 | STRIDE_1(Op::load16): r[d].i32 = 0; memcpy(&r[d].i32, args[immy], 2); break; |
| 137 | STRIDE_1(Op::load32): r[d].i32 = 0; memcpy(&r[d].i32, args[immy], 4); break; |
Mike Klein | 3136789 | 2020-07-30 08:19:12 -0500 | [diff] [blame] | 138 | STRIDE_1(Op::load64): |
| 139 | r[d].i32 = 0; memcpy(&r[d].i32, (char*)args[immy] + 4*immz, 4); break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 140 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 141 | STRIDE_K(Op::load8 ): r[d].i32= skvx::cast<int>(U8 ::Load(args[immy])); break; |
| 142 | STRIDE_K(Op::load16): r[d].i32= skvx::cast<int>(U16::Load(args[immy])); break; |
| 143 | STRIDE_K(Op::load32): r[d].i32= I32::Load(args[immy]) ; break; |
Mike Klein | 3136789 | 2020-07-30 08:19:12 -0500 | [diff] [blame] | 144 | STRIDE_K(Op::load64): |
| 145 | // Low 32 bits if immz=0, or high 32 bits if immz=1. |
| 146 | r[d].i32 = skvx::cast<int>(U64::Load(args[immy]) >> (32*immz)); break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 147 | |
| 148 | // The pointer we base our gather on is loaded indirectly from a uniform: |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 149 | // - args[immy] is the uniform holding our gather base pointer somewhere; |
| 150 | // - (const uint8_t*)args[immy] + immz points to the gather base pointer; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 151 | // - memcpy() loads the gather base and into a pointer of the right type. |
| 152 | // 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] | 153 | // and we then gather from it using the varying indices in r[x]. |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 154 | STRIDE_1(Op::gather8): |
| 155 | for (int i = 0; i < K; i++) { |
| 156 | const uint8_t* ptr; |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 157 | memcpy(&ptr, (const uint8_t*)args[immy] + immz, sizeof(ptr)); |
| 158 | r[d].i32[i] = (i==0) ? ptr[ r[x].i32[i] ] : 0; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 159 | } break; |
| 160 | STRIDE_1(Op::gather16): |
| 161 | for (int i = 0; i < K; i++) { |
| 162 | const uint16_t* ptr; |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 163 | memcpy(&ptr, (const uint8_t*)args[immy] + immz, sizeof(ptr)); |
| 164 | r[d].i32[i] = (i==0) ? ptr[ r[x].i32[i] ] : 0; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 165 | } break; |
| 166 | STRIDE_1(Op::gather32): |
| 167 | for (int i = 0; i < K; i++) { |
| 168 | const int* ptr; |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 169 | memcpy(&ptr, (const uint8_t*)args[immy] + immz, sizeof(ptr)); |
| 170 | r[d].i32[i] = (i==0) ? ptr[ r[x].i32[i] ] : 0; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 171 | } break; |
| 172 | |
| 173 | STRIDE_K(Op::gather8): |
| 174 | for (int i = 0; i < K; i++) { |
| 175 | const uint8_t* ptr; |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 176 | memcpy(&ptr, (const uint8_t*)args[immy] + immz, sizeof(ptr)); |
| 177 | r[d].i32[i] = ptr[ r[x].i32[i] ]; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 178 | } break; |
| 179 | STRIDE_K(Op::gather16): |
| 180 | for (int i = 0; i < K; i++) { |
| 181 | const uint16_t* ptr; |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 182 | memcpy(&ptr, (const uint8_t*)args[immy] + immz, sizeof(ptr)); |
| 183 | r[d].i32[i] = ptr[ r[x].i32[i] ]; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 184 | } break; |
| 185 | STRIDE_K(Op::gather32): |
| 186 | for (int i = 0; i < K; i++) { |
| 187 | const int* ptr; |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 188 | memcpy(&ptr, (const uint8_t*)args[immy] + immz, sizeof(ptr)); |
| 189 | r[d].i32[i] = ptr[ r[x].i32[i] ]; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 190 | } break; |
| 191 | |
| 192 | #undef STRIDE_1 |
| 193 | #undef STRIDE_K |
| 194 | |
| 195 | // Ops that don't interact with memory should never care about the stride. |
| 196 | #define CASE(op) case 2*(int)op: /*fallthrough*/ case 2*(int)op+1 |
| 197 | |
Mike Klein | 89b3c1f | 2020-07-29 16:45:05 -0500 | [diff] [blame] | 198 | // These 128-bit ops are implemented serially for simplicity. |
Mike Klein | 3136789 | 2020-07-30 08:19:12 -0500 | [diff] [blame] | 199 | CASE(Op::store128): { |
| 200 | int ptr = immz>>1, |
| 201 | lane = immz&1; |
Mike Klein | 89b3c1f | 2020-07-29 16:45:05 -0500 | [diff] [blame] | 202 | U64 src = (skvx::cast<uint64_t>(r[x].u32) << 0 | |
| 203 | skvx::cast<uint64_t>(r[y].u32) << 32); |
| 204 | for (int i = 0; i < stride; i++) { |
Mike Klein | 3136789 | 2020-07-30 08:19:12 -0500 | [diff] [blame] | 205 | memcpy((char*)args[ptr] + 16*i + 8*lane, &src[i], 8); |
Mike Klein | 89b3c1f | 2020-07-29 16:45:05 -0500 | [diff] [blame] | 206 | } |
| 207 | } break; |
| 208 | |
Mike Klein | 3136789 | 2020-07-30 08:19:12 -0500 | [diff] [blame] | 209 | CASE(Op::load128): |
Mike Klein | 89b3c1f | 2020-07-29 16:45:05 -0500 | [diff] [blame] | 210 | r[d].i32 = 0; |
| 211 | for (int i = 0; i < stride; i++) { |
| 212 | memcpy(&r[d].i32[i], (const char*)args[immy] + 16*i+ 4*immz, 4); |
| 213 | } break; |
| 214 | |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 215 | CASE(Op::assert_true): |
| 216 | #ifdef SK_DEBUG |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 217 | if (!all(r[x].i32)) { |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 218 | SkDebugf("inst %d, register %d\n", i, y); |
| 219 | for (int i = 0; i < K; i++) { |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 220 | 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] | 221 | } |
Mike Klein | 51a7f95 | 2020-09-16 16:00:33 -0500 | [diff] [blame^] | 222 | SkASSERT(false); |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 223 | } |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 224 | #endif |
| 225 | break; |
| 226 | |
| 227 | CASE(Op::index): { |
| 228 | const int iota[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15, |
| 229 | 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}; |
| 230 | static_assert(K <= SK_ARRAY_COUNT(iota), ""); |
| 231 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 232 | r[d].i32 = n - I32::Load(iota); |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 233 | } break; |
| 234 | |
| 235 | CASE(Op::uniform8): |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 236 | r[d].i32 = *(const uint8_t* )( (const char*)args[immy] + immz ); |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 237 | break; |
| 238 | CASE(Op::uniform16): |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 239 | r[d].i32 = *(const uint16_t*)( (const char*)args[immy] + immz ); |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 240 | break; |
| 241 | CASE(Op::uniform32): |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 242 | r[d].i32 = *(const int* )( (const char*)args[immy] + immz ); |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 243 | break; |
| 244 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 245 | CASE(Op::splat): r[d].i32 = immy; 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::add_f32): r[d].f32 = r[x].f32 + r[y].f32; break; |
| 248 | CASE(Op::sub_f32): r[d].f32 = r[x].f32 - r[y].f32; break; |
| 249 | CASE(Op::mul_f32): r[d].f32 = r[x].f32 * r[y].f32; break; |
| 250 | CASE(Op::div_f32): r[d].f32 = r[x].f32 / r[y].f32; break; |
| 251 | CASE(Op::min_f32): r[d].f32 = min(r[x].f32, r[y].f32); break; |
| 252 | 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] | 253 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 254 | CASE(Op::fma_f32): r[d].f32 = fma( r[x].f32, r[y].f32, r[z].f32); break; |
| 255 | CASE(Op::fms_f32): r[d].f32 = fma( r[x].f32, r[y].f32, -r[z].f32); break; |
| 256 | 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] | 257 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 258 | CASE(Op::sqrt_f32): r[d].f32 = sqrt(r[x].f32); break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 259 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 260 | CASE(Op::add_i32): r[d].i32 = r[x].i32 + r[y].i32; break; |
| 261 | CASE(Op::sub_i32): r[d].i32 = r[x].i32 - r[y].i32; break; |
| 262 | 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] | 263 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 264 | CASE(Op::shl_i32): r[d].i32 = r[x].i32 << immy; break; |
| 265 | CASE(Op::sra_i32): r[d].i32 = r[x].i32 >> immy; break; |
| 266 | CASE(Op::shr_i32): r[d].u32 = r[x].u32 >> immy; break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 267 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 268 | CASE(Op:: eq_f32): r[d].i32 = r[x].f32 == r[y].f32; break; |
| 269 | CASE(Op::neq_f32): r[d].i32 = r[x].f32 != r[y].f32; break; |
| 270 | CASE(Op:: gt_f32): r[d].i32 = r[x].f32 > r[y].f32; break; |
| 271 | 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] | 272 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 273 | CASE(Op:: eq_i32): r[d].i32 = r[x].i32 == r[y].i32; break; |
| 274 | 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] | 275 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 276 | CASE(Op::bit_and ): r[d].i32 = r[x].i32 & r[y].i32; break; |
| 277 | CASE(Op::bit_or ): r[d].i32 = r[x].i32 | r[y].i32; break; |
| 278 | CASE(Op::bit_xor ): r[d].i32 = r[x].i32 ^ r[y].i32; break; |
| 279 | 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] | 280 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 281 | 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] | 282 | break; |
| 283 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 284 | CASE(Op::pack): r[d].u32 = r[x].u32 | (r[y].u32 << immz); break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 285 | |
Mike Klein | 4284f75 | 2020-07-10 15:16:17 -0500 | [diff] [blame] | 286 | CASE(Op::ceil): r[d].f32 = skvx::ceil(r[x].f32) ; break; |
| 287 | CASE(Op::floor): r[d].f32 = skvx::floor(r[x].f32) ; break; |
| 288 | CASE(Op::to_f32): r[d].f32 = skvx::cast<float>( r[x].i32 ); break; |
| 289 | CASE(Op::trunc): r[d].i32 = skvx::cast<int> ( r[x].f32 ); break; |
| 290 | 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] | 291 | |
| 292 | CASE(Op::to_half): |
| 293 | r[d].i32 = skvx::cast<int>(skvx::to_half(r[x].f32)); |
| 294 | break; |
| 295 | CASE(Op::from_half): |
| 296 | r[d].f32 = skvx::from_half(skvx::cast<uint16_t>(r[x].i32)); |
| 297 | break; |
Mike Klein | 98c512c | 2020-09-15 10:00:27 -0500 | [diff] [blame] | 298 | |
Mike Klein | 9791e50 | 2020-09-15 12:43:38 -0500 | [diff] [blame] | 299 | CASE(Op::add_q14x2): r[d].i16x2 = r[x].i16x2 + r[y].i16x2; break; |
| 300 | CASE(Op::sub_q14x2): r[d].i16x2 = r[x].i16x2 - r[y].i16x2; break; |
Mike Klein | 6d94b65 | 2020-09-16 11:37:03 -0500 | [diff] [blame] | 301 | CASE(Op::mul_q14x2): r[d].i16x2 = mul_q14(r[x].i16x2, r[y].i16x2); break; |
Mike Klein | 9791e50 | 2020-09-15 12:43:38 -0500 | [diff] [blame] | 302 | |
| 303 | CASE(Op::shl_q14x2): r[d].i16x2 = r[x].i16x2 << immy; break; |
| 304 | CASE(Op::sra_q14x2): r[d].i16x2 = r[x].i16x2 >> immy; break; |
| 305 | CASE(Op::shr_q14x2): r[d].u16x2 = r[x].u16x2 >> immy; break; |
| 306 | |
| 307 | CASE(Op::eq_q14x2): r[d].i16x2 = r[x].i16x2 == r[y].i16x2; break; |
| 308 | CASE(Op::gt_q14x2): r[d].i16x2 = r[x].i16x2 > r[y].i16x2; break; |
| 309 | |
| 310 | CASE(Op:: min_q14x2): r[d].i16x2 = min(r[x].i16x2, r[y].i16x2); break; |
| 311 | CASE(Op:: max_q14x2): r[d].i16x2 = max(r[x].i16x2, r[y].i16x2); break; |
| 312 | CASE(Op::umin_q14x2): r[d].u16x2 = min(r[x].u16x2, r[y].u16x2); break; |
| 313 | |
Mike Klein | 7b1620f | 2020-09-16 10:18:47 -0500 | [diff] [blame] | 314 | // Happily, Clang can see through this one and generates perfect code |
| 315 | // using vpavgw without any help from us! |
Mike Klein | 98c512c | 2020-09-15 10:00:27 -0500 | [diff] [blame] | 316 | CASE(Op::uavg_q14x2): |
Mike Klein | 9791e50 | 2020-09-15 12:43:38 -0500 | [diff] [blame] | 317 | r[d].u16x2 = skvx::cast<uint16_t>( (skvx::cast<int>(r[x].u16x2) + |
| 318 | skvx::cast<int>(r[y].u16x2) + 1)>>1 ); |
| 319 | break; |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 320 | #undef CASE |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 326 | } // namespace SK_OPTS_NS |
Mike Klein | ec37097 | 2020-03-05 10:15:35 -0600 | [diff] [blame] | 327 | |
| 328 | #endif//SkVM_opts_DEFINED |