2011-06-16 10:32:52 -07:00
|
|
|
// Use `clang++ -emit-llvm -S -arch i386 -O3 -I../isaac -I../uthash
|
2011-07-08 21:55:43 -07:00
|
|
|
// -I../arch/i386 -fno-stack-protector -o intrinsics.ll intrinsics.cpp`
|
2011-05-05 12:45:34 -07:00
|
|
|
|
2011-05-03 18:49:29 -07:00
|
|
|
#include "../rust_internal.h"
|
2011-07-09 20:14:20 -07:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
extern "C" CDECL void
|
|
|
|
upcall_fail(rust_task *task, char const *expr, char const *file, size_t line);
|
2011-05-03 18:49:29 -07:00
|
|
|
|
2011-07-09 21:13:25 -07:00
|
|
|
extern "C" void
|
2011-07-10 01:20:18 -07:00
|
|
|
rust_intrinsic_vec_len(rust_task *task, size_t *retptr, type_desc *ty,
|
|
|
|
rust_vec *v)
|
2011-07-09 21:13:25 -07:00
|
|
|
{
|
|
|
|
*retptr = v->fill / ty->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
2011-07-10 01:20:18 -07:00
|
|
|
rust_intrinsic_ivec_len(rust_task *task, size_t *retptr, type_desc *ty,
|
|
|
|
rust_ivec *v)
|
2011-07-09 21:13:25 -07:00
|
|
|
{
|
|
|
|
size_t fill;
|
|
|
|
if (v->fill)
|
|
|
|
fill = v->fill;
|
|
|
|
else if (v->payload.ptr)
|
|
|
|
fill = v->payload.ptr->fill;
|
|
|
|
else
|
|
|
|
fill = 0;
|
|
|
|
*retptr = fill / ty->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
|
|
|
rust_intrinsic_ptr_offset(rust_task *task, void **retptr, type_desc *ty,
|
|
|
|
void *ptr, uintptr_t count)
|
2011-07-08 21:55:43 -07:00
|
|
|
{
|
2011-07-09 21:13:25 -07:00
|
|
|
*retptr = &((uint8_t *)ptr)[ty->size * count];
|
2011-07-08 21:55:43 -07:00
|
|
|
}
|
|
|
|
|
2011-07-09 20:14:20 -07:00
|
|
|
extern "C" void
|
2011-07-09 21:13:25 -07:00
|
|
|
rust_intrinsic_cast(rust_task *task, void *retptr, type_desc *t1,
|
|
|
|
type_desc *t2, void *src)
|
2011-07-09 20:14:20 -07:00
|
|
|
{
|
|
|
|
if (t1->size != t2->size) {
|
|
|
|
upcall_fail(task, "attempt to cast values of differing sizes",
|
|
|
|
__FILE__, __LINE__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-09 21:13:25 -07:00
|
|
|
memmove(retptr, src, t1->size);
|
2011-07-09 20:14:20 -07:00
|
|
|
}
|
|
|
|
|