include/simd.h
author Radek Brich <radek.brich@devl.cz>
Mon, 05 May 2008 15:31:14 +0200
branchpyrit
changeset 92 9af5c039b678
child 94 4c8abb8977dc
permissions -rw-r--r--
add MSVC compiler support, make it default for Windows new header file simd.h for SSE abstraction and helpers add mselect pseudo instruction for common or(and(...), andnot(...)) replace many SSE intrinsics with new names new MemoryPool class (mempool.h) for faster KdNode allocation remove setMaxDepth() from Octree and KdTree, make max_depth const, it should be defined in constructor and never changed, change after building tree would cause error in traversal modify DefaultSampler to generate nice 2x2 packets of samples for packet tracing optimize Box and BBox::intersect_packet add precomputed invdir attribute to RayPacket scons build system: check for pthread library on Windows check for SDL generate include/config.h with variables detected by scons configuration move auxiliary files to build/ add sanity checks add writable operator[] to Vector

/*
 * simd.h: abstraction of Intel SSE instruction set
 *
 * This file is part of Pyrit Ray Tracer.
 *
 * Copyright 2008  Radek Brich
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef SIMD_H
#define SIMD_H

#include "common.h"

#ifndef NO_SIMD

#include <xmmintrin.h>

typedef __m128 mfloat4;

#define mZero  _mm_set_ps1(0.0f)
#define mOne   _mm_set_ps1(1.0f)
#define mTwo   _mm_set_ps1(2.0f)
#define mEps   _mm_set_ps1(Eps)
#define mMEps  _mm_set_ps1(-Eps)
#define mInf   _mm_set_ps1(Inf)
#define mMInf  _mm_set_ps1(-Inf)
#define mAllSet  _mm_cmplt_ps(mZero, mOne)

#define mset1 _mm_set_ps1
#define mset _mm_set_ps

#define madd _mm_add_ps
#define msub _mm_sub_ps
#define mmul _mm_mul_ps
#define mdiv _mm_div_ps
#define msqrt _mm_sqrt_ps

#define mand _mm_and_ps
#define mor  _mm_or_ps
#define mcmpgt _mm_cmpgt_ps
#define mcmplt _mm_cmplt_ps
#define mcmpge _mm_cmpge_ps
#define mcmple _mm_cmple_ps
#define mcmpeq _mm_cmpeq_ps
#define mcmpneq _mm_cmpneq_ps
#define mmin _mm_min_ps
#define mmax _mm_max_ps
#define mmovemask _mm_movemask_ps

inline const mfloat4 mselect(const mfloat4& mask, const mfloat4& a, const mfloat4& b)
{
	return _mm_or_ps(_mm_and_ps(mask, a), _mm_andnot_ps(mask, b));
}

inline const mfloat4 mfastpow(const mfloat4& base, const mfloat4& exponent)
{
    __m128 denom = _mm_mul_ps(exponent, base);
    denom = _mm_sub_ps(exponent, denom);
    denom = _mm_add_ps(base, denom);
    return _mm_mul_ps(base, _mm_rcp_ps(denom));
}
#endif

#endif