This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/12196] New: Encapsulation penalty should not exist for simple classes
- From: "yuri at tsoft dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 6 Sep 2003 21:03:17 -0000
- Subject: [Bug c++/12196] New: Encapsulation penalty should not exist for simple classes
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12196
Summary: Encapsulation penalty should not exist for simple
classes
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: yuri at tsoft dot com
CC: gcc-bugs at gcc dot gnu dot org
When I compile the following with -O3
changing TYPE macro from "int" to "C_int"
I see performance penalty from
10% to 100% depending on how many accumulators
(res variables) with the same number of total
multiplications.
Modifications with smaller array size and longer
repetitions of overall arrays do not change the
trend.
This should NOT occur for such a simplistic
class having only one integer inside.
Yuri
---------------------------------------------------
#include <stdio.h>
class C_int {
public:
int i;
inline C_int() { }
inline C_int(int new_i) { i = new_i; }
inline C_int operator*(C_int i1) {
C_int ii(i*i1.i);
return (ii);
}
inline C_int operator+(C_int i1) {
C_int ii(i+i1.i);
return (ii);
}
inline void operator+=(C_int i1) {
i += i1.i;
}
inline void operator=(int ii) { i = ii; }
// inline void operator(int)() { return (i); }
};
#define TYPE int // 1
//#define TYPE C_int // 2
#define SZ 30000000
TYPE v1[SZ];
TYPE v2[SZ];
int
main(int argc, const char *argv[]) {
{ // initialize
for (int i = 0; i < SZ; i++) {
v1[i] = i^0x010101 + 0x437785;
v2[i] = i^0x017132 + 0x245726;
}
}
TYPE res = 0;
{ // inner product
for (int i = 0; i < SZ; i++) {
res += v1[i] * v2[i];
}
}
// printf("res=%i\n", res.i);
return (0);
}