Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional ICC-only support for using long doubles on Win32 #16264

Open
p5pRT opened this issue Nov 21, 2017 · 2 comments
Open

Add optional ICC-only support for using long doubles on Win32 #16264

p5pRT opened this issue Nov 21, 2017 · 2 comments
Labels
distro-mswin32 longdouble-builds -Duselongdouble related failures type-core

Comments

@p5pRT
Copy link

p5pRT commented Nov 21, 2017

Migrated from rt.perl.org#132478 (status was 'new')

Searchable as RT132478$

@p5pRT
Copy link
Author

p5pRT commented Nov 21, 2017

From @steve-m-hay

Created by @steve-m-hay

The attached patch by bulk88 taken from
https://rt-archive.perl.org/perl5/Ticket/Display.html?id=123113
is a work in progress to add optional ICC (Intel C++ Compiler) support
for "long doubles"
on Windows.

See the following entries on that ticket for further details​:

https://rt-archive.perl.org/perl5/Ticket/Display.html?id=123113#txn-1316983
https://rt-archive.perl.org/perl5/Ticket/Display.html?id=123113#txn-1316988

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.27.7:

Configured by shay at Tue Nov 21 13:25:42 2017.

Summary of my perl5 (revision 5 version 27 subversion 7) configuration:

  Platform:
    osname=MSWin32
    osvers=6.3.9600
    archname=MSWin32-x86-multi-thread-ld
    uname=''
    config_args='undef'
    hint=recommended
    useposix=true
    d_sigaction=undef
    useithreads=define
    usemultiplicity=define
    use64bitint=undef
    use64bitall=undef
    uselongdouble=define
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='gcc'
    ccflags =' -s -O2 -DWIN32  -DPERL_TEXTMODE_SCRIPTS
-DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -D__USE_MINGW_ANSI_STDIO
-fwrapv -fno-strict-aliasing -mms-bitfields'
    optimize='-s -O2'
    cppflags='-DWIN32'
    ccversion=''
    gccversion='7.1.0'
    gccosandvers=''
    intsize=4
    longsize=4
    ptrsize=4
    doublesize=8
    byteorder=1234
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=12
    longdblkind=3
    ivtype='long'
    ivsize=4
    nvtype='long double'
    nvsize=12
    Off_t='long long'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='g++'
    ldflags ='-s -L"c:\perl\lib\CORE"
-L"C:\Dev\Software\MinGW-w64\x86\7.1.0\lib"'
    libpth=C:\Dev\Software\MinGW-w64\x86\7.1.0\lib
    libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32
-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32
-lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool
-lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid
-lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    libc=
    so=dll
    useshrplib=true
    libperl=libperl527.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs
    dlext=dll
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags='-mdll -s -L"c:\perl\lib\CORE"
-L"C:\Dev\Software\MinGW-w64\x86\7.1.0\lib"'



@INC for perl 5.27.7:
    C:/perl/site/lib
    C:/perl/lib


Environment for perl 5.27.7:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\Dev\Software\MinGW-w64\x86\7.1.0\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32\wbem;C:\perl\bin
    PERL_BADLANG (unset)
    SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Nov 21, 2017

From @steve-m-hay

0001-icc-longdouble-wip.patch
From 6d149aa0e5feff84216d4da035c7f1b2278e81bc Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Thu, 9 Jan 2014 03:10:40 -0500
Subject: [PATCH] icc longdouble wip

---
 generate_uudmap.c |  2 ++
 perl.h            | 12 ++++++++++++
 uconfig.h         |  8 ++++----
 util.c            |  9 +++++++--
 win32/Makefile    | 10 +++++-----
 win32/config.vc   | 18 +++++++++---------
 win32/config_H.vc | 30 +++++++++++++++---------------
 7 files changed, 54 insertions(+), 35 deletions(-)

diff --git a/generate_uudmap.c b/generate_uudmap.c
index b6307c0..b72f374 100644
--- a/generate_uudmap.c
+++ b/generate_uudmap.c
@@ -108,6 +108,8 @@ int main(int argc, char **argv) {
   int bits;
   struct mg_data_raw_t *p = mg_data_raw;
 
+    fprintf(stderr, "sizeof ld %d\n", sizeof(long double));
+
   if (argc < 4 || argv[1][0] == '\0' || argv[2][0] == '\0'
       || argv[3][0] == '\0') {
     fprintf(stderr, "Usage: %s uudemap.h bitcount.h mg_data.h\n", argv[0]);
diff --git a/perl.h b/perl.h
index b6e0c3e..6c7d5bd 100644
--- a/perl.h
+++ b/perl.h
@@ -1671,6 +1671,7 @@ typedef UVTYPE UV;
 #  endif
 #  if !(defined(HAS_LONG_DOUBLE) && (LONG_DOUBLESIZE > DOUBLESIZE))
 #     undef USE_LONG_DOUBLE /* Ouch! */
+      #error undefed ULD
 #  endif
 #endif
 
@@ -1763,10 +1764,15 @@ typedef NVTYPE NV;
 #   include <ieeefp.h>
 #endif
 
+#ifndef USE_LONG_DOUBLE
+#error no LD
+#endif
+
 #ifdef USE_LONG_DOUBLE
 #   ifdef I_SUNMATH
 #       include <sunmath.h>
 #   endif
+#   include <mathimf.h>
 #   define NV_DIG LDBL_DIG
 #   ifdef LDBL_MANT_DIG
 #       define NV_MANT_DIG LDBL_MANT_DIG
@@ -1798,6 +1804,7 @@ typedef NVTYPE NV;
 #           endif
 #       endif
 #   endif
+
 #   ifdef HAS_SQRTL
 #       define Perl_cos cosl
 #       define Perl_sin sinl
@@ -1843,6 +1850,7 @@ EXTERN_C long double modfl(long double, long double *);
 #       endif
 #   endif
 #else
+#error die
 #   define NV_DIG DBL_DIG
 #   ifdef DBL_MANT_DIG
 #       define NV_MANT_DIG DBL_MANT_DIG
@@ -5833,6 +5841,10 @@ extern void moncontrol(int);
 
 */
 
+#ifndef HAS_SQRTL
+#error no long
+#endif
+
 #endif /* Include guard */
 
 /*
diff --git a/uconfig.h b/uconfig.h
index 8e728ab..e29fabd 100644
--- a/uconfig.h
+++ b/uconfig.h
@@ -4361,10 +4361,10 @@
  *	This symbol, if defined, contains the string used by stdio to
  *	format long doubles (format 'f') for input.
  */
-/*#define PERL_PRIfldbl	"llf"	/ **/
-/*#define PERL_PRIgldbl	"llg"	/ **/
-/*#define PERL_PRIeldbl	"lle"	/ **/
-/*#define PERL_SCNfldbl	"llf"	/ **/
+#define PERL_PRIfldbl	"llf"	/ **/
+#define PERL_PRIgldbl	"llg"	/ **/
+#define PERL_PRIeldbl	"lle"	/ **/
+#define PERL_SCNfldbl	"llf"	/ **/
 
 /* PERL_MAD:
  *	This symbol, if defined, indicates that the Misc Attribution
diff --git a/util.c b/util.c
index f308e93..455b7bb 100644
--- a/util.c
+++ b/util.c
@@ -4769,10 +4769,12 @@ Perl_my_snprintf(char *buffer, const Size_t len, const char *format, ...)
 {
     int retval;
     va_list ap;
+    restart:
     PERL_ARGS_ASSERT_MY_SNPRINTF;
     va_start(ap, format);
+    memset(buffer, 0, len);
 #ifdef HAS_VSNPRINTF
-    retval = vsnprintf(buffer, len, format, ap);
+    retval = ___mingw_vsnprintf(buffer, len, format, ap);
 #else
     retval = vsprintf(buffer, format, ap);
 #endif
@@ -4784,8 +4786,11 @@ Perl_my_snprintf(char *buffer, const Size_t len, const char *format, ...)
         ||
         (len > 0 && (Size_t)retval >= len) 
 #endif
-    )
+    ) {
+	DebugBreak();
+	goto restart;
 	Perl_croak_nocontext("panic: my_snprintf buffer overflow");
+    }
     return retval;
 }
 
diff --git a/win32/Makefile b/win32/Makefile
index 885f8ce..2c90bef 100644
--- a/win32/Makefile
+++ b/win32/Makefile
@@ -134,14 +134,14 @@ CCTYPE		= MSVC90
 #
 # If you are using Intel C++ Compiler uncomment this
 #
-#__ICC		= define
+__ICC		= define
 
 #
 # uncomment next line if you want debug version of perl (big,slow)
 # If not enabled, we automatically try to use maximum optimization
 # with all compilers that are known to have a working optimizer.
 #
-#CFG		= Debug
+CFG		= Debug
 
 #
 # uncomment to enable linking with setargv.obj under the Visual C
@@ -443,10 +443,10 @@ LOCDEFS		= -DPERLDLL -DPERL_CORE
 SUBSYS		= console
 CXX_FLAG	= -TP -EHsc
 
-LIBC	= msvcrt.lib
+LIBC	= msvcrtd.lib
 
 !IF  "$(CFG)" == "Debug"
-OPTIMIZE	= -Od -MD -Zi -DDEBUGGING
+OPTIMIZE	= -Od -MDd -Zi -DDEBUGGING
 LINK_DBG	= -debug
 !ELSE
 # -O1 yields smaller code, which turns out to be faster than -O2 on x86 and x64
@@ -517,7 +517,7 @@ LIBBASEFILES    = $(LIBBASEFILES) bufferoverflowU.lib
 LIBFILES	= $(LIBBASEFILES) $(LIBC)
 
 #EXTRACFLAGS	= -nologo -GF -W4 -wd4127 -wd4706
-EXTRACFLAGS	= -nologo -GF -W3
+EXTRACFLAGS	= -nologo -GF -W3 /Qlong-double /Qpc80 -DUSE_LONG_DOUBLE -DHAS_LONG_DOUBLE
 CFLAGS		= $(EXTRACFLAGS) $(INCLUDES) $(DEFINES) $(LOCDEFS) \
 		$(PCHFLAGS) $(OPTIMIZE)
 LINK_FLAGS	= -nologo -nodefaultlib $(LINK_DBG) \
diff --git a/win32/config.vc b/win32/config.vc
index a15b926..bc90fd8 100644
--- a/win32/config.vc
+++ b/win32/config.vc
@@ -449,7 +449,7 @@ d_socklen_t='undef'
 d_sockpair='undef'
 d_socks5_init='undef'
 d_sprintf_returns_strlen='define'
-d_sqrtl='undef'
+d_sqrtl='define'
 d_srand48_r='undef'
 d_srandom_r='undef'
 d_sresgproto='undef'
@@ -828,16 +828,16 @@ nm_opt=''
 nm_so_opt=''
 nonxs_ext='Errno'
 nroff=''
-nvEUformat='"E"'
-nvFUformat='"F"'
-nvGUformat='"G"'
+nvEUformat='"LE"'
+nvFUformat='"LF"'
+nvGUformat='"LG"'
 nv_overflows_integers_at='256.0*256.0*256.0*256.0*256.0*256.0*2.0*2.0*2.0*2.0*2.0'
 nv_preserves_uv_bits='32'
-nveformat='"e"'
-nvfformat='"f"'
-nvgformat='"g"'
-nvsize='8'
-nvtype='double'
+nveformat='"Le"'
+nvfformat='"Lf"'
+nvgformat='"Lg"'
+nvsize='12'
+nvtype='long double'
 o_nonblock='O_NONBLOCK'
 obj_ext='.obj'
 old_pthread_create_joinable=''
diff --git a/win32/config_H.vc b/win32/config_H.vc
index f55a6d2..7f612f3 100644
--- a/win32/config_H.vc
+++ b/win32/config_H.vc
@@ -1930,9 +1930,9 @@
  *	C preprocessor can make decisions based on it.  It is only
  *	defined if the system supports long doubles.
  */
-#define HAS_LONG_DOUBLE		/**/
+/*#define HAS_LONG_DOUBLE		/**/
 #ifdef HAS_LONG_DOUBLE
-#define LONG_DOUBLESIZE 8		/**/
+#define LONG_DOUBLESIZE 16		/**/
 #endif
 
 /* HAS_LONG_LONG:
@@ -3558,7 +3558,7 @@
  *	available to break a long double floating-point number into
  *	a normalized fraction and an integral power of 2.
  */
-/*#define HAS_FREXPL		/ **/
+#define HAS_FREXPL
 
 /* HAS_STRUCT_FS_DATA:
  *	This symbol, if defined, indicates that the struct fs_data
@@ -3780,8 +3780,8 @@
  *	and 1.150000.  The bug has been seen in certain versions of glibc,
  *	release 2.2.2 is known to be okay.
  */
-/*#define HAS_MODFL		/ **/
-/*#define HAS_MODFL_PROTO		/ **/
+#define HAS_MODFL
+#define HAS_MODFL_PROTO
 /*#define HAS_MODFL_POW32_BUG		/ **/
 
 /* HAS_MPROTECT:
@@ -3954,7 +3954,7 @@
  *	This symbol, if defined, indicates that the sqrtl routine is
  *	available to do long double square roots.
  */
-/*#define HAS_SQRTL		/ **/
+#define HAS_SQRTL		/ **/
 
 /* HAS_SETRESGID_PROTO:
  *	This symbol, if defined, indicates that the system provides
@@ -4361,10 +4361,10 @@
  *	This symbol, if defined, contains the string used by stdio to
  *	format long doubles (format 'f') for input.
  */
-/*#define PERL_PRIfldbl	"f"	/ **/
-/*#define PERL_PRIgldbl	"g"	/ **/
-/*#define PERL_PRIeldbl	"e"	/ **/
-/*#define PERL_SCNfldbl	"f"	/ **/
+#define PERL_PRIfldbl	"f"
+#define PERL_PRIgldbl	"g"
+#define PERL_PRIeldbl	"e"
+#define PERL_SCNfldbl	"f"
 
 /* PERL_MAD:
  *	This symbol, if defined, indicates that the Misc Attribution
@@ -4479,7 +4479,7 @@
 #define	I64TYPE		__int64	/**/
 #define	U64TYPE		unsigned __int64	/**/
 #endif
-#define	NVTYPE		double		/**/
+#define	NVTYPE		long double		/**/
 #define	IVSIZE		4		/**/
 #define	UVSIZE		4		/**/
 #define	I8SIZE		1		/**/
@@ -4492,7 +4492,7 @@
 #define	I64SIZE		8	/**/
 #define	U64SIZE		8	/**/
 #endif
-#define	NVSIZE		8		/**/
+#define	NVSIZE		12		/**/
 #define	NV_PRESERVES_UV
 #define	NV_PRESERVES_UV_BITS	32
 #define	NV_OVERFLOWS_INTEGERS_AT	256.0*256.0*256.0*256.0*256.0*256.0*2.0*2.0*2.0*2.0*2.0
@@ -4548,9 +4548,9 @@
 #define	UVof		"lo"		/**/
 #define	UVxf		"lx"		/**/
 #define	UVXf		"lX"		/**/
-#define	NVef		"e"		/**/
-#define	NVff		"f"		/**/
-#define	NVgf		"g"		/**/
+#define	NVef		"Le"		/**/
+#define	NVff		"Lf"		/**/
+#define	NVgf		"Lg"		/**/
 
 /* SELECT_MIN_BITS:
  *	This symbol holds the minimum number of bits operated by select.
-- 
1.8.0.msysgit.0

@jkeenan jkeenan added the longdouble-builds -Duselongdouble related failures label Jun 11, 2020
@xenu xenu removed the affects-5.27 label Nov 19, 2021
@xenu xenu removed the Severity Low label Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distro-mswin32 longdouble-builds -Duselongdouble related failures type-core
Projects
None yet
Development

No branches or pull requests

3 participants