Coverage Report

Created: 2021-04-14 04:30

/home/liu/buildslave/linux-x64-runtests/build/lib/ccv_internal.h
Line
Count
Source (jump to first uncovered line)
1
/**********************************************************
2
 * C-based/Cached/Core Computer Vision Library
3
 * Liu Liu, 2010-02-01
4
 **********************************************************/
5
6
#ifndef GUARD_ccv_internal_h
7
#define GUARD_ccv_internal_h
8
9
static int _CCV_PRINT_COUNT __attribute__ ((unused)) = 0;
10
static int _CCV_PRINT_LOOP __attribute__ ((unused)) = 0;
11
12
/* simple utility functions */
13
14
0
#define ccv_descale(x, n) (((x) + (1 << ((n) - 1))) >> (n))
15
#define conditional_assert(x, expr) if ((x)) { assert(expr); }
16
17
#define MACRO_STRINGIFY(x) #x
18
19
#define UNROLL_PRAGMA0(x) MACRO_STRINGIFY(unroll x)
20
55.1M
#define UNROLL_FOR0(x, s, ss, ...) 
_Pragma(UNROLL_PRAGMA0((ss))) for ((x) = 0; 8.68M
(x) < (s);
(x)++46.5M
)
{46.5M
21
/* How to use this:
22
 * unroll_for(i, the number of iterations, the number of unrolls)
23
 * Or
24
 * unroll_for(i, the number of iterations)
25
 */
26
8.68M
#define unroll_for(x, s, ...) UNROLL_FOR0(x, s, ##__VA_ARGS__, s)
27
55.1M
#define unroll_endfor }
28
#ifdef USE_OPENMP
29
#define OMP_PRAGMA0(x) MACRO_STRINGIFY(omp parallel for private(x) schedule(dynamic))
30
355k
#define parallel_for(x, n) 
{ int x = 0; _Pragma(OMP_PRAGMA0(x)) 95.5k
for ((x) = 0; 0
(x) < (n); (x)++)
{0
31
266k
#define parallel_endfor } }
32
#define FOR_IS_PARALLEL (1)
33
#else
34
#define parallel_for(x, n) { int x; for ((x) = 0; (x) < (n); (x)++) {
35
#define parallel_endfor } }
36
#define FOR_IS_PARALLEL (0)
37
#endif
38
39
/* macro printf utilities */
40
41
#define PRINT(l, a, ...) \
42
3.20M
  do { \
43
3.20M
    if (CCV_CLI_OUTPUT_LEVEL_IS(l)) \
44
3.20M
    { \
45
0
      printf(a, ##__VA_ARGS__); \
46
0
      fflush(stdout); \
47
0
    } \
48
3.20M
  } while (0) // using do while (0) to force ; line end
49
50
51
#define FLUSH(l, a, ...) \
52
0
  do { \
53
0
    if (CCV_CLI_OUTPUT_LEVEL_IS(l)) \
54
0
    { \
55
0
      for (_CCV_PRINT_LOOP = 0; _CCV_PRINT_LOOP < _CCV_PRINT_COUNT; _CCV_PRINT_LOOP++) \
56
0
        printf("\b"); \
57
0
      for (_CCV_PRINT_LOOP = 0; _CCV_PRINT_LOOP < _CCV_PRINT_COUNT; _CCV_PRINT_LOOP++) \
58
0
        printf(" "); \
59
0
      for (_CCV_PRINT_LOOP = 0; _CCV_PRINT_LOOP < _CCV_PRINT_COUNT; _CCV_PRINT_LOOP++) \
60
0
        printf("\b"); \
61
0
      _CCV_PRINT_COUNT = printf(a, ##__VA_ARGS__); \
62
0
      fflush(stdout); \
63
0
    } \
64
0
  } while (0) // using do while (0) to force ; line end
65
66
/* the following macro enables the usage such as:
67
 * ccv_object_return_if_cached(, db, dc, dd, ...);
68
 * effectively, it only returns when db, dc and dd are all successfully retrieved from cache */
69
70
#define INTERNAL_GARBAGE_TYPEDEF_CONCATENATE_N(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_30,_31,_32,_33,_34,_35,_36,_37,_38,_39,_40,_41,_42,_43,_44,_45,_46,_47,_48,_49,_50,_51,_52,_53,_54,_55,_56,_57,_58,_59,_60,_61,_62,_63,...) \
71
376k
  
(375k
!(_1)375k
|| (((int*)(_1))[0] & CCV_GARBAGE)) &&
(0
!(_2)0
||
(((int*)(_2))[0] & CCV_GARBAGE)0
) &&
(0
!(_3)0
||
(((int*)(_3))[0] & CCV_GARBAGE)0
) &&
(0
!(_4)0
||
(((int*)(_4))[0] & CCV_GARBAGE)0
) &&
(0
!(_5)0
||
(((int*)(_5))[0] & CCV_GARBAGE)0
) &&
(0
!(_6)0
||
(((int*)(_6))[0] & CCV_GARBAGE)0
) &&
(0
!(_7)0
||
(((int*)(_7))[0] & CCV_GARBAGE)0
) &&
(0
!(_8)0
||
(((int*)(_8))[0] & CCV_GARBAGE)0
) &&
(0
!(_9)0
||
(((int*)(_9))[0] & CCV_GARBAGE)0
) &&
(0
!(_10)0
||
(((int*)(_10))[0] & CCV_GARBAGE)0
) &&
(0
!(_11)0
||
(((int*)(_11))[0] & CCV_GARBAGE)0
) &&
(0
!(_12)0
||
(((int*)(_12))[0] & CCV_GARBAGE)0
) &&
(0
!(_13)0
||
(((int*)(_13))[0] & CCV_GARBAGE)0
) &&
(0
!(_14)0
||
(((int*)(_14))[0] & CCV_GARBAGE)0
) &&
(0
!(_15)0
||
(((int*)(_15))[0] & CCV_GARBAGE)0
) &&
(0
!(_16)0
||
(((int*)(_16))[0] & CCV_GARBAGE)0
) &&
(0
!(_17)0
||
(((int*)(_17))[0] & CCV_GARBAGE)0
) &&
(0
!(_18)0
||
(((int*)(_18))[0] & CCV_GARBAGE)0
) &&
(0
!(_19)0
||
(((int*)(_19))[0] & CCV_GARBAGE)0
) &&
(0
!(_20)0
||
(((int*)(_20))[0] & CCV_GARBAGE)0
) &&
(0
!(_21)0
||
(((int*)(_21))[0] & CCV_GARBAGE)0
) &&
(0
!(_22)0
||
(((int*)(_22))[0] & CCV_GARBAGE)0
) &&
(0
!(_23)0
||
(((int*)(_23))[0] & CCV_GARBAGE)0
) &&
(0
!(_24)0
||
(((int*)(_24))[0] & CCV_GARBAGE)0
) &&
(0
!(_25)0
||
(((int*)(_25))[0] & CCV_GARBAGE)0
) &&
(0
!(_26)0
||
(((int*)(_26))[0] & CCV_GARBAGE)0
) &&
(0
!(_27)0
||
(((int*)(_27))[0] & CCV_GARBAGE)0
) &&
(0
!(_28)0
||
(((int*)(_28))[0] & CCV_GARBAGE)0
) &&
(0
!(_29)0
||
(((int*)(_29))[0] & CCV_GARBAGE)0
) &&
(0
!(_30)0
||
(((int*)(_30))[0] & CCV_GARBAGE)0
) &&
(0
!(_31)0
||
(((int*)(_31))[0] & CCV_GARBAGE)0
) &&
(0
!(_32)0
||
(((int*)(_32))[0] & CCV_GARBAGE)0
) &&
(0
!(_33)0
||
(((int*)(_33))[0] & CCV_GARBAGE)0
) &&
(0
!(_34)0
||
(((int*)(_34))[0] & CCV_GARBAGE)0
) &&
(0
!(_35)0
||
(((int*)(_35))[0] & CCV_GARBAGE)0
) &&
(0
!(_36)0
||
(((int*)(_36))[0] & CCV_GARBAGE)0
) &&
(0
!(_37)0
||
(((int*)(_37))[0] & CCV_GARBAGE)0
) &&
(0
!(_38)0
||
(((int*)(_38))[0] & CCV_GARBAGE)0
) &&
(0
!(_39)0
||
(((int*)(_39))[0] & CCV_GARBAGE)0
) &&
(0
!(_40)0
||
(((int*)(_40))[0] & CCV_GARBAGE)0
) &&
(0
!(_41)0
||
(((int*)(_41))[0] & CCV_GARBAGE)0
) &&
(0
!(_42)0
||
(((int*)(_42))[0] & CCV_GARBAGE)0
) &&
(0
!(_43)0
||
(((int*)(_43))[0] & CCV_GARBAGE)0
) &&
(0
!(_44)0
||
(((int*)(_44))[0] & CCV_GARBAGE)0
) &&
(0
!(_45)0
||
(((int*)(_45))[0] & CCV_GARBAGE)0
) &&
(0
!(_46)0
||
(((int*)(_46))[0] & CCV_GARBAGE)0
) &&
(0
!(_47)0
||
(((int*)(_47))[0] & CCV_GARBAGE)0
) &&
(0
!(_48)0
||
(((int*)(_48))[0] & CCV_GARBAGE)0
) &&
(0
!(_49)0
||
(((int*)(_49))[0] & CCV_GARBAGE)0
) &&
(0
!(_50)0
||
(((int*)(_50))[0] & CCV_GARBAGE)0
) &&
(0
!(_51)0
||
(((int*)(_51))[0] & CCV_GARBAGE)0
) &&
(0
!(_52)0
||
(((int*)(_52))[0] & CCV_GARBAGE)0
) &&
(0
!(_53)0
||
(((int*)(_53))[0] & CCV_GARBAGE)0
) &&
(0
!(_54)0
||
(((int*)(_54))[0] & CCV_GARBAGE)0
) &&
(0
!(_55)0
||
(((int*)(_55))[0] & CCV_GARBAGE)0
) &&
(0
!(_56)0
||
(((int*)(_56))[0] & CCV_GARBAGE)0
) &&
(0
!(_57)0
||
(((int*)(_57))[0] & CCV_GARBAGE)0
) &&
(0
!(_58)0
||
(((int*)(_58))[0] & CCV_GARBAGE)0
) &&
(0
!(_59)0
||
(((int*)(_59))[0] & CCV_GARBAGE)0
) &&
(0
!(_60)0
||
(((int*)(_60))[0] & CCV_GARBAGE)0
) &&
(0
!(_61)0
||
(((int*)(_61))[0] & CCV_GARBAGE)0
) &&
(0
!(_62)0
||
(((int*)(_62))[0] & CCV_GARBAGE)0
) &&
(0
!(_63)0
||
(((int*)(_63))[0] & CCV_GARBAGE)0
)
72
375k
#define INTERNAL_GARBAGE_TYPEDEF_CONCATENATE(...) INTERNAL_GARBAGE_TYPEDEF_CONCATENATE_N(__VA_ARGS__)
73
74
#define INTERNAL_EXPAND_RENEW_MATRIX_LINE_N(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_30,_31,_32,_33,_34,_35,_36,_37,_38,_39,_40,_41,_42,_43,_44,_45,_46,_47,_48,_49,_50,_51,_52,_53,_54,_55,_56,_57,_58,_59,_60,_61,_62,_63,...) \
75
2
  (void)((_1) && (((int*)(_1))[0] &= ~CCV_GARBAGE));(void)((_2) && 
(((int*)(_2))[0] &= ~CCV_GARBAGE)0
);(void)((_3) &&
(((int*)(_3))[0] &= ~CCV_GARBAGE)0
);(void)((_4) &&
(((int*)(_4))[0] &= ~CCV_GARBAGE)0
);(void)((_5) &&
(((int*)(_5))[0] &= ~CCV_GARBAGE)0
);(void)((_6) &&
(((int*)(_6))[0] &= ~CCV_GARBAGE)0
);(void)((_7) &&
(((int*)(_7))[0] &= ~CCV_GARBAGE)0
);(void)((_8) &&
(((int*)(_8))[0] &= ~CCV_GARBAGE)0
);(void)((_9) &&
(((int*)(_9))[0] &= ~CCV_GARBAGE)0
);(void)((_10) &&
(((int*)(_10))[0] &= ~CCV_GARBAGE)0
);(void)((_11) &&
(((int*)(_11))[0] &= ~CCV_GARBAGE)0
);(void)((_12) &&
(((int*)(_12))[0] &= ~CCV_GARBAGE)0
);(void)((_13) &&
(((int*)(_13))[0] &= ~CCV_GARBAGE)0
);(void)((_14) &&
(((int*)(_14))[0] &= ~CCV_GARBAGE)0
);(void)((_15) &&
(((int*)(_15))[0] &= ~CCV_GARBAGE)0
);(void)((_16) &&
(((int*)(_16))[0] &= ~CCV_GARBAGE)0
);(void)((_17) &&
(((int*)(_17))[0] &= ~CCV_GARBAGE)0
);(void)((_18) &&
(((int*)(_18))[0] &= ~CCV_GARBAGE)0
);(void)((_19) &&
(((int*)(_19))[0] &= ~CCV_GARBAGE)0
);(void)((_20) &&
(((int*)(_20))[0] &= ~CCV_GARBAGE)0
);(void)((_21) &&
(((int*)(_21))[0] &= ~CCV_GARBAGE)0
);(void)((_22) &&
(((int*)(_22))[0] &= ~CCV_GARBAGE)0
);(void)((_23) &&
(((int*)(_23))[0] &= ~CCV_GARBAGE)0
);(void)((_24) &&
(((int*)(_24))[0] &= ~CCV_GARBAGE)0
);(void)((_25) &&
(((int*)(_25))[0] &= ~CCV_GARBAGE)0
);(void)((_26) &&
(((int*)(_26))[0] &= ~CCV_GARBAGE)0
);(void)((_27) &&
(((int*)(_27))[0] &= ~CCV_GARBAGE)0
);(void)((_28) &&
(((int*)(_28))[0] &= ~CCV_GARBAGE)0
);(void)((_29) &&
(((int*)(_29))[0] &= ~CCV_GARBAGE)0
);(void)((_30) &&
(((int*)(_30))[0] &= ~CCV_GARBAGE)0
);(void)((_31) &&
(((int*)(_31))[0] &= ~CCV_GARBAGE)0
);(void)((_32) &&
(((int*)(_32))[0] &= ~CCV_GARBAGE)0
);(void)((_33) &&
(((int*)(_33))[0] &= ~CCV_GARBAGE)0
);(void)((_34) &&
(((int*)(_34))[0] &= ~CCV_GARBAGE)0
);(void)((_35) &&
(((int*)(_35))[0] &= ~CCV_GARBAGE)0
);(void)((_36) &&
(((int*)(_36))[0] &= ~CCV_GARBAGE)0
);(void)((_37) &&
(((int*)(_37))[0] &= ~CCV_GARBAGE)0
);(void)((_38) &&
(((int*)(_38))[0] &= ~CCV_GARBAGE)0
);(void)((_39) &&
(((int*)(_39))[0] &= ~CCV_GARBAGE)0
);(void)((_40) &&
(((int*)(_40))[0] &= ~CCV_GARBAGE)0
);(void)((_41) &&
(((int*)(_41))[0] &= ~CCV_GARBAGE)0
);(void)((_42) &&
(((int*)(_42))[0] &= ~CCV_GARBAGE)0
);(void)((_43) &&
(((int*)(_43))[0] &= ~CCV_GARBAGE)0
);(void)((_44) &&
(((int*)(_44))[0] &= ~CCV_GARBAGE)0
);(void)((_45) &&
(((int*)(_45))[0] &= ~CCV_GARBAGE)0
);(void)((_46) &&
(((int*)(_46))[0] &= ~CCV_GARBAGE)0
);(void)((_47) &&
(((int*)(_47))[0] &= ~CCV_GARBAGE)0
);(void)((_48) &&
(((int*)(_48))[0] &= ~CCV_GARBAGE)0
);(void)((_49) &&
(((int*)(_49))[0] &= ~CCV_GARBAGE)0
);(void)((_50) &&
(((int*)(_50))[0] &= ~CCV_GARBAGE)0
);(void)((_51) &&
(((int*)(_51))[0] &= ~CCV_GARBAGE)0
);(void)((_52) &&
(((int*)(_52))[0] &= ~CCV_GARBAGE)0
);(void)((_53) &&
(((int*)(_53))[0] &= ~CCV_GARBAGE)0
);(void)((_54) &&
(((int*)(_54))[0] &= ~CCV_GARBAGE)0
);(void)((_55) &&
(((int*)(_55))[0] &= ~CCV_GARBAGE)0
);(void)((_56) &&
(((int*)(_56))[0] &= ~CCV_GARBAGE)0
);(void)((_57) &&
(((int*)(_57))[0] &= ~CCV_GARBAGE)0
);(void)((_58) &&
(((int*)(_58))[0] &= ~CCV_GARBAGE)0
);(void)((_59) &&
(((int*)(_59))[0] &= ~CCV_GARBAGE)0
);(void)((_60) &&
(((int*)(_60))[0] &= ~CCV_GARBAGE)0
);(void)((_61) &&
(((int*)(_61))[0] &= ~CCV_GARBAGE)0
);(void)((_62) &&
(((int*)(_62))[0] &= ~CCV_GARBAGE)0
);(void)((_63) &&
(((int*)(_63))[0] &= ~CCV_GARBAGE)0
);
76
2
#define INTERNAL_EXPAND_RENEW_MATRIX_LINE(...) INTERNAL_EXPAND_RENEW_MATRIX_LINE_N(__VA_ARGS__)
77
78
#define INTERNAL_SEQ_PADDING_ZERO() 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
79
#define ccv_revive_object_if_cached(...) \
80
2
  INTERNAL_EXPAND_RENEW_MATRIX_LINE(__VA_ARGS__, INTERNAL_SEQ_PADDING_ZERO());
81
82
375k
#define ccv_object_return_if_cached(rv, ...) { \
83
375k
  if (INTERNAL_GARBAGE_TYPEDEF_CONCATENATE(__VA_ARGS__, INTERNAL_SEQ_PADDING_ZERO())) { \
84
0
    ccv_revive_object_if_cached(__VA_ARGS__); \
85
0
    return rv; } }
86
87
/* the following 9 lines to generate unique name was taken from Catch: https://github.com/philsquared/Catch
88
 * here is the licence:
89
 * Boost Software License - Version 1.0 - August 17th, 2003
90
 *
91
 * Permission is hereby granted, free of charge, to any person or organization
92
 * obtaining a copy of the software and accompanying documentation covered by
93
 * this license (the "Software") to use, reproduce, display, distribute,
94
 * execute, and transmit the Software, and to prepare derivative works of the
95
 * Software, and to permit third-parties to whom the Software is furnished to
96
 * do so, all subject to the following:
97
 *
98
 * The copyright notices in the Software and this entire statement, including
99
 * the above license grant, this restriction and the following disclaimer,
100
 * must be included in all copies of the Software, in whole or in part, and
101
 * all derivative works of the Software, unless such copies or derivative
102
 * works are solely in the form of machine-executable object code generated by
103
 * a source language processor.
104
 *
105
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
106
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
107
 * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
108
 * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
109
 * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
110
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
111
 * DEALINGS IN THE SOFTWARE. */
112
#ifndef INTERNAL_CATCH_UNIQUE_NAME_LINE2
113
3.34k
#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
114
#endif
115
#ifndef INTERNAL_CATCH_UNIQUE_NAME_LINE
116
3.34k
#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
117
#endif
118
#ifndef INTERNAL_CATCH_UNIQUE_NAME
119
3.34k
#define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
120
#endif
121
122
#define ccv_sign_with_literal(string) \
123
  char INTERNAL_CATCH_UNIQUE_NAME(_ccv_identifier_)[] = (string); \
124
  size_t INTERNAL_CATCH_UNIQUE_NAME(_ccv_string_size_) = sizeof(INTERNAL_CATCH_UNIQUE_NAME(_ccv_identifier_));
125
126
#define ccv_sign_with_format(size, string, ...) \
127
  char INTERNAL_CATCH_UNIQUE_NAME(_ccv_identifier_)[(size)]; \
128
  memset(INTERNAL_CATCH_UNIQUE_NAME(_ccv_identifier_), 0, (size)); \
129
  snprintf(INTERNAL_CATCH_UNIQUE_NAME(_ccv_identifier_), (size), (string), ##__VA_ARGS__); \
130
  size_t INTERNAL_CATCH_UNIQUE_NAME(_ccv_string_size_) = (size);
131
132
6.20M
#define CCV_EOF_SIGN ((uint64_t)0)
133
134
#define ccv_declare_derived_signature(var, cond, submacro, ...) \
135
297k
  submacro; \
136
297k
  uint64_t var = (
cond16
) ?
ccv_cache_generate_signature(50
INTERNAL_CATCH_UNIQUE_NAME50
(_ccv_identifier_),
INTERNAL_CATCH_UNIQUE_NAME50
(_ccv_string_size_), __VA_ARGS__) :
0297k
;
137
138
/* the following macro enables more finer-control of ccv_declare_derived_signature, notably, it supports much more complex conditions:
139
 * ccv_declare_derived_signature_case(sig,
140
 * ccv_sign_with_format(64, "function_name(%f,%f,%f)", a_parameter, b_parameter, c_parameter),
141
 * ccv_sign_if(% the first custom condition %, a->sig, 0),
142
 * ccv_sign_if(% the second custom condition %, a->sig, b->sig, 0), ...)
143
 * the conditions will pass on, thus, there is no early termination, if the last condition meets, the signature will be determined
144
 * by the operation associated with the last condition */
145
146
#define ccv_sign_if(cond, ...) \
147
  if (cond) { \
148
    INTERNAL_CATCH_UNIQUE_NAME(_ccv_temp_sig_) = ccv_cache_generate_signature(INTERNAL_CATCH_UNIQUE_NAME(_ccv_identifier_), INTERNAL_CATCH_UNIQUE_NAME(_ccv_string_size_), __VA_ARGS__); \
149
  }
150
151
#define INTERNAL_EXPAND_MACRO_ARGUMENT_TO_LINE_N(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_30,_31,_32,_33,_34,_35,_36,_37,_38,_39,_40,_41,_42,_43,_44,_45,_46,_47,_48,_49,_50,_51,_52,_53,_54,_55,_56,_57,_58,_59,_60,_61,_62,_63,...) \
152
16.2k
  
_19.72k
;_2;_3;_4;_5;_6;_7;_8;_9;_10;_11;_12;_13;_14;_15;_16;_17;_18;_19;_20;_21;_22;_23;_24;_25;_26;_27;_28;_29;_30;_31;_32;_33;_34;_35;_36;_37;_38;_39;_40;_41;_42;_43;_44;_45;_46;_47;_48;_49;_50;_51;_52;_53;_54;_55;_56;_57;_58;_59;_60;_61;_62;_63
153
3.24k
#define INTERNAL_EXPAND_MACRO_ARGUMENT_TO_LINE(...) INTERNAL_EXPAND_MACRO_ARGUMENT_TO_LINE_N(__VA_ARGS__)
154
155
#define INTERNAL_SEQ_PADDING_LINE() ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
156
157
#define ccv_declare_derived_signature_case(var, submacro, ...) \
158
3.24k
  submacro; \
159
3.24k
  uint64_t INTERNAL_CATCH_UNIQUE_NAME(_ccv_temp_sig_) = 0; \
160
3.24k
  INTERNAL_EXPAND_MACRO_ARGUMENT_TO_LINE(__VA_ARGS__, INTERNAL_SEQ_PADDING_LINE()); \
161
3.24k
  uint64_t var = INTERNAL_CATCH_UNIQUE_NAME(_ccv_temp_sig_);
162
163
/* the macros enable us to preserve state of the program at any point in a structure way, this is borrowed from coroutine idea */
164
165
#define ccv_function_state_reserve_field int line_no;
166
#define ccv_function_state_begin(reader, s, file) (reader)((file), &(s)); switch ((s).line_no) { case 0:;
167
#define ccv_function_state_resume(writer, s, file) do { (s).line_no = __LINE__; (writer)(&(s), (file)); case __LINE__:; } while (0)
168
#define ccv_function_state_finish() }
169
170
/* the factor used to provide higher accuracy in integer type (all integer computation in some cases) */
171
0
#define _ccv_get_32s_value_1(ptr, i, factor) (((int*)(ptr))[(i)] << factor)
172
0
#define _ccv_get_32f_value_1(ptr, i, factor) ((float*)(ptr))[(i)]
173
1.72M
#define _ccv_get_64s_value_1(ptr, i, factor) (((int64_t*)(ptr))[(i)] << factor)
174
430k
#define _ccv_get_64f_value_1(ptr, i, factor) ((double*)(
ptr0
))[(
i0
)]
175
333k
#define _ccv_get_8u_value_1(ptr, i, factor) (((unsigned char*)(
ptr0
))[(
i0
)] << factor)
176
177
169M
#define _ccv_get_32s_value_0(ptr, i) (((int*)(ptr))[(i)])
178
991k
#define _ccv_get_32f_value_0(ptr, i) ((float*)(ptr))[(i)]
179
0
#define _ccv_get_64s_value_0(ptr, i) (((int64_t*)(ptr))[(i)])
180
134
#define _ccv_get_64f_value_0(ptr, i) ((double*)(ptr))[(i)]
181
74.0M
#define _ccv_get_8u_value_0(ptr, i) (((unsigned char*)(ptr))[(i)])
182
183
247M
#define _ccv_get_value_x(A, B, C, ...) C
184
185
169M
#define _ccv_get_32s_value(ptr, i, ...) _ccv_get_value_x(0, ##__VA_ARGS__, 
_ccv_get_32s_value_10
, _ccv_get_32s_value_0)(ptr, i, ##__VA_ARGS__)
186
991k
#define _ccv_get_32f_value(ptr, i, ...) _ccv_get_value_x(0, ##__VA_ARGS__, 
_ccv_get_32f_value_10
, _ccv_get_32f_value_0)(ptr, i, ##__VA_ARGS__)
187
1.72M
#define _ccv_get_64s_value(ptr, i, ...) _ccv_get_value_x(0, ##__VA_ARGS__, _ccv_get_64s_value_1, 
_ccv_get_64s_value_00
)(ptr, i, ##__VA_ARGS__)
188
430k
#define _ccv_get_64f_value(ptr, i, ...) _ccv_get_value_x(0, ##__VA_ARGS__, 
_ccv_get_64f_value_1430k
,
_ccv_get_64f_value_0134
)(ptr, i, ##__VA_ARGS__)
189
74.3M
#define _ccv_get_8u_value(ptr, i, ...) _ccv_get_value_x(0, ##__VA_ARGS__, 
_ccv_get_8u_value_1333k
,
_ccv_get_8u_value_074.0M
)(ptr, i, ##__VA_ARGS__)
190
191
147k
#define ccv_matrix_getter(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
192
3
  
case CCV_32S: { 2
block
(__VA_ARGS__, 0
_ccv_get_32s_value0
)
; break1
; } \
193
221k
  
case CCV_32F: { 147k
block147k
(__VA_ARGS__, 0
_ccv_get_32f_value)
; break8
; } \
194
1.72M
  
case CCV_64S: { 0
block1
(__VA_ARGS__, 0
_ccv_get_64s_value)
; break1
; } \
195
7
  
case CCV_64F: { 3
block5
(__VA_ARGS__, 0
_ccv_get_64f_value)
; break2
; } \
196
8.23M
  
default: { 42
block42
(__VA_ARGS__, 2
_ccv_get_8u_value)
; }28
} }
197
198
6
#define ccv_matrix_getter_a(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
199
0
  case CCV_32S: { block(__VA_ARGS__, _ccv_get_32s_value); break; } \
