get CW for HCS12X to use Hardware division

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

get CW for HCS12X to use Hardware division

ソリューションへジャンプ
1,893件の閲覧回数
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 解決策
606件の閲覧回数
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 返答(返信)
607件の閲覧回数
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 件の賞賛
606件の閲覧回数
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
606件の閲覧回数
oiser
Contributor I
Thanks a lot for the Hints,
 
the -PEDIV compiler options works fine.
 
Mario.
 
 
0 件の賞賛