VS 2008 asp dotNET bugs?

OK, szoval regen VS 2003.NET -et hasznaltam, most meg 2008-at. Olyan erzes mint amikor uj helyre koltozik az ember. Semmit se talal elsore, minden mashol van, es tiszta frusztraltan erzi magat.
Szoval a multkori bejegyzesemben irtam/hivatkoztam az autoEventWireup kikapcsolasara mint teljesitmenyjavito eljaras. Nos ez nehezebbnek bizonyult mint azt vartam. VS 2003-ban .NET 1.1-ben ez tiszta ugy volt. olyan szep kodot generalt a Visual studio:

/// <summary>
 /// Summary description for AdminResurce.
 /// </summary>
public class AdminResurce : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.DataGrid DataGridResource;
...
#region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {   
   this.DataGridResource.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGridResource_ItemCommand);
...
this.Load += new System.EventHandler(this.Page_Load);

Most se InitializeComponent, se OnInit, minden oldalra automatikusan beirja az AutoEventWireup=”ture”-t, ha kikapcsolom, akkor persze nem mukodik a Page_Load (csak ha kezzel letrehozom a megfelelo OnInit kodot). Ha Website-hoz kapcsolodok, es ott hozok letre webformot, akkor meg csak a kontrollokat se latom (amiket Web Application projectnel a *.aspx.designer.cs-be pakol: protected global::System.Web.UI.HtmlControls.HtmlForm form1; )
A templatek itt talalhatok : C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplatesCache\Web\CSharp\1033\WebForm.zip
Szandekosan butitja a microsoft a visual studiojat, hogy tobb programozasi konyvet, meg tanfolyamot tudjon eladni?

autoEventWireup is hard-coded into templates making changing the default stupidly time-consuming
http://blog.dantup.me.uk/2007/08/autoeventwireup-still-broken-in-visual.html

ASP.NET info

Mivel mar regen programoztam asp.NET-et, amikor meg az 1.1-es .NET volt a legfrissebb, igy ugy dontottem nem art szetnezni a neten. Mivel a Microsoft folyamatosan tolja ki az uj dolgaait, nem lehet pihenni mindig van ujdonsag.
Itt van nehany link amit erdemesnek talaltam osszegyujtani a barangolasom soran. Nehany alapfogalom, koncepcio…
Ha valaki webre fejleszt jo ha szet tudja valasztani a design elemeket es az uzleti logikat. Az elozo bejegyzesem az elobbivel foglalkozott (absolute, float layout..). Itt van meg egy link: Multi Column CSS Layouts .Mint azt rogton eszrevettem a VS 2008 nem kinalja fel a gridLayoutot mint azt regen az 1.0-s framework idejen. De ez nem is baj, hiszen weboldalt es nem pc alkalmazast fejlesztunk. (egyebkent be lehet kapcsolni az abszolut pozicionalast a tools menuben). Az egymasba agyazhato Master Pagek ami ujdonsag. Ha nem egy oldalt keszit az ember erdemes hasznalni, es raforditani turelmet es jol elkesziteni. A tobbi oldalt mar gyorsabban el lehet kesziteni, es egyseges look-and-feel-t kapunk.
ASP.NET Master Pages Overview
VS 2008 Nested Master Page Support
Open Source Templates

Nade lepjunk tovabb az izgalmasabb programozasi reszekre, mint peldaul a tobbretegu megoldasok (DAL) es egyebek. Talaltam par leirast a kovetendo modszerekrol (best practices) amit mindenkepp meg kel fontolni, de ezek mar inkabb haladoknak szolnak, nem ebbol fognak a legtobben megtanulni programozni, es remelhetoleg nem kezdoket vesznek fel nagy teljesitmenyu portalok megirasara, de azert itt van:
ASP.NET Best Practices for High Performance Applications
“Good” ASP.NET Coding Practices
Best Practices to Improve ASP.Net Web Application Performance
Best Practices for Speeding Up Your Web Site
(gondolom mar mindenki kitalalta mi volt a search phrasem a googleban, ha talalkoztok jobb cikkekkel irjatok meg : )

