Path: blob/master/thirdparty/embree/common/simd/varying.h
9912 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "../sys/platform.h"67namespace embree8{9/* Varying numeric types */10template<int N>11struct vfloat_impl12{13union { float f[N]; int i[N]; };14__forceinline const float& operator [](size_t index) const { assert(index < N); return f[index]; }15__forceinline float& operator [](size_t index) { assert(index < N); return f[index]; }16};1718template<int N>19struct vdouble_impl20{21union { double f[N]; long long i[N]; };22__forceinline const double& operator [](size_t index) const { assert(index < N); return f[index]; }23__forceinline double& operator [](size_t index) { assert(index < N); return f[index]; }24};2526template<int N>27struct vint_impl28{29int i[N];30__forceinline const int& operator [](size_t index) const { assert(index < N); return i[index]; }31__forceinline int& operator [](size_t index) { assert(index < N); return i[index]; }32};3334template<int N>35struct vuint_impl36{37unsigned int i[N];38__forceinline const unsigned int& operator [](size_t index) const { assert(index < N); return i[index]; }39__forceinline unsigned int& operator [](size_t index) { assert(index < N); return i[index]; }40};4142template<int N>43struct vllong_impl44{45long long i[N];46__forceinline const long long& operator [](size_t index) const { assert(index < N); return i[index]; }47__forceinline long long& operator [](size_t index) { assert(index < N); return i[index]; }48};4950/* Varying bool types */51template<int N> struct vboolf_impl { int i[N]; }; // for float/int52template<int N> struct vboold_impl { long long i[N]; }; // for double/long long5354/* Varying size constants */55#if defined(__AVX512VL__) // SKX56const int VSIZEX = 8; // default size57const int VSIZEL = 16; // large size58#elif defined(__AVX__)59const int VSIZEX = 8;60const int VSIZEL = 8;61#else62const int VSIZEX = 4;63const int VSIZEL = 4;64#endif6566template<int N>67struct vtypes {68using vbool = vboolf_impl<N>;69using vboolf = vboolf_impl<N>;70using vboold = vboold_impl<N>;71using vint = vint_impl<N>;72using vuint = vuint_impl<N>;73using vllong = vllong_impl<N>;74using vfloat = vfloat_impl<N>;75using vdouble = vdouble_impl<N>;76};7778template<>79struct vtypes<1> {80using vbool = bool;81using vboolf = bool;82using vboold = bool;83using vint = int;84using vuint = unsigned int;85using vllong = long long;86using vfloat = float;87using vdouble = double;88};8990/* Aliases to default types */91template<int N> using vbool = typename vtypes<N>::vbool;92template<int N> using vboolf = typename vtypes<N>::vboolf;93template<int N> using vboold = typename vtypes<N>::vboold;94template<int N> using vint = typename vtypes<N>::vint;95template<int N> using vuint = typename vtypes<N>::vuint;96template<int N> using vllong = typename vtypes<N>::vllong;97template<int N> using vreal = typename vtypes<N>::vfloat;98template<int N> using vfloat = typename vtypes<N>::vfloat;99template<int N> using vdouble = typename vtypes<N>::vdouble;100101/* 4-wide shortcuts */102typedef vfloat<4> vfloat4;103typedef vdouble<4> vdouble4;104typedef vreal<4> vreal4;105typedef vint<4> vint4;106typedef vuint<4> vuint4;107typedef vllong<4> vllong4;108typedef vbool<4> vbool4;109typedef vboolf<4> vboolf4;110typedef vboold<4> vboold4;111112/* 8-wide shortcuts */113typedef vfloat<8> vfloat8;114typedef vdouble<8> vdouble8;115typedef vreal<8> vreal8;116typedef vint<8> vint8;117typedef vuint<8> vuint8;118typedef vllong<8> vllong8;119typedef vbool<8> vbool8;120typedef vboolf<8> vboolf8;121typedef vboold<8> vboold8;122123/* 16-wide shortcuts */124typedef vfloat<16> vfloat16;125typedef vdouble<16> vdouble16;126typedef vreal<16> vreal16;127typedef vint<16> vint16;128typedef vuint<16> vuint16;129typedef vllong<16> vllong16;130typedef vbool<16> vbool16;131typedef vboolf<16> vboolf16;132typedef vboold<16> vboold16;133134/* Default shortcuts */135typedef vfloat<VSIZEX> vfloatx;136typedef vdouble<VSIZEX> vdoublex;137typedef vreal<VSIZEX> vrealx;138typedef vint<VSIZEX> vintx;139typedef vuint<VSIZEX> vuintx;140typedef vllong<VSIZEX> vllongx;141typedef vbool<VSIZEX> vboolx;142typedef vboolf<VSIZEX> vboolfx;143typedef vboold<VSIZEX> vbooldx;144}145146147