michael@0: michael@0: /* michael@0: * Copyright 2009 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include michael@0: #include "SkUtils_opts_SSE2.h" michael@0: michael@0: void sk_memset16_SSE2(uint16_t *dst, uint16_t value, int count) michael@0: { michael@0: SkASSERT(dst != NULL && count >= 0); michael@0: michael@0: // dst must be 2-byte aligned. michael@0: SkASSERT((((size_t) dst) & 0x01) == 0); michael@0: michael@0: if (count >= 32) { michael@0: while (((size_t)dst) & 0x0F) { michael@0: *dst++ = value; michael@0: --count; michael@0: } michael@0: __m128i *d = reinterpret_cast<__m128i*>(dst); michael@0: __m128i value_wide = _mm_set1_epi16(value); michael@0: while (count >= 32) { michael@0: _mm_store_si128(d , value_wide); michael@0: _mm_store_si128(d + 1, value_wide); michael@0: _mm_store_si128(d + 2, value_wide); michael@0: _mm_store_si128(d + 3, value_wide); michael@0: d += 4; michael@0: count -= 32; michael@0: } michael@0: dst = reinterpret_cast(d); michael@0: } michael@0: while (count > 0) { michael@0: *dst++ = value; michael@0: --count; michael@0: } michael@0: } michael@0: michael@0: void sk_memset32_SSE2(uint32_t *dst, uint32_t value, int count) michael@0: { michael@0: SkASSERT(dst != NULL && count >= 0); michael@0: michael@0: // dst must be 4-byte aligned. michael@0: SkASSERT((((size_t) dst) & 0x03) == 0); michael@0: michael@0: if (count >= 16) { michael@0: while (((size_t)dst) & 0x0F) { michael@0: *dst++ = value; michael@0: --count; michael@0: } michael@0: __m128i *d = reinterpret_cast<__m128i*>(dst); michael@0: __m128i value_wide = _mm_set1_epi32(value); michael@0: while (count >= 16) { michael@0: _mm_store_si128(d , value_wide); michael@0: _mm_store_si128(d + 1, value_wide); michael@0: _mm_store_si128(d + 2, value_wide); michael@0: _mm_store_si128(d + 3, value_wide); michael@0: d += 4; michael@0: count -= 16; michael@0: } michael@0: dst = reinterpret_cast(d); michael@0: } michael@0: while (count > 0) { michael@0: *dst++ = value; michael@0: --count; michael@0: } michael@0: }