Skip to content

Commit 3739af2

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 5806043 commit 3739af2

15 files changed

+947
-2690
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

1314
#
@@ -238,26 +239,6 @@ list(REMOVE_ITEM FE_SRC
238239
${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/id.c
239240
${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/impcnvtab.c
240241
)
241-
# Add/remove files for MSVC
242-
if(MSVC)
243-
list(APPEND FE_SRC
244-
${PROJECT_SOURCE_DIR}/vcbuild/strtold.c
245-
# See below why this don't work
246-
# if(CMAKE_CL_64)
247-
# ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
248-
# endif()
249-
)
250-
if(CMAKE_CL_64)
251-
# MASM support does not work yet!
252-
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj
253-
COMMAND ${CMAKE_ASM_MASM_COMPILER} /c /Fo${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
254-
DEPENDS ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
255-
COMMENT "generate ldfpu.obj")
256-
list(APPEND FE_SRC
257-
${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj
258-
)
259-
endif()
260-
endif()
261242
set(LDC_SOURCE_FILES
262243
${LDC_GENERATED}
263244
${FE_SRC}
@@ -338,6 +319,27 @@ else()
338319
set(EXTRA_CXXFLAGS "-fexceptions")
339320
endif()
340321

322+
#
323+
# check string functions
324+
#
325+
check_symbol_exists(memicmp "string.h" HAVE_MEMICMP)
326+
check_symbol_exists(stricmp "string.h" HAVE_STRICMP)
327+
check_symbol_exists(strupr "string.h" HAVE_STRUPR)
328+
check_symbol_exists(strtof "stdlib.h" HAVE_STRTOF)
329+
330+
if(HAVE_MEMICMP)
331+
add_definitions(-DHAVE_MEMICMP)
332+
endif()
333+
334+
if(HAVE_STRICMP)
335+
add_definitions(-DHAVE_STRICMP)
336+
endif()
337+
338+
if(HAVE_STRUPR)
339+
add_definitions(-DHAVE_STRUPR)
340+
endif()
341+
342+
341343
#
342344
# Check endianess.
343345
# There is no realiable way to delegate the work to the compiler.
@@ -468,7 +470,6 @@ endif()
468470
#
469471
# LDMD
470472
#
471-
include(CheckSymbolExists)
472473
CHECK_SYMBOL_EXISTS(_SC_ARG_MAX "unistd.h" HAVE_SC_ARG_MAX)
473474
if (HAVE_SC_ARG_MAX)
474475
add_definitions(-DHAVE_SC_ARG_MAX)

dmd2/builtin.c

+26
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Expression *eval_unimp(Loc loc, FuncDeclaration *fd, Expressions *arguments)
4343
return NULL;
4444
}
4545

46+
#if !IN_LLVM
4647
Expression *eval_sin(Loc loc, FuncDeclaration *fd, Expressions *arguments)
4748
{
4849
Expression *arg0 = (*arguments)[0];
@@ -63,6 +64,7 @@ Expression *eval_tan(Loc loc, FuncDeclaration *fd, Expressions *arguments)
6364
assert(arg0->op == TOKfloat64);
6465
return new RealExp(loc, tanl(arg0->toReal()), arg0->type);
6566
}
67+
#endif
6668

6769
Expression *eval_sqrt(Loc loc, FuncDeclaration *fd, Expressions *arguments)
6870
{
@@ -133,18 +135,30 @@ void builtin_init()
133135
builtins._init(45);
134136

135137
// @safe pure nothrow real function(real)
138+
#if IN_LLVM
139+
add_builtin("_D4core4math3sinFNaNbNfeZe", &eval_unimp);
140+
add_builtin("_D4core4math3cosFNaNbNfeZe", &eval_unimp);
141+
add_builtin("_D4core4math3tanFNaNbNfeZe", &eval_unimp);
142+
#else
136143
add_builtin("_D4core4math3sinFNaNbNfeZe", &eval_sin);
137144
add_builtin("_D4core4math3cosFNaNbNfeZe", &eval_cos);
138145
add_builtin("_D4core4math3tanFNaNbNfeZe", &eval_tan);
146+
#endif
139147
add_builtin("_D4core4math4sqrtFNaNbNfeZe", &eval_sqrt);
140148
add_builtin("_D4core4math4fabsFNaNbNfeZe", &eval_fabs);
141149
add_builtin("_D4core4math5expm1FNaNbNfeZe", &eval_unimp);
142150
add_builtin("_D4core4math4exp21FNaNbNfeZe", &eval_unimp);
143151

144152
// @trusted pure nothrow real function(real)
153+
#if IN_LLVM
154+
add_builtin("_D4core4math3sinFNaNbNeeZe", &eval_unimp);
155+
add_builtin("_D4core4math3cosFNaNbNeeZe", &eval_unimp);
156+
add_builtin("_D4core4math3tanFNaNbNeeZe", &eval_unimp);
157+
#else
145158
add_builtin("_D4core4math3sinFNaNbNeeZe", &eval_sin);
146159
add_builtin("_D4core4math3cosFNaNbNeeZe", &eval_cos);
147160
add_builtin("_D4core4math3tanFNaNbNeeZe", &eval_tan);
161+
#endif
148162
add_builtin("_D4core4math4sqrtFNaNbNeeZe", &eval_sqrt);
149163
add_builtin("_D4core4math4fabsFNaNbNeeZe", &eval_fabs);
150164
add_builtin("_D4core4math5expm1FNaNbNeeZe", &eval_unimp);
@@ -164,18 +178,30 @@ void builtin_init()
164178
add_builtin("_D4core4math6rndtolFNaNbNfeZl", &eval_unimp);
165179

166180
// @safe pure nothrow real function(real)
181+
#if IN_LLVM
182+
add_builtin("_D3std4math3sinFNaNbNfeZe", &eval_unimp);
183+
add_builtin("_D3std4math3cosFNaNbNfeZe", &eval_unimp);
184+
add_builtin("_D3std4math3tanFNaNbNfeZe", &eval_unimp);
185+
#else
167186
add_builtin("_D3std4math3sinFNaNbNfeZe", &eval_sin);
168187
add_builtin("_D3std4math3cosFNaNbNfeZe", &eval_cos);
169188
add_builtin("_D3std4math3tanFNaNbNfeZe", &eval_tan);
189+
#endif
170190
add_builtin("_D3std4math4sqrtFNaNbNfeZe", &eval_sqrt);
171191
add_builtin("_D3std4math4fabsFNaNbNfeZe", &eval_fabs);
172192
add_builtin("_D3std4math5expm1FNaNbNfeZe", &eval_unimp);
173193
add_builtin("_D3std4math4exp21FNaNbNfeZe", &eval_unimp);
174194

175195
// @trusted pure nothrow real function(real)
196+
#if IN_LLVM
197+
add_builtin("_D3std4math3sinFNaNbNeeZe", &eval_unimp);
198+
add_builtin("_D3std4math3cosFNaNbNeeZe", &eval_unimp);
199+
add_builtin("_D3std4math3tanFNaNbNeeZe", &eval_unimp);
200+
#else
176201
add_builtin("_D3std4math3sinFNaNbNeeZe", &eval_sin);
177202
add_builtin("_D3std4math3cosFNaNbNeeZe", &eval_cos);
178203
add_builtin("_D3std4math3tanFNaNbNeeZe", &eval_tan);
204+
#endif
179205
add_builtin("_D3std4math4sqrtFNaNbNeeZe", &eval_sqrt);
180206
add_builtin("_D3std4math4fabsFNaNbNeeZe", &eval_fabs);
181207
add_builtin("_D3std4math5expm1FNaNbNeeZe", &eval_unimp);

0 commit comments

Comments
 (0)