Take the following case

   uint256 x = z * 100/1000;//1st statement

   uint256 y = z * 1/10;// 2nd statement

   uint256 superOptimized = z /10;

   ///special cases z * 4/3 or any other number with rounding error or NaN
   ///z = uint256::MAX

    As you can see all statements are essentially doing the same thing

I am coming from an Embedded Engineers perspective at this problem. Depeding on the Microprocesor/Cpu/Microcontroller architecture

More computational resources such as memory/machinecycles are spent on the first statement if the Optimization was handled simply by the CPU at runtime or prior to execution.

If a OS is involved still everything falls back on CPU.

Suppose this code was compiled using a different computer with a Compiler and Language features a Smart language or Compiler will recognize that the unit on the right hand side is the same so both statements are equals in terms of resources. So in Assembly first and second code is outputted as the same.

This example shows that people building popular compilers or creating a new language must have known about this patterns.

My gist of the question beginning from C upto javascript, rust, python and solidity are these arithmatic optimizations as mentioned in Point 4 implemented in language level or compiler level in modern programming languages and to what extent. This may come off as an opinion based question but I was curious about what language/compiler combination produces best optimizations in Computing arithmatic operations.

  • $\begingroup$ What is your question? We are a question-and-answer site, so we ask that you formulate a specific question, and that you ask the question in the body of your post. A question usually ends with a "?". We also expect that you ask only one question per post. $\endgroup$
    – D.W.
    Nov 29, 2021 at 0:12
  • $\begingroup$ I see your different statements doing essentially different things. (2 and 3 would be the same, but 1 is totally different). $\endgroup$
    – gnasher729
    Nov 29, 2021 at 11:24
  • $\begingroup$ @D.W Thanks had a more nuanced and fulfilling discussion at Reddit. Just goes to show how much SO has degraded. Here is a link just in case you need an answer. Thanks reddit.com/r/ProgrammingLanguages/comments/r44oex/… $\endgroup$
    – newInt1x1
    Nov 29, 2021 at 21:12
  • $\begingroup$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. $\endgroup$
    – Community Bot
    Nov 30, 2021 at 14:09


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.