🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.delphi
Article #2

Function SUM for arrays of type Single?

#2
From: Anonymous
Date: Sun, 22 Aug 2004 02:01
40 lines
2857 bytes
To make a long story short: the following is the delphi SUM function for
arrays of Doubles. Any ideas how to re-code this to work with an array of
Singles? (*other* than simply writing a non-asm delphi routine...)

function SUM(const Data: array of Double): Extended;
asm  // IN: EAX = ptr to Data, EDX = High(Data) = Count - 1
     // Uses 4 accumulators to minimize read-after-write delays and loop
overhead
     // 5 clocks per loop, 4 items per loop = 1.2 clocks per item
       FLDZ
       MOV      ECX, EDX
       FLD      ST(0)
       AND      EDX, not 3
       FLD      ST(0)
       AND      ECX, 3
       FLD      ST(0)
       SHL      EDX, 3      // count * sizeof(Double) = count * 8
       JMP      @Vector.Pointer[ECX*4]
@Vector:
       DD @@1
       DD @@2
       DD @@3
       DD @@4
@@4:   FADD     qword ptr [EAX+EDX+24]    // 1
       FXCH     ST(3)                     // 0
@@3:   FADD     qword ptr [EAX+EDX+16]    // 1
       FXCH     ST(2)                     // 0
@@2:   FADD     qword ptr [EAX+EDX+8]     // 1
       FXCH     ST(1)                     // 0
@@1:   FADD     qword ptr [EAX+EDX]       // 1
       FXCH     ST(2)                     // 0
       SUB      EDX, 32
       JNS      @@4
       FADDP    ST(3),ST                  // ST(3) := ST + ST(3); Pop ST
       FADD                               // ST(1) := ST + ST(1); Pop ST
       FADD                               // ST(1) := ST + ST(1); Pop ST
       FWAIT
end;

Thanks in advance.
Technical Details
Message-ID: <yK-dneDo45SVbbrcRVn-oQ@giganews.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: fa375,11755bff3dbc8ff6,start
X-Google-Thread: f894d,11755bff3dbc8ff6,start
X-Google-Thread: 104e31,11755bff3dbc8ff6,start
X-Google-Attributes: gidfa375,gidf894d,gid104e31,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 21 Aug 2004 19:59:52 -0500
From: "Anonymous" <anon@inter.net>
Newsgroups: alt.comp.lang.delphi,borland.public.delphi,comp.lang.delphi,comp.lang.pascal.delphi
Subject: Function SUM for arrays of type Single?
Date: Sun, 22 Aug 2004 04:01:18 +0200
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Message-ID: <yK-dneDo45SVbbrcRVn-oQ@giganews.com>
Lines: 42
X-Trace: sv3-8bd8wOA7++XATiKIjF25F8Up2/pgHYgergWDGpyVpcIM0tV/NOUUfAe0RvqnBlnsrYHjh0RfNVdQApv!NOPp9qgGJZOMGLau3ByJk5St/QwSH8TT2q3WxiL/JtPnHWTHijfgqWvnyFVT
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.13