This bugzilla service is closed. All entries have been migrated to
Bug 684 - Scalar minus Array operation is implemented suboptimal
Summary: Scalar minus Array operation is implemented suboptimal
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - vectorization (show other bugs)
Version: 3.2
Hardware: All All
: Normal minor
Assignee: Nobody
Depends on:
Blocks: 3.3
  Show dependency treegraph
Reported: 2013-10-18 12:56 UTC by Christoph Hertzberg
Modified: 2019-12-04 12:43 UTC (History)
2 users (show)


Description Christoph Hertzberg 2013-10-18 12:56:33 UTC
Currently expressions like
  void foo(Array2d &a, const double s) {
    a = s - a;

lead to this inefficient code (only excerpt shown, comments added):
	movapd	.LC0, %xmm0          #.LC0 is a {-0.0, -0.0}
	xorpd	(%eax), %xmm0        # negate elements of a
	movddup	8(%esp), %xmm1       # load s
	addpd	%xmm1, %xmm0         # add s + (-a)
	movapd	%xmm0, (%eax)        # store result

This could be implemented more efficiently using the subpd instruction:
	movddup	8(%esp), %xmm0       # load s
	subpd	(eax), %xmm0         # subtract s - a
	movapd	%xmm0, (%eax)        # store result
Comment 1 Gael Guennebaud 2013-10-18 14:51:03 UTC
I hoped the compiler would optimize this by itself, but that's not the case. Here is the fix:
Changeset:   0720fd0684a9
User:        ggael
Date:        2013-10-18 14:56:36
Summary:     Fix bug 684: optimize vectorization of array-scalar and scalar-array
Comment 2 Nobody 2019-12-04 12:43:31 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance:

Note You need to log in before you can comment on or make changes to this bug.