pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgvector/pgvector] issue #1007: RFC: Enable multiply and add for inner_product
2+ messages / 2 participants
[nested] [flat]

* [pgvector/pgvector] issue #1007: RFC: Enable multiply and add for inner_product
@ 2026-07-31 11:40 "Andreas-Krebbel (@Andreas-Krebbel)" <noreply+Andreas-Krebbel@github.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Andreas-Krebbel (@Andreas-Krebbel) @ 2026-07-31 11:40 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

On my Fedora (and perhaps other distros) the default compile options pulled in from /usr/lib64/pgsql/pgxs/src/Makefile.global enforce strict standard compliance (`-std=c17`). This prevents the vector multiply and add instruction from being used for the `inner_product` routine:

```
.L324:
        vmovups 8(%rsi,%rax), %zmm0
        vmulps  8(%rbx,%rax), %zmm0, %zmm0
        addq    $64, %rax
        vaddps  %zmm0, %zmm1, %zmm1
        cmpq    %rax, %rcx
        jne     .L324
```

With `-std=c17` GCC defaults to `-ffp-contract=off `. Overriding it with `-ffp-contract=fast` brings me back to:
```
.L328:
        vmovups 8(%rax), %zmm4
        addq    $256, %rax
        vmovups -184(%rax), %zmm5
        addq    $256, %rdx
        vmovups -120(%rax), %zmm6
        vmovups -56(%rax), %zmm7
        vfmadd231ps     -128(%rdx), %zmm6, %zmm1
        vfmadd231ps     -64(%rdx), %zmm7, %zmm3
        vfmadd231ps     -256(%rdx), %zmm4, %zmm0
        vfmadd231ps     -192(%rdx), %zmm5, %zmm2
        cmpq    %rsi, %rax
        jne     .L328
```
Would it make sense to add `-ffp-contract=fast` to `PG_CFLAGS`? 

^ permalink  raw  [nested|flat] 2+ messages in thread

* Re: [pgvector/pgvector] issue #1007: RFC: Enable multiply and add for inner_product
@ 2026-08-04 12:45 "ankane (@ankane)" <noreply+ankane@github.com>
  0 siblings, 0 replies; 2+ messages in thread

From: ankane (@ankane) @ 2026-08-04 12:45 UTC (permalink / raw)
  To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>

@ankane closed this.

^ permalink  raw  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-08-04 12:45 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-07-31 11:40 [pgvector/pgvector] issue #1007: RFC: Enable multiply and add for inner_product "Andreas-Krebbel (@Andreas-Krebbel)" <noreply+Andreas-Krebbel@github.com>
2026-08-04 12:45 Re: [pgvector/pgvector] issue #1007: RFC: Enable multiply and add for inner_product "ankane (@ankane)" <noreply+ankane@github.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox