Created
October 17, 2015 00:29
-
-
Save yannk/b275658025481d25a17d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#line 18 "/home/yann/src/github.com/svent/sift/matching_cgo.go" | |
#include <stddef.h> | |
inline int count_newlines(const unsigned char *buf, size_t n) { | |
int count = 0; | |
int base; | |
int dist = n / 4; | |
for (int i = 0; i < dist; i++) { | |
base = i * 4; | |
if (buf[base] == 0x0a) { | |
count++; | |
} | |
if (buf[base+1] == 0x0a) { | |
count++; | |
} | |
if (buf[base+2] == 0x0a) { | |
count++; | |
} | |
if (buf[base+3] == 0x0a) { | |
count++; | |
} | |
} | |
for (int i = (n / 4) * 4; i < n; i++) { | |
if (buf[i] == 0x0a) { | |
count += 1; | |
} | |
} | |
return count; | |
} | |
inline void bytes_to_lower(const unsigned char *buf, unsigned char *out, size_t n) { | |
int base; | |
int dist = n / 4; | |
for (int i = 0; i < dist; i++) { | |
base = i * 4; | |
out[base] = (buf[base] - 65U < 26) ? buf[base] + 32 : buf[base]; | |
out[base+1] = (buf[base+1] - 65U < 26) ? buf[base+1] + 32 : buf[base+1]; | |
out[base+2] = (buf[base+2] - 65U < 26) ? buf[base+2] + 32 : buf[base+2]; | |
out[base+3] = (buf[base+3] - 65U < 26) ? buf[base+3] + 32 : buf[base+3]; | |
} | |
for (int i = (n / 4) * 4; i < n; i++) { | |
out[i] = (buf[i] - 65U < 26) ? buf[i] + 32 : buf[i]; | |
} | |
} | |
// Usual nonsense: if x and y are not equal, the type will be invalid | |
// (have a negative array count) and an inscrutable error will come | |
// out of the compiler and hopefully mention "name". | |
#define __cgo_compile_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1]; | |
// Check at compile time that the sizes we use match our expectations. | |
#define __cgo_size_assert(t, n) __cgo_compile_assert_eq(sizeof(t), n, _cgo_sizeof_##t##_is_not_##n) | |
__cgo_size_assert(char, 1) | |
__cgo_size_assert(short, 2) | |
__cgo_size_assert(int, 4) | |
typedef long long __cgo_long_long; | |
__cgo_size_assert(__cgo_long_long, 8) | |
__cgo_size_assert(float, 4) | |
__cgo_size_assert(double, 8) | |
extern char* _cgo_topofstack(void); | |
#include <errno.h> | |
#include <string.h> | |
void | |
_cgo_16b4a92ce965_Cfunc_bytes_to_lower(void *v) | |
{ | |
struct { | |
unsigned char* p0; | |
unsigned char* p1; | |
size_t p2; | |
} __attribute__((__packed__)) *a = v; | |
bytes_to_lower((void*)a->p0, (void*)a->p1, a->p2); | |
} | |
void | |
_cgo_16b4a92ce965_Cfunc_count_newlines(void *v) | |
{ | |
struct { | |
unsigned char* p0; | |
size_t p1; | |
int r; | |
char __pad20[4]; | |
} __attribute__((__packed__)) *a = v; | |
char *stktop = _cgo_topofstack(); | |
__typeof__(a->r) r = count_newlines((void*)a->p0, a->p1); | |
a = (void*)((char*)a + (_cgo_topofstack() - stktop)); | |
a->r = r; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment