blob: ee356050f2f1e4f4a250b9584b395c9b64f07ce2 [file] [log] [blame]
Mike Klein87db0012017-05-23 12:20:38 -04001/*
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 Klein25954b62017-08-15 15:08:54 -040011#include <stdint.h>
12#include "SkNx.h"
Hal Canary466c7d62017-07-03 15:11:49 -040013
Mike Klein87db0012017-05-23 12:20:38 -040014namespace SK_OPTS_NS {
15
Mike Klein25954b62017-08-15 15:08:54 -040016 template <typename T>
17 static void memsetT(T buffer[], T value, int count) {
Mike Klein15eb1e92018-08-31 11:21:27 -040018 #if defined(SK_CPU_SSE_LEVEL) && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX
Mike Klein25954b62017-08-15 15:08:54 -040019 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 Klein87db0012017-05-23 12:20:38 -040027 }
Mike Klein25954b62017-08-15 15:08:54 -040028 while (count --> 0) {
29 *buffer++ = value;
30 }
31 }
32
Mike Kleincd71f112017-08-23 11:11:55 -040033 /*not static*/ inline void memset16(uint16_t buffer[], uint16_t value, int count) {
Mike Klein25954b62017-08-15 15:08:54 -040034 memsetT(buffer, value, count);
Mike Klein87db0012017-05-23 12:20:38 -040035 }
Mike Kleincd71f112017-08-23 11:11:55 -040036 /*not static*/ inline void memset32(uint32_t buffer[], uint32_t value, int count) {
Mike Klein25954b62017-08-15 15:08:54 -040037 memsetT(buffer, value, count);
Mike Klein87db0012017-05-23 12:20:38 -040038 }
Mike Kleincd71f112017-08-23 11:11:55 -040039 /*not static*/ inline void memset64(uint64_t buffer[], uint64_t value, int count) {
Mike Klein25954b62017-08-15 15:08:54 -040040 memsetT(buffer, value, count);
Mike Klein87db0012017-05-23 12:20:38 -040041 }
42
43}
44
45#endif//SkUtils_opts_DEFINED