Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
Jan Depner: I was under the impression that there was bounds checking going on with vectors. Is this not the case? Nope. Chris
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
[EMAIL PROTECTED] wrote: I was under the impression that there was bounds checking going on with vectors. Is this not the case? Not necesserally: if you are using operator (), yes, if you use operator [], no. David
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
On Thursday 09 June 2005 12:46, Chris Cannam wrote: Jan Depner: I was under the impression that there was bounds checking going on with vectors. Is this not the case? Nope. As far as I know the [] is not checked. but at() is... Arnold -- There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable. There is another theory which states that this has already happened. -- Douglas Adams, The Restaurant at the End of the Universe pgpbEMINViN93.pgp Description: PGP signature
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
David Cournapeau wrote: [EMAIL PROTECTED] wrote: I was under the impression that there was bounds checking going on with vectors. Is this not the case? Not necesserally: if you are using operator (), yes, if you use operator [], no. I think you are all guessing. At least wil C arrays you kopw exactly what you get :-). Erik -- +---+ Erik de Castro Lopo [EMAIL PROTECTED] (Yes it's valid) +---+ ...Please don't assume Lisp is only useful for Animation and Graphics, AI, Bioinformatics, B2B and E-Commerce, Data Mining, EDA/Semiconductor applications, Expert Systems, Finance, Intelligent Agents, Knowledge Management, Mechanical CAD, Modeling and Simulation, Natural Language, Optimization, Research, Risk Analysis, Scheduling, Telecom, and Web Authoring just because these are the only things they happened to list. -- Kent Pitman
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
On 6/9/05, Erik de Castro Lopo [EMAIL PROTECTED] wrote: David Cournapeau wrote: [EMAIL PROTECTED] wrote: I was under the impression that there was bounds checking going on with vectors. Is this not the case? Not necesserally: if you are using operator (), yes, if you use operator [], no. I think you are all guessing. No, I am not. I cannot find the information on the C++ faq right now, but If m pretty sure that it is written in the book of Stroustrup. I did a small test mself: if you check the assembly code of g++ for the functions void c_array(int * a) { a[5] } void vector(vectorint a) { a[5] } void vector(vectorint a) { a.at(5) } you will see that the assembly code for c_array and vector are quite similar ( I don't know much about assembly, but here is the output of g++ -O3 -S for c_array : .file c_array.cpp .text .align 2 .p2align 4,,15 .globl _Z7c_arrayPi .type _Z7c_arrayPi, @function _Z7c_arrayPi: .LFB529: pushl %ebp .LCFI0: movl%esp, %ebp .LCFI1: movl8(%ebp), %edx movl$0, 20(%edx) popl%ebp ret .LFE529: .size _Z7c_arrayPi, .-_Z7c_arrayPi .weak pthread_mutex_unlock .weak pthread_mutex_trylock .weak pthread_mutex_lock .weak pthread_create .weak pthread_setspecific .weak pthread_getspecific .weak pthread_key_delete .weak pthread_key_create .weak pthread_once .section.note.GNU-stack,,@progbits .ident GCC: (GNU) 3.3.6 (Debian 1:3.3.6-5) and for void vector(vectorint v) .file vector.cpp .text .align 2 .p2align 4,,15 .globl _Z6vectorSt6vectorIiSaIiEE .type _Z6vectorSt6vectorIiSaIiEE, @function _Z6vectorSt6vectorIiSaIiEE: .LFB539: .L2: .L7: pushl %ebp .LCFI0: movl%esp, %ebp .LCFI1: popl%ebp ret .LFE539: .size _Z6vectorSt6vectorIiSaIiEE, .-_Z6vectorSt6vectorIiSaIiEE .weak pthread_mutex_unlock .weak pthread_mutex_trylock .weak pthread_mutex_lock .weak pthread_create .weak pthread_setspecific .weak pthread_getspecific .weak pthread_key_delete .weak pthread_key_create .weak pthread_once .section.note.GNU-stack,,@progbits .ident GCC: (GNU) 3.3.6 (Debian 1:3.3.6-5) The assembly code using at() instead of [] is much longer. Cheers, David
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
No, I am not. I cannot find the information on the C++ faq right now, but If m pretty sure that it is written in the book of Stroustrup. Of course, once I press the send button, I find the relevant webpage: http://www.research.att.com/~bs/3rd_tour2.pdf (page 9 of the pdf) 3.7.2 Range Checking The standard library vector does not provide range checking by default (§16.3.3). [...] The at() operation is a vector subscript operation that throws an exception of type o ut _o f_ range if its argument is out of the v ec to r's range (§16.3.3).
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
On Thu, Jun 09, 2005 at 10:31:35PM +0900, David Cournapeau wrote: _Z6vectorSt6vectorIiSaIiEE: .LFB539: .L2: .L7: pushl %ebp .LCFI0: movl%esp, %ebp .LCFI1: popl%ebp ret you've been bitten by the optimizer, this function does nothing but return (nothing). another hint to the fact that c++ is superior ;) sk signature.asc Description: Digital signature
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
On 6/9/05, stefan kersten [EMAIL PROTECTED] wrote: On Thu, Jun 09, 2005 at 10:31:35PM +0900, David Cournapeau wrote: _Z6vectorSt6vectorIiSaIiEE: .LFB539: .L2: .L7: pushl %ebp .LCFI0: movl%esp, %ebp .LCFI1: popl%ebp ret Well, that's what happens when one post some code after some heavy coding all day long, and when one tries to answer two questions at the same timeThat's why I would have prefered to find the relevant part instead in the C++FAQ :) Anyway, for the question is there bound checking with operator[], the answer of Bjarne Stroustrup is no :). The other problem is [] as efficient for vector and plain c array ?, well, people who know better than me asm/gcc can test and answer. Cheers, David
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
On Thu, 9 Jun 2005 23:41 , David Cournapeau [EMAIL PROTECTED] sent: On 6/9/05, stefan kersten [EMAIL PROTECTED] wrote: On Thu, Jun 09, 2005 at 10:31:35PM +0900, David Cournapeau wrote: _Z6vectorSt6vectorIiSaIiEE: .LFB539: .L2: .L7: pushl %ebp .LCFI0: movl%esp, %ebp .LCFI1: popl%ebp ret Well, that's what happens when one post some code after some heavy coding all day long, and when one tries to answer two questions at the same timeThat's why I would have prefered to find the relevant part instead in the C++FAQ :) Anyway, for the question is there bound checking with operator[], the answer of Bjarne Stroustrup is no :). The other problem is [] as efficient for vector and plain c array ?, well, people who know better than me asm/gcc can test and answer. Yeah, it really needs to be tested to tell. I remember taking a course in VAX Macro asm back in the days of dinosaur eggs and phonograph needles. The book, DEC, and the teacher all said you could turn off the VAX debugging mode when you compiled. I wrote some self-modifying code for one of the exercises (I wouldn't do that in real life ;-) The compiler still slapped in some debugging stuff and it wouldn't work. It was a real simple program though so the instructor checked it and passed it anyway ;-) Jan
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
On Thu, Jun 09, 2005 at 11:41:00PM +0900, David Cournapeau wrote: The other problem is [] as efficient for vector and plain c array ? possibly maybe: #include vector int access(int* v, int i) { return v[i]; } int access(std::vectorint v, int i) { return v[i]; } produces (g++ -fverbose-asm -O3 -S): _Z6accessPii: pushl %ebp movl%esp, %ebp movl12(%ebp), %ecx # i, i movl8(%ebp), %edx # v, v popl%ebp movl(%edx,%ecx,4), %eax # * v ret _Z6accessSt6vectorIiSaIiEEi: pushl %ebp movl%esp, %ebp movl8(%ebp), %edx # v, this movl12(%ebp), %eax # i, i popl%ebp movl(%edx), %ecx# * this sall$2, %eax addl%ecx, %eax movl(%eax), %eax ret on intel and _Z6accessPii: slwi 0,4,2 # i lwzx 3,3,0 # * v, v blr _Z6accessSt6vectorIiSaIiEEi: lwz 0,0(3) # * this slwi 5,4,2 # i lwzx 3,5,0 # this blr on ppc. note that on ppc the generated code is equivalent, while on intel movl (%edx,%ecx,4), %eax might translate to a shift, add, fetch anyway. but probably it's one of the 172 addressing modes. basically, accessing std::vector needs one indirection more; gcc should be smart enough (only verified on ppc) to hold the actual array pointer in one of the numerous registers when chaining accesses. sk signature.asc Description: Digital signature
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
On Thu, 2005-06-09 at 18:14 +0200, stefan kersten wrote: int access(std::vectorint v, int i) { return v[i]; } At least you are making copy here, should be int access(std::vectorint v, int i) -- Jussi Laako [EMAIL PROTECTED]
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
#include vector int access(int* v, int i) {=20 return v[i]; }=20 int access(std::vectorint v, int i) ahem. pass by reference vs. pass by value?
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
On Thursday 09 Jun 2005 20:07, stefan kersten wrote: On Thu, Jun 09, 2005 at 09:39:21PM +0300, Jussi Laako wrote: On Thu, 2005-06-09 at 18:14 +0200, stefan kersten wrote: int access(std::vectorint v, int i) At least you are making copy here, should be int access(std::vectorint v, int i) actually not, structs are passed by reference. $ cat a.cpp #include cassert struct A { A() { } A(const A ) { assert(0); } }; void f(A) { } int main(int argc, char **argv) { A a; f(a); } $ gcc -O3 a.cpp -o a $ ./a a: a.cpp:5: A::A(const A): Assertion `0' failed. Aborted $
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
On Thu, Jun 09, 2005 at 08:23:57PM +0100, Chris Cannam wrote: On Thursday 09 Jun 2005 20:07, stefan kersten wrote: On Thu, Jun 09, 2005 at 09:39:21PM +0300, Jussi Laako wrote: On Thu, 2005-06-09 at 18:14 +0200, stefan kersten wrote: int access(std::vectorint v, int i) At least you are making copy here, should be int access(std::vectorint v, int i) actually not, structs are passed by reference. [...] a: a.cpp:5: A::A(const A): Assertion `0' failed. Aborted oh, you're right, i missed that. the struct is copied by the caller, of course. doesn't change the code exmitted for std::vector _access_, though. sk signature.asc Description: Digital signature
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
On Thu, Jun 09, 2005 at 09:39:21PM +0300, Jussi Laako wrote: int access(std::vectorint v, int i) { return v[i]; } At least you are making copy here, should be int access(std::vectorint v, int i) No such problem with int access(int *v, int i) { return v[i]; } :-) :-) :-)
Re: [linux-audio-dev] [ot] [rant] gcc, you let me down one time toomany
On Thursday 09 Jun 2005 23:16, fons adriaensen wrote: int access(int *v, int i) { return v[i]; } Of course, passing that pointer by value is horribly inefficient. int access(int *const v, int i) { return v[i]; } Chris