SkUtils_opts.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef SkUtils_opts_DEFINED
  8. #define SkUtils_opts_DEFINED
  9. #include <stdint.h>
  10. #include "include/private/SkNx.h"
  11. namespace SK_OPTS_NS {
  12. template <typename T>
  13. static void memsetT(T buffer[], T value, int count) {
  14. #if defined(SK_CPU_SSE_LEVEL) && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_AVX
  15. static const int N = 32 / sizeof(T);
  16. #else
  17. static const int N = 16 / sizeof(T);
  18. #endif
  19. while (count >= N) {
  20. SkNx<N,T>(value).store(buffer);
  21. buffer += N;
  22. count -= N;
  23. }
  24. while (count --> 0) {
  25. *buffer++ = value;
  26. }
  27. }
  28. /*not static*/ inline void memset16(uint16_t buffer[], uint16_t value, int count) {
  29. memsetT(buffer, value, count);
  30. }
  31. /*not static*/ inline void memset32(uint32_t buffer[], uint32_t value, int count) {
  32. memsetT(buffer, value, count);
  33. }
  34. /*not static*/ inline void memset64(uint64_t buffer[], uint64_t value, int count) {
  35. memsetT(buffer, value, count);
  36. }
  37. template <typename T>
  38. static void rect_memsetT(T buffer[], T value, int count, size_t rowBytes, int height) {
  39. while (height --> 0) {
  40. memsetT(buffer, value, count);
  41. buffer = (T*)((char*)buffer + rowBytes);
  42. }
  43. }
  44. /*not static*/ inline void rect_memset16(uint16_t buffer[], uint16_t value, int count,
  45. size_t rowBytes, int height) {
  46. rect_memsetT(buffer, value, count, rowBytes, height);
  47. }
  48. /*not static*/ inline void rect_memset32(uint32_t buffer[], uint32_t value, int count,
  49. size_t rowBytes, int height) {
  50. rect_memsetT(buffer, value, count, rowBytes, height);
  51. }
  52. /*not static*/ inline void rect_memset64(uint64_t buffer[], uint64_t value, int count,
  53. size_t rowBytes, int height) {
  54. rect_memsetT(buffer, value, count, rowBytes, height);
  55. }
  56. }
  57. #endif//SkUtils_opts_DEFINED