Skip to content

Commit 62af475

Browse files
committed
.
2 parents b356d24 + e0db7c3 commit 62af475

1 file changed

Lines changed: 56 additions & 39 deletions

File tree

CImg.h

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
#define cimg_time __TIME__
117117
#endif
118118

119-
// Disable silly warnings on some Microsoft VC++ compilers.
119+
// Disable silly warnings on some Microsoft and GCC compilers.
120120
#ifdef _MSC_VER
121121
#pragma warning(push)
122122
#pragma warning(disable:4127)
@@ -148,6 +148,12 @@
148148
#endif
149149
#endif
150150

151+
#if __GNUC__>10
152+
#pragma GCC diagnostic push
153+
#pragma GCC diagnostic ignored "-Wformat-truncation"
154+
#pragma GCC diagnostic ignored "-Wformat-overflow"
155+
#endif
156+
151157
// Define correct string functions for each compiler and OS.
152158
#if cimg_OS==2 && defined(_MSC_VER)
153159
#define cimg_sscanf std::sscanf
@@ -18730,30 +18736,33 @@ namespace cimg_library {
1873018736
mempos-=size(arg3) + 1;
1873118737
std::memset(&memtype[mempos],0,sizeof(int)*size(arg3) + 1);
1873218738
}
18733-
} else if (pop.size()==4 && pop[1]==arg3 && pop[3]==arg1) {
18734-
// Spot cases 'X = f(X)' -> in-place modification of vector X.
18735-
pop[1] = arg1;
18736-
if (mempos==arg3 + size(arg3) + 1) mempos-=size(arg3) + 1;
18737-
} else
18738-
CImg<ulongT>::vector((ulongT)mp_vector_copy,arg1,arg3,(ulongT)size(arg1)).
18739-
move_to(code);
18739+
} else {
18740+
is_sth = is_comp_vector(arg3) && pop[1]==arg3;
18741+
if (is_sth)
18742+
for (unsigned int k = 2; k<pop.size(); ++k) if (pop[k]==arg3) { is_sth = false; break; }
18743+
if (is_sth) {
18744+
// Spot case 'X = f(...)' -> make 'f()' write directly into variable slot.
18745+
pop[1] = arg1;
18746+
if (mempos==arg3 + size(arg3) + 1) {
18747+
mempos-=size(arg3) + 1;
18748+
std::memset(&memtype[mempos],0,sizeof(int)*size(arg3) + 1);
18749+
}
18750+
} else
18751+
CImg<ulongT>::vector((ulongT)mp_vector_copy,arg1,arg3,(ulongT)size(arg1)).
18752+
move_to(code);
18753+
}
1874018754
}
1874118755
} else // From scalar
1874218756
CImg<ulongT>::vector((ulongT)mp_vector_init,arg1,(ulongT)size(arg1),1,arg3,0).
1874318757
move_to(code);
1874418758
} else { // Scalar
1874518759
if (arg1!=arg3) {
1874618760
CImg<ulongT> &pop = code.back();
18747-
if (pop.size()==3 && pop[1]==arg3 && pop[2]==arg1) {
18748-
// Spot cases 'x = f(x)' -> in-place modification of scalar x.
18749-
pop[1] = arg1;
18750-
if (mempos==arg3 + 1) memtype[--mempos] = 0;
18751-
} else if (pop.size()==4 && pop[1]==arg3 && pop[2]==arg1 && pop[3]!=arg3) {
18752-
// Spot cases 'x = f(x,y)' -> in-place modification of scalar x.
18753-
pop[1] = arg1;
18754-
if (mempos==arg3 + 1) memtype[--mempos] = 0;
18755-
} else if (pop.size()==4 && pop[1]==arg3 && pop[3]==arg1 && pop[2]!=arg3) {
18756-
// Spot case 'y = f(x,y)' -> in-place modification of scalar y.
18761+
is_sth = is_comp_scalar(arg3) && pop[1]==arg3;
18762+
if (is_sth)
18763+
for (unsigned int k = 2; k<pop.size(); ++k) if (pop[k]==arg3) { is_sth = false; break; }
18764+
if (is_sth) {
18765+
// Spot case 'x = f(...)' -> make 'f()' write directly into variable slot.
1875718766
pop[1] = arg1;
1875818767
if (mempos==arg3 + 1) memtype[--mempos] = 0;
1875918768
} else
@@ -18859,7 +18868,6 @@ namespace cimg_library {
1885918868
if (is_vector(arg1)) { // Vector variable: (V) = value
1886018869
_cimg_mp_check_type(arg2,2,3,size(arg1));
1886118870
if (is_vector(arg2)) { // From vector
18862-
1886318871
if (arg1!=arg2) {
1886418872
CImg<ulongT> &pop = code.back();
1886518873
mp_func fn = (mp_func)pop[0];
@@ -18881,13 +18889,21 @@ namespace cimg_library {
1888118889
mempos-=size(arg2) + 1;
1888218890
std::memset(&memtype[mempos],0,sizeof(int)*size(arg2) + 1);
1888318891
}
18884-
} else if (pop.size()==4 && pop[1]==arg2 && pop[3]==arg1) {
18885-
// Spot cases '(X) = f(X)' -> in-place modification of vector X.
18886-
pop[1] = arg1;
18887-
if (mempos==arg2 + size(arg2) + 1) mempos-=size(arg2) + 1;
18888-
} else
18889-
CImg<ulongT>::vector((ulongT)mp_vector_copy,arg1,arg2,(ulongT)size(arg1)).
18890-
move_to(code);
18892+
} else {
18893+
is_sth = is_comp_vector(arg2) && pop[1]==arg2;
18894+
if (is_sth)
18895+
for (unsigned int k = 2; k<pop.size(); ++k) if (pop[k]==arg2) { is_sth = false; break; }
18896+
if (is_sth) {
18897+
// Spot case '(X) = f(...)' -> make 'f()' write directly into variable slot.
18898+
pop[1] = arg1;
18899+
if (mempos==arg2 + size(arg2) + 1) {
18900+
mempos-=size(arg2) + 1;
18901+
std::memset(&memtype[mempos],0,sizeof(int)*size(arg2) + 1);
18902+
}
18903+
} else
18904+
CImg<ulongT>::vector((ulongT)mp_vector_copy,arg1,arg2,(ulongT)size(arg1)).
18905+
move_to(code);
18906+
}
1889118907
}
1889218908
} else // From scalar
1889318909
CImg<ulongT>::vector((ulongT)mp_vector_init,arg1,(ulongT)size(arg1),1,arg2,0).
@@ -18899,16 +18915,11 @@ namespace cimg_library {
1889918915
_cimg_mp_check_type(arg2,2,1,0);
1890018916
if (arg1!=arg2) {
1890118917
CImg<ulongT> &pop = code.back();
18902-
if (pop.size()==3 && pop[1]==arg2 && pop[2]==arg1) {
18903-
// Spot cases '(x) = f(x)' -> in-place modification of scalar x.
18904-
pop[1] = arg1;
18905-
if (mempos==arg2 + 1) memtype[--mempos] = 0;
18906-
} else if (pop.size()==4 && pop[1]==arg2 && pop[2]==arg1 && pop[3]!=arg2) {
18907-
// Spot cases '(x) = f(x,y)' -> in-place modification of scalar x.
18908-
pop[1] = arg1;
18909-
if (mempos==arg2 + 1) memtype[--mempos] = 0;
18910-
} else if (pop.size()==4 && pop[1]==arg2 && pop[3]==arg1 && pop[2]!=arg2) {
18911-
// Spot case '(y) = f(x,y)' -> in-place modification of scalar y.
18918+
is_sth = is_comp_scalar(arg2) && pop[1]==arg2;
18919+
if (is_sth)
18920+
for (unsigned int k = 2; k<pop.size(); ++k) if (pop[k]==arg2) { is_sth = false; break; }
18921+
if (is_sth) {
18922+
// Spot case '(x) = f(...)' -> make 'f()' write directly into variable slot.
1891218923
pop[1] = arg1;
1891318924
if (mempos==arg2 + 1) memtype[--mempos] = 0;
1891418925
} else
@@ -18960,7 +18971,7 @@ namespace cimg_library {
1896018971
if (arg2==1) _cimg_mp_return(arg1);
1896118972
if (*ps=='*') _cimg_mp_self_vector2(mp_self_vector_mul_s,arg1,arg2);
1896218973
else if (*ps=='/') _cimg_mp_self_vector2(mp_self_vector_div_s,arg1,arg2);
18963-
else if (arg2==2) CImg<ulongT>::vector((ulongT)mp_complex_sqr,arg1,arg1 + 1,arg1 + 2).move_to(code);
18974+
else if (arg2==2) CImg<ulongT>::vector((ulongT)mp_complex_sqr,arg1,2,arg1).move_to(code);
1896418975
else CImg<ulongT>::vector((ulongT)mp_complex_pow_vs,arg1,arg1,arg2).move_to(code);
1896518976
}
1896618977

@@ -19739,8 +19750,11 @@ namespace cimg_library {
1973919750
pos = vector(2);
1974019751
if (!arg2) CImg<ulongT>::vector((ulongT)mp_complex_one,pos).move_to(code);
1974119752
else if (arg2==2) {
19742-
if (is_scalar(arg1)) CImg<ulongT>::vector((ulongT)mp_complex_sqr,pos,arg1,0).move_to(code);
19743-
else CImg<ulongT>::vector((ulongT)mp_complex_sqr,pos,arg1 + 1,arg1 + 2).move_to(code);
19753+
if (is_scalar(arg1)) {
19754+
CImg<ulongT>::vector((ulongT)mp_vector_init,pos,2,2,0,arg1,0,0).move_to(code);
19755+
arg1 = pos;
19756+
}
19757+
CImg<ulongT>::vector((ulongT)mp_complex_sqr,pos,2,arg1).move_to(code);
1974419758
} else {
1974519759
if (is_vector(arg1) && is_vector(arg2))
1974619760
CImg<ulongT>::vector((ulongT)mp_complex_pow_vv,pos,arg1,arg2).move_to(code);
@@ -70874,6 +70888,9 @@ namespace cil = cimg_library;
7087470888
#ifdef _MSC_VER
7087570889
#pragma warning(pop)
7087670890
#endif
70891+
#if __GNUC__>10
70892+
#pragma GCC diagnostic pop
70893+
#endif
7087770894

7087870895
#endif
7087970896

0 commit comments

Comments
 (0)