Skip to content

Commit ae5ea15

Browse files
committed
Implement longdouble as a wrapper around llvm::APFloat.
This commit introduces a new class ldc::longdouble which provides real_t semantics based on the target. It uses llvm::APFloat as base implementation. This fixes issue ldc-developers#259.
1 parent 0e00a02 commit ae5ea15

15 files changed

+1080
-2725
lines changed

CMakeLists.txt

+22-21
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ if(MSVC)
88
endif()
99

1010
include(CheckIncludeFile)
11+
include(CheckSymbolExists)
1112
include(CheckLibraryExists)
1213
include(CheckCXXCompilerFlag)
1314

@@ -248,26 +249,6 @@ list(REMOVE_ITEM FE_SRC
248249
${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/id.c
249250
${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/impcnvtab.c
250251
)
251-
# Add/remove files for MSVC
252-
if(MSVC)
253-
list(APPEND FE_SRC
254-
${PROJECT_SOURCE_DIR}/vcbuild/strtold.c
255-
# See below why this don't work
256-
# if(CMAKE_CL_64)
257-
# ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
258-
# endif()
259-
)
260-
if(CMAKE_CL_64)
261-
# MASM support does not work yet!
262-
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj
263-
COMMAND ${CMAKE_ASM_MASM_COMPILER} /c /Fo${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
264-
DEPENDS ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
265-
COMMENT "generate ldfpu.obj")
266-
list(APPEND FE_SRC
267-
${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj
268-
)
269-
endif()
270-
endif()
271252
set(LDC_SOURCE_FILES
272253
${LDC_GENERATED}
273254
${FE_SRC}
@@ -349,6 +330,27 @@ if(LLVM_ENABLE_ASSERTIONS)
349330
string(REGEX REPLACE "(^| )[/-]D *NDEBUG( |$)" " " CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
350331
endif()
351332

333+
#
334+
# check string functions
335+
#
336+
check_symbol_exists(memicmp "string.h" HAVE_MEMICMP)
337+
check_symbol_exists(stricmp "string.h" HAVE_STRICMP)
338+
check_symbol_exists(strupr "string.h" HAVE_STRUPR)
339+
check_symbol_exists(strtof "stdlib.h" HAVE_STRTOF)
340+
341+
if(HAVE_MEMICMP)
342+
add_definitions(-DHAVE_MEMICMP)
343+
endif()
344+
345+
if(HAVE_STRICMP)
346+
add_definitions(-DHAVE_STRICMP)
347+
endif()
348+
349+
if(HAVE_STRUPR)
350+
add_definitions(-DHAVE_STRUPR)
351+
endif()
352+
353+
352354
#
353355
# Check endianess.
354356
# There is no realiable way to delegate the work to the compiler.
@@ -477,7 +479,6 @@ endif()
477479
#
478480
# LDMD
479481
#
480-
include(CheckSymbolExists)
481482
CHECK_SYMBOL_EXISTS(_SC_ARG_MAX "unistd.h" HAVE_SC_ARG_MAX)
482483
if (HAVE_SC_ARG_MAX)
483484
add_definitions(-DHAVE_SC_ARG_MAX)

dmd2/builtin.c

+42-5
Original file line numberDiff line numberDiff line change
@@ -48,41 +48,78 @@ Expression *eval_unimp(Loc loc, FuncDeclaration *fd, Expressions *arguments)
4848
return NULL;
4949
}
5050

51+
#if IN_LLVM
5152
Expression *eval_sin(Loc loc, FuncDeclaration *fd, Expressions *arguments)
5253
{
5354
Expression *arg0 = (*arguments)[0];
5455
assert(arg0->op == TOKfloat64);
55-
return new RealExp(loc, sinl(arg0->toReal()), arg0->type);
56+
return new RealExp(loc, ldouble(arg0->toReal()).sin(), arg0->type);
5657
}
5758

5859
Expression *eval_cos(Loc loc, FuncDeclaration *fd, Expressions *arguments)
5960
{
6061
Expression *arg0 = (*arguments)[0];
6162
assert(arg0->op == TOKfloat64);
62-
return new RealExp(loc, cosl(arg0->toReal()), arg0->type);
63+
return new RealExp(loc, ldouble(arg0->toReal()).cos(), arg0->type);
6364
}
6465

6566
Expression *eval_tan(Loc loc, FuncDeclaration *fd, Expressions *arguments)
6667
{
6768
Expression *arg0 = (*arguments)[0];
6869
assert(arg0->op == TOKfloat64);
69-
return new RealExp(loc, tanl(arg0->toReal()), arg0->type);
70+
return new RealExp(loc, ldouble(arg0->toReal()).tan(), arg0->type);
7071
}
7172

7273
Expression *eval_sqrt(Loc loc, FuncDeclaration *fd, Expressions *arguments)
7374
{
7475
Expression *arg0 = (*arguments)[0];
7576
assert(arg0->op == TOKfloat64);
76-
return new RealExp(loc, Port::sqrt(arg0->toReal()), arg0->type);
77+
return new RealExp(loc, ldouble(arg0->toReal()).sqrt(), arg0->type);
7778
}
7879

7980
Expression *eval_fabs(Loc loc, FuncDeclaration *fd, Expressions *arguments)
8081
{
8182
Expression *arg0 = (*arguments)[0];
8283
assert(arg0->op == TOKfloat64);
83-
return new RealExp(loc, fabsl(arg0->toReal()), arg0->type);
84+
return new RealExp(loc, ldouble(arg0->toReal()).abs(), arg0->type);
85+
}
86+
#else
87+
Expression *eval_sin(Loc loc, FuncDeclaration *fd, Expressions *arguments)
88+
{
89+
Expression *arg0 = (*arguments)[0];
90+
assert(arg0->op == TOKfloat64);
91+
return new RealExp(loc, sinl(arg0->toReal()), arg0->type);
92+
}
93+
94+
Expression *eval_cos(Loc loc, FuncDeclaration *fd, Expressions *arguments)
95+
{
96+
Expression *arg0 = (*arguments)[0];
97+
assert(arg0->op == TOKfloat64);
98+
return new RealExp(loc, cosl(arg0->toReal()), arg0->type);
99+
}
100+
101+
Expression *eval_tan(Loc loc, FuncDeclaration *fd, Expressions *arguments)
102+
{
103+
Expression *arg0 = (*arguments)[0];
104+
assert(arg0->op == TOKfloat64);
105+
return new RealExp(loc, tanl(arg0->toReal()), arg0->type);
106+
}
107+
108+
Expression *eval_sqrt(Loc loc, FuncDeclaration *fd, Expressions *arguments)
109+
{
110+
Expression *arg0 = (*arguments)[0];
111+
assert(arg0->op == TOKfloat64);
112+
return new RealExp(loc, Port::sqrt(arg0->toReal()), arg0->type);
84113
}
85114

115+
Expression *eval_fabs(Loc loc, FuncDeclaration *fd, Expressions *arguments)
116+
{
117+
Expression *arg0 = (*arguments)[0];
118+
assert(arg0->op == TOKfloat64);
119+
return new RealExp(loc, fabsl(arg0->toReal()), arg0->type);
120+
}
121+
#endif
122+
86123
#if IN_LLVM
87124

88125
static inline Type *getTypeOfOverloadedIntrinsic(FuncDeclaration *fd)

0 commit comments

Comments
 (0)