Skip to content

Commit

Permalink
fix remill intrinsics for float80 (#539)
Browse files Browse the repository at this point in the history
* Fix remill fp intrinsics to handle fp80 types

* update f80 write intrinsic

* define read function
  • Loading branch information
kumarak authored Sep 13, 2021
1 parent d93575e commit d8d3b6c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
5 changes: 3 additions & 2 deletions include/remill/Arch/Runtime/Intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ __remill_write_memory_64(Memory *, addr_t, uint64_t);
[[gnu::used, gnu::const]] extern float64_t __remill_read_memory_f64(Memory *,
addr_t);

[[gnu::used]] extern float80_t __remill_read_memory_f80(Memory *, addr_t);
[[gnu::used]] extern Memory* __remill_read_memory_f80(Memory *, addr_t,
native_float80_t&);

[[gnu::used]] extern float128_t __remill_read_memory_f128(Memory *, addr_t);

Expand All @@ -68,7 +69,7 @@ __remill_write_memory_f32(Memory *, addr_t, float32_t);
__remill_write_memory_f64(Memory *, addr_t, float64_t);

[[gnu::used]] extern Memory *__remill_write_memory_f80(Memory *, addr_t,
float80_t);
const native_float80_t&);

[[gnu::used]] extern Memory *__remill_write_memory_f128(Memory *, addr_t,
float128_t);
Expand Down
13 changes: 12 additions & 1 deletion include/remill/Arch/Runtime/Operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,21 @@ MAKE_MREAD(128, 128, uint, 128)

MAKE_MREAD(32, 32, float, f32)
MAKE_MREAD(64, 64, float, f64)
MAKE_MREAD(80, 80, float, f80)

#undef MAKE_MREAD

ALWAYS_INLINE static float80_t _Read(Memory *&memory, Mn<float80_t> op) {
native_float80_t val;
memory = __remill_read_memory_f80(memory, op.addr, val);
return val;
}

ALWAYS_INLINE static float80_t _Read(Memory *&memory, MnW<float80_t> op) {
native_float80_t val;
memory = __remill_read_memory_f80(memory, op.addr, val);
return val;
}

// Basic write form for references.
template <typename T>
ALWAYS_INLINE static Memory *_Write(Memory *memory, T &dst, T src) {
Expand Down
16 changes: 11 additions & 5 deletions lib/BC/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1850,9 +1850,12 @@ llvm::Value *LoadFromMemory(const IntrinsicTable &intrinsics,
case llvm::Type::DoubleTyID:
return ir.CreateCall(intrinsics.read_memory_f64, args_2);

case llvm::Type::X86_FP80TyID:
return ir.CreateFPExt(ir.CreateCall(intrinsics.read_memory_f80, args_2),
type);
case llvm::Type::X86_FP80TyID: {
auto res = ir.CreateAlloca(type);
llvm::Value *args_3[3] = {args_2[0], args_2[1], res};
ir.CreateCall(intrinsics.read_memory_f80, args_3);
return ir.CreateLoad(res);
}

case llvm::Type::X86_MMXTyID:
return ir.CreateBitCast(ir.CreateCall(intrinsics.read_memory_64, args_2),
Expand Down Expand Up @@ -2022,8 +2025,11 @@ llvm::Value *StoreToMemory(const IntrinsicTable &intrinsics,
return ir.CreateCall(intrinsics.write_memory_f64, args_3);

case llvm::Type::X86_FP80TyID: {
auto double_type = llvm::Type::getDoubleTy(context);
args_3[2] = ir.CreateFPTrunc(val_to_store, double_type);
auto res = ir.CreateAlloca(type);
auto fp80_type = llvm::Type::getX86_FP80Ty(context);
auto fp80_value = ir.CreateFPTrunc(val_to_store, fp80_type);
(void) ir.CreateStore(fp80_value, res);
args_3[2] = res;
return ir.CreateCall(intrinsics.write_memory_f80, args_3);
}

Expand Down
13 changes: 12 additions & 1 deletion tests/X86/Run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,20 @@ MAKE_RW_MEMORY(64)

MAKE_RW_FP_MEMORY(32)
MAKE_RW_FP_MEMORY(64)
MAKE_RW_FP_MEMORY(80)
//MAKE_RW_FP_MEMORY(80)
MAKE_RW_FP_MEMORY(128)

NEVER_INLINE Memory *__remill_read_memory_f80(Memory *, addr_t addr,
native_float80_t &out) {
out = AccessMemory<native_float80_t>(addr);
return nullptr;
}

NEVER_INLINE Memory *__remill_write_memory_f80(Memory *, addr_t addr,
const native_float80_t &in) {
AccessMemory<native_float80_t>(addr) = in;
return nullptr;
}

Memory *__remill_compare_exchange_memory_8(Memory *memory, addr_t addr,
uint8_t &expected, uint8_t desired) {
Expand Down

0 comments on commit d8d3b6c

Please sign in to comment.