uwx_swap.c revision 160157
1127668Sbms/*
2127668SbmsCopyright (c) 2003-2006 Hewlett-Packard Development Company, L.P.
3127668SbmsPermission is hereby granted, free of charge, to any person
4127668Sbmsobtaining a copy of this software and associated documentation
5127668Sbmsfiles (the "Software"), to deal in the Software without
6127668Sbmsrestriction, including without limitation the rights to use,
7127668Sbmscopy, modify, merge, publish, distribute, sublicense, and/or sell
8127668Sbmscopies of the Software, and to permit persons to whom the
9127668SbmsSoftware is furnished to do so, subject to the following
10127668Sbmsconditions:
11127668Sbms
12127668SbmsThe above copyright notice and this permission notice shall be
13127668Sbmsincluded in all copies or substantial portions of the Software.
14127668Sbms
15127668SbmsTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16127668SbmsEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17127668SbmsOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18127668SbmsNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19127668SbmsHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20127668SbmsWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21127668SbmsFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22127668SbmsOTHER DEALINGS IN THE SOFTWARE.
23127668Sbms*/
24127668Sbms
25127668Sbms#include "uwx_env.h"
26127668Sbms#include "uwx_swap.h"
27127668Sbms
28127668Sbmsvoid uwx_swap4(uint32_t *w)
29127668Sbms{
30127668Sbms    unsigned char *p;
31127668Sbms    unsigned char t[4];
32127668Sbms
33127668Sbms    p = (unsigned char *) w;
34127668Sbms
35127668Sbms    t[0] = p[0];
36127668Sbms    t[1] = p[1];
37127668Sbms    t[2] = p[2];
38127668Sbms    t[3] = p[3];
39127668Sbms
40127668Sbms    p[0] = t[3];
41127668Sbms    p[1] = t[2];
42127668Sbms    p[2] = t[1];
43127668Sbms    p[3] = t[0];
44127668Sbms}
45147899Ssam
46147899Ssamvoid uwx_swap8(uint64_t *dw)
47127668Sbms{
48127668Sbms    unsigned char *p;
49147899Ssam    unsigned char t[8];
50127668Sbms
51127668Sbms    p = (unsigned char *) dw;
52127668Sbms
53127668Sbms    t[0] = p[0];
54127668Sbms    t[1] = p[1];
55127668Sbms    t[2] = p[2];
56127668Sbms    t[3] = p[3];
57127668Sbms    t[4] = p[4];
58147899Ssam    t[5] = p[5];
59    t[6] = p[6];
60    t[7] = p[7];
61
62    p[0] = t[7];
63    p[1] = t[6];
64    p[2] = t[5];
65    p[3] = t[4];
66    p[4] = t[3];
67    p[5] = t[2];
68    p[6] = t[1];
69    p[7] = t[0];
70}
71