Author Topic: GCC compiler optimisation  (Read 45811 times)

0 Members and 5 Guests are viewing this topic.

Offline AVI-crak

  • Regular Contributor
  • *
  • Posts: 133
  • Country: ru
    • Rtos
Re: GCC compiler optimisation
« Reply #350 on: May 27, 2023, 08:44:22 pm »
One very crooked company made usb hardware buffers with holes (like cheese). Real 16bit data, 16bit empty, 16bit data, 16bit empty, and so on. To transfer data, the company wrote a simple code that GCC optimized to 32bit reads. GCC knows that the buffer is always clear before starting work, and therefore performs the addition with a shift (it is more convenient for it).
You can look for a data transfer error indefinitely when you accidentally deleted a buffer flush.
So, DMA can read sparse data, and write without emptiness. Able to do in the opposite direction (creates cheese). But the configurator from the company prohibits such DMA settings.
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4542
  • Country: nz
Re: GCC compiler optimisation
« Reply #351 on: May 28, 2023, 12:34:00 am »
If I was writing code which actually needs the speed I would do an asm function for it.

It's safer.

Other than needing 3 or 4 or 5 different asm versions if the code is going to be widely used. Always keep a plain C (with idioms you hope will be recognised) as fallback when the code is compiled for an ISA you don't expect.
 
The following users thanked this post: MK14, SiliconWizard

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4316
  • Country: us
Re: GCC compiler optimisation
« Reply #352 on: May 28, 2023, 02:06:07 am »
A compiler that optimizes a byteswap of memory into a load (at memory speed - 10s of nanoseconds) followed by a SWAP instruction (sub-nanosecond speed, once the value is in a register) can handle arbitrary network traffic in any endianness with essentially no performance penalties.  Allowing Intel and AMD to sell into significant markets that used to be dominated by MIPS CPUs (which could be configured for different endianness.)
As of a dozen year ago, that's making switching decisions (in software) for over 4 million packets/s.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf