-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommon.cu
55 lines (44 loc) · 971 Bytes
/
common.cu
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
#include "common.cuh"
void usage(char *arg) {
fprintf(stderr,
"Usage : %s -f <function_name> -a <function_args> -s "
"<function_signature>\n",
arg);
fprintf(stderr,
"Example : %s -f withdraw -a \"(uint256,address)\" -s "
"0xab0202ba\n",
arg);
}
__host__ __device__ size_t _strlen(char s[]) {
size_t i;
i = 0;
while (s[i] != '\0') // loop over the array, if null is seen, break
++i;
return i; // return length (without null)
}
__device__ int _itoa(int value, char *sp, int radix) {
char tmp[16];
char *tp = tmp;
int i;
unsigned v;
int sign = (radix == 10 && value < 0);
if (sign)
v = -value;
else
v = (unsigned)value;
while (v || tp == tmp) {
i = v % radix;
v /= radix;
if (i < 10)
*tp++ = i + '0';
else
*tp++ = i + 'a' - 10;
}
int len = tp - tmp;
if (sign) {
*sp++ = '-';
len++;
}
while (tp > tmp) *sp++ = *--tp;
return len;
}