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

SCM Repository

[smlnj] Annotation of /sml/trunk/src/compiler/PervEnv/Basis/pack-word-l32.sml
ViewVC logotype

Annotation of /sml/trunk/src/compiler/PervEnv/Basis/pack-word-l32.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 114 - (view) (download)

1 : monnier 89 (* pack-word-l32.sml
2 :     *
3 :     * COPYRIGHT (c) 1995 AT&T Bell Laboratories.
4 :     *
5 :     * This is the non-native implementation of 32-bit big-endian packing
6 :     * operations.
7 :     *
8 :     *)
9 :    
10 :     structure Pack32Little : PACK_WORD =
11 :     struct
12 :     structure W = LargeWord
13 :     structure W8 = Word8
14 :     structure W8V = InlineT.Word8Vector
15 :     structure W8A = InlineT.Word8Array
16 :    
17 :     val bytesPerElem = 4
18 :     val isBigEndian = false
19 :    
20 :     (* convert the byte length into word32 length (n div 4), and check the index *)
21 :     fun chkIndex (len, i) = let
22 :     val len = Word.toIntX(Word.>>(Word.fromInt len, 0w2))
23 :     in
24 :     if (InlineT.DfltInt.ltu(i, len)) then () else raise Subscript
25 :     end
26 :    
27 :     fun mkWord (b1, b2, b3, b4) =
28 :     W.orb (W.<<(Word8.toLargeWord b4, 0w24),
29 :     W.orb (W.<<(Word8.toLargeWord b3, 0w16),
30 :     W.orb (W.<<(Word8.toLargeWord b2, 0w8),
31 :     Word8.toLargeWord b1)))
32 :    
33 :     fun subVec (vec, i) = let
34 :     val _ = chkIndex (W8V.length vec, i)
35 :     val k = Word.toIntX(Word.<<(Word.fromInt i, 0w2))
36 :     in
37 :     mkWord (W8V.sub(vec, k), W8V.sub(vec, k+1),
38 :     W8V.sub(vec, k+2), W8V.sub(vec, k+3))
39 :     end
40 :     (* since LargeWord is 32-bits, no sign extension is required *)
41 :     fun subVecX(vec, i) = subVec (vec, i)
42 :    
43 :     fun subArr (arr, i) = let
44 :     val _ = chkIndex (W8A.length arr, i)
45 :     val k = Word.toIntX(Word.<<(Word.fromInt i, 0w2))
46 :     in
47 :     mkWord (W8A.sub(arr, k), W8A.sub(arr, k+1),
48 :     W8A.sub(arr, k+2), W8A.sub(arr, k+3))
49 :     end
50 :     (* since LargeWord is 32-bits, no sign extension is required *)
51 :     fun subArrX(arr, i) = subArr (arr, i)
52 :    
53 :     fun update (arr, i, w) = let
54 :     val _ = chkIndex (W8A.length arr, i)
55 :     val k = Word.toIntX(Word.<<(Word.fromInt i, 0w2))
56 :     in
57 :     W8A.update (arr, k, W8.fromLargeWord w);
58 :     W8A.update (arr, k+1, W8.fromLargeWord(W.>>(w, 0w8)));
59 :     W8A.update (arr, k+2, W8.fromLargeWord(W.>>(w, 0w16)));
60 :     W8A.update (arr, k+3, W8.fromLargeWord(W.>>(w, 0w24)))
61 :     end
62 :    
63 :     end;
64 :    
65 :    
66 :     (*
67 : monnier 113 * $Log$
68 : monnier 89 *)

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