blob: 2c082f283adc18037964cb70c40ae03d5f0d7b3c [file] [log] [blame]
Jon Medhurstaaf37a32013-06-11 12:10:56 +01001/**
2 * Copyright (C) ARM Limited 2010-2013. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 */
9
10static void gator_buffer_write_packed_int(int cpu, int buftype, int x)
11{
12 uint32_t write = per_cpu(gator_buffer_write, cpu)[buftype];
13 uint32_t mask = gator_buffer_mask[buftype];
14 char *buffer = per_cpu(gator_buffer, cpu)[buftype];
15 int packedBytes = 0;
16 int more = true;
17 while (more) {
18 // low order 7 bits of x
19 char b = x & 0x7f;
20 x >>= 7;
21
22 if ((x == 0 && (b & 0x40) == 0) || (x == -1 && (b & 0x40) != 0)) {
23 more = false;
24 } else {
25 b |= 0x80;
26 }
27
28 buffer[(write + packedBytes) & mask] = b;
29 packedBytes++;
30 }
31
32 per_cpu(gator_buffer_write, cpu)[buftype] = (write + packedBytes) & mask;
33}
34
35static void gator_buffer_write_packed_int64(int cpu, int buftype, long long x)
36{
37 uint32_t write = per_cpu(gator_buffer_write, cpu)[buftype];
38 uint32_t mask = gator_buffer_mask[buftype];
39 char *buffer = per_cpu(gator_buffer, cpu)[buftype];
40 int packedBytes = 0;
41 int more = true;
42 while (more) {
43 // low order 7 bits of x
44 char b = x & 0x7f;
45 x >>= 7;
46
47 if ((x == 0 && (b & 0x40) == 0) || (x == -1 && (b & 0x40) != 0)) {
48 more = false;
49 } else {
50 b |= 0x80;
51 }
52
53 buffer[(write + packedBytes) & mask] = b;
54 packedBytes++;
55 }
56
57 per_cpu(gator_buffer_write, cpu)[buftype] = (write + packedBytes) & mask;
58}