200
3
  
case CCV_32F: { 0
block(__VA_ARGS__,
_ccv_get_32f_value0
); break; } \
201
3
  
case CCV_64S: { 0
block0
(__VA_ARGS__,
_ccv_get_64s_value0
)
; break0
; } \
202
430k
  
case CCV_64F: { 1
block2
(__VA_ARGS__, _ccv_get_64f_value)
; break1
; } \
203
1
  default: { block(__VA_ARGS__, 
_ccv_get_8u_value0
); } } }
204
205
4
#define ccv_matrix_getter_b(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
206
0
  case CCV_32S: { block(__VA_ARGS__, _ccv_get_32s_value); break; } \
207
3
  case CCV_32F: { block(__VA_ARGS__, _ccv_get_32f_value); break; } \
208
3
  
case CCV_64S: { 0
block0
(__VA_ARGS__, _ccv_get_64s_value)
; break0
; } \
209
1
  case CCV_64F: { block(__VA_ARGS__, _ccv_get_64f_value); break; } \
210
1
  
default: { 0
block0
(__VA_ARGS__, _ccv_get_8u_value)
; }0
} }
211
212
28
#define ccv_matrix_getter_integer_only(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
213
4.00M
  
case CCV_32S: { 0
block8
(__VA_ARGS__, _ccv_get_32s_value)
; break8
; } \
214
8
  
case CCV_64S: { 0
block0
(__VA_ARGS__,
_ccv_get_64s_value0
)
; break0
; } \
215
58.3M
  
case CCV_8U: { 1
block20
(__VA_ARGS__, _ccv_get_8u_value)
; break19
; } \
216
19
  
default: { assert((type & CCV_32S) || (type & CCV_64S) || (type & CCV_8U)); }0
} }
217
218
#define ccv_matrix_getter_integer_only_a(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
219
  case CCV_32S: { block(__VA_ARGS__, _ccv_get_32s_value); break; } \
220
  case CCV_64S: { block(__VA_ARGS__, _ccv_get_64s_value); break; } \
221
  case CCV_8U: { block(__VA_ARGS__, _ccv_get_8u_value); break; } \
222
  default: { assert((type & CCV_32S) || (type & CCV_64S) || (type & CCV_8U)); } } }
223
224
#define ccv_matrix_getter_integer_only_b(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
225
  case CCV_32S: { block(__VA_ARGS__, _ccv_get_32s_value); break; } \
226
  case CCV_64S: { block(__VA_ARGS__, _ccv_get_64s_value); break; } \
227
  case CCV_8U: { block(__VA_ARGS__, _ccv_get_8u_value); break; } \
228
  default: { assert((type & CCV_32S) || (type & CCV_64S) || (type & CCV_8U)); } } }
229
230
0
#define ccv_matrix_getter_float_only(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
231
0
  case CCV_32F: { block(__VA_ARGS__, _ccv_get_32f_value); break; } \
232
0
  case CCV_64F: { block(__VA_ARGS__, _ccv_get_64f_value); break; } \
233
0
  default: { assert((type & CCV_32F) || (type & CCV_64F)); } } }
234
235
6
#define ccv_matrix_typeof(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
236
0
  case CCV_32S: { block(__VA_ARGS__, int); break; } \
237
5
  case CCV_32F: { block
(__VA_ARGS__, float)0
; break; } \
238
5
  
case CCV_64S: { 0
block0
(__VA_ARGS__, int64_t)0
; break0
; } \
239
1
  case CCV_64F: { block
(__VA_ARGS__, double)0
; break; } \
240
1
  
default: { 0
block0
(__VA_ARGS__, unsigned char)0
; }0
} }
241
242
#define ccv_matrix_typeof_a(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
243
  case CCV_32S: { block(__VA_ARGS__, int); break; } \
244
  case CCV_32F: { block(__VA_ARGS__, float); break; } \
245
  case CCV_64S: { block(__VA_ARGS__, int64_t); break; } \
246
  case CCV_64F: { block(__VA_ARGS__, double); break; } \
247
  default: { block(__VA_ARGS__, unsigned char); } } }
248
249
#define ccv_matrix_typeof_b(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
250
  case CCV_32S: { block(__VA_ARGS__, int); break; } \
251
  case CCV_32F: { block(__VA_ARGS__, float); break; } \
252
  case CCV_64S: { block(__VA_ARGS__, int64_t); break; } \
253
  case CCV_64F: { block(__VA_ARGS__, double); break; } \
254
  default: { block(__VA_ARGS__, unsigned char); } } }
255
256
3.88M
#define _ccv_set_32s_value_1(ptr, i, value, factor) (((int*)(ptr))[(i)] = (int)(value) >> factor)
257
7.44M
#define _ccv_set_32f_value_1(ptr, i, value, factor) (((float*)(ptr))[(i)] = (float)(value))
258
0
#define _ccv_set_64s_value_1(ptr, i, value, factor) (((int64_t*)(ptr))[(i)] = (int64_t)(value) >> factor)
259
0
#define _ccv_set_64f_value_1(ptr, i, value, factor) (((double*)(ptr))[(i)] = (double)(value))
260
1.44M
#define _ccv_set_8u_value_1(ptr, i, value, factor) (((unsigned char*)(ptr))[(i)] = ccv_clamp((int)(value) >> factor, 0, 255))
261
262
9.69M
#define _ccv_set_32s_value_0(ptr, i, value) (((int*)(ptr))[(i)] = (int)(
value0
))
263
91.9M
#define _ccv_set_32f_value_0(ptr, i, value) (((float*)(ptr))[(i)] = (float)(
value0
))
264
819k
#define _ccv_set_64s_value_0(ptr, i, value) (((int64_t*)(ptr))[(i)] = (int64_t)(
value0
))
265
1.12M
#define _ccv_set_64f_value_0(ptr, i, value) (((double*)(ptr))[(i)] = (double)(
value0
))
266
10.0M
#define _ccv_set_8u_value_0(ptr, i, value) (((unsigned char*)(ptr))[(i)] = ccv_clamp((int)(value), 0, 255))
267
268
126M
#define _ccv_set_value_x(A, B, C, ...) C
269
270
13.5M
#define _ccv_set_32s_value(ptr, i, value, ...) _ccv_set_value_x(0, ##__VA_ARGS__, 
_ccv_set_32s_value_13.88M
,
_ccv_set_32s_value_09.69M
)(ptr, i, value, ##__VA_ARGS__)
271
99.3M
#define _ccv_set_32f_value(ptr, i, value, ...) _ccv_set_value_x(0, ##__VA_ARGS__, 
_ccv_set_32f_value_17.44M
,
_ccv_set_32f_value_091.9M
)(ptr, i, value, ##__VA_ARGS__)
272
819k
#define _ccv_set_64s_value(ptr, i, value, ...) _ccv_set_value_x(0, ##__VA_ARGS__, 
_ccv_set_64s_value_10
, _ccv_set_64s_value_0)(ptr, i, value, ##__VA_ARGS__)
273
1.12M
#define _ccv_set_64f_value(ptr, i, value, ...) _ccv_set_value_x(0, ##__VA_ARGS__, 
_ccv_set_64f_value_10
, _ccv_set_64f_value_0)(ptr, i, value, ##__VA_ARGS__)
274
11.4M
#define _ccv_set_8u_value(ptr, i, value, ...) _ccv_set_value_x(0, ##__VA_ARGS__, 
_ccv_set_8u_value_11.44M
,
_ccv_set_8u_value_010.0M
)(ptr, i, value, ##__VA_ARGS__)
275
276
149k
#define ccv_matrix_setter(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
277
5.42k
  
case CCV_32S: { 6
block6
(__VA_ARGS__, _ccv_set_32s_value)
; break0
; } \
278
95.8M
  
case CCV_32F: { 22
block147k
(__VA_ARGS__, _ccv_set_32f_value)
; break146k
; } \
279
147k
  
case CCV_64S: { 0
block0
(__VA_ARGS__,
_ccv_set_64s_value0
)
; break0
; } \
280
290k
  
case CCV_64F: { 3
block6
(__VA_ARGS__, _ccv_set_64f_value)
; break3
; } \
281
5.13M
  
default: { 8
block8
(__VA_ARGS__, _ccv_set_8u_value)
; }4
} }
282
283
#define ccv_matrix_setter_a(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
284
  case CCV_32S: { block(__VA_ARGS__, _ccv_set_32s_value); break; } \
285
  case CCV_32F: { block(__VA_ARGS__, _ccv_set_32f_value); break; } \
286
  case CCV_64S: { block(__VA_ARGS__, _ccv_set_64s_value); break; } \
287
  case CCV_64F: { block(__VA_ARGS__, _ccv_set_64f_value); break; } \
288
  default: { block(__VA_ARGS__, _ccv_set_8u_value); } } }
