LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiSinCos.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005, 2006
00003  * Peter Doerfler
00004  *
00005  * This file is part of the LTI-Computer Vision Library (LTI-Lib)
00006  *
00007  * The LTI-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License (LGPL)
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * The LTI-Lib is distributed in the hope that it will be
00013  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00014  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with the LTI-Lib; see the file LICENSE.  If
00019  * not, write to the Free Software Foundation, Inc., 59 Temple Place -
00020  * Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 
00024 /*----------------------------------------------------------------
00025  * project ....: LTI Digital Image/Signal Processing Library
00026  * file .......: ltiSinCos.h
00027  * authors ....: Peter Doerfler
00028  * organization: 
00029  * creation ...: 27.10.2005
00030  * revisions ..: $Id: ltiSinCos.h,v 1.6 2007/01/10 02:26:23 alvarado Exp $
00031  */
00032 
00033 #ifndef _LTI_SIN_COS_H_
00034 #define _LTI_SIN_COS_H_
00035 
00036 #include "ltiTypes.h"
00037 #include "ltiMacroSymbols.h"
00038 #include <cmath>
00039 
00040 /**
00041  * \file ltiSinCos.h Contains platform and/or compiler specific implementations
00042  * of sincos, sincosf, and sincosl - always appending _impl to the name. Don't
00043  * use this file directly but include ltiMath.h instead which provides a
00044  * template functions sincos()
00045  */
00046 
00047 namespace lti {
00048 
00049   // structure: first level: compiler, possibly second level with
00050   // machine type needed.
00051 
00052   // MacOSX somehow misses sincos() and sincosf()
00053 #if defined(_LTI_GNUC_3) && !(defined(_LTI_MACOSX))
00054 
00055   // just wrap for constistency
00056 
00057   /**
00058    * Calculate the sine and cosine values of \p angle in one step if
00059    * the setup allows it.
00060    */
00061   void inline sincos_impl(double angle, double& sval, double& cval) {
00062     ::sincos(angle, &sval, &cval);
00063   }
00064 
00065   /**
00066    * Calculate the sine and cosine values of \p angle in one step if
00067    * the setup allows it.
00068    */
00069   void inline sincosf_impl(float angle, float& sval, float& cval) {
00070     ::sincosf(angle, &sval, &cval);
00071   }
00072 
00073 #elif defined(_LTI_MSC_VER)
00074 
00075   // inline asm implementations
00076 
00077   /**
00078    * Calculate the sine and cosine values of \p angle in one step if
00079    * the setup allows it.
00080    */
00081   void inline sincos_impl(double angle, double& sval, double& cval) {
00082     __asm {
00083   
00084       fld QWORD PTR [angle]
00085       fsincos
00086       mov ebx, [cval]
00087       fstp QWORD PTR [ebx]
00088       mov ebx, [sval]
00089       fstp QWORD PTR [ebx]
00090     }  
00091   }
00092 
00093   /**
00094    * Calculate the sine and cosine values of \p angle in one step if
00095    * the setup allows it.
00096    */
00097   void inline sincosf_impl(float angle, float& sval, float& cval) {
00098     __asm {
00099   
00100       fld DWORD PTR [angle]
00101       fsincos
00102       mov ebx, [cval]
00103       fstp DWORD PTR [ebx]
00104       mov ebx, [sval]
00105       fstp DWORD PTR [ebx]
00106     }  
00107   }
00108 
00109 #else
00110 
00111   // don't know how to do this right so just do the simple thing
00112   void inline sincos_impl(double angle, double& sval, double& cval) {
00113     sval = sin(angle);
00114     cval = cos(angle);
00115   }
00116   void inline sincosf_impl(float angle, float& sval, float& cval) {
00117     sval = sin(angle);
00118     cval = cos(angle);
00119   }
00120 
00121 #endif // compilers
00122 
00123 }
00124 
00125 #endif // _LTI_SIN_COS_H

Generated on Sat Apr 10 15:26:12 2010 for LTI-Lib by Doxygen 1.6.1