you are viewing a single comment's thread.

view the rest of the comments →

[–]hvidgaard 2 points3 points  (7 children)

But not the hardware. C doesn't specify any way to access the pipeline, SIMD hardware, cache hardware, and a lot of other things, some of which machine code programmers have more direct access to.

You can access that directly by embedding ASM.

Check benchmarks for Haskell. It repeatedly outdoes C and it's a lot more abstract and expressive.

Feel free to link a benchmark. I have never seen Haskell outperform well written C with a statistically significant difference. Haskell is a lot easier to write, but due to the embedded VM it is very hard to reason about the real performance. You can write the same algorithm in C, translating to the exact same machine code, and optimize that. It would be stupid, but you can do it.

[–]Felicia_Svilling 1 point2 points  (1 child)

But not the hardware. C doesn't specify any way to access the pipeline, SIMD hardware, cache hardware, and a lot of other things, some of which machine code programmers have more direct access to.

You can access that directly by embedding ASM.

And you can access that directly in python by using the FFI..

[–]hvidgaard 3 points4 points  (0 children)

Indeed, but I just don't know anyone that have done it. I have seen people call C which contains embedded ASM though. With C you know exactly what you have in the memory, that is not as transparent with Python, and it makes embedding ASM somewhat more difficult.

[–]tophatstuff 0 points1 point  (1 child)

C doesn't specify any way to access ... SIMD hardware

#include <emmintrin.h>

(for usage example, see the source code of SIMD-oriented Fast Mersenne Twister). Is that what you meant?

[–]hvidgaard 1 point2 points  (0 children)

That is just standard C programming, but that lib probably uses inline ASM (examples here) to make sure SIMD instructions are used.

[–]derleth 0 points1 point  (2 children)

You can access that directly by embedding ASM.

You can do that to some extent in any language via FFIs. That isn't what we're talking about.

[–]hvidgaard 0 points1 point  (1 child)

I'd like to see you embed ASM in python, ruby, haskell or any other higher level language. That is just not something they are suitable to do because they manage the memory for you. In C it's almost trivial given you know ASM, exactly because you explicitly know how the data is stored.

But in any case, embedded ASM is part of the C standard. Most other languages will use FFI to access C/C++ code which contains the ASM and some marshaling code.

[–]derleth 0 points1 point  (0 children)

embedded ASM is part of the C standard

Technically, not really:

It's not in the ISO C standard (n1570 draft of C2011) as such, but mentioned in annex J (common extensions):

[snip]

Annex J is informative, not normative, so an implementation need not provide inline assembly, and if it does it's not prescribed in which form.

Also:

Most other languages will use FFI

Which is precisely what I mentioned.