OpenCores
URL https://opencores.org/ocsvn/s6soc/s6soc/trunk

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [bench/] [cpp/] [byteswap.cpp] - Blame information for rev 49

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 49 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    byteswap.cpp
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
6
//
7
// Purpose:     
8
//
9
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Technology, LLC
11
//
12
////////////////////////////////////////////////////////////////////////////////
13
//
14
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
15
//
16
// This program is free software (firmware): you can redistribute it and/or
17
// modify it under the terms of  the GNU General Public License as published
18
// by the Free Software Foundation, either version 3 of the License, or (at
19
// your option) any later version.
20
//
21
// This program is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License along
27
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
28
// target there if the PDF file isn't present.)  If not, see
29
// <http://www.gnu.org/licenses/> for a copy.
30
//
31
// License:     GPL, v3, as defined and found on www.gnu.org,
32
//              http://www.gnu.org/licenses/gpl.html
33
//
34
//
35
////////////////////////////////////////////////////////////////////////////////
36
//
37
//
38
#include <stdint.h>
39
#include "byteswap.h"
40
 
41
uint32_t
42
byteswap(uint32_t v) {
43
        uint32_t        r = 0;
44
 
45
        r = (v & 0x0ff);
46
        r <<= 8; v >>= 8;
47
        r |= (v & 0x0ff);
48
        r <<= 8; v >>= 8;
49
        r |= (v & 0x0ff);
50
        r <<= 8; v >>= 8;
51
        r |= (v & 0x0ff);
52
 
53
        return r;
54
}
55
 
56
uint32_t
57
buildword(const unsigned char *p) {
58
        uint32_t        r = 0;
59
 
60
        r  = (*p++); r <<= 8;
61
        r |= (*p++); r <<= 8;
62
        r |= (*p++); r <<= 8;
63
        r |= (*p  );
64
 
65
        return r;
66
}
67
 
68
uint32_t
69
buildswap(const unsigned char *p) {
70
        uint32_t        r = 0;
71
 
72
        r  = p[3]; r <<= 8;
73
        r |= p[2]; r <<= 8;
74
        r |= p[1]; r <<= 8;
75
        r |= p[0];
76
 
77
        return r;
78
}
79
 
80
void
81
byteswapbuf(int ln, uint32_t *buf) {
82
        for(int i=0; i<ln; i++)
83
                buf[i] = byteswap(buf[i]);
84
}
85
 
86
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.