Missing S12Z compiler intrinsics for max/min

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Missing S12Z compiler intrinsics for max/min

Jump to solution
954 Views
kef2
Senior Contributor IV

Hi,

S12Z compiler intrinsic functions are useful to optimize code without switching to assembler. But why __minu() / __mins() / __maxu() / __maxs() are missing? Optimizer seems being unable to replace something very common like this

   if(x > max) x = max;

with MINU, and time expensive conditional branch is used instead. Any plans to implement these min/max intrinsics and perhaps improve optimizer?

Thanks,

Edward

1 Solution
874 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Edward,

Thanks for your comment.

I will escalate this as feature request to development.

Thanks for bringing the problem to our attention.

Best Regards

Jun Zhang

View solution in original post

3 Replies
874 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Edward

Under CodeWarrior11 install folder, there is file MCU_S12Z_Compiler.pdf. Open this file, take a look at Chapter 17 Supported Intrinsic Functions
"When mixing high level C/C++ code with low level code for better performance, the user can either use inline assembly code or intrinsic function calls. S12Z compiler provides 14 intrinsic that can be used by the user to instruct the compiler to use a specific machine instruction."

The supported functions as as below. Other functions are not supported.

pastedImage_1.png

Thanks,

Jun Zhang

0 Kudos
874 Views
kef2
Senior Contributor IV

Hi Jun,

yes, that was the question! Why only abs, qmul and sat are provided? __abs are very useful. __sat are quite dangerous without looking at disassembly and/or not knowing details of corresponding CPU instruction. __qmul are fine while optimizer doesn't change size of destination register. But why min/max are not here?! Min/max instruction could eliminate needless branches. I could use inline assembler, but it is not as good as it was for S12(X). Local variables on the stack or in registers are almost taboo to use with inline assembler. And __min/__max intrinsics would reduce the needs for inline assembler...

Thanks

Edward

0 Kudos
875 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Edward,

Thanks for your comment.

I will escalate this as feature request to development.

Thanks for bringing the problem to our attention.

Best Regards

Jun Zhang