From owner-freebsd-chat@FreeBSD.ORG Thu Apr 22 15:19:47 2004 Return-Path: Delivered-To: freebsd-chat@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id A775816A4CE for ; Thu, 22 Apr 2004 15:19:47 -0700 (PDT) Received: from castle.comp.uvic.ca (castle.comp.uvic.ca [142.104.5.97]) by mx1.FreeBSD.org (Postfix) with ESMTP id 656E543D1D for ; Thu, 22 Apr 2004 15:19:47 -0700 (PDT) (envelope-from chrisa@uvic.ca) Received: from uvic.ca (S01060050bab00fcb.gv.shawcable.net [24.68.226.164]) i3MMJk5w3874992; Thu, 22 Apr 2004 15:19:46 -0700 Message-ID: <40884502.9060301@uvic.ca> Date: Thu, 22 Apr 2004 15:19:46 -0700 From: Chris Ashlee User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: en-us, en MIME-Version: 1.0 To: DoubleF References: <200404151110.i3FBAaoo048373@adsl-68-76-19-75.dsl.klmzmi.ameritech.net> <200404171050.29467.dgw@liwest.at> <20040417123848.GA244@Shark.localdomain> <200404202139.53518.dgw@liwest.at> <20040421162837.GA296@Shark.localdomain> In-Reply-To: <20040421162837.GA296@Shark.localdomain> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-UVic-Virus-Scanned: OK - Passed virus scan by Sophos (sophie) on castle X-UVic-Spam-Scan: castle.comp.uvic.ca Not_scanned_LOCAL X-Scanned-By: MIMEDefang 2.33 (www . roaringpenguin . com / mimedefang) cc: freebsd-chat@freebsd.org Subject: Re: Beginning C++ in FreeBSD X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Apr 2004 22:19:47 -0000 DoubleF wrote: > [When I say `moving to chat@', I mean it] > > On Tue, Apr 20, 2004 at 09:39:53PM +0000, > Daniela probably wrote: >>[assembly language-related stuff and etc] >>And if I want it to be fast ... > > > Undoubtedly, today you can hand-optimize your code to run faster. But > there are certain problems (I'm not touching compatibility problems > here, they're known to you): > > 1) what you have written to be optimal for an AMD processor may be > suboptimal for an Intel processor, and vice versa, and Intel and AMD > aren't the only companies out there; > > 2) what you have written to be optimal for a Pentium P54C (read: Pentium > 1; that's what I'm sitting in front of now) processor may be suboptimal > even for a P6 (Pentium Pro) processor, because their architectures are > different; > > 3) (a bit more serious) it's not difficult to manage the 8 basic 32-bit > registers (okay, maybe 7:)) efficiently, but do you think you can do the > same with 16 64-bit registers of the AMD 64-bit processor? not sure > about you, but I wouldn't bet I can outoptimize a good compiler there; > > 4) it's not difficult to write instructions one by one, but it's not > easy for the processor to process them that way , so Intel's 64-bit > architecture wants you to pack 3-s of instructions into chunks. I think > 3 is an odd number of instructions to have in a 128-bit chunk:). This > definitely doesn't make assembly programmer's life easier either. > > (3 and 4: just look at the manuals of the respective architectures and > see, for instance, how the 3-convention makes IA-64 assembly > unreadable --- just MHO). All of these are good points, and debunk assembly's supposed advantages. But the difficulty of writing fast assembly code on any decent architecture (ie. not x86) is really the least of its problems. The worst of its problems: 1) It takes longer to write, 2) It takes longer to debug, 3) It's much harder for others to understand, 4) It's MUCH harder to change, 5) It limits you to one CPU architecture. All these disadvantages, for only a *chance* at faster code in return. Why such an emphasis on speed before anything's even written, let alone profiled? > > >>I'd give up all the comforts of a high-level language even for no particular >>reason. Every programming language is fun and easy in it's own way. For me, >>ASM in not just a last resort. >> Fair enough. That's your choice. And there is a certain measure of fun in it. At my school, they make us all take a class in assembly language programming, albeit on 68HC11 microcontrollers, and it is a lot of fun. But more importantly, it teaches us what's going on in the machine, which can be useful for debugging, and writing code that is likely to be compiled to run fast. And of course, a good knowledge of assembly is essential if you want to write compilers. But writing *everything* in assembly is not the way of good software engineering, for all the reasons I mentioned above. While you write your programs in assembly language, everyone else is writing code in half the time, debugging it in a quarter the time, and it can be changed more easily to add new features or adapt to changing requirements. And it runs just as fast, too! The focus in software engineering these days is not on more performance: we've already solved that problem. The focus is on developing things on time, on budget, that meet the ever-changing requirements. Assembly is a poor choice for all of these needs. Daniela, if you ever want to collaborate on software projects with other programmers, you're not going to be able to do it in assembly language. Bear this in mind as you continue to learn as a programmer. Chris