Skip to content

Commit 3fe43f9

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 4066b29 commit 3fe43f9

15 files changed

+926
-2690
lines changed

CMakeLists.txt

+22-21
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ if(MSVC)
1313
endif()
1414

1515
include(CheckIncludeFile)
16+
include(CheckSymbolExists)
1617
include(CheckLibraryExists)
1718

1819
#
@@ -249,26 +250,6 @@ list(REMOVE_ITEM FE_SRC
249250
${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/id.c
250251
${PROJECT_SOURCE_DIR}/${DMDFE_PATH}/impcnvtab.c
251252
)
252-
# Add/remove files for MSVC
253-
if(MSVC)
254-
list(APPEND FE_SRC
255-
${PROJECT_SOURCE_DIR}/vcbuild/strtold.c
256-
# See below why this don't work
257-
# if(CMAKE_CL_64)
258-
# ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
259-
# endif()
260-
)
261-
if(CMAKE_CL_64)
262-
# MASM support does not work yet!
263-
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj
264-
COMMAND ${CMAKE_ASM_MASM_COMPILER} /c /Fo${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
265-
DEPENDS ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
266-
COMMENT "generate ldfpu.obj")
267-
list(APPEND FE_SRC
268-
${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj
269-
)
270-
endif()
271-
endif()
272253
set(LDC_SOURCE_FILES
273254
${LDC_GENERATED}
274255
${FE_SRC}
@@ -347,6 +328,27 @@ else()
347328
set(EXTRA_CXXFLAGS "-fexceptions")
348329
endif()
349330

331+
#
332+
# check string functions
333+
#
334+
check_symbol_exists(memicmp "string.h" HAVE_MEMICMP)
335+
check_symbol_exists(stricmp "string.h" HAVE_STRICMP)
336+
check_symbol_exists(strupr "string.h" HAVE_STRUPR)
337+
check_symbol_exists(strtof "stdlib.h" HAVE_STRTOF)
338+
339+
if(HAVE_MEMICMP)
340+
add_definitions(-DHAVE_MEMICMP)
341+
endif()
342+
343+
if(HAVE_STRICMP)
344+
add_definitions(-DHAVE_STRICMP)
345+
endif()
346+
347+
if(HAVE_STRUPR)
348+
add_definitions(-DHAVE_STRUPR)
349+
endif()
350+
351+
350352
#
351353
# Check endianess.
352354
# There is no realiable way to delegate the work to the compiler.
@@ -481,7 +483,6 @@ get_target_property(GEN_GCCBUILTINS_LOC gen_gccbuiltins LOCATION)
481483
#
482484
# LDMD
483485
#
484-
include(CheckSymbolExists)
485486
CHECK_SYMBOL_EXISTS(_SC_ARG_MAX "unistd.h" HAVE_SC_ARG_MAX)
486487
if (HAVE_SC_ARG_MAX)
487488
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)