SIMDAlignment.h

00001 /*
00002  * Expression Template Matrix Library
00003  *
00004  * Copyright (C) 2004 - 2006 Ricky Lung <mtlung@users.sourceforge.net>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00023 #ifndef _EXMAT_SIMD_SIMDALIGNMENT_H
00024 #define _EXMAT_SIMD_SIMDALIGNMENT_H
00025 
00026 #include "../Config.h"
00027 
00028 #if EXMAT_ENABLE_SIMD
00029 
00030 #if EXMAT_SIMD_FLOAT
00031 #   if EXMAT_ENABLE_SSE
00032 #       include "SSE/Intrinsics.h"
00033 #       define EXMAT_SIMD_FLOAT_UNIT __m128
00034 #       ifndef EXMAT_SIMD_DEFAULT_ALIGN
00035 #           define EXMAT_SIMD_DEFAULT_ALIGN 16
00036 #       endif   // EXMAT_SIMD_DEFAULT_ALIGN
00037 #       define EXMAT_SIMD_FLOAT_ALIGN 16
00038 #       include "SSE/MatMul.h"
00039 #   endif   // EXMAT_ENABLE_SSE
00040 #endif  // EXMAT_SIMD_FLOAT
00041 
00042 #if EXMAT_SIMD_DOUBLE
00043 #   if EXMAT_ENABLE_SSE2
00044 #       include "SSE2/Intrinsics.h"
00045 #       define EXMAT_SIMD_DOUBLE_UNIT __m128d
00046 #       ifndef EXMAT_SIMD_DEFAULT_ALIGN
00047 #           define EXMAT_SIMD_DEFAULT_ALIGN 16
00048 #       endif   // EXMAT_SIMD_DEFAULT_ALIGN
00049 #       define EXMAT_SIMD_DOUBLE_ALIGN 16
00050 #       include "SSE2/MatMul.h"
00051 #   endif   // EXMAT_ENABLE_SSE2
00052 #endif  // EXMAT_SIMD_DOUBLE
00053 
00054 
00055 // MACRO for declaring aligned variable
00056 #if (EXMAT_VC || EXMAT_ICL)
00057 #   define EXMAT_VAR_ALIGN(declaration, num) __declspec(align(num)) declaration;
00058 #else
00059 #   define EXMAT_VAR_ALIGN(declaration, num) declaration __attribute__((aligned(num)));
00060 #endif
00061 
00062 
00063 // MACRO for declaring aligned type
00064 #if (EXMAT_VC || EXMAT_ICL)
00065 #   define EXMAT_TYPE_ALIGN_PREFIX(num) __declspec(align(num))
00066 #   define EXMAT_TYPE_ALIGN_SUFFIX(num)
00067 #else
00068 #   define EXMAT_TYPE_ALIGN_PREFIX(num)
00069 #   define EXMAT_TYPE_ALIGN_SUFFIX(num) __attribute__((aligned(num)))
00070 #endif
00071 
00072 
00073 // Alignment checking
00074 #if ENABLE_ALIGNMENT_CHECK
00075 #   define ALIGNMENT_CHECK(Num) \
00076     if(int(&unitData) % Num != 0) { throw mem_align_error("mem_align_error: struct not #Num aligned\n");    }
00077 #else
00078 #   define ALIGNMENT_CHECK(Num)
00079 #endif  // ENABLE_ALLIGNMENT_CHECK
00080 
00081 
00082 // new and delete operators
00083 #define NEW_ALIGN(Num)  \
00084     EXMAT_INLINE2 static void* operator new( size_t size ) {    return AlignedMalloc(size, Num);    }
00085 #define DELETE_ALIGN()  \
00086     EXMAT_INLINE2 static void operator delete(void* addr) { AlignedFree(addr);  }
00087 
00088 #else
00089 
00090 #endif  // EXMAT_ENABLE_SIMD
00091 
00092 #ifndef EXMAT_SIMD_DEFAULT_ALIGN
00093 #   define EXMAT_SIMD_DEFAULT_ALIGN 8
00094 #endif
00095 
00096 #endif  // _EXMAT_SIMD_SIMDALIGNMENT_H

Generated on Sat May 6 23:12:00 2006 for Exmat by  doxygen 1.4.6-NO