|
The answer to that also comes from XKCD
|
|
|
|
|
Instead of just complaining about it, I set out to fix it. Although maybe "fix" is a big word for what I'm doing since I'm not building it into the language, just adding it on as a class library. As a result it does not mix with normal code well.
Here is an example of what it would look like:
SIMDcode s = new SIMDcode(_ =>
{
var ptr = _.arg(0);
var size = _.arg(1);
var constants = _.arg(2);
var w = _._mm_loadu_si128(constants, 0);
var shufmask = _._mm_loadu_si128(constants, 16);
var alpha = _._mm_loadu_si128(constants, 32);
_.repeat(size, 4);
{
var p = _._mm_load_si128(ptr, 0);
p = _._mm_maddubs_epi16(p, w);
p = _._mm_add_epi32(p, _._mm_srli_si128(p, 2));
p = _._mm_srli_epi32(p, 6);
p = _._mm_shuffle_epi8(p, shufmask);
p = _._mm_or_si128(p, alpha);
_._mm_store_si128(ptr, 0, p);
_.add_r_i(ptr, 16);
}
_.endrepeat();
});
The "meat" looks just like "intrinsics" like you're used to (or not, if you've never worked with them), but in this case they're not proper intrinsic functions. When executed they build up some internal representation of the code, which is then compiled and written to unmanaged memory. That is also why it needs the "weird stuff" such as `arg` and `repeat` and `add_r_i` - normally normal code fills those rolls but here normal C# code will just execute once, it does not itself end up in the native code.
The native code generated by the example above is
push rbp
mov rbp,rsp
vmovdqu xmm0,XMMWORD PTR [r8]
vmovdqu xmm1,XMMWORD PTR [r8+0x10]
vmovdqu xmm2,XMMWORD PTR [r8+0x20]
15: vmovdqa xmm3,XMMWORD PTR [rcx]
vpmaddubsw xmm3,xmm3,xmm0
vpsrldq xmm4,xmm3,0x2
vpaddd xmm3,xmm3,xmm4
vpsrld xmm3,xmm3,0x6
vpshufb xmm3,xmm3,xmm1
vpor xmm3,xmm3,xmm2
vmovdqa XMMWORD PTR [rcx],xmm3
add rcx,0x10
sub rdx,0x4
jnz 0x15
leave
ret
To actually invoke the code you define a delegate and ask for a function pointer of that type:
delegate void ToGrayDelegate(IntPtr pixels, int length, byte[] constants);
...
var f = s.GetDelegate<ToGrayDelegate>(0);
Just invoke that as normal. (this runs in 1 cycle per pixel on Haswell, the best I could do in pure C# was 6 cycles per pixel)
This is just a preview, and maybe that's all it will ever be. A bunch of things work, a lot of things do not work yet, because I just threw this whole together in a day.
Anyway I'm not sure how useful this actually is. On the one hand, you wouldn't need a separate C++ project that has to be kept in sync with the main project (but that's not even a real problem). On the other hand, it's more annoying to write code like in the example than to just write C++ with intrinsics. But this way the code can be tuned with run-time parameters (but is that even useful? and you can't do it too often since compiling more code obviously costs time). Theoretically this can easily support x86 and x64 simultaneously (that's a bit of a hassle with native dlls), but choosing one of them at compile time isn't really a problem anyway.
Compared to System.Numerics.Vectors I'd say this is a lot better - it actually allows you to get stuff done, there are all the usual things that you need such as shuffles and shifts and oddball instructions like vpmaddubsw. But compared to a C++ dll it doesn't seem all that useful.
So what do you think. Useful? Interesting? Total waste of time?
modified 14-Mar-17 8:17am.
|
|
|
|
|
Nevermind what anyone else says, this looks fascinating. I would love to see an article or three about this.
This space for rent
|
|
|
|
|
|
Pete O'Hanlon wrote: Nevermind what anyone else says
Damn, now I am not going to be able to say anything.
|
|
|
|
|
An interesting idea. As Pete says, I'd like to see a proper article written about this.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
I second the opinion that an article on this would definetely be interesting, I am a user of SIMD and intrinsics and while I plan to use C# (if and when we will be able to spend the due time necessary to rewrite 60kloc in VB6 unto muche less C#) only for the GUI and leave the meat of elaborations and hardware and I/O processing in C++ I would definetely bookmark such a technique as it could prove useful in a number of situations.
* CALL APOGEE, SAY AARDWOLF
* GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X
* Never pay more than 20 bucks for a computer game.
* I'm a puny punmaker.
|
|
|
|
|
If you are not already doing so.
Thought I would share this real world experience with some of the newer developers here.
Do you think you deserve a promotion or a raise in pay? Ask for it.
You can't expect anyone to advocate for you other than...you. I try to take care of my team, and reward those who are on the radar, but sometimes that falls through the cracks and I miss things.
I recently had a team member who felt they were being overlooked on promo/raise. That team member advocated for himself. They brought their concerns to me, we discussed, and now they are scheduled for promo and raise.
It doesn't hurt to ask. If you work at a company where asking can have negative consequences, then you are working at the wrong company and you need to move on.
modified 14-Mar-17 6:46am.
|
|
|
|
|
As my Grannie used to say: "They can only say no".
I'd love to know where the biscuit factory is.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Mark_Wallace wrote: "They can only say no".
Exactly.
However, even if I say no, or upper management says no, that person is now on our radar, and the next time could be yes.
|
|
|
|
|
Slacker007 wrote: However, even if I say no,
I didn't realise you was in management.
Slacker007 wrote: now on our radar
Oh yes, I see you are now.
|
|
|
|
|
|
BURN THE WITCH!
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Slacker007 wrote: that person is now on our radar
[Devil's advocate mode] Being on management's radar as someone who is not happy with their salary may not always be a good thing. [/Devil's advocate mode]
|
|
|
|
|
It can be a good thing if you are a valued employee.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Depends on the organization. Such practices in highly structured organizations where salary review is part of a set schedule can be considered stepping out of line or whishing to be treated with 'special' consideration over and above coworkers who operate within the bounds of policy.
Such organizations it would be better to keep your powder dry until such a review interval and then express a strong case advocating your position while remaining within the set parameters of policy.
|
|
|
|
|
And if they say 'no', then ask about what goals you can achieve that will change that.
Open a conversation about your career path in that organization.
Let them know you want advancement, otherwise you'll just be one of the worker-drones.
Mark
Just another cog in the wheel
|
|
|
|
|
Slacker007 wrote: If you work at a company where asking can have negative consequences, then you are working at the wrong company and you need to move on.
If you work for a company that has no idea of your work, how you are doing, your skills and abilities, where you need to ask for recognition instead of just getting the recognition you deserve then you need to move on and find a company that takes an active interest in their employees
|
|
|
|
|
I don't agree. A business needs to be concerned about running the business, of which only part is keeping the employees happy. At every place I have worked, people always have more to do than they can actually accomplish and so they don't always focus on employee happiness. A supervisor might be completely happy with your work, but neglect to mention it. An employee advocating on their own behalf could just remind a supervisor of something that should have been done a while ago.
I've had at least three occasions where I have worked for excellent people who have not offered me a raise, but who responded positively when I asked.
Outside of a dog, a book is a man's best friend; inside of a dog, it's too dark to read. -- Groucho Marx
|
|
|
|
|
And also to add to that, ask for realistic pay rises. Where I work a previous developer who had been with the company for 12 months tried to ask for a £10,000 pay rise one year.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Well if this guy can can earn £26,000 an hour...
Ah, I see you have the machine that goes ping. This is my favorite. You see we lease it back from the company we sold it to and that way it comes under the monthly current budget and not the capital account.
modified 31-Aug-21 21:01pm.
|
|
|
|
|
If you don't ask, you don't get. Simple.
|
|
|
|
|
Thanks for the advice.
For future reference I'm just letting everyone know that I'm awesome
|
|
|
|
|
Mathew Crothers wrote: I'm just letting everyone know that I'm awesome
As you should, and is highly recommended.
|
|
|
|
|
Rightfully said, I've known people rise to the top in terms of pay just by keeping pressure on the management for raises.
Others lacked the vigor to push their agendas afraid of getting the pink slip.
Take your chances.
Sometimes it is better to be sorry (ephmerally) than to be safe.
Let the future tell the truth, and evaluate each one according to his work and accomplishments. The present is theirs; the future, for which I have really worked, is mine
|
|
|
|
|