Thread overview
[Issue 4240] New: Array operations on short fixed-length arrays should be inlined
May 27, 2010
Don
Jul 08, 2010
Leandro Lucarella
Jul 09, 2010
Brad Roberts
Jul 09, 2010
Leandro Lucarella
Jul 12, 2010
Don
May 27, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4240

           Summary: Array operations on short fixed-length arrays should
                    be inlined
           Product: D
           Version: 1.020
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: performance
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: clugdbug@yahoo.com.au


--- Comment #0 from Don <clugdbug@yahoo.com.au> 2010-05-26 23:19:03 PDT ---
If an array operation is performed on a short fixed-length array, for example:

float[3] x,y;
x[] += y[] * 4.0;

then it should not become a function call, it should simply be turned into:

x[0] += y[0] * 4.0;
x[1] += y[1] * 4.0;
x[2] += y[2] * 4.0;

I suspect that the threshold for making the function call will be occur at length at least 9, possibly higher, since the overhead for the function call is very large (it needs to check the capabilities of the processor, for example).

This will allow array operations to provide good performance in the commonly-used case of 2D, 3D and 4D vectors.

For x86, when the code generator supports it, such usage should be turned directly into SSE instructions. This issue is a step towards that longer-term goal.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 08, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4240


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #1 from bearophile_hugs@eml.cc 2010-07-08 04:37:18 PDT ---
A use case:

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=113021

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 08, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4240


Leandro Lucarella <llucax@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |llucax@gmail.com
             Blocks|                            |859


--- Comment #2 from Leandro Lucarella <llucax@gmail.com> 2010-07-08 06:54:51 PDT ---
I'm marking this a a blocker of bug 859 so there is a single bug to track all the inlining issues. Please do the same if you open more bugs associated to inlining, or post them directly in bug 859.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 09, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4240


Brad Roberts <braddr@puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |braddr@puremagic.com
             Blocks|859                         |


--- Comment #3 from Brad Roberts <braddr@puremagic.com> 2010-07-08 22:50:21 PDT ---
undoing false dependency

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 09, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4240



--- Comment #4 from Leandro Lucarella <llucax@gmail.com> 2010-07-09 06:15:55 PDT ---
(In reply to comment #3)
> undoing false dependency

Can you elaborate a little on why having bug 859 as a tracker of all missing inline oportunities is a bad thing?

Thanks

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 12, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4240



--- Comment #5 from Don <clugdbug@yahoo.com.au> 2010-07-12 07:01:32 PDT ---
It's worth noting that this is NOT a problem with the DMD inliner. This bug will be fixed by making the array operation generator more sophisticated. All changes will be confined to arrayop.c and will not involve the inliner in any way.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 12, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4240


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei@metalanguage.com


--- Comment #6 from Andrei Alexandrescu <andrei@metalanguage.com> 2010-07-12 07:50:29 PDT ---
I suggest (and discussed this with Walter too) to strongly move towards making arrays a library type. This is already happening for hashtables.

The compiler should reduce its role to only (a) translating array syntactic
sugar (e.g. literals) to calls to that library type, (b) CTFE for arrays (which
would be very difficult if CTFE were using the library array type), and (c)
figuring out high-level bulk operations like the one in this bug report and
optimize them.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------