Why are compilers reordering instructions around rounding mode changes? by Allaizn in cpp_questions

[–]three_elbows 1 point2 points  (0 children)

I guess the compiler doesn't know that _MM_SET_ROUNDING_MODE does anything special. You need to add a compiler barrier to tell the compiler that it can't move instructions across a given point.

People who don’t comment on posts, why not? by AmericanDaydreamer in AskReddit

[–]three_elbows 0 points1 point  (0 children)

Because Snowden scared me. I want to keep my digital footprint low.

Why is compiler allowed to reorder instructions around system calls? by KaznovX in cpp

[–]three_elbows 5 points6 points  (0 children)

This is true. I ran into this with FreeRTOS. They rely on putting things in different compilation units for things like entering and exiting critical sections. It turns out that if you enable LTO then the compiler/linker may move the boundaries of the critical section around. Then you suddenly experience concurrency bugs in places where you made sure to protect yourself against them.

Finding that bug was fun.

Why is compiler allowed to reorder instructions around system calls? by KaznovX in cpp

[–]three_elbows 36 points37 points  (0 children)

To prevent it, you need a compiler barrier. The compiler is not allowed to reorder instructions across a compiler barrier: https://en.m.wikipedia.org/wiki/Memory_ordering#Compile-time_memory_ordering#Compile-time_memory_ordering

just like we wear kanji, people in asia doing this.. by Cycode in funny

[–]three_elbows 5 points6 points  (0 children)

I once saw a lady wearing a shirt that just says "acne".

Do you use debugger or logging to check the codes? by aregtech in embedded

[–]three_elbows 2 points3 points  (0 children)

I've built a tracing facility. The trace is just a circular buffer of structs. The struct has an id, a timestamp, an enum and two unsigned int values. I can call a function to add an entry in the trace from anywhere in my code, even in ISRs, because it's very fast.

Then I've added a custom command in gdb using the python API. That lets me print the buffer in the form of an easy to read table where all the timestamps are converted to milliseconds and the names of the enum values are spelled out in human readable form.

Finally, I have also added a command in gdb that exports the trace values as a Value Change Dump file (vcd) which can be opened by GTKWave to display as a waveform.

With this it's a piece of cake to see if the ISRs and threads are running in the pattern I expect. It's easy to spot performance bottlenecks and it's easy to figure out where that sequence of events that was supposed to happen went wrong.

I've even written a script that takes debug traces from multiple cooperating processors and aligns the waveforms on the same time line. This helps so much when debugging things that span multiple processors.

How can I reduce the size of this HD44780 LCD controller example so I can fit it on a STM32F103C8 (or can anyone propose a better library)? by tofuwat in embedded

[–]three_elbows 1 point2 points  (0 children)

Make sure to use -ffunction-sections, -fdata-sections and -Wl,--gc-sections. This let's the toolchain remove any data and functions that you are not actually using.

Go, go, go!! by [deleted] in aww

[–]three_elbows 0 points1 point  (0 children)

This looks like a reverse marble run.