|
Way more in depth than I've ever gotten. I just avoid ifs in tight code!
But maybe I shouldn't be. I do know if you can make say, an entire DFA traversal without conditional branching (and I think it's possible?) it should be significantly faster than the traditional method, which requires a ton of branching, but then you probably wouldn't be using idiv instructions in the first place with such a beast.
So I guess ultimately it depends, as you suggest.
I did not know that about the ARMs. I've been mostly dealing with Tensilica XTensa LX chips, but I'm getting sick of them.
The trouble with ARMs is they're as rare as hen's teeth. Out of stock everywhere for the ones I want.
To err is human. Fortune favors the monsters.
|
|
|
|
|
I wouldn't care one way or the other unless this code was executed frequently. Very frequently.
|
|
|
|
|
The conditional branch should be slower on modern/latest Desktop cpu.
Have a look at this table: Instruction tables
Scroll down to the Intel 11th generation Tiger Lake. The IDIV only costs 4 ops. The JGE and two MOVs for the conditional will exceed that.
It depends on the cpu, older architectures benefit from the branch.
|
|
|
|
|
CMP+JGE (these macro-fuse) and two MOVs is only 3 µops, and they're fast µops. Why are there two movs anyway, only entry.assetLen should be getting loaded here, we already have gopNr and I don't see any immediate reason to copy it to another register. These µops are also not in the dependency chain of gopNr , they're only there for the compare&branch, following code could execute at the same time as this condition is being evaluated (of course subject to throughput limitations).
At least one of the µops in IDIV has a bad latency and moderately bad throughput, and they're in the dependency chain from computing gopNr to using it (not shown).
|
|
|
|
|
Yeah,
If it makes you feel better, I would probably use the 'if statement' simply because not everyone is on Ice/Tiger Lake.
|
|
|
|
|
I suppose both operands are known to always be positive?
If not, you understand that the meaning of the % operator varies between languages?
I probably wouldn't use the if , though I might test both ways just out of curiosity.
It looks like a sophomoric inclusion.
A freshman doesn't know an issue may exist.
A sophomore thinks an issue may exist -- and adds protection.
A master knows the suspected issue doesn't exist.
A little knowledge is a dangerous thing.
It's like when junior developers test an index value every time rather than simply catching an Exception (C#) when something goes awry.
|
|
|
|
|
My gut feeling is that code that's clever at the expense of readability should only be allowed when it has a demonstrated performance impact. Show me something that indicates that it will significantly increase application performance or the PR gets rejected.
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
|
|
|
|
|
Yeah! If you can't do it in VB then don't other.
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
I'll put the if there, especially if wrapping is unusual.
Even on modern chips with so-called "fast division", 64-bit div (surely we're talking about unsigned numbers here?) takes over a dozen cycles at best. Sure it has only a few µops today, but they're µops with a high latency (or at least one of them is anyway). Further in the past, div only gets worse. Computers with "slow division" are still extremely common. Cascade Lake still had slow division, those are high-end computers that are only a couple of years old.
By contrast, a branch can be bad, but this one won't be, if the comment is to be believed. If wrapping is unusual, then the branch will usually be correctly predicted non-taken. The comparison (and associated loads, if any) that happens before the branch is also nearly irrelevant in that case, because that dependency chain ends in the branch. Code after it does not need to wait until the comparison is done. In the normal case where there is no wrapping, an instruction that uses the new value of gopNr may be able to execute back-to-back with the instruction that produced it (doesn't mean it will, but it could). That is of course impossible if there was a div between them.
If that is expensive, there might even be an if in the operator already...
Doesn't happen on any compiler I'm familiar with. I'm not familiar with the Go compiler, but still. It's not really a thing.
modified 14-Sep-22 11:58am.
|
|
|
|
|
megaadam wrote: blazing 10 nanoseconds
That's about 10 feet (3 meters) at light speed. Whenever I see 'nanoseconds', I am reminded of USN Rear Admiral Grace Hopper - one of the "great's" in early computing history. See, for example, Grace Hopper's Nanoseconds[^]
<edit>Mis-spelt 'Hopper'
modified 15-Sep-22 5:28am.
|
|
|
|
|
Tyrant works with badly paid journalist (9)
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
OPPRESSOR = Tyrant ?
Journalist = PRESS
Badly paid = POOR
|
|
|
|
|
And you are up tomorrow
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
As if I needed another reason to hate python, and the fact that there are people out there that actually like it.
I've been trying to check my lightweight TTF code into the LVGL master branch. I have been working at it for days - far longer than it took me to write the actual code.
The STUPID MICROPYTHON AUTOMAGIC BINDINGS GENERATORS FAIL
Nobody knows how they work. Nobody knows why.
They modify my friggin code. They parse it and MODIFY IT.
And nobody knows how it works.
I finally told them sorry, until they drop support for micropython or start writing their bindings by hand I can't support their codebase.
So I am not a contributor to LVGL.
If you're upset about it (I know I am), talk to them. I already have.
To err is human. Fortune favors the monsters.
|
|
|
|
|
Quote: The STUPID MICROPYTHON AUTOMAGIC BINDINGS GENERATORS FAIL
Quote: Nobody knows how they work. Nobody knows why.
Another adventure is waiting for you!
As side note, Lua binding mechanism is crystal clear.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
No.
And yeah, generating Lua bindings by parsing C would be just as bad as doing it with python.
To err is human. Fortune favors the monsters.
|
|
|
|
|
Life is a long chain of compromises. I understand you are upset, but honestly I think there is more for you to lose not to contribute. Take a deep breath and go back to it, it would surprise me you would not find a spell to make it work.
|
|
|
|
|
One generated c file for all the micropython bindings.
scripts i don't even know where they exist. Much less how they work.
And i'm not going to find out. I don't want to.
I don't WANT to learn Micropython to fix *THEIR* build scripts.
It's a project with over 300 contributors. Let THEM do it.
It's not my job. Nor do I want it to be.
Not my circus. Not my monkeys.
To err is human. Fortune favors the monsters.
|
|
|
|
|
I'm expecting a series of post about a new fancy bindings generator for Python in the near future.
|
|
|
|
|
The only reason I'd ever use Python is to show someone why they should never use python.
To err is human. Fortune favors the monsters.
|
|
|
|
|
I guess you mean that you hate their elephanting micropython hack. But you wrote that you hate Python. That might not exactly be where blame is deserved...
This is the first time I hear about micropython. Perhaps Cython seems to an alternative that creates readable cod? Cython: C-Extensions for Python[^]
And many numerical standard libraries are written in C. Maybe creating your own bindings is easy?
1. Extending Python with C or C++ — Python 3.10.7 documentation[^]
But then I just realise that maybe the LVGL-folks have painted you into the micro... corner
"If we don't change direction, we'll end up where we're going"
|
|
|
|
|
Python always deserves blame. It was written by someone who didn't understand a simple, obvious concept: When you make whitespace part of your program, it means part of your source code is invisible.
Anyone that stupid should not be allowed near a computer.
Edit: Specifically, I blame python because if it didn't exist this would have never been a problem.
Edit 2: The language you mention shouldn't exist, but does anyway. It doesn't run anywhere that matters.
To err is human. Fortune favors the monsters.
|
|
|
|
|
honey the codewitch wrote: When you make whitespace part of your program, it means part of your source code is invisible.
Unfortunately I can upvote it only once - otherwise I would make you a CP millionaire...
"Everybody is a genius. But if you judge a fish by its ability to climb a tree, it will live its whole life believing that it is stupid." ― Albert Einstein
|
|
|
|
|
Since the Soapbox is closed I am not entering the War on Python, on either side...
But I was referring to your specific complaint&blame regarding the micropython toolchain forking up your code. That is clearly a micropython blunder. Anyway, what happened to all your praise for this Gabor-dude, he appears to fancy the Python-concept?
"If we don't change direction, we'll end up where we're going"
|
|
|
|