SIMD.cpp

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @file   SIMD.cpp
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @date   Fall 2008
00005    
00006    @brief
00007       Contains useful/common definitions for working with SSE intrinsics
00008    <!-------------------------------------------------------------------->**/
00009 
00010 #include "SIMD.h"
00011 
00012 #if MILTON_ENABLE_SSE
00013 
00014 #include <stdlib.h>
00015 
00016 void *malloc_aligned(unsigned n) {
00017    return _mm_malloc(n, 16);
00018    /*// allocate memory + 16 bytes incase we need to align
00019    unsigned char *_ptr = (unsigned char*)malloc(n + 16);
00020    
00021    // how many btyes do we need to offset the address by?
00022    const unsigned offset = 16U - (((unsigned)_ptr) & 15U);
00023    
00024    // offset by the required amount s.t. _ptr is now 16-byte aligned
00025    _ptr += offset;
00026    
00027    // in the byte before the aligned address, store the offset
00028    _ptr[-1] = (unsigned char)offset;
00029    return _ptr;*/
00030 }
00031 
00032 void free_aligned(void *ptr) {
00033    if (ptr) {
00034       _mm_free(ptr);
00035       /*unsigned char *_ptr = (unsigned char*)ptr;
00036       
00037       // _ptr[-1] gets the offset we stored earlier. We subtract that
00038       // from the address passed to this func to move back to the address
00039       // originally returned from malloc. 
00040       free(_ptr - _ptr[-1]);*/
00041    }
00042 }
00043 
00044 void *operator new(size_t size) throw (std::bad_alloc) {
00045    return malloc_aligned(size);
00046 }
00047 
00048 void *operator new[](size_t size) throw (std::bad_alloc) {
00049    return malloc_aligned(size);
00050 }
00051 
00052 #endif // MILTON_ENABLE_SSE
00053 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6