[M3devel] suggested Target.Int change

Jay K jay.krell at cornell.edu
Tue Dec 18 20:12:53 CET 2012


Here is the suggested change. Ok?

Index: m3middle/src/TInt.i3
===================================================================
RCS file: /usr/cvs/cm3/m3-sys/m3middle/src/TInt.i3,v
retrieving revision 1.34
diff -u -r1.34 TInt.i3
--- m3middle/src/TInt.i3    15 Dec 2010 16:10:46 -0000    1.34
+++ m3middle/src/TInt.i3    18 Dec 2012 18:43:44 -0000
@@ -33,8 +33,8 @@
   Max16  = Int{16_FF, 16_7f, 16_00,..};
   Min32  = Int{16_00, 16_00, 16_00, 16_80, 16_FF,..};
   Max32  = Int{16_FF, 16_FF, 16_FF, 16_7f, 16_00,..};
-  Min64  = Int{16_00, 16_00, 16_00, 16_00, 16_00, 16_00, 16_00, 16_80};
-  Max64  = Int{16_FF, 16_FF, 16_FF, 16_FF, 16_FF, 16_FF, 16_FF, 16_7f};
+  Min64  = Int{16_00, 16_00, 16_00, 16_00, 16_00, 16_00, 16_00, 16_80, 16_FF};
+  Max64  = Int{16_FF, 16_FF, 16_FF, 16_FF, 16_FF, 16_FF, 16_FF, 16_7f, 0};
 
 PROCEDURE FromInt (x: INTEGER;  VAR i: Int): BOOLEAN;
 (* converts a host integer 'x' to a target integer 'i' *)
Index: m3middle/src/TWord.i3
===================================================================
RCS file: /usr/cvs/cm3/m3-sys/m3middle/src/TWord.i3,v
retrieving revision 1.11
diff -u -r1.11 TWord.i3
--- m3middle/src/TWord.i3    27 Feb 2010 00:43:06 -0000    1.11
+++ m3middle/src/TWord.i3    18 Dec 2012 18:43:44 -0000
@@ -26,7 +26,7 @@
   Max8  = Int{16_FF, 0, ..};
   Max16 = Int{16_FF, 16_FF, 0, ..};
   Max32 = Int{16_FF, 16_FF, 16_FF, 16_FF, 0, ..};
-  Max64 = Int{16_FF, 16_FF, 16_FF, 16_FF, 16_FF, 16_FF, 16_FF, 16_FF};
+  Max64 = Int{16_FF, 16_FF, 16_FF, 16_FF, 16_FF, 16_FF, 16_FF, 16_FF, 0};
 
 PROCEDURE New (READONLY chars: ARRAY OF CHAR;  base: [2..16];
                VAR i: Int): BOOLEAN;
Index: m3middle/src/Target.i3
===================================================================
RCS file: /usr/cvs/cm3/m3-sys/m3middle/src/Target.i3,v
retrieving revision 1.70
diff -u -r1.70 Target.i3
--- m3middle/src/Target.i3    4 Sep 2012 15:11:09 -0000    1.70
+++ m3middle/src/Target.i3    18 Dec 2012 18:43:44 -0000
@@ -224,7 +226,7 @@
    element of the array. *)
 
 TYPE
-  Int = (* OPAQUE *) ARRAY [0..7] OF IByte;
+  Int = (* OPAQUE *) ARRAY [0..8] OF IByte;
   IByte = BITS 8 FOR [0..16_ff];
 
 TYPE


As a follow up, TWord could change so that many but not all of its procedure are just constants assigned from TInt.
i.e.
INTERFACE TWord;

CONST LT = TInt.LT;

 - Jay


From: jay.krell at cornell.edu
To: m3devel at elegosoft.com
Subject: suggested Target.Int change
Date: Thu, 13 Dec 2012 08:32:27 +0000





[added subject]





I strongly suggest that Target.Int be extended from 8 bytes to 9.

The reason is thus:


I was trying to mix TWord and TInt in M3C.m3.
It become tedious and error prone.


If Target.Int were extended to 9 bytes internally,
then it would have a range exceeding a signed 64bit integer
and a full range unsigned 64bit integer, and the need
for TWord would, I believe, go away.


The result would be *slightly* *slightly* *slightly*
less efficient, but more convenient.

I have already applied this change locally and built with it.
It was very simple.
I did have to visit the initializations of this mostly-opaque type, i.e. in Target.m3 and TInt.i3.


Furthermore, I weakly suggest that Target.Int
internally be changed to separately store the sign
and the magnitude. This would be a hidden implementation detail
and I believe it would simplify the implementation.
It would *slightly* deoptimize the representation size,
but the code, I think, would be smaller and simpler.
This would not affect the public interface.


I came to this suggestion when someone recently asked me how
to implement this sort of thing. I realize it is slightly easier
to store the sign and magnitude separately.



 - Jay
 		 	   		   		 	   		   		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20121218/c5946101/attachment-0002.html>


More information about the M3devel mailing list