#ifndef GIM_MEMORY_H_INCLUDED #define GIM_MEMORY_H_INCLUDED /*! \file gim_memory.h \author Francisco Leon Najera */ /* ----------------------------------------------------------------------------- This source file is part of GIMPACT Library. For the latest info, see http://gimpact.sourceforge.net/ Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371. email: projectileman@yahoo.com This library is free software; you can redistribute it and/or modify it under the terms of EITHER: (1) The GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The text of the GNU Lesser General Public License is included with this library in the file GIMPACT-LICENSE-LGPL.TXT. (2) The BSD-style license that is included with this library in the file GIMPACT-LICENSE-BSD.TXT. (3) The zlib/libpng license that is included with this library in the file GIMPACT-LICENSE-ZLIB.TXT. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details. ----------------------------------------------------------------------------- */ #include "gim_math.h" #include #ifdef PREFETCH #include // for prefetch #define pfval 64 #define pfval2 128 //! Prefetch 64 #define pf(_x,_i) _mm_prefetch((void *)(_x + _i + pfval), 0) //! Prefetch 128 #define pf2(_x,_i) _mm_prefetch((void *)(_x + _i + pfval2), 0) #else //! Prefetch 64 #define pf(_x,_i) //! Prefetch 128 #define pf2(_x,_i) #endif ///Functions for manip packed arrays of numbers #define GIM_COPY_ARRAYS(dest_array,source_array,element_count)\ {\ for (GUINT _i_=0;_i_=SIMD_T_SIZE) { *(ui_dst_ptr++) = *(ui_src_ptr++); copysize-=SIMD_T_SIZE; } if(copysize==0) return; */ char * c_src_ptr = (char *)src; char * c_dst_ptr = (char *)dst; while(copysize>0) { *(c_dst_ptr++) = *(c_src_ptr++); copysize--; } return; #else memcpy(dst,src,copysize); #endif } template inline void gim_swap_elements(T* _array,size_t _i,size_t _j) { T _e_tmp_ = _array[_i]; _array[_i] = _array[_j]; _array[_j] = _e_tmp_; } template inline void gim_swap_elements_memcpy(T* _array,size_t _i,size_t _j) { char _e_tmp_[sizeof(T)]; gim_simd_memcpy(_e_tmp_,&_array[_i],sizeof(T)); gim_simd_memcpy(&_array[_i],&_array[_j],sizeof(T)); gim_simd_memcpy(&_array[_j],_e_tmp_,sizeof(T)); } template inline void gim_swap_elements_ptr(char * _array,size_t _i,size_t _j) { char _e_tmp_[SIZE]; _i*=SIZE; _j*=SIZE; gim_simd_memcpy(_e_tmp_,_array+_i,SIZE); gim_simd_memcpy(_array+_i,_array+_j,SIZE); gim_simd_memcpy(_array+_j,_e_tmp_,SIZE); } #endif // GIM_MEMORY_H_INCLUDED