Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Lessons in Optimization on Modern X86-64 Silicon
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2  
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9927
Location: almost Mile High in the USA

PostPosted: Mon Mar 10, 2025 4:04 pm    Post subject: Reply with quote

On another note, ultimately since we're doing popcount on constants, I'm doubly surprised gcc didn't optimize all these away to another constant since f(constant) = another constant (at least standard arithmetic operators it's smart enough to do)...

granted fibonacci(999999) or factorial(999999) do take a lot of iterations to run (if not using their closed form solutions) and the compiler would still need to do it, so there's probably some stuff best left for runtime ... else it'd need to know a lot of solutions to iterative functions.
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10747
Location: Somewhere over Atlanta, Georgia

PostPosted: Mon Mar 10, 2025 8:14 pm    Post subject: Reply with quote

Hu wrote:
You may like the related trick that value & (value - 1) is false when value is a power of 2, and true otherwise.
Yeah, that would follow, wouldn't it, because all powers of two only have a single one bit.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10747
Location: Somewhere over Atlanta, Georgia

PostPosted: Mon Mar 10, 2025 8:18 pm    Post subject: Reply with quote

eccerr0r wrote:
On another note, ultimately since we're doing popcount on constants, I'm doubly surprised gcc didn't optimize all these away to another constant since f(constant) = another constant (at least standard arithmetic operators it's smart enough to do)...
At LTO time, you mean? I've seen a rule that says you can't optimize out of existence a function with global visibility. Certainly the compiler doesn't know how it might be used elsewhere.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum