diff options
Diffstat (limited to 'SD-VBS/common/matlab')
31 files changed, 1586 insertions, 0 deletions
diff --git a/SD-VBS/common/matlab/cycle.h b/SD-VBS/common/matlab/cycle.h new file mode 100644 index 0000000..2652a04 --- /dev/null +++ b/SD-VBS/common/matlab/cycle.h | |||
| @@ -0,0 +1,514 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2003, 2007-8 Matteo Frigo | ||
| 3 | * Copyright (c) 2003, 2007-8 Massachusetts Institute of Technology | ||
| 4 | * | ||
| 5 | * Permission is hereby granted, free of charge, to any person obtaining | ||
| 6 | * a copy of this software and associated documentation files (the | ||
| 7 | * "Software"), to deal in the Software without restriction, including | ||
| 8 | * without limitation the rights to use, copy, modify, merge, publish, | ||
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to | ||
| 10 | * permit persons to whom the Software is furnished to do so, subject to | ||
| 11 | * the following conditions: | ||
| 12 | * | ||
| 13 | * The above copyright notice and this permission notice shall be | ||
| 14 | * included in all copies or substantial portions of the Software. | ||
| 15 | * | ||
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
| 20 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
| 21 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
| 22 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 23 | * | ||
| 24 | */ | ||
| 25 | |||
| 26 | |||
| 27 | /* machine-dependent cycle counters code. Needs to be inlined. */ | ||
| 28 | |||
| 29 | /***************************************************************************/ | ||
| 30 | /* To use the cycle counters in your code, simply #include "cycle.h" (this | ||
| 31 | file), and then use the functions/macros: | ||
| 32 | |||
| 33 | ticks getticks(void); | ||
| 34 | |||
| 35 | ticks is an opaque typedef defined below, representing the current time. | ||
| 36 | You extract the elapsed time between two calls to gettick() via: | ||
| 37 | |||
| 38 | double elapsed(ticks t1, ticks t0); | ||
| 39 | |||
| 40 | which returns a double-precision variable in arbitrary units. You | ||
| 41 | are not expected to convert this into human units like seconds; it | ||
| 42 | is intended only for *comparisons* of time intervals. | ||
| 43 | |||
| 44 | (In order to use some of the OS-dependent timer routines like | ||
| 45 | Solaris' gethrtime, you need to paste the autoconf snippet below | ||
| 46 | into your configure.ac file and #include "config.h" before cycle.h, | ||
| 47 | or define the relevant macros manually if you are not using autoconf.) | ||
| 48 | */ | ||
| 49 | |||
| 50 | /***************************************************************************/ | ||
| 51 | /* This file uses macros like HAVE_GETHRTIME that are assumed to be | ||
| 52 | defined according to whether the corresponding function/type/header | ||
| 53 | is available on your system. The necessary macros are most | ||
| 54 | conveniently defined if you are using GNU autoconf, via the tests: | ||
| 55 | |||
| 56 | dnl --------------------------------------------------------------------- | ||
| 57 | |||
| 58 | AC_C_INLINE | ||
| 59 | AC_HEADER_TIME | ||
| 60 | AC_CHECK_HEADERS([sys/time.h c_asm.h intrinsics.h mach/mach_time.h]) | ||
| 61 | |||
| 62 | AC_CHECK_TYPE([hrtime_t],[AC_DEFINE(HAVE_HRTIME_T, 1, [Define to 1 if hrtime_t is defined in <sys/time.h>])],,[#if HAVE_SYS_TIME_H | ||
| 63 | #include <sys/time.h> | ||
| 64 | #endif]) | ||
| 65 | |||
| 66 | AC_CHECK_FUNCS([gethrtime read_real_time time_base_to_time clock_gettime mach_absolute_time]) | ||
| 67 | |||
| 68 | dnl Cray UNICOS _rtc() (real-time clock) intrinsic | ||
| 69 | AC_MSG_CHECKING([for _rtc intrinsic]) | ||
| 70 | rtc_ok=yes | ||
| 71 | AC_TRY_LINK([#ifdef HAVE_INTRINSICS_H | ||
| 72 | #include <intrinsics.h> | ||
| 73 | #endif], [_rtc()], [AC_DEFINE(HAVE__RTC,1,[Define if you have the UNICOS _rtc() intrinsic.])], [rtc_ok=no]) | ||
| 74 | AC_MSG_RESULT($rtc_ok) | ||
| 75 | |||
| 76 | dnl --------------------------------------------------------------------- | ||
| 77 | */ | ||
| 78 | |||
| 79 | /***************************************************************************/ | ||
| 80 | |||
| 81 | #if TIME_WITH_SYS_TIME | ||
| 82 | # include <sys/time.h> | ||
| 83 | # include <time.h> | ||
| 84 | #else | ||
| 85 | # if HAVE_SYS_TIME_H | ||
| 86 | # include <sys/time.h> | ||
| 87 | # else | ||
| 88 | # include <time.h> | ||
| 89 | # endif | ||
| 90 | #endif | ||
| 91 | |||
| 92 | #define INLINE_ELAPSED(INL) static INL double elapsed(ticks t1, ticks t0) \ | ||
| 93 | { \ | ||
| 94 | return (double)t1 - (double)t0; \ | ||
| 95 | } | ||
| 96 | |||
| 97 | /*----------------------------------------------------------------*/ | ||
| 98 | /* Solaris */ | ||
| 99 | #if defined(HAVE_GETHRTIME) && defined(HAVE_HRTIME_T) && !defined(HAVE_TICK_COUNTER) | ||
| 100 | typedef hrtime_t ticks; | ||
| 101 | |||
| 102 | #define getticks gethrtime | ||
| 103 | |||
| 104 | INLINE_ELAPSED(inline) | ||
| 105 | |||
| 106 | #define HAVE_TICK_COUNTER | ||
| 107 | #endif | ||
| 108 | |||
| 109 | /*----------------------------------------------------------------*/ | ||
| 110 | /* AIX v. 4+ routines to read the real-time clock or time-base register */ | ||
| 111 | #if defined(HAVE_READ_REAL_TIME) && defined(HAVE_TIME_BASE_TO_TIME) && !defined(HAVE_TICK_COUNTER) | ||
| 112 | typedef timebasestruct_t ticks; | ||
| 113 | |||
| 114 | static __inline ticks getticks(void) | ||
| 115 | { | ||
| 116 | ticks t; | ||
| 117 | read_real_time(&t, TIMEBASE_SZ); | ||
| 118 | return t; | ||
| 119 | } | ||
| 120 | |||
| 121 | static __inline double elapsed(ticks t1, ticks t0) /* time in nanoseconds */ | ||
| 122 | { | ||
| 123 | time_base_to_time(&t1, TIMEBASE_SZ); | ||
| 124 | time_base_to_time(&t0, TIMEBASE_SZ); | ||
| 125 | return (((double)t1.tb_high - (double)t0.tb_high) * 1.0e9 + | ||
| 126 | ((double)t1.tb_low - (double)t0.tb_low)); | ||
| 127 | } | ||
| 128 | |||
| 129 | #define HAVE_TICK_COUNTER | ||
| 130 | #endif | ||
| 131 | |||
| 132 | /*----------------------------------------------------------------*/ | ||
| 133 | /* | ||
| 134 | * PowerPC ``cycle'' counter using the time base register. | ||
| 135 | */ | ||
| 136 | #if ((((defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))) || (defined(__MWERKS__) && defined(macintosh)))) || (defined(__IBM_GCC_ASM) && (defined(__powerpc__) || defined(__ppc__)))) && !defined(HAVE_TICK_COUNTER) | ||
| 137 | typedef unsigned long long ticks; | ||
| 138 | |||
| 139 | static __inline__ ticks getticks(void) | ||
| 140 | { | ||
| 141 | unsigned int tbl, tbu0, tbu1; | ||
| 142 | |||
| 143 | do { | ||
| 144 | __asm__ __volatile__ ("mftbu %0" : "=r"(tbu0)); | ||
| 145 | __asm__ __volatile__ ("mftb %0" : "=r"(tbl)); | ||
| 146 | __asm__ __volatile__ ("mftbu %0" : "=r"(tbu1)); | ||
| 147 | } while (tbu0 != tbu1); | ||
| 148 | |||
| 149 | return (((unsigned long long)tbu0) << 32) | tbl; | ||
| 150 | } | ||
