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/runtime/kernel/swap-bytes.c
ViewVC logotype

Annotation of /sml/trunk/src/runtime/kernel/swap-bytes.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 651 - (view) (download) (as text)

1 : monnier 249 /* swap-bytes.c
2 :     *
3 :     * COPYRIGHT (c) 1993 by AT&T Bell Laboratories.
4 :     *
5 :     */
6 :    
7 :     #include "ml-base.h"
8 :    
9 :     #ifdef BYTE_ORDER_LITTLE
10 :    
11 :     #if (WORD_SZB == 8) /* 64-bit ML words */
12 :     /* SwapBytesOfWord:
13 :     */
14 :     Word_t SwapBytes (Word_t x)
15 :     {
16 :     unsigned int b0 = x & 0x00000000000000FF;
17 :     unsigned int b1 = x & 0x000000000000FF00;
18 :     unsigned int b2 = x & 0x0000000000FF0000;
19 :     unsigned int b3 = x & 0x00000000FF000000;
20 :     unsigned int b4 = x & 0x000000FF00000000;
21 :     unsigned int b5 = x & 0x0000FF0000000000;
22 :     unsigned int b6 = x & 0x00FF000000000000;
23 :     unsigned int b7 = x & 0xFF00000000000000;
24 :    
25 :     return ((b0 << 56) | (b1 << 40) | (b2 << 24) | (b3 << 8)
26 :     | (b4 >> 8) | (b5 >> 24) | (b6 >> 40) | (b7 >> 56));
27 :    
28 :     } /* end of SwapBytesOfWord */
29 :     #endif
30 :    
31 :     /* SwapBytes:
32 :     */
33 :     Unsigned32_t SwapBytes (Unsigned32_t x)
34 :     {
35 :     unsigned int b0 = x & 0x000000FF;
36 :     unsigned int b1 = x & 0x0000FF00;
37 :     unsigned int b2 = x & 0x00FF0000;
38 :     unsigned int b3 = x & 0xFF000000;
39 :    
40 :     return ((b0 << 24) | (b1 << 8) | (b2 >> 8) | (b3 >> 24));
41 :    
42 :     } /* end of SwapBytes */
43 :    
44 :     #endif

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