get CW for HCS12X to use Hardware division

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

get CW for HCS12X to use Hardware division

跳至解决方案
3,021 次查看
oiser
Contributor I
Hello.
 
Im trying to divide a signed 32bit integer by a singned 16bit integer and want to have a signed 16bit bit result.
 
like this:
Code:

sint32 multiplic;
sint16 divisor;
sint16result;

result = multiplic / divisor;
the compiler always generates code with a call of the subroutine _LDIVS instead of using the EDIVS instruction.

Code:
74: result = multiplic / divisor;00d8 fc0000 [3] LDD divisor00db b74d [1] SEX D,X00dd 3b [2] PSHD 00de 34 [2] PSHX 00df fc0000 [3] LDD multiplic:200e2 b765 [1] TFR Y,X00e4 160000 [4] JSR _LDIVS00e7 7c0000 [3] STD result


 
Is there any way to get the compiler to use the Hardware division instead of this Software version?

Thanks in advance.
标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,734 次查看
CrasyCat
Specialist III
Hello
 
  Did you look into the option -PEDIV?
 
According to the Help file (and reference manual):
 
"With this option enabled, the compiler generates an EDIV instructions instead of calling a division runtime routine for matching cases. When a 32-bit value is divided by a 16-bit value, only 16 bits of the result are used."
 
CrasyCat

在原帖中查看解决方案

0 项奖励
回复
3 回复数
1,735 次查看
CrasyCat
Specialist III
Hello
 
  Did you look into the option -PEDIV?
 
According to the Help file (and reference manual):
 
"With this option enabled, the compiler generates an EDIV instructions instead of calling a division runtime routine for matching cases. When a 32-bit value is divided by a 16-bit value, only 16 bits of the result are used."
 
CrasyCat
0 项奖励
回复
1,734 次查看
CompilerGuru
NXP Employee
NXP Employee
The EDIV instruction does only return the expected result if the 32/16 = 16 bit division does not overflow.
As for the computation
 
> result = multiplic / divisor;

the ANSI C standard does a 32/32 = 32 bit division with a subsequent truncation of the result to 16, the EDIV instruction does not return the result as mandated in ANSI for some (usually not useful, but well, the compiler can not know for sure) cases and therefore the compiler insists in that option to generate the EDIV opcode.

Daniel
1,734 次查看
oiser
Contributor I
Thanks a lot for the Hints,
 
the -PEDIV compiler options works fine.
 
Mario.
 
 
0 项奖励
回复