289
290
2
#define ccv_matrix_setter_b(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
291
0
  case CCV_32S: { block(__VA_ARGS__, _ccv_set_32s_value); break; } \
292
0
  case CCV_32F: { block(__VA_ARGS__, _ccv_set_32f_value); break; } \
293
0
  case CCV_64S: { block(__VA_ARGS__, _ccv_set_64s_value); break; } \
294
0
  case CCV_64F: { block(__VA_ARGS__, _ccv_set_64f_value); break; } \
295
3.00M
  
default: { 2
block2
(__VA_ARGS__, _ccv_set_8u_value); } } }
296
297
0
#define ccv_matrix_setter_integer_only(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
298
0
  case CCV_32S: { block(__VA_ARGS__, _ccv_set_32s_value); break; } \
299
0
  case CCV_64S: { block(__VA_ARGS__, _ccv_set_64s_value); break; } \
300
0
  case CCV_8U: { block(__VA_ARGS__, _ccv_set_8u_value); break; } \
301
0
  default: { assert((type & CCV_32S) || (type & CCV_64S) || (type & CCV_8U)); } } }
302
303
#define ccv_matrix_setter_float_only(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
304
  case CCV_32F: { block(__VA_ARGS__, _ccv_set_32f_value); break; } \
305
  case CCV_64F: { block(__VA_ARGS__, _ccv_set_64f_value); break; } \
306
  default: { assert((type & CCV_32F) || (type & CCV_64F)); } } }
307
308
13
#define ccv_matrix_setter_getter(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
309
9.53k
  
case CCV_32S: { 4
block7
(__VA_ARGS__, _ccv_set_32s_value,
_ccv_get_32s_value0
)
; break3
; } \
310
6
  
case CCV_32F: { 3
block3
(__VA_ARGS__, _ccv_set_32f_value,
_ccv_get_32f_value0
)
; break0
; } \
311
851
  
case CCV_64S: { 0
block1
(__VA_ARGS__, _ccv_set_64s_value,
_ccv_get_64s_value0
)
; break1
; } \
312
126
  
case CCV_64F: { 1
block1
(__VA_ARGS__, _ccv_set_64f_value,
_ccv_get_64f_value112
)
; break0
; } \
313
2.40k
  
default: { 1
block1
(__VA_ARGS__, _ccv_set_8u_value,
_ccv_get_8u_value0
)
; }0
} }
314
315
#define ccv_matrix_setter_getter_a(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
316
  case CCV_32S: { block(__VA_ARGS__, _ccv_set_32s_value, _ccv_get_32s_value); break; } \
317
  case CCV_32F: { block(__VA_ARGS__, _ccv_set_32f_value, _ccv_get_32f_value); break; } \
318
  case CCV_64S: { block(__VA_ARGS__, _ccv_set_64s_value, _ccv_get_64s_value); break; } \
319
  case CCV_64F: { block(__VA_ARGS__, _ccv_set_64f_value, _ccv_get_64f_value); break; } \
320
  default: { block(__VA_ARGS__, _ccv_set_8u_value, _ccv_get_8u_value); } } }
321
322
#define ccv_matrix_setter_getter_b(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
323
  case CCV_32S: { block(__VA_ARGS__, _ccv_set_32s_value, _ccv_get_32s_value); break; } \
324
  case CCV_32F: { block(__VA_ARGS__, _ccv_set_32f_value, _ccv_get_32f_value); break; } \
325
  case CCV_64S: { block(__VA_ARGS__, _ccv_set_64s_value, _ccv_get_64s_value); break; } \
326
  case CCV_64F: { block(__VA_ARGS__, _ccv_set_64f_value, _ccv_get_64f_value); break; } \
327
  default: { block(__VA_ARGS__, _ccv_set_8u_value, _ccv_get_8u_value); } } }
328
329
1
#define ccv_matrix_setter_getter_integer_only(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
330
1.50M
  
case CCV_32S: { 0
block1
(__VA_ARGS__, _ccv_set_32s_value,
_ccv_get_32s_value0
)
; break1
; } \
331
1
  
case CCV_64S: { 0
block0
(__VA_ARGS__,
_ccv_set_64s_value0
,
_ccv_get_64s_value0
)
; break0
; } \
332
0
  case CCV_8U: { block(__VA_ARGS__, _ccv_set_8u_value, _ccv_get_8u_value); break; } \
333
0
  default: { assert((type & CCV_32S) || (type & CCV_64S) || (type & CCV_8U)); } } }
334
335
0
#define ccv_matrix_setter_getter_float_only(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
336
0
  case CCV_32F: { block(__VA_ARGS__, _ccv_set_32f_value, _ccv_get_32f_value); break; } \
337
0
  case CCV_64F: { block(__VA_ARGS__, _ccv_set_64f_value, _ccv_get_64f_value); break; } \
338
0
  default: { assert((type & CCV_32F) || (type & CCV_64F)); } } }
339
340
#define ccv_matrix_typeof_getter(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
341
  case CCV_32S: { block(__VA_ARGS__, int, _ccv_get_32s_value); break; } \
342
  case CCV_32F: { block(__VA_ARGS__, float, _ccv_get_32f_value); break; } \
343
  case CCV_64S: { block(__VA_ARGS__, int64_t, _ccv_get_64s_value); break; } \
344
  case CCV_64F: { block(__VA_ARGS__, double, _ccv_get_64f_value); break; } \
345
  default: { block(__VA_ARGS__, unsigned char, _ccv_get_8u_value); } } }
346
347
#define ccv_matrix_typeof_getter_a(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
348
  case CCV_32S: { block(__VA_ARGS__, int, _ccv_get_32s_value); break; } \
349
  case CCV_32F: { block(__VA_ARGS__, float, _ccv_get_32f_value); break; } \
350
  case CCV_64S: { block(__VA_ARGS__, int64_t, _ccv_get_64s_value); break; } \
351
  case CCV_64F: { block(__VA_ARGS__, double, _ccv_get_64f_value); break; } \
352
  default: { block(__VA_ARGS__, unsigned char, _ccv_get_8u_value); } } }
353
354
#define ccv_matrix_typeof_getter_b(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
355
  case CCV_32S: { block(__VA_ARGS__, int, _ccv_get_32s_value); break; } \
356
  case CCV_32F: { block(__VA_ARGS__, float, _ccv_get_32f_value); break; } \
357
  case CCV_64S: { block(__VA_ARGS__, int64_t, _ccv_get_64s_value); break; } \
358
  case CCV_64F: { block(__VA_ARGS__, double, _ccv_get_64f_value); break; } \
359
  default: { block(__VA_ARGS__, unsigned char, _ccv_get_8u_value); } } }
360
361
1
#define ccv_matrix_typeof_setter(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
362
4
  
case CCV_32S: { 1
block1
(__VA_ARGS__, int, _ccv_set_32s_value); break; } \
363
0
  case CCV_32F: { block(__VA_ARGS__, float, _ccv_set_32f_value); break; } \
364
0
  case CCV_64S: { block(__VA_ARGS__, int64_t, _ccv_set_64s_value); break; } \
365
0
  case CCV_64F: { block(__VA_ARGS__, double, _ccv_set_64f_value); break; } \
366
0
  default: { block(__VA_ARGS__, unsigned char, _ccv_set_8u_value); } } }
367
368
#define ccv_matrix_typeof_setter_a(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
369
  case CCV_32S: { block(__VA_ARGS__, int, _ccv_set_32s_value); break; } \
370
  case CCV_32F: { block(__VA_ARGS__, float, _ccv_set_32f_value); break; } \
371
  case CCV_64S: { block(__VA_ARGS__, int64_t, _ccv_set_64s_value); break; } \
372
  case CCV_64F: { block(__VA_ARGS__, double, _ccv_set_64f_value); break; } \
373
  default: { block(__VA_ARGS__, unsigned char, _ccv_set_8u_value); } } }
374
375
#define ccv_matrix_typeof_setter_b(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
376
  case CCV_32S: { block(__VA_ARGS__, int, _ccv_set_32s_value); break; } \
377
  case CCV_32F: { block(__VA_ARGS__, float, _ccv_set_32f_value); break; } \
378
  case CCV_64S: { block(__VA_ARGS__, int64_t, _ccv_set_64s_value); break; } \
379
  case CCV_64F: { block(__VA_ARGS__, double, _ccv_set_64f_value); break; } \
380
  default: { block(__VA_ARGS__, unsigned char, _ccv_set_8u_value); } } }
381
382
6
#define ccv_matrix_typeof_setter_getter(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
383
86.6M
  
case CCV_32S: { 2
block4
(__VA_ARGS__, int,
_ccv_set_32s_value3.89M
, _ccv_get_32s_value)
; break2
; } \
384
549k
  
case CCV_32F: { 0
block2
(__VA_ARGS__, float,
_ccv_set_32f_value520k
, _ccv_get_32f_value)
; break2
; } \
385
2
  
case CCV_64S: { 0
block0
(__VA_ARGS__, int64_t,
_ccv_set_64s_value0
,
_ccv_get_64s_value0
)
; break0
; } \
386
0
  case CCV_64F: { block(__VA_ARGS__, double, _ccv_set_64f_value, _ccv_get_64f_value); break; } \
387
0
  default: { block(__VA_ARGS__, unsigned char, _ccv_set_8u_value, _ccv_get_8u_value); } } }
388
389
#define ccv_matrix_typeof_setter_getter_a(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
390
  case CCV_32S: { block(__VA_ARGS__, int, _ccv_set_32s_value, _ccv_get_32s_value); break; } \
391
  case CCV_32F: { block(__VA_ARGS__, float, _ccv_set_32f_value, _ccv_get_32f_value); break; } \
392
  case CCV_64S: { block(__VA_ARGS__, int64_t, _ccv_set_64s_value, _ccv_get_64s_value); break; } \
393
  case CCV_64F: { block(__VA_ARGS__, double, _ccv_set_64f_value, _ccv_get_64f_value); break; } \
394
  default: { block(__VA_ARGS__, unsigned char, _ccv_set_8u_value, _ccv_get_8u_value); } } }
395
396
#define ccv_matrix_typeof_setter_getter_b(type, block, ...) { switch (CCV_GET_DATA_TYPE(type)) { \
397
  case CCV_32S: { block(__VA_ARGS__, int, _ccv_set_32s_value, _ccv_get_32s_value); break; } \
398
  case CCV_32F: { block(__VA_ARGS__, float, _ccv_set_32f_value, _ccv_get_32f_value); break; } \
399
  case CCV_64S: { block(__VA_ARGS__, int64_t, _ccv_set_64s_value, _ccv_get_64s_value); break; } \
400
  case CCV_64F: { block(__VA_ARGS__, double, _ccv_set_64f_value, _ccv_get_64f_value); break; } \
401
  default: { block(__VA_ARGS__, unsigned char, _ccv_set_8u_value, _ccv_get_8u_value); } } }
402
403
/****************************************************************************************\
404
405
  Generic implementation of QuickSort algorithm.
406
  ----------------------------------------------
407
  Using this macro user can declare customized sort function that can be much faster
408
  than built-in qsort function because of lower overhead on elements
409
  comparison and exchange. The macro takes less_than (or LT) argument - a macro or function
410
  that takes 2 arguments returns non-zero if the first argument should be before the second
411
  one in the sorted sequence and zero otherwise.
412
413
  Example:
414
415
    Suppose that the task is to sort points by ascending of y coordinates and if
416
    y's are equal x's should ascend.
417
418
    The code is:
419
    ------------------------------------------------------------------------------
420
           #define cmp_pts( pt1, pt2 ) \
421
               ((pt1).y < (pt2).y || ((pt1).y < (pt2).y && (pt1).x < (pt2).x))
422
423
           [static] CV_IMPLEMENT_QSORT( icvSortPoints, CvPoint, cmp_pts )
424
    ------------------------------------------------------------------------------
425
426
    After that the function "void icvSortPoints( CvPoint* array, size_t total, int aux );"
427
    is available to user.
428
429
  aux is an additional parameter, which can be used when comparing elements.
430
  The current implementation was derived from *BSD system qsort():
431
432
    * Copyright (c) 1992, 1993
433
    *  The Regents of the University of California.  All rights reserved.
434
    *
435
    * Redistribution and use in source and binary forms, with or without
436
    * modification, are permitted provided that the following conditions
437
    * are met:
438
    * 1. Redistributions of source code must retain the above copyright
439
    *    notice, this list of conditions and the following disclaimer.
440
    * 2. Redistributions in binary form must reproduce the above copyright
441
    *    notice, this list of conditions and the following disclaimer in the
442
    *    documentation and/or other materials provided with the distribution.
443
    * 3. All advertising materials mentioning features or use of this software
444
    *    must display the following acknowledgement:
445
    *  This product includes software developed by the University of
446
    *  California, Berkeley and its contributors.
447
    * 4. Neither the name of the University nor the names of its contributors
448
    *    may be used to endorse or promote products derived from this software
449
    *    without specific prior written permission.
450
    *
451
    * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
452
    * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
453
    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
454
    * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
455
    * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
456
    * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
457
    * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
458
    * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
459
    * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
460
    * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
461
    * SUCH DAMAGE.
462
463
\****************************************************************************************/
464
465
770k
#define CCV_SWAP(a,b,t) ((t) = (a), (a) = (b), (b) = (t))
466
467
#define CCV_IMPLEMENT_QSORT_EX(func_name, T, LT, swap_func, user_data_type)                     \
468
29.1k
void func_name(T *array, size_t total, user_data_type aux)                                      \
469
29.1k
{                                                                                               \
470
29.1k
    int isort_thresh = 7;                                                                       \
471
29.1k
    T t;                                                                                        \
472
29.1k
    int sp = 0;                                                                                 \
473
29.1k
                                                                                                \
474
29.1k
    struct                                                                                      \
475
29.1k
    {                                                                                           \
476
29.1k
        T *lb;                                                                                  \
477
29.1k
        T *ub;                                                                                  \
478
29.1k
    }                                                                                           \
479
29.1k
    stack[48];                                                                                  \
480
29.1k
                                                                                                \
481
29.1k
    if( total <= 1 )                                                                            \
482
29.1k
        
return5.36k
; \
483
29.1k
                                                                                                \
484
29.1k
    stack[0].lb = array;                                                                        \
485
23.8k
    stack[0].ub = array + (total - 1);                                                          \
486
23.8k
                                                                                                \
487
51.6k
    while( sp >= 0 )                                                                            \
488
27.8k
    {                                                                                           \
489
27.8k
        T* left = stack[sp].lb;                                                                 \
490
27.8k
        T* right = stack[sp--].ub;                                                              \
491
27.8k
                                                                                                \
492
27.8k
        for(;;)                                                                                 \
493
32.1k
        {                                                                                       \
494
32.1k
            int i, n = (int)(right - left) + 1, m;                                              \
495
32.1k
            T* ptr;                                                                             \
496
32.1k
            T* ptr2;                                                                            \
497
32.1k
                                                                                                \
498
32.1k
            if( n <= isort_thresh )                                                             \
499
32.1k
            {                                                                                   \
500
27.8k
            insert_sort:                                                                        \
501
113k
                for( ptr = left + 1; ptr <= right; 
ptr++85.8k
) \
502
85.8k
                {                                                                               \
503
217k
                    for( ptr2 = ptr; ptr2 > left && 
LT169k
(ptr2[0],ptr2[-1], aux);
ptr2--131k
) \
504
85.8k
                        
swap_func85.8k
( ptr2[0], ptr2[-1], array, aux, t ); \
505
85.8k
                }                                                                               \
506
27.8k
                break;                                                                          \
507
27.7k
            }                                                                                   \
508
32.1k
            else                                                                                \
509
32.1k
            {                                                                                   \
510
4.39k
                T* left0;                                                                       \
511
4.39k
                T* left1;                                                                       \
512
4.39k
                T* right0;                                                                      \
513
4.39k
                T* right1;                                                                      \
514
4.39k
                T* pivot;                                                                       \
515
4.39k
                T* a;                                                                           \
516
4.39k
                T* b;                                                                           \
517
4.39k
                T* c;                                                                           \
518
4.39k
                int swap_cnt = 0;                                                               \
519
4.39k
                                                                                                \
520
4.39k
                left0 = left;                                                                   \
521
4.39k
                right0 = right;                                                                 \
522
4.39k
                pivot = left + (n/2);                                                           \
523
4.39k
                                                                                                \
524
4.39k
                if( n > 40 )                                                                    \
525
4.39k
                {                                                                               \
526
46
                    int d = n / 8;                                                              \
527
46
                    a = left, b = left + d, c = left + 2*d;                                     \
528
46
                    left = LT(*a, *b, aux) ? 
(36
LT36
(*b, *c, aux) ?
b8
:
(28
LT28
(*a, *c, aux) ?
c26
:
a2
)) \
529
46
                                      : 
(10
LT10
(*c, *b, aux) ?
b4
:
(6
LT6
(*a, *c, aux) ?
a4
:
c2
)); \
530
46
                                                                                                \
531
46
                    a = pivot - d, b = pivot, c = pivot + d;                                    \
532
46
                    pivot = LT(*a, *b, aux) ? 
(15
LT15
(*b, *c, aux) ?
b8
:
(7
LT7
(*a, *c, aux) ?
c5
:
a2
)) \
533
46
                                      : 
(31
LT31
(*c, *b, aux) ?
b2
:
(29
LT29
(*a, *c, aux) ?
a2
:
c27
)); \
534
46
                                                                                                \
535
46
                    a = right - 2*d, b = right - d, c = right;                                  \
536
46
                    right = LT(*a, *b, aux) ? 
(36
LT36
(*b, *c, aux) ?
b30
:
(6
LT6
(*a, *c, aux) ?
c2
:
a4
)) \
537
46
                                      : 
(10
LT10
(*c, *b, aux) ?
b6
:
(4
LT4
(*a, *c, aux) ?
a0
:
c4
)); \
538
46
                }                                                                               \
539
4.39k
                                                                                                \
540
4.39k
                a = left, b = pivot, c = right;                                                 \
541
4.39k
                pivot = LT(*a, *b, aux) ? 
(2.59k
LT2.59k
(*b, *c, aux) ?
b2.01k
:
(579
LT579
(*a, *c, aux) ?
c416
:
a163
)) \
542
4.39k
                                   : 
(1.80k
LT1.80k
(*c, *b, aux) ?
b648
:
(1.15k
LT1.15k
(*a, *c, aux) ?
a611
:
c542
)); \
543
4.39k
                if( pivot != left0 )                                                            \
544
4.39k
                {                                                                               \
545
3.62k
                    swap_func( *pivot, *left0, array, aux, t );                                 \
546
3.62k
                    pivot = left0;                                                              \
547
3.62k
                }                                                                               \
548
4.39k
                left = left1 = left0 + 1;                                                       \
549
4.39k
                right = right1 = right0;                                                        \
550
4.39k
                                                                                                \
551
4.39k
                for(;;)                                                                         \
552
23.2k
                {                                                                               \
553
36.4k
                    while( left <= right && 
!32.9k
LT32.9k
(*pivot, *left, aux) ) \
554
23.2k
                    {                                                                           \
555
13.1k
                        if( !LT(*left, *pivot, aux) )                                           \
556
13.1k
                        {                                                                       \
557
255
                            if( left > left1 )                                                  \
558
255
                                swap_func( *left1, *left, array, aux, t );                      \
559
255
                            swap_cnt = 1;                                                       \
560
255
                            left1++;                                                            \
561
255
                        }                                                                       \
562
13.1k
                        left++;                                                                 \
563
13.1k
                    }                                                                           \
564
23.2k
                                                                                                \
565
33.3k
                    while( left <= right && 
!28.9k
LT28.9k
(*right, *pivot, aux) ) \
566
23.2k
                    {                                                                           \
567
10.0k
                        if( !LT(*pivot, *right, aux) )                                          \
568
10.0k
                        {                                                                       \
569
179
                            if( right < right1 )                                                \
570
179
                                swap_func( *right1, *right, array, aux, t );                    \
571
179
                            swap_cnt = 1;                                                       \
572
179
                            right1--;                                                           \
573
179
                        }                                                                       \
574
10.0k
                        right--;                                                                \
575
10.0k
                    }                                                                           \
576
23.2k
                                                                                                \
577
23.2k
                    if( left > right )                                                          \
578
23.2k
                        
break4.39k
; \
579
23.2k
                    
swap_func18.8k
( *left, *right, array, aux, t ); \
580
18.8k
                    swap_cnt = 1;                                                               \
581
18.8k
                    left++;                                                                     \
582
18.8k
                    right--;                                                                    \
583
18.8k
                }                                                                               \
584
4.39k
                                                                                                \
585
4.39k
                if( swap_cnt == 0 )                                                             \
586
4.39k
                {                                                                               \
587
106
                    left = left0, right = right0;                                               \
588
106
                    goto insert_sort;                                                           \
589
106
                }                                                                               \
590
4.39k
                                                                                                \
591
4.39k
                
n = 4.28k
ccv_min4.28k
( (int)(left1 - left0), (int)(left - left1) ); \
592
8.73k
                for( i = 0; i < n; 
i++4.44k
) \
593
4.28k
                    swap_func( left0[i], left[i-n], array, aux, t );                            \
594
4.28k
                                                                                                \
595
4.28k
                n = ccv_min( (int)(right0 - right1), (int)(right1 - right) );                   \
596
4.46k
                for( i = 0; i < n; 
i++176
) \
597
4.28k
                    
swap_func4.28k
( left[i], right0[i-n+1], array, aux, t ); \
598
4.28k
                n = (int)(left - left1);                                                        \
599
4.28k
                m = (int)(right1 - right);                                                      \
600
4.28k
                if( n > 1 )                                                                     \
601
4.28k
                {                                                                               \
602
4.19k
                    if( m > 1 )                                                                 \
603
4.19k
                    {                                                                           \
604
4.04k
                        if( n > m )                                                             \
605
4.04k
                        {                                                                       \
606
1.42k
                            stack[++sp].lb = left0;                                             \
607
1.42k
                            stack[sp].ub = left0 + n - 1;                                       \
608
1.42k
                            left = right0 - m + 1, right = right0;                              \
609
1.42k
                        }                                                                       \
610
4.04k
                        else                                                                    \
611
4.04k
                        {                                                                       \
612
2.62k
                            stack[++sp].lb = right0 - m + 1;                                    \
613
2.62k
                            stack[sp].ub = right0;                                              \
614
2.62k
                            left = left0, right = left0 + n - 1;                                \
615
2.62k
                        }                                                                       \
616
4.04k
                    }                                                                           \
617
4.19k
                    else                                                                        \
618
4.19k
                        
left = left0, right = left0 + n - 1144
; \
619
4.19k
                }                                                                               \
620
4.28k
                else 
if( 94
m > 194
) \
621
94
                    
left = right0 - m + 1, right = right090
; \
622
94
                else                                                                            \
623
94
                    
break4
; \
624
4.28k
            }                                                                                   \
625
32.1k
        }                                                                                       \
626
27.8k
    }                                                                                           \
627
23.8k
}
Unexecuted instantiation: ccv_util.c:_ccv_indice_uchar_sort
Unexecuted instantiation: ccv_util.c:_ccv_indice_int_sort
ccv_util.c:_ccv_indice_float_sort
Line
Count
Source
468
3
void func_name(T *array, size_t total, user_data_type aux)                                      \
469
3
{                                                                                               \
470
3
    int isort_thresh = 7;                                                                       \
471
3
    T t;                                                                                        \
472
3
    int sp = 0;                                                                                 \
473
3
                                                                                                \
474
3
    struct                                                                                      \
475
3
    {                                                                                           \
476
3
        T *lb;                                                                                  \
477
3
        T *ub;                                                                                  \
478
3
    }                                                                                           \
479
3
    stack[48];                                                                                  \
480
3
                                                                                                \
481
3
    if( total <= 1 )                                                                            \
482
3
        
return1
; \
483
3
                                                                                                \
484
3
    stack[0].lb = array;                                                                        \
485
2
    stack[0].ub = array + (total - 1);                                                          \
486
2
                                                                                                \
487
4
    while( sp >= 0 )                                                                            \
488
2
    {                                                                                           \
489
2
        T* left = stack[sp].lb;                                                                 \
490
2
        T* right = stack[sp--].ub;                                                              \
491
2
                                                                                                \
492
2
        for(;;)                                                                                 \
493
2
        {                                                                                       \
494
2
            int i, n = (int)(right - left) + 1, m;                                              \
495
2
            T* ptr;                                                                             \
496
2
            T* ptr2;                                                                            \
497
2
                                                                                                \
498
2
            if( n <= isort_thresh )                                                             \
499
2
            {                                                                                   \
500
2
            insert_sort:                                                                        \
501
5
                for( ptr = left + 1; ptr <= right; 
ptr++3
) \
502
3
                {                                                                               \
503
3
                    for( ptr2 = ptr; ptr2 > left && LT(ptr2[0],ptr2[-1], aux); 
ptr2--0
) \
504
3
                        
swap_func0
( ptr2[0], ptr2[-1], array, aux, t ); \
505
3
                }                                                                               \
506
2
                break;                                                                          \
507
2
            }                                                                                   \
508
2
            else                                                                                \
509
2
            {                                                                                   \
510
0
                T* left0;                                                                       \
511
0
                T* left1;                                                                       \
512
0
                T* right0;                                                                      \
513
0
                T* right1;                                                                      \
514
0
                T* pivot;                                                                       \
515
0
                T* a;                                                                           \
516
0
                T* b;                                                                           \
517
0
                T* c;                                                                           \
518
0
                int swap_cnt = 0;                                                               \
519
0
                                                                                                \
520
0
                left0 = left;                                                                   \
521
0
                right0 = right;                                                                 \
522
0
                pivot = left + (n/2);                                                           \
523
0
                                                                                                \
524
0
                if( n > 40 )                                                                    \
525
0
                {                                                                               \
526
0
                    int d = n / 8;                                                              \
527
0
                    a = left, b = left + d, c = left + 2*d;                                     \
528
0
                    left = LT(*a, *b, aux) ? (LT(*b, *c, aux) ? b : (LT(*a, *c, aux) ? c : a))  \
529
0
                                      : (LT(*c, *b, aux) ? b : (LT(*a, *c, aux) ? a : c));      \
530
0
                                                                                                \
531
0
                    a = pivot - d, b = pivot, c = pivot + d;                                    \
532
0
                    pivot = LT(*a, *b, aux) ? (LT(*b, *c, aux) ? b : (LT(*a, *c, aux) ? c : a)) \
533
0
                                      : (LT(*c, *b, aux) ? b : (LT(*a, *c, aux) ? a : c));      \
534
0
                                                                                                \
535
0
                    a = right - 2*d, b = right - d, c = right;                                  \
536
0
                    right = LT(*a, *b, aux) ? (LT(*b, *c, aux) ? b : (LT(*a, *c, aux) ? c : a)) \
537
0
                                      : (LT(*c, *b, aux) ? b : (LT(*a, *c, aux) ? a : c));      \
538
0
                }                                                                               \
539
0
                                                                                                \
540
0
                a = left, b = pivot, c = right;                                                 \
541
0
                pivot = LT(*a, *b, aux) ? (LT(*b, *c, aux) ? b : (LT(*a, *c, aux) ? c : a))     \
542
0
                                   : (LT(*c, *b, aux) ? b : (LT(*a, *c, aux) ? a : c));         \
543
0
                if( pivot != left0 )                                                            \
544
0
                {                                                                               \
545
0
                    swap_func( *pivot, *left0, array, aux, t );                                 \
546
0
                    pivot = left0;                                                              \
547
0
                }                                                                               \
548
0
                left = left1 = left0 + 1;                                                       \
549
0
                right = right1 = right0;                                                        \
550
0
                                                                                                \
551
0
                for(;;)                                                                         \
552
0
                {                                                                               \
553
0
                    while( left <= right && !LT(*pivot, *left, aux) )                           \
554
0
                    {                                                                           \
555
0
                        if( !LT(*left, *pivot, aux) )                                           \
556
0
                        {                                                                       \
557
0
                            if( left > left1 )                                                  \
558
0
                                swap_func( *left1, *left, array, aux, t );                      \
559
0
                            swap_cnt = 1;                                                       \
560
0
                            left1++;                                                            \
561
0
                        }                                                                       \
562
0
                        left++;                                                                 \
563
0
                    }                                                                           \
564
0
                                                                                                \
565
0
                    while( left <= right && !LT(*right, *pivot, aux) )                          \
566
0
                    {                                                                           \
567
0
                        if( !LT(*pivot, *right, aux) )                                          \
568
0
                        {                                                                       \
569
0
                            if( right < right1 )                                                \
570
0
                                swap_func( *right1, *right, array, aux, t );                    \
571
0
                            swap_cnt = 1;                                                       \
572
0
                            right1--;                                                           \
573
0
                        }                                                                       \
574
0
                        right--;                                                                \
575
0
                    }                                                                           \
576
0
                                                                                                \
577
0
                    if( left > right )                                                          \
578
0
                        break;                                                                  \
579
0
                    swap_func( *left, *right, array, aux, t );                                  \
580
0
                    swap_cnt = 1;                                                               \
581
0
                    left++;                                                                     \
582
0
                    right--;                                                                    \
583
0
                }                                                                               \
584
0
                                                                                                \
585
0
                if( swap_cnt == 0 )                                                             \
586
0
                {                                                                               \
587
0
                    left = left0, right = right0;                                               \
588
0
                    goto insert_sort;                                                           \
589
0
                }                                                                               \
590
0
                                                                                                \
591
0
                n = ccv_min( (int)(left1 - left0), (int)(left - left1) );                       \
592
0
                for( i = 0; i < n; i++ )                                                        \
593
0
                    swap_func( left0[i], left[i-n], array, aux, t );                            \
594
0
                                                                                                \
595
0
                n = ccv_min( (int)(right0 - right1), (int)(right1 - right) );                   \
596
0
                for( i = 0; i < n; i++ )                                                        \
597
0
                    swap_func( left[i], right0[i-n+1], array, aux, t );                         \
598
0
                n = (int)(left - left1);                                                        \
599
0
                m = (int)(right1 - right);                                                      \
600
0
                if( n > 1 )                                                                     \
601
0
                {                                                                               \
602
0
                    if( m > 1 )                                                                 \
603
0
                    {                                                                           \
604
0
                        if( n > m )                                                             \
605
0
                        {                                                                       \
606
0
                            stack[++sp].lb = left0;                                             \
607
0
                            stack[sp].ub = left0 + n - 1;                                       \
608
0
                            left = right0 - m + 1, right = right0;                              \
609
0
                        }                                                                       \
610
0
                        else                                                                    \
611
0
                        {                                                                       \
612
0
                            stack[++sp].lb = right0 - m + 1;                                    \
613
0
                            stack[sp].ub = right0;                                              \
614
0
                            left = left0, right = left0 + n - 1;                                \
615
0
                        }                                                                       \
616
0
                    }                                                                           \
617
0
                    else                                                                        \
618
0
                        left = left0, right = left0 + n - 1;                                    \
619
0
                }                                                                               \
620
0
                else if( m > 1 )                                                                \
621
0
                    left = right0 - m + 1, right = right0;                                      \
622
0
                else                                                                            \
623
0
                    break;                                                                      \
624
0
            }                                                                                   \
625
2
        }                                                                                       \
626
2
    }                                                                                           \
627
2
}
Unexecuted instantiation: ccv_util.c:_ccv_indice_double_sort
ccv_nnc_graph.c:_ccv_nnc_tensor_dot_sort_by_ptr
Line
Count
Source
468
169
void func_name(T *array, size_t total, user_data_type aux)                                      \
469
169
{                                                                                               \
470
169
    int isort_thresh = 7;                                                                       \
471
169
    T t;                                                                                        \
472
169
    int sp = 0;                                                                                 \
473
169
                                                                                                \
474
169
    struct                                                                                      \
475
169
    {                                                                                           \
476
169
        T *lb;                                                                                  \
477
169
        T *ub;                                                                                  \
478
169
    }                                                                                           \
479
169
    stack[48];                                                                                  \
480
169
                                                                                                \
481
169
    if( total <= 1 )                                                                            \
482
169
        
return22
; \
483
169
                                                                                                \
484
169
    stack[0].lb = array;                                                                        \
485
147
    stack[0].ub = array + (total - 1);                                                          \
486
147
                                                                                                \
487
460
    while( sp >= 0 )                                                                            \
488
313
    {                                                                                           \
489
313
        T* left = stack[sp].lb;                                                                 \
490
313
        T* right = stack[sp--].ub;                                                              \
491
313
                                                                                                \
492
313
        for(;;)                                                                                 \
493
537
        {                                                                                       \
494
537
            int i, n = (int)(right - left) + 1, m;                                              \
495
537
            T* ptr;                                                                             \
496
537
            T* ptr2;                                                                            \
497
537
                                                                                                \
498
537
            if( n <= isort_thresh )                                                             \
499
537
            {                                                                                   \
500
309
            insert_sort:                                                                        \
501
1.29k
                for( ptr = left + 1; ptr <= right; 
ptr++989
) \
502
989
                {                                                                               \
503
1.88k
                    for( ptr2 = ptr; ptr2 > left && 
LT1.68k
(ptr2[0],ptr2[-1], aux);
ptr2--892
) \
504
989
                        swap_func( ptr2[0], ptr2[-1], array, aux, t );                          \
505
989
                }                                                                               \
506
309
                break;                                                                          \
507
305
            }                                                                                   \
508
537
            else                                                                                \
509
537
            {                                                                                   \
510
232
                T* left0;                                                                       \
511
232
                T* left1;                                                                       \
512
232
                T* right0;                                                                      \
513
232
                T* right1;                                                                      \
514
232
                T* pivot;                                                                       \
515
232
                T* a;                                                                           \
516
232
                T* b;                                                                           \
517
232
                T* c;                                                                           \
518
232
                int swap_cnt = 0;                                                               \
519
232
                                                                                                \
520
232
                left0 = left;                                                                   \
521
232
                right0 = right;                                                                 \
522
232
                pivot = left + (n/2);                                                           \
523
232
                                                                                                \
524
232
                if( n > 40 )                                                                    \
525
232
                {                                                                               \
526
19
                    int d = n / 8;                                                              \
527
19
                    a = left, b = left + d, c = left + 2*d;                                     \
528
19
                    left = LT(*a, *b, aux) ? 
(12
LT12
(*b, *c, aux) ?
b8
:
(4
LT4
(*a, *c, aux) ?
c2
:
a2
)) \
529
19
                                      : 
(7
LT7
(*c, *b, aux) ?
b3
:
(4
LT4
(*a, *c, aux) ?
a4
:
c0
)); \
530
19
                                                                                                \
531
19
                    a = pivot - d, b = pivot, c = pivot + d;                                    \
532
19
                    pivot = LT(*a, *b, aux) ? 
(13
LT13
(*b, *c, aux) ?
b6
:
(7
LT7
(*a, *c, aux) ?
c5
:
a2
)) \
533
19
                                      : 
(6
LT6
(*c, *b, aux) ?
b1
:
(5
LT5
(*a, *c, aux) ?
a2
:
c3
)); \
534
19
                                                                                                \
535
19
                    a = right - 2*d, b = right - d, c = right;                                  \
536
19
                    right = LT(*a, *b, aux) ? 
(10
LT10
(*b, *c, aux) ?
b4
:
(6
LT6
(*a, *c, aux) ?
c2
:
a4
)) \
537
19
                                      : 
(9
LT9
(*c, *b, aux) ?
b5
:
(4
LT4
(*a, *c, aux) ?
a0
:
c4
)); \
538
19
                }                                                                               \
539
232
                                                                                                \
540
232
                a = left, b = pivot, c = right;                                                 \
541
232
                pivot = LT(*a, *b, aux) ? 
(95
LT95
(*b, *c, aux) ?
b18
:
(77
LT77
(*a, *c, aux) ?
c41
:
a36
)) \
542
232
                                   : 
(137
LT137
(*c, *b, aux) ?
b27
:
(110
LT110
(*a, *c, aux) ?
a30
:
c80
)); \
543
232
                if( pivot != left0 )                                                            \
544
232
                {                                                                               \
545
172
                    swap_func( *pivot, *left0, array, aux, t );                                 \
546
172
                    pivot = left0;                                                              \
547
172
                }                                                                               \
548
232
                left = left1 = left0 + 1;                                                       \
549
232
                right = right1 = right0;                                                        \
550
232
                                                                                                \
551
232
                for(;;)                                                                         \
552
964
                {                                                                               \
553
2.31k
                    while( left <= right && 
!2.20k
LT2.20k
(*pivot, *left, aux) ) \
554
1.35k
                    {                                                                           \
555
1.35k
                        if( !LT(*left, *pivot, aux) )                                           \
556
1.35k
                        {                                                                       \
557
255
                            if( left > left1 )                                                  \
558
255
                                swap_func( *left1, *left, array, aux, t );                      \
559
255
                            swap_cnt = 1;                                                       \
560
255
                            left1++;                                                            \
561
255
                        }                                                                       \
562
1.35k
                        left++;                                                                 \
563
1.35k
                    }                                                                           \
564
964
                                                                                                \
565
2.58k
                    while( left <= right && 
!2.34k
LT2.34k
(*right, *pivot, aux) ) \
566
1.61k
                    {                                                                           \
567
1.61k
                        if( !LT(*pivot, *right, aux) )                                          \
568
1.61k
                        {                                                                       \
569
179
                            if( right < right1 )                                                \
570
179
                                swap_func( *right1, *right, array, aux, t );                    \
571
179
                            swap_cnt = 1;                                                       \
572
179
                            right1--;                                                           \
573
179
                        }                                                                       \
574
1.61k
                        right--;                                                                \
575
1.61k
                    }                                                                           \
576
964
                                                                                                \
577
964
                    if( left > right )                                                          \
578
964
                        
break232
; \
579
964
                    
swap_func732
( *left, *right, array, aux, t ); \
580
732
                    swap_cnt = 1;                                                               \
581
732
                    left++;                                                                     \
582
732
                    right--;                                                                    \
583
732
                }                                                                               \
584
232
                                                                                                \
585
232
                if( swap_cnt == 0 )                                                             \
586
232
                {                                                                               \
587
4
                    left = left0, right = right0;                                               \
588
4
                    goto insert_sort;                                                           \
589
4
                }                                                                               \
590
232
                                                                                                \
591
232
                
n = 228
ccv_min228
( (int)(left1 - left0), (int)(left - left1) ); \
592
617
                for( i = 0; i < n; 
i++389
) \
593
228
                    swap_func( left0[i], left[i-n], array, aux, t );                            \
594
228
                                                                                                \
595
228
                n = ccv_min( (int)(right0 - right1), (int)(right1 - right) );                   \
596
404
                for( i = 0; i < n; 
i++176
) \
597
228
                    swap_func( left[i], right0[i-n+1], array, aux, t );                         \
598
228
                n = (int)(left - left1);                                                        \
599
228
                m = (int)(right1 - right);                                                      \
600
228
                if( n > 1 )                                                                     \
601
228
                {                                                                               \
602
189
                    if( m > 1 )                                                                 \
603
189
                    {                                                                           \
604
166
                        if( n > m )                                                             \
605
166
                        {                                                                       \
606
68
                            stack[++sp].lb = left0;                                             \
607
68
                            stack[sp].ub = left0 + n - 1;                                       \
608
68
                            left = right0 - m + 1, right = right0;                              \
609
68
                        }                                                                       \
610
166
                        else                                                                    \
611
166
                        {                                                                       \
612
98
                            stack[++sp].lb = right0 - m + 1;                                    \
613
98
                            stack[sp].ub = right0;                                              \
614
98
                            left = left0, right = left0 + n - 1;                                \
615
98
                        }                                                                       \
616
166
                    }                                                                           \
617
189
                    else                                                                        \
618
189
                        
left = left0, right = left0 + n - 123
; \
619
189
                }                                                                               \
620
228
                else 
if( 39
m > 139
) \
621
39
                    
left = right0 - m + 1, right = right035
; \
622
39
                else                                                                            \
623
39
                    
break4
; \
624
228
            }                                                                                   \
625
537
        }                                                                                       \
626
313
    }                                                                                           \
627
147
}
ccv_nnc_symbolic_graph_compile.c:_ccv_nnc_tensor_opt_sort_by_size_and_oc
Line
Count
Source
468
28.9k
void func_name(T *array, size_t total, user_data_type aux)                                      \
469
28.9k
{                                                                                               \
470
28.9k
    int isort_thresh = 7;                                                                       \
471
28.9k
    T t;                                                                                        \
472
28.9k
    int sp = 0;                                                                                 \
473
28.9k
                                                                                                \
474
28.9k
    struct                                                                                      \
475
28.9k
    {                                                                                           \
476
28.9k
        T *lb;                                                                                  \
477
28.9k
        T *ub;                                                                                  \
478
28.9k
    }                                                                                           \
479
28.9k
    stack[48];                                                                                  \
480
28.9k
                                                                                                \
481
28.9k
    if( total <= 1 )                                                                            \
482
28.9k
        
return5.34k
; \
483
28.9k
                                                                                                \
484
28.9k
    stack[0].lb = array;                                                                        \
485
23.6k
    stack[0].ub = array + (total - 1);                                                          \
486
23.6k
                                                                                                \
487
51.1k
    while( sp >= 0 )                                                                            \
488
27.5k
    {                                                                                           \
489
27.5k
        T* left = stack[sp].lb;                                                                 \
490
27.5k
        T* right = stack[sp--].ub;                                                              \
491
27.5k
                                                                                                \
492
27.5k
        for(;;)                                                                                 \
493
31.5k
        {                                                                                       \
494
31.5k
            int i, n = (int)(right - left) + 1, m;                                              \
495
31.5k
            T* ptr;                                                                             \
496
31.5k
            T* ptr2;                                                                            \
497
31.5k
                                                                                                \
498
31.5k
            if( n <= isort_thresh )                                                             \
499
31.5k
            {                                                                                   \
500
27.5k
            insert_sort:                                                                        \
501
111k
                for( ptr = left + 1; ptr <= right; 
ptr++83.8k
) \
502
83.8k
                {                                                                               \
503
213k
                    for( ptr2 = ptr; ptr2 > left && 
LT166k
(ptr2[0],ptr2[-1], aux);
ptr2--130k
) \
504
83.8k
                        swap_func( ptr2[0], ptr2[-1], array, aux, t );                          \
505
83.8k
                }                                                                               \
506
27.5k
                break;                                                                          \
507
27.4k
            }                                                                                   \
508
31.5k
            else                                                                                \
509
31.5k
            {                                                                                   \
510
4.15k
                T* left0;                                                                       \
511
4.15k
                T* left1;                                                                       \
512
4.15k
                T* right0;                                                                      \
513
4.15k
                T* right1;                                                                      \
514
4.15k
                T* pivot;                                                                       \
515
4.15k
                T* a;                                                                           \
516
4.15k
                T* b;                                                                           \
517
4.15k
                T* c;                                                                           \
518
4.15k
                int swap_cnt = 0;                                                               \
519
4.15k
                                                                                                \
520
4.15k
                left0 = left;                                                                   \
521
4.15k
                right0 = right;                                                                 \
522
4.15k
                pivot = left + (n/2);                                                           \
523
4.15k
                                                                                                \
524
4.15k
                if( n > 40 )                                                                    \
525
4.15k
                {                                                                               \
526
24
                    int d = n / 8;                                                              \
527
24
                    a = left, b = left + d, c = left + 2*d;                                     \
528
24
                    left = LT(*a, *b, aux) ? (LT(*b, *c, aux) ? 
b0
: (LT(*a, *c, aux) ? c :
a0
)) \
529
24
                                      : 
(0
LT0
(*c, *b, aux) ?
b0
:
(0
LT0
(*a, *c, aux) ?
a0
:
c0
)); \
530
24
                                                                                                \
531
24
                    a = pivot - d, b = pivot, c = pivot + d;                                    \
532
24
                    pivot = LT(*a, *b, aux) ? 
(0
LT0
(*b, *c, aux) ?
b0
:
(0
LT0
(*a, *c, aux) ?
c0
:
a0
)) \
533
24
                                      : (LT(*c, *b, aux) ? 
b0
: (LT(*a, *c, aux) ?
a0
: c)); \
534
24
                                                                                                \
535
24
                    a = right - 2*d, b = right - d, c = right;                                  \
536
24
                    right = LT(*a, *b, aux) ? (LT(*b, *c, aux) ? b : 
(0
LT0
(*a, *c, aux) ?
c0
:
a0
)) \
537
24
                                      : 
(0
LT0
(*c, *b, aux) ?
b0
:
(0
LT0
(*a, *c, aux) ?
a0
:
c0
)); \
538
24
                }                                                                               \
539
4.15k
                                                                                                \
540
4.15k
                a = left, b = pivot, c = right;                                                 \
541
4.15k
                pivot = LT(*a, *b, aux) ? 
(2.49k
LT2.49k
(*b, *c, aux) ?
b1.99k
:
(502
LT502
(*a, *c, aux) ?
c375
:
a127
)) \
542
4.15k
                                   : 
(1.66k
LT1.66k
(*c, *b, aux) ?
b617
:
(1.04k
LT1.04k
(*a, *c, aux) ?
a581
:
c462
)); \
543
4.15k
                if( pivot != left0 )                                                            \
544
4.15k
                {                                                                               \
545
3.44k
                    swap_func( *pivot, *left0, array, aux, t );                                 \
546
3.44k
                    pivot = left0;                                                              \
547
3.44k
                }                                                                               \
548
4.15k
                left = left1 = left0 + 1;                                                       \
549
4.15k
                right = right1 = right0;                                                        \
550
4.15k
                                                                                                \
551
4.15k
                for(;;)                                                                         \
552
21.7k
                {                                                                               \
553
33.0k
                    while( left <= right && 
!29.6k
LT29.6k
(*pivot, *left, aux) ) \
554
21.7k
                    {                                                                           \
555
11.3k
                        if( !LT(*left, *pivot, aux) )                                           \
556
11.3k
                        {                                                                       \
557
0
                            if( left > left1 )                                                  \
558
0
                                swap_func( *left1, *left, array, aux, t );                      \
559
0
                            swap_cnt = 1;                                                       \
560
0
                            left1++;                                                            \
561
0
                        }                                                                       \
562
11.3k
                        left++;                                                                 \
563
11.3k
                    }                                                                           \
564
21.7k
                                                                                                \
565
29.7k
                    while( left <= right && 
!25.5k
LT25.5k
(*right, *pivot, aux) ) \
566
21.7k
                    {                                                                           \
567
7.97k
                        if( !LT(*pivot, *right, aux) )                                          \
568
7.97k
                        {                                                                       \
569
0
                            if( right < right1 )                                                \
570
0
                                swap_func( *right1, *right, array, aux, t );                    \
571
0
                            swap_cnt = 1;                                                       \
572
0
                            right1--;                                                           \
573
0
                        }                                                                       \
574
7.97k
                        right--;                                                                \
575
7.97k
                    }                                                                           \
576
21.7k
                                                                                                \
577
21.7k
                    if( left > right )                                                          \
578
21.7k
                        
break4.15k
; \
579
21.7k
                    
swap_func17.5k
( *left, *right, array, aux, t ); \
580
17.5k
                    swap_cnt = 1;                                                               \
581
17.5k
                    left++;                                                                     \
582
17.5k
                    right--;                                                                    \
583
17.5k
                }                                                                               \
584
4.15k
                                                                                                \
585
4.15k
                if( swap_cnt == 0 )                                                             \
586
4.15k
                {                                                                               \
587
100
                    left = left0, right = right0;                                               \
588
100
                    goto insert_sort;                                                           \
589
100
                }                                                                               \
590
4.15k
                                                                                                \
591
4.15k
                
n = 4.05k
ccv_min4.05k
( (int)(left1 - left0), (int)(left - left1) ); \
592
8.10k
                for( i = 0; i < n; 
i++4.05k
) \
593
4.05k
                    swap_func( left0[i], left[i-n], array, aux, t );                            \
594
4.05k
                                                                                                \
595
4.05k
                n = ccv_min( (int)(right0 - right1), (int)(right1 - right) );                   \
596
4.05k
                for( i = 0; i < n; 
i++0
) \
597
4.05k
                    swap_func( left[i], right0[i-n+1], array, aux, t );                         \
598
4.05k
                n = (int)(left - left1);                                                        \
599
4.05k
                m = (int)(right1 - right);                                                      \
600
4.05k
                if( n > 1 )                                                                     \
601
4.05k
                {                                                                               \
602
3.99k
                    if( m > 1 )                                                                 \
603
3.99k
                    {                                                                           \
604
3.87k
                        if( n > m )                                                             \
605
3.87k
                        {                                                                       \
606
1.35k
                            stack[++sp].lb = left0;                                             \
607
1.35k
                            stack[sp].ub = left0 + n - 1;                                       \
608
1.35k
                            left = right0 - m + 1, right = right0;                              \
609
1.35k
                        }                                                                       \
610
3.87k
                        else                                                                    \
611
3.87k
                        {                                                                       \
612
2.52k
                            stack[++sp].lb = right0 - m + 1;                                    \
613
2.52k
                            stack[sp].ub = right0;                                              \
614
2.52k
                            left = left0, right = left0 + n - 1;                                \
615
2.52k
                        }                                                                       \
616
3.87k
                    }                                                                           \
617
3.99k
                    else                                                                        \
618
3.99k
                        
left = left0, right = left0 + n - 1121
; \
619
3.99k
                }                                                                               \
620
4.05k
                else 
if( 55
m > 155
) \
621
55
                    left = right0 - m + 1, right = right0;                                      \
622
55
                else                                                                            \
623
55
                    
break0
; \
624
4.05k
            }                                                                                   \
625
31.5k
        }                                                                                       \
626
27.5k
    }                                                                                           \
627
23.6k
}
_ccv_nnc_nms_sortby_f5_32f
Line
Count
Source
468
4
void func_name(T *array, size_t total, user_data_type aux)                                      \
469
4
{                                                                                               \
470
4
    int isort_thresh = 7;                                                                       \
471
4
    T t;                                                                                        \
472
4
    int sp = 0;                                                                                 \
473
4
                                                                                                \
474
4
    struct                                                                                      \
475
4
    {                                                                                           \
476
4
        T *lb;                                                                                  \
477
4
        T *ub;                                                                                  \
478
4
    }                                                                                           \
479
4
    stack[48];                                                                                  \
480
4
                                                                                                \
481
4
    if( total <= 1 )                                                                            \
482
4
        
return0
; \
483
4
                                                                                                \
484
4
    stack[0].lb = array;                                                                        \
485
4
    stack[0].ub = array + (total - 1);                                                          \
486
4
                                                                                                \
487
12
    while( sp >= 0 )                                                                            \
488
8
    {                                                                                           \
489
8
        T* left = stack[sp].lb;                                                                 \
490
8
        T* right = stack[sp--].ub;                                                              \
491
8
                                                                                                \
492
8
        for(;;)                                                                                 \
493
12
        {                                                                                       \
494
12
            int i, n = (int)(right - left) + 1, m;                                              \
495
12
            T* ptr;                                                                             \
496
12
            T* ptr2;                                                                            \
497
12
                                                                                                \
498
12
            if( n <= isort_thresh )                                                             \
499
12
            {                                                                                   \
500
8
            insert_sort:                                                                        \
501
1.02k
                for( ptr = left + 1; ptr <= right; 
ptr++1.01k
) \
502
1.01k
                {                                                                               \
503
2.03k
                    for( ptr2 = ptr; ptr2 > left && 
LT2.02k
(ptr2[0],ptr2[-1], aux);
ptr2--1.01k
) \
504
1.01k
                        
swap_func1.01k
( ptr2[0], ptr2[-1], array, aux, t ); \
505
1.01k
                }                                                                               \
506
8
                break;                                                                          \
507
6
            }                                                                                   \
508
12
            else                                                                                \
509
12
            {                                                                                   \
510
6
                T* left0;                                                                       \
511
6
                T* left1;                                                                       \
512
6
                T* right0;                                                                      \
513
6
                T* right1;                                                                      \
514
6
                T* pivot;                                                                       \
515
6
                T* a;                                                                           \
516
6
                T* b;                                                                           \
517
6
                T* c;                                                                           \
518
6
                int swap_cnt = 0;                                                               \
519
6
                                                                                                \
520
6
                left0 = left;                                                                   \
521
6
                right0 = right;                                                                 \
522
6
                pivot = left + (n/2);                                                           \
523
6
                                                                                                \
524
6
                if( n > 40 )                                                                    \
525
6
                {                                                                               \
526
3
                    int d = n / 8;                                                              \
527
3
                    a = left, b = left + d, c = left + 2*d;                                     \
528
3
                    left = LT(*a, *b, aux) ? 
(0
LT0
(*b, *c, aux) ?
b0
:
(0
LT0
(*a, *c, aux) ?
c0
:
a0
)) \
529
3
                                      : (LT(*c, *b, aux) ? 
b1
:
(2
LT2
(*a, *c, aux) ?
a0
:
c2
)); \
530
3
                                                                                                \
531
3
                    a = pivot - d, b = pivot, c = pivot + d;                                    \
532
3
                    pivot = LT(*a, *b, aux) ? 
(2
LT2
(*b, *c, aux) ?
b2
:
(0
LT0
(*a, *c, aux) ?
c0
:
a0
)) \
533
3
                                      : 
(1
LT1
(*c, *b, aux) ?
b1
:
(0
LT0
(*a, *c, aux) ?
a0
:
c0
)); \
534
3
                                                                                                \
535
3
                    a = right - 2*d, b = right - d, c = right;                                  \
536
3
                    right = LT(*a, *b, aux) ? 
(2
LT2
(*b, *c, aux) ?
b2
:
(0
LT0
(*a, *c, aux) ?
c0
:
a0
)) \
537
3
                                      : 
(1
LT1
(*c, *b, aux) ?
b1
:
(0
LT0
(*a, *c, aux) ?
a0
:
c0
)); \
538
3
                }                                                                               \
539
6
                                                                                                \
540
6
                a = left, b = pivot, c = right;                                                 \
541
6
                pivot = LT(*a, *b, aux) ? 
(2
LT2
(*b, *c, aux) ?
b2
:
(0
LT0
(*a, *c, aux) ?
c0
:
a0
)) \
542
6
                                   : 
(4
LT4
(*c, *b, aux) ?
b4
:
(0
LT0
(*a, *c, aux) ?
a0
:
c0
)); \
543
6
                if( pivot != left0 )                                                            \
544
6
                {                                                                               \
545
6
                    swap_func( *pivot, *left0, array, aux, t );                                 \
546
6
                    pivot = left0;                                                              \
547
6
                }                                                                               \
548
6
                left = left1 = left0 + 1;                                                       \
549
6
                right = right1 = right0;                                                        \
550
6
                                                                                                \
551
6
                for(;;)                                                                         \
552
517
                {                                                                               \
553
1.01k
                    while( left <= right && !LT(*pivot, *left, aux) )                           \
554
517
                    {                                                                           \
555
497
                        if( !LT(*left, *pivot, aux) )                                           \
556
497
                        {                                                                       \
557
0
                            if( left > left1 )                                                  \
558
0
                                swap_func( *left1, *left, array, aux, t );                      \
559
0
                            swap_cnt = 1;                                                       \
560
0
                            left1++;                                                            \
561
0
                        }                                                                       \
562
497
                        left++;                                                                 \
563
497
                    }                                                                           \
564
517
                                                                                                \
565
1.02k
                    while( left <= right && 
!1.01k
LT1.01k
(*right, *pivot, aux) ) \
566
517
                    {                                                                           \
567
504
                        if( !LT(*pivot, *right, aux) )                                          \
568
504
                        {                                                                       \
569
0
                            if( right < right1 )                                                \
570
0
                                swap_func( *right1, *right, array, aux, t );                    \
571
0
                            swap_cnt = 1;                                                       \
572
0
                            right1--;                                                           \
573
0
                        }                                                                       \
574
504
                        right--;                                                                \
575
504
                    }                                                                           \
576
517
                                                                                                \
577
517
                    if( left > right )                                                          \
578
517
                        
break6
; \
579
517
                    
swap_func511
( *left, *right, array, aux, t ); \
580
511
                    swap_cnt = 1;                                                               \
581
511
                    left++;                                                                     \
582
511
                    right--;                                                                    \
583
511
                }                                                                               \
584
6
                                                                                                \
585
6
                if( swap_cnt == 0 )                                                             \
586
6
                {                                                                               \
587
2
                    left = left0, right = right0;                                               \
588
2
                    goto insert_sort;                                                           \
589
2
                }                                                                               \
590
6
                                                                                                \
591
6
                
n = 4
ccv_min4
( (int)(left1 - left0), (int)(left - left1) ); \
592
8
                for( i = 0; i < n; 
i++4
) \
593
4
                    swap_func( left0[i], left[i-n], array, aux, t );                            \
594
4
                                                                                                \
595
4
                n = ccv_min( (int)(right0 - right1), (int)(right1 - right) );                   \
596
4
                for( i = 0; i < n; 
i++0
) \
597
4
                    
swap_func0
( left[i], right0[i-n+1], array, aux, t ); \
598
4
                n = (int)(left - left1);                                                        \
599
4
                m = (int)(right1 - right);                                                      \
600
4
                if( n > 1 )                                                                     \
601
4
                {                                                                               \
602
4
                    if( m > 1 )                                                                 \
603
4
                    {                                                                           \
604
4
                        if( n > m )                                                             \
605
4
                        {                                                                       \
606
0
                            stack[++sp].lb = left0;                                             \
607
0
                            stack[sp].ub = left0 + n - 1;                                       \
608
0
                            left = right0 - m + 1, right = right0;                              \
609
0
                        }                                                                       \
610
4
                        else                                                                    \
611
4
                        {                                                                       \
612
4
                            stack[++sp].lb = right0 - m + 1;                                    \
613
4
                            stack[sp].ub = right0;                                              \
614
4
                            left = left0, right = left0 + n - 1;                                \
615
4
                        }                                                                       \
616
4
                    }                                                                           \
617
4
                    else                                                                        \
618
4
                        
left = left0, right = left0 + n - 10
; \
619
4
                }                                                                               \
620
4
                else 
if( 0
m > 10
) \
621
0
                    left = right0 - m + 1, right = right0;                                      \
622
0
                else                                                                            \
623
0
                    break;                                                                      \
624
4
            }                                                                                   \
625
12
        }                                                                                       \
626
8
    }                                                                                           \
627
4
}
628
629
157k
#define _ccv_qsort_default_swap(a, b, array, aux, t) CCV_SWAP((a), (b), (t))
630
631
#define CCV_IMPLEMENT_QSORT(func_name, T, cmp) \
632
115k
    CCV_IMPLEMENT_QSORT_EX(func_name, T, cmp, _ccv_qsort_default_swap, int)
