Skip to content

Commit 28fb79e

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 d97a8ca commit 28fb79e

14 files changed

+830
-2112
lines changed

CMakeLists.txt

+22-17
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
#
@@ -243,22 +244,7 @@ list(REMOVE_ITEM FE_SRC
243244
# Add/remove files for MSVC
244245
if(MSVC)
245246
list(APPEND FE_SRC
246-
${PROJECT_SOURCE_DIR}/vcbuild/strtold.c
247-
# See below why this don't work
248-
# if(CMAKE_CL_64)
249-
# ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
250-
# endif()
251-
)
252-
if(CMAKE_CL_64)
253-
# MASM support does not work yet!
254-
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj
255-
COMMAND ${CMAKE_ASM_MASM_COMPILER} /c /Fo${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
256-
DEPENDS ${PROJECT_SOURCE_DIR}/vcbuild/ldfpu.asm
257-
COMMENT "generate ldfpu.obj")
258-
list(APPEND FE_SRC
259-
${CMAKE_CURRENT_BINARY_DIR}/ldfpu.obj
260-
)
261-
endif()
247+
${PROJECT_SOURCE_DIR}/vcbuild/strtold.c)
262248
endif()
263249
set(LDC_SOURCE_FILES
264250
${LDC_GENERATED}
@@ -338,6 +324,26 @@ else()
338324
set(EXTRA_CXXFLAGS "-fexceptions")
339325
endif()
340326

327+
#
328+
# check string functions
329+
#
330+
check_symbol_exists(memicmp "string.h" HAVE_MEMICMP)
331+
check_symbol_exists(stricmp "string.h" HAVE_STRICMP)
332+
check_symbol_exists(strupr "string.h" HAVE_STRUPR)
333+
334+
if(HAVE_MEMICMP)
335+
add_definitions(-DHAVE_MEMICMP)
336+
endif()
337+
338+
if(HAVE_STRICMP)
339+
add_definitions(-DHAVE_STRICMP)
340+
endif()
341+
342+
if(HAVE_STRUPR)
343+
add_definitions(-DHAVE_STRUPR)
344+
endif()
345+
346+
341347
#
342348
# Check endianess.
343349
# There is no realiable way to delegate the work to the compiler.
@@ -472,7 +478,6 @@ get_target_property(GEN_GCCBUILTINS_LOC gen_gccbuiltins LOCATION)
472478
#
473479
# LDMD
474480
#
475-
include(CheckSymbolExists)
476481
CHECK_SYMBOL_EXISTS(_SC_ARG_MAX "unistd.h" HAVE_SC_ARG_MAX)
477482
if (HAVE_SC_ARG_MAX)
478483
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)