aboutsummaryrefslogtreecommitdiff
path: root/driver/gator_pack.c
blob: 119746befb09d2792e39c483101c03afa2b69540 (plain)
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
 * Copyright (C) ARM Limited 2010-2012. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 */

static void gator_buffer_write_packed_int(int cpu, int buftype, unsigned int x)
{
	uint32_t write = per_cpu(gator_buffer_write, cpu)[buftype];
	uint32_t mask = gator_buffer_mask[buftype];
	char *buffer = per_cpu(gator_buffer, cpu)[buftype];
	int write0 = (write + 0) & mask;
	int write1 = (write + 1) & mask;

	if ((x & 0xffffff80) == 0) {
		buffer[write0] = x & 0x7f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write1;
	} else if ((x & 0xffffc000) == 0) {
		int write2 = (write + 2) & mask;
		buffer[write0] = x | 0x80;
		buffer[write1] = (x >> 7) & 0x7f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write2;
	} else if ((x & 0xffe00000) == 0) {
		int write2 = (write + 2) & mask;
		int write3 = (write + 3) & mask;
		buffer[write0] = x | 0x80;
		buffer[write1] = (x >> 7) | 0x80;
		buffer[write2] = (x >> 14) & 0x7f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write3;
	} else if ((x & 0xf0000000) == 0) {
		int write2 = (write + 2) & mask;
		int write3 = (write + 3) & mask;
		int write4 = (write + 4) & mask;
		buffer[write0] = x | 0x80;
		buffer[write1] = (x >> 7) | 0x80;
		buffer[write2] = (x >> 14) | 0x80;
		buffer[write3] = (x >> 21) & 0x7f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write4;
	} else {
		int write2 = (write + 2) & mask;
		int write3 = (write + 3) & mask;
		int write4 = (write + 4) & mask;
		int write5 = (write + 5) & mask;
		buffer[write0] = x | 0x80;
		buffer[write1] = (x >> 7) | 0x80;
		buffer[write2] = (x >> 14) | 0x80;
		buffer[write3] = (x >> 21) | 0x80;
		buffer[write4] = (x >> 28) & 0x0f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write5;
	}
}

