Skip to main content

Search

Items tagged with: cplusplus


One of the reasons I keep dropping hints about #perlffi , #pdl and #openmp is that one can literally have five multithreading frameworks in the same #perl application of a master process: 1) PDL, and FFI intefacing with 2) #Fortran coarrays, 3) Fortran openmp, 4) #c openmp and 5) #cplusplus #openmp. All these frameworks can share memory addresses for array and vector objects, and #perl aided by #PerlAlien makes the authoring of the high-level code a pleasure ! https://hgpu.org/?p=29403

submitted by /u/ReplacementSlight413
[link] [comments]


Fun project: a #memory manager for multi-lang applications (#c, #cplusplus #assembly #fortran) in which workflow management is done by #Perl. Currently allocates using either #perl strings or #glibc malloc/calloc. Other allocators #jemalloc coming soon.
https://github.com/chrisarg/task-memmanager


Direct (non-LinkedIn-shortened) link: https://catonmat.net/ftp/perl1line.txt

I’m also pleased that its author ranked Perl as one of his top 5 best #programming languages: https://catonmat.net/5-best-programming-languages
1. #C / #Clang
2. #PHP
3. #Perl
4. #GoLang
5. #JavaScript (but only version 1 circa 1995 plus #jQuery)

His 5 worst? https://catonmat.net/5-worst-programming-languages
1. #Haskell
2. #Rust / #RustLang
3. #CPlusPlus
4. #Python
5. modern #JavaScript

β€œMy only metric... is time to get things done and ship to customers.”


I want a really good hate speech piece though, not a moderate one. The challenge is to do those well, a task complicated because of the inferiority complex of your average computer language troll against #fortran (too mathsy) and the bona fide superiority of the portable assembly language we known as #clang for many tasks. To clarify #cplusplus bashing does not qualify as #clang trashtalking.


To demonstrate the power of C++, I have reimplemented the algorithm in a single file using the built-in metaprogramming capabilities of C++. No more manual source generation; no more Python!

#[url=https://infosec.exchange/tags/include]include[/url] <stdio.h><br>#[url=https://infosec.exchange/tags/include]include[/url] <stdint.h><br>#[url=https://infosec.exchange/tags/include]include[/url] <stdlib.h><br>#[url=https://infosec.exchange/tags/include]include[/url] <limits><br><br>using T = uint8_t;<br><br>namespace {<br>    template<T><br>    void do_check(T, const char *, const char *);<br><br>    template<><br>    void do_check<0>(T n, const char *msg_yes, const char *) {<br>        if (n == 0) {<br>            puts(msg_yes);<br>        }<br>    }<br><br>    template<T limit><br>    void do_check(T n, const char *msg_yes, const char *msg_no) {<br>        do_check<limit - 1>(n, msg_no, msg_yes);<br>        if (n == limit) {<br>            puts(msg_yes);<br>        }<br>    }<br>}<br><br>static void check(T n) {<br>    do_check<std::numeric_limits<T>::max()>(n, "odd", "even");<br>}<br><br>int main(int, char **argv) {<br>    check(atoi(argv[1]));<br>}<br>

Compiler explorer: https://godbolt.org/z/434bPMP3M

To generate the comparisons, we use template metaprogramming. However, there are no template loops. C++ templates can be classified as an esoteric purely functional programming language, so we have to use pattern matching and recursion.

The do_check<N> template generates comparisons up to N. Our base case is do_check<0>, which compares to 0 and does nothing else. The general (inductive) case calls do_check<N - 1> and then compares to N.

It is interesting to look at the generated code. G++ translates the algorithm faithfully, if slightly chaotically (look at the order of labels and comparisons in the source; it jumps all over the place). Clang, on the other hand, implements one of the optimizations suggested by @gkemp. It fills a big array with messages (messages[256] = { "even", "odd", "even", "odd", ... }) and then outputs messages[n] (there is only a single call to puts in the generated assembler code).

This covers numbers from 0 to 255 (the range of uint8_t). We can extend the range by switching to using T = uint16_t, although doing so naively runs into the following error:

x.cc:21:28: fatal error: template instantiation depth exceeds maximum of 900 (use β€˜-ftemplate-depth=’ to increase the maximum)<br>

Fortunately it tells us how to fix it and with g++ -ftemplate-depth=65536 we are right back in business. Well, after waiting 2Β½ minutes for the compilation to finish, that is. (Clang is less fortunate: It crashes with a segmentation fault after exhausting the available stack space, at least on Compiler Explorer.)

I haven't dared try T = uint32_t yet.

#CPlusPlus #templates


Could be - though I can't locate line sweep implementations in #perl online (though could find for #cplusplus , #Python and #java). One can further postulate that since a larger (vs #python) chunk of #perl is not oo , the #LLM was more likely to generate this code with less prompting. Or that #perl can go a long way before needing objects (sorry @ovid ).
Would be nice to have a benchmark set of problems to compare #copilot 's performance across languages.


Programmers, developers, coders!

Let's get to know each other in Mastodon

πŸ“» Make a repost, write what you do and where you are from
🀝 Subscribe each other
πŸ›°οΈ Let this signal pass through all obstacles

Let the wave flow! Halt and Catch Fire!

#programming #mastodon #developer #programmer #coding #code #introduction #community #dev #gamedev #webdev #linux #android #ios #csharp #cplusplus #java #javascript #ai #clouds #windows #socialmedia #world #introductions

⇧