633
634
#define CCV_IMPLEMENT_MEDIAN(func_name, T) \
635
T func_name(T* buf, int low, int high) \
636
{                                                    \
637
  T w;                                             \
638
  int middle, ll, hh;                              \
639
  int median = (low + high) / 2;                   \
640
  for (;;)                                         \
641
  {                                                \
642
    if (high <= low)                             \
643
      return buf[median];                      \
644
    if (high == low + 1)                         \
645
    {                                            \
646
      if (buf[low] > buf[high])                \
647
        CCV_SWAP(buf[low], buf[high], w);    \
648
      return buf[median];                      \
649
    }                                            \
650
    middle = (low + high) / 2;                   \
651
    if (buf[middle] > buf[high])                 \
652
      CCV_SWAP(buf[middle], buf[high], w);     \
653
    if (buf[low] > buf[high])                    \
654
      CCV_SWAP(buf[low], buf[high], w);        \
655
    if (buf[middle] > buf[low])                  \
656
      CCV_SWAP(buf[middle], buf[low], w);      \
657
    CCV_SWAP(buf[middle], buf[low + 1], w);      \
658
    ll = low + 1;                                \
659
    hh = high;                                   \
660
    for (;;)                                     \
661
    {                                            \
662
      do ll++; while (buf[low] > buf[ll]);     \
663
      do hh--; while (buf[hh] > buf[low]);     \
664
      if (hh < ll)                             \
665
        break;                               \
666
      CCV_SWAP(buf[ll], buf[hh], w);           \
667
    }                                            \
668
    CCV_SWAP(buf[low], buf[hh], w);              \
669
    if (hh <= median)                            \
670
      low = ll;                                \
671
    else if (hh >= median)                       \
672
      high = hh - 1;                           \
673
  }                                                \
674
}
675
676
#endif