Skip to content

Commit 4e45ba4

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 4e45ba4

14 files changed

+886
-1972
lines changed

CMakeLists.txt

+23-17
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
#
@@ -252,22 +253,7 @@ list(REMOVE_ITEM FE_SRC
252253
# Add/remove files for MSVC
253254
if(MSVC)
254255
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()
256+
${PROJECT_SOURCE_DIR}/vcbuild/strtold.c)
271257
endif()
272258
set(LDC_SOURCE_FILES
273259
${LDC_GENERATED}
@@ -347,6 +333,27 @@ else()
347333
set(EXTRA_CXXFLAGS "-fexceptions")
348334
endif()
349335

336+
#
337+
# check string functions
338+
#
339+
check_symbol_exists(memicmp "string.h" HAVE_MEMICMP)
340+
check_symbol_exists(stricmp "string.h" HAVE_STRICMP)
341+
check_symbol_exists(strupr "string.h" HAVE_STRUPR)
342+
check_symbol_exists(strtof "stdlib.h" HAVE_STRTOF)
343+
344+
if(HAVE_MEMICMP)
345+
add_definitions(-DHAVE_MEMICMP)
346+
endif()
347+
348+
if(HAVE_STRICMP)
349+
add_definitions(-DHAVE_STRICMP)
350+
endif()
351+
352+
if(HAVE_STRUPR)
353+
add_definitions(-DHAVE_STRUPR)
354+
endif()
355+
356+
350357
#
351358
# Check endianess.
352359
# There is no realiable way to delegate the work to the compiler.
@@ -481,7 +488,6 @@ get_target_property(GEN_GCCBUILTINS_LOC gen_gccbuiltins LOCATION)
481488
#
482489
# LDMD
483490
#
484-
include(CheckSymbolExists)
485491
CHECK_SYMBOL_EXISTS(_SC_ARG_MAX "unistd.h" HAVE_SC_ARG_MAX)
486492
if (HAVE_SC_ARG_MAX)
487493
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)