/home/liu/actions-runner/_work/ccv/ccv/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 | 85.5M | #define UNROLL_FOR0(x, s, ss, ...) _Pragma(UNROLL_PRAGMA0((ss))) for ((x) = 0; 11.4M (x) < (s); (x)++74.1M ) {74.1M |
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 | 11.4M | #define unroll_for(x, s, ...) UNROLL_FOR0(x, s, ##__VA_ARGS__, s) |
27 | 85.5M | #define unroll_endfor } |
28 | | #ifdef USE_OPENMP |
29 | | #define OMP_PRAGMA0(x) MACRO_STRINGIFY(omp parallel for private(x) schedule(dynamic)) |
30 | | #define parallel_for(x, n) { int x = 0; _Pragma(OMP_PRAGMA0(x)) for ((x) = 0; (x) < (n); (x)++) { |
31 | | #define parallel_endfor } } |
32 | | #define FOR_IS_PARALLEL (1) |
33 | | #else |
34 | 40.8M | #define parallel_for(x, n) { int x; for ((x) = 0; 386k (x) < (n); (x)++40.5M ) {40.5M |
35 | 40.5M | #define parallel_endfor } } |
36 | | #define FOR_IS_PARALLEL (0) |
37 | | #endif |
38 | | |
39 | | /* macro printf utilities */ |
40 | | |
41 | | #define PRINT(l, a, ...) \ |
42 | 3.37M | do { \ |
43 | 3.37M | if (CCV_CLI_OUTPUT_LEVEL_IS(l)) \ |
44 | 3.37M | { \ |
45 | 0 | printf(a, ##__VA_ARGS__); \ |
46 | 0 | fflush(stdout); \ |
47 | 0 | } \ |
48 | 3.37M | } 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 | 378k | (!(_1) || (((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 | 378k | #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 | 378k | #define ccv_object_return_if_cached(rv, ...) { \ |
83 | 378k | 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.35k | #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line |
114 | | #endif |
115 | | #ifndef INTERNAL_CATCH_UNIQUE_NAME_LINE |
116 | 3.35k | #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.35k | #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 | 300k | submacro; \ |
136 | 300k | uint64_t var = (cond16 ) ? ccv_cache_generate_signature(54 INTERNAL_CATCH_UNIQUE_NAME54 (_ccv_identifier_), INTERNAL_CATCH_UNIQUE_NAME54 (_ccv_string_size_), __VA_ARGS__) : 0300k ; |
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.73k ;_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 | 3.44M | #define _ccv_get_64s_value_1(ptr, i, factor) (((int64_t*)(1.72M 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 | 94.6M | #define _ccv_get_8u_value_0(ptr, i) (((unsigned char*)(ptr))[(i)]) |
182 | | |
183 | 267M | #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 | 94.9M | #define _ccv_get_8u_value(ptr, i, ...) _ccv_get_value_x(0, ##__VA_ARGS__, _ccv_get_8u_value_1333k , _ccv_get_8u_value_094.6M )(ptr, i, ##__VA_ARGS__) |
190 | | |
191 | 150k | #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: { 150k block150k (__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: { 46 block46 (__VA_ARGS__, 2 _ccv_get_8u_value); }32 } } |
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 | 35 | #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 | 72.9M | case CCV_8U: { 1 block27 (__VA_ARGS__, _ccv_get_8u_value); break26 ; } \ |
216 | 26 | 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 | 465M | #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 | 22.0M | #define _ccv_set_8u_value_0(ptr, i, value) (((unsigned char*)(ptr))[(i)] = ccv_clamp((int)(value), 0, 255)) |
267 | | |
268 | 512M | #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 | 473M | #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_0465M )(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 | 23.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_022.0M )(ptr, i, value, ##__VA_ARGS__) |
275 | | |
276 | 150k | #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 | 469M | case CCV_32F: { 22 block150k (__VA_ARGS__, _ccv_set_32f_value); break150k ; } \ |
279 | 150k | 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 | 10 | #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 | 6.01M | default: { 4 block4 (__VA_ARGS__, unsigned char, _ccv_set_8u_value, _ccv_get_8u_value6.00M ); }0 } } |
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 | 1.30M | #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 | 86.8k | void func_name(T *array, size_t total, user_data_type aux) \ |
469 | 86.8k | { \ |
470 | 86.8k | int isort_thresh = 7; \ |
471 | 86.8k | T t; \ |
472 | 86.8k | int sp = 0; \ |
473 | 86.8k | \ |
474 | 86.8k | struct \ |
475 | 86.8k | { \ |
476 | 86.8k | T *lb; \ |
477 | 86.8k | T *ub; \ |
478 | 86.8k | } \ |
479 | 86.8k | stack[48]; \ |
480 | 86.8k | \ |
481 | 86.8k | if( total <= 1 ) \ |
482 | 86.8k | return58.2k ; \ |
483 | 86.8k | \ |
484 | 86.8k | stack[0].lb = array; \ |
485 | 28.6k | stack[0].ub = array + (total - 1); \ |
486 | 28.6k | \ |
487 | 80.0k | while( sp >= 0 ) \ |
488 | 51.4k | { \ |
489 | 51.4k | T* left = stack[sp].lb; \ |
490 | 51.4k | T* right = stack[sp--].ub; \ |
491 | 51.4k | \ |
492 | 51.4k | for(;;) \ |
493 | 82.5k | { \ |
494 | 82.5k | int i, n = (int)(right - left) + 1, m; \ |
495 | 82.5k | T* ptr; \ |
496 | 82.5k | T* ptr2; \ |
497 | 82.5k | \ |
498 | 82.5k | if( n <= isort_thresh ) \ |
499 | 82.5k | { \ |
500 | 47.6k | insert_sort: \ |
501 | 194k | for( ptr = left + 1; ptr <= right; ptr++146k ) \ |
502 | 146k | { \ |
503 | 313k | for( ptr2 = ptr; ptr2 > left && LT258k (ptr2[0],ptr2[-1], aux); ptr2--167k ) \ |
504 | 146k | swap_func146k ( ptr2[0], ptr2[-1], array, aux, t ); \ |
505 | 146k | } \ |
506 | 47.6k | break; \ |
507 | 46.9k | } \ |
508 | 82.5k | else \ |
509 | 82.5k | { \ |
510 | 35.6k | T* left0; \ |
511 | 35.6k | T* left1; \ |
512 | 35.6k | T* right0; \ |
513 | 35.6k | T* right1; \ |
514 | 35.6k | T* pivot; \ |
515 | 35.6k | T* a; \ |
516 | 35.6k | T* b; \ |
517 | 35.6k | T* c; \ |
518 | 35.6k | int swap_cnt = 0; \ |
519 | 35.6k | \ |
520 | 35.6k | left0 = left; \ |
521 | 35.6k | right0 = right; \ |
522 | 35.6k | pivot = left + (n/2); \ |
523 | 35.6k | \ |
524 | 35.6k | if( n > 40 ) \ |
525 | 35.6k | { \ |
526 | 5.98k | int d = n / 8; \ |
527 | 5.98k | a = left, b = left + d, c = left + 2*d; \ |
528 | 5.98k | left = LT(*a, *b, aux) ? (3.36k LT3.36k (*b, *c, aux) ? b1.28k : (2.08k LT2.08k (*a, *c, aux) ? c1.04k : a1.04k )) \ |
529 | 5.98k | : (2.61k LT2.61k (*c, *b, aux) ? b1.08k : (1.53k LT1.53k (*a, *c, aux) ? a384 : c1.15k )); \ |
530 | 5.98k | \ |
531 | 5.98k | a = pivot - d, b = pivot, c = pivot + d; \ |
532 | 5.98k | pivot = LT(*a, *b, aux) ? (2.84k LT2.84k (*b, *c, aux) ? b1.12k : (1.71k LT1.71k (*a, *c, aux) ? c524 : a1.19k )) \ |
533 | 5.98k | : (3.14k LT3.14k (*c, *b, aux) ? b910 : (2.23k LT2.23k (*a, *c, aux) ? a742 : c1.48k )); \ |
534 | 5.98k | \ |
535 | 5.98k | a = right - 2*d, b = right - d, c = right; \ |
536 | 5.98k | right = LT(*a, *b, aux) ? (2.27k LT2.27k (*b, *c, aux) ? b1.06k : (1.20k LT1.20k (*a, *c, aux) ? c507 : a699 )) \ |
537 | 5.98k | : (3.71k LT3.71k (*c, *b, aux) ? b1.30k : (2.41k LT2.41k (*a, *c, aux) ? a832 : c1.58k )); \ |
538 | 5.98k | } \ |
539 | 35.6k | \ |
540 | 35.6k | a = left, b = pivot, c = right; \ |
541 | 35.6k | pivot = LT(*a, *b, aux) ? (13.1k LT13.1k (*b, *c, aux) ? b4.19k : (9.00k LT9.00k (*a, *c, aux) ? c3.98k : a5.01k )) \ |
542 | 35.6k | : (22.4k LT22.4k (*c, *b, aux) ? b4.99k : (17.4k LT17.4k (*a, *c, aux) ? a4.31k : c13.1k )); \ |
543 | 35.6k | if( pivot != left0 ) \ |
544 | 35.6k | { \ |
545 | 27.4k | swap_func( *pivot, *left0, array, aux, t ); \ |
546 | 27.4k | pivot = left0; \ |
547 | 27.4k | } \ |
548 | 35.6k | left = left1 = left0 + 1; \ |
549 | 35.6k | right = right1 = right0; \ |
550 | 35.6k | \ |
551 | 35.6k | for(;;) \ |
552 | 261k | { \ |
553 | 619k | while( left <= right && !598k LT598k (*pivot, *left, aux) ) \ |
554 | 358k | { \ |
555 | 358k | if( !LT(*left, *pivot, aux) ) \ |
556 | 358k | { \ |
557 | 78.5k | if( left > left1 ) \ |
558 | 78.5k | swap_func( *left1, *left, array, aux, t ); \ |
559 | 78.5k | swap_cnt = 1; \ |
560 | 78.5k | left1++; \ |
561 | 78.5k | } \ |
562 | 358k | left++; \ |
563 | 358k | } \ |
564 | 261k | \ |
565 | 728k | while( left <= right && !692k LT692k (*right, *pivot, aux) ) \ |
566 | 466k | { \ |
567 | 466k | if( !LT(*pivot, *right, aux) ) \ |
568 | 466k | { \ |
569 | 44.1k | if( right < right1 ) \ |
570 | 44.1k | swap_func( *right1, *right, array, aux, t ); \ |
571 | 44.1k | swap_cnt = 1; \ |
572 | 44.1k | right1--; \ |
573 | 44.1k | } \ |
574 | 466k | right--; \ |
575 | 466k | } \ |
576 | 261k | \ |
577 | 261k | if( left > right ) \ |
578 | 261k | break35.6k ; \ |
579 | 261k | swap_func225k ( *left, *right, array, aux, t ); \ |
580 | 225k | swap_cnt = 1; \ |
581 | 225k | left++; \ |
582 | 225k | right--; \ |
583 | 225k | } \ |
584 | 35.6k | \ |
585 | 35.6k | if( swap_cnt == 0 ) \ |
586 | 35.6k | { \ |
587 | 668 | left = left0, right = right0; \ |
588 | 668 | goto insert_sort; \ |
589 | 668 | } \ |
590 | 35.6k | \ |
591 | 35.6k | n = 34.9k ccv_min34.9k ( (int)(left1 - left0), (int)(left - left1) ); \ |
592 | 107k | for( i = 0; i < n; i++72.9k ) \ |
593 | 34.9k | swap_func( left0[i], left[i-n], array, aux, t ); \ |
594 | 34.9k | \ |
595 | 34.9k | n = ccv_min( (int)(right0 - right1), (int)(right1 - right) ); \ |
596 | 79.0k | for( i = 0; i < n; i++44.1k ) \ |
597 | 34.9k | swap_func34.9k ( left[i], right0[i-n+1], array, aux, t ); \ |
598 | 34.9k | n = (int)(left - left1); \ |
599 | 34.9k | m = (int)(right1 - right); \ |
600 | 34.9k | if( n > 1 ) \ |
601 | 34.9k | { \ |
602 | 26.7k | if( m > 1 ) \ |
603 | 26.7k | { \ |
604 | 22.7k | if( n > m ) \ |
605 | 22.7k | { \ |
606 | 8.13k | stack[++sp].lb = left0; \ |
607 | 8.13k | stack[sp].ub = left0 + n - 1; \ |
608 | 8.13k | left = right0 - m + 1, right = right0; \ |
609 | 8.13k | } \ |
610 | 22.7k | else \ |
611 | 22.7k | { \ |
612 | 14.6k | stack[++sp].lb = right0 - m + 1; \ |
613 | 14.6k | stack[sp].ub = right0; \ |
614 | 14.6k | left = left0, right = left0 + n - 1; \ |
615 | 14.6k | } \ |
616 | 22.7k | } \ |
617 | 26.7k | else \ |
618 | 26.7k | left = left0, right = left0 + n - 13.99k ; \ |
619 | 26.7k | } \ |
620 | 34.9k | else if( 8.16k m > 18.16k ) \ |
621 | 8.16k | left = right0 - m + 1, right = right04.37k ; \ |
622 | 8.16k | else \ |
623 | 8.16k | break3.79k ; \ |
624 | 34.9k | } \ |
625 | 82.5k | } \ |
626 | 51.4k | } \ |
627 | 28.6k | } ccv_numeric.c:_ccv_kmeans1d_undo_qsort Line | Count | Source | 468 | 742 | void func_name(T *array, size_t total, user_data_type aux) \ | 469 | 742 | { \ | 470 | 742 | int isort_thresh = 7; \ | 471 | 742 | T t; \ | 472 | 742 | int sp = 0; \ | 473 | 742 | \ | 474 | 742 | struct \ | 475 | 742 | { \ | 476 | 742 | T *lb; \ | 477 | 742 | T *ub; \ | 478 | 742 | } \ | 479 | 742 | stack[48]; \ | 480 | 742 | \ | 481 | 742 | if( total <= 1 ) \ | 482 | 742 | return0 ; \ | 483 | 742 | \ | 484 | 742 | stack[0].lb = array; \ | 485 | 742 | stack[0].ub = array + (total - 1); \ | 486 | 742 | \ | 487 | 16.1k | while( sp >= 0 ) \ | 488 | 15.4k | { \ | 489 | 15.4k | T* left = stack[sp].lb; \ | 490 | 15.4k | T* right = stack[sp--].ub; \ | 491 | 15.4k | \ | 492 | 15.4k | for(;;) \ | 493 | 37.3k | { \ | 494 | 37.3k | int i, n = (int)(right - left) + 1, m; \ | 495 | 37.3k | T* ptr; \ | 496 | 37.3k | T* ptr2; \ | 497 | 37.3k | \ | 498 | 37.3k | if( n <= isort_thresh ) \ | 499 | 37.3k | { \ | 500 | 11.6k | insert_sort: \ | 501 | 51.4k | for( ptr = left + 1; ptr <= right; ptr++39.8k ) \ | 502 | 39.8k | { \ | 503 | 59.0k | for( ptr2 = ptr; ptr2 > left && LT55.3k (ptr2[0],ptr2[-1], aux); ptr2--19.1k ) \ | 504 | 39.8k | swap_func( ptr2[0], ptr2[-1], array, aux, t ); \ | 505 | 39.8k | } \ | 506 | 11.6k | break; \ | 507 | 11.4k | } \ | 508 | 37.3k | else \ | 509 | 37.3k | { \ | 510 | 25.8k | T* left0; \ | 511 | 25.8k | T* left1; \ | 512 | 25.8k | T* right0; \ | 513 | 25.8k | T* right1; \ | 514 | 25.8k | T* pivot; \ | 515 | 25.8k | T* a; \ | 516 | 25.8k | T* b; \ | 517 | 25.8k | T* c; \ | 518 | 25.8k | int swap_cnt = 0; \ | 519 | 25.8k | \ | 520 | 25.8k | left0 = left; \ | 521 | 25.8k | right0 = right; \ | 522 | 25.8k | pivot = left + (n/2); \ | 523 | 25.8k | \ | 524 | 25.8k | if( n > 40 ) \ | 525 | 25.8k | { \ | 526 | 5.63k | int d = n / 8; \ | 527 | 5.63k | a = left, b = left + d, c = left + 2*d; \ | 528 | 5.63k | left = LT(*a, *b, aux) ? (3.16k LT3.16k (*b, *c, aux) ? b1.21k : (1.95k LT1.95k (*a, *c, aux) ? c969 : a990 )) \ | 529 | 5.63k | : (2.46k LT2.46k (*c, *b, aux) ? b1.04k : (1.42k LT1.42k (*a, *c, aux) ? a323 : c1.09k )); \ | 530 | 5.63k | \ | 531 | 5.63k | a = pivot - d, b = pivot, c = pivot + d; \ | 532 | 5.63k | pivot = LT(*a, *b, aux) ? (2.66k LT2.66k (*b, *c, aux) ? b1.04k : (1.61k LT1.61k (*a, *c, aux) ? c473 : a1.14k )) \ | 533 | 5.63k | : (2.96k LT2.96k (*c, *b, aux) ? b828 : (2.13k LT2.13k (*a, *c, aux) ? a696 : c1.44k )); \ | 534 | 5.63k | \ | 535 | 5.63k | a = right - 2*d, b = right - d, c = right; \ | 536 | 5.63k | right = LT(*a, *b, aux) ? (2.06k LT2.06k (*b, *c, aux) ? b935 : (1.13k LT1.13k (*a, *c, aux) ? c469 : a663 )) \ | 537 | 5.63k | : (3.56k LT3.56k (*c, *b, aux) ? b1.23k : (2.32k LT2.32k (*a, *c, aux) ? a786 : c1.53k )); \ | 538 | 5.63k | } \ | 539 | 25.8k | \ | 540 | 25.8k | a = left, b = pivot, c = right; \ | 541 | 25.8k | pivot = LT(*a, *b, aux) ? (8.12k LT8.12k (*b, *c, aux) ? b1.19k : (6.92k LT6.92k (*a, *c, aux) ? c3.06k : a3.86k )) \ | 542 | 25.8k | : (17.7k LT17.7k (*c, *b, aux) ? b3.81k : (13.9k LT13.9k (*a, *c, aux) ? a2.85k : c11.0k )); \ | 543 | 25.8k | if( pivot != left0 ) \ | 544 | 25.8k | { \ | 545 | 20.2k | swap_func( *pivot, *left0, array, aux, t ); \ | 546 | 20.2k | pivot = left0; \ | 547 | 20.2k | } \ | 548 | 25.8k | left = left1 = left0 + 1; \ | 549 | 25.8k | right = right1 = right0; \ | 550 | 25.8k | \ | 551 | 25.8k | for(;;) \ | 552 | 218k | { \ | 553 | 529k | while( left <= right && !514k LT514k (*pivot, *left, aux) ) \ | 554 | 311k | { \ | 555 | 311k | if( !LT(*left, *pivot, aux) ) \ | 556 | 311k | { \ | 557 | 75.9k | if( left > left1 ) \ | 558 | 75.9k | swap_func( *left1, *left, array, aux, t ); \ | 559 | 75.9k | swap_cnt = 1; \ | 560 | 75.9k | left1++; \ | 561 | 75.9k | } \ | 562 | 311k | left++; \ | 563 | 311k | } \ | 564 | 218k | \ | 565 | 647k | while( left <= right && !622k LT622k (*right, *pivot, aux) ) \ | 566 | 429k | { \ | 567 | 429k | if( !LT(*pivot, *right, aux) ) \ | 568 | 429k | { \ | 569 | 41.8k | if( right < right1 ) \ | 570 | 41.8k | swap_func( *right1, *right, array, aux, t ); \ | 571 | 41.8k | swap_cnt = 1; \ | 572 | 41.8k | right1--; \ | 573 | 41.8k | } \ | 574 | 429k | right--; \ | 575 | 429k | } \ | 576 | 218k | \ | 577 | 218k | if( left > right ) \ | 578 | 218k | break25.8k ; \ | 579 | 218k | swap_func192k ( *left, *right, array, aux, t ); \ | 580 | 192k | swap_cnt = 1; \ | 581 | 192k | left++; \ | 582 | 192k | right--; \ | 583 | 192k | } \ | 584 | 25.8k | \ | 585 | 25.8k | if( swap_cnt == 0 ) \ | 586 | 25.8k | { \ | 587 | 173 | left = left0, right = right0; \ | 588 | 173 | goto insert_sort; \ | 589 | 173 | } \ | 590 | 25.8k | \ | 591 | 25.8k | n = 25.6k ccv_min25.6k ( (int)(left1 - left0), (int)(left - left1) ); \ | 592 | 87.2k | for( i = 0; i < n; i++61.5k ) \ | 593 | 25.6k | swap_func( left0[i], left[i-n], array, aux, t ); \ | 594 | 25.6k | \ | 595 | 25.6k | n = ccv_min( (int)(right0 - right1), (int)(right1 - right) ); \ | 596 | 67.5k | for( i = 0; i < n; i++41.8k ) \ | 597 | 25.6k | swap_func( left[i], right0[i-n+1], array, aux, t ); \ | 598 | 25.6k | n = (int)(left - left1); \ | 599 | 25.6k | m = (int)(right1 - right); \ | 600 | 25.6k | if( n > 1 ) \ | 601 | 25.6k | { \ | 602 | 18.1k | if( m > 1 ) \ | 603 | 18.1k | { \ | 604 | 14.6k | if( n > m ) \ | 605 | 14.6k | { \ | 606 | 4.68k | stack[++sp].lb = left0; \ | 607 | 4.68k | stack[sp].ub = left0 + n - 1; \ | 608 | 4.68k | left = right0 - m + 1, right = right0; \ | 609 | 4.68k | } \ | 610 | 14.6k | else \ | 611 | 14.6k | { \ | 612 | 9.97k | stack[++sp].lb = right0 - m + 1; \ | 613 | 9.97k | stack[sp].ub = right0; \ | 614 | 9.97k | left = left0, right = left0 + n - 1; \ | 615 | 9.97k | } \ | 616 | 14.6k | } \ | 617 | 18.1k | else \ | 618 | 18.1k | left = left0, right = left0 + n - 13.44k ; \ | 619 | 18.1k | } \ | 620 | 25.6k | else if( 7.59k m > 17.59k ) \ | 621 | 7.59k | left = right0 - m + 1, right = right03.81k ; \ | 622 | 7.59k | else \ | 623 | 7.59k | break3.78k ; \ | 624 | 25.6k | } \ | 625 | 37.3k | } \ | 626 | 15.4k | } \ | 627 | 742 | } |
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 | 225 | void func_name(T *array, size_t total, user_data_type aux) \ | 469 | 225 | { \ | 470 | 225 | int isort_thresh = 7; \ | 471 | 225 | T t; \ | 472 | 225 | int sp = 0; \ | 473 | 225 | \ | 474 | 225 | struct \ | 475 | 225 | { \ | 476 | 225 | T *lb; \ | 477 | 225 | T *ub; \ | 478 | 225 | } \ | 479 | 225 | stack[48]; \ | 480 | 225 | \ | 481 | 225 | if( total <= 1 ) \ | 482 | 225 | return22 ; \ | 483 | 225 | \ | 484 | 225 | stack[0].lb = array; \ | 485 | 203 | stack[0].ub = array + (total - 1); \ | 486 | 203 | \ | 487 | 618 | while( sp >= 0 ) \ | 488 | 415 | { \ | 489 | 415 | T* left = stack[sp].lb; \ | 490 | 415 | T* right = stack[sp--].ub; \ | 491 | 415 | \ | 492 | 415 | for(;;) \ | 493 | 720 | { \ | 494 | 720 | int i, n = (int)(right - left) + 1, m; \ | 495 | 720 | T* ptr; \ | 496 | 720 | T* ptr2; \ | 497 | 720 | \ | 498 | 720 | if( n <= isort_thresh ) \ | 499 | 720 | { \ | 500 | 409 | insert_sort: \ | 501 | 1.73k | for( ptr = left + 1; ptr <= right; ptr++1.32k ) \ | 502 | 1.32k | { \ | 503 | 2.57k | for( ptr2 = ptr; ptr2 > left && LT2.31k (ptr2[0],ptr2[-1], aux); ptr2--1.25k ) \ | 504 | 1.32k | swap_func( ptr2[0], ptr2[-1], array, aux, t ); \ | 505 | 1.32k | } \ | 506 | 409 | break; \ | 507 | 408 | } \ | 508 | 720 | else \ | 509 | 720 | { \ | 510 | 312 | T* left0; \ | 511 | 312 | T* left1; \ | 512 | 312 | T* right0; \ | 513 | 312 | T* right1; \ | 514 | 312 | T* pivot; \ | 515 | 312 | T* a; \ | 516 | 312 | T* b; \ | 517 | 312 | T* c; \ | 518 | 312 | int swap_cnt = 0; \ | 519 | 312 | \ | 520 | 312 | left0 = left; \ | 521 | 312 | right0 = right; \ | 522 | 312 | pivot = left + (n/2); \ | 523 | 312 | \ | 524 | 312 | if( n > 40 ) \ | 525 | 312 | { \ | 526 | 28 | int d = n / 8; \ | 527 | 28 | a = left, b = left + d, c = left + 2*d; \ | 528 | 28 | left = LT(*a, *b, aux) ? (13 LT13 (*b, *c, aux) ? b6 : (7 LT7 (*a, *c, aux) ? c1 : a6 )) \ | 529 | 28 | : (15 LT15 (*c, *b, aux) ? b3 : (12 LT12 (*a, *c, aux) ? a10 : c2 )); \ | 530 | 28 | \ | 531 | 28 | a = pivot - d, b = pivot, c = pivot + d; \ | 532 | 28 | pivot = LT(*a, *b, aux) ? (19 LT19 (*b, *c, aux) ? b9 : (10 LT10 (*a, *c, aux) ? c3 : a7 )) \ | 533 | 28 | : (9 LT9 (*c, *b, aux) ? b3 : (6 LT6 (*a, *c, aux) ? a3 : c3 )); \ | 534 | 28 | \ | 535 | 28 | a = right - 2*d, b = right - d, c = right; \ | 536 | 28 | right = LT(*a, *b, aux) ? (16 LT16 (*b, *c, aux) ? b5 : (11 LT11 (*a, *c, aux) ? c7 : a4 )) \ | 537 | 28 | : (12 LT12 (*c, *b, aux) ? b3 : (9 LT9 (*a, *c, aux) ? a2 : c7 )); \ | 538 | 28 | } \ | 539 | 312 | \ | 540 | 312 | a = left, b = pivot, c = right; \ | 541 | 312 | pivot = LT(*a, *b, aux) ? (132 LT132 (*b, *c, aux) ? b24 : (108 LT108 (*a, *c, aux) ? c57 : a51 )) \ | 542 | 312 | : (180 LT180 (*c, *b, aux) ? b52 : (128 LT128 (*a, *c, aux) ? a39 : c89 )); \ | 543 | 312 | if( pivot != left0 ) \ | 544 | 312 | { \ | 545 | 228 | swap_func( *pivot, *left0, array, aux, t ); \ | 546 | 228 | pivot = left0; \ | 547 | 228 | } \ | 548 | 312 | left = left1 = left0 + 1; \ | 549 | 312 | right = right1 = right0; \ | 550 | 312 | \ | 551 | 312 | for(;;) \ | 552 | 1.30k | { \ | 553 | 3.27k | while( left <= right && !3.11k LT3.11k (*pivot, *left, aux) ) \ | 554 | 1.96k | { \ | 555 | 1.96k | if( !LT(*left, *pivot, aux) ) \ | 556 | 1.96k | { \ | 557 | 444 | if( left > left1 ) \ | 558 | 444 | swap_func( *left1, *left, array, aux, t ); \ | 559 | 444 | swap_cnt = 1; \ | 560 | 444 | left1++; \ | 561 | 444 | } \ | 562 | 1.96k | left++; \ | 563 | 1.96k | } \ | 564 | 1.30k | \ | 565 | 3.23k | while( left <= right && !2.91k LT2.91k (*right, *pivot, aux) ) \ | 566 | 1.92k | { \ | 567 | 1.92k | if( !LT(*pivot, *right, aux) ) \ | 568 | 1.92k | { \ | 569 | 298 | if( right < right1 ) \ | 570 | 298 | swap_func( *right1, *right, array, aux, t ); \ | 571 | 298 | swap_cnt = 1; \ | 572 | 298 | right1--; \ | 573 | 298 | } \ | 574 | 1.92k | right--; \ | 575 | 1.92k | } \ | 576 | 1.30k | \ | 577 | 1.30k | if( left > right ) \ | 578 | 1.30k | break312 ; \ | 579 | 1.30k | swap_func992 ( *left, *right, array, aux, t ); \ | 580 | 992 | swap_cnt = 1; \ | 581 | 992 | left++; \ | 582 | 992 | right--; \ | 583 | 992 | } \ | 584 | 312 | \ | 585 | 312 | if( swap_cnt == 0 ) \ | 586 | 312 | { \ | 587 | 1 | left = left0, right = right0; \ | 588 | 1 | goto insert_sort; \ | 589 | 1 | } \ | 590 | 312 | \ | 591 | 312 | n = 311 ccv_min311 ( (int)(left1 - left0), (int)(left - left1) ); \ | 592 | 912 | for( i = 0; i < n; i++601 ) \ | 593 | 311 | swap_func( left0[i], left[i-n], array, aux, t ); \ | 594 | 311 | \ | 595 | 311 | n = ccv_min( (int)(right0 - right1), (int)(right1 - right) ); \ | 596 | 581 | for( i = 0; i < n; i++270 ) \ | 597 | 311 | swap_func( left[i], right0[i-n+1], array, aux, t ); \ | 598 | 311 | n = (int)(left - left1); \ | 599 | 311 | m = (int)(right1 - right); \ | 600 | 311 | if( n > 1 ) \ | 601 | 311 | { \ | 602 | 256 | if( m > 1 ) \ | 603 | 256 | { \ | 604 | 212 | if( n > m ) \ | 605 | 212 | { \ | 606 | 100 | stack[++sp].lb = left0; \ | 607 | 100 | stack[sp].ub = left0 + n - 1; \ | 608 | 100 | left = right0 - m + 1, right = right0; \ | 609 | 100 | } \ | 610 | 212 | else \ | 611 | 212 | { \ | 612 | 112 | stack[++sp].lb = right0 - m + 1; \ | 613 | 112 | stack[sp].ub = right0; \ | 614 | 112 | left = left0, right = left0 + n - 1; \ | 615 | 112 | } \ | 616 | 212 | } \ | 617 | 256 | else \ | 618 | 256 | left = left0, right = left0 + n - 144 ; \ | 619 | 256 | } \ | 620 | 311 | else if( 55 m > 155 ) \ | 621 | 55 | left = right0 - m + 1, right = right049 ; \ | 622 | 55 | else \ | 623 | 55 | break6 ; \ | 624 | 311 | } \ | 625 | 720 | } \ | 626 | 415 | } \ | 627 | 203 | } |
ccv_nnc_symbolic_graph_compile.c:_ccv_nnc_tensor_opt_sort_by_size_and_oc Line | Count | Source | 468 | 27.3k | void func_name(T *array, size_t total, user_data_type aux) \ | 469 | 27.3k | { \ | 470 | 27.3k | int isort_thresh = 7; \ | 471 | 27.3k | T t; \ | 472 | 27.3k | int sp = 0; \ | 473 | 27.3k | \ | 474 | 27.3k | struct \ | 475 | 27.3k | { \ | 476 | 27.3k | T *lb; \ | 477 | 27.3k | T *ub; \ | 478 | 27.3k | } \ | 479 | 27.3k | stack[48]; \ | 480 | 27.3k | \ | 481 | 27.3k | if( total <= 1 ) \ | 482 | 27.3k | return5.51k ; \ | 483 | 27.3k | \ | 484 | 27.3k | stack[0].lb = array; \ | 485 | 21.8k | stack[0].ub = array + (total - 1); \ | 486 | 21.8k | \ | 487 | 47.0k | while( sp >= 0 ) \ | 488 | 25.1k | { \ | 489 | 25.1k | T* left = stack[sp].lb; \ | 490 | 25.1k | T* right = stack[sp--].ub; \ | 491 | 25.1k | \ | 492 | 25.1k | for(;;) \ | 493 | 28.6k | { \ | 494 | 28.6k | int i, n = (int)(right - left) + 1, m; \ | 495 | 28.6k | T* ptr; \ | 496 | 28.6k | T* ptr2; \ | 497 | 28.6k | \ | 498 | 28.6k | if( n <= isort_thresh ) \ | 499 | 28.6k | { \ | 500 | 25.1k | insert_sort: \ | 501 | 99.9k | for( ptr = left + 1; ptr <= right; ptr++74.8k ) \ | 502 | 74.8k | { \ | 503 | 187k | for( ptr2 = ptr; ptr2 > left && LT144k (ptr2[0],ptr2[-1], aux); ptr2--112k ) \ | 504 | 74.8k | swap_func( ptr2[0], ptr2[-1], array, aux, t ); \ | 505 | 74.8k | } \ | 506 | 25.1k | break; \ | 507 | 24.8k | } \ | 508 | 28.6k | else \ | 509 | 28.6k | { \ | 510 | 3.80k | T* left0; \ | 511 | 3.80k | T* left1; \ | 512 | 3.80k | T* right0; \ | 513 | 3.80k | T* right1; \ | 514 | 3.80k | T* pivot; \ | 515 | 3.80k | T* a; \ | 516 | 3.80k | T* b; \ | 517 | 3.80k | T* c; \ | 518 | 3.80k | int swap_cnt = 0; \ | 519 | 3.80k | \ | 520 | 3.80k | left0 = left; \ | 521 | 3.80k | right0 = right; \ | 522 | 3.80k | pivot = left + (n/2); \ | 523 | 3.80k | \ | 524 | 3.80k | if( n > 40 ) \ | 525 | 3.80k | { \ | 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 | 3.80k | \ | 540 | 3.80k | a = left, b = pivot, c = right; \ | 541 | 3.80k | pivot = LT(*a, *b, aux) ? (2.39k LT2.39k (*b, *c, aux) ? b2.20k : (187 LT187 (*a, *c, aux) ? c101 : a86 )) \ | 542 | 3.80k | : (1.40k LT1.40k (*c, *b, aux) ? b253 : (1.15k LT1.15k (*a, *c, aux) ? a510 : c643 )); \ | 543 | 3.80k | if( pivot != left0 ) \ | 544 | 3.80k | { \ | 545 | 3.20k | swap_func( *pivot, *left0, array, aux, t ); \ | 546 | 3.20k | pivot = left0; \ | 547 | 3.20k | } \ | 548 | 3.80k | left = left1 = left0 + 1; \ | 549 | 3.80k | right = right1 = right0; \ | 550 | 3.80k | \ | 551 | 3.80k | for(;;) \ | 552 | 18.1k | { \ | 553 | 32.6k | while( left <= right && !29.6k LT29.6k (*pivot, *left, aux) ) \ | 554 | 18.1k | { \ | 555 | 14.4k | if( !LT(*left, *pivot, aux) ) \ | 556 | 14.4k | { \ | 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 | 14.4k | left++; \ | 563 | 14.4k | } \ | 564 | 18.1k | \ | 565 | 25.3k | while( left <= right && !21.5k LT21.5k (*right, *pivot, aux) ) \ | 566 | 18.1k | { \ | 567 | 7.18k | if( !LT(*pivot, *right, aux) ) \ | 568 | 7.18k | { \ | 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.18k | right--; \ | 575 | 7.18k | } \ | 576 | 18.1k | \ | 577 | 18.1k | if( left > right ) \ | 578 | 18.1k | break3.80k ; \ | 579 | 18.1k | swap_func14.3k ( *left, *right, array, aux, t ); \ | 580 | 14.3k | swap_cnt = 1; \ | 581 | 14.3k | left++; \ | 582 | 14.3k | right--; \ | 583 | 14.3k | } \ | 584 | 3.80k | \ | 585 | 3.80k | if( swap_cnt == 0 ) \ | 586 | 3.80k | { \ | 587 | 299 | left = left0, right = right0; \ | 588 | 299 | goto insert_sort; \ | 589 | 299 | } \ | 590 | 3.80k | \ | 591 | 3.80k | n = 3.50k ccv_min3.50k ( (int)(left1 - left0), (int)(left - left1) ); \ | 592 | 7.00k | for( i = 0; i < n; i++3.50k ) \ | 593 | 3.50k | swap_func( left0[i], left[i-n], array, aux, t ); \ | 594 | 3.50k | \ | 595 | 3.50k | n = ccv_min( (int)(right0 - right1), (int)(right1 - right) ); \ | 596 | 3.50k | for( i = 0; i < n; i++0 ) \ | 597 | 3.50k | swap_func( left[i], right0[i-n+1], array, aux, t ); \ | 598 | 3.50k | n = (int)(left - left1); \ | 599 | 3.50k | m = (int)(right1 - right); \ | 600 | 3.50k | if( n > 1 ) \ | 601 | 3.50k | { \ | 602 | 3.44k | if( m > 1 ) \ | 603 | 3.44k | { \ | 604 | 3.31k | if( n > m ) \ | 605 | 3.31k | { \ | 606 | 1.15k | stack[++sp].lb = left0; \ | 607 | 1.15k | stack[sp].ub = left0 + n - 1; \ | 608 | 1.15k | left = right0 - m + 1, right = right0; \ | 609 | 1.15k | } \ | 610 | 3.31k | else \ | 611 | 3.31k | { \ | 612 | 2.16k | stack[++sp].lb = right0 - m + 1; \ | 613 | 2.16k | stack[sp].ub = right0; \ | 614 | 2.16k | left = left0, right = left0 + n - 1; \ | 615 | 2.16k | } \ | 616 | 3.31k | } \ | 617 | 3.44k | else \ | 618 | 3.44k | left = left0, right = left0 + n - 1133 ; \ | 619 | 3.44k | } \ | 620 | 3.50k | else if( 53 m > 153 ) \ | 621 | 53 | left = right0 - m + 1, right = right0; \ | 622 | 53 | else \ | 623 | 53 | break0 ; \ | 624 | 3.50k | } \ | 625 | 28.6k | } \ | 626 | 25.1k | } \ | 627 | 21.8k | } |
ccv_nnc_symbolic_graph_compile.c:_ccv_nnc_sort_by_hops Line | Count | Source | 468 | 58.5k | void func_name(T *array, size_t total, user_data_type aux) \ | 469 | 58.5k | { \ | 470 | 58.5k | int isort_thresh = 7; \ | 471 | 58.5k | T t; \ | 472 | 58.5k | int sp = 0; \ | 473 | 58.5k | \ | 474 | 58.5k | struct \ | 475 | 58.5k | { \ | 476 | 58.5k | T *lb; \ | 477 | 58.5k | T *ub; \ | 478 | 58.5k | } \ | 479 | 58.5k | stack[48]; \ | 480 | 58.5k | \ | 481 | 58.5k | if( total <= 1 ) \ | 482 | 58.5k | return52.7k ; \ | 483 | 58.5k | \ | 484 | 58.5k | stack[0].lb = array; \ | 485 | 5.81k | stack[0].ub = array + (total - 1); \ | 486 | 5.81k | \ | 487 | 16.2k | while( sp >= 0 ) \ | 488 | 10.4k | { \ | 489 | 10.4k | T* left = stack[sp].lb; \ | 490 | 10.4k | T* right = stack[sp--].ub; \ | 491 | 10.4k | \ | 492 | 10.4k | for(;;) \ | 493 | 15.8k | { \ | 494 | 15.8k | int i, n = (int)(right - left) + 1, m; \ | 495 | 15.8k | T* ptr; \ | 496 | 15.8k | T* ptr2; \ | 497 | 15.8k | \ | 498 | 15.8k | if( n <= isort_thresh ) \ | 499 | 15.8k | { \ | 500 | 10.4k | insert_sort: \ | 501 | 39.9k | for( ptr = left + 1; ptr <= right; ptr++29.5k ) \ | 502 | 29.5k | { \ | 503 | 62.5k | for( ptr2 = ptr; ptr2 > left && LT54.1k (ptr2[0],ptr2[-1], aux); ptr2--33.0k ) \ | 504 | 29.5k | swap_func( ptr2[0], ptr2[-1], array, aux, t ); \ | 505 | 29.5k | } \ | 506 | 10.4k | break; \ | 507 | 10.2k | } \ | 508 | 15.8k | else \ | 509 | 15.8k | { \ | 510 | 5.63k | T* left0; \ | 511 | 5.63k | T* left1; \ | 512 | 5.63k | T* right0; \ | 513 | 5.63k | T* right1; \ | 514 | 5.63k | T* pivot; \ | 515 | 5.63k | T* a; \ | 516 | 5.63k | T* b; \ | 517 | 5.63k | T* c; \ | 518 | 5.63k | int swap_cnt = 0; \ | 519 | 5.63k | \ | 520 | 5.63k | left0 = left; \ | 521 | 5.63k | right0 = right; \ | 522 | 5.63k | pivot = left + (n/2); \ | 523 | 5.63k | \ | 524 | 5.63k | if( n > 40 ) \ | 525 | 5.63k | { \ | 526 | 326 | int d = n / 8; \ | 527 | 326 | a = left, b = left + d, c = left + 2*d; \ | 528 | 326 | left = LT(*a, *b, aux) ? (186 LT186 (*b, *c, aux) ? b67 : (119 LT119 (*a, *c, aux) ? c75 : a44 )) \ | 529 | 326 | : (140 LT140 (*c, *b, aux) ? b37 : (103 LT103 (*a, *c, aux) ? a51 : c52 )); \ | 530 | 326 | \ | 531 | 326 | a = pivot - d, b = pivot, c = pivot + d; \ | 532 | 326 | pivot = LT(*a, *b, aux) ? (163 LT163 (*b, *c, aux) ? b71 : (92 LT92 (*a, *c, aux) ? c48 : a44 )) \ | 533 | 326 | : (163 LT163 (*c, *b, aux) ? b78 : (85 LT85 (*a, *c, aux) ? a43 : c42 )); \ | 534 | 326 | \ | 535 | 326 | a = right - 2*d, b = right - d, c = right; \ | 536 | 326 | right = LT(*a, *b, aux) ? (185 LT185 (*b, *c, aux) ? b122 : (63 LT63 (*a, *c, aux) ? c31 : a32 )) \ | 537 | 326 | : (141 LT141 (*c, *b, aux) ? b61 : (80 LT80 (*a, *c, aux) ? a44 : c36 )); \ | 538 | 326 | } \ | 539 | 5.63k | \ | 540 | 5.63k | a = left, b = pivot, c = right; \ | 541 | 5.63k | pivot = LT(*a, *b, aux) ? (2.54k LT2.54k (*b, *c, aux) ? b764 : (1.77k LT1.77k (*a, *c, aux) ? c764 : a1.01k )) \ | 542 | 5.63k | : (3.09k LT3.09k (*c, *b, aux) ? b874 : (2.21k LT2.21k (*a, *c, aux) ? a912 : c1.30k )); \ | 543 | 5.63k | if( pivot != left0 ) \ | 544 | 5.63k | { \ | 545 | 3.78k | swap_func( *pivot, *left0, array, aux, t ); \ | 546 | 3.78k | pivot = left0; \ | 547 | 3.78k | } \ | 548 | 5.63k | left = left1 = left0 + 1; \ | 549 | 5.63k | right = right1 = right0; \ | 550 | 5.63k | \ | 551 | 5.63k | for(;;) \ | 552 | 23.3k | { \ | 553 | 53.5k | while( left <= right && !50.7k LT50.7k (*pivot, *left, aux) ) \ | 554 | 30.2k | { \ | 555 | 30.2k | if( !LT(*left, *pivot, aux) ) \ | 556 | 30.2k | { \ | 557 | 2.14k | if( left > left1 ) \ | 558 | 2.14k | swap_func( *left1, *left, array, aux, t ); \ | 559 | 2.14k | swap_cnt = 1; \ | 560 | 2.14k | left1++; \ | 561 | 2.14k | } \ | 562 | 30.2k | left++; \ | 563 | 30.2k | } \ | 564 | 23.3k | \ | 565 | 50.6k | while( left <= right && !44.9k LT44.9k (*right, *pivot, aux) ) \ | 566 | 27.2k | { \ | 567 | 27.2k | if( !LT(*pivot, *right, aux) ) \ | 568 | 27.2k | { \ | 569 | 1.98k | if( right < right1 ) \ | 570 | 1.98k | swap_func( *right1, *right, array, aux, t ); \ | 571 | 1.98k | swap_cnt = 1; \ | 572 | 1.98k | right1--; \ | 573 | 1.98k | } \ | 574 | 27.2k | right--; \ | 575 | 27.2k | } \ | 576 | 23.3k | \ | 577 | 23.3k | if( left > right ) \ | 578 | 23.3k | break5.63k ; \ | 579 | 23.3k | swap_func17.6k ( *left, *right, array, aux, t ); \ | 580 | 17.6k | swap_cnt = 1; \ | 581 | 17.6k | left++; \ | 582 | 17.6k | right--; \ | 583 | 17.6k | } \ | 584 | 5.63k | \ | 585 | 5.63k | if( swap_cnt == 0 ) \ | 586 | 5.63k | { \ | 587 | 193 | left = left0, right = right0; \ | 588 | 193 | goto insert_sort; \ | 589 | 193 | } \ | 590 | 5.63k | \ | 591 | 5.63k | n = 5.44k ccv_min5.44k ( (int)(left1 - left0), (int)(left - left1) ); \ | 592 | 12.7k | for( i = 0; i < n; i++7.29k ) \ | 593 | 5.44k | swap_func( left0[i], left[i-n], array, aux, t ); \ | 594 | 5.44k | \ | 595 | 5.44k | n = ccv_min( (int)(right0 - right1), (int)(right1 - right) ); \ | 596 | 7.41k | for( i = 0; i < n; i++1.97k ) \ | 597 | 5.44k | swap_func( left[i], right0[i-n+1], array, aux, t ); \ | 598 | 5.44k | n = (int)(left - left1); \ | 599 | 5.44k | m = (int)(right1 - right); \ | 600 | 5.44k | if( n > 1 ) \ | 601 | 5.44k | { \ | 602 | 4.98k | if( m > 1 ) \ | 603 | 4.98k | { \ | 604 | 4.60k | if( n > m ) \ | 605 | 4.60k | { \ | 606 | 2.19k | stack[++sp].lb = left0; \ | 607 | 2.19k | stack[sp].ub = left0 + n - 1; \ | 608 | 2.19k | left = right0 - m + 1, right = right0; \ | 609 | 2.19k | } \ | 610 | 4.60k | else \ | 611 | 4.60k | { \ | 612 | 2.41k | stack[++sp].lb = right0 - m + 1; \ | 613 | 2.41k | stack[sp].ub = right0; \ | 614 | 2.41k | left = left0, right = left0 + n - 1; \ | 615 | 2.41k | } \ | 616 | 4.60k | } \ | 617 | 4.98k | else \ | 618 | 4.98k | left = left0, right = left0 + n - 1375 ; \ | 619 | 4.98k | } \ | 620 | 5.44k | else if( 460 m > 1460 ) \ | 621 | 460 | left = right0 - m + 1, right = right0; \ | 622 | 460 | else \ | 623 | 460 | break0 ; \ | 624 | 5.44k | } \ | 625 | 15.8k | } \ | 626 | 10.4k | } \ | 627 | 5.81k | } |
_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 | 619k | #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 | 590k | 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 |