[M3devel] cardinal vs. word, divide?

Jay K jay.krell at cornell.edu
Tue Nov 23 08:57:56 CET 2010


So, here are two maybe interesting cases.
At least to jog my brain and help make sense of the system.


DIV vs. Word.Divide of CARDINAL.
u is for unsigned, or word
C is for Cardinal.
 Cardinal is [0..LAST(INTEGER)].


<*NOWARN*>PROCEDURE uDivide_param_C_C(a:CARDINAL;b:CARDINAL):Word.T=BEGIN RETURN Word.Divide(a,b);END uDivide_param_C_C;

<*NOWARN*>PROCEDURE Divide_param_C_C(a:CARDINAL;b:CARDINAL):CARDINAL=BEGIN RETURN a DIV b;END Divide_param_C_C;


(5579) begin_procedure procedure:0x178:Divide__Divide_param_C_C Divide__Divide_param_C_C
(5580) load var:0x2E5:a offset:0 src_t:word_64 dst_t:int_64
(5581) load var:0x2E6:b offset:0 src_t:word_64 dst_t:int_64
(5582) div type:int_64
(5583) check_lo type:int_64 0 code:1
(5584) exit_proc type:word_64
(5585) end_procedure procedure:0x178:Divide__Divide_param_C_C


(5571) begin_procedure procedure:0x177:Divide__uDivide_param_C_C Divide__uDivide_param_C_C
(5572) load var:0x2E2:a offset:0 src_t:word_64 dst_t:int_64
(5573) load var:0x2E3:b offset:0 src_t:word_64 dst_t:int_64
(5574) div type:word_64
(5575) exit_proc type:int_64
(5576) end_procedure procedure:0x177:Divide__uDivide_param_C_C


Thoughts?


Is it right for the load to convert from word to int?
 (I'll see about removing the address_token for unsigned/signed-only conversions, if it is there.)
 
 
I can see how makes sense.
CARDINAL is just a subrange of INTEGER. So it is INTEGER.


If/when we are clever, we can represent the subranges in the types
in the backend, and the optimizer should notice, and these
would generate identical code, if they don't already.


But the return types of the divides vary as well.
There do exist unsigned types at this level.


Does that imply that
a,b:CARDINAL

Word.Or(a, 0) DIV Word.Or(b, 0)
is different than
a DIV b?


I guess so. Different code at least.
Given that cardinal is "half range", the results should always match.
That is, really, other than added/missing range checks, CARDINAL
will always act the same as INTEGER.
So then the unsigned types..don't mean anything?


 - Jay




 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20101123/4eace167/attachment-0001.html>


More information about the M3devel mailing list