get CW for HCS12X to use Hardware division

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

get CW for HCS12X to use Hardware division

Jump to solution
1,852 Views
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.
Labels (1)
Tags (1)
0 Kudos
1 Solution
565 Views
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

View solution in original post

0 Kudos
3 Replies
566 Views
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 Kudos
565 Views
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
565 Views
oiser
Contributor I
Thanks a lot for the Hints,
 
the -PEDIV compiler options works fine.
 
Mario.
 
 
0 Kudos