Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/system/Basis/Implementation/pack-word-l32.sml
ViewVC logotype

Diff of /sml/trunk/system/Basis/Implementation/pack-word-l32.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 5447, Sun Jun 16 17:51:39 2019 UTC revision 5448, Sun Jun 16 17:52:28 2019 UTC
# Line 30  Line 30 
30              if (InlineT.Int.ltu(i, len)) then () else raise Subscript              if (InlineT.Int.ltu(i, len)) then () else raise Subscript
31            end            end
32    
33      (* scale word32 index to byte index *)
34        fun scale i = Word.toIntX(Word.<<(Word.fromInt i, 0w2))
35    
36      (* make a word32 from little-endian-order bytes [b1, b2, b3, b4] *)
37      fun mkWord (b1, b2, b3, b4) =      fun mkWord (b1, b2, b3, b4) =
38            W.orb (W.<<(Word8.toLargeWord b4, 0w24),            W.orb (W.<<(Word8.toLargeWord b4, 0w24),
39            W.orb (W.<<(Word8.toLargeWord b3, 0w16),            W.orb (W.<<(Word8.toLargeWord b3, 0w16),
40            W.orb (W.<<(Word8.toLargeWord b2,  0w8),            W.orb (W.<<(Word8.toLargeWord b2,  0w8),
41                        Word8.toLargeWord b1)))                        Word8.toLargeWord b1)))
42    
43        fun signExt w = W.-(W.xorb(0wx80000000, w), 0wx80000000)
44    
45      fun subVec (vec, i) = let      fun subVec (vec, i) = let
46            val _ = chkIndex (W8V.length vec, i)            val _ = chkIndex (W8V.length vec, i)
47            val k = Word.toIntX(Word.<<(Word.fromInt i, 0w2))            val k = scale i
48            in            in
49              mkWord (W8V.sub(vec, k), W8V.sub(vec, k+1),              mkWord (W8V.sub(vec, k), W8V.sub(vec, k+1),
50                W8V.sub(vec, k+2), W8V.sub(vec, k+3))                W8V.sub(vec, k+2), W8V.sub(vec, k+3))
51            end            end
52    (* since LargeWord is 32-bits, no sign extension is required *)      fun subVecX (vec, i) = signExt (subVec (vec, i))
     fun subVecX(vec, i) = subVec (vec, i)  
53    
54      fun subArr (arr, i) = let      fun subArr (arr, i) = let
55            val _ = chkIndex (W8A.length arr, i)            val _ = chkIndex (W8A.length arr, i)
56            val k = Word.toIntX(Word.<<(Word.fromInt i, 0w2))            val k = scale i
57            in            in
58              mkWord (W8A.sub(arr, k), W8A.sub(arr, k+1),              mkWord (W8A.sub(arr, k), W8A.sub(arr, k+1),
59                W8A.sub(arr, k+2), W8A.sub(arr, k+3))                W8A.sub(arr, k+2), W8A.sub(arr, k+3))
60            end            end
61    (* since LargeWord is 32-bits, no sign extension is required *)      fun subArrX (arr, i) = signExt (subArr (arr, i))
     fun subArrX(arr, i) = subArr (arr, i)  
62    
63      fun update (arr, i, w) = let      fun update (arr, i, w) = let
64            val _ = chkIndex (W8A.length arr, i)            val _ = chkIndex (W8A.length arr, i)
65            val k = Word.toIntX(Word.<<(Word.fromInt i, 0w2))            val k = scale i
66            in            in
67              W8A.update (arr, k,   W8.fromLargeWord w);              W8A.update (arr, k,   W8.fromLargeWord w);
68              W8A.update (arr, k+1, W8.fromLargeWord(W.>>(w,  0w8)));              W8A.update (arr, k+1, W8.fromLargeWord(W.>>(w,  0w8)));
# Line 67  Line 71 
71            end            end
72    
73    end    end
74  end  end (* local *)
   

Legend:
Removed from v.5447  
changed lines
  Added in v.5448

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0