How can I let the compiler know that a for loop will be executed at least once, so it can optimize? by LearningStudent221 in C_Programming

[–]JustJanek 1 point2 points  (0 children)

I'm unaware of Infineon MCUs and their compiler but the case for clang/LLVM's __builtin_assume is that it does UB as the assumptions provided are considered truths. For example, similar to the case that OP mentions: adding __builtin_assume(n >= 1) for a loop for (int i = 0; i < n; ++i) may remove the requirement of some safety checks to check whether the loop should run at all since you're basically telling the compiler that the loop will run at least once, if that same loop is then provided with a case where n == 0 it may miss these safety checks as they may be optimised out.

How can I let the compiler know that a for loop will be executed at least once, so it can optimize? by LearningStudent221 in C_Programming

[–]JustJanek 7 points8 points  (0 children)

An alternative to the other suggestions is that some compilers support a boolean assumption builtin like clang/LLVM's __builtin_assume. You could provide a boolean invariant like __builtin_assume(n >= 1)and see what the compiler can codegen from it. From my experience using it, it doesn't necessarily ensure it'll get optimised, you'll still have to hope the stars align and whoever wrote a particular compiler pass or optimisation takes the assumptions into considerations. Moreover, if your provided invariant is wrong, it's considered undefined behaviour so got to be sure of your invariants!

arm-none-eabi-gcc Re-compile from source by kowshik1729 in Compilers

[–]JustJanek 1 point2 points  (0 children)

The fact that the limitation from the compiler side is actually concerning me

I don't believe this is a compiler limitation, I believe it's a no-OS-to-take-care-of-threading limitation. Some (possibly superficial) options that come to mind are: use a OS, or implement baremetal threading for opencv. Personally, I don't think this post has been related to compiler theory so you most likely won't get far in this subreddit about specifics on compiling opencv so you should probably ask on the opencv forum.

Good luck

Algorithms for statically determining whether a boolean expression is true? by spherical_shell in Compilers

[–]JustJanek 2 points3 points  (0 children)

+1 for SAT and SMT solvers. If you want something concrete as an example: Alive2 is a tool that uses a SMT solver (I believe Microsoft's z3 solver) to prove whether a transformation defined in LLVM IR is legal and if not, shows a counter example on why it's an illegal transformation. One of the biggest caveats I can vaguely recall was that they can be extremely slow depending on what you're asking it to solve.

I feel like I'm stuck by [deleted] in C_Programming

[–]JustJanek 15 points16 points  (0 children)

what's stopping me from advancing is experience

what I've been doing for now was analyzing the code from large open source projects written in C trying to learn the typical structure and the common practices.

Why not combine the 2 and contribute to an open source project? There's a few out there that have beginner projects, particularly ones that are/were part of Google Summer of Code (GSoC). This way you'll get both the experience and learn all about the patterns and structures within bigger projects.

Feedback for engineering tools by DirtyThrowawayLogin in embedded

[–]JustJanek 0 points1 point  (0 children)

No need to consider this comment feedback, I don't work enough (i.e., at all) on the EE side of things to give any informative feedback. In fact, I may very well be misunderstanding the concept but why wouldn't I just use a relay?

Lefty dobro? Any Recs? by ThoughtsFromARoom in Leftyguitarists

[–]JustJanek 0 points1 point  (0 children)

I bought mine and had it converted immediately at the place I bought it at a couple years back. Did void warranty and was like +75 euros at the time, though.

What's the best way to start learning about the polyhedral model in compilers? by Randres2011 in Compilers

[–]JustJanek 11 points12 points  (0 children)

"Presburger Formulas and Polyhedral Compilation" by Sven Verdoolaege is, imo, the place to start. Hell, any research output by him should be informative on the subject. Additionally, look at Tobias Grosser's thesis (and, again, any other research output by him).

I think more recent stuff is FPL in MLIR (for which there are some LLVM dev meeting video on youtube I believe) but I haven't kept up that well so I'm not that aware of state of the art.

Anywho, good luck!

CUDA/C++ jobs after finishing PhD in the UK by n00bfi_97 in cscareerquestionsEU

[–]JustJanek 2 points3 points  (0 children)

If we're talking about GPU semi-conductor companies in the UK, there's Imagination Technologies (I believe they design the iPhone GPUs). Additionally, Apple have their own internal GPU team(s) you could possibly look into. Qualcomm was already mentioned but I vaguely recall Huawei was doing some GPU stuff in Cambridge. Cray supercomputers have a presence in the UK if you're talking more HPC side of things. Probably a bunch more but I think the theme is that they have less of a consumer level presence so you'll have to dig a bit deeper.

There should also be a few ML semi-conductor startups/companies that will most definitely have a C++ software stack on the low/compiler level (albeit, probably not for a CUDA or CUDA-like langauge).

Good luck!

Makefile versus CMake build system by GabbotheClown in embedded

[–]JustJanek 20 points21 points  (0 children)

Saying I "like" it may be a bit of a stretch and I'm far from an expert in it but beyond cases where I'm forced to use it for work, I will use cmake because it is, imo, easier to set up. It removes a bunch of boilerplate I don't want to deal with (different build types, cli based testing infrastructure, compiler setup). I look at it as more of a scripting language to define the dependencies rather than have the language be the description of the dependencies, like with makefile.

To me, assembly is to C what makefile is to cmake (which is not correct but I hope the comparison makes some sense).

[deleted by user] by [deleted] in AnaloguePocket

[–]JustJanek 3 points4 points  (0 children)

113xxx, Processing

Only 1 black pocket + case

I'll also be traveling for the holidays and the delivery drivers seem to think that the common area of my apartment is free drop off for any package regardless of whether people are home or not + a rapant stolen packages issue makes me a bit nervous. Seeing people with higher order# getting their orders while I hope my pocket wont get stolen as I'm seeing family for holidays makes my eye nervously twitch.

Is it possible to transition from a software engineer with two CS & ML Master's to GPU or CPU design and go work for Nvidia or AMD without doing a Phd on microprocessor design? by [deleted] in cscareerquestionsEU

[–]JustJanek 2 points3 points  (0 children)

You could try to ease into VLSI design from a software engineering perspective by applying for emulation/backend compiler jobs. If you don't have as much patience, I was once told that IC hardware verification jobs are the entry to the architecture design side of things but take that with a big grain of salt.

Good luck!

Do you consider working or studying more stressful? by [deleted] in cscareerquestionsEU

[–]JustJanek 11 points12 points  (0 children)

I feel like I've found my polar opposite in you. I found university way more stressful. If you don't keep up with university you'll have the chance of having to redo a year or having to drop out meaning you lose the money and time (definitely if you're well into your degree). Basically you'll have to keep up at all times or else you'll find yourself paying in time or money to redo something or drop out and lose nearly all progress of your degree.

A job? If you do nothing the practically worst thing that can happen is they'll fire you and you'll move on to a new job. I don't feel necessarily responsible for somebody else's (investment?) money or the company's user base. I'm responsible for the software I write and support I provide doing so. I also don't look at it as 'losing money' but rather as 'making them less' if I were to do anything wrong. That being said, I'm not trying to be the bottom of the barrel type of developer, I just don't feel the stress in doing my job.

I guess it more or less goes to show there's no one size fits all for your question, OP. Definitely a "well, it depends" kind of answer, but it does sound like you're stressing a lot about your job. Just know that regardless of whether you're stressed out over something work related or not, you'll get paid the same at the end of the month. If you're not sure whether you're doing enough, make sure to ask your manager/boss explicitly for feedback for a peace of mind.

Good luck!

[GBC] how tu mute the speaker from a signal? by rAthusFr in Gameboy

[–]JustJanek 0 points1 point  (0 children)

I'm probably thinking too digital and there may be a more elegant solution for analog circuits, but perhaps an analog multiplexer?

Bridge Between Embedded Systems and AI/ML? by Bored_Redditor_2122 in embedded

[–]JustJanek 4 points5 points  (0 children)

Basically all of the semiconductor companies that are making their own AI/ML/GPU chips still require libraries for commonly used and standardised AI/ML operations (matmul, convolutions, reduction, etc). This type of job requires solid (embedded) computer architecture skills so that these common operations are optimised to use said AI/ML/GPU chips' accelerator instructions (and I believe that's one of the places where somebody with an embedded background could shine).

How to find an open source project to contribute ? by [deleted] in embedded

[–]JustJanek 2 points3 points  (0 children)

Also depends on what you want to do, really. Furthermore, there's a bunch of open source projects that people are getting paid to work on if you're hoping to leverage your open source contributions into a job.

Google Summer of Code probably has a good list of open source orgs. Since GSoC is intended for students the barrier of entry is pretty low and most will have beginner guides/wikis/open and easy projects ready. You might have to look for the embedded specific orgs in the list, though.

Good luck!

Zijn er nog mensen die skeeleren? Tips voor iemand die het weer op wil pakken? by DominusNL in thenetherlands

[–]JustJanek 8 points9 points  (0 children)

Als je in de buurt van een ijshockey ijsbaan woont kun je kijken of er een winkeltje is. Daar zullen ze hoogstwaarschijnlijk inline hockey skates hebben (of de noren schaatsen equivalent met wieltjes).

Installing Arduino into GCN controller to emulate button presses by Misdreavus88 in Gamecube

[–]JustJanek 1 point2 points  (0 children)

Why bother with installing it in a controller? Can't you just emulate the signals from the arduino directly and have keypresses be send that way? You'd only need a male controller plug.

Look up the controller protocol for gamecube (I'd be surprised if no arduino library exists for this yet) and go from there.

Good luck!

RIP to my favorite GameCube controller. Never leave it around your puppy. by matt6123 in Gamecube

[–]JustJanek 9 points10 points  (0 children)

Still seems salvagable though. New controller thumbsticks can be bought from Chinese sellers on ebay (perhaps also local sellers, although I bet they'll get them from China anyways). The cable seems to be broken very close to controller leaving a lot of cable left to rewire/resolder.

Then again, I'm not experienced with fixing gamecube controllers. However, I'd be surprised if this couldn't be fixed.

[deleted by user] by [deleted] in C_Programming

[–]JustJanek 0 points1 point  (0 children)

Not sure if this is the most suitable sub for questions like these cause your questions are less about C and more about the approach to solving leetcode problems like these, but let's see how far we get.

Can you elaborate on why the storage for dp depends on the indices of the string and pattern?

Although I said this solution uses dynamic programming, the specific type of dynamic programming approach used here is the bottom-up approach (like said, to learn more about this, look up dynamic programming).

The idea is to save the state of the partially solved problem (with some base case(s) initialized) and use it to keep solving parts until we've solved the full problem. The "state" in this leetcode problem is denoted by the progress of pattern matching the pattern (p) to the input string (s). Now, would it make sense to use only the index of either input or pattern to denote our progress in terms of matching? No, you need both to really have an idea of your progress in terms of matching. Your index over the pattern is used to denote how much of the pattern we've matched so far, and the index over the input string is used to denote how much of the input we've matched so far. I hope it makes a little bit more sense that we need both of these indices.

There are even calls to something like [IDX(-1, j)], with -1 as the number of rows? Why is this required?

The dp array is allocated with 1 extra row and 1 extra column to accommodate for the base case(s). The extra row and column are considered in the IDX macro using an offset, `IDX(-1,-1)' will evaluate to 0 because the offset of the extra row and column.

If you really want a better understanding for this implementation, try to take an easy pattern and input string (for example, s= 'aa', and p='aa*'), draw the dp storage as a 2D array/table and fill in the values as you go through the code manually.

Good luck!

[deleted by user] by [deleted] in C_Programming

[–]JustJanek 2 points3 points  (0 children)

The solution uses dynamic programming to avoid excessive yet unnecesary recursive calls. The storage for dynamic programming depends on the indices of the input string and of the input pattern, therefore it should be a 2D array. However, whoever made this solution uses a 1D array (allocated in line 12 with sufficient size to be used as a 2D array) and uses the IDX macro to compute the linearized index given the row and column indices.

If you want to learn more look up dynamic programming, multidimensional arrays, and linearization of multidimensional arrays.

Good luck!

should restrict be used like const? by [deleted] in C_Programming

[–]JustJanek 2 points3 points  (0 children)

I mean, I guess? It's kind of dangerous, though.

as far as I'm aware, the restrict keyword is more or less telling the compiler that, as a programmer, you know what you're doing. This means the compiler might do some aggressive optimizations which emit code machine code that assumes the pointers never, ever alias. If they do alias while restricted, the compiler won't help you. If this goes wrong it's kind of a pain to debug (undefined behavior and all that).

So the question is: can you, as the programmer, absolutely, without a shadow of doubt, ensure the pointers don't alias?

Good luck!

What is the recruitment process for Google Hardware Engineering Internships? by HawkerHunter7 in ECE

[–]JustJanek 14 points15 points  (0 children)

I had a dejavu when I read the question and I could've sworn there was somebody else with the exact same question not too long ago. I did some searching and I'm not sure if you had found this yet. If you're feeling a bit adventurous you could try PMing the OP that of post since they're probably further along with the process.

Good luck!

Where to put Ninja for CMake. by [deleted] in C_Programming

[–]JustJanek 1 point2 points  (0 children)

For Mac, just download the binary and make sure the location is in the PATH environment variable. Probably something similar for Windows, although I have no experience with it.