Go to the documentation of this file.00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef VL_GENERIC_H
00016 #define VL_GENERIC_H
00017
00018 #include "host.h"
00019 #include "random.h"
00020
00021 #include <stdlib.h>
00022 #include <stddef.h>
00023 #include <time.h>
00024 #include <assert.h>
00025
00027 #define VL_VERSION_STRING "0.9.20"
00028
00030 #define VL_ERR_MSG_LEN 1024
00031
00035 #define VL_TYPE_FLOAT 1
00036 #define VL_TYPE_DOUBLE 2
00037 #define VL_TYPE_INT8 3
00038 #define VL_TYPE_UINT8 4
00039 #define VL_TYPE_INT16 5
00040 #define VL_TYPE_UINT16 6
00041 #define VL_TYPE_INT32 7
00042 #define VL_TYPE_UINT32 8
00043 #define VL_TYPE_INT64 9
00044 #define VL_TYPE_UINT64 10
00046 typedef vl_uint32 vl_type ;
00047
00057 VL_INLINE char const *
00058 vl_get_type_name (vl_type type)
00059 {
00060 switch (type) {
00061 case VL_TYPE_FLOAT : return "float" ;
00062 case VL_TYPE_DOUBLE : return "double" ;
00063 case VL_TYPE_INT8 : return "int8" ;
00064 case VL_TYPE_INT16 : return "int16" ;
00065 case VL_TYPE_INT32 : return "int32" ;
00066 case VL_TYPE_INT64 : return "int64" ;
00067 case VL_TYPE_UINT8 : return "int8" ;
00068 case VL_TYPE_UINT16 : return "int16" ;
00069 case VL_TYPE_UINT32 : return "int32" ;
00070 case VL_TYPE_UINT64 : return "int64" ;
00071 default: return NULL ;
00072 }
00073 }
00074
00084 VL_INLINE vl_size
00085 vl_get_type_size (vl_type type)
00086 {
00087 vl_size dataSize = 0 ;
00088 switch (type) {
00089 case VL_TYPE_DOUBLE : dataSize = sizeof(double) ; break ;
00090 case VL_TYPE_FLOAT : dataSize = sizeof(float) ; break ;
00091 case VL_TYPE_INT64 : case VL_TYPE_UINT64 : dataSize = sizeof(vl_int64) ; break ;
00092 case VL_TYPE_INT32 : case VL_TYPE_UINT32 : dataSize = sizeof(vl_int32) ; break ;
00093 case VL_TYPE_INT16 : case VL_TYPE_UINT16 : dataSize = sizeof(vl_int16) ; break ;
00094 case VL_TYPE_INT8 : case VL_TYPE_UINT8 : dataSize = sizeof(vl_int8) ; break ;
00095 default:
00096 abort() ;
00097 }
00098 return dataSize ;
00099 }
00102 VL_EXPORT char const * vl_get_version_string (void) ;
00103 VL_EXPORT char * vl_configuration_to_string_copy (void) ;
00104 VL_EXPORT void vl_set_simd_enabled (vl_bool x) ;
00105 VL_EXPORT vl_bool vl_get_simd_enabled (void) ;
00106 VL_EXPORT vl_bool vl_cpu_has_avx (void) ;
00107 VL_EXPORT vl_bool vl_cpu_has_sse3 (void) ;
00108 VL_EXPORT vl_bool vl_cpu_has_sse2 (void) ;
00109 VL_EXPORT vl_size vl_get_num_cpus (void) ;
00110 VL_EXPORT VlRand * vl_get_rand (void) ;
00111
00114 VL_EXPORT vl_size vl_get_max_threads (void) ;
00115 VL_EXPORT void vl_set_num_threads (vl_size n) ;
00116 VL_EXPORT vl_size vl_get_thread_limit (void) ;
00122 #define VL_ERR_OK 0
00123 #define VL_ERR_OVERFLOW 1
00124 #define VL_ERR_ALLOC 2
00125 #define VL_ERR_BAD_ARG 3
00126 #define VL_ERR_IO 4
00127 #define VL_ERR_EOF 5
00128 #define VL_ERR_NO_MORE 5
00130 VL_EXPORT int vl_get_last_error (void) ;
00131 VL_EXPORT char const * vl_get_last_error_message (void) ;
00132 VL_EXPORT int vl_set_last_error (int error, char const * errorMessage, ...) ;
00138 VL_EXPORT void
00139 vl_set_alloc_func (void *(*malloc_func) (size_t),
00140 void *(*realloc_func) (void*,size_t),
00141 void *(*calloc_func) (size_t, size_t),
00142 void (*free_func) (void*)) ;
00143 VL_EXPORT void *vl_malloc (size_t n) ;
00144 VL_EXPORT void *vl_realloc (void *ptr, size_t n) ;
00145 VL_EXPORT void *vl_calloc (size_t n, size_t size) ;
00146 VL_EXPORT void *vl_memalign (size_t n, size_t size) ;
00147 VL_EXPORT void vl_free (void* ptr) ;
00154 typedef int(*printf_func_t) (char const *format, ...) ;
00155 VL_EXPORT void vl_set_printf_func (printf_func_t printf_func) ;
00156 VL_EXPORT printf_func_t vl_get_printf_func (void) ;
00157
00168 #define VL_PRINTF (*vl_get_printf_func())
00169 #define VL_PRINT (*vl_get_printf_func())
00170
00181 #define VL_MIN(x,y) (((x)<(y))?(x):(y))
00182
00188 #define VL_MAX(x,y) (((x)>(y))?(x):(y))
00189
00197 #define VL_SHIFT_LEFT(x,n) (((n)>=0)?((x)<<(n)):((x)>>-(n)))
00198
00199
00204 VL_EXPORT void vl_tic (void) ;
00205 VL_EXPORT double vl_toc (void) ;
00206 VL_EXPORT double vl_get_cpu_time (void) ;
00209
00210 #endif