static void gator_buffer_write_packed_int64(int cpu, int buftype, unsigned long long x)
{
	uint32_t write = per_cpu(gator_buffer_write, cpu)[buftype];
	uint32_t mask = gator_buffer_mask[buftype];
	char *buffer = per_cpu(gator_buffer, cpu)[buftype];
	int write0 = (write + 0) & mask;
	int write1 = (write + 1) & mask;

	if ((x & 0xffffffffffffff80LL) == 0) {
		buffer[write0] = x & 0x7f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write1;
	} else if ((x & 0xffffffffffffc000LL) == 0) {
		int write2 = (write + 2) & mask;
		buffer[write0] = x | 0x80;
		buffer[write1] = (x >> 7) & 0x7f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write2;
	} else if ((x & 0xffffffffffe00000LL) == 0) {
		int write2 = (write + 2) & mask;
		int write3 = (write + 3) & mask;
		buffer[write0] = x | 0x80;
		buffer[write1] = (x >> 7) | 0x80;
		buffer[write2] = (x >> 14) & 0x7f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write3;
	} else if ((x & 0xfffffffff0000000LL) == 0) {
		int write2 = (write + 2) & mask;
		int write3 = (write + 3) & mask;
		int write4 = (write + 4) & mask;
		buffer[write0] = x | 0x80;
		buffer[write1] = (x >> 7) | 0x80;
		buffer[write2] = (x >> 14) | 0x80;
		buffer[write3] = (x >> 21) & 0x7f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write4;
	} else if ((x & 0xfffffff800000000LL) == 0) {
		int write2 = (write + 2) & mask;
		int write3 = (write + 3) & mask;
		int write4 = (write + 4) & mask;
		int write5 = (write + 5) & mask;
		buffer[write0] = x | 0x80;
		buffer[write1] = (x >> 7) | 0x80;
		buffer[write2] = (x >> 14) | 0x80;
		buffer[write3] = (x >> 21) | 0x80;
		buffer[write4] = (x >> 28) & 0x7f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write5;
	} else if ((x & 0xfffffc0000000000LL) == 0) {
		int write2 = (write + 2) & mask;
		int write3 = (write + 3) & mask;
		int write4 = (write + 4) & mask;
		int write5 = (write + 5) & mask;
		int write6 = (write + 6) & mask;
		buffer[write0] = x | 0x80;
		buffer[write1] = (x >> 7) | 0x80;
		buffer[write2] = (x >> 14) | 0x80;
		buffer[write3] = (x >> 21) | 0x80;
		buffer[write4] = (x >> 28) | 0x80;
		buffer[write5] = (x >> 35) & 0x7f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write6;
	} else if ((x & 0xfffe000000000000LL) == 0) {
		int write2 = (write + 2) & mask;
		int write3 = (write + 3) & mask;
		int write4 = (write + 4) & mask;
		int write5 = (write + 5) & mask;
		int write6 = (write + 6) & mask;
		int write7 = (write + 7) & mask;
		buffer[write0] = x | 0x80;
		buffer[write1] = (x >> 7) | 0x80;
		buffer[write2] = (x >> 14) | 0x80;
		buffer[write3] = (x >> 21) | 0x80;
		buffer[write4] = (x >> 28) | 0x80;
		buffer[write5] = (x >> 35) | 0x80;
		buffer[write6] = (x >> 42) & 0x7f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write7;
	} else if ((x & 0xff00000000000000LL) == 0) {
		int write2 = (write + 2) & mask;
		int write3 = (write + 3) & mask;
		int write4 = (write + 4) & mask;
		int write5 = (write + 5) & mask;
		int write6 = (write + 6) & mask;
		int write7 = (write + 7) & mask;
		int write8 = (write + 8) & mask;
		buffer[write0] = x | 0x80;
		buffer[write1] = (x >> 7) | 0x80;
		buffer[write2] = (x >> 14) | 0x80;
		buffer[write3] = (x >> 21) | 0x80;
		buffer[write4] = (x >> 28) | 0x80;
		buffer[write5] = (x >> 35) | 0x80;
		buffer[write6] = (x >> 42) | 0x80;
		buffer[write7] = (x >> 49) & 0x7f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write8;
	} else if ((x & 0x8000000000000000LL) == 0) {
		int write2 = (write + 2) & mask;
		int write3 = (write + 3) & mask;
		int write4 = (write + 4) & mask;
		int write5 = (write + 5) & mask;
		int write6 = (write + 6) & mask;
		int write7 = (write + 7) & mask;
		int write8 = (write + 8) & mask;
		int write9 = (write + 9) & mask;
		buffer[write0] = x | 0x80;
		buffer[write1] = (x >> 7) | 0x80;
		buffer[write2] = (x >> 14) | 0x80;
		buffer[write3] = (x >> 21) | 0x80;
		buffer[write4] = (x >> 28) | 0x80;
		buffer[write5] = (x >> 35) | 0x80;
		buffer[write6] = (x >> 42) | 0x80;
		buffer[write7] = (x >> 49) | 0x80;
		buffer[write8] = (x >> 56) & 0x7f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write9;
	} else {
		int write2 = (write + 2) & mask;
		int write3 = (write + 3) & mask;
		int write4 = (write + 4) & mask;
		int write5 = (write + 5) & mask;
		int write6 = (write + 6) & mask;
		int write7 = (write + 7) & mask;
		int write8 = (write + 8) & mask;
		int write9 = (write + 9) & mask;
		int write10 = (write + 10) & mask;
		buffer[write0] = x | 0x80;
		buffer[write1] = (x >> 7) | 0x80;
		buffer[write2] = (x >> 14) | 0x80;
		buffer[write3] = (x >> 21) | 0x80;
		buffer[write4] = (x >> 28) | 0x80;
		buffer[write5] = (x >> 35) | 0x80;
		buffer[write6] = (x >> 42) | 0x80;
		buffer[write7] = (x >> 49) | 0x80;
		buffer[write8] = (x >> 56) | 0x80;
		buffer[write9] = (x >> 63) & 0x7f;
		per_cpu(gator_buffer_write, cpu)[buftype] = write10;
	}
}