Es akkor egy kis 101. Foleg ha tobb oldalunk van, valahogy allapotot kell tudnunk tarolni, informaciot cserelni. (oldalako kozotti valtasra a fenti cikkek Server.Transfer-t javasolnak)
ASP.NET’s Data Storage Objects
Ma mar keves oldal engedheti meg maganak, hogy ne hasznaljon JS-eket.
JavaScript with ASP.NET 2.0 Pages

Elvalasztani az adatfeldolgozast, adathozzaferest es a GUI:
Tutorial 1: Creating a Data Access Layer

Mivel foleg C#-ban programoztam eddig, de most megkertek hogy VB.NET-ben irjak kodot, igy utana kellett neznem par dolognak itt is, az egyik ilyen a type-casting

Web design

Eloszo:
Mindig is maximalista voltam, es a leheto legjobban akartam mindent csinalni. eppen ezert a web programozas sohasem vonzott, mert messze nem eroforrashatekony. En meg commodore-on kezdtem programozni, aztan PC-n folytattam assemblyben, most mikrokontrollereket programozok. Ezekben az a kozos, hogy szamit a meret! Nem mindegy hany biten abrazolsz egy szamot, vagy vegzel vele muveletet. Igazabol ez sohasem mindegy, de a modern fejlesztokornyezetek, es programnyelvek elfedik ezt. Persze aki igazan ert hozza az ott is tudja, hogy egy osszeadas, szorzas, tomb indexeles muvelet hogy fog vegrehajtodni a processzoron (es a memoriaban, processzor cacheben). Bar ez nem mindig egyszeru, hiszen ma a platformfuggetlenseg sokszor fontosabb, igy nem is tudjuk min fog futni. Sokszor nem is erdekli a fejlesztoket hogy gyors legyen a kod, majd vesznek erosebb gepet ala, ha kell, inkabb az a lenyeges, hogy gyorsan kesz legyen. Ma a gyors fejlodes (es gyors profit) vilagaban a fejlesztesi ido az elsodleges. Ami nem baj, hisz a fejlesztes penz, es ha nem igyekszenek akkor masok hamarabb kijonnek ugyanazzal a termekkel.

A Web fejlesztesnel is fontos a gyors fejlesztes, de az elsodleges szempont az elerhetoseg. Mindig, mindenhonnan! Mig mas programokat telepiteni kell addig szinte minden PC-n van web bongeszo. Igy minden ami a weben fent van az barhonnan elerheto. Az mas kerdes, hogy ha mobiltelefonon GPRS-en keresztul egy megabyte-nyi flasht es java scriptet kell letolteni az oldal betoltodesehez annek nem fog a felhasznaloja orulni. A bongeszopiacon eles verseny van a gyors javascript motorok teren is. Barmennyire jol is irnak meg egy webes alkalmazast, mivel az bongeszon belul futtatott, igy mindig lassabb eroforras igenyesebb lesz mint egy jol megirt helyi program. Persze a jol megirtat fontos hangsulyozni, mert vannak programok amik egymaguk ki tudjak donteni a gepet.
Talan ez az overload nem latszik meg egy mai gepen, ha csak egy-ket program/bongeszoablak fut. Viszont nalam allandoan tele van a kepernyo ablakokkal, felbehagyott feladatokkal (irodalomkutatas…) Csak az operaban 29 tab van most nyitva, a firefoxban legalabb negyven oldal kb 10 ablakban, es IE-ben is meg van nyitva vagy 10, meg google chromeban is kb 10. A firefox es az opera csak egy-egy processzt hasznal mindketto 250..500MB memoria+ ugyanennyi virtualis memoriahasznalattal. A firefox igen gyakran egy gigaig is felmagy (mem+VM), ed volt mar olyan is hogy 1GM mem, 1.3GM VM hasznalattal futott (.. jart.. setalt.. cammogott). Az IE is siman felment kozel 400MB VM hasznalatik tegnap.
Nem ritkasag hogy a taskbaron 50-nel tobb ablak van (3 sorban), de van kepernyomentesem ahol 69 ablak volt megnyitva. Az se ritka, hogy remote desktop es vagy virtual PC is az ablakok kozott van amin tovabbi proceszek futnak (de ez nem annyira lenyeges az eroforras hasznalat szempontjabol). A lenyeg, hogy hard core felhasznalo vagyok, es az oprendszert, bongeszoket nem ezekhez az igenyekhez tervezik.
A chrome peldaul buszken hangoztatja hogy minden ablakhoz/tabhoz sajat processt hasznal, igy az egyik kiakadas nam akasztja meg a tobbiben a betoltest… Aki elolvasta az elozo postomban szereplo “Pushing the Limits of Windows: Processes and Threads” cikket az tudja, hogy a sok processnek megvannak a hatulutoi. Tegnap pl a chromeban tobb masodpercet kellett varnom hogy barmit reagaljon, vagy betoltodjon a google maps oldal (pedig ugye azt irja, hogy hasznaljak chrome-ot mert azzal gyorsabb). Persze ez azert van mert a bongeszok es egyebek (visual studio…) annyi memoriat foglaltak, hogy a ket giga rendszermemoria nem eleg, es szinte a teljes memoriajat kiswappeli page fileba, majd onnan probalja visszatoltogetni…
Csak a kontraszt kedveert a uTorrent kozel ezer torrentel a listajan (kb 50 fut is) (tudjatok linux image-ek) kevesebb mint20+40MB-ot hasznal! (a memoria meretek task manager adatok, a VMMap szerint se hasznal 65MB VM, 16MB WS-et) Pedig forgalomban is ez bonyolitja a legtobbet (tobb szaz giga). A FAR Managerbol szokott futni 5..10..20 db es csak nehany mega memoriat hasznal (colorer+autocomplete.. pluginekkel)

Szoval nagyabol ennyi mar sok is a webes alkalmazasok, es weboldalak eroforras hatekonysagarol. Teny, hogy rendkivul kenyelmes, es a vilag is a mobilitas fele megy.
Ha viszont web oldalt tervezunk, akkor tervezzunk jot. Itt kapasbol ket reszre lehet osztani: a kliensben megjeleno oldal, es az azt generalo szerverre. aztan azokat tovabb: webszerver, adatbazis szerver, cgi/php/asp(x)/jsp… eloallito program/script. php eseten lehet gyorsitan cache megoldasokkal, hogy ne keljen minden hozzaferesnel ujraforditani/ertelmezni a scriptet pl. eAcceleratorral. Klieons oldalon htlm, java script, css, flash, java applet… megoldasok kozul lehet valasztani, kombinalni… Ill. szinten ide tartozik nem utolsosorban, hogy hogy fog az oldalkinezni, hogy lehet hasznalni. (ez ezert kezdtem el irni ma)

(web) Design. Meg koli alatt olvastam webdesign pszihologiat. Nehany inkek kint is van az oldalamon http://szikraistvan.no-ip.info/. A kedvencem a regi HTML Hell page. Ezek magaval az oldal megjelenesevel foglalkoznak.
Itt van meg par link:
Top Ten Mistakes in Web Design
113 Design Guidelines for Homepage Usability
Guidelines for Visualizing Links
Web 2.0 Can Be Dangerous
Feature Richness and User Engagement
The Need for Web Design Standards
The Power of Defaults
Site Map Usability
Training Wheels User Interface
Information Foraging: Why Google Makes People Leave Your Site Faster
Top Ten Guidelines for Homepage Usability
Deep Linking is Good Linking
The Canonical Intranet Homepage
The Difference Between Intranet and Internet Design
Growing a Business Website: Fix the Basics First
Fancy Formatting, Fancy Words = Looks Like a Promotion = Ignored
Eyetracking Research
Show Numbers as Numerals When Writing for Online Readers
How Little Do Users Read
How Users Read on the Web
Does the Internet Make Us Lonely?
Banner Blindness: Old and New Findings
The Ten Most Violated Homepage Design Guidelines
Writing for the Web

Szinten a design resze az ami mogotte van, vagyis maga a kod. Egy programot/oldalt rengeteg fele keppen meg lehet irni. En azt szeretem ha a forraskod majdnem olyan latvanyos mint maga a megjelenitett kezelofelulet 🙂
Persze egy webes oldalnal nem art utana egy minimalizalot raengedni (html, js, css), hogy minnel kevesebb adatot kelljen a halozaton atkuldeni. Ezen persze segit ha a szerver es a kliens tamogatja a gzippel tomoritett adatatvitelt.
A htmlben, css-ben, es java scriptben lehet hosszu ertelmes classokat, es id-ket hasznalni, vagy rovid ertelmetleneket is. Ha kesz vagyunk (vagy legalabbis azt hiszuk), akkor lehet hogy erdemes a deployment szakaszaban a kiszolgalora mar minimalizalt verziot felrakni. Nem utolso sorban az oldal visszafejteset is neheziti (ha ez cel), viszont ha szerkeztheto, adatbazisbol generalt css-eket hasznalunk, akkor erdemes megtartani az ertelmes classokat, id-kat.
Maga az oldal megjelenes strukturalasara is tobb megoldas van. Pl. a phpBB 2.x meg tablakat hasznalt a design elemek elhelyezesere, a phpBB 3.x, a wordpress mar div elemekkel alakitja ki a kinezetet.
Table Layouts vs. Div Layouts: From Hell to… Hell?
in-line vs. kulonallo javascript/css file…
Yahoo!’s Rules for High Performance Web Sites.

Technologiak, eszkozok:
en.wikipedia.org/wiki/Minification_(programming)
code.google.com/p/minify/

Optimal Coding 6 – 2D algorithms

Line and Circle drawing
Line-Drawing Algorithms
Bresenham’s line algorithm
Implementations in Delphi

Here is my old “Pascal” line drawing function for 256 color SVGA in DOS:
procedure LineSVGA256(x1,y1,x2,y2:word;c:byte);assembler;
var xtav,ytav,xdir,ydir:word;
asm mov dx,0ffffh; mov ax,0a000h; mov es,ax; mov ax,x1; mov bx,x2
sub ax,bx; jnc @negxdir; neg ax; neg dx
@negxdir: mov xtav,ax; mov xdir,dx; mov dx,0ffffh; mov ax,y1; mov bx,y2
sub ax,bx; jnc @negydir; neg ax; neg dx
@negydir: mov ytav,ax; mov ydir,dx; cmp ax,xtav; jc @vizsintes
@fuggoleges: or byte ptr cs:[@incdecf],00001000b; cmp xdir,1; jnz @i0; and byte ptr cs:[@incdecf],11110111b
@i0: or byte ptr cs:[@addsubf],00101000b; cmp ydir,1; jnz @i2; and byte ptr cs:[@addsubf],11010111b
@i2: mov cx,ytav; mov bx,cx; shr bx,1; inc cx; push bx
mov ax,y1; mov bx,VideoUResX; mul bx; add ax,x1; jnc @ide1; inc dx
@ide1: mov di,ax; mov ax,4f05h; xor bx,bx; int 10h; pop bx; mov al,c
@_0: mov es:[di],al
@addsubf: sub di,VideoUResX
jnc @05; add dx,ydir; push bx; mov ax,4f05h; xor bx,bx; int 10h; mov al,c; pop bx;
@05: add bx,xtav; cmp bx,ytav; jc @_1; sub bx,ytav;
@incdecf: dec di
jno @_1; add dx,xdir; push bx; mov ax,4f05h; xor bx,bx; int 10h; mov al,c; pop bx;
@_1: loop @_0; jmp @vege
@vizsintes: or byte ptr cs:[@addsubv],00101000b; cmp ydir,1; jnz @i1; and byte ptr cs:[@addsubv],11010111b
@i1: or byte ptr cs:[@incdecv],00001000b; cmp xdir,1; jnz @i3; and byte ptr cs:[@incdecv],11110111b
@i3:mov cx,xtav; mov bx,cx; shr bx,1; inc cx; push bx
mov ax,y1; mov bx,VideoUResX; mul bx; add ax,x1; jnc @ide2; inc dx
@ide2: mov di,ax; mov ax,4f05h; xor bx,bx; int 10h; pop bx; mov al,c
@_2: mov es:[di],al
@incdecv: dec di
jno @15; add dx,xdir; push bx; mov ax,4f05h; xor bx,bx; int 10h; mov al,c; pop bx;
@15: add bx,ytav; cmp bx,xtav; jc @_3; sub bx,xtav;
@addsubv: sub di,VideoUResX
jnc @_3; add dx,ydir; push bx; mov ax,4f05h; xor bx,bx; int 10h; mov al,c; pop bx;{}
@_3: loop @_2
@vege:
end;

Midpoint circle algorithm/Bresenham’s circle algorithm
Circle-Drawing Algorithms

Optimal Coding 5 – Algorithms – Mul

The Fastcode Project is mostly about optimizing for architecture. I was looking for similar project, but sadly i couldn’t find any. Maybe I wasn’t usign the right phrases in google.
A few days ago I remembered the LibTom Library for C I downloaded a while ago. The LibTomMath is a multiple precision integer library. I was reading the code of mp_mul function. Then I looked up the referenced algorithms and more…

Comba multiplication
Karatsuba multiplication
Toom-Cook multiplication
Strassen algorithm for polynomial multiplication
Multiplication using the Fast Fourier Transform
Martin Fürer FFT algorithm

the time complexity of conventional long multiplication is O(n^2)
Karatsuba Multiplication: O(n^lg2(3)) or O(n^1.585)
Toom-Cook 3-way: O(n^1.464)
FFT: O(n log n)

A promising library: GNU Multiple Precision Arithmetic Library

And here is some instruction timings for optimizing for architectures I forgot to put up last time: http://swox.com/doc/x86-timing.pdf

Optimal Coding 4 – Code Libraries

AMD – ACML 4.1.0
AMD Core Math Library (ACML) for Windows®. Built with Intel® Fortran. 32bit/64bit
You can use Freepascal’s h2pas.exe to convert the acml.h to acml.pas. While it’s not perfect it helps.
procedure acmlversion(major:Plongint; minor:Plongint; patch:Plongint);cdecl; external 'libacml_dll.dll';
procedure acmlinfo; cdecl; external 'libacml_dll.dll';
...
var a,b,c:integer;
begin
acmlversion(@a,@b,@c);
...

Intel
Intel® Performance Libraries
Intel® Integrated Performance Primitives (Intel® IPP) for Windows
Intel® Math Kernel Library (Intel® MKL) for Windows
Intel® Software Evaluation Center
Intel® Compiler Suite Professional Edition for Windows
Intel® Visual Fortran Compiler Professional Edition for Windows

Optimal Coding 3 – Processor Architecture

This is where it gets interresting.
Removing redundant code is not too hard, although it is a bit surprising that compilers of this age do such a lazy job (MS VC2008, BDS2006). But it is nothing compared to writting code with keeping an eye on processor pipelines, branch predictions, cache levels… Which makes it more difficult is that there is a lot of different processors out there (486,PPro,PII,PIII,P4,AMD,AMDXP,AMD64… not mentioning PowerPC, ARM…) and thely all require different optimization.

Let’s start with integer instruction paring
More info at: http://www.agner.org/assem/
Mike Schmit’s Top Ten Rules for Pairing Pentium Instructions
Pentium Optimization Cross-Reference by Instruction
Optimization Stratagies for the Pentium Processor
3DNow! Instruction Porting Guide
AMD Athlonâ„¢ Processor x86 Code Optimization Guide

There are two pipelines for executing instructions, called the U-pipe and the V-pipe
There are many rules you need to know (you can read them at the links above)

So lets take a look at our previous example
function AddInt64_A(A, B : Int64) : Int64;
004089E0 55 push ebp
004089E1 8BEC mov ebp,esp
004089E3 8B4510 mov eax,[ebp+$10]
004089E6 8B5514 mov edx,[ebp+$14]
004089E9 034508 add eax,[ebp+$08]
004089EC 13550C adc edx,[ebp+$0c]
004089EF 5D pop ebp
004089F0 C21000 ret $0010

mov eax,dword ptr [esp+04h]//[A]
add eax,dword ptr [esp+0ch]
mov edx,dword ptr [esp+08h]
adc edx,dword ptr [esp+10h]

MOV register, memory, or immediate into register or memory are pairable in either pipe
PUSH register or immediate, POP register are pairable in either pipe
INC, DEC, ADD, SUB, CMP, AND, OR, XOR are pairable in either pipe
ADC, SBB are pairable in the U-pipe only
near call, short and near [conditional] jump are only pairable when in the V-pipe

So “push ebp / mov ebp,esp” should pair although not needed
“mov eax,[ebp+$10] / mov edx,[ebp+$14]” can also be paired
“add eax,[ebp+$08] /” adc cannot run in V pipe
“adc edx,[ebp+$0c] / pop ebp”

In the second example
“mov eax,dword ptr [esp+04h] / ” the add instruction won’t pair beacause it would violate the “second instruction does not read or write a register which the first instruction writes to” rule
“add eax,dword ptr [esp+0ch] / mov edx,dword ptr [esp+08h]”
“adc edx,dword ptr [esp+10h]”

There are empty V-pipe slots in booth cases we could use for other instructions like inc ecx if we also need to increment a counter…

Extended instructions, optimizing with processor specificc instructions and code paths.
some random opcodes :
MMX:
movq mm0, [ebp+$10]
movq mm1, [ebp+$08]
SSE2:
paddq mm0, mm1
movd eax, mm0
psrlq mm0, 32
movd edx, mm0
emms

Moving data between MMX register and IA32 registers is expensive.

I love “lea eax, [eax+edx*4+5]”…

Optimal Coding 2 – Borland vs. MS vs. GNU

Delphi (Borland Developer Studio 2006):

function AddInt64_1(A, B : Int64) : Int64;
begin
Result := A + B;
end;

The BDS2006 compiler generated this:
OptimizeMathFunctions.dpr.74: writeln(IntToHex(AddInt64_1($1111000022223333,$1234567890123456),16));
0040915F 6800001111 push $11110000
00409164 6833332222 push $22223333
00409169 6878563412 push $12345678
0040916E 6856341290 push $90123456
00409173 E844F8FFFF call AddInt64_1
...
OptimizeMathFunctions.dpr.9: begin
004089BC 55 push ebp
004089BD 8BEC mov ebp,esp
004089BF 83C4F8 add esp,-$08
OptimizeMathFunctions.dpr.10: Result := A + B;
004089C2 8B4510 mov eax,[ebp+$10]
004089C5 8B5514 mov edx,[ebp+$14]
004089C8 034508 add eax,[ebp+$08]
004089CB 13550C adc edx,[ebp+$0c]
004089CE 8945F8 mov [ebp-$08],eax
004089D1 8955FC mov [ebp-$04],edx
OptimizeMathFunctions.dpr.11: end;
004089D4 8B45F8 mov eax,[ebp-$08]
004089D7 8B55FC mov edx,[ebp-$04]
004089DA 59 pop ecx
004089DB 59 pop ecx
004089DC 5D pop ebp
004089DD C21000 ret $0010

What We wanted is this:

function AddInt64_A(A, B : Int64) : Int64;
asm
mov eax,[ebp+$10]
mov edx,[ebp+$14]
add eax,[ebp+$08]
adc edx,[ebp+$0c]
end;

Which looks like this in action:

OptimizeMathFunctions.dpr.82: writeln(IntToHex(AddInt64_A($1111000022223333,$1234567890123456),16));
004091A1 6800001111 push $11110000
004091A6 6833332222 push $22223333
004091AB 6878563412 push $12345678
004091B0 6856341290 push $90123456
004091B5 E826F8FFFF call AddInt64_A
...
OptimizeMathFunctions.dpr.14: asm
004089E0 55 push ebp
004089E1 8BEC mov ebp,esp
004089E3 8B4510 mov eax,[ebp+$10]
004089E6 8B5514 mov edx,[ebp+$14]
004089E9 034508 add eax,[ebp+$08]
004089EC 13550C adc edx,[ebp+$0c]
OptimizeMathFunctions.dpr.19: end;
004089EF 5D pop ebp
004089F0 C21000 ret $0010

Much better, (the delphi optimizer looks lazy).

Lets see the Visual Studio 2008 Pro C++:

typedef long long int64;
int64 AddInt64_1(int64 A, int64 B)
{
return (A+B);
}

printf("%I64xn",AddInt64_1(0x1111000022223333UL,0x1234567890123456UL));
004135AC push 12345678h
004135B1 push 90123456h
004135B6 push 11110000h
004135BB push 22223333h
004135C0 call AddInt64_1 (4111D1h)
...
004111D1 jmp AddInt64_1 (4113A0h)
...
004113A0 push ebp
004113A1 mov ebp,esp
004113A3 sub esp,0C0h
004113A9 push ebx
004113AA push esi
004113AB push edi
004113AC lea edi,[ebp-0C0h]
004113B2 mov ecx,30h
004113B7 mov eax,0CCCCCCCCh
004113BC rep stos dword ptr es:[edi]
return (A+B);
004113BE mov eax,dword ptr [A]
004113C1 add eax,dword ptr [B]
004113C4 mov edx,dword ptr [ebp+0Ch]
004113C7 adc edx,dword ptr [ebp+14h]
}
004113CA pop edi
004113CB pop esi
004113CC pop ebx
004113CD mov esp,ebp
004113CF pop ebp
004113D0 ret

I would have expected something more efficient. I thought MS VS2008 would produce better code than BDS2006 for sure. I was wrong.

What I wanted looks something like this:

int64 __declspec(naked) AddInt64_AN2(int64 A, int64 B)
{
__asm {
mov eax,dword ptr [esp+04h]//[A]
add eax,dword ptr [esp+0ch]
mov edx,dword ptr [esp+08h]
adc edx,dword ptr [esp+10h]
ret
}
}

Assembly is still king. And so is pascal/delphi with assembler rutines.

Next is gcc…

MinGW32 – gcc 3.4.5 (mingw-vista special r3)

int64 AddInt64_1(int64 A, int64 B)
{
return (A+B);
}
...
printf("%I64xn",AddInt64_1(0x1111000022223333LL,0x1234567890123456LL));

the result of gcc -S :

movl $-1877855146, 8(%esp)
movl $305419896, 12(%esp)
movl $572666675, (%esp)
movl $286326784, 4(%esp)
call __Z10AddInt64_1xx
...
__Z10AddInt64_1xx:
pushl %ebp
movl %esp, %ebp
movl 16(%ebp), %eax
movl 20(%ebp), %edx
addl 8(%ebp), %eax
adcl 12(%ebp), %edx
popl %ebp
ret

Thats what I call nice code (apart from the GAS syntax)

Optimalis kod iras

Regen volt mar amikor a HelpPC es hasonlo dos-os programokbol neztem ki az utasitas vegrehajtasi idoket az OP kod mereteket.
I love xor ax,ax !

Azota jo par ev eltelt, egyre tobb fajta processzor es egyre bonyolultabb pipeline es cache szervezes van a mai PC architekturakban.

Sajnos a Delphi fordito nem eppen produkal optimalis kodot alapbol. Ez nem jelenti azt, hogy delphiben akrar csak pascalban ne lehetne optimalizalt kodot irni. Igenis lehet. Mi sem jobb bizonyitek erre mint a fast code project.
FastMM, BASM
http://dennishomepage.gugs-cats.dk/CodingForSpeedInDelphi.doc
http://fastcode.sourceforge.net/
http://mikedimmick.blogspot.com/2008/03/what-heck-does-ret-mean.html

Nehany altalanos hasznos anyag:
http://www.agner.org/optimize/

AMD
AMD Athlonâ„¢ Processor x86 Code Optimization Guide
Software Optimization Guide for AMD64 Processors
AMD64 Architecture Programmer’s Manual Volume 1: Application Programming
AMD64 Architecture Programmer’s Manual Volume 2: System Programming
AMD64 Architecture Programmer’s Manual Volume 3: General-Purpose and System Instructions
AMD64 Architecture Programmer’s Manual Volume 4: 128-Bit Media Instructions
AMD64 Architecture Programmer’s Manual Volume 5: 64-Bit Media and x87 Floating-Point Instructions
Performance Guidelines for AMD Athlonâ„¢ and AMD Opteronâ„¢ ccNUMA Multiprocessor Systems
Software Optimization Guide for AMD Family 10h Rev C Processors
http://www.amd.com/us-en/Processors/TechnicalResources/0,,30_182_739,00.html
http://www.amd.com/us-en/Processors/TechnicalResources/0,,30_182_739_3748,00.html
http://www.amd.com/us-en/Processors/TechnicalResources/0,,30_182_739_7044,00.html
http://www.amd.com/us-en/Processors/DevelopWithAMD/0,,30_2252_875_7044,00.html

Intel
IA-32 Intel® Architecture Optimization Reference Manual
IA-32 Intel® Architecture Software Developer’s Manual Volume 1: Basic Architecture
IA-32 Intel Architecture Software Developer’s Manual Volume 2: Instruction Set Reference

Assembly
Sok jo konyv es leiras van ebben a temaban az egyik ilyen az
The Art of Assembly Language Programming