[M3devel] Target.First_readable_addr

Jay K jay.krell at cornell.edu
Wed Aug 26 02:28:48 CEST 2015


Of course, my agenda is to remove target-specificity.


Target.First_readable_addr is a target-specific optimizationto omit null checks. Or maybe range checks..

The assumption is that dereferencing "actual" null is checkedby the hardware, so code doesn't have to be generated to check for null.

I'm not even sure I like this -- as the behavior of dereferencing null is not portable. 

The assumption is further that accesses to the first page, at least,are subject to the same hardware checks, and can also be optimized away.

At first, glance, I thought this was based on offset + size of a static access.

For example:
a: ARRAY [0...large] OF CHAR

a[0..4095]   no checka[4096 and up] would check

Target.First_deadable_addr is 4k on many targets; 8k on others.Setting it too low would yield extra checks.Setting it too high would yield missing checks and a loss of safety.

Here is what I actually found though.

 - The check is based on the size of the type being accessed.
 - It is off by a factor of 8 -- there is confusing between m3middle and m3front  as to if it is bit number of a byte number.

small: ARRAY[0..100] OF CHARlarge:ARRAY[0..100000] OF CHAR
no access to small gets checked and every access to larger gets checked.
Should we do anything about this?
In m3-sys/m3tests/src/p2/p263:cm3 -realcleancm3 -keepgrep fault <target>/*ms

All the accesses are to offset 0.So, by some expectation, no null checks are needed.Null checks are output when the size of thecontaining type is, for x86, larger than 4096*8.

The checks have been largely but not completely wrong/missing.Safety behooves us to check though.
 - fix the factor of 8? - make it 0?? too slow? - make it 4k on all target? until such time as a target manifests with a smaller page size? - base the checks on access offset + size, not containing size?   Containing size is conservative. It checks more than i think is meant.

I couldn't actually figure out the code here, I added various:
    IF RTParams.IsPresent("qual") THEN      RTIO.PutText("NilChkExpr.Compile p.offset:" & Fmt.Int(p.offset) & "\n");      RTIO.Flush();    END;
and such to m3front to figure it out.

Thanks,- Jay
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20150826/a0f5ebed/attachment-0001.html>


More information about the M3devel mailing list