Mike Klein | 87db001 | 2017-05-23 12:20:38 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 8 | #ifndef SkUtils_opts_DEFINED |
| 9 | #define SkUtils_opts_DEFINED |
| 10 | |
Mike Klein | 25954b6 | 2017-08-15 15:08:54 -0400 | [diff] [blame] | 11 | #include <stdint.h> |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/private/SkNx.h" |
Hal Canary | 466c7d6 | 2017-07-03 15:11:49 -0400 | [diff] [blame] | 13 | |
Mike Klein | 87db001 | 2017-05-23 12:20:38 -0400 | [diff] [blame] | 14 | namespace SK_OPTS_NS { |
| 15 | |
Mike Klein | 25954b6 | 2017-08-15 15:08:54 -0400 | [diff] [blame] | 16 | template <typename T> |
| 17 | static void memsetT(T buffer[], T value, int count) { |
Mike Klein | 15eb1e9 | 2018-08-31 11:21:27 -0400 | [diff] [blame] | 18 | #if defined(SK_CPU_SSE_LEVEL) && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX |
Mike Klein | 25954b6 | 2017-08-15 15:08:54 -0400 | [diff] [blame] | 19 | static const int N = 32 / sizeof(T); |
| 20 | #else |
| 21 | static const int N = 16 / sizeof(T); |
| 22 | #endif |
| 23 | while (count >= N) { |
| 24 | SkNx<N,T>(value).store(buffer); |
| 25 | buffer += N; |
| 26 | count -= N; |
Mike Klein | 87db001 | 2017-05-23 12:20:38 -0400 | [diff] [blame] | 27 | } |
Mike Klein | 25954b6 | 2017-08-15 15:08:54 -0400 | [diff] [blame] | 28 | while (count --> 0) { |
| 29 | *buffer++ = value; |
| 30 | } |
| 31 | } |
| 32 | |
Mike Klein | cd71f11 | 2017-08-23 11:11:55 -0400 | [diff] [blame] | 33 | /*not static*/ inline void memset16(uint16_t buffer[], uint16_t value, int count) { |
Mike Klein | 25954b6 | 2017-08-15 15:08:54 -0400 | [diff] [blame] | 34 | memsetT(buffer, value, count); |
Mike Klein | 87db001 | 2017-05-23 12:20:38 -0400 | [diff] [blame] | 35 | } |
Mike Klein | cd71f11 | 2017-08-23 11:11:55 -0400 | [diff] [blame] | 36 | /*not static*/ inline void memset32(uint32_t buffer[], uint32_t value, int count) { |
Mike Klein | 25954b6 | 2017-08-15 15:08:54 -0400 | [diff] [blame] | 37 | memsetT(buffer, value, count); |
Mike Klein | 87db001 | 2017-05-23 12:20:38 -0400 | [diff] [blame] | 38 | } |
Mike Klein | cd71f11 | 2017-08-23 11:11:55 -0400 | [diff] [blame] | 39 | /*not static*/ inline void memset64(uint64_t buffer[], uint64_t value, int count) { |
Mike Klein | 25954b6 | 2017-08-15 15:08:54 -0400 | [diff] [blame] | 40 | memsetT(buffer, value, count); |
Mike Klein | 87db001 | 2017-05-23 12:20:38 -0400 | [diff] [blame] | 41 | } |
| 42 | |
Mike Reed | dbc3caa | 2019-05-20 16:10:55 -0400 | [diff] [blame] | 43 | template <typename T> |
| 44 | static void rect_memsetT(T buffer[], T value, int count, size_t rowBytes, int height) { |
| 45 | while (height --> 0) { |
| 46 | memsetT(buffer, value, count); |
| 47 | buffer = (T*)((char*)buffer + rowBytes); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /*not static*/ inline void rect_memset16(uint16_t buffer[], uint16_t value, int count, |
| 52 | size_t rowBytes, int height) { |
| 53 | rect_memsetT(buffer, value, count, rowBytes, height); |
| 54 | } |
| 55 | /*not static*/ inline void rect_memset32(uint32_t buffer[], uint32_t value, int count, |
| 56 | size_t rowBytes, int height) { |
| 57 | rect_memsetT(buffer, value, count, rowBytes, height); |
| 58 | } |
| 59 | /*not static*/ inline void rect_memset64(uint64_t buffer[], uint64_t value, int count, |
| 60 | size_t rowBytes, int height) { |
| 61 | rect_memsetT(buffer, value, count, rowBytes, height); |
| 62 | } |
| 63 | |
Mike Klein | 87db001 | 2017-05-23 12:20:38 -0400 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | #endif//SkUtils_opts_DEFINED |