* . *
  • About
  • Advertise
  • Privacy & Policy
  • Contact
Saturday, July 5, 2025
Earth-News
  • Home
  • Business
  • Entertainment
    Kennedy Publishing, MGA Entertainment Launch Yummiland Magazine – License Global

    Kennedy Publishing, MGA Entertainment Launch Yummiland Magazine – License Global

    MAY HER SOUL REST IN PEACE 🙏 Veteran entertainment columnist and talent manager Lolit Solis has passed away. She was 78 years old. https://tinyurl.com/6kumarkx | LatestChika.com – Facebook

    Beloved Entertainment Icon Lolit Solis Passes Away at 78 – A Life Remembered with Love and Respect 🙏

    Neil Young Plays Rare Full-Band ‘Ambulance Blues’ With The Chrome Hearts – Yahoo

    Neil Young Stuns Fans with Rare Full-Band Performance of ‘Ambulance Blues’ Alongside The Chrome Hearts

    BTS Announce Their Big Return and Yes, They Already Have Some Major Plans in the Works – Yahoo

    BTS Announce Their Big Return and Yes, They Already Have Some Major Plans in the Works – Yahoo

    Nantucket Dance Festival opens July 8 – The Inquirer and Mirror

    Nantucket Dance Festival Launches with Thrilling Performances Beginning July 8

    A Secret Society, Ritualistic Killings, and a Century-Old Curse Netflix and YRF Entertainment’s ‘Mandala Murders’ Premieres July 25 – About Netflix

    A Secret Society, Ritualistic Killings, and a Century-Old Curse: Dive into the Chilling World of ‘Mandala Murders’ Premiering July 25

  • General
  • Health
  • News

    Cracking the Code: Why China’s Economic Challenges Aren’t Shaking Markets, Unlike America’s” – Bloomberg

    Trump’s Narrow Window to Spread the Truth About Harris

    Trump’s Narrow Window to Spread the Truth About Harris

    Israel-Gaza war live updates: Hamas leader Ismail Haniyeh assassinated in Iran, group says

    Israel-Gaza war live updates: Hamas leader Ismail Haniyeh assassinated in Iran, group says

    PAP Boss to Niger Delta Youths, Stay Away from the Protest

    PAP Boss to Niger Delta Youths, Stay Away from the Protest

    Court Restricts Protests In Lagos To Freedom, Peace Park

    Court Restricts Protests In Lagos To Freedom, Peace Park

    Fans React to Jazz Jennings’ Inspiring Weight Loss Journey

    Fans React to Jazz Jennings’ Inspiring Weight Loss Journey

    Trending Tags

    • Trump Inauguration
    • United Stated
    • White House
    • Market Stories
    • Election Results
  • Science
  • Sports
  • Technology
    New Technology for Water Efficiency and Working with Mexico on Screwworm – AG INFORMATION NETWORK OF THE WEST

    Revolutionary Water Efficiency Technology and Cross-Border Collaboration to Defeat Screwworm

    Environmental cognitive distance, R&D capability distance, and supply chain green technology innovation – Nature

    Bridging Gaps: How Environmental and R&D Differences Drive Green Technology Innovation in Supply Chains

    LG Innotek CEO Moon Hyuksoo: “Our Next-gen Substrate Technology Will Change the Industry Paradigm” – TechPowerUp

    LG Innotek CEO Moon Hyuksoo: “Our Next-Gen Substrate Technology Will Revolutionize the Industry” Revolutionizing the Future: LG Innotek’s CEO Unveils Game-Changing Next-Gen Substrate Technology

    Inspira Technologies Secures Landmark $22.5M Deal: Major Revenue Breakthrough After FDA Clearance – Stock Titan

    Inspira Technologies Secures Landmark $22.5M Deal: Major Revenue Breakthrough After FDA Clearance – Stock Titan

    Meiwu Technology Company Limited and Shenzhen Zhinuo – GlobeNewswire

    Meiwu Technology Company Limited and Shenzhen Zhinuo – GlobeNewswire

    Owls inspire new revolutionary noise reduction technology – KTEN

    Owls inspire new revolutionary noise reduction technology – KTEN

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
No Result
View All Result
  • Home
  • Business
  • Entertainment
    Kennedy Publishing, MGA Entertainment Launch Yummiland Magazine – License Global

    Kennedy Publishing, MGA Entertainment Launch Yummiland Magazine – License Global

    MAY HER SOUL REST IN PEACE 🙏 Veteran entertainment columnist and talent manager Lolit Solis has passed away. She was 78 years old. https://tinyurl.com/6kumarkx | LatestChika.com – Facebook

    Beloved Entertainment Icon Lolit Solis Passes Away at 78 – A Life Remembered with Love and Respect 🙏

    Neil Young Plays Rare Full-Band ‘Ambulance Blues’ With The Chrome Hearts – Yahoo

    Neil Young Stuns Fans with Rare Full-Band Performance of ‘Ambulance Blues’ Alongside The Chrome Hearts

    BTS Announce Their Big Return and Yes, They Already Have Some Major Plans in the Works – Yahoo

    BTS Announce Their Big Return and Yes, They Already Have Some Major Plans in the Works – Yahoo

    Nantucket Dance Festival opens July 8 – The Inquirer and Mirror

    Nantucket Dance Festival Launches with Thrilling Performances Beginning July 8

    A Secret Society, Ritualistic Killings, and a Century-Old Curse Netflix and YRF Entertainment’s ‘Mandala Murders’ Premieres July 25 – About Netflix

    A Secret Society, Ritualistic Killings, and a Century-Old Curse: Dive into the Chilling World of ‘Mandala Murders’ Premiering July 25

  • General
  • Health
  • News

    Cracking the Code: Why China’s Economic Challenges Aren’t Shaking Markets, Unlike America’s” – Bloomberg

    Trump’s Narrow Window to Spread the Truth About Harris

    Trump’s Narrow Window to Spread the Truth About Harris

    Israel-Gaza war live updates: Hamas leader Ismail Haniyeh assassinated in Iran, group says

    Israel-Gaza war live updates: Hamas leader Ismail Haniyeh assassinated in Iran, group says

    PAP Boss to Niger Delta Youths, Stay Away from the Protest

    PAP Boss to Niger Delta Youths, Stay Away from the Protest

    Court Restricts Protests In Lagos To Freedom, Peace Park

    Court Restricts Protests In Lagos To Freedom, Peace Park

    Fans React to Jazz Jennings’ Inspiring Weight Loss Journey

    Fans React to Jazz Jennings’ Inspiring Weight Loss Journey

    Trending Tags

    • Trump Inauguration
    • United Stated
    • White House
    • Market Stories
    • Election Results
  • Science
  • Sports
  • Technology
    New Technology for Water Efficiency and Working with Mexico on Screwworm – AG INFORMATION NETWORK OF THE WEST

    Revolutionary Water Efficiency Technology and Cross-Border Collaboration to Defeat Screwworm

    Environmental cognitive distance, R&D capability distance, and supply chain green technology innovation – Nature

    Bridging Gaps: How Environmental and R&D Differences Drive Green Technology Innovation in Supply Chains

    LG Innotek CEO Moon Hyuksoo: “Our Next-gen Substrate Technology Will Change the Industry Paradigm” – TechPowerUp

    LG Innotek CEO Moon Hyuksoo: “Our Next-Gen Substrate Technology Will Revolutionize the Industry” Revolutionizing the Future: LG Innotek’s CEO Unveils Game-Changing Next-Gen Substrate Technology

    Inspira Technologies Secures Landmark $22.5M Deal: Major Revenue Breakthrough After FDA Clearance – Stock Titan

    Inspira Technologies Secures Landmark $22.5M Deal: Major Revenue Breakthrough After FDA Clearance – Stock Titan

    Meiwu Technology Company Limited and Shenzhen Zhinuo – GlobeNewswire

    Meiwu Technology Company Limited and Shenzhen Zhinuo – GlobeNewswire

    Owls inspire new revolutionary noise reduction technology – KTEN

    Owls inspire new revolutionary noise reduction technology – KTEN

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
No Result
View All Result
Earth-News
No Result
View All Result
Home Technology

Don’t pass structs bigger than 16 bytes on AMD64

January 5, 2024
in Technology
Don’t pass structs bigger than 16 bytes on AMD64
Share on FacebookShare on Twitter

Or “How I sped up Neat by a factor of 2x”.

If you check the related_post_gen benchmark, you will find that Neat,
my language, has moved up a few spots. How did I achieve this? Did I implement new high-level optimizer
passes that use language details to expose hidden optimization potential?

I changed arrays to be passed as three pointer parameters instead of one parameter consisting of a
three-pointer struct. That’s it.

This problem has been vexing me for a long time. Neat seemed weirdly slower than it should have been,
particularly compared to D, and if I looked at a profiler I would be seeing a lot of weird stack moves.
The compiler seemed to be spending most of its time rearranging large amounts of the stack for function calls.

Why are Neat arrays three pointers? As opposed to D, Neat employs a refcounter. That means that arrays, in addition
to start and end, also need a pointer to the base of the array object, where the reference count is stored.
It turns out the reason that D arrays are fast and Neat arrays are so slow is just because having 24 bytes instead of
16 puts them into a different regime of parameter passing.

If we check the SystemV AMD64 ABI specification (PDF),
it tells us that any struct greater than 16 bytes is passed by pointer.
(“If the size of the aggregate exceeds two eightbytes and the first eightbyte isn’t SSE or any other
eightbyte isn’t SSEUP, the whole argument is passed in memory.”)
To pass a struct by memory, we allocate a struct-sized spot on the stack, fill it with the values we pass, then
pass the pointer to the function.

Now, LLVM is a very good optimizer, but this does not leave it much room. The value has to go on the stack, which
means there must be space for it there, it must be copied out of the register it is probably living in, and
it has to remember which parts of the stack are in use and which ones can be reused by another call, which it turns
out to be pretty poor at.

We can demonstrate the issue with this benchmark:

==========
harness.h:
==========

#define TYPE double

struct Vector { TYPE x, y, z; };

struct Vector vector_add_struct(struct Vector left, struct Vector right);

struct Vector vector_add_fields(
TYPE left_x, TYPE left_y, TYPE left_z,
TYPE right_x, TYPE right_y, TYPE right_z);

==========
harness.c:
==========

#include
#include
#include “harness.h”

int main(int argc, const char *argv[])
{
int mode=atoi(argv[1]);
int length=atoi(argv[2]);
struct Vector result={0};
if (mode==0)
{
for (int i=0; i As you can see, depending on parameters, this either passes some values as separate parameters or a single large struct.
The mode and run length are passed on the commandline to prevent the optimizer from constant folding everything.

We must compile impl.c separately to avoid inlining:

clang -O3 impl.c -c -o impl.o
clang -O3 harness.c impl.o -o benchmark
time ./benchmark 0 1000000000
time ./benchmark 1 1000000000

This is hardly subtle: with just the change of passing three separate fields instead of a vector struct, I go
from 12.3 seconds to 5.3 seconds!

If we check the assembly, we can indeed see that a lot of instructions are occupied with stack shuffles.
In fact, a major benefit of the field version is that the parameters already enter the function in SSE registers, rather
than having to be loaded from the stack every time. This was the whole point of the SystemV ABI and its focus on
passing values in registers as much as possible, so it’s kind of sad to see it fail here. I believe with the number of
registers available on AMD64, a benchmark would have shown by-value passing to be valuable even for types above 16 bytes.

In fact, if you think about what the code does, by writing the fields on the stack and then (explicitly rather than
implicitly) passing a pointer, the (new, performant) AMD64 System V ABI has effectively regressed to the old x86 cdecl
ABI, where everything was passed on the stack! Cdecl, famously, was so known for its slowness that it spawned multiple
calling conventions aimed just at making it fast.

Of course, in any real situation this code would be all inlined. In fact, turning on LTO with gcc (though interestingly
not clang!) erases any performance difference between the two versions. But still, not every function can or
should be inlined.

Now, if you are calling a C API, you have to use the C ABI. But lots of high-level types internal to non-C languages,
though they may be presented to the compiler’s backend as a struct (such as Neat’s three-pointer arrays), don’t strictly
speaking need to be expressed as one. You are the language writer, and it’s up to you to decide how arrays,
tuples, sumtypes etc. are passed. That’s why I chose to pass all of those (if above 16 bytes) as individual fields instead,
and the benchmark shows the benefit.

So if you are on AMD64, and you’re either working on languages or microoptimizing an API, I advise you to take
the free speedup. You should at least benchmark to see if you can benefit from splitting structs above 16 bytes manually.
Especially in inner loops, the benefit can be surprisingly large.

Addendum:

Q: Sure, maybe this is true for structs of pointers. But double is in class SSE, according to the spec.
Why isn’t the struct passed in SSE registers anyways?
A: Man I don’t know. All I can tell you is that it doesn’t.

>>> Read full article>>>
Copyright for syndicated content belongs to the linked Source : Hacker News – https://gist.github.com/FeepingCreature/5dff669aad380a123b15659e195fb96c

Tags: Don’tstructstechnology
Previous Post

How Australia’s ‘Bluey’ conquered children’s entertainment

Next Post

Learning bimanual mobile manipulation with low-cost whole-body teleoperation

New Technology for Water Efficiency and Working with Mexico on Screwworm – AG INFORMATION NETWORK OF THE WEST

Revolutionary Water Efficiency Technology and Cross-Border Collaboration to Defeat Screwworm

July 4, 2025
California AG Rob Bonta says online fantasy sports platforms are illegal in the state – KCRA

California AG Rob Bonta Cracks Down, Declares Online Fantasy Sports Platforms Illegal

July 4, 2025
Bridge Point Tacoma permit and settlement – Washington State Department of Ecology (.gov)

Bridge Point Tacoma permit and settlement – Washington State Department of Ecology (.gov)

July 4, 2025
Accelerated data-driven materials science with the Materials Project – Nature

Accelerated data-driven materials science with the Materials Project – Nature

July 4, 2025
Downtown Louisville, Ky., gets new lifestyle hotel – hotelmanagement.net

Downtown Louisville Welcomes Exciting New Lifestyle Hotel

July 4, 2025
Romer: Finding common ground in a divided world – VailDaily.com

Romer: Building Bridges to Unite a Divided World

July 4, 2025
The Republican Budget Bill Is an Economy Killer – Bloomberg.com

The Republican Budget Bill Is an Economy Killer – Bloomberg.com

July 4, 2025
Kennedy Publishing, MGA Entertainment Launch Yummiland Magazine – License Global

Kennedy Publishing, MGA Entertainment Launch Yummiland Magazine – License Global

July 4, 2025
Trump says his 6th phone call with Putin this year ‘didn’t make any progress’ – PBS

Trump says his 6th phone call with Putin this year ‘didn’t make any progress’ – PBS

July 4, 2025
Environmental cognitive distance, R&D capability distance, and supply chain green technology innovation – Nature

Bridging Gaps: How Environmental and R&D Differences Drive Green Technology Innovation in Supply Chains

July 4, 2025

Categories

Archives

July 2025
MTWTFSS
 123456
78910111213
14151617181920
21222324252627
28293031 
« Jun    
Earth-News.info

The Earth News is an independent English-language daily published Website from all around the World News

Browse by Category

  • Business (20,132)
  • Ecology (705)
  • Economy (731)
  • Entertainment (21,619)
  • General (15,711)
  • Health (9,768)
  • Lifestyle (735)
  • News (22,149)
  • People (731)
  • Politics (738)
  • Science (15,947)
  • Sports (21,229)
  • Technology (15,715)
  • World (711)

Recent News

New Technology for Water Efficiency and Working with Mexico on Screwworm – AG INFORMATION NETWORK OF THE WEST

Revolutionary Water Efficiency Technology and Cross-Border Collaboration to Defeat Screwworm

July 4, 2025
California AG Rob Bonta says online fantasy sports platforms are illegal in the state – KCRA

California AG Rob Bonta Cracks Down, Declares Online Fantasy Sports Platforms Illegal

July 4, 2025
  • About
  • Advertise
  • Privacy & Policy
  • Contact

© 2023 earth-news.info

No Result
View All Result

© 2023 earth-news.info

No Result
View All Result

© 2023 earth-news.info

Go to mobile version