🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #898

Re: vector length CSR?

#898
From: Michael S
Date: Sun, 22 Nov 2026 22:47
105 lines
4331 bytes
On Sun, 22 Nov 2026 22:04:35 GMT
anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:

> Michael S <already5chosen@yahoo.com> writes:
> >On Sun, 22 Nov 2026 09:16:24 GMT
> >anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:  
> >> int foo(int a, int b, int c, int d)
> >> {
> >>   int r=a;
> >>   r+=b;
> >>   r+=c;
> >>   r+=d;
> >>   return r;
> >> }  
> ...
> >> [~/tmp:173588] clang -fwrapv -O3 -c reassoc.c && objdump -d
> >> reassoc.o
> >> 
> >> reassoc.o:     file format elf64-x86-64
> >> 
> >> 
> >> Disassembly of section .text:
> >> 
> >> 0000000000000000 <foo>:
> >>    0:   8d 04 37                lea    (%rdi,%rsi,1),%eax
> >>    3:   01 d0                   add    %edx,%eax
> >>    5:   01 c8                   add    %ecx,%eax
> >>    7:   c3                      ret
> >> 
> >> No reassociation with either flag.
> >> 
> >> - anton  
> >
> >Unlike clang, gcc performs no useful re-association for "open" code.
> > 
> 
> And clang does not reassociate at all in this example.  Do you have an
> example (without vectorization) where it reassociates.
> 

int sum4(int a, int b, int c, int d)
{
  return a + b + c + d;
}

Windows ABI
sum4:                                   # @sum4
# %bb.0:
                                        # kill: def $r9d killed $r9d
def $r9
                                        # kill: def $r8d killed $r8d
def $r8
                                        # kill: def $edx killed $edx
def $rdx
                                        # kill: def $ecx killed $ecx
def $rcx
	addl	%edx, %ecx
	leal	(%r8,%r9), %eax
	addl	%ecx, %eax
	retq


> >BTW, gcc will happily vectorize very short summation loops, even as
> >short as 4 integers, where vectorization almost certainly would be
> >pessimizing.  
> 
> Better measure that.  Last year clang surprised me by vectorizing the
> following loop:
> 
> #include <stddef.h>
> 
> void axpy1(float a, float *x, float *y,
>            float *z, float *w, float *v,
>            size_t n)
> {
>   size_t i;
>   for (i=0; i<n; i++) {
>     z[i] += a*x[i];
>     w[i] = x[i]+y[i];
>     v[i] = x[i]*z[i];
>   }
> }
> 
> v, w, and z are not restrict, so clang has to check first that they do
> not overlap.  Still vectorization was profitable for n=5 or so.  When
> the compiler is told that v, w, and z are restrict, the vectorized
> variant was faster for even lower n (also for gcc).
> 
> - anton


In your example there is higher amount of work in the inner loop.
I am talking about really minimal case:
int sum4v(const int* a)
{
  int sum = 0;
  for (int i = 0; i < 4; ++i)
    sum += a[i];
  return sum;
}




Technical Details
Message-ID: <20261123004710.000041d3@yahoo.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11cpqih$acf5$1@dont-email.me> <11cvcr4$28k7g$1@dont-email.me> <11d3npt$3mmho$1@dont-email.me> <11dn936$2ebc2$1@dont-email.me> <11dndfd$2fr9j$1@dont-email.me> <11dngb5$2he51$1@dont-email.me> <2026Nov19.203832@mips.complang.tuwien.ac.at> <11dq56a$3f094$1@dont-email.me> <11ds0io$12f8$1@dont-email.me> <11ds88c$46jd$1@dont-email.me> <11ds95m$4co4$1@dont-email.me> <11dsbag$5a43$1@dont-email.me> <2026Nov22.101624@mips.complang.tuwien.ac.at> <20261122215511.0000513f@yahoo.com> <2026Nov22.230435@mips.complang.tuwien.ac.at>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Michael S <already5chosen@yahoo.com>
Newsgroups: comp.arch
Subject: Re: vector length CSR?
Date: Mon, 23 Nov 2026 00:47:10 +0200
Organization: A noiseless patient Spider
Lines: 105
Message-ID: <20261123004710.000041d3@yahoo.com>
References: <11cpqih$acf5$1@dont-email.me>
	<11cvcr4$28k7g$1@dont-email.me>
	<11d3npt$3mmho$1@dont-email.me>
	<11dn936$2ebc2$1@dont-email.me>
	<11dndfd$2fr9j$1@dont-email.me>
	<11dngb5$2he51$1@dont-email.me>
	<2026Nov19.203832@mips.complang.tuwien.ac.at>
	<11dq56a$3f094$1@dont-email.me>
	<11ds0io$12f8$1@dont-email.me>
	<11ds88c$46jd$1@dont-email.me>
	<11ds95m$4co4$1@dont-email.me>
	<11dsbag$5a43$1@dont-email.me>
	<2026Nov22.101624@mips.complang.tuwien.ac.at>
	<20261122215511.0000513f@yahoo.com>
	<2026Nov22.230435@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 22 Nov 2026 22:47:11 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="1412523"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/TUooh6iYanO7BcmD7DxQFy0L9AYewqug="; posting-host="8ed8fb11f8730b45d16f936e8720ca13"
Cancel-Lock: sha1:xiwAM2zqUtcfu53g5dhy8txlXQc= sha256:VbeZ4S5HGc+mZ7WrQAckjBExF7Q7cVjrBTxzr7PWybU=
	sha1:uiPPotWo87FGGuzQ20q3gFS+Noo= sha256:/8PyjhzhCTWAk0lFl+XcvAl4wtoy1B/FYNiw2EfmsiM=
X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)