Skip to content

Commit

Permalink
Fix issue JuliaLang#7687, by revising original fix for issue JuliaLan…
Browse files Browse the repository at this point in the history
…g#41

to use volatile store/load on 32-bit x86 only.
  • Loading branch information
Arch D. Robison committed Jul 24, 2014
1 parent 81d82ef commit 3f77ae0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ static Value *V_null;
static GlobalVariable *jltrue_var;
static GlobalVariable *jlfalse_var;
static GlobalVariable *jlnull_var;
#if defined(_CPU_X86_)
#define JL_NEED_FLOATTEMP_VAR 1
#endif
#if JL_NEED_FLOATTEMP_VAR
static GlobalVariable *jlfloattemp_var;
#endif
#ifdef JL_GC_MARKSWEEP
static GlobalVariable *jlpgcstack_var;
#endif
Expand Down Expand Up @@ -4043,14 +4048,14 @@ static void init_julia_llvm_env(Module *m)
NULL, "jl_dl_handle");
add_named_global(jldll_var, (void*)&jl_dl_handle);
#endif

#if JL_NEED_FLOATTEMP_VAR
// Has to be big enough for the biggest LLVM-supported float type
jlfloattemp_var =
new GlobalVariable(*m, IntegerType::get(jl_LLVMContext,128),
false, GlobalVariable::ExternalLinkage,
ConstantInt::get(IntegerType::get(jl_LLVMContext,128),0),
"jl_float_temp");

#endif

std::vector<Type*> args1(0);
args1.push_back(T_pint8);
Expand Down
12 changes: 7 additions & 5 deletions src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,16 +891,18 @@ static Value *emit_intrinsic(intrinsic f, jl_value_t **args, size_t nargs,

HANDLE(fptrunc,2) return builder.CreateFPTrunc(FP(auto_unbox(args[2],ctx)), FTnbits(try_to_determine_bitstype_nbits(args[1],ctx)));
HANDLE(fpext,2) {
// when extending a float32 to a float64, we need to force
// rounding to single precision first. the reason is that it's
Value *x = auto_unbox(args[2],ctx);
#if JL_NEED_FLOATTEMP_VAR
// Target platform might carry extra precision.
// Force rounding to single precision first. The reason is that it's
// fine to keep working in extended precision as long as it's
// understood that everything is implicitly rounded to 23 bits,
// but if we start looking at more bits we need to actually do the
// rounding first instead of carrying around incorrect low bits.
Value *x = auto_unbox(args[2],ctx);
builder.CreateStore(FP(x), builder.CreateBitCast(prepare_global(jlfloattemp_var),FT(x->getType())->getPointerTo()), true);
return builder.CreateFPExt(builder.CreateLoad(builder.CreateBitCast(prepare_global(jlfloattemp_var),FT(x->getType())->getPointerTo()), true),
FTnbits(try_to_determine_bitstype_nbits(args[1],ctx)));
x = builder.CreateLoad(builder.CreateBitCast(prepare_global(jlfloattemp_var),FT(x->getType())->getPointerTo()), true);
#endif
return builder.CreateFPExt(x, FTnbits(try_to_determine_bitstype_nbits(args[1],ctx)));
}
HANDLE(select_value,3) {
Value *isfalse = emit_condition(args[1], "select_value", ctx);
Expand Down

0 comments on commit 3f77ae0

Please sign in to comment.