|
You mean you didn't have a backup monitor? Shame on you.
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
I had 2 x 22" (one landscape, one portrait), and an old 18" square one (it used to be Herself's) so there are backups - but I miss my landscape monitor - it's where all the "real work" got done. It was reserved for "full screen" aps: Word, Excel, VS, with Chrome on the portrait, and email / small stuff on the square one.
I've ordered a new 27" to replace it which should be here tomorrow (and hopefully canceled the 24" I did order but which post-order can't be delivered until the 18th).
"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!
|
|
|
|
|
A tale of two functions:
int max(int x, int y) {
if(x>y)
return x;
return y;
}
and
int max(int x, int y) {
return x*(x>y)+y*(x<=y);
}
do the same thing
one is much harder to read, but also optimizable in ways the other isn't.
the CPU really likes code like the second one. Even with the extra multiplies, you can use SIMD instructions to pay for that overhead, while the code doesn't interfere with branch prediction
but coding without ifs gets weird really fast. The above is simple. Now add code to do the same thing but operate on 4 32-bit ints at a time so that it efficiently uses SIMD. Or do something more complicated than finding a max of two values and you'll see what i mean.
Smart optimizing compilers can do some of this, and much of the stdlib is already optimized with simd instructions and branch prediction in mind, but when you're trying to squeeze every last cycle out of your CPU you have to take things into your own hands.
It's not something I'd normally do, but I'm working with a codebase that's already highly optimized, to try and make it faster. So this is par for the course.
Real programmers use butterflies
|
|
|
|
|
What about a ternary operator?
|
|
|
|
|
That's just an abbreviated if statement.
Real programmers use butterflies
|
|
|
|
|
The price of salt has lately gone up so much that today, I enjoyed my breakfast egg without salt.
|
|
|
|
|
Enough to make you weep....
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Hmmm... Your second post on this subject. Do you have a quantum computer in your basement, and need to pay strict attention to the Copenhagen Interpretation?
|
|
|
|
|
No, but I have steve wozinak (the only good thing about apple) in my basement. I lured him there with cookies and promise of a new NeXT
Real programmers use butterflies
|
|
|
|
|
int max(int x, int y) {
return x*(x>y)+y*(x<=y);
}
| |
| OPTIMIZATION |
| OPTIMIZATION |
| OPTIMIZATION |
| OPTIMIZATION |
| OPTIMIZATION |
| OPTIMIZATION |
---- ----
\ /
\ /
\ /
\ /
\ /
\ /
\ /
\ /
\ /
\ /
\ /
\/
int max(int x, int y)
{
if (x > y)
return x;
return y;
}
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
that would figure
Real programmers use butterflies
|
|
|
|
|
This version uses table lookup, no branching.
int max(int x, int y)
{
int arr[2] = {y, x};
return arr[(int)(x > y)];
}
|
|
|
|
|
well played
though you do some memory writes there, which might not be a great thing. then again, it might never leave CPU cache anyway. it's definitely more readable than my approach.
Real programmers use butterflies
modified 8-Jan-21 8:56am.
|
|
|
|
|
In this example the branch prediction won't be an issue. It will basically skip only a few statements. The cost of the multiplications will be significant.
|
|
|
|
|
weird then that my stdlib implementation is branchless. also i'd have to check but i think the compiler can generate better instructions for multiplies by 1 and 0
Real programmers use butterflies
modified 8-Jan-21 10:19am.
|
|
|
|
|
is SIMD a medication your on to prevent writing maintainable code ?
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Yes. It makes my code execute sometimes 16x as fast.
Real programmers use butterflies
|
|
|
|
|
Can I have some of what you're having ?
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Sure!
avx implementation of strstr() by Wojciech Muła
SIMD-friendly algorithms for substring searching[^]
I didn't make my own because i'm allergic to bugs. this compares 16 bytes at a time.
#define _mm512_set1_epu8(c) _mm512_set1_epi32(uint32_t(c) * 0x01010101u)
size_t avx512f_strstr_v2_anysize(const char* string, size_t n, const char* needle, size_t k) {
assert(n > 0);
assert(k > 0);
const __m512i first = _mm512_set1_epu8(needle[0]);
const __m512i last = _mm512_set1_epu8(needle[k - 1]);
char* haystack = const_cast<char*>(string);
char* end = haystack + n;
for (; haystack < end; haystack += 64) {
const __m512i block_first = _mm512_loadu_si512(haystack + 0);
const __m512i block_last = _mm512_loadu_si512(haystack + k - 1);
const __m512i first_zeros = _mm512_xor_si512(block_first, first);
const __m512i zeros = _mm512_ternarylogic_epi32(first_zeros, block_last, last, 0xf6);
uint32_t mask = zero_byte_mask(zeros);
while (mask) {
const uint64_t p = __builtin_ctz(mask);
if (memcmp(haystack + 4*p + 0, needle, k) == 0) {
return (haystack - string) + 4*p + 0;
}
if (memcmp(haystack + 4*p + 1, needle, k) == 0) {
return (haystack - string) + 4*p + 1;
}
if (memcmp(haystack + 4*p + 2, needle, k) == 0) {
return (haystack - string) + 4*p + 2;
}
if (memcmp(haystack + 4*p + 3, needle, k) == 0) {
return (haystack - string) + 4*p + 3;
}
mask = bits::clear_leftmost_set(mask);
}
}
return size_t(-1);
}
Real programmers use butterflies
|
|
|
|
|
Yesterday Her Dell desktop's CPU fan started making grinding noises . I left it alone, kind of hoping it will behave today. Well, no, it got worse. Checked with Dell and her machine is 5 weeks out of warranty. They wanted to sell me a fan/heatsink combination for over $200! Yikes! Then I had a moment of inspiration. I had a much older Dell, which I had previously stripped of its hard drives, just gathering dust. I hauled its fan out and it was an exact match for her machine's fan.
So now Her machine is running silently with an old fan. I checked the factory label on the failed fan. It proudly boasted that it had some "hydrodynamic" bearing. Well, Mr. Dell, your hydrodynamic bearing went for a swim and drowned! Now I also know what to avoid if I ever have to buy another fan!
Get me coffee and no one gets hurt!
|
|
|
|
|
My desktop has a noisy fan - but only when I turn it on in the morning and everything is cold. One of these days I must find out which one it is and replace it, but since it means me trying to do that before my first coffee it is not such a simple task ...
"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!
|
|
|
|
|
One of these days I'm going to make a computer with no moving parts in it. Fanless power supply, one of those copper "bloom" looking heat sinks, NVMe, the works.
I didn't really think about the repairing the fans angle, but that's another good reason to build one.
I'm glad you got your fan issue sorted.
Real programmers use butterflies
|
|
|
|
|
Ya know, you can probably get a fan from amazon that will fit for about $10. if you want a high quality fan, should be no more than #20. You shouldn't need to get a heat sink.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
My thoughts as well. I had a family desktop machine that liked to go through CPU fans once or twice a year. I kept the mounting bracket from the original fan. Replacements got glued on with cyanoacrylate, When they needed to be replaced, a little acetone removed the old fan.
Kind of reminded me of my first car, a '72 Ford Maverick that went through water pumps faster than I did oil changes. I even replaced the water pump one time in the college parking lot. I had the process down to a little more than an hour.
Software Zen: delete this;
|
|
|
|
|
Also avoid installing the fan backwards on the heatsink. Nothing bad will happen...for a couple of years, anyway.
(Yes, I've found two installed wrong-way around. I now check before installing factory-mounted CPU fan/heatsink combos.)
|
|
|
|