You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
divide by a constant known at compile-time. This is covered by Steven Hoving's code.
divide by a variable. Perhaps lookup parameters in a table and thus we are back to the previous problem.
Case 1: divide by a constant known at compile-time
Perhaps SDCC is smart enough in turn to transform the resulting multiplication-by-a-constant into a series of shift and add.
The net result, for example, is that we can transform a division by 10 into a simple, constant-time, series of shifts and add. This is nice on a simple platform like the Z80.
Case 2: divide by a variable
Nothing more to add: perhaps lookup parameters in a table and thus we are back to the previous problem.
The text was updated successfully, but these errors were encountered:
I can indeed confirm that SDCC is smart enough to do optimizations when multiplying/dividing by constants. I haven't test all possible combinations, but those I have tested are well translated by SDCC. When dividing by variables, SDCC introduces it's own dividing routines and calles them. I think math routines are actually defined in the folder /src/device/lib/z80/
Based on https://github.com/stevenhoving/integer_division .
For example, include https://github.com/stevenhoving/integer_division/blob/master/integer_division_uint8.h and check if it's indeed faster than SDCC's division.
I see 3 cases:
Case 1: divide by a constant known at compile-time
Perhaps SDCC is smart enough in turn to transform the resulting multiplication-by-a-constant into a series of shift and add.
The net result, for example, is that we can transform a division by 10 into a simple, constant-time, series of shifts and add. This is nice on a simple platform like the Z80.
Case 2: divide by a variable
Nothing more to add: perhaps lookup parameters in a table and thus we are back to the previous problem.
The text was updated successfully, but these errors were encountered: