Skip to content

Commit

Permalink
cleanup runtime_intrinsics DLLEXPORT and license
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Oct 13, 2015
1 parent d23dc85 commit a2516aa
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 68 deletions.
8 changes: 6 additions & 2 deletions src/APInt-C.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// This file is a part of Julia. License is MIT: http://julialang.org/license

#include "llvm-version.h"
#include <llvm/ADT/APInt.h>
#include <llvm/ADT/APFloat.h>
#include <llvm/Support/MathExtras.h>

#define DLLEXPORT
extern "C" DLLEXPORT void jl_error(const char *str);
extern "C" {
#include "APInt-C.h"
DLLEXPORT void jl_error(const char *str);
}

using namespace llvm;

Expand Down
131 changes: 69 additions & 62 deletions src/APInt-C.h
Original file line number Diff line number Diff line change
@@ -1,74 +1,81 @@
// This file is a part of Julia. License is MIT: http://julialang.org/license

#ifndef APINT_C_H
#define APINT_C_H

#ifdef __cplusplus
extern "C" {
#endif
#include "dtypes.h"

#ifdef LLVM_VERSION_MAJOR
using llvm::integerPart;
#else
typedef void integerPart;
#endif

void LLVMNeg(unsigned numbits, integerPart *pa, integerPart *pr);
void LLVMByteSwap(unsigned numbits, integerPart *pa, integerPart *pr);

void LLVMAdd(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
void LLVMSub(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
void LLVMMul(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
void LLVMSDiv(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
void LLVMUDiv(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
void LLVMSRem(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
void LLVMURem(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);

void LLVMAnd(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
void LLVMOr(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
void LLVMXor(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
void LLVMShl(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
void LLVMLShr(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
void LLVMAShr(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
void LLVMFlipAllBits(unsigned numbits, integerPart *pa, integerPart *pr);

int LLVMICmpEQ(unsigned numbits, integerPart *pa, integerPart *pr);
int LLVMICmpNE(unsigned numbits, integerPart *pa, integerPart *pb);
int LLVMICmpSLT(unsigned numbits, integerPart *pa, integerPart *pb);
int LLVMICmpULT(unsigned numbits, integerPart *pa, integerPart *pb);
int LLVMICmpSLE(unsigned numbits, integerPart *pa, integerPart *pb);
int LLVMICmpULE(unsigned numbits, integerPart *pa, integerPart *pb);

int LLVMAdd_uov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
int LLVMAdd_sov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
int LLVMSub_uov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
int LLVMSub_sov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
int LLVMMul_sov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
int LLVMMul_uov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);

unsigned LLVMCountPopulation(unsigned numbits, integerPart *pa);
unsigned LLVMCountTrailingOnes(unsigned numbits, integerPart *pa);
unsigned LLVMCountTrailingZeros(unsigned numbits, integerPart *pa);
unsigned LLVMCountLeadingOnes(unsigned numbits, integerPart *pa);
unsigned LLVMCountLeadingZeros(unsigned numbits, integerPart *pa);

void LLVMFPtoSI(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);
void LLVMFPtoUI(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);
void LLVMSItoFP(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);
void LLVMUItoFP(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);
void LLVMSExt(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);
void LLVMZExt(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);
void LLVMTrunc(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);

int LLVMFPtoSI_exact(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);
int LLVMFPtoUI_exact(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);

void jl_LLVMSMod(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
void jl_LLVMFlipSign(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);

unsigned countTrailingZeros_8(uint8_t Val);
unsigned countTrailingZeros_16(uint16_t Val);
unsigned countTrailingZeros_32(uint32_t Val);
unsigned countTrailingZeros_64(uint64_t Val);

uint8_t getSwappedBytes_8(uint8_t Value); // no-op
uint16_t getSwappedBytes_16(uint16_t Value);
uint32_t getSwappedBytes_32(uint32_t Value);
uint64_t getSwappedBytes_64(uint64_t Value);
DLLEXPORT void LLVMNeg(unsigned numbits, integerPart *pa, integerPart *pr);
DLLEXPORT void LLVMByteSwap(unsigned numbits, integerPart *pa, integerPart *pr);

DLLEXPORT void LLVMAdd(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT void LLVMSub(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT void LLVMMul(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT void LLVMSDiv(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT void LLVMUDiv(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT void LLVMSRem(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT void LLVMURem(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);

DLLEXPORT void LLVMAnd(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT void LLVMOr(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT void LLVMXor(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT void LLVMShl(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT void LLVMLShr(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT void LLVMAShr(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT void LLVMFlipAllBits(unsigned numbits, integerPart *pa, integerPart *pr);

DLLEXPORT int LLVMICmpEQ(unsigned numbits, integerPart *pa, integerPart *pr);
DLLEXPORT int LLVMICmpNE(unsigned numbits, integerPart *pa, integerPart *pb);
DLLEXPORT int LLVMICmpSLT(unsigned numbits, integerPart *pa, integerPart *pb);
DLLEXPORT int LLVMICmpULT(unsigned numbits, integerPart *pa, integerPart *pb);
DLLEXPORT int LLVMICmpSLE(unsigned numbits, integerPart *pa, integerPart *pb);
DLLEXPORT int LLVMICmpULE(unsigned numbits, integerPart *pa, integerPart *pb);

DLLEXPORT int LLVMAdd_uov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT int LLVMAdd_sov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT int LLVMSub_uov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT int LLVMSub_sov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT int LLVMMul_sov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT int LLVMMul_uov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);

DLLEXPORT unsigned LLVMCountPopulation(unsigned numbits, integerPart *pa);
DLLEXPORT unsigned LLVMCountTrailingOnes(unsigned numbits, integerPart *pa);
DLLEXPORT unsigned LLVMCountTrailingZeros(unsigned numbits, integerPart *pa);
DLLEXPORT unsigned LLVMCountLeadingOnes(unsigned numbits, integerPart *pa);
DLLEXPORT unsigned LLVMCountLeadingZeros(unsigned numbits, integerPart *pa);

DLLEXPORT void LLVMFPtoSI(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);
DLLEXPORT void LLVMFPtoUI(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);
DLLEXPORT void LLVMSItoFP(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);
DLLEXPORT void LLVMUItoFP(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);
DLLEXPORT void LLVMSExt(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);
DLLEXPORT void LLVMZExt(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);
DLLEXPORT void LLVMTrunc(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);

DLLEXPORT int LLVMFPtoSI_exact(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);
DLLEXPORT int LLVMFPtoUI_exact(unsigned numbits, integerPart *pa, unsigned onumbits, integerPart *pr);

DLLEXPORT void jl_LLVMSMod(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
DLLEXPORT void jl_LLVMFlipSign(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);

DLLEXPORT unsigned countTrailingZeros_8(uint8_t Val);
DLLEXPORT unsigned countTrailingZeros_16(uint16_t Val);
DLLEXPORT unsigned countTrailingZeros_32(uint32_t Val);
DLLEXPORT unsigned countTrailingZeros_64(uint64_t Val);

//uint8_t getSwappedBytes_8(uint8_t Value); // no-op
//uint16_t getSwappedBytes_16(uint16_t Value);
//uint32_t getSwappedBytes_32(uint32_t Value);
//uint64_t getSwappedBytes_64(uint64_t Value);


#ifdef __cplusplus
Expand Down
11 changes: 7 additions & 4 deletions src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,10 @@ static jl_cgval_t generic_unbox(jl_value_t *targ, jl_value_t *x, jl_codectx_t *c
}
else {
if (!jl_is_leaf_type(v.typ) && !jl_is_bitstype(v.typ)) {
return jl_cgval_t(); // TODO: XXX
// TODO: currently doesn't handle the case where the type of neither argument is understood at compile time
// since codegen has no idea what size it might have
jl_error("codegen: failed during evaluation of a call to unbox");
return jl_cgval_t();
}
nb = jl_datatype_size(v.typ);
llvmt = staticeval_bitstype(v.typ);
Expand All @@ -515,7 +518,7 @@ static jl_cgval_t generic_unbox(jl_value_t *targ, jl_value_t *x, jl_codectx_t *c

if (!jl_is_bitstype(bt)) {
// TODO: to accept arbitrary types, replace this function with a call to llvm_type_rewrite
emit_error("reinterpret: expected bits type as first argument", ctx);
emit_error("unbox: expected bits type as first argument", ctx);
return jl_cgval_t();
}

Expand All @@ -536,7 +539,7 @@ static jl_cgval_t generic_unbox(jl_value_t *targ, jl_value_t *x, jl_codectx_t *c
else {
vx = v.V;
if (!jl_is_bitstype(v.typ)) {
emit_error("reinterpret: expected bits type value for second argument", ctx);
emit_error("unbox: expected bits type value for second argument", ctx);
return jl_cgval_t();
}
}
Expand All @@ -554,7 +557,7 @@ static jl_cgval_t generic_unbox(jl_value_t *targ, jl_value_t *x, jl_codectx_t *c
if (vxt->getPrimitiveSizeInBits() != llvmt->getPrimitiveSizeInBits() &&
!(vxt->isPointerTy() && llvmt->getPrimitiveSizeInBits() == sizeof(void*)*8) &&
!(llvmt->isPointerTy() && vxt->getPrimitiveSizeInBits() == sizeof(void*)*8)) {
emit_error("box: argument is of incorrect size", ctx);
emit_error("unbox: argument is of incorrect size", ctx);
return jl_cgval_t();
}
if (vxt->isPointerTy() && !llvmt->isPointerTy())
Expand Down
1 change: 1 addition & 0 deletions src/runtime_ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <map>
#include <string>
#include <cstdio>
#include "julia.h"
#include "julia_internal.h"

Expand Down

0 comments on commit a2516aa

Please sign in to comment.