blender/intern/cycles/util/util_simd.h
Thomas Dinges 1578b55c27 Cycles: Move SIMD utility functions into its own file.
Recently added SSE macros for noise texture can be moved here as well, but I leave this for later.
2013-12-27 21:30:21 +01:00

88 lines
2.2 KiB
C++

/*
* Copyright 2011-2013 Blender Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
#ifndef __UTIL_SIMD_H__
#define __UTIL_SIMD_H__
CCL_NAMESPACE_BEGIN
#ifdef __KERNEL_SSE2__
/* SSE shuffle utility functions */
#ifdef __KERNEL_SSSE3__
/* faster version for SSSE3 */
typedef __m128i shuffle_swap_t;
ccl_device_inline const shuffle_swap_t shuffle_swap_identity(void)
{
return _mm_set_epi8(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
}
ccl_device_inline const shuffle_swap_t shuffle_swap_swap(void)
{
return _mm_set_epi8(7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8);
}
ccl_device_inline const __m128 shuffle_swap(const __m128& a, const shuffle_swap_t& shuf)
{
return _mm_castsi128_ps(_mm_shuffle_epi8(_mm_castps_si128(a), shuf));
}
#else
/* somewhat slower version for SSE2 */
typedef int shuffle_swap_t;
ccl_device_inline const shuffle_swap_t shuffle_swap_identity(void)
{
return 0;
}
ccl_device_inline const shuffle_swap_t shuffle_swap_swap(void)
{
return 1;
}
ccl_device_inline const __m128 shuffle_swap(const __m128& a, shuffle_swap_t shuf)
{
/* shuffle value must be a constant, so we need to branch */
if(shuf)
return _mm_shuffle_ps(a, a, _MM_SHUFFLE(1, 0, 3, 2));
else
return _mm_shuffle_ps(a, a, _MM_SHUFFLE(3, 2, 1, 0));
}
#endif
template<size_t i0, size_t i1, size_t i2, size_t i3> ccl_device_inline const __m128 shuffle(const __m128& a, const __m128& b)
{
return _mm_shuffle_ps(a, b, _MM_SHUFFLE(i3, i2, i1, i0));
}
template<size_t i0, size_t i1, size_t i2, size_t i3> ccl_device_inline const __m128 shuffle(const __m128& b)
{
return _mm_castsi128_ps(_mm_shuffle_epi32(_mm_castps_si128(b), _MM_SHUFFLE(i3, i2, i1, i0)));
}
#endif /* __KERNEL_SSE2__ */
CCL_NAMESPACE_END
#endif /* __UTIL_SIMD_H__ */