forked from trou/debit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfgbit.h
123 lines (102 loc) · 3.62 KB
/
cfgbit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Copyright (C) 2006, 2007 Jean-Baptiste Note <jean-baptiste.note@m4x.org>
*
* This file is part of debit.
*
* Debit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Debit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with debit. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _HAS_CFGBIT_H
#define _HAS_CFGBIT_H
/****
* Cfgbit configuration:
* - lower 8 bits are the position of the *bit* on the Y axis. Thus, to
* get byte positionning, one should ask for the (bitposition >> 3)
* - next 8 bits are the position of the bit on the X axis, identical
* to the position of the byte on the X axis.
*/
#define CFGBIT_Y_LENGTH 8
#define CFGBIT_Y_MASK ((1 << CFGBIT_Y_LENGTH) - 1)
#define CFGBIT_BYTE_OFFSET_LENGTH 3
#define CFGBIT_BYTE_OFFSET_MASK ((1 << CFGBIT_BYTE_OFFSET_LENGTH) - 1)
#define CFGBIT_Y_BYTE_LEN (CFGBIT_Y_LENGTH - CFGBIT_BYTE_OFFSET_LENGTH)
#define CFGBIT_Y_BYTE_MASK ((1 << CFGBIT_Y_BYTE_LEN) - 1)
static inline
unsigned byte_y(const unsigned cfgbit) {
return (cfgbit >> CFGBIT_BYTE_OFFSET_LENGTH) & CFGBIT_Y_BYTE_MASK;
}
static inline
unsigned bit_y(const unsigned cfgbit) {
return (cfgbit & CFGBIT_Y_MASK);
}
static inline
unsigned bit_offset(const unsigned cfgbit) {
return (cfgbit & CFGBIT_BYTE_OFFSET_MASK);
}
static inline
unsigned bit_x(const unsigned cfgbit) {
return (cfgbit >> CFGBIT_Y_LENGTH);
}
static inline
unsigned byte_x(const unsigned cfgbit) {
return (cfgbit >> CFGBIT_Y_LENGTH);
}
static inline
unsigned byte_addr(const unsigned cfgbit) {
return (cfgbit | CFGBIT_BYTE_OFFSET_MASK);
}
static inline
unsigned assemble_cfgbit(const unsigned x,
const unsigned y) {
return (y | (x << CFGBIT_Y_LENGTH));
}
/* Temporary conversion function for the database. To get rid of once
the database is moved to the new format */
#if defined(VIRTEX5)
#define BITPOS_INVERT(val, width) ((val) << 3)
static inline
unsigned bitpos_invert(const unsigned bitpos, const unsigned width) {
(void) width;
return bitpos << 3;
}
#else /* This is still in use for virtex4 and virtex2 */
#define BITPOS_INVERT(val, width) (((width - 1) - (val)) << 3)
static inline
unsigned bitpos_invert(const unsigned bitpos, const unsigned width) {
return ((width - 1) - bitpos) << 3;
}
#endif
static inline
unsigned bitpos_to_cfgbit(const unsigned bitpos, const unsigned width) {
const unsigned xoff = bitpos / (8*width);
const unsigned yoff = bitpos % (8*width);
const unsigned nyoff = bitpos_invert(yoff>>3, width) | (yoff & 7);
return assemble_cfgbit(xoff,nyoff);
}
/* Unrolled macro version of the above */
#define XOFF(val, width) ((val) / (8*width))
#define YOFF(val, width) ((val) % (8*width))
#define NYOFF(val, width) (BITPOS_INVERT(YOFF(val, width) >> 3, width) | (YOFF(val, width) & 7))
#define CFG_ASSEMBLE(x, y) ((y) | (x) << CFGBIT_Y_LENGTH)
#define CFGBIT(bitpos, width) CFG_ASSEMBLE(XOFF(bitpos, width), NYOFF(bitpos, width))
typedef struct _type_bits {
/** Column type */
guint col_type;
/** Frames to skip at the beginning of the type array */
guint x_type_off;
/** Bytes to skip at the beginning of the type array */
gint y_offset;
guint y_width;
} type_bits_t;
extern const type_bits_t type_bits[NR_SITE_TYPE];
#endif /* _HAS_CFGBIT_H */