diff options
author | Ian Lance Taylor <iant@golang.org> | 2021-02-12 11:38:19 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-02-12 11:38:19 -0800 |
commit | 89d7be42db00cd0953e7d4584877cf50a56ed046 (patch) | |
tree | 3a471e8ee60b7be687ab7501f70379618adcf174 /libphobos | |
parent | 305e9d2c7815e90a29bbde1e3a7cd776861f4d7c (diff) | |
parent | 9769564e7456453e2273071d0faa5aab2554ff78 (diff) | |
download | gcc-89d7be42db00cd0953e7d4584877cf50a56ed046.zip gcc-89d7be42db00cd0953e7d4584877cf50a56ed046.tar.gz gcc-89d7be42db00cd0953e7d4584877cf50a56ed046.tar.bz2 |
Merge from trunk revision 9769564e7456453e2273071d0faa5aab2554ff78.
Diffstat (limited to 'libphobos')
47 files changed, 3383 insertions, 1130 deletions
diff --git a/libphobos/ChangeLog b/libphobos/ChangeLog index 43e5c8e..235af5b 100644 --- a/libphobos/ChangeLog +++ b/libphobos/ChangeLog @@ -1,3 +1,33 @@ +2021-02-04 Iain Buclaw <ibuclaw@gdcproject.org> + + PR d/98910 + * libdruntime/MERGE: Merge upstream druntime 0fd4364c. + * libdruntime/Makefile.am (DRUNTIME_DSOURCES): Add core/volatile.d. + * libdruntime/Makefile.in: Regenerate. + * testsuite/libphobos.allocations/tls_gc_integration.d: Update test. + +2021-02-03 Iain Buclaw <ibuclaw@gdcproject.org> + + PR d/98910 + * libdruntime/MERGE: Merge upstream druntime 9d0c8364. + * libdruntime/Makefile.am (DRUNTIME_DSOURCES): Add + core/internal/attributes.d + (DRUNTIME_DSOURCES_BIONIC): Add core/sys/bionic/stdlib.d. + (DRUNTIME_DSOURCES_DARWIN): Add core/sys/darwin/stdlib.d, and + core/sys/darwin/sys/sysctl.d. + (DRUNTIME_DSOURCES_DRAGONFLYBSD): Add + core/sys/dragonflybsd/stdlib.d, and + core/sys/dragonflybsd/sys/sysctl.d. + (DRUNTIME_DSOURCES_FREEBSD): Add core/sys/freebsd/stdlib.d, and + core/sys/freebsd/sys/sysctl.d. + (DRUNTIME_DSOURCES_NETBSD): Add core/sys/netbsd/stdlib.d, and + core/sys/netbsd/sys/sysctl.d. + (DRUNTIME_DSOURCES_OPENBSD): Add core/sys/openbsd/stdlib.d, and + core/sys/openbsd/sys/sysctl.d. + (DRUNTIME_DSOURCES_SOLARIS): Add core/sys/solaris/stdlib.d. + * libdruntime/Makefile.in: Regenerate. + * src/MERGE: Merge upstream phobos 9d575282e. + 2021-01-30 Iain Buclaw <ibuclaw@gdcproject.org> * Makefile.in: Regenerate. diff --git a/libphobos/libdruntime/MERGE b/libphobos/libdruntime/MERGE index 4654e58..a4a9a94 100644 --- a/libphobos/libdruntime/MERGE +++ b/libphobos/libdruntime/MERGE @@ -1,4 +1,4 @@ -e4aae28e36c118f13e346a61af6c413aadd8e838 +0fd4364c4a4eb2ce0ebb8f613092c5bed7a63bf9 The first line of this file holds the git revision number of the last merge done from the dlang/druntime repository. diff --git a/libphobos/libdruntime/Makefile.am b/libphobos/libdruntime/Makefile.am index 57de872..945271e 100644 --- a/libphobos/libdruntime/Makefile.am +++ b/libphobos/libdruntime/Makefile.am @@ -166,7 +166,8 @@ DRUNTIME_CSOURCES = core/stdc/errno_.c DRUNTIME_DSOURCES = core/atomic.d core/attribute.d core/bitop.d \ core/checkedint.d core/cpuid.d core/demangle.d core/exception.d \ - core/internal/abort.d core/internal/arrayop.d core/internal/convert.d \ + core/internal/abort.d core/internal/arrayop.d \ + core/internal/attributes.d core/internal/convert.d \ core/internal/hash.d core/internal/spinlock.d core/internal/string.d \ core/internal/traits.d core/math.d core/memory.d core/runtime.d \ core/simd.d core/stdc/assert_.d core/stdc/complex.d core/stdc/config.d \ @@ -181,28 +182,29 @@ DRUNTIME_DSOURCES = core/atomic.d core/attribute.d core/bitop.d \ core/sync/rwmutex.d core/sync/semaphore.d core/thread/context.d \ core/thread/fiber.d core/thread/osthread.d core/thread/package.d \ core/thread/threadbase.d core/thread/threadgroup.d core/thread/types.d \ - core/time.d core/vararg.d gc/bits.d gc/config.d gc/gcinterface.d \ - gc/impl/conservative/gc.d gc/impl/manual/gc.d gc/os.d gc/pooltable.d \ - gc/proxy.d gcc/attribute.d gcc/backtrace.d gcc/builtins.d gcc/deh.d \ - gcc/emutls.d gcc/gthread.d gcc/sections/android.d \ - gcc/sections/elf_shared.d gcc/sections/osx.d gcc/sections/package.d \ - gcc/sections/win32.d gcc/sections/win64.d gcc/unwind/arm.d \ - gcc/unwind/arm_common.d gcc/unwind/c6x.d gcc/unwind/generic.d \ - gcc/unwind/package.d gcc/unwind/pe.d object.d rt/aApply.d rt/aApplyR.d \ - rt/aaA.d rt/adi.d rt/arrayassign.d rt/arraycast.d rt/arraycat.d \ - rt/cast_.d rt/config.d rt/critical_.d rt/deh.d rt/dmain2.d \ - rt/invariant.d rt/lifetime.d rt/memory.d rt/minfo.d rt/monitor_.d \ - rt/obj.d rt/qsort.d rt/sections.d rt/switch_.d rt/tlsgc.d \ - rt/util/array.d rt/util/container/array.d rt/util/container/common.d \ - rt/util/container/hashtab.d rt/util/container/treap.d rt/util/random.d \ - rt/util/typeinfo.d rt/util/utf.d + core/time.d core/vararg.d core/volatile.d gc/bits.d gc/config.d \ + gc/gcinterface.d gc/impl/conservative/gc.d gc/impl/manual/gc.d gc/os.d \ + gc/pooltable.d gc/proxy.d gcc/attribute.d gcc/backtrace.d \ + gcc/builtins.d gcc/deh.d gcc/emutls.d gcc/gthread.d \ + gcc/sections/android.d gcc/sections/elf_shared.d gcc/sections/osx.d \ + gcc/sections/package.d gcc/sections/win32.d gcc/sections/win64.d \ + gcc/unwind/arm.d gcc/unwind/arm_common.d gcc/unwind/c6x.d \ + gcc/unwind/generic.d gcc/unwind/package.d gcc/unwind/pe.d object.d \ + rt/aApply.d rt/aApplyR.d rt/aaA.d rt/adi.d rt/arrayassign.d \ + rt/arraycast.d rt/arraycat.d rt/cast_.d rt/config.d rt/critical_.d \ + rt/deh.d rt/dmain2.d rt/invariant.d rt/lifetime.d rt/memory.d \ + rt/minfo.d rt/monitor_.d rt/obj.d rt/qsort.d rt/sections.d \ + rt/switch_.d rt/tlsgc.d rt/util/array.d rt/util/container/array.d \ + rt/util/container/common.d rt/util/container/hashtab.d \ + rt/util/container/treap.d rt/util/random.d rt/util/typeinfo.d \ + rt/util/utf.d DRUNTIME_DSOURCES_STDCXX = core/stdcpp/exception.d \ core/stdcpp/typeinfo.d DRUNTIME_DSOURCES_BIONIC = core/sys/bionic/err.d \ - core/sys/bionic/fcntl.d core/sys/bionic/string.d \ - core/sys/bionic/unistd.d + core/sys/bionic/fcntl.d core/sys/bionic/stdlib.d \ + core/sys/bionic/string.d core/sys/bionic/unistd.d DRUNTIME_DSOURCES_DARWIN = core/sys/darwin/crt_externs.d \ core/sys/darwin/dlfcn.d core/sys/darwin/err.d \ @@ -212,32 +214,35 @@ DRUNTIME_DSOURCES_DARWIN = core/sys/darwin/crt_externs.d \ core/sys/darwin/mach/nlist.d core/sys/darwin/mach/port.d \ core/sys/darwin/mach/semaphore.d core/sys/darwin/mach/stab.d \ core/sys/darwin/mach/thread_act.d core/sys/darwin/netinet/in_.d \ - core/sys/darwin/pthread.d core/sys/darwin/string.d \ - core/sys/darwin/sys/attr.d core/sys/darwin/sys/cdefs.d \ - core/sys/darwin/sys/event.d core/sys/darwin/sys/mman.d + core/sys/darwin/pthread.d core/sys/darwin/stdlib.d \ + core/sys/darwin/string.d core/sys/darwin/sys/attr.d \ + core/sys/darwin/sys/cdefs.d core/sys/darwin/sys/event.d \ + core/sys/darwin/sys/mman.d core/sys/darwin/sys/sysctl.d DRUNTIME_DSOURCES_DRAGONFLYBSD = core/sys/dragonflybsd/dlfcn.d \ core/sys/dragonflybsd/err.d core/sys/dragonflybsd/execinfo.d \ core/sys/dragonflybsd/netinet/in_.d core/sys/dragonflybsd/pthread_np.d \ - core/sys/dragonflybsd/string.d core/sys/dragonflybsd/sys/_bitset.d \ + core/sys/dragonflybsd/stdlib.d core/sys/dragonflybsd/string.d \ + core/sys/dragonflybsd/sys/_bitset.d \ core/sys/dragonflybsd/sys/_cpuset.d core/sys/dragonflybsd/sys/cdefs.d \ core/sys/dragonflybsd/sys/elf.d core/sys/dragonflybsd/sys/elf32.d \ core/sys/dragonflybsd/sys/elf64.d \ core/sys/dragonflybsd/sys/elf_common.d \ core/sys/dragonflybsd/sys/event.d core/sys/dragonflybsd/sys/link_elf.d \ core/sys/dragonflybsd/sys/mman.d core/sys/dragonflybsd/sys/socket.d \ - core/sys/dragonflybsd/time.d + core/sys/dragonflybsd/sys/sysctl.d core/sys/dragonflybsd/time.d DRUNTIME_DSOURCES_FREEBSD = core/sys/freebsd/config.d \ core/sys/freebsd/dlfcn.d core/sys/freebsd/err.d \ core/sys/freebsd/execinfo.d core/sys/freebsd/netinet/in_.d \ - core/sys/freebsd/pthread_np.d core/sys/freebsd/string.d \ - core/sys/freebsd/sys/_bitset.d core/sys/freebsd/sys/_cpuset.d \ - core/sys/freebsd/sys/cdefs.d core/sys/freebsd/sys/elf.d \ - core/sys/freebsd/sys/elf32.d core/sys/freebsd/sys/elf64.d \ - core/sys/freebsd/sys/elf_common.d core/sys/freebsd/sys/event.d \ - core/sys/freebsd/sys/link_elf.d core/sys/freebsd/sys/mman.d \ - core/sys/freebsd/sys/mount.d core/sys/freebsd/time.d \ + core/sys/freebsd/pthread_np.d core/sys/freebsd/stdlib.d \ + core/sys/freebsd/string.d core/sys/freebsd/sys/_bitset.d \ + core/sys/freebsd/sys/_cpuset.d core/sys/freebsd/sys/cdefs.d \ + core/sys/freebsd/sys/elf.d core/sys/freebsd/sys/elf32.d \ + core/sys/freebsd/sys/elf64.d core/sys/freebsd/sys/elf_common.d \ + core/sys/freebsd/sys/event.d core/sys/freebsd/sys/link_elf.d \ + core/sys/freebsd/sys/mman.d core/sys/freebsd/sys/mount.d \ + core/sys/freebsd/sys/sysctl.d core/sys/freebsd/time.d \ core/sys/freebsd/unistd.d DRUNTIME_DSOURCES_LINUX = core/sys/linux/config.d \ @@ -257,18 +262,20 @@ DRUNTIME_DSOURCES_LINUX = core/sys/linux/config.d \ DRUNTIME_DSOURCES_NETBSD = core/sys/netbsd/dlfcn.d \ core/sys/netbsd/err.d core/sys/netbsd/execinfo.d \ - core/sys/netbsd/string.d core/sys/netbsd/sys/elf.d \ - core/sys/netbsd/sys/elf32.d core/sys/netbsd/sys/elf64.d \ - core/sys/netbsd/sys/elf_common.d core/sys/netbsd/sys/event.d \ - core/sys/netbsd/sys/featuretest.d core/sys/netbsd/sys/link_elf.d \ - core/sys/netbsd/sys/mman.d core/sys/netbsd/time.d + core/sys/netbsd/stdlib.d core/sys/netbsd/string.d \ + core/sys/netbsd/sys/elf.d core/sys/netbsd/sys/elf32.d \ + core/sys/netbsd/sys/elf64.d core/sys/netbsd/sys/elf_common.d \ + core/sys/netbsd/sys/event.d core/sys/netbsd/sys/featuretest.d \ + core/sys/netbsd/sys/link_elf.d core/sys/netbsd/sys/mman.d \ + core/sys/netbsd/sys/sysctl.d core/sys/netbsd/time.d DRUNTIME_DSOURCES_OPENBSD = core/sys/openbsd/dlfcn.d \ - core/sys/openbsd/err.d core/sys/openbsd/string.d \ - core/sys/openbsd/sys/cdefs.d core/sys/openbsd/sys/elf.d \ - core/sys/openbsd/sys/elf32.d core/sys/openbsd/sys/elf64.d \ - core/sys/openbsd/sys/elf_common.d core/sys/openbsd/sys/link_elf.d \ - core/sys/openbsd/sys/mman.d core/sys/openbsd/time.d + core/sys/openbsd/err.d core/sys/openbsd/stdlib.d \ + core/sys/openbsd/string.d core/sys/openbsd/sys/cdefs.d \ + core/sys/openbsd/sys/elf.d core/sys/openbsd/sys/elf32.d \ + core/sys/openbsd/sys/elf64.d core/sys/openbsd/sys/elf_common.d \ + core/sys/openbsd/sys/link_elf.d core/sys/openbsd/sys/mman.d \ + core/sys/openbsd/sys/sysctl.d core/sys/openbsd/time.d DRUNTIME_DSOURCES_POSIX = core/sys/posix/aio.d \ core/sys/posix/arpa/inet.d core/sys/posix/config.d \ @@ -300,12 +307,13 @@ DRUNTIME_DSOURCES_POSIX = core/sys/posix/aio.d \ DRUNTIME_DSOURCES_SOLARIS = core/sys/solaris/dlfcn.d \ core/sys/solaris/elf.d core/sys/solaris/err.d \ core/sys/solaris/execinfo.d core/sys/solaris/libelf.d \ - core/sys/solaris/link.d core/sys/solaris/sys/elf.d \ - core/sys/solaris/sys/elf_386.d core/sys/solaris/sys/elf_SPARC.d \ - core/sys/solaris/sys/elf_amd64.d core/sys/solaris/sys/elf_notes.d \ - core/sys/solaris/sys/elftypes.d core/sys/solaris/sys/link.d \ - core/sys/solaris/sys/priocntl.d core/sys/solaris/sys/procset.d \ - core/sys/solaris/sys/types.d core/sys/solaris/time.d + core/sys/solaris/link.d core/sys/solaris/stdlib.d \ + core/sys/solaris/sys/elf.d core/sys/solaris/sys/elf_386.d \ + core/sys/solaris/sys/elf_SPARC.d core/sys/solaris/sys/elf_amd64.d \ + core/sys/solaris/sys/elf_notes.d core/sys/solaris/sys/elftypes.d \ + core/sys/solaris/sys/link.d core/sys/solaris/sys/priocntl.d \ + core/sys/solaris/sys/procset.d core/sys/solaris/sys/types.d \ + core/sys/solaris/time.d DRUNTIME_DSOURCES_WINDOWS = core/sys/windows/accctrl.d \ core/sys/windows/aclapi.d core/sys/windows/aclui.d \ diff --git a/libphobos/libdruntime/Makefile.in b/libphobos/libdruntime/Makefile.in index e1b0a85..06c0296 100644 --- a/libphobos/libdruntime/Makefile.in +++ b/libphobos/libdruntime/Makefile.in @@ -188,25 +188,26 @@ am__dirstamp = $(am__leading_dot)dirstamp am__objects_1 = core/atomic.lo core/attribute.lo core/bitop.lo \ core/checkedint.lo core/cpuid.lo core/demangle.lo \ core/exception.lo core/internal/abort.lo \ - core/internal/arrayop.lo core/internal/convert.lo \ - core/internal/hash.lo core/internal/spinlock.lo \ - core/internal/string.lo core/internal/traits.lo core/math.lo \ - core/memory.lo core/runtime.lo core/simd.lo \ - core/stdc/assert_.lo core/stdc/complex.lo core/stdc/config.lo \ - core/stdc/ctype.lo core/stdc/errno.lo core/stdc/fenv.lo \ - core/stdc/float_.lo core/stdc/inttypes.lo core/stdc/limits.lo \ - core/stdc/locale.lo core/stdc/math.lo core/stdc/signal.lo \ - core/stdc/stdarg.lo core/stdc/stddef.lo core/stdc/stdint.lo \ - core/stdc/stdio.lo core/stdc/stdlib.lo core/stdc/string.lo \ - core/stdc/tgmath.lo core/stdc/time.lo core/stdc/wchar_.lo \ - core/stdc/wctype.lo core/sync/barrier.lo \ - core/sync/condition.lo core/sync/config.lo \ - core/sync/exception.lo core/sync/mutex.lo core/sync/rwmutex.lo \ - core/sync/semaphore.lo core/thread/context.lo \ - core/thread/fiber.lo core/thread/osthread.lo \ - core/thread/package.lo core/thread/threadbase.lo \ - core/thread/threadgroup.lo core/thread/types.lo core/time.lo \ - core/vararg.lo gc/bits.lo gc/config.lo gc/gcinterface.lo \ + core/internal/arrayop.lo core/internal/attributes.lo \ + core/internal/convert.lo core/internal/hash.lo \ + core/internal/spinlock.lo core/internal/string.lo \ + core/internal/traits.lo core/math.lo core/memory.lo \ + core/runtime.lo core/simd.lo core/stdc/assert_.lo \ + core/stdc/complex.lo core/stdc/config.lo core/stdc/ctype.lo \ + core/stdc/errno.lo core/stdc/fenv.lo core/stdc/float_.lo \ + core/stdc/inttypes.lo core/stdc/limits.lo core/stdc/locale.lo \ + core/stdc/math.lo core/stdc/signal.lo core/stdc/stdarg.lo \ + core/stdc/stddef.lo core/stdc/stdint.lo core/stdc/stdio.lo \ + core/stdc/stdlib.lo core/stdc/string.lo core/stdc/tgmath.lo \ + core/stdc/time.lo core/stdc/wchar_.lo core/stdc/wctype.lo \ + core/sync/barrier.lo core/sync/condition.lo \ + core/sync/config.lo core/sync/exception.lo core/sync/mutex.lo \ + core/sync/rwmutex.lo core/sync/semaphore.lo \ + core/thread/context.lo core/thread/fiber.lo \ + core/thread/osthread.lo core/thread/package.lo \ + core/thread/threadbase.lo core/thread/threadgroup.lo \ + core/thread/types.lo core/time.lo core/vararg.lo \ + core/volatile.lo gc/bits.lo gc/config.lo gc/gcinterface.lo \ gc/impl/conservative/gc.lo gc/impl/manual/gc.lo gc/os.lo \ gc/pooltable.lo gc/proxy.lo gcc/attribute.lo gcc/backtrace.lo \ gcc/builtins.lo gcc/deh.lo gcc/emutls.lo gcc/gthread.lo \ @@ -263,14 +264,16 @@ am__objects_5 = core/sys/darwin/crt_externs.lo \ core/sys/darwin/mach/stab.lo \ core/sys/darwin/mach/thread_act.lo \ core/sys/darwin/netinet/in_.lo core/sys/darwin/pthread.lo \ - core/sys/darwin/string.lo core/sys/darwin/sys/attr.lo \ - core/sys/darwin/sys/cdefs.lo core/sys/darwin/sys/event.lo \ - core/sys/darwin/sys/mman.lo + core/sys/darwin/stdlib.lo core/sys/darwin/string.lo \ + core/sys/darwin/sys/attr.lo core/sys/darwin/sys/cdefs.lo \ + core/sys/darwin/sys/event.lo core/sys/darwin/sys/mman.lo \ + core/sys/darwin/sys/sysctl.lo @DRUNTIME_OS_DARWIN_TRUE@am__objects_6 = $(am__objects_5) am__objects_7 = core/sys/dragonflybsd/dlfcn.lo \ core/sys/dragonflybsd/err.lo core/sys/dragonflybsd/execinfo.lo \ core/sys/dragonflybsd/netinet/in_.lo \ core/sys/dragonflybsd/pthread_np.lo \ + core/sys/dragonflybsd/stdlib.lo \ core/sys/dragonflybsd/string.lo \ core/sys/dragonflybsd/sys/_bitset.lo \ core/sys/dragonflybsd/sys/_cpuset.lo \ @@ -283,39 +286,43 @@ am__objects_7 = core/sys/dragonflybsd/dlfcn.lo \ core/sys/dragonflybsd/sys/link_elf.lo \ core/sys/dragonflybsd/sys/mman.lo \ core/sys/dragonflybsd/sys/socket.lo \ + core/sys/dragonflybsd/sys/sysctl.lo \ core/sys/dragonflybsd/time.lo @DRUNTIME_OS_DRAGONFLYBSD_TRUE@am__objects_8 = $(am__objects_7) am__objects_9 = core/sys/bionic/err.lo core/sys/bionic/fcntl.lo \ - core/sys/bionic/string.lo core/sys/bionic/unistd.lo + core/sys/bionic/stdlib.lo core/sys/bionic/string.lo \ + core/sys/bionic/unistd.lo @DRUNTIME_OS_ANDROID_TRUE@am__objects_10 = $(am__objects_9) am__objects_11 = core/sys/freebsd/config.lo core/sys/freebsd/dlfcn.lo \ core/sys/freebsd/err.lo core/sys/freebsd/execinfo.lo \ core/sys/freebsd/netinet/in_.lo core/sys/freebsd/pthread_np.lo \ - core/sys/freebsd/string.lo core/sys/freebsd/sys/_bitset.lo \ + core/sys/freebsd/stdlib.lo core/sys/freebsd/string.lo \ + core/sys/freebsd/sys/_bitset.lo \ core/sys/freebsd/sys/_cpuset.lo core/sys/freebsd/sys/cdefs.lo \ core/sys/freebsd/sys/elf.lo core/sys/freebsd/sys/elf32.lo \ core/sys/freebsd/sys/elf64.lo \ core/sys/freebsd/sys/elf_common.lo \ core/sys/freebsd/sys/event.lo core/sys/freebsd/sys/link_elf.lo \ core/sys/freebsd/sys/mman.lo core/sys/freebsd/sys/mount.lo \ - core/sys/freebsd/time.lo core/sys/freebsd/unistd.lo + core/sys/freebsd/sys/sysctl.lo core/sys/freebsd/time.lo \ + core/sys/freebsd/unistd.lo @DRUNTIME_OS_FREEBSD_TRUE@am__objects_12 = $(am__objects_11) am__objects_13 = core/sys/netbsd/dlfcn.lo core/sys/netbsd/err.lo \ - core/sys/netbsd/execinfo.lo core/sys/netbsd/string.lo \ - core/sys/netbsd/sys/elf.lo core/sys/netbsd/sys/elf32.lo \ - core/sys/netbsd/sys/elf64.lo core/sys/netbsd/sys/elf_common.lo \ - core/sys/netbsd/sys/event.lo \ + core/sys/netbsd/execinfo.lo core/sys/netbsd/stdlib.lo \ + core/sys/netbsd/string.lo core/sys/netbsd/sys/elf.lo \ + core/sys/netbsd/sys/elf32.lo core/sys/netbsd/sys/elf64.lo \ + core/sys/netbsd/sys/elf_common.lo core/sys/netbsd/sys/event.lo \ core/sys/netbsd/sys/featuretest.lo \ core/sys/netbsd/sys/link_elf.lo core/sys/netbsd/sys/mman.lo \ - core/sys/netbsd/time.lo + core/sys/netbsd/sys/sysctl.lo core/sys/netbsd/time.lo @DRUNTIME_OS_NETBSD_TRUE@am__objects_14 = $(am__objects_13) am__objects_15 = core/sys/openbsd/dlfcn.lo core/sys/openbsd/err.lo \ - core/sys/openbsd/string.lo core/sys/openbsd/sys/cdefs.lo \ - core/sys/openbsd/sys/elf.lo core/sys/openbsd/sys/elf32.lo \ - core/sys/openbsd/sys/elf64.lo \ + core/sys/openbsd/stdlib.lo core/sys/openbsd/string.lo \ + core/sys/openbsd/sys/cdefs.lo core/sys/openbsd/sys/elf.lo \ + core/sys/openbsd/sys/elf32.lo core/sys/openbsd/sys/elf64.lo \ core/sys/openbsd/sys/elf_common.lo \ core/sys/openbsd/sys/link_elf.lo core/sys/openbsd/sys/mman.lo \ - core/sys/openbsd/time.lo + core/sys/openbsd/sys/sysctl.lo core/sys/openbsd/time.lo @DRUNTIME_OS_OPENBSD_TRUE@am__objects_16 = $(am__objects_15) am__objects_17 = core/sys/linux/config.lo core/sys/linux/dlfcn.lo \ core/sys/linux/elf.lo core/sys/linux/epoll.lo \ @@ -422,7 +429,8 @@ am__objects_19 = core/sys/windows/accctrl.lo \ am__objects_21 = core/sys/solaris/dlfcn.lo core/sys/solaris/elf.lo \ core/sys/solaris/err.lo core/sys/solaris/execinfo.lo \ core/sys/solaris/libelf.lo core/sys/solaris/link.lo \ - core/sys/solaris/sys/elf.lo core/sys/solaris/sys/elf_386.lo \ + core/sys/solaris/stdlib.lo core/sys/solaris/sys/elf.lo \ + core/sys/solaris/sys/elf_386.lo \ core/sys/solaris/sys/elf_SPARC.lo \ core/sys/solaris/sys/elf_amd64.lo \ core/sys/solaris/sys/elf_notes.lo \ @@ -784,7 +792,8 @@ libgdruntime_convenience_la_LINK = $(libgdruntime_la_LINK) DRUNTIME_CSOURCES = core/stdc/errno_.c DRUNTIME_DSOURCES = core/atomic.d core/attribute.d core/bitop.d \ core/checkedint.d core/cpuid.d core/demangle.d core/exception.d \ - core/internal/abort.d core/internal/arrayop.d core/internal/convert.d \ + core/internal/abort.d core/internal/arrayop.d \ + core/internal/attributes.d core/internal/convert.d \ core/internal/hash.d core/internal/spinlock.d core/internal/string.d \ core/internal/traits.d core/math.d core/memory.d core/runtime.d \ core/simd.d core/stdc/assert_.d core/stdc/complex.d core/stdc/config.d \ @@ -799,28 +808,29 @@ DRUNTIME_DSOURCES = core/atomic.d core/attribute.d core/bitop.d \ core/sync/rwmutex.d core/sync/semaphore.d core/thread/context.d \ core/thread/fiber.d core/thread/osthread.d core/thread/package.d \ core/thread/threadbase.d core/thread/threadgroup.d core/thread/types.d \ - core/time.d core/vararg.d gc/bits.d gc/config.d gc/gcinterface.d \ - gc/impl/conservative/gc.d gc/impl/manual/gc.d gc/os.d gc/pooltable.d \ - gc/proxy.d gcc/attribute.d gcc/backtrace.d gcc/builtins.d gcc/deh.d \ - gcc/emutls.d gcc/gthread.d gcc/sections/android.d \ - gcc/sections/elf_shared.d gcc/sections/osx.d gcc/sections/package.d \ - gcc/sections/win32.d gcc/sections/win64.d gcc/unwind/arm.d \ - gcc/unwind/arm_common.d gcc/unwind/c6x.d gcc/unwind/generic.d \ - gcc/unwind/package.d gcc/unwind/pe.d object.d rt/aApply.d rt/aApplyR.d \ - rt/aaA.d rt/adi.d rt/arrayassign.d rt/arraycast.d rt/arraycat.d \ - rt/cast_.d rt/config.d rt/critical_.d rt/deh.d rt/dmain2.d \ - rt/invariant.d rt/lifetime.d rt/memory.d rt/minfo.d rt/monitor_.d \ - rt/obj.d rt/qsort.d rt/sections.d rt/switch_.d rt/tlsgc.d \ - rt/util/array.d rt/util/container/array.d rt/util/container/common.d \ - rt/util/container/hashtab.d rt/util/container/treap.d rt/util/random.d \ - rt/util/typeinfo.d rt/util/utf.d + core/time.d core/vararg.d core/volatile.d gc/bits.d gc/config.d \ + gc/gcinterface.d gc/impl/conservative/gc.d gc/impl/manual/gc.d gc/os.d \ + gc/pooltable.d gc/proxy.d gcc/attribute.d gcc/backtrace.d \ + gcc/builtins.d gcc/deh.d gcc/emutls.d gcc/gthread.d \ + gcc/sections/android.d gcc/sections/elf_shared.d gcc/sections/osx.d \ + gcc/sections/package.d gcc/sections/win32.d gcc/sections/win64.d \ + gcc/unwind/arm.d gcc/unwind/arm_common.d gcc/unwind/c6x.d \ + gcc/unwind/generic.d gcc/unwind/package.d gcc/unwind/pe.d object.d \ + rt/aApply.d rt/aApplyR.d rt/aaA.d rt/adi.d rt/arrayassign.d \ + rt/arraycast.d rt/arraycat.d rt/cast_.d rt/config.d rt/critical_.d \ + rt/deh.d rt/dmain2.d rt/invariant.d rt/lifetime.d rt/memory.d \ + rt/minfo.d rt/monitor_.d rt/obj.d rt/qsort.d rt/sections.d \ + rt/switch_.d rt/tlsgc.d rt/util/array.d rt/util/container/array.d \ + rt/util/container/common.d rt/util/container/hashtab.d \ + rt/util/container/treap.d rt/util/random.d rt/util/typeinfo.d \ + rt/util/utf.d DRUNTIME_DSOURCES_STDCXX = core/stdcpp/exception.d \ core/stdcpp/typeinfo.d DRUNTIME_DSOURCES_BIONIC = core/sys/bionic/err.d \ - core/sys/bionic/fcntl.d core/sys/bionic/string.d \ - core/sys/bionic/unistd.d + core/sys/bionic/fcntl.d core/sys/bionic/stdlib.d \ + core/sys/bionic/string.d core/sys/bionic/unistd.d DRUNTIME_DSOURCES_DARWIN = core/sys/darwin/crt_externs.d \ core/sys/darwin/dlfcn.d core/sys/darwin/err.d \ @@ -830,32 +840,35 @@ DRUNTIME_DSOURCES_DARWIN = core/sys/darwin/crt_externs.d \ core/sys/darwin/mach/nlist.d core/sys/darwin/mach/port.d \ core/sys/darwin/mach/semaphore.d core/sys/darwin/mach/stab.d \ core/sys/darwin/mach/thread_act.d core/sys/darwin/netinet/in_.d \ - core/sys/darwin/pthread.d core/sys/darwin/string.d \ - core/sys/darwin/sys/attr.d core/sys/darwin/sys/cdefs.d \ - core/sys/darwin/sys/event.d core/sys/darwin/sys/mman.d + core/sys/darwin/pthread.d core/sys/darwin/stdlib.d \ + core/sys/darwin/string.d core/sys/darwin/sys/attr.d \ + core/sys/darwin/sys/cdefs.d core/sys/darwin/sys/event.d \ + core/sys/darwin/sys/mman.d core/sys/darwin/sys/sysctl.d DRUNTIME_DSOURCES_DRAGONFLYBSD = core/sys/dragonflybsd/dlfcn.d \ core/sys/dragonflybsd/err.d core/sys/dragonflybsd/execinfo.d \ core/sys/dragonflybsd/netinet/in_.d core/sys/dragonflybsd/pthread_np.d \ - core/sys/dragonflybsd/string.d core/sys/dragonflybsd/sys/_bitset.d \ + core/sys/dragonflybsd/stdlib.d core/sys/dragonflybsd/string.d \ + core/sys/dragonflybsd/sys/_bitset.d \ core/sys/dragonflybsd/sys/_cpuset.d core/sys/dragonflybsd/sys/cdefs.d \ core/sys/dragonflybsd/sys/elf.d core/sys/dragonflybsd/sys/elf32.d \ core/sys/dragonflybsd/sys/elf64.d \ core/sys/dragonflybsd/sys/elf_common.d \ core/sys/dragonflybsd/sys/event.d core/sys/dragonflybsd/sys/link_elf.d \ core/sys/dragonflybsd/sys/mman.d core/sys/dragonflybsd/sys/socket.d \ - core/sys/dragonflybsd/time.d + core/sys/dragonflybsd/sys/sysctl.d core/sys/dragonflybsd/time.d DRUNTIME_DSOURCES_FREEBSD = core/sys/freebsd/config.d \ core/sys/freebsd/dlfcn.d core/sys/freebsd/err.d \ core/sys/freebsd/execinfo.d core/sys/freebsd/netinet/in_.d \ - core/sys/freebsd/pthread_np.d core/sys/freebsd/string.d \ - core/sys/freebsd/sys/_bitset.d core/sys/freebsd/sys/_cpuset.d \ - core/sys/freebsd/sys/cdefs.d core/sys/freebsd/sys/elf.d \ - core/sys/freebsd/sys/elf32.d core/sys/freebsd/sys/elf64.d \ - core/sys/freebsd/sys/elf_common.d core/sys/freebsd/sys/event.d \ - core/sys/freebsd/sys/link_elf.d core/sys/freebsd/sys/mman.d \ - core/sys/freebsd/sys/mount.d core/sys/freebsd/time.d \ + core/sys/freebsd/pthread_np.d core/sys/freebsd/stdlib.d \ + core/sys/freebsd/string.d core/sys/freebsd/sys/_bitset.d \ + core/sys/freebsd/sys/_cpuset.d core/sys/freebsd/sys/cdefs.d \ + core/sys/freebsd/sys/elf.d core/sys/freebsd/sys/elf32.d \ + core/sys/freebsd/sys/elf64.d core/sys/freebsd/sys/elf_common.d \ + core/sys/freebsd/sys/event.d core/sys/freebsd/sys/link_elf.d \ + core/sys/freebsd/sys/mman.d core/sys/freebsd/sys/mount.d \ + core/sys/freebsd/sys/sysctl.d core/sys/freebsd/time.d \ core/sys/freebsd/unistd.d DRUNTIME_DSOURCES_LINUX = core/sys/linux/config.d \ @@ -875,18 +888,20 @@ DRUNTIME_DSOURCES_LINUX = core/sys/linux/config.d \ DRUNTIME_DSOURCES_NETBSD = core/sys/netbsd/dlfcn.d \ core/sys/netbsd/err.d core/sys/netbsd/execinfo.d \ - core/sys/netbsd/string.d core/sys/netbsd/sys/elf.d \ - core/sys/netbsd/sys/elf32.d core/sys/netbsd/sys/elf64.d \ - core/sys/netbsd/sys/elf_common.d core/sys/netbsd/sys/event.d \ - core/sys/netbsd/sys/featuretest.d core/sys/netbsd/sys/link_elf.d \ - core/sys/netbsd/sys/mman.d core/sys/netbsd/time.d + core/sys/netbsd/stdlib.d core/sys/netbsd/string.d \ + core/sys/netbsd/sys/elf.d core/sys/netbsd/sys/elf32.d \ + core/sys/netbsd/sys/elf64.d core/sys/netbsd/sys/elf_common.d \ + core/sys/netbsd/sys/event.d core/sys/netbsd/sys/featuretest.d \ + core/sys/netbsd/sys/link_elf.d core/sys/netbsd/sys/mman.d \ + core/sys/netbsd/sys/sysctl.d core/sys/netbsd/time.d DRUNTIME_DSOURCES_OPENBSD = core/sys/openbsd/dlfcn.d \ - core/sys/openbsd/err.d core/sys/openbsd/string.d \ - core/sys/openbsd/sys/cdefs.d core/sys/openbsd/sys/elf.d \ - core/sys/openbsd/sys/elf32.d core/sys/openbsd/sys/elf64.d \ - core/sys/openbsd/sys/elf_common.d core/sys/openbsd/sys/link_elf.d \ - core/sys/openbsd/sys/mman.d core/sys/openbsd/time.d + core/sys/openbsd/err.d core/sys/openbsd/stdlib.d \ + core/sys/openbsd/string.d core/sys/openbsd/sys/cdefs.d \ + core/sys/openbsd/sys/elf.d core/sys/openbsd/sys/elf32.d \ + core/sys/openbsd/sys/elf64.d core/sys/openbsd/sys/elf_common.d \ + core/sys/openbsd/sys/link_elf.d core/sys/openbsd/sys/mman.d \ + core/sys/openbsd/sys/sysctl.d core/sys/openbsd/time.d DRUNTIME_DSOURCES_POSIX = core/sys/posix/aio.d \ core/sys/posix/arpa/inet.d core/sys/posix/config.d \ @@ -918,12 +933,13 @@ DRUNTIME_DSOURCES_POSIX = core/sys/posix/aio.d \ DRUNTIME_DSOURCES_SOLARIS = core/sys/solaris/dlfcn.d \ core/sys/solaris/elf.d core/sys/solaris/err.d \ core/sys/solaris/execinfo.d core/sys/solaris/libelf.d \ - core/sys/solaris/link.d core/sys/solaris/sys/elf.d \ - core/sys/solaris/sys/elf_386.d core/sys/solaris/sys/elf_SPARC.d \ - core/sys/solaris/sys/elf_amd64.d core/sys/solaris/sys/elf_notes.d \ - core/sys/solaris/sys/elftypes.d core/sys/solaris/sys/link.d \ - core/sys/solaris/sys/priocntl.d core/sys/solaris/sys/procset.d \ - core/sys/solaris/sys/types.d core/sys/solaris/time.d + core/sys/solaris/link.d core/sys/solaris/stdlib.d \ + core/sys/solaris/sys/elf.d core/sys/solaris/sys/elf_386.d \ + core/sys/solaris/sys/elf_SPARC.d core/sys/solaris/sys/elf_amd64.d \ + core/sys/solaris/sys/elf_notes.d core/sys/solaris/sys/elftypes.d \ + core/sys/solaris/sys/link.d core/sys/solaris/sys/priocntl.d \ + core/sys/solaris/sys/procset.d core/sys/solaris/sys/types.d \ + core/sys/solaris/time.d DRUNTIME_DSOURCES_WINDOWS = core/sys/windows/accctrl.d \ core/sys/windows/aclapi.d core/sys/windows/aclui.d \ @@ -1106,6 +1122,7 @@ core/internal/$(am__dirstamp): @: > core/internal/$(am__dirstamp) core/internal/abort.lo: core/internal/$(am__dirstamp) core/internal/arrayop.lo: core/internal/$(am__dirstamp) +core/internal/attributes.lo: core/internal/$(am__dirstamp) core/internal/convert.lo: core/internal/$(am__dirstamp) core/internal/hash.lo: core/internal/$(am__dirstamp) core/internal/spinlock.lo: core/internal/$(am__dirstamp) @@ -1162,6 +1179,7 @@ core/thread/threadgroup.lo: core/thread/$(am__dirstamp) core/thread/types.lo: core/thread/$(am__dirstamp) core/time.lo: core/$(am__dirstamp) core/vararg.lo: core/$(am__dirstamp) +core/volatile.lo: core/$(am__dirstamp) gc/$(am__dirstamp): @$(MKDIR_P) gc @: > gc/$(am__dirstamp) @@ -1347,6 +1365,7 @@ core/sys/darwin/netinet/$(am__dirstamp): core/sys/darwin/netinet/in_.lo: \ core/sys/darwin/netinet/$(am__dirstamp) core/sys/darwin/pthread.lo: core/sys/darwin/$(am__dirstamp) +core/sys/darwin/stdlib.lo: core/sys/darwin/$(am__dirstamp) core/sys/darwin/string.lo: core/sys/darwin/$(am__dirstamp) core/sys/darwin/sys/$(am__dirstamp): @$(MKDIR_P) core/sys/darwin/sys @@ -1355,6 +1374,7 @@ core/sys/darwin/sys/attr.lo: core/sys/darwin/sys/$(am__dirstamp) core/sys/darwin/sys/cdefs.lo: core/sys/darwin/sys/$(am__dirstamp) core/sys/darwin/sys/event.lo: core/sys/darwin/sys/$(am__dirstamp) core/sys/darwin/sys/mman.lo: core/sys/darwin/sys/$(am__dirstamp) +core/sys/darwin/sys/sysctl.lo: core/sys/darwin/sys/$(am__dirstamp) core/sys/dragonflybsd/$(am__dirstamp): @$(MKDIR_P) core/sys/dragonflybsd @: > core/sys/dragonflybsd/$(am__dirstamp) @@ -1369,6 +1389,8 @@ core/sys/dragonflybsd/netinet/in_.lo: \ core/sys/dragonflybsd/netinet/$(am__dirstamp) core/sys/dragonflybsd/pthread_np.lo: \ core/sys/dragonflybsd/$(am__dirstamp) +core/sys/dragonflybsd/stdlib.lo: \ + core/sys/dragonflybsd/$(am__dirstamp) core/sys/dragonflybsd/string.lo: \ core/sys/dragonflybsd/$(am__dirstamp) core/sys/dragonflybsd/sys/$(am__dirstamp): @@ -1396,12 +1418,15 @@ core/sys/dragonflybsd/sys/mman.lo: \ core/sys/dragonflybsd/sys/$(am__dirstamp) core/sys/dragonflybsd/sys/socket.lo: \ core/sys/dragonflybsd/sys/$(am__dirstamp) +core/sys/dragonflybsd/sys/sysctl.lo: \ + core/sys/dragonflybsd/sys/$(am__dirstamp) core/sys/dragonflybsd/time.lo: core/sys/dragonflybsd/$(am__dirstamp) core/sys/bionic/$(am__dirstamp): @$(MKDIR_P) core/sys/bionic @: > core/sys/bionic/$(am__dirstamp) core/sys/bionic/err.lo: core/sys/bionic/$(am__dirstamp) core/sys/bionic/fcntl.lo: core/sys/bionic/$(am__dirstamp) +core/sys/bionic/stdlib.lo: core/sys/bionic/$(am__dirstamp) core/sys/bionic/string.lo: core/sys/bionic/$(am__dirstamp) core/sys/bionic/unistd.lo: core/sys/bionic/$(am__dirstamp) core/sys/freebsd/$(am__dirstamp): @@ -1417,6 +1442,7 @@ core/sys/freebsd/netinet/$(am__dirstamp): core/sys/freebsd/netinet/in_.lo: \ core/sys/freebsd/netinet/$(am__dirstamp) core/sys/freebsd/pthread_np.lo: core/sys/freebsd/$(am__dirstamp) +core/sys/freebsd/stdlib.lo: core/sys/freebsd/$(am__dirstamp) core/sys/freebsd/string.lo: core/sys/freebsd/$(am__dirstamp) core/sys/freebsd/sys/$(am__dirstamp): @$(MKDIR_P) core/sys/freebsd/sys @@ -1434,6 +1460,7 @@ core/sys/freebsd/sys/link_elf.lo: \ core/sys/freebsd/sys/$(am__dirstamp) core/sys/freebsd/sys/mman.lo: core/sys/freebsd/sys/$(am__dirstamp) core/sys/freebsd/sys/mount.lo: core/sys/freebsd/sys/$(am__dirstamp) +core/sys/freebsd/sys/sysctl.lo: core/sys/freebsd/sys/$(am__dirstamp) core/sys/freebsd/time.lo: core/sys/freebsd/$(am__dirstamp) core/sys/freebsd/unistd.lo: core/sys/freebsd/$(am__dirstamp) core/sys/netbsd/$(am__dirstamp): @@ -1442,6 +1469,7 @@ core/sys/netbsd/$(am__dirstamp): core/sys/netbsd/dlfcn.lo: core/sys/netbsd/$(am__dirstamp) core/sys/netbsd/err.lo: core/sys/netbsd/$(am__dirstamp) core/sys/netbsd/execinfo.lo: core/sys/netbsd/$(am__dirstamp) +core/sys/netbsd/stdlib.lo: core/sys/netbsd/$(am__dirstamp) core/sys/netbsd/string.lo: core/sys/netbsd/$(am__dirstamp) core/sys/netbsd/sys/$(am__dirstamp): @$(MKDIR_P) core/sys/netbsd/sys @@ -1456,12 +1484,14 @@ core/sys/netbsd/sys/featuretest.lo: \ core/sys/netbsd/sys/$(am__dirstamp) core/sys/netbsd/sys/link_elf.lo: core/sys/netbsd/sys/$(am__dirstamp) core/sys/netbsd/sys/mman.lo: core/sys/netbsd/sys/$(am__dirstamp) +core/sys/netbsd/sys/sysctl.lo: core/sys/netbsd/sys/$(am__dirstamp) core/sys/netbsd/time.lo: core/sys/netbsd/$(am__dirstamp) core/sys/openbsd/$(am__dirstamp): @$(MKDIR_P) core/sys/openbsd @: > core/sys/openbsd/$(am__dirstamp) core/sys/openbsd/dlfcn.lo: core/sys/openbsd/$(am__dirstamp) core/sys/openbsd/err.lo: core/sys/openbsd/$(am__dirstamp) +core/sys/openbsd/stdlib.lo: core/sys/openbsd/$(am__dirstamp) core/sys/openbsd/string.lo: core/sys/openbsd/$(am__dirstamp) core/sys/openbsd/sys/$(am__dirstamp): @$(MKDIR_P) core/sys/openbsd/sys @@ -1475,6 +1505,7 @@ core/sys/openbsd/sys/elf_common.lo: \ core/sys/openbsd/sys/link_elf.lo: \ core/sys/openbsd/sys/$(am__dirstamp) core/sys/openbsd/sys/mman.lo: core/sys/openbsd/sys/$(am__dirstamp) +core/sys/openbsd/sys/sysctl.lo: core/sys/openbsd/sys/$(am__dirstamp) core/sys/openbsd/time.lo: core/sys/openbsd/$(am__dirstamp) core/sys/linux/$(am__dirstamp): @$(MKDIR_P) core/sys/linux @@ -1698,6 +1729,7 @@ core/sys/solaris/err.lo: core/sys/solaris/$(am__dirstamp) core/sys/solaris/execinfo.lo: core/sys/solaris/$(am__dirstamp) core/sys/solaris/libelf.lo: core/sys/solaris/$(am__dirstamp) core/sys/solaris/link.lo: core/sys/solaris/$(am__dirstamp) +core/sys/solaris/stdlib.lo: core/sys/solaris/$(am__dirstamp) core/sys/solaris/sys/$(am__dirstamp): @$(MKDIR_P) core/sys/solaris/sys @: > core/sys/solaris/sys/$(am__dirstamp) diff --git a/libphobos/libdruntime/core/bitop.d b/libphobos/libdruntime/core/bitop.d index 0daee55..25b5cd5 100644 --- a/libphobos/libdruntime/core/bitop.d +++ b/libphobos/libdruntime/core/bitop.d @@ -267,7 +267,7 @@ unittest * (No longer an intrisic - the compiler recognizes the patterns * in the body.) */ -int bt(in size_t* p, size_t bitnum) pure @system +int bt(const scope size_t* p, size_t bitnum) pure @system { static if (size_t.sizeof == 8) return ((p[bitnum >> 6] & (1L << (bitnum & 63)))) != 0; @@ -495,25 +495,61 @@ struct BitRange } /** + * Swaps bytes in a 2 byte ushort. + * Params: + * x = value + * Returns: + * `x` with bytes swapped + */ +pragma(inline, false) +ushort byteswap(ushort x) pure +{ + /* Calling it bswap(ushort) would break existing code that calls bswap(uint). + * + * This pattern is meant to be recognized by the dmd code generator. + * Don't change it without checking that an XCH instruction is still + * used to implement it. + * Inlining may also throw it off. + */ + return cast(ushort) (((x >> 8) & 0xFF) | ((x << 8) & 0xFF00u)); +} + +/// +unittest +{ + assert(byteswap(cast(ushort)0xF234) == 0x34F2); + static ushort xx = 0xF234; + assert(byteswap(xx) == 0x34F2); +} + +/** * Swaps bytes in a 4 byte uint end-to-end, i.e. byte 0 becomes * byte 3, byte 1 becomes byte 2, byte 2 becomes byte 1, byte 3 * becomes byte 0. */ uint bswap(uint v) pure; +/// +unittest +{ + assert(bswap(0x01020304u) == 0x04030201u); + static uint xx = 0x10203040u; + assert(bswap(xx) == 0x40302010u); +} + /** * Swaps bytes in an 8 byte ulong end-to-end, i.e. byte 0 becomes * byte 7, byte 1 becomes byte 6, etc. + * This is meant to be recognized by the compiler as an intrinsic. */ -ulong bswap(ulong v) pure -{ - auto sv = Split64(v); - - const temp = sv.lo; - sv.lo = bswap(sv.hi); - sv.hi = bswap(temp); +ulong bswap(ulong v) pure; - return (cast(ulong) sv.hi << 32) | sv.lo; +/// +unittest +{ + assert(bswap(0x01020304_05060708uL) == 0x08070605_04030201uL); + static ulong xx = 0x10203040_50607080uL; + assert(bswap(xx) == 0x80706050_40302010uL); } version (DigitalMars) version (AnyX86) @system // not pure @@ -722,57 +758,14 @@ version (DigitalMars) version (AnyX86) } -/************************************* - * Read/write value from/to the memory location indicated by ptr. - * - * These functions are recognized by the compiler, and calls to them are guaranteed - * to not be removed (as dead assignment elimination or presumed to have no effect) - * or reordered in the same thread. - * - * These reordering guarantees are only made with regards to other - * operations done through these functions; the compiler is free to reorder regular - * loads/stores with regards to loads/stores done through these functions. - * - * This is useful when dealing with memory-mapped I/O (MMIO) where a store can - * have an effect other than just writing a value, or where sequential loads - * with no intervening stores can retrieve - * different values from the same location due to external stores to the location. - * - * These functions will, when possible, do the load/store as a single operation. In - * general, this is possible when the size of the operation is less than or equal to - * $(D (void*).sizeof), although some targets may support larger operations. If the - * load/store cannot be done as a single operation, multiple smaller operations will be used. - * - * These are not to be conflated with atomic operations. They do not guarantee any - * atomicity. This may be provided by coincidence as a result of the instructions - * used on the target, but this should not be relied on for portable programs. - * Further, no memory fences are implied by these functions. - * They should not be used for communication between threads. - * They may be used to guarantee a write or read cycle occurs at a specified address. - */ - -ubyte volatileLoad(ubyte * ptr); -ushort volatileLoad(ushort* ptr); /// ditto -uint volatileLoad(uint * ptr); /// ditto -ulong volatileLoad(ulong * ptr); /// ditto - -void volatileStore(ubyte * ptr, ubyte value); /// ditto -void volatileStore(ushort* ptr, ushort value); /// ditto -void volatileStore(uint * ptr, uint value); /// ditto -void volatileStore(ulong * ptr, ulong value); /// ditto - -@system unittest +deprecated("volatileLoad has been moved to core.volatile. Use core.volatile.volatileLoad instead.") { - alias TT(T...) = T; + public import core.volatile : volatileLoad; +} - foreach (T; TT!(ubyte, ushort, uint, ulong)) - { - T u; - T* p = &u; - volatileStore(p, 1); - T r = volatileLoad(p); - assert(r == u); - } +deprecated("volatileStore has been moved to core.volatile. Use core.volatile.volatileStore instead.") +{ + public import core.volatile : volatileStore; } @@ -954,51 +947,51 @@ version (D_InlineAsm_X86_64) * Bitwise rotate `value` left (`rol`) or right (`ror`) by * `count` bit positions. */ -pure T rol(T)(in T value, in uint count) +pure T rol(T)(const T value, const uint count) if (__traits(isIntegral, T) && __traits(isUnsigned, T)) { assert(count < 8 * T.sizeof); - return cast(T) ((value << count) | (value >> (-count & (T.sizeof * 8 - 1)))); + return cast(T) ((value << count) | (value >> (T.sizeof * 8 - count))); } /// ditto -pure T ror(T)(in T value, in uint count) +pure T ror(T)(const T value, const uint count) if (__traits(isIntegral, T) && __traits(isUnsigned, T)) { assert(count < 8 * T.sizeof); - return cast(T) ((value >> count) | (value << (-count & (T.sizeof * 8 - 1)))); + return cast(T) ((value >> count) | (value << (T.sizeof * 8 - count))); } /// ditto -pure T rol(uint count, T)(in T value) +pure T rol(uint count, T)(const T value) if (__traits(isIntegral, T) && __traits(isUnsigned, T)) { static assert(count < 8 * T.sizeof); - return cast(T) ((value << count) | (value >> (-count & (T.sizeof * 8 - 1)))); + return cast(T) ((value << count) | (value >> (T.sizeof * 8 - count))); } /// ditto -pure T ror(uint count, T)(in T value) +pure T ror(uint count, T)(const T value) if (__traits(isIntegral, T) && __traits(isUnsigned, T)) { static assert(count < 8 * T.sizeof); - return cast(T) ((value >> count) | (value << (-count & (T.sizeof * 8 - 1)))); + return cast(T) ((value >> count) | (value << (T.sizeof * 8 - count))); } /// unittest { - ubyte a = 0b10101010U; - ulong b = ulong.max; + ubyte a = 0b11110000U; + ulong b = ~1UL; - assert(rol(a, 1) == 0b01010101); - assert(ror(a, 1) == 0b01010101); - assert(rol(a, 3) == 0b01010101); - assert(ror(a, 3) == 0b01010101); + assert(rol(a, 1) == 0b11100001); + assert(ror(a, 1) == 0b01111000); + assert(rol(a, 3) == 0b10000111); + assert(ror(a, 3) == 0b00011110); assert(rol(a, 0) == a); assert(ror(a, 0) == a); - assert(rol(b, 63) == ulong.max); - assert(ror(b, 63) == ulong.max); + assert(rol(b, 63) == ~(1UL << 63)); + assert(ror(b, 63) == ~2UL); - assert(rol!3(a) == 0b01010101); - assert(ror!3(a) == 0b01010101); + assert(rol!3(a) == 0b10000111); + assert(ror!3(a) == 0b00011110); } diff --git a/libphobos/libdruntime/core/checkedint.d b/libphobos/libdruntime/core/checkedint.d index 237c8e4..57209ad 100644 --- a/libphobos/libdruntime/core/checkedint.d +++ b/libphobos/libdruntime/core/checkedint.d @@ -47,7 +47,7 @@ pure: */ pragma(inline, true) -int adds(int x, int y, ref bool overflow) +int adds()(int x, int y, ref bool overflow) { long r = cast(long)x + cast(long)y; if (r < int.min || r > int.max) @@ -75,7 +75,7 @@ unittest /// ditto pragma(inline, true) -long adds(long x, long y, ref bool overflow) +long adds()(long x, long y, ref bool overflow) { long r = cast(ulong)x + cast(ulong)y; if (x < 0 && y < 0 && r >= 0 || @@ -106,7 +106,7 @@ static if (is(cent)) { /// ditto pragma(inline, true) -cent adds(cent x, cent y, ref bool overflow) +cent adds()(cent x, cent y, ref bool overflow) { cent r = cast(ucent)x + cast(ucent)y; if (x < 0 && y < 0 && r >= 0 || @@ -149,7 +149,7 @@ unittest */ pragma(inline, true) -uint addu(uint x, uint y, ref bool overflow) +uint addu()(uint x, uint y, ref bool overflow) { immutable uint r = x + y; if (r < x || r < y) @@ -177,7 +177,7 @@ unittest /// ditto pragma(inline, true) -ulong addu(ulong x, ulong y, ref bool overflow) +ulong addu()(ulong x, ulong y, ref bool overflow) { immutable ulong r = x + y; if (r < x || r < y) @@ -207,7 +207,7 @@ static if (is(ucent)) { /// ditto pragma(inline, true) -ucent addu(ucent x, ucent y, ref bool overflow) +ucent addu()(ucent x, ucent y, ref bool overflow) { immutable ucent r = x + y; if (r < x || r < y) @@ -249,7 +249,7 @@ unittest */ pragma(inline, true) -int subs(int x, int y, ref bool overflow) +int subs()(int x, int y, ref bool overflow) { immutable long r = cast(long)x - cast(long)y; if (r < int.min || r > int.max) @@ -277,7 +277,7 @@ unittest /// ditto pragma(inline, true) -long subs(long x, long y, ref bool overflow) +long subs()(long x, long y, ref bool overflow) { immutable long r = cast(ulong)x - cast(ulong)y; if (x < 0 && y >= 0 && r >= 0 || @@ -310,7 +310,7 @@ static if (is(cent)) { /// ditto pragma(inline, true) -cent subs(cent x, cent y, ref bool overflow) +cent subs()(cent x, cent y, ref bool overflow) { immutable cent r = cast(ucent)x - cast(ucent)y; if (x < 0 && y >= 0 && r >= 0 || @@ -355,7 +355,7 @@ unittest */ pragma(inline, true) -uint subu(uint x, uint y, ref bool overflow) +uint subu()(uint x, uint y, ref bool overflow) { if (x < y) overflow = true; @@ -383,7 +383,7 @@ unittest /// ditto pragma(inline, true) -ulong subu(ulong x, ulong y, ref bool overflow) +ulong subu()(ulong x, ulong y, ref bool overflow) { if (x < y) overflow = true; @@ -412,7 +412,7 @@ static if (is(ucent)) { /// ditto pragma(inline, true) -ucent subu(ucent x, ucent y, ref bool overflow) +ucent subu()(ucent x, ucent y, ref bool overflow) { if (x < y) overflow = true; @@ -450,7 +450,7 @@ unittest */ pragma(inline, true) -int negs(int x, ref bool overflow) +int negs()(int x, ref bool overflow) { if (x == int.min) overflow = true; @@ -474,7 +474,7 @@ unittest /// ditto pragma(inline, true) -long negs(long x, ref bool overflow) +long negs()(long x, ref bool overflow) { if (x == long.min) overflow = true; @@ -500,7 +500,7 @@ static if (is(cent)) { /// ditto pragma(inline, true) -cent negs(cent x, ref bool overflow) +cent negs()(cent x, ref bool overflow) { if (x == cent.min) overflow = true; @@ -538,7 +538,7 @@ unittest */ pragma(inline, true) -int muls(int x, int y, ref bool overflow) +int muls()(int x, int y, ref bool overflow) { long r = cast(long)x * cast(long)y; if (r < int.min || r > int.max) @@ -568,11 +568,13 @@ unittest /// ditto pragma(inline, true) -long muls(long x, long y, ref bool overflow) +long muls()(long x, long y, ref bool overflow) { immutable long r = cast(ulong)x * cast(ulong)y; enum not0or1 = ~1L; - if ((x & not0or1) && ((r == y)? r : (r / x) != y)) + if ((x & not0or1) && + ((r == y) ? r != 0 + : (r == 0x8000_0000_0000_0000 && x == -1L) || ((r / x) != y))) overflow = true; return r; } @@ -604,7 +606,7 @@ static if (is(cent)) { /// ditto pragma(inline, true) -cent muls(cent x, cent y, ref bool overflow) +cent muls()(cent x, cent y, ref bool overflow) { immutable cent r = cast(ucent)x * cast(ucent)y; enum not0or1 = ~1L; @@ -652,7 +654,7 @@ unittest */ pragma(inline, true) -uint mulu(uint x, uint y, ref bool overflow) +uint mulu()(uint x, uint y, ref bool overflow) { immutable ulong r = ulong(x) * ulong(y); if (r >> 32) @@ -682,7 +684,7 @@ unittest /// ditto pragma(inline, true) -ulong mulu(ulong x, uint y, ref bool overflow) +ulong mulu()(ulong x, uint y, ref bool overflow) { ulong r = x * y; if (x >> 32 && @@ -693,7 +695,7 @@ ulong mulu(ulong x, uint y, ref bool overflow) /// ditto pragma(inline, true) -ulong mulu(ulong x, ulong y, ref bool overflow) +ulong mulu()(ulong x, ulong y, ref bool overflow) { immutable ulong r = x * y; if ((x | y) >> 32 && @@ -751,7 +753,7 @@ static if (is(ucent)) { /// ditto pragma(inline, true) -ucent mulu(ucent x, ucent y, ref bool overflow) +ucent mulu()(ucent x, ucent y, ref bool overflow) { immutable ucent r = x * y; if (x && (r / x) != y) diff --git a/libphobos/libdruntime/core/cpuid.d b/libphobos/libdruntime/core/cpuid.d index 2ba13b5..e31f776 100644 --- a/libphobos/libdruntime/core/cpuid.d +++ b/libphobos/libdruntime/core/cpuid.d @@ -56,6 +56,9 @@ module core.cpuid; +version (GNU) version = GNU_OR_LDC; +version (LDC) version = GNU_OR_LDC; + @trusted: nothrow: @nogc: @@ -318,10 +321,10 @@ private: struct CpuFeatures { bool probablyIntel; // true = _probably_ an Intel processor, might be faking - bool probablyAMD; // true = _probably_ an AMD processor + bool probablyAMD; // true = _probably_ an AMD or Hygon processor string processorName; - char [12] vendorID; - char [48] processorNameBuffer; + char [12] vendorID = 0; + char [48] processorNameBuffer = 0; uint features = 0; // mmx, sse, sse2, hyperthreading, etc uint miscfeatures = 0; // sse3, etc. uint extfeatures = 0; // HLE, AVX2, RTM, etc. @@ -426,7 +429,7 @@ CpuFeatures* getCpuFeatures() @nogc nothrow } -version (GNU) { +version (GNU_OR_LDC) { version (X86) enum supportedX86 = true; else version (X86_64) @@ -509,12 +512,12 @@ void getcacheinfoCPUID2() // for old single-core CPUs. uint numinfos = 1; do { - version (GNU) asm pure nothrow @nogc { + version (GNU_OR_LDC) asm pure nothrow @nogc { "cpuid" : "=a" (a[0]), "=b" (a[1]), "=c" (a[2]), "=d" (a[3]) : "a" (2); } else asm pure nothrow @nogc { mov EAX, 2; cpuid; - mov a, EAX; + mov a+0, EAX; mov a+4, EBX; mov a+8, ECX; mov a+12, EDX; @@ -553,7 +556,7 @@ void getcacheinfoCPUID4() int cachenum = 0; for (;;) { uint a, b, number_of_sets; - version (GNU) asm pure nothrow @nogc { + version (GNU_OR_LDC) asm pure nothrow @nogc { "cpuid" : "=a" (a), "=b" (b), "=c" (number_of_sets) : "a" (4), "c" (cachenum) : "edx"; } else asm pure nothrow @nogc { mov EAX, 4; @@ -593,7 +596,7 @@ void getcacheinfoCPUID4() void getAMDcacheinfo() { uint dummy, c5, c6, d6; - version (GNU) asm pure nothrow @nogc { + version (GNU_OR_LDC) asm pure nothrow @nogc { "cpuid" : "=a" (dummy), "=c" (c5) : "a" (0x8000_0005) : "ebx", "edx"; } else asm pure nothrow @nogc { mov EAX, 0x8000_0005; // L1 cache @@ -612,7 +615,7 @@ void getAMDcacheinfo() // AMD K6-III or K6-2+ or later. ubyte numcores = 1; if (max_extended_cpuid >= 0x8000_0008) { - version (GNU) asm pure nothrow @nogc { + version (GNU_OR_LDC) asm pure nothrow @nogc { "cpuid" : "=a" (dummy), "=c" (numcores) : "a" (0x8000_0008) : "ebx", "edx"; } else asm pure nothrow @nogc { mov EAX, 0x8000_0008; @@ -623,7 +626,7 @@ void getAMDcacheinfo() if (numcores>cpuFeatures.maxCores) cpuFeatures.maxCores = numcores; } - version (GNU) asm pure nothrow @nogc { + version (GNU_OR_LDC) asm pure nothrow @nogc { "cpuid" : "=a" (dummy), "=c" (c6), "=d" (d6) : "a" (0x8000_0006) : "ebx"; } else asm pure nothrow @nogc { mov EAX, 0x8000_0006; // L2/L3 cache @@ -652,7 +655,7 @@ void getCpuInfo0B() int threadsPerCore; uint a, b, c, d; do { - version (GNU) asm pure nothrow @nogc { + version (GNU_OR_LDC) asm pure nothrow @nogc { "cpuid" : "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (0x0B), "c" (level); } else asm pure nothrow @nogc { mov EAX, 0x0B; @@ -684,7 +687,7 @@ void cpuidX86() uint a, b, c, d; uint* venptr = cast(uint*)cf.vendorID.ptr; - version (GNU) + version (GNU_OR_LDC) { asm pure nothrow @nogc { "cpuid" : "=a" (max_cpuid), "=b" (venptr[0]), "=d" (venptr[1]), "=c" (venptr[2]) : "a" (0); @@ -729,9 +732,9 @@ void cpuidX86() cf.probablyIntel = cf.vendorID == "GenuineIntel"; - cf.probablyAMD = cf.vendorID == "AuthenticAMD"; + cf.probablyAMD = (cf.vendorID == "AuthenticAMD" || cf.vendorID == "HygonGenuine"); uint apic = 0; // brand index, apic id - version (GNU) asm pure nothrow @nogc { + version (GNU_OR_LDC) asm pure nothrow @nogc { "cpuid" : "=a" (a), "=b" (apic), "=c" (cf.miscfeatures), "=d" (cf.features) : "a" (1); } else { asm pure nothrow @nogc { @@ -754,7 +757,7 @@ void cpuidX86() if (max_cpuid >= 7) { - version (GNU) asm pure nothrow @nogc { + version (GNU_OR_LDC) asm pure nothrow @nogc { "cpuid" : "=a" (a), "=b" (cf.extfeatures), "=c" (c) : "a" (7), "c" (0) : "edx"; } else { uint ext; @@ -770,8 +773,11 @@ void cpuidX86() if (cf.miscfeatures & OSXSAVE_BIT) { - version (GNU) asm pure nothrow @nogc { - "xgetbv" : "=a" (a), "=d" (d) : "c" (0); + version (GNU_OR_LDC) asm pure nothrow @nogc { + /* Old assemblers do not recognize xgetbv, and there is no easy way + * to conditionally compile based on the assembler used, so use the + * raw .byte sequence instead. */ + ".byte 0x0f, 0x01, 0xd0" : "=a" (a), "=d" (d) : "c" (0); } else asm pure nothrow @nogc { mov ECX, 0; xgetbv; @@ -784,7 +790,7 @@ void cpuidX86() cf.amdfeatures = 0; cf.amdmiscfeatures = 0; if (max_extended_cpuid >= 0x8000_0001) { - version (GNU) asm pure nothrow @nogc { + version (GNU_OR_LDC) asm pure nothrow @nogc { "cpuid" : "=a" (a), "=c" (cf.amdmiscfeatures), "=d" (cf.amdfeatures) : "a" (0x8000_0001) : "ebx"; } else { asm pure nothrow @nogc { @@ -805,7 +811,7 @@ void cpuidX86() cf.maxCores = 1; if (hyperThreadingBit) { // determine max number of cores for AMD - version (GNU) asm pure nothrow @nogc { + version (GNU_OR_LDC) asm pure nothrow @nogc { "cpuid" : "=a" (a), "=c" (c) : "a" (0x8000_0008) : "ebx", "edx"; } else asm pure nothrow @nogc { mov EAX, 0x8000_0008; @@ -818,7 +824,7 @@ void cpuidX86() if (max_extended_cpuid >= 0x8000_0004) { uint* pnb = cast(uint*)cf.processorNameBuffer.ptr; - version (GNU) + version (GNU_OR_LDC) { asm pure nothrow @nogc { "cpuid" : "=a" (pnb[0]), "=b" (pnb[1]), "=c" (pnb[ 2]), "=d" (pnb[ 3]) : "a" (0x8000_0002); @@ -950,7 +956,7 @@ void cpuidX86() else cf.maxThreads = cf.maxCores; if (cf.probablyAMD && max_extended_cpuid >= 0x8000_001E) { - version (GNU) asm pure nothrow @nogc { + version (GNU_OR_LDC) asm pure nothrow @nogc { "cpuid" : "=a" (a), "=b" (b) : "a" (0x8000_001E) : "ecx", "edx"; } else { asm pure nothrow @nogc { @@ -974,21 +980,18 @@ bool hasCPUID() else { uint flags; - version (GNU) + version (GNU_OR_LDC) { // http://wiki.osdev.org/CPUID#Checking_CPUID_availability - // ASM template supports both AT&T and Intel syntax. asm nothrow @nogc { " - pushf{l|d} # Save EFLAGS - pushf{l|d} # Store EFLAGS - xor{l $0x00200000, (%%esp)| dword ptr [esp], 0x00200000} - # Invert the ID bit in stored EFLAGS - popf{l|d} # Load stored EFLAGS (with ID bit inverted) - pushf{l|d} # Store EFLAGS again (ID bit may or may not be inverted) - pop {%%}eax # eax = modified EFLAGS (ID bit may or may not be inverted) - xor {(%%esp), %%eax|eax, [esp]} - # eax = whichever bits were changed - popf{l|d} # Restore original EFLAGS + pushfl # Save EFLAGS + pushfl # Store EFLAGS + xorl $0x00200000, (%%esp) # Invert the ID bit in stored EFLAGS + popfl # Load stored EFLAGS (with ID bit inverted) + pushfl # Store EFLAGS again (ID bit may or may not be inverted) + popl %%eax # eax = modified EFLAGS (ID bit may or may not be inverted) + xorl (%%esp), %%eax # eax = whichever bits were changed + popfl # Restore original EFLAGS " : "=a" (flags); } } diff --git a/libphobos/libdruntime/core/internal/attributes.d b/libphobos/libdruntime/core/internal/attributes.d new file mode 100644 index 0000000..b7253c2 --- /dev/null +++ b/libphobos/libdruntime/core/internal/attributes.d @@ -0,0 +1,11 @@ +module core.internal.attributes; + +/** +Used to annotate `unittest`s which need to be tested in a `-betterC` environment. + +Such `unittest`s will be compiled and executed without linking druntime in, with +a `__traits(getUnitTests, mixin(__MODULE__))` style test runner. +Note that just like any other `unittest` in druntime, they will also be compiled +and executed without `-betterC`. +*/ +package(core) enum betterC = 1; diff --git a/libphobos/libdruntime/core/internal/traits.d b/libphobos/libdruntime/core/internal/traits.d index e56f016..9f79dd0 100644 --- a/libphobos/libdruntime/core/internal/traits.d +++ b/libphobos/libdruntime/core/internal/traits.d @@ -8,10 +8,16 @@ */ module core.internal.traits; -/// taken from std.typetuple.TypeTuple -template TypeTuple(TList...) +alias AliasSeq(TList...) = TList; + +template Fields(T) { - alias TypeTuple = TList; + static if (is(T == struct) || is(T == union)) + alias Fields = typeof(T.tupleof[0 .. $ - __traits(isNested, T)]); + else static if (is(T == class)) + alias Fields = typeof(T.tupleof); + else + alias Fields = AliasSeq!T; } T trustedCast(T, U)(auto ref U u) @trusted pure nothrow @@ -109,17 +115,17 @@ template staticIota(int beg, int end) { static if (beg >= end) { - alias staticIota = TypeTuple!(); + alias staticIota = AliasSeq!(); } else { - alias staticIota = TypeTuple!(+beg); + alias staticIota = AliasSeq!(+beg); } } else { enum mid = beg + (end - beg) / 2; - alias staticIota = TypeTuple!(staticIota!(beg, mid), staticIota!(mid, end)); + alias staticIota = AliasSeq!(staticIota!(beg, mid), staticIota!(mid, end)); } } @@ -235,24 +241,150 @@ template hasElaborateCopyConstructor(T...) enum bool hasElaborateCopyConstructor = false; } +template hasUnsharedIndirections(T) +{ + static if (is(T == immutable)) + enum hasUnsharedIndirections = false; + else static if (is(T == struct) || is(T == union)) + enum hasUnsharedIndirections = anySatisfy!(.hasUnsharedIndirections, Fields!T); + else static if (is(T : E[N], E, size_t N)) + enum hasUnsharedIndirections = is(E == void) ? false : hasUnsharedIndirections!E; + else static if (isFunctionPointer!T) + enum hasUnsharedIndirections = false; + else static if (isPointer!T) + enum hasUnsharedIndirections = !is(T : shared(U)*, U) && !is(T : immutable(U)*, U); + else static if (isDynamicArray!T) + enum hasUnsharedIndirections = !is(T : shared(V)[], V) && !is(T : immutable(V)[], V); + else static if (is(T == class) || is(T == interface)) + enum hasUnsharedIndirections = !is(T : shared(W), W); + else + enum hasUnsharedIndirections = isDelegate!T || __traits(isAssociativeArray, T); // TODO: how to handle these? +} + +unittest +{ + static struct Foo { shared(int)* val; } + + static assert(!hasUnsharedIndirections!(immutable(char)*)); + static assert(!hasUnsharedIndirections!(string)); + + static assert(!hasUnsharedIndirections!(Foo)); + static assert( hasUnsharedIndirections!(Foo*)); + static assert(!hasUnsharedIndirections!(shared(Foo)*)); + static assert(!hasUnsharedIndirections!(immutable(Foo)*)); +} + +enum bool isAggregateType(T) = is(T == struct) || is(T == union) || + is(T == class) || is(T == interface); + +enum bool isPointer(T) = is(T == U*, U) && !isAggregateType!T; + +enum bool isDynamicArray(T) = is(DynamicArrayTypeOf!T) && !isAggregateType!T; + +template OriginalType(T) +{ + template Impl(T) + { + static if (is(T U == enum)) alias Impl = OriginalType!U; + else alias Impl = T; + } + + alias OriginalType = ModifyTypePreservingTQ!(Impl, T); +} + +template DynamicArrayTypeOf(T) +{ + static if (is(AliasThisTypeOf!T AT) && !is(AT[] == AT)) + alias X = DynamicArrayTypeOf!AT; + else + alias X = OriginalType!T; + + static if (is(Unqual!X : E[], E) && !is(typeof({ enum n = X.length; }))) + alias DynamicArrayTypeOf = X; + else + static assert(0, T.stringof ~ " is not a dynamic array"); +} + +private template AliasThisTypeOf(T) + if (isAggregateType!T) +{ + alias members = __traits(getAliasThis, T); + + static if (members.length == 1) + alias AliasThisTypeOf = typeof(__traits(getMember, T.init, members[0])); + else + static assert(0, T.stringof~" does not have alias this type"); +} + +template isFunctionPointer(T...) + if (T.length == 1) +{ + static if (is(T[0] U) || is(typeof(T[0]) U)) + { + static if (is(U F : F*) && is(F == function)) + enum bool isFunctionPointer = true; + else + enum bool isFunctionPointer = false; + } + else + enum bool isFunctionPointer = false; +} + +template isDelegate(T...) + if (T.length == 1) +{ + static if (is(typeof(& T[0]) U : U*) && is(typeof(& T[0]) U == delegate)) + { + // T is a (nested) function symbol. + enum bool isDelegate = true; + } + else static if (is(T[0] W) || is(typeof(T[0]) W)) + { + // T is an expression or a type. Take the type of it and examine. + enum bool isDelegate = is(W == delegate); + } + else + enum bool isDelegate = false; +} + // std.meta.Filter template Filter(alias pred, TList...) { static if (TList.length == 0) { - alias Filter = TypeTuple!(); + alias Filter = AliasSeq!(); } else static if (TList.length == 1) { static if (pred!(TList[0])) - alias Filter = TypeTuple!(TList[0]); + alias Filter = AliasSeq!(TList[0]); else - alias Filter = TypeTuple!(); + alias Filter = AliasSeq!(); + } + /* The next case speeds up compilation by reducing + * the number of Filter instantiations + */ + else static if (TList.length == 2) + { + static if (pred!(TList[0])) + { + static if (pred!(TList[1])) + alias Filter = AliasSeq!(TList[0], TList[1]); + else + alias Filter = AliasSeq!(TList[0]); + } + else + { + static if (pred!(TList[1])) + alias Filter = AliasSeq!(TList[1]); + else + alias Filter = AliasSeq!(); + } } else { alias Filter = - TypeTuple!( + AliasSeq!( Filter!(pred, TList[ 0 .. $/2]), Filter!(pred, TList[$/2 .. $ ])); } diff --git a/libphobos/libdruntime/core/simd.d b/libphobos/libdruntime/core/simd.d index 32e2aaf..11a4711 100644 --- a/libphobos/libdruntime/core/simd.d +++ b/libphobos/libdruntime/core/simd.d @@ -5,9 +5,10 @@ * * Source: $(DRUNTIMESRC core/_simd.d) * - * Copyright: Copyright Digital Mars 2012. - * License: $(WEB www.boost.org/LICENSE_1_0.txt, Boost License 1.0). - * Authors: $(WEB digitalmars.com, Walter Bright), + * Copyright: Copyright Digital Mars 2012-2020 + * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0). + * Authors: $(HTTP digitalmars.com, Walter Bright), + * Source: $(DRUNTIMESRC core/_simd.d) */ module core.simd; @@ -38,470 +39,523 @@ template Vector(T) /* Handy aliases */ -static if (is(Vector!(void[8]))) alias Vector!(void[8]) void8; /// -static if (is(Vector!(double[1]))) alias Vector!(double[1]) double1; /// -static if (is(Vector!(float[2]))) alias Vector!(float[2]) float2; /// -static if (is(Vector!(byte[8]))) alias Vector!(byte[8]) byte8; /// -static if (is(Vector!(ubyte[8]))) alias Vector!(ubyte[8]) ubyte8; /// -static if (is(Vector!(short[4]))) alias Vector!(short[4]) short4; /// -static if (is(Vector!(ushort[4]))) alias Vector!(ushort[4]) ushort4; /// -static if (is(Vector!(int[2]))) alias Vector!(int[2]) int2; /// -static if (is(Vector!(uint[2]))) alias Vector!(uint[2]) uint2; /// -static if (is(Vector!(long[1]))) alias Vector!(long[1]) long1; /// -static if (is(Vector!(ulong[1]))) alias Vector!(ulong[1]) ulong1; /// - -static if (is(Vector!(void[16]))) alias Vector!(void[16]) void16; /// -static if (is(Vector!(double[2]))) alias Vector!(double[2]) double2; /// -static if (is(Vector!(float[4]))) alias Vector!(float[4]) float4; /// -static if (is(Vector!(byte[16]))) alias Vector!(byte[16]) byte16; /// -static if (is(Vector!(ubyte[16]))) alias Vector!(ubyte[16]) ubyte16; /// -static if (is(Vector!(short[8]))) alias Vector!(short[8]) short8; /// -static if (is(Vector!(ushort[8]))) alias Vector!(ushort[8]) ushort8; /// -static if (is(Vector!(int[4]))) alias Vector!(int[4]) int4; /// -static if (is(Vector!(uint[4]))) alias Vector!(uint[4]) uint4; /// -static if (is(Vector!(long[2]))) alias Vector!(long[2]) long2; /// -static if (is(Vector!(ulong[2]))) alias Vector!(ulong[2]) ulong2; /// - -static if (is(Vector!(void[32]))) alias Vector!(void[32]) void32; /// -static if (is(Vector!(double[4]))) alias Vector!(double[4]) double4; /// -static if (is(Vector!(float[8]))) alias Vector!(float[8]) float8; /// -static if (is(Vector!(byte[32]))) alias Vector!(byte[32]) byte32; /// -static if (is(Vector!(ubyte[32]))) alias Vector!(ubyte[32]) ubyte32; /// -static if (is(Vector!(short[16]))) alias Vector!(short[16]) short16; /// -static if (is(Vector!(ushort[16]))) alias Vector!(ushort[16]) ushort16; /// -static if (is(Vector!(int[8]))) alias Vector!(int[8]) int8; /// -static if (is(Vector!(uint[8]))) alias Vector!(uint[8]) uint8; /// -static if (is(Vector!(long[4]))) alias Vector!(long[4]) long4; /// -static if (is(Vector!(ulong[4]))) alias Vector!(ulong[4]) ulong4; /// +static if (is(Vector!(void[8]))) alias Vector!(void[8]) void8; /// +static if (is(Vector!(double[1]))) alias Vector!(double[1]) double1; /// +static if (is(Vector!(float[2]))) alias Vector!(float[2]) float2; /// +static if (is(Vector!(byte[8]))) alias Vector!(byte[8]) byte8; /// +static if (is(Vector!(ubyte[8]))) alias Vector!(ubyte[8]) ubyte8; /// +static if (is(Vector!(short[4]))) alias Vector!(short[4]) short4; /// +static if (is(Vector!(ushort[4]))) alias Vector!(ushort[4]) ushort4; /// +static if (is(Vector!(int[2]))) alias Vector!(int[2]) int2; /// +static if (is(Vector!(uint[2]))) alias Vector!(uint[2]) uint2; /// +static if (is(Vector!(long[1]))) alias Vector!(long[1]) long1; /// +static if (is(Vector!(ulong[1]))) alias Vector!(ulong[1]) ulong1; /// + +static if (is(Vector!(void[16]))) alias Vector!(void[16]) void16; /// +static if (is(Vector!(double[2]))) alias Vector!(double[2]) double2; /// +static if (is(Vector!(float[4]))) alias Vector!(float[4]) float4; /// +static if (is(Vector!(byte[16]))) alias Vector!(byte[16]) byte16; /// +static if (is(Vector!(ubyte[16]))) alias Vector!(ubyte[16]) ubyte16; /// +static if (is(Vector!(short[8]))) alias Vector!(short[8]) short8; /// +static if (is(Vector!(ushort[8]))) alias Vector!(ushort[8]) ushort8; /// +static if (is(Vector!(int[4]))) alias Vector!(int[4]) int4; /// +static if (is(Vector!(uint[4]))) alias Vector!(uint[4]) uint4; /// +static if (is(Vector!(long[2]))) alias Vector!(long[2]) long2; /// +static if (is(Vector!(ulong[2]))) alias Vector!(ulong[2]) ulong2; /// + +static if (is(Vector!(void[32]))) alias Vector!(void[32]) void32; /// +static if (is(Vector!(double[4]))) alias Vector!(double[4]) double4; /// +static if (is(Vector!(float[8]))) alias Vector!(float[8]) float8; /// +static if (is(Vector!(byte[32]))) alias Vector!(byte[32]) byte32; /// +static if (is(Vector!(ubyte[32]))) alias Vector!(ubyte[32]) ubyte32; /// +static if (is(Vector!(short[16]))) alias Vector!(short[16]) short16; /// +static if (is(Vector!(ushort[16]))) alias Vector!(ushort[16]) ushort16; /// +static if (is(Vector!(int[8]))) alias Vector!(int[8]) int8; /// +static if (is(Vector!(uint[8]))) alias Vector!(uint[8]) uint8; /// +static if (is(Vector!(long[4]))) alias Vector!(long[4]) long4; /// +static if (is(Vector!(ulong[4]))) alias Vector!(ulong[4]) ulong4; /// + +static if (is(Vector!(void[64]))) alias Vector!(void[64]) void64; /// +static if (is(Vector!(double[8]))) alias Vector!(double[8]) double8; /// +static if (is(Vector!(float[16]))) alias Vector!(float[16]) float16; /// +static if (is(Vector!(byte[64]))) alias Vector!(byte[64]) byte64; /// +static if (is(Vector!(ubyte[64]))) alias Vector!(ubyte[64]) ubyte64; /// +static if (is(Vector!(short[32]))) alias Vector!(short[32]) short32; /// +static if (is(Vector!(ushort[32]))) alias Vector!(ushort[32]) ushort32; /// +static if (is(Vector!(int[16]))) alias Vector!(int[16]) int16; /// +static if (is(Vector!(uint[16]))) alias Vector!(uint[16]) uint16; /// +static if (is(Vector!(long[8]))) alias Vector!(long[8]) long8; /// +static if (is(Vector!(ulong[8]))) alias Vector!(ulong[8]) ulong8; /// version (D_SIMD) { - /** XMM opcodes that conform to the following: - * - * opcode xmm1,xmm2/mem - * - * and do not have side effects (i.e. do not write to memory). - */ - enum XMM - { - ADDSS = 0xF30F58, - ADDSD = 0xF20F58, - ADDPS = 0x000F58, - ADDPD = 0x660F58, - PADDB = 0x660FFC, - PADDW = 0x660FFD, - PADDD = 0x660FFE, - PADDQ = 0x660FD4, - - SUBSS = 0xF30F5C, - SUBSD = 0xF20F5C, - SUBPS = 0x000F5C, - SUBPD = 0x660F5C, - PSUBB = 0x660FF8, - PSUBW = 0x660FF9, - PSUBD = 0x660FFA, - PSUBQ = 0x660FFB, - - MULSS = 0xF30F59, - MULSD = 0xF20F59, - MULPS = 0x000F59, - MULPD = 0x660F59, - PMULLW = 0x660FD5, - - DIVSS = 0xF30F5E, - DIVSD = 0xF20F5E, - DIVPS = 0x000F5E, - DIVPD = 0x660F5E, - - PAND = 0x660FDB, - POR = 0x660FEB, - - UCOMISS = 0x000F2E, - UCOMISD = 0x660F2E, - - XORPS = 0x000F57, - XORPD = 0x660F57, - - // Use STO and LOD instead of MOV to distinguish the direction - STOSS = 0xF30F11, - STOSD = 0xF20F11, - STOAPS = 0x000F29, - STOAPD = 0x660F29, - STODQA = 0x660F7F, - STOD = 0x660F7E, // MOVD reg/mem64, xmm 66 0F 7E /r - STOQ = 0x660FD6, - - LODSS = 0xF30F10, - LODSD = 0xF20F10, - LODAPS = 0x000F28, - LODAPD = 0x660F28, - LODDQA = 0x660F6F, - LODD = 0x660F6E, // MOVD xmm, reg/mem64 66 0F 6E /r - LODQ = 0xF30F7E, - - LODDQU = 0xF30F6F, // MOVDQU xmm1, xmm2/mem128 F3 0F 6F /r - STODQU = 0xF30F7F, // MOVDQU xmm1/mem128, xmm2 F3 0F 7F /r - MOVDQ2Q = 0xF20FD6, // MOVDQ2Q mmx, xmm F2 0F D6 /r - MOVHLPS = 0x0F12, // MOVHLPS xmm1, xmm2 0F 12 /r - LODHPD = 0x660F16, - STOHPD = 0x660F17, // MOVHPD mem64, xmm 66 0F 17 /r - LODHPS = 0x0F16, - STOHPS = 0x0F17, - MOVLHPS = 0x0F16, - LODLPD = 0x660F12, - STOLPD = 0x660F13, - LODLPS = 0x0F12, - STOLPS = 0x0F13, - MOVMSKPD = 0x660F50, - MOVMSKPS = 0x0F50, - MOVNTDQ = 0x660FE7, - MOVNTI = 0x0FC3, - MOVNTPD = 0x660F2B, - MOVNTPS = 0x0F2B, - MOVNTQ = 0x0FE7, - MOVQ2DQ = 0xF30FD6, - LODUPD = 0x660F10, - STOUPD = 0x660F11, - LODUPS = 0x0F10, - STOUPS = 0x0F11, - - PACKSSDW = 0x660F6B, - PACKSSWB = 0x660F63, - PACKUSWB = 0x660F67, - PADDSB = 0x660FEC, - PADDSW = 0x660FED, - PADDUSB = 0x660FDC, - PADDUSW = 0x660FDD, - PANDN = 0x660FDF, - PCMPEQB = 0x660F74, - PCMPEQD = 0x660F76, - PCMPEQW = 0x660F75, - PCMPGTB = 0x660F64, - PCMPGTD = 0x660F66, - PCMPGTW = 0x660F65, - PMADDWD = 0x660FF5, - PSLLW = 0x660FF1, - PSLLD = 0x660FF2, - PSLLQ = 0x660FF3, - PSRAW = 0x660FE1, - PSRAD = 0x660FE2, - PSRLW = 0x660FD1, - PSRLD = 0x660FD2, - PSRLQ = 0x660FD3, - PSUBSB = 0x660FE8, - PSUBSW = 0x660FE9, - PSUBUSB = 0x660FD8, - PSUBUSW = 0x660FD9, - PUNPCKHBW = 0x660F68, - PUNPCKHDQ = 0x660F6A, - PUNPCKHWD = 0x660F69, - PUNPCKLBW = 0x660F60, - PUNPCKLDQ = 0x660F62, - PUNPCKLWD = 0x660F61, - PXOR = 0x660FEF, - ANDPD = 0x660F54, - ANDPS = 0x0F54, - ANDNPD = 0x660F55, - ANDNPS = 0x0F55, - CMPPS = 0x0FC2, - CMPPD = 0x660FC2, - CMPSD = 0xF20FC2, - CMPSS = 0xF30FC2, - COMISD = 0x660F2F, - COMISS = 0x0F2F, - CVTDQ2PD = 0xF30FE6, - CVTDQ2PS = 0x0F5B, - CVTPD2DQ = 0xF20FE6, - CVTPD2PI = 0x660F2D, - CVTPD2PS = 0x660F5A, - CVTPI2PD = 0x660F2A, - CVTPI2PS = 0x0F2A, - CVTPS2DQ = 0x660F5B, - CVTPS2PD = 0x0F5A, - CVTPS2PI = 0x0F2D, - CVTSD2SI = 0xF20F2D, - CVTSD2SS = 0xF20F5A, - CVTSI2SD = 0xF20F2A, - CVTSI2SS = 0xF30F2A, - CVTSS2SD = 0xF30F5A, - CVTSS2SI = 0xF30F2D, - CVTTPD2PI = 0x660F2C, - CVTTPD2DQ = 0x660FE6, - CVTTPS2DQ = 0xF30F5B, - CVTTPS2PI = 0x0F2C, - CVTTSD2SI = 0xF20F2C, - CVTTSS2SI = 0xF30F2C, - MASKMOVDQU = 0x660FF7, - MASKMOVQ = 0x0FF7, - MAXPD = 0x660F5F, - MAXPS = 0x0F5F, - MAXSD = 0xF20F5F, - MAXSS = 0xF30F5F, - MINPD = 0x660F5D, - MINPS = 0x0F5D, - MINSD = 0xF20F5D, - MINSS = 0xF30F5D, - ORPD = 0x660F56, - ORPS = 0x0F56, - PAVGB = 0x660FE0, - PAVGW = 0x660FE3, - PMAXSW = 0x660FEE, - //PINSRW = 0x660FC4, - PMAXUB = 0x660FDE, - PMINSW = 0x660FEA, - PMINUB = 0x660FDA, - //PMOVMSKB = 0x660FD7, - PMULHUW = 0x660FE4, - PMULHW = 0x660FE5, - PMULUDQ = 0x660FF4, - PSADBW = 0x660FF6, - PUNPCKHQDQ = 0x660F6D, - PUNPCKLQDQ = 0x660F6C, - RCPPS = 0x0F53, - RCPSS = 0xF30F53, - RSQRTPS = 0x0F52, - RSQRTSS = 0xF30F52, - SQRTPD = 0x660F51, - SHUFPD = 0x660FC6, - SHUFPS = 0x0FC6, - SQRTPS = 0x0F51, - SQRTSD = 0xF20F51, - SQRTSS = 0xF30F51, - UNPCKHPD = 0x660F15, - UNPCKHPS = 0x0F15, - UNPCKLPD = 0x660F14, - UNPCKLPS = 0x0F14, - - PSHUFD = 0x660F70, - PSHUFHW = 0xF30F70, - PSHUFLW = 0xF20F70, - PSHUFW = 0x0F70, - PSLLDQ = 0x07660F73, - PSRLDQ = 0x03660F73, - - //PREFETCH = 0x0F18, - -// SSE3 Pentium 4 (Prescott) - - ADDSUBPD = 0x660FD0, - ADDSUBPS = 0xF20FD0, - HADDPD = 0x660F7C, - HADDPS = 0xF20F7C, - HSUBPD = 0x660F7D, - HSUBPS = 0xF20F7D, - MOVDDUP = 0xF20F12, - MOVSHDUP = 0xF30F16, - MOVSLDUP = 0xF30F12, - LDDQU = 0xF20FF0, - MONITOR = 0x0F01C8, - MWAIT = 0x0F01C9, - -// SSSE3 - PALIGNR = 0x660F3A0F, - PHADDD = 0x660F3802, - PHADDW = 0x660F3801, - PHADDSW = 0x660F3803, - PABSB = 0x660F381C, - PABSD = 0x660F381E, - PABSW = 0x660F381D, - PSIGNB = 0x660F3808, - PSIGND = 0x660F380A, - PSIGNW = 0x660F3809, - PSHUFB = 0x660F3800, - PMADDUBSW = 0x660F3804, - PMULHRSW = 0x660F380B, - PHSUBD = 0x660F3806, - PHSUBW = 0x660F3805, - PHSUBSW = 0x660F3807, - -// SSE4.1 - - BLENDPD = 0x660F3A0D, - BLENDPS = 0x660F3A0C, - BLENDVPD = 0x660F3815, - BLENDVPS = 0x660F3814, - DPPD = 0x660F3A41, - DPPS = 0x660F3A40, - EXTRACTPS = 0x660F3A17, - INSERTPS = 0x660F3A21, - MPSADBW = 0x660F3A42, - PBLENDVB = 0x660F3810, - PBLENDW = 0x660F3A0E, - PEXTRD = 0x660F3A16, - PEXTRQ = 0x660F3A16, - PINSRB = 0x660F3A20, - PINSRD = 0x660F3A22, - PINSRQ = 0x660F3A22, - - MOVNTDQA = 0x660F382A, - PACKUSDW = 0x660F382B, - PCMPEQQ = 0x660F3829, - PEXTRB = 0x660F3A14, - PHMINPOSUW = 0x660F3841, - PMAXSB = 0x660F383C, - PMAXSD = 0x660F383D, - PMAXUD = 0x660F383F, - PMAXUW = 0x660F383E, - PMINSB = 0x660F3838, - PMINSD = 0x660F3839, - PMINUD = 0x660F383B, - PMINUW = 0x660F383A, - PMOVSXBW = 0x660F3820, - PMOVSXBD = 0x660F3821, - PMOVSXBQ = 0x660F3822, - PMOVSXWD = 0x660F3823, - PMOVSXWQ = 0x660F3824, - PMOVSXDQ = 0x660F3825, - PMOVZXBW = 0x660F3830, - PMOVZXBD = 0x660F3831, - PMOVZXBQ = 0x660F3832, - PMOVZXWD = 0x660F3833, - PMOVZXWQ = 0x660F3834, - PMOVZXDQ = 0x660F3835, - PMULDQ = 0x660F3828, - PMULLD = 0x660F3840, - PTEST = 0x660F3817, - - ROUNDPD = 0x660F3A09, - ROUNDPS = 0x660F3A08, - ROUNDSD = 0x660F3A0B, - ROUNDSS = 0x660F3A0A, - -// SSE4.2 - PCMPESTRI = 0x660F3A61, - PCMPESTRM = 0x660F3A60, - PCMPISTRI = 0x660F3A63, - PCMPISTRM = 0x660F3A62, - PCMPGTQ = 0x660F3837, - //CRC32 - -// SSE4a (AMD only) - // EXTRQ,INSERTQ,MOVNTSD,MOVNTSS - -// POPCNT and LZCNT (have their own CPUID bits) - POPCNT = 0xF30FB8, - // LZCNT - } - - /** - * Generate two operand instruction with XMM 128 bit operands. - * - * This is a compiler magic function - it doesn't behave like - * regular D functions. - * - * Parameters: - * opcode any of the XMM opcodes; it must be a compile time constant - * op1 first operand - * op2 second operand - * Returns: - * result of opcode - */ - pure @safe void16 __simd(XMM opcode, void16 op1, void16 op2); - - /** - * Unary SIMD instructions. - */ - pure @safe void16 __simd(XMM opcode, void16 op1); - pure @safe void16 __simd(XMM opcode, double d); /// - pure @safe void16 __simd(XMM opcode, float f); /// - - /**** - * For instructions: - * CMPPD, CMPSS, CMPSD, CMPPS, - * PSHUFD, PSHUFHW, PSHUFLW, - * BLENDPD, BLENDPS, DPPD, DPPS, - * MPSADBW, PBLENDW, - * ROUNDPD, ROUNDPS, ROUNDSD, ROUNDSS - * Parameters: - * opcode any of the above XMM opcodes; it must be a compile time constant - * op1 first operand - * op2 second operand - * imm8 third operand; must be a compile time constant - * Returns: - * result of opcode - */ - pure @safe void16 __simd(XMM opcode, void16 op1, void16 op2, ubyte imm8); - - /*** - * For instructions with the imm8 version: - * PSLLD, PSLLQ, PSLLW, PSRAD, PSRAW, PSRLD, PSRLQ, PSRLW, - * PSRLDQ, PSLLDQ - * Parameters: - * opcode any of the XMM opcodes; it must be a compile time constant - * op1 first operand - * imm8 second operand; must be a compile time constant - * Returns: - * result of opcode - */ - pure @safe void16 __simd_ib(XMM opcode, void16 op1, ubyte imm8); - - /***** - * For "store" operations of the form: - * op1 op= op2 - * Returns: - * op2 - * These cannot be marked as pure, as semantic() doesn't check them. - */ - @safe void16 __simd_sto(XMM opcode, void16 op1, void16 op2); - @safe void16 __simd_sto(XMM opcode, double op1, void16 op2); /// - @safe void16 __simd_sto(XMM opcode, float op1, void16 op2); /// - - /* The following use overloading to ensure correct typing. - * Compile with inlining on for best performance. - */ - - pure @safe short8 pcmpeq()(short8 v1, short8 v2) - { - return __simd(XMM.PCMPEQW, v1, v2); - } - - pure @safe ushort8 pcmpeq()(ushort8 v1, ushort8 v2) - { - return __simd(XMM.PCMPEQW, v1, v2); - } - - /********************* - * Emit prefetch instruction. - * Params: - * address = address to be prefetched - * writeFetch = true for write fetch, false for read fetch - * locality = 0..3 (0 meaning least local, 3 meaning most local) - * Note: - * The Intel mappings are: - * $(TABLE - * $(THEAD writeFetch, locality, Instruction) - * $(TROW false, 0, prefetchnta) - * $(TROW false, 1, prefetch2) - * $(TROW false, 2, prefetch1) - * $(TROW false, 3, prefetch0) - * $(TROW false, 0, prefetchw) - * $(TROW false, 1, prefetchw) - * $(TROW false, 2, prefetchw) - * $(TROW false, 3, prefetchw) - * ) - */ - void prefetch(bool writeFetch, ubyte locality)(const(void)* address) - { + /** XMM opcodes that conform to the following: + * + * opcode xmm1,xmm2/mem + * + * and do not have side effects (i.e. do not write to memory). + */ + enum XMM + { + ADDSS = 0xF30F58, + ADDSD = 0xF20F58, + ADDPS = 0x000F58, + ADDPD = 0x660F58, + PADDB = 0x660FFC, + PADDW = 0x660FFD, + PADDD = 0x660FFE, + PADDQ = 0x660FD4, + + SUBSS = 0xF30F5C, + SUBSD = 0xF20F5C, + SUBPS = 0x000F5C, + SUBPD = 0x660F5C, + PSUBB = 0x660FF8, + PSUBW = 0x660FF9, + PSUBD = 0x660FFA, + PSUBQ = 0x660FFB, + + MULSS = 0xF30F59, + MULSD = 0xF20F59, + MULPS = 0x000F59, + MULPD = 0x660F59, + PMULLW = 0x660FD5, + + DIVSS = 0xF30F5E, + DIVSD = 0xF20F5E, + DIVPS = 0x000F5E, + DIVPD = 0x660F5E, + + PAND = 0x660FDB, + POR = 0x660FEB, + + UCOMISS = 0x000F2E, + UCOMISD = 0x660F2E, + + XORPS = 0x000F57, + XORPD = 0x660F57, + + // Use STO and LOD instead of MOV to distinguish the direction + // (Destination is first operand, Source is second operand) + STOSS = 0xF30F11, /// MOVSS xmm1/m32, xmm2 + STOSD = 0xF20F11, /// MOVSD xmm1/m64, xmm2 + STOAPS = 0x000F29, /// MOVAPS xmm2/m128, xmm1 + STOAPD = 0x660F29, /// MOVAPD xmm2/m128, xmm1 + STODQA = 0x660F7F, /// MOVDQA xmm2/m128, xmm1 + STOD = 0x660F7E, /// MOVD reg/mem64, xmm 66 0F 7E /r + STOQ = 0x660FD6, /// MOVQ xmm2/m64, xmm1 + + LODSS = 0xF30F10, /// MOVSS xmm1, xmm2/m32 + LODSD = 0xF20F10, /// MOVSD xmm1, xmm2/m64 + LODAPS = 0x000F28, /// MOVAPS xmm1, xmm2/m128 + LODAPD = 0x660F28, /// MOVAPD xmm1, xmm2/m128 + LODDQA = 0x660F6F, /// MOVDQA xmm1, xmm2/m128 + LODD = 0x660F6E, /// MOVD xmm, reg/mem64 66 0F 6E /r + LODQ = 0xF30F7E, /// MOVQ xmm1, xmm2/m64 + + LODDQU = 0xF30F6F, /// MOVDQU xmm1, xmm2/mem128 F3 0F 6F /r + STODQU = 0xF30F7F, /// MOVDQU xmm1/mem128, xmm2 F3 0F 7F /r + MOVDQ2Q = 0xF20FD6, /// MOVDQ2Q mmx, xmm F2 0F D6 /r + MOVHLPS = 0x0F12, /// MOVHLPS xmm1, xmm2 0F 12 /r + LODHPD = 0x660F16, /// MOVHPD xmm1, m64 + STOHPD = 0x660F17, /// MOVHPD mem64, xmm1 66 0F 17 /r + LODHPS = 0x0F16, /// MOVHPS xmm1, m64 + STOHPS = 0x0F17, /// MOVHPS m64, xmm1 + MOVLHPS = 0x0F16, /// MOVLHPS xmm1, xmm2 + LODLPD = 0x660F12, /// MOVLPD xmm1, m64 + STOLPD = 0x660F13, /// MOVLPD m64, xmm1 + LODLPS = 0x0F12, /// MOVLPS xmm1, m64 + STOLPS = 0x0F13, /// MOVLPS m64, xmm1 + MOVMSKPD = 0x660F50, /// MOVMSKPD reg, xmm + MOVMSKPS = 0x0F50, /// MOVMSKPS reg, xmm + MOVNTDQ = 0x660FE7, /// MOVNTDQ m128, xmm1 + MOVNTI = 0x0FC3, /// MOVNTI m32, r32 + MOVNTPD = 0x660F2B, /// MOVNTPD m128, xmm1 + MOVNTPS = 0x0F2B, /// MOVNTPS m128, xmm1 + MOVNTQ = 0x0FE7, /// MOVNTQ m64, mm + MOVQ2DQ = 0xF30FD6, /// MOVQ2DQ + LODUPD = 0x660F10, /// MOVUPD xmm1, xmm2/m128 + STOUPD = 0x660F11, /// MOVUPD xmm2/m128, xmm1 + LODUPS = 0x0F10, /// MOVUPS xmm1, xmm2/m128 + STOUPS = 0x0F11, /// MOVUPS xmm2/m128, xmm1 + + PACKSSDW = 0x660F6B, + PACKSSWB = 0x660F63, + PACKUSWB = 0x660F67, + PADDSB = 0x660FEC, + PADDSW = 0x660FED, + PADDUSB = 0x660FDC, + PADDUSW = 0x660FDD, + PANDN = 0x660FDF, + PCMPEQB = 0x660F74, + PCMPEQD = 0x660F76, + PCMPEQW = 0x660F75, + PCMPGTB = 0x660F64, + PCMPGTD = 0x660F66, + PCMPGTW = 0x660F65, + PMADDWD = 0x660FF5, + PSLLW = 0x660FF1, + PSLLD = 0x660FF2, + PSLLQ = 0x660FF3, + PSRAW = 0x660FE1, + PSRAD = 0x660FE2, + PSRLW = 0x660FD1, + PSRLD = 0x660FD2, + PSRLQ = 0x660FD3, + PSUBSB = 0x660FE8, + PSUBSW = 0x660FE9, + PSUBUSB = 0x660FD8, + PSUBUSW = 0x660FD9, + PUNPCKHBW = 0x660F68, + PUNPCKHDQ = 0x660F6A, + PUNPCKHWD = 0x660F69, + PUNPCKLBW = 0x660F60, + PUNPCKLDQ = 0x660F62, + PUNPCKLWD = 0x660F61, + PXOR = 0x660FEF, + ANDPD = 0x660F54, + ANDPS = 0x0F54, + ANDNPD = 0x660F55, + ANDNPS = 0x0F55, + CMPPS = 0x0FC2, + CMPPD = 0x660FC2, + CMPSD = 0xF20FC2, + CMPSS = 0xF30FC2, + COMISD = 0x660F2F, + COMISS = 0x0F2F, + CVTDQ2PD = 0xF30FE6, + CVTDQ2PS = 0x0F5B, + CVTPD2DQ = 0xF20FE6, + CVTPD2PI = 0x660F2D, + CVTPD2PS = 0x660F5A, + CVTPI2PD = 0x660F2A, + CVTPI2PS = 0x0F2A, + CVTPS2DQ = 0x660F5B, + CVTPS2PD = 0x0F5A, + CVTPS2PI = 0x0F2D, + CVTSD2SI = 0xF20F2D, + CVTSD2SS = 0xF20F5A, + CVTSI2SD = 0xF20F2A, + CVTSI2SS = 0xF30F2A, + CVTSS2SD = 0xF30F5A, + CVTSS2SI = 0xF30F2D, + CVTTPD2PI = 0x660F2C, + CVTTPD2DQ = 0x660FE6, + CVTTPS2DQ = 0xF30F5B, + CVTTPS2PI = 0x0F2C, + CVTTSD2SI = 0xF20F2C, + CVTTSS2SI = 0xF30F2C, + MASKMOVDQU = 0x660FF7, + MASKMOVQ = 0x0FF7, + MAXPD = 0x660F5F, + MAXPS = 0x0F5F, + MAXSD = 0xF20F5F, + MAXSS = 0xF30F5F, + MINPD = 0x660F5D, + MINPS = 0x0F5D, + MINSD = 0xF20F5D, + MINSS = 0xF30F5D, + ORPD = 0x660F56, + ORPS = 0x0F56, + PAVGB = 0x660FE0, + PAVGW = 0x660FE3, + PMAXSW = 0x660FEE, + //PINSRW = 0x660FC4, + PMAXUB = 0x660FDE, + PMINSW = 0x660FEA, + PMINUB = 0x660FDA, + //PMOVMSKB = 0x660FD7, + PMULHUW = 0x660FE4, + PMULHW = 0x660FE5, + PMULUDQ = 0x660FF4, + PSADBW = 0x660FF6, + PUNPCKHQDQ = 0x660F6D, + PUNPCKLQDQ = 0x660F6C, + RCPPS = 0x0F53, + RCPSS = 0xF30F53, + RSQRTPS = 0x0F52, + RSQRTSS = 0xF30F52, + SQRTPD = 0x660F51, + SHUFPD = 0x660FC6, + SHUFPS = 0x0FC6, + SQRTPS = 0x0F51, + SQRTSD = 0xF20F51, + SQRTSS = 0xF30F51, + UNPCKHPD = 0x660F15, + UNPCKHPS = 0x0F15, + UNPCKLPD = 0x660F14, + UNPCKLPS = 0x0F14, + + PSHUFD = 0x660F70, + PSHUFHW = 0xF30F70, + PSHUFLW = 0xF20F70, + PSHUFW = 0x0F70, + PSLLDQ = 0x07660F73, + PSRLDQ = 0x03660F73, + + //PREFETCH = 0x0F18, + + // SSE3 Pentium 4 (Prescott) + + ADDSUBPD = 0x660FD0, + ADDSUBPS = 0xF20FD0, + HADDPD = 0x660F7C, + HADDPS = 0xF20F7C, + HSUBPD = 0x660F7D, + HSUBPS = 0xF20F7D, + MOVDDUP = 0xF20F12, + MOVSHDUP = 0xF30F16, + MOVSLDUP = 0xF30F12, + LDDQU = 0xF20FF0, + MONITOR = 0x0F01C8, + MWAIT = 0x0F01C9, + + // SSSE3 + PALIGNR = 0x660F3A0F, + PHADDD = 0x660F3802, + PHADDW = 0x660F3801, + PHADDSW = 0x660F3803, + PABSB = 0x660F381C, + PABSD = 0x660F381E, + PABSW = 0x660F381D, + PSIGNB = 0x660F3808, + PSIGND = 0x660F380A, + PSIGNW = 0x660F3809, + PSHUFB = 0x660F3800, + PMADDUBSW = 0x660F3804, + PMULHRSW = 0x660F380B, + PHSUBD = 0x660F3806, + PHSUBW = 0x660F3805, + PHSUBSW = 0x660F3807, + + // SSE4.1 + + BLENDPD = 0x660F3A0D, + BLENDPS = 0x660F3A0C, + BLENDVPD = 0x660F3815, + BLENDVPS = 0x660F3814, + DPPD = 0x660F3A41, + DPPS = 0x660F3A40, + EXTRACTPS = 0x660F3A17, + INSERTPS = 0x660F3A21, + MPSADBW = 0x660F3A42, + PBLENDVB = 0x660F3810, + PBLENDW = 0x660F3A0E, + PEXTRD = 0x660F3A16, + PEXTRQ = 0x660F3A16, + PINSRB = 0x660F3A20, + PINSRD = 0x660F3A22, + PINSRQ = 0x660F3A22, + + MOVNTDQA = 0x660F382A, + PACKUSDW = 0x660F382B, + PCMPEQQ = 0x660F3829, + PEXTRB = 0x660F3A14, + PHMINPOSUW = 0x660F3841, + PMAXSB = 0x660F383C, + PMAXSD = 0x660F383D, + PMAXUD = 0x660F383F, + PMAXUW = 0x660F383E, + PMINSB = 0x660F3838, + PMINSD = 0x660F3839, + PMINUD = 0x660F383B, + PMINUW = 0x660F383A, + PMOVSXBW = 0x660F3820, + PMOVSXBD = 0x660F3821, + PMOVSXBQ = 0x660F3822, + PMOVSXWD = 0x660F3823, + PMOVSXWQ = 0x660F3824, + PMOVSXDQ = 0x660F3825, + PMOVZXBW = 0x660F3830, + PMOVZXBD = 0x660F3831, + PMOVZXBQ = 0x660F3832, + PMOVZXWD = 0x660F3833, + PMOVZXWQ = 0x660F3834, + PMOVZXDQ = 0x660F3835, + PMULDQ = 0x660F3828, + PMULLD = 0x660F3840, + PTEST = 0x660F3817, + + ROUNDPD = 0x660F3A09, + ROUNDPS = 0x660F3A08, + ROUNDSD = 0x660F3A0B, + ROUNDSS = 0x660F3A0A, + + // SSE4.2 + PCMPESTRI = 0x660F3A61, + PCMPESTRM = 0x660F3A60, + PCMPISTRI = 0x660F3A63, + PCMPISTRM = 0x660F3A62, + PCMPGTQ = 0x660F3837, + //CRC32 + + // SSE4a (AMD only) + // EXTRQ,INSERTQ,MOVNTSD,MOVNTSS + + // POPCNT and LZCNT (have their own CPUID bits) + POPCNT = 0xF30FB8, + // LZCNT + } + + /** + * Generate two operand instruction with XMM 128 bit operands. + * + * This is a compiler magic function - it doesn't behave like + * regular D functions. + * + * Parameters: + * opcode = any of the XMM opcodes; it must be a compile time constant + * op1 = first operand + * op2 = second operand + * Returns: + * result of opcode + */ + pure @safe void16 __simd(XMM opcode, void16 op1, void16 op2); + + /// + unittest + { + float4 a; + a = cast(float4)__simd(XMM.PXOR, a, a); + } + + /** + * Unary SIMD instructions. + */ + pure @safe void16 __simd(XMM opcode, void16 op1); + pure @safe void16 __simd(XMM opcode, double d); /// + pure @safe void16 __simd(XMM opcode, float f); /// + + /// + unittest + { + float4 a; + a = cast(float4)__simd(XMM.LODSS, a); + } + + /**** + * For instructions: + * CMPPD, CMPSS, CMPSD, CMPPS, + * PSHUFD, PSHUFHW, PSHUFLW, + * BLENDPD, BLENDPS, DPPD, DPPS, + * MPSADBW, PBLENDW, + * ROUNDPD, ROUNDPS, ROUNDSD, ROUNDSS + * Parameters: + * opcode = any of the above XMM opcodes; it must be a compile time constant + * op1 = first operand + * op2 = second operand + * imm8 = third operand; must be a compile time constant + * Returns: + * result of opcode + */ + pure @safe void16 __simd(XMM opcode, void16 op1, void16 op2, ubyte imm8); + + /// + unittest + { + float4 a; + a = cast(float4)__simd(XMM.CMPPD, a, a, 0x7A); + } + + /*** + * For instructions with the imm8 version: + * PSLLD, PSLLQ, PSLLW, PSRAD, PSRAW, PSRLD, PSRLQ, PSRLW, + * PSRLDQ, PSLLDQ + * Parameters: + * opcode = any of the XMM opcodes; it must be a compile time constant + * op1 = first operand + * imm8 = second operand; must be a compile time constant + * Returns: + * result of opcode + */ + pure @safe void16 __simd_ib(XMM opcode, void16 op1, ubyte imm8); + + /// + unittest + { + float4 a; + a = cast(float4) __simd_ib(XMM.PSRLQ, a, 0x7A); + } + + /***** + * For "store" operations of the form: + * op1 op= op2 + * Returns: + * op2 + * These cannot be marked as pure, as semantic() doesn't check them. + */ + @safe void16 __simd_sto(XMM opcode, void16 op1, void16 op2); + @safe void16 __simd_sto(XMM opcode, double op1, void16 op2); /// + @safe void16 __simd_sto(XMM opcode, float op1, void16 op2); /// + + /// + unittest + { + void16 a; + float f = 1; + double d = 1; + + cast(void)__simd_sto(XMM.STOUPS, a, a); + cast(void)__simd_sto(XMM.STOUPS, f, a); + cast(void)__simd_sto(XMM.STOUPS, d, a); + } + + /* The following use overloading to ensure correct typing. + * Compile with inlining on for best performance. + */ + + pure @safe short8 pcmpeq()(short8 v1, short8 v2) + { + return cast(short8)__simd(XMM.PCMPEQW, v1, v2); + } + + pure @safe ushort8 pcmpeq()(ushort8 v1, ushort8 v2) + { + return cast(ushort8)__simd(XMM.PCMPEQW, v1, v2); + } + + /********************* + * Emit prefetch instruction. + * Params: + * address = address to be prefetched + * writeFetch = true for write fetch, false for read fetch + * locality = 0..3 (0 meaning least local, 3 meaning most local) + * Note: + * The Intel mappings are: + * $(TABLE + * $(THEAD writeFetch, locality, Instruction) + * $(TROW false, 0, prefetchnta) + * $(TROW false, 1, prefetch2) + * $(TROW false, 2, prefetch1) + * $(TROW false, 3, prefetch0) + * $(TROW true, 0, prefetchw) + * $(TROW true, 1, prefetchw) + * $(TROW true, 2, prefetchw) + * $(TROW true, 3, prefetchw) + * ) + */ + void prefetch(bool writeFetch, ubyte locality)(const(void)* address) + { static if (writeFetch) __prefetch(address, 4); else static if (locality < 4) __prefetch(address, 3 - locality); else static assert(0, "0..3 expected for locality"); - } + } - private void __prefetch(const(void*) address, ubyte encoding); + private void __prefetch(const(void*) address, ubyte encoding); - /************************************* - * Load unaligned vector from address. - * This is a compiler intrinsic. - * Params: - * p = pointer to vector - * Returns: - * vector - */ + /************************************* + * Load unaligned vector from address. + * This is a compiler intrinsic. + * Params: + * p = pointer to vector + * Returns: + * vector + */ - V loadUnaligned(V)(const V* p) + V loadUnaligned(V)(const V* p) if (is(V == void16) || is(V == byte16) || is(V == ubyte16) || @@ -510,8 +564,10 @@ version (D_SIMD) is(V == int4) || is(V == uint4) || is(V == long2) || - is(V == ulong2)) - { + is(V == ulong2) || + is(V == double2) || + is(V == float4)) + { pragma(inline, true); static if (is(V == double2)) return cast(V)__simd(XMM.LODUPD, *cast(const void16*)p); @@ -519,19 +575,63 @@ version (D_SIMD) return cast(V)__simd(XMM.LODUPS, *cast(const void16*)p); else return cast(V)__simd(XMM.LODDQU, *cast(const void16*)p); - } - - /************************************* - * Store vector to unaligned address. - * This is a compiler intrinsic. - * Params: - * p = pointer to vector - * value = value to store - * Returns: - * value - */ - - V storeUnaligned(V)(V* p, V value) + } + + @system + unittest + { + // Memory to load into the vector: + // Should have enough data to test all 16-byte alignments, and still + // have room for a 16-byte vector + ubyte[32] data; + foreach (i; 0..data.length) + { + data[i] = cast(ubyte)i; + } + + // to test all alignments from 1 ~ 16 + foreach (i; 0..16) + { + ubyte* d = &data[i]; + + void test(T)() + { + // load the data + T v = loadUnaligned(cast(T*)d); + + // check that the data was loaded correctly + ubyte* ptrToV = cast(ubyte*)&v; + foreach (j; 0..T.sizeof) + { + assert(ptrToV[j] == d[j]); + } + } + + test!void16(); + test!byte16(); + test!ubyte16(); + test!short8(); + test!ushort8(); + test!int4(); + test!uint4(); + test!long2(); + test!ulong2(); + test!double2(); + test!float4(); + } + } + + /************************************* + * Store vector to unaligned address. + * This is a compiler intrinsic. + * Params: + * p = pointer to vector + * value = value to store + * Returns: + * value + */ + + V storeUnaligned(V)(V* p, V value) if (is(V == void16) || is(V == byte16) || is(V == ubyte16) || @@ -540,8 +640,10 @@ version (D_SIMD) is(V == int4) || is(V == uint4) || is(V == long2) || - is(V == ulong2)) - { + is(V == ulong2) || + is(V == double2) || + is(V == float4)) + { pragma(inline, true); static if (is(V == double2)) return cast(V)__simd_sto(XMM.STOUPD, *cast(void16*)p, value); @@ -549,5 +651,53 @@ version (D_SIMD) return cast(V)__simd_sto(XMM.STOUPS, *cast(void16*)p, value); else return cast(V)__simd_sto(XMM.STODQU, *cast(void16*)p, value); - } + } + + @system + unittest + { + // Memory to store the vector to: + // Should have enough data to test all 16-byte alignments, and still + // have room for a 16-byte vector + ubyte[32] data; + + // to test all alignments from 1 ~ 16 + foreach (i; 0..16) + { + ubyte* d = &data[i]; + + void test(T)() + { + T v; + + // populate v` with data + ubyte* ptrToV = cast(ubyte*)&v; + foreach (j; 0..T.sizeof) + { + ptrToV[j] = cast(ubyte)j; + } + + // store `v` to location pointed to by `d` + storeUnaligned(cast(T*)d, v); + + // check that the the data was stored correctly + foreach (j; 0..T.sizeof) + { + assert(ptrToV[j] == d[j]); + } + } + + test!void16(); + test!byte16(); + test!ubyte16(); + test!short8(); + test!ushort8(); + test!int4(); + test!uint4(); + test!long2(); + test!ulong2(); + test!double2(); + test!float4(); + } + } } diff --git a/libphobos/libdruntime/core/stdc/stdio.d b/libphobos/libdruntime/core/stdc/stdio.d index 00efe88..6701159 100644 --- a/libphobos/libdruntime/core/stdc/stdio.d +++ b/libphobos/libdruntime/core/stdc/stdio.d @@ -1527,7 +1527,7 @@ else version (OpenBSD) { void __sclearerr()(FILE* p) { - p._flags &= ~(__SERR|__SEOF); + p._flags = p._flags & ~(__SERR|__SEOF); } int __sfeof()(FILE* p) diff --git a/libphobos/libdruntime/core/sys/bionic/stdlib.d b/libphobos/libdruntime/core/sys/bionic/stdlib.d new file mode 100644 index 0000000..46fabe5 --- /dev/null +++ b/libphobos/libdruntime/core/sys/bionic/stdlib.d @@ -0,0 +1,17 @@ +/** + * D header file for Bionic stdlib.h. + * + * Copyright: Copyright © 2021, The D Language Foundation + * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. + * Authors: Iain Buclaw + */ +module core.sys.bionic.stdlib; +public import core.sys.posix.stdlib; + +version (CRuntime_Bionic): +extern (C): +nothrow: +@nogc: + +const(char)* getprogname(); +void setprogname(scope const char* name); diff --git a/libphobos/libdruntime/core/sys/darwin/mach/dyld.d b/libphobos/libdruntime/core/sys/darwin/mach/dyld.d index 62d1a77..6e28bfa 100644 --- a/libphobos/libdruntime/core/sys/darwin/mach/dyld.d +++ b/libphobos/libdruntime/core/sys/darwin/mach/dyld.d @@ -33,7 +33,10 @@ uint _dyld_image_count(); const(char)* _dyld_get_image_name(uint image_index); mach_header* _dyld_get_image_header(uint image_index); intptr_t _dyld_get_image_vmaddr_slide(uint image_index); + void _dyld_register_func_for_add_image(void function(const scope mach_header* mh, intptr_t vmaddr_slide)); void _dyld_register_func_for_remove_image(void function(const scope mach_header* mh, intptr_t vmaddr_slide)); - +int NSVersionOfRunTimeLibrary(const char* libraryPath); +int NSVersionOfLinkTimeLibrary(const char* libraryPath); +int _NSGetExecutablePath(char* buf, uint* bufsize); diff --git a/libphobos/libdruntime/core/sys/darwin/stdlib.d b/libphobos/libdruntime/core/sys/darwin/stdlib.d new file mode 100644 index 0000000..287eaa0 --- /dev/null +++ b/libphobos/libdruntime/core/sys/darwin/stdlib.d @@ -0,0 +1,26 @@ +/** + * D header file for Darwin stdlib.h. + * + * Copyright: Copyright © 2021, The D Language Foundation + * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. + * Authors: Iain Buclaw + */ +module core.sys.darwin.stdlib; +public import core.sys.posix.stdlib; + +version (OSX) + version = Darwin; +else version (iOS) + version = Darwin; +else version (TVOS) + version = Darwin; +else version (WatchOS) + version = Darwin; + +version (Darwin): +extern (C): +nothrow: +@nogc: + +const(char)* getprogname(); +void setprogname(scope const char* name); diff --git a/libphobos/libdruntime/core/sys/darwin/sys/sysctl.d b/libphobos/libdruntime/core/sys/darwin/sys/sysctl.d new file mode 100644 index 0000000..6af16cc8 --- /dev/null +++ b/libphobos/libdruntime/core/sys/darwin/sys/sysctl.d @@ -0,0 +1,253 @@ +/** + * D header file for Darwin sys/sysctl.h + * + * Copyright: Copyright © 2021, The D Language Foundation + * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. + * Authors: Iain Buclaw + */ +module core.sys.darwin.sys.sysctl; + +version (OSX) + version = Darwin; +else version (iOS) + version = Darwin; +else version (TVOS) + version = Darwin; +else version (WatchOS) + version = Darwin; + +version (Darwin): +extern (C): +nothrow: +@nogc: + +// Top-level identifiers +enum +{ + CTL_UNSPEC = 0, + CTL_KERN = 1, + CTL_VM = 2, + CTL_VFS = 3, + CTL_NET = 4, + CTL_DEBUG = 5, + CTL_HW = 6, + CTL_MACHDEP = 7, + CTL_USER = 8, + CTL_MAXID = 9, +} + +// CTL_KERN identifiers +enum +{ + KERN_OSTYPE = 1, + KERN_OSRELEASE = 2, + KERN_OSREV = 3, + KERN_VERSION = 4, + KERN_MAXVNODES = 5, + KERN_MAXPROC = 6, + KERN_MAXFILES = 7, + KERN_ARGMAX = 8, + KERN_SECURELVL = 9, + KERN_HOSTNAME = 10, + KERN_HOSTID = 11, + KERN_CLOCKRATE = 12, + KERN_VNODE = 13, + KERN_PROC = 14, + KERN_FILE = 15, + KERN_PROF = 16, + KERN_POSIX1 = 17, + KERN_NGROUPS = 18, + KERN_JOB_CONTROL = 19, + KERN_SAVED_IDS = 20, + KERN_BOOTTIME = 21, + KERN_NISDOMAINNAME = 22, + KERN_DOMAINNAME = KERN_NISDOMAINNAME, + KERN_MAXPARTITIONS = 23, + KERN_KDEBUG = 24, + KERN_UPDATEINTERVAL = 25, + KERN_OSRELDATE = 26, + KERN_NTP_PLL = 27, + KERN_BOOTFILE = 28, + KERN_MAXFILESPERPROC = 29, + KERN_MAXPROCPERUID = 30, + KERN_DUMPDEV = 31, + KERN_IPC = 32, + KERN_DUMMY = 33, + KERN_PS_STRINGS = 34, + KERN_USRSTACK32 = 35, + KERN_LOGSIGEXIT = 36, + KERN_SYMFILE = 37, + KERN_PROCARGS = 38, + KERN_NETBOOT = 40, + KERN_SYSV = 42, + KERN_AFFINITY = 43, + KERN_TRANSLATE = 44, + KERN_CLASSIC = KERN_TRANSLATE, + KERN_EXEC = 45, + KERN_CLASSICHANDLER = KERN_EXEC, + KERN_AIOMAX = 46, + KERN_AIOPROCMAX = 47, + KERN_AIOTHREADS = 48, + KERN_PROCARGS2 = 49, + KERN_COREFILE = 50, + KERN_COREDUMP = 51, + KERN_SUGID_COREDUMP = 52, + KERN_PROCDELAYTERM = 53, + KERN_SHREG_PRIVATIZABLE = 54, + KERN_LOW_PRI_WINDOW = 56, + KERN_LOW_PRI_DELAY = 57, + KERN_POSIX = 58, + KERN_USRSTACK64 = 59, + KERN_NX_PROTECTION = 60, + KERN_TFP = 61, + KERN_PROCNAME = 62, + KERN_THALTSTACK = 63, + KERN_SPECULATIVE_READS = 64, + KERN_OSVERSION = 65, + KERN_SAFEBOOT = 66, + KERN_RAGEVNODE = 68, + KERN_TTY = 69, + KERN_CHECKOPENEVT = 70, + KERN_THREADNAME = 71, + KERN_MAXID = 72, +} + +// KERN_RAGEVNODE types +enum +{ + KERN_RAGE_PROC = 1, + KERN_RAGE_THREAD = 2, + KERN_UNRAGE_PROC = 3, + KERN_UNRAGE_THREAD = 4, +} + +// KERN_OPENEVT types +enum +{ + KERN_OPENEVT_PROC = 1, + KERN_UNOPENEVT_PROC = 2, +} + +// KERN_TFP types +enum +{ + KERN_TFP_POLICY = 1, +} + +// KERN_TFP_POLICY values +enum +{ + KERN_TFP_POLICY_DENY = 0, + KERN_TFP_POLICY_DEFAULT = 2, +} + +// KERN_PROC subtypes +enum +{ + KERN_PROC_ALL = 0, + KERN_PROC_PID = 1, + KERN_PROC_PGRP = 2, + KERN_PROC_SESSION = 3, + KERN_PROC_TTY = 4, + KERN_PROC_UID = 5, + KERN_PROC_RUID = 6, + KERN_PROC_LCID = 7, +} + +// KERN_VFSNSPACE subtypes +enum +{ + KERN_VFSNSPACE_HANDLE_PROC = 1, + KERN_VFSNSPACE_UNHANDLE_PROC = 2, +} + +// KERN_IPC identifiers +enum +{ + KIPC_MAXSOCKBUF = 1, + KIPC_SOCKBUF_WASTE = 2, + KIPC_SOMAXCONN = 3, + KIPC_MAX_LINKHDR = 4, + KIPC_MAX_PROTOHDR = 5, + KIPC_MAX_HDR = 6, + KIPC_MAX_DATALEN = 7, + KIPC_MBSTAT = 8, + KIPC_NMBCLUSTERS = 9, + KIPC_SOQLIMITCOMPAT = 10, +} + +// CTL_VM identifiers +enum +{ + VM_METER = 1, + VM_LOADAVG = 2, + VM_MACHFACTOR = 4, + VM_SWAPUSAGE = 5, + VM_MAXID = 6, +} + +// CTL_HW identifiers +enum +{ + HW_MACHINE = 1, + HW_MODEL = 2, + HW_NCPU = 3, + HW_BYTEORDER = 4, + HW_PHYSMEM = 5, + HW_USERMEM = 6, + HW_PAGESIZE = 7, + HW_DISKNAMES = 8, + HW_DISKSTATS = 9, + HW_EPOCH = 10, + HW_FLOATINGPT = 11, + HW_MACHINE_ARCH = 12, + HW_VECTORUNIT = 13, + HW_BUS_FREQ = 14, + HW_CPU_FREQ = 15, + HW_CACHELINE = 16, + HW_L1ICACHESIZE = 17, + HW_L1DCACHESIZE = 18, + HW_L2SETTINGS = 19, + HW_L2CACHESIZE = 20, + HW_L3SETTINGS = 21, + HW_L3CACHESIZE = 22, + HW_TB_FREQ = 23, + HW_MEMSIZE = 24, + HW_AVAILCPU = 25, + HW_MAXID = 26, +} + +// CTL_USER identifiers +enum +{ + USER_CS_PATH = 1, + USER_BC_BASE_MAX = 2, + USER_BC_DIM_MAX = 3, + USER_BC_SCALE_MAX = 4, + USER_BC_STRING_MAX = 5, + USER_COLL_WEIGHTS_MAX = 6, + USER_EXPR_NEST_MAX = 7, + USER_LINE_MAX = 8, + USER_RE_DUP_MAX = 9, + USER_POSIX2_VERSION = 10, + USER_POSIX2_C_BIND = 11, + USER_POSIX2_C_DEV = 12, + USER_POSIX2_CHAR_TERM = 13, + USER_POSIX2_FORT_DEV = 14, + USER_POSIX2_FORT_RUN = 15, + USER_POSIX2_LOCALEDEF = 16, + USER_POSIX2_SW_DEV = 17, + USER_POSIX2_UPE = 18, + USER_STREAM_MAX = 19, + USER_TZNAME_MAX = 20, + USER_MAXID = 21, +} + +/// +int sysctl(const int* name, uint namelen, void* oldp, size_t* oldlenp, + const void* newp, size_t newlen); +/// +int sysctlbyname(const char* name, void* oldp, size_t* oldlenp, + const void* newp, size_t newlen); +/// +int sysctlnametomib(const char* sname, int* name, size_t* namelenp); diff --git a/libphobos/libdruntime/core/sys/dragonflybsd/stdlib.d b/libphobos/libdruntime/core/sys/dragonflybsd/stdlib.d new file mode 100644 index 0000000..8936701 --- /dev/null +++ b/libphobos/libdruntime/core/sys/dragonflybsd/stdlib.d @@ -0,0 +1,17 @@ +/** + * D header file for DragonFlyBSD stdlib.h. + * + * Copyright: Copyright © 2021, The D Language Foundation + * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. + * Authors: Iain Buclaw + */ +module core.sys.dragonflybsd.stdlib; +public import core.sys.posix.stdlib; + +version (DragonFlyBSD): +extern (C): +nothrow: +@nogc: + +const(char)* getprogname(); +void setprogname(scope const char* name); diff --git a/libphobos/libdruntime/core/sys/dragonflybsd/sys/sysctl.d b/libphobos/libdruntime/core/sys/dragonflybsd/sys/sysctl.d new file mode 100644 index 0000000..932082f --- /dev/null +++ b/libphobos/libdruntime/core/sys/dragonflybsd/sys/sysctl.d @@ -0,0 +1,199 @@ +/** + * D header file for DragonFlyBSD sys/sysctl.h + * + * Copyright: Copyright © 2021, The D Language Foundation + * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. + * Authors: Iain Buclaw + */ +module core.sys.dragonflybsd.sys.sysctl; + +version (DragonFlyBSD): +extern (C): +nothrow: +@nogc: + +// Top-level identifiers +enum +{ + CTL_SYSCTL = 0, + CTL_KERN = 1, + CTL_VM = 2, + CTL_VFS = 3, + CTL_NET = 4, + CTL_DEBUG = 5, + CTL_HW = 6, + CTL_MACHDEP = 7, + CTL_USER = 8, + CTL_P1003_1B = 9, + CTL_LWKT = 10, + CTL_MAXID = 11, +} + +// CTL_SYSCTL identifiers +enum +{ + CTL_SYSCTL_DEBUG = 0, + CTL_SYSCTL_NAME = 1, + CTL_SYSCTL_NEXT = 2, + CTL_SYSCTL_NAME2OID = 3, + CTL_SYSCTL_OIDFMT = 4, + CTL_SYSCTL_OIDDESCR = 5, +} + +// CTL_KERN identifiers +enum +{ + KERN_OSTYPE = 1, + KERN_OSRELEASE = 2, + KERN_OSREV = 3, + KERN_VERSION = 4, + KERN_MAXVNODES = 5, + KERN_MAXPROC = 6, + KERN_MAXFILES = 7, + KERN_ARGMAX = 8, + KERN_SECURELVL = 9, + KERN_HOSTNAME = 10, + KERN_HOSTID = 11, + KERN_CLOCKRATE = 12, + KERN_VNODE = 13, + KERN_PROC = 14, + KERN_FILE = 15, + KERN_POSIX1 = 17, + KERN_NGROUPS = 18, + KERN_JOB_CONTROL = 19, + KERN_SAVED_IDS = 20, + KERN_BOOTTIME = 21, + KERN_NISDOMAINNAME = 22, + KERN_UPDATEINTERVAL = 23, + KERN_OSRELDATE = 24, + KERN_NTP_PLL = 25, + KERN_BOOTFILE = 26, + KERN_MAXFILESPERPROC = 27, + KERN_MAXPROCPERUID = 28, + KERN_DUMPDEV = 29, + KERN_IPC = 30, + KERN_DUMMY = 31, + KERN_PS_STRINGS = 32, + KERN_USRSTACK = 33, + KERN_LOGSIGEXIT = 34, + KERN_IOV_MAX = 35, + KERN_MAXPOSIXLOCKSPERUID = 36, + KERN_MAXID = 37, +} + +// KERN_PROC subtypes +enum +{ + KERN_PROC_ALL = 0, + KERN_PROC_PID = 1, + KERN_PROC_PGRP = 2, + KERN_PROC_SESSION = 3, + KERN_PROC_TTY = 4, + KERN_PROC_UID = 5, + KERN_PROC_RUID = 6, + KERN_PROC_ARGS = 7, + KERN_PROC_CWD = 8, + KERN_PROC_PATHNAME = 9, + KERN_PROC_SIGTRAMP = 10, + KERN_PROC_FLAGMASK = 0x10, + KERN_PROC_FLAG_LWP = 0x10, +} + +// KERN_IPC identifiers +enum +{ + KIPC_MAXSOCKBUF = 1, + KIPC_SOCKBUF_WASTE = 2, + KIPC_SOMAXCONN = 3, + KIPC_MAX_LINKHDR = 4, + KIPC_MAX_PROTOHDR = 5, + KIPC_MAX_HDR = 6, + KIPC_MAX_DATALEN = 7, + KIPC_MBSTAT = 8, + KIPC_NMBCLUSTERS = 9, +} + +// CTL_HW identifiers +enum +{ + HW_MACHINE = 1, + HW_MODEL = 2, + HW_NCPU = 3, + HW_BYTEORDER = 4, + HW_PHYSMEM = 5, + HW_USERMEM = 6, + HW_PAGESIZE = 7, + HW_DISKNAMES = 8, + HW_DISKSTATS = 9, + HW_FLOATINGPT = 10, + HW_MACHINE_ARCH = 11, + HW_MACHINE_PLATFORM = 12, + HW_SENSORS = 13, + HW_MAXID = 14, +} + +// CTL_USER definitions +enum +{ + USER_CS_PATH = 1, + USER_BC_BASE_MAX = 2, + USER_BC_DIM_MAX = 3, + USER_BC_SCALE_MAX = 4, + USER_BC_STRING_MAX = 5, + USER_COLL_WEIGHTS_MAX = 6, + USER_EXPR_NEST_MAX = 7, + USER_LINE_MAX = 8, + USER_RE_DUP_MAX = 9, + USER_POSIX2_VERSION = 10, + USER_POSIX2_C_BIND = 11, + USER_POSIX2_C_DEV = 12, + USER_POSIX2_CHAR_TERM = 13, + USER_POSIX2_FORT_DEV = 14, + USER_POSIX2_FORT_RUN = 15, + USER_POSIX2_LOCALEDEF = 16, + USER_POSIX2_SW_DEV = 17, + USER_POSIX2_UPE = 18, + USER_STREAM_MAX = 19, + USER_TZNAME_MAX = 20, + USER_MAXID = 21, +} + +// POSIX 1003.1B definitions +enum +{ + CTL_P1003_1B_ASYNCHRONOUS_IO = 1, + CTL_P1003_1B_MAPPED_FILES = 2, + CTL_P1003_1B_MEMLOCK = 3, + CTL_P1003_1B_MEMLOCK_RANGE = 4, + CTL_P1003_1B_MEMORY_PROTECTION = 5, + CTL_P1003_1B_MESSAGE_PASSING = 6, + CTL_P1003_1B_PRIORITIZED_IO = 7, + CTL_P1003_1B_PRIORITY_SCHEDULING = 8, + CTL_P1003_1B_REALTIME_SIGNALS = 9, + CTL_P1003_1B_SEMAPHORES = 10, + CTL_P1003_1B_FSYNC = 11, + CTL_P1003_1B_SHARED_MEMORY_OBJECTS = 12, + CTL_P1003_1B_SYNCHRONIZED_IO = 13, + CTL_P1003_1B_TIMERS = 14, + CTL_P1003_1B_AIO_LISTIO_MAX = 15, + CTL_P1003_1B_AIO_MAX = 16, + CTL_P1003_1B_AIO_PRIO_DELTA_MAX = 17, + CTL_P1003_1B_DELAYTIMER_MAX = 18, + CTL_P1003_1B_UNUSED19 = 19, + CTL_P1003_1B_PAGESIZE = 20, + CTL_P1003_1B_RTSIG_MAX = 21, + CTL_P1003_1B_SEM_NSEMS_MAX = 22, + CTL_P1003_1B_UNUSED23 = 23, + CTL_P1003_1B_SIGQUEUE_MAX = 24, + CTL_P1003_1B_TIMER_MAX = 25, + CTL_P1003_1B_MAXID = 26, +} + +/// +int sysctl(const int* name, uint namelen, void* oldp, size_t* oldlenp, + const void* newp, size_t newlen); +/// +int sysctlbyname(const char* name, void* oldp, size_t* oldlenp, + const void* newp, size_t newlen); +/// +int sysctlnametomib(const char* name, int* mibp, size_t* sizep); diff --git a/libphobos/libdruntime/core/sys/freebsd/stdlib.d b/libphobos/libdruntime/core/sys/freebsd/stdlib.d new file mode 100644 index 0000000..bf93c3a --- /dev/null +++ b/libphobos/libdruntime/core/sys/freebsd/stdlib.d @@ -0,0 +1,17 @@ +/** + * D header file for FreeBSD stdlib.h. + * + * Copyright: Copyright © 2021, The D Language Foundation + * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. + * Authors: Iain Buclaw + */ +module core.sys.freebsd.stdlib; +public import core.sys.posix.stdlib; + +version (FreeBSD): +extern (C): +nothrow: +@nogc: + +const(char)* getprogname(); +void setprogname(scope const char* name); diff --git a/libphobos/libdruntime/core/sys/freebsd/sys/sysctl.d b/libphobos/libdruntime/core/sys/freebsd/sys/sysctl.d new file mode 100644 index 0000000..b9b3e93 --- /dev/null +++ b/libphobos/libdruntime/core/sys/freebsd/sys/sysctl.d @@ -0,0 +1,211 @@ +/** + * D header file for FreeBSD sys/sysctl.h + * + * Copyright: Copyright © 2021, The D Language Foundation + * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. + * Authors: Iain Buclaw + */ +module core.sys.freebsd.sys.sysctl; + +version (FreeBSD): +extern (C): +nothrow: +@nogc: + +// Top-level identifiers +enum +{ + CTL_SYSCTL = 0, + CTL_KERN = 1, + CTL_VM = 2, + CTL_VFS = 3, + CTL_NET = 4, + CTL_DEBUG = 5, + CTL_HW = 6, + CTL_MACHDEP = 7, + CTL_USER = 8, + CTL_P1003_1B = 9, +} + +// CTL_SYSCTL identifiers +enum +{ + CTL_SYSCTL_DEBUG = 0, + CTL_SYSCTL_NAME = 1, + CTL_SYSCTL_NEXT = 2, + CTL_SYSCTL_NAME2OID = 3, + CTL_SYSCTL_OIDFMT = 4, + CTL_SYSCTL_OIDDESCR = 5, + CTL_SYSCTL_OIDLABEL = 6, +} + +// CTL_KERN identifiers +enum +{ + KERN_OSTYPE = 1, + KERN_OSRELEASE = 2, + KERN_OSREV = 3, + KERN_VERSION = 4, + KERN_MAXVNODES = 5, + KERN_MAXPROC = 6, + KERN_MAXFILES = 7, + KERN_ARGMAX = 8, + KERN_SECURELVL = 9, + KERN_HOSTNAME = 10, + KERN_HOSTID = 11, + KERN_CLOCKRATE = 12, + KERN_VNODE = 13, + KERN_PROC = 14, + KERN_FILE = 15, + KERN_PROF = 16, + KERN_POSIX1 = 17, + KERN_NGROUPS = 18, + KERN_JOB_CONTROL = 19, + KERN_SAVED_IDS = 20, + KERN_BOOTTIME = 21, + KERN_NISDOMAINNAME = 22, + KERN_UPDATEINTERVAL = 23, + KERN_OSRELDATE = 24, + KERN_NTP_PLL = 25, + KERN_BOOTFILE = 26, + KERN_MAXFILESPERPROC = 27, + KERN_MAXPROCPERUID = 28, + KERN_DUMPDEV = 29, + KERN_IPC = 30, + KERN_DUMMY = 31, + KERN_PS_STRINGS = 32, + KERN_USRSTACK = 33, + KERN_LOGSIGEXIT = 34, + KERN_IOV_MAX = 35, + KERN_HOSTUUID = 36, + KERN_ARND = 37, + KERN_MAXPHYS = 38, +} + +// KERN_PROC subtypes +enum +{ + KERN_PROC_ALL = 0, + KERN_PROC_PID = 1, + KERN_PROC_PGRP = 2, + KERN_PROC_SESSION = 3, + KERN_PROC_TTY = 4, + KERN_PROC_UID = 5, + KERN_PROC_RUID = 6, + KERN_PROC_ARGS = 7, + KERN_PROC_PROC = 8, + KERN_PROC_SV_NAME = 9, + KERN_PROC_RGID = 10, + KERN_PROC_GID = 11, + KERN_PROC_PATHNAME = 12, + KERN_PROC_OVMMAP = 13, + KERN_PROC_OFILEDESC = 14, + KERN_PROC_KSTACK = 15, + KERN_PROC_INC_THREAD = 0x10, + KERN_PROC_VMMAP = 32, + KERN_PROC_FILEDESC = 33, + KERN_PROC_GROUPS = 34, + KERN_PROC_ENV = 35, + KERN_PROC_AUXV = 36, + KERN_PROC_RLIMIT = 37, + KERN_PROC_PS_STRINGS = 38, + KERN_PROC_UMASK = 39, + KERN_PROC_OSREL = 40, + KERN_PROC_SIGTRAMP = 41, + KERN_PROC_CWD = 42, + KERN_PROC_NFDS = 43, +} + +// KERN_IPC identifiers +enum +{ + KIPC_MAXSOCKBUF = 1, + KIPC_SOCKBUF_WASTE = 2, + KIPC_SOMAXCONN = 3, + KIPC_MAX_LINKHDR = 4, + KIPC_MAX_PROTOHDR = 5, + KIPC_MAX_HDR = 6, + KIPC_MAX_DATALEN = 7, +} + +// CTL_HW identifiers +enum +{ + HW_MACHINE = 1, + HW_MODEL = 2, + HW_NCPU = 3, + HW_BYTEORDER = 4, + HW_PHYSMEM = 5, + HW_USERMEM = 6, + HW_PAGESIZE = 7, + HW_DISKNAMES = 8, + HW_DISKSTATS = 9, + HW_FLOATINGPT = 10, + HW_MACHINE_ARCH = 11, + HW_REALMEM = 12, +} + +// CTL_USER identifiers +enum +{ + USER_CS_PATH = 1, + USER_BC_BASE_MAX = 2, + USER_BC_DIM_MAX = 3, + USER_BC_SCALE_MAX = 4, + USER_BC_STRING_MAX = 5, + USER_COLL_WEIGHTS_MAX = 6, + USER_EXPR_NEST_MAX = 7, + USER_LINE_MAX = 8, + USER_RE_DUP_MAX = 9, + USER_POSIX2_VERSION = 10, + USER_POSIX2_C_BIND = 11, + USER_POSIX2_C_DEV = 12, + USER_POSIX2_CHAR_TERM = 13, + USER_POSIX2_FORT_DEV = 14, + USER_POSIX2_FORT_RUN = 15, + USER_POSIX2_LOCALEDEF = 16, + USER_POSIX2_SW_DEV = 17, + USER_POSIX2_UPE = 18, + USER_STREAM_MAX = 19, + USER_TZNAME_MAX = 20, +} + +// POSIX 1003.1B definitions +enum +{ + CTL_P1003_1B_ASYNCHRONOUS_IO = 1, + CTL_P1003_1B_MAPPED_FILES = 2, + CTL_P1003_1B_MEMLOCK = 3, + CTL_P1003_1B_MEMLOCK_RANGE = 4, + CTL_P1003_1B_MEMORY_PROTECTION = 5, + CTL_P1003_1B_MESSAGE_PASSING = 6, + CTL_P1003_1B_PRIORITIZED_IO = 7, + CTL_P1003_1B_PRIORITY_SCHEDULING = 8, + CTL_P1003_1B_REALTIME_SIGNALS = 9, + CTL_P1003_1B_SEMAPHORES = 10, + CTL_P1003_1B_FSYNC = 11, + CTL_P1003_1B_SHARED_MEMORY_OBJECTS = 12, + CTL_P1003_1B_SYNCHRONIZED_IO = 13, + CTL_P1003_1B_TIMERS = 14, + CTL_P1003_1B_AIO_LISTIO_MAX = 15, + CTL_P1003_1B_AIO_MAX = 16, + CTL_P1003_1B_AIO_PRIO_DELTA_MAX = 17, + CTL_P1003_1B_DELAYTIMER_MAX = 18, + CTL_P1003_1B_UNUSED19 = 19, + CTL_P1003_1B_PAGESIZE = 20, + CTL_P1003_1B_RTSIG_MAX = 21, + CTL_P1003_1B_SEM_NSEMS_MAX = 22, + CTL_P1003_1B_UNUSED23 = 23, + CTL_P1003_1B_SIGQUEUE_MAX = 24, + CTL_P1003_1B_TIMER_MAX = 25, + CTL_P1003_1B_MAXID = 26, +} + +/// +int sysctl(const int* name, uint namelen, void* oldp, size_t* oldlenp, + const void* newp, size_t newlen); +/// +int sysctlbyname(const char* name, void* oldp, size_t* oldlenp, + const void* newp, size_t newlen); +/// +int sysctlnametomib(const char* name, int* mibp, size_t* sizep); diff --git a/libphobos/libdruntime/core/sys/netbsd/stdlib.d b/libphobos/libdruntime/core/sys/netbsd/stdlib.d new file mode 100644 index 0000000..84c68a7 --- /dev/null +++ b/libphobos/libdruntime/core/sys/netbsd/stdlib.d @@ -0,0 +1,17 @@ +/** + * D header file for NetBSD stdlib.h. + * + * Copyright: Copyright © 2021, The D Language Foundation + * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. + * Authors: Iain Buclaw + */ +module core.sys.netbsd.stdlib; +public import core.sys.posix.stdlib; + +version (NetBSD): +extern (C): +nothrow: +@nogc: + +const(char)* getprogname(); +void setprogname(scope const char* name); diff --git a/libphobos/libdruntime/core/sys/netbsd/sys/sysctl.d b/libphobos/libdruntime/core/sys/netbsd/sys/sysctl.d new file mode 100644 index 0000000..9b2a0b7 --- /dev/null +++ b/libphobos/libdruntime/core/sys/netbsd/sys/sysctl.d @@ -0,0 +1,254 @@ +/** + * D header file for NetBSD sys/sysctl.h + * + * Copyright: Copyright © 2021, The D Language Foundation + * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. + * Authors: Iain Buclaw + */ +module core.sys.netbsd.sys.sysctl; + +version (NetBSD): +extern (C): +nothrow: +@nogc: + +// Top-level identifiers +enum +{ + CTL_UNSPEC = 0, + CTL_KERN = 1, + CTL_VM = 2, + CTL_VFS = 3, + CTL_NET = 4, + CTL_DEBUG = 5, + CTL_HW = 6, + CTL_MACHDEP = 7, + CTL_DDB = 9, + CTL_PROC = 10, + CTL_VENDOR = 11, + CTL_EMUL = 12, + CTL_SECURITY = 13, +} + +// CTL_KERN identifiers +enum +{ + KERN_OSTYPE = 1, + KERN_OSRELEASE = 2, + KERN_OSREV = 3, + KERN_VERSION = 4, + KERN_MAXVNODES = 5, + KERN_MAXPROC = 6, + KERN_MAXFILES = 7, + KERN_ARGMAX = 8, + KERN_SECURELVL = 9, + KERN_HOSTNAME = 10, + KERN_HOSTID = 11, + KERN_CLOCKRATE = 12, + KERN_VNODE = 13, + KERN_PROC = 14, + KERN_FILE = 15, + KERN_PROF = 16, + KERN_POSIX1 = 17, + KERN_NGROUPS = 18, + KERN_JOB_CONTROL = 19, + KERN_SAVED_IDS = 20, + KERN_OBOOTTIME = 21, + KERN_DOMAINNAME = 22, + KERN_MAXPARTITIONS = 23, + KERN_RAWPARTITION = 24, + KERN_NTPTIME = 25, + KERN_TIMEX = 26, + KERN_AUTONICETIME = 27, + KERN_AUTONICEVAL = 28, + KERN_RTC_OFFSET = 29, + KERN_ROOT_DEVICE = 30, + KERN_MSGBUFSIZE = 31, + KERN_FSYNC = 32, + KERN_OLDSYSVMSG = 33, + KERN_OLDSYSVSEM = 34, + KERN_OLDSYSVSHM = 35, + KERN_OLDSHORTCORENAME = 36, + KERN_SYNCHRONIZED_IO = 37, + KERN_IOV_MAX = 38, + KERN_MBUF = 39, + KERN_MAPPED_FILES = 40, + KERN_MEMLOCK = 41, + KERN_MEMLOCK_RANGE = 42, + KERN_MEMORY_PROTECTION = 43, + KERN_LOGIN_NAME_MAX = 44, + KERN_DEFCORENAME = 45, + KERN_LOGSIGEXIT = 46, + KERN_PROC2 = 47, + KERN_PROC_ARGS = 48, + KERN_FSCALE = 49, + KERN_CCPU = 50, + KERN_CP_TIME = 51, + KERN_OLDSYSVIPC_INFO = 52, + KERN_MSGBUF = 53, + KERN_CONSDEV = 54, + KERN_MAXPTYS = 55, + KERN_PIPE = 56, + KERN_MAXPHYS = 57, + KERN_SBMAX = 58, + KERN_TKSTAT = 59, + KERN_MONOTONIC_CLOCK = 60, + KERN_URND = 61, + KERN_LABELSECTOR = 62, + KERN_LABELOFFSET = 63, + KERN_LWP = 64, + KERN_FORKFSLEEP = 65, + KERN_POSIX_THREADS = 66, + KERN_POSIX_SEMAPHORES = 67, + KERN_POSIX_BARRIERS = 68, + KERN_POSIX_TIMERS = 69, + KERN_POSIX_SPIN_LOCKS = 70, + KERN_POSIX_READER_WRITER_LOCKS = 71, + KERN_DUMP_ON_PANIC = 72, + KERN_SOMAXKVA = 73, + KERN_ROOT_PARTITION = 74, + KERN_DRIVERS = 75, + KERN_BUF = 76, + KERN_FILE2 = 77, + KERN_VERIEXEC = 78, + KERN_CP_ID = 79, + KERN_HARDCLOCK_TICKS = 80, + KERN_ARND = 81, + KERN_SYSVIPC = 82, + KERN_BOOTTIME = 83, + KERN_EVCNT = 84, + KERN_SOFIXEDBUF = 85, +} + +// KERN_PROC subtypes +enum +{ + KERN_PROC_ALL = 0, + KERN_PROC_PID = 1, + KERN_PROC_PGRP = 2, + KERN_PROC_SESSION = 3, + KERN_PROC_TTY = 4, + KERN_PROC_UID = 5, + KERN_PROC_RUID = 6, + KERN_PROC_KTHREAD = 7, + KERN_PROC_RGID = 8, +} + +// KERN_PROC_ARGS subtypes +enum +{ + KERN_PROC_ARGV = 1, + KERN_PROC_NARGV = 2, + KERN_PROC_ENV = 3, + KERN_PROC_NENV = 4, + KERN_PROC_PATHNAME = 5, + KERN_PROC_CWD = 6, +} + +// KERN_SYSVIPC subtypes +enum +{ + KERN_SYSVIPC_INFO = 1, + KERN_SYSVIPC_MSG = 2, + KERN_SYSVIPC_SEM = 3, + KERN_SYSVIPC_SHM = 4, + KERN_SYSVIPC_SHMMAX = 5, + KERN_SYSVIPC_SHMMNI = 6, + KERN_SYSVIPC_SHMSEG = 7, + KERN_SYSVIPC_SHMMAXPGS = 8, + KERN_SYSVIPC_SHMUSEPHYS = 9, +} + +// KERN_SYSVIPC_INFO subtypes +enum +{ + KERN_SYSVIPC_MSG_INFO = 4, + KERN_SYSVIPC_SEM_INFO = 5, + KERN_SYSVIPC_SHM_INFO = 6, +} + +// KERN_TKSTAT subtypes +enum +{ + KERN_TKSTAT_NIN = 1, + KERN_TKSTAT_NOUT = 2, + KERN_TKSTAT_CANCC = 3, + KERN_TKSTAT_RAWCC = 4, +} + +// KERN_BUF subtypes +enum +{ + KERN_BUF_ALL = 0, +} + +// KERN_FILE +enum +{ + KERN_FILE_BYFILE = 1, + KERN_FILE_BYPID = 2, + KERN_FILESLOP = 10, +} + +// KERN_EVCNT +enum +{ + KERN_EVCNT_COUNT_ANY = 0, + KERN_EVCNT_COUNT_NONZERO = 1, +} + +// CTL_HW identifiers +enum +{ + HW_MACHINE = 1, + HW_MODEL = 2, + HW_NCPU = 3, + HW_BYTEORDER = 4, + HW_PHYSMEM = 5, + HW_USERMEM = 6, + HW_PAGESIZE = 7, + HW_DISKNAMES = 8, + HW_IOSTATS = 9, + HW_MACHINE_ARCH = 10, + HW_ALIGNBYTES = 11, + HW_CNMAGIC = 12, + HW_PHYSMEM64 = 13, + HW_USERMEM64 = 14, + HW_IOSTATNAMES = 15, + HW_NCPUONLINE = 16, +} + +// CTL_USER definitions +enum +{ + USER_CS_PATH = 1, + USER_BC_BASE_MAX = 2, + USER_BC_DIM_MAX = 3, + USER_BC_SCALE_MAX = 4, + USER_BC_STRING_MAX = 5, + USER_COLL_WEIGHTS_MAX = 6, + USER_EXPR_NEST_MAX = 7, + USER_LINE_MAX = 8, + USER_RE_DUP_MAX = 9, + USER_POSIX2_VERSION = 10, + USER_POSIX2_C_BIND = 11, + USER_POSIX2_C_DEV = 12, + USER_POSIX2_CHAR_TERM = 13, + USER_POSIX2_FORT_DEV = 14, + USER_POSIX2_FORT_RUN = 15, + USER_POSIX2_LOCALEDEF = 16, + USER_POSIX2_SW_DEV = 17, + USER_POSIX2_UPE = 18, + USER_STREAM_MAX = 19, + USER_TZNAME_MAX = 20, + USER_ATEXIT_MAX = 21, +} + +/// +int sysctl(const int* name, uint namelen, void* oldp, size_t* oldlenp, + const void* newp, size_t newlen); +/// +int sysctlbyname(const char* name, void* oldp, size_t* oldlenp, + const void* newp, size_t newlen); +/// +int sysctlnametomib(const char* sname, int* name, size_t* namelenp); diff --git a/libphobos/libdruntime/core/sys/openbsd/stdlib.d b/libphobos/libdruntime/core/sys/openbsd/stdlib.d new file mode 100644 index 0000000..2d4d7a9 --- /dev/null +++ b/libphobos/libdruntime/core/sys/openbsd/stdlib.d @@ -0,0 +1,17 @@ +/** + * D header file for OpenBSD stdlib.h. + * + * Copyright: Copyright © 2021, The D Language Foundation + * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. + * Authors: Iain Buclaw + */ +module core.sys.openbsd.stdlib; +public import core.sys.posix.stdlib; + +version (OpenBSD): +extern (C): +nothrow: +@nogc: + +const(char)* getprogname(); +void setprogname(scope const char* name); diff --git a/libphobos/libdruntime/core/sys/openbsd/sys/sysctl.d b/libphobos/libdruntime/core/sys/openbsd/sys/sysctl.d new file mode 100644 index 0000000..c6f9845 --- /dev/null +++ b/libphobos/libdruntime/core/sys/openbsd/sys/sysctl.d @@ -0,0 +1,254 @@ +/** + * D header file for OpenBSD sys/sysctl.h + * + * Copyright: Copyright © 2021, The D Language Foundation + * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. + * Authors: Iain Buclaw + */ +module core.sys.openbsd.sys.sysctl; + +version (OpenBSD): +extern (C): +nothrow: +@nogc: + +// Top-level identifiers +enum +{ + CTL_UNSPEC = 0, + CTL_KERN = 1, + CTL_VM = 2, + CTL_FS = 3, + CTL_NET = 4, + CTL_DEBUG = 5, + CTL_HW = 6, + CTL_MACHDEP = 7, + CTL_DDB = 9, + CTL_VFS = 10, + CTL_MAXID = 11, +} + +// CTL_KERN identifiers +enum +{ + KERN_OSTYPE = 1, + KERN_OSRELEASE = 2, + KERN_OSREV = 3, + KERN_VERSION = 4, + KERN_MAXVNODES = 5, + KERN_MAXPROC = 6, + KERN_MAXFILES = 7, + KERN_ARGMAX = 8, + KERN_SECURELVL = 9, + KERN_HOSTNAME = 10, + KERN_HOSTID = 11, + KERN_CLOCKRATE = 12, + KERN_PROF = 16, + KERN_POSIX1 = 17, + KERN_NGROUPS = 18, + KERN_JOB_CONTROL = 19, + KERN_SAVED_IDS = 20, + KERN_BOOTTIME = 21, + KERN_DOMAINNAME = 22, + KERN_MAXPARTITIONS = 23, + KERN_RAWPARTITION = 24, + KERN_MAXTHREAD = 25, + KERN_NTHREADS = 26, + KERN_OSVERSION = 27, + KERN_SOMAXCONN = 28, + KERN_SOMINCONN = 29, + KERN_NOSUIDCOREDUMP = 32, + KERN_FSYNC = 33, + KERN_SYSVMSG = 34, + KERN_SYSVSEM = 35, + KERN_SYSVSHM = 36, + KERN_MSGBUFSIZE = 38, + KERN_MALLOCSTATS = 39, + KERN_CPTIME = 40, + KERN_NCHSTATS = 41, + KERN_FORKSTAT = 42, + KERN_NSELCOLL = 43, + KERN_TTY = 44, + KERN_CCPU = 45, + KERN_FSCALE = 46, + KERN_NPROCS = 47, + KERN_MSGBUF = 48, + KERN_POOL = 49, + KERN_STACKGAPRANDOM = 50, + KERN_SYSVIPC_INFO = 51, + KERN_ALLOWKMEM = 52, + KERN_WITNESSWATCH = 53, + KERN_SPLASSERT = 54, + KERN_PROC_ARGS = 55, + KERN_NFILES = 56, + KERN_TTYCOUNT = 57, + KERN_NUMVNODES = 58, + KERN_MBSTAT = 59, + KERN_WITNESS = 60, + KERN_SEMINFO = 61, + KERN_SHMINFO = 62, + KERN_INTRCNT = 63, + KERN_WATCHDOG = 64, + KERN_ALLOWDT = 65, + KERN_PROC = 66, + KERN_MAXCLUSTERS = 67, + KERN_EVCOUNT = 68, + KERN_TIMECOUNTER = 69, + KERN_MAXLOCKSPERUID = 70, + KERN_CPTIME2 = 71, + KERN_CACHEPCT = 72, + KERN_FILE = 73, + KERN_WXABORT = 74, + KERN_CONSDEV = 75, + KERN_NETLIVELOCKS = 76, + KERN_POOL_DEBUG = 77, + KERN_PROC_CWD = 78, + KERN_PROC_NOBROADCASTKILL = 79, + KERN_PROC_VMMAP = 80, + KERN_GLOBAL_PTRACE = 81, + KERN_CONSBUFSIZE = 82, + KERN_CONSBUF = 83, + KERN_AUDIO = 84, + KERN_CPUSTATS = 85, + KERN_PFSTATUS = 86, + KERN_TIMEOUT_STATS = 87, + KERN_UTC_OFFSET = 88, + KERN_MAXID = 89, +} + +// KERN_PROC subtypes +enum +{ + KERN_PROC_ALL = 0, + KERN_PROC_PID = 1, + KERN_PROC_PGRP = 2, + KERN_PROC_SESSION = 3, + KERN_PROC_TTY = 4, + KERN_PROC_UID = 5, + KERN_PROC_RUID = 6, + KERN_PROC_KTHREAD = 7, + KERN_PROC_SHOW_THREADS = 0x40000000, +} + +// KERN_SYSVIPC_INFO subtypes +enum +{ + KERN_SYSVIPC_MSG_INFO = 1, + KERN_SYSVIPC_SEM_INFO = 2, + KERN_SYSVIPC_SHM_INFO = 3, +} + +// KERN_PROC_ARGS subtypes +enum +{ + KERN_PROC_ARGV = 1, + KERN_PROC_NARGV = 2, + KERN_PROC_ENV = 3, + KERN_PROC_NENV = 4, +} + +// KERN_AUDIO subtypes +enum +{ + KERN_AUDIO_RECORD = 1, + KERN_AUDIO_MAXID = 2, +} + +// KERN_WITNESS +enum +{ + KERN_WITNESS_WATCH = 1, + KERN_WITNESS_LOCKTRACE = 2, + KERN_WITNESS_MAXID = 3, +} + +// KERN_FILE +enum +{ + KERN_FILE_BYFILE = 1, + KERN_FILE_BYPID = 2, + KERN_FILE_BYUID = 3, + KERN_FILESLOP = 10, + + KERN_FILE_TEXT = -1, + KERN_FILE_CDIR = -2, + KERN_FILE_RDIR = -3, + KERN_FILE_TRACE = -4, +} + +// KERN_INTRCNT +enum +{ + KERN_INTRCNT_NUM = 1, + KERN_INTRCNT_CNT = 2, + KERN_INTRCNT_NAME = 3, + KERN_INTRCNT_VECTOR = 4, + KERN_INTRCNT_MAXID = 5, +} + +// KERN_WATCHDOG +enum +{ + KERN_WATCHDOG_PERIOD = 1, + KERN_WATCHDOG_AUTO = 2, + KERN_WATCHDOG_MAXID = 3, +} + +// KERN_TIMECOUNTER +enum +{ + KERN_TIMECOUNTER_TICK = 1, + KERN_TIMECOUNTER_TIMESTEPWARNINGS = 2, + KERN_TIMECOUNTER_HARDWARE = 3, + KERN_TIMECOUNTER_CHOICE = 4, + KERN_TIMECOUNTER_MAXID = 5, +} + +// CTL_FS identifiers +enum +{ + FS_POSIX = 1, + FS_MAXID = 2, +} + +// CTL_FS_POSIX identifiers +enum +{ + FS_POSIX_SETUID = 1, + FS_POSIX_MAXID = 2, +} + +// CTL_HW identifiers +enum +{ + HW_MACHINE = 1, + HW_MODEL = 2, + HW_NCPU = 3, + HW_BYTEORDER = 4, + HW_PHYSMEM = 5, + HW_USERMEM = 6, + HW_PAGESIZE = 7, + HW_DISKNAMES = 8, + HW_DISKSTATS = 9, + HW_DISKCOUNT = 10, + HW_SENSORS = 11, + HW_CPUSPEED = 12, + HW_SETPERF = 13, + HW_VENDOR = 14, + HW_PRODUCT = 15, + HW_VERSION = 16, + HW_SERIALNO = 17, + HW_UUID = 18, + HW_PHYSMEM64 = 19, + HW_USERMEM64 = 20, + HW_NCPUFOUND = 21, + HW_ALLOWPOWERDOWN = 22, + HW_PERFPOLICY = 23, + HW_SMT = 24, + HW_NCPUONLINE = 25, + HW_MAXID = 26, +} + +/// +int sysctl(const int* name, uint namelen, void* oldp, size_t* oldlenp, + const void* newp, size_t newlen); diff --git a/libphobos/libdruntime/core/sys/posix/locale.d b/libphobos/libdruntime/core/sys/posix/locale.d index 172e9aa..18558a2 100644 --- a/libphobos/libdruntime/core/sys/posix/locale.d +++ b/libphobos/libdruntime/core/sys/posix/locale.d @@ -34,51 +34,45 @@ version (NetBSD) version (DragonflyBSD) version = DarwinBSDLocale; -/// -struct lconv -{ - char* currency_symbol; - char* decimal_point; - char frac_digits; - char* grouping; - char* int_curr_symbol; - char int_frac_digits; - char int_n_cs_precedes; - char int_n_sep_by_space; - char int_n_sign_posn; - char int_p_cs_precedes; - char int_p_sep_by_space; - char int_p_sign_posn; - char* mon_decimal_point; - char* mon_grouping; - char* mon_thousands_sep; - char* negative_sign; - char n_cs_precedes; - char n_sep_by_space; - char n_sign_posn; - char* positive_sign; - char p_cs_precedes; - char p_sep_by_space; - char p_sign_posn; - char* thousands_sep; -} - -/// Duplicate existing locale -locale_t duplocale(locale_t locale); -/// Free an allocated locale -void freelocale(locale_t locale); -/// Natural language formatting for C -lconv* localeconv(); -/// Create a new locale -locale_t newlocale(int mask, const char* locale, locale_t base); -/// Set the C library's notion of natural language formatting style -char* setlocale(int category, const char* locale); -/// Set the per-thread locale -locale_t uselocale (locale_t locale); +version (CRuntime_Glibc) + version = GNULinuxLocale; +version (CRuntime_Bionic) + version = GNULinuxLocale; +version (CRuntime_UClibc) + version = GNULinuxLocale; version (DarwinBSDLocale) { /// + struct lconv + { + char* decimal_point; + char* thousands_sep; + char* grouping; + char* int_curr_symbol; + char* currency_symbol; + char* mon_decimal_point; + char* mon_thousands_sep; + char* mon_grouping; + char* positive_sign; + char* negative_sign; + char int_frac_digits; + char frac_digits; + char p_cs_precedes; + char p_sep_by_space; + char n_cs_precedes; + char n_sep_by_space; + char p_sign_posn; + char n_sign_posn; + char int_p_cs_precedes; + char int_n_cs_precedes; + char int_p_sep_by_space; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; + } + + /// enum { LC_ALL = 0, @@ -116,11 +110,52 @@ version (DarwinBSDLocale) /// enum LC_GLOBAL_LOCALE = (cast(locale_t)-1); -} -version (linux) + /// Duplicate existing locale + locale_t duplocale(locale_t locale); + /// Free an allocated locale + void freelocale(locale_t locale); + /// Natural language formatting for C + lconv* localeconv(); + /// Create a new locale + locale_t newlocale(int mask, const char* locale, locale_t base); + /// Set the C library's notion of natural language formatting style + char* setlocale(int category, const char* locale); + /// Set the per-thread locale + locale_t uselocale (locale_t locale); +} +else version (GNULinuxLocale) { /// + struct lconv + { + char* decimal_point; + char* thousands_sep; + char* grouping; + char* int_curr_symbol; + char* currency_symbol; + char* mon_decimal_point; + char* mon_thousands_sep; + char* mon_grouping; + char* positive_sign; + char* negative_sign; + char int_frac_digits; + char frac_digits; + char p_cs_precedes; + char p_sep_by_space; + char n_cs_precedes; + char n_sep_by_space; + char p_sign_posn; + char n_sign_posn; + char int_p_cs_precedes; + char int_p_sep_by_space; + char int_n_cs_precedes; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; + } + + /// enum { LC_ALL = 6, @@ -172,4 +207,246 @@ version (linux) /// enum LC_GLOBAL_LOCALE = (cast(locale_t)-1); + + /// Duplicate existing locale + locale_t duplocale(locale_t locale); + /// Free an allocated locale + void freelocale(locale_t locale); + /// Natural language formatting for C + lconv* localeconv(); + /// Create a new locale + locale_t newlocale(int mask, const char* locale, locale_t base); + /// Set the C library's notion of natural language formatting style + char* setlocale(int category, const char* locale); + /// Set the per-thread locale + locale_t uselocale (locale_t locale); +} +else version (CRuntime_Musl) +{ + /// + struct lconv + { + char* decimal_point; + char* thousands_sep; + char* grouping; + char* int_curr_symbol; + char* currency_symbol; + char* mon_decimal_point; + char* mon_thousands_sep; + char* mon_grouping; + char* positive_sign; + char* negative_sign; + char int_frac_digits; + char frac_digits; + char p_cs_precedes; + char p_sep_by_space; + char n_cs_precedes; + char n_sep_by_space; + char p_sign_posn; + char n_sign_posn; + char int_p_cs_precedes; + char int_p_sep_by_space; + char int_n_cs_precedes; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; + } + + /// + enum + { + LC_CTYPE = 0, + LC_NUMERIC = 1, + LC_TIME = 2, + LC_COLLATE = 3, + LC_MONETARY = 4, + LC_MESSAGES = 5, + LC_ALL = 6, + } + + /// + enum + { + LC_CTYPE_MASK = (1 << LC_CTYPE), + LC_NUMERIC_MASK = (1 << LC_NUMERIC), + LC_TIME_MASK = (1 << LC_TIME), + LC_COLLATE_MASK = (1 << LC_COLLATE), + LC_MONETARY_MASK = (1 << LC_MONETARY), + LC_MESSAGES_MASK = (1 << LC_MESSAGES), + LC_ALL_MASK = 0x7fffffff, + } + + private struct __locale_struct; + + /// + alias locale_t = __locale_struct*; + + /// + enum LC_GLOBAL_LOCALE = (cast(locale_t)-1); + + /// Duplicate existing locale + locale_t duplocale(locale_t locale); + /// Free an allocated locale + void freelocale(locale_t locale); + /// Natural language formatting for C + lconv* localeconv(); + /// Create a new locale + locale_t newlocale(int mask, const char* locale, locale_t base); + /// Set the C library's notion of natural language formatting style + char* setlocale(int category, const char* locale); + /// Set the per-thread locale + locale_t uselocale (locale_t locale); +} +else version (OpenBSD) +{ + /// + struct lconv + { + char* decimal_point; + char* thousands_sep; + char* grouping; + char* int_curr_symbol; + char* currency_symbol; + char* mon_decimal_point; + char* mon_thousands_sep; + char* mon_grouping; + char* positive_sign; + char* negative_sign; + char int_frac_digits; + char frac_digits; + char p_cs_precedes; + char p_sep_by_space; + char n_cs_precedes; + char n_sep_by_space; + char p_sign_posn; + char n_sign_posn; + char int_p_cs_precedes; + char int_n_cs_precedes; + char int_p_sep_by_space; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; + } + + /// + enum + { + LC_ALL = 0, + LC_COLLATE = 1, + LC_CTYPE = 2, + LC_MONETARY = 3, + LC_NUMERIC = 4, + LC_TIME = 5, + LC_MESSAGES = 6, + } + private enum _LC_LAST = 7; + + /// + enum + { + LC_COLLATE_MASK = (1 << LC_COLLATE), + LC_CTYPE_MASK = (1 << LC_CTYPE), + LC_MONETARY_MASK = (1 << LC_MONETARY), + LC_NUMERIC_MASK = (1 << LC_NUMERIC), + LC_TIME_MASK = (1 << LC_TIME), + LC_MESSAGES_MASK = (1 << LC_MESSAGES), + LC_ALL_MASK = ((1 << _LC_LAST) - 2), + } + + /// + alias locale_t = void*; + + /// + enum LC_GLOBAL_LOCALE = (cast(locale_t)-1); + + /// Duplicate existing locale + locale_t duplocale(locale_t locale); + /// Free an allocated locale + void freelocale(locale_t locale); + /// Natural language formatting for C + lconv* localeconv(); + /// Create a new locale + locale_t newlocale(int mask, const char* locale, locale_t base); + /// Set the C library's notion of natural language formatting style + char* setlocale(int category, const char* locale); + /// Set the per-thread locale + locale_t uselocale (locale_t locale); +} +else version (Solaris) +{ + /// + struct lconv + { + char* decimal_point; + char* thousands_sep; + char* grouping; + char* int_curr_symbol; + char* currency_symbol; + char* mon_decimal_point; + char* mon_thousands_sep; + char* mon_grouping; + char* positive_sign; + char* negative_sign; + char int_frac_digits; + char frac_digits; + char p_cs_precedes; + char p_sep_by_space; + char n_cs_precedes; + char n_sep_by_space; + char p_sign_posn; + char n_sign_posn; + char int_p_cs_precedes; + char int_n_cs_precedes; + char int_p_sep_by_space; + char int_n_sep_by_space; + char int_p_sign_posn; + char int_n_sign_posn; + } + + /// + enum + { + LC_CTYPE = 0, + LC_NUMERIC = 1, + LC_TIME = 2, + LC_COLLATE = 3, + LC_MONETARY = 4, + LC_MESSAGES = 5, + LC_ALL = 6, + } + + /// + enum + { + LC_CTYPE_MASK = (1 << LC_CTYPE), + LC_NUMERIC_MASK = (1 << LC_NUMERIC), + LC_TIME_MASK = (1 << LC_TIME), + LC_COLLATE_MASK = (1 << LC_COLLATE), + LC_MONETARY_MASK = (1 << LC_MONETARY), + LC_MESSAGES_MASK = (1 << LC_MESSAGES), + LC_ALL_MASK = 0x3f, + } + + private struct _LC_locale_t; + + /// + alias locale_t = _LC_locale_t**; + + /// + enum LC_GLOBAL_LOCALE = (cast(locale_t)-1); + + /// Duplicate existing locale + locale_t duplocale(locale_t locale); + /// Free an allocated locale + void freelocale(locale_t locale); + /// Natural language formatting for C + lconv* localeconv(); + /// Create a new locale + locale_t newlocale(int mask, const char* locale, locale_t base); + /// Set the C library's notion of natural language formatting style + char* setlocale(int category, const char* locale); + /// Set the per-thread locale + locale_t uselocale (locale_t locale); } +else + static assert(false, "unimplemented platform"); diff --git a/libphobos/libdruntime/core/sys/posix/mqueue.d b/libphobos/libdruntime/core/sys/posix/mqueue.d index 3b447a1..2f1a8c6 100644 --- a/libphobos/libdruntime/core/sys/posix/mqueue.d +++ b/libphobos/libdruntime/core/sys/posix/mqueue.d @@ -19,6 +19,7 @@ * Authors: Andreas Bok Andersen, Mathias Lang * Standards: POSIX.1-2001. * See_Also: $(HTTP pubs.opengroup.org/onlinepubs/9699919799/basedefs/mqueue.h.html, Standard) + * Source: $(DRUNTIMESRC core/sys/posix/mqueue.d) */ module core.sys.posix.mqueue; @@ -58,16 +59,17 @@ struct mq_attr * Note: * Linux prototypes are: * mqd_t mq_open (const(char)* name, int oflag); - * mqd_t mq_open(const(char)* name, int oflag, mode_t mode, mq_attr* attr); + * mqd_t mq_open (const(char)* name, int oflag, mode_t mode, mq_attr* attr); * * Params: * name = Name of the message queue to open. - * oflags = determines the type of access used. + * oflag = determines the type of access used. * If `O_CREAT` is on `oflag`, the third argument is taken as a * `mode_t`, the mode of the created message queue. * If `O_CREAT` is on `oflag`, the fourth argument is taken as * a pointer to a `mq_attr' (message queue attributes). * If the fourth argument is `null`, default attributes are used. + * ... = varargs matching the function prototypes * * Returns: * Message queue descriptor or (mqd_t) -1 on error. diff --git a/libphobos/libdruntime/core/sys/posix/pthread.d b/libphobos/libdruntime/core/sys/posix/pthread.d index 577fb71..395ed0f 100644 --- a/libphobos/libdruntime/core/sys/posix/pthread.d +++ b/libphobos/libdruntime/core/sys/posix/pthread.d @@ -291,7 +291,7 @@ else version (OpenBSD) } enum PTHREAD_MUTEX_INITIALIZER = null; - //enum PTHREAD_ONCE_INIT = { PTHREAD_NEEDS_INIT, PTHREAD_MUTEX_INITIALIZER }; + enum PTHREAD_ONCE_INIT = pthread_once_t.init; enum PTHREAD_COND_INITIALIZER = null; enum PTHREAD_RWLOCK_INITIALIZER = null; } @@ -330,7 +330,6 @@ else version (DragonFlyBSD) enum PTHREAD_DONE_INIT = 1; enum PTHREAD_MUTEX_INITIALIZER = null; - //enum PTHREAD_ONCE_INIT = { PTHREAD_NEEDS_INIT, NULL }; enum PTHREAD_ONCE_INIT = pthread_once_t.init; enum PTHREAD_COND_INITIALIZER = null; enum PTHREAD_RWLOCK_INITIALIZER = null; diff --git a/libphobos/libdruntime/core/sys/posix/sys/statvfs.d b/libphobos/libdruntime/core/sys/posix/sys/statvfs.d index aeaf5bc..49c8450 100644 --- a/libphobos/libdruntime/core/sys/posix/sys/statvfs.d +++ b/libphobos/libdruntime/core/sys/posix/sys/statvfs.d @@ -159,107 +159,6 @@ else version (OpenBSD) } else version (FreeBSD) { - import core.sys.freebsd.sys.mount; - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - alias MFSNAMELEN = core.sys.freebsd.sys.mount.MFSNAMELEN; - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - alias MNAMELEN = core.sys.freebsd.sys.mount.MNAMELEN; - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - alias fsid_t = core.sys.freebsd.sys.mount.fsid_t; - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - alias statfs_t = core.sys.freebsd.sys.mount.statfs_t; - - // @@@DEPRECATED_2.091@@@ - deprecated("Values moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - enum FFlag - { - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_RDONLY = 1, /* read only filesystem */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_SYNCHRONOUS = 2, /* fs written synchronously */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_NOEXEC = 4, /* can't exec from filesystem */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_NOSUID = 8, /* don't honor setuid fs bits */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_NFS4ACLS = 16, /* enable NFS version 4 ACLs */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_UNION = 32, /* union with underlying fs */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_ASYNC = 64, /* fs written asynchronously */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_SUIDDIR = 128, /* special SUID dir handling */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_SOFTDEP = 256, /* using soft updates */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_NOSYMFOLLOW = 512, /* do not follow symlinks */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_GJOURNAL = 1024, /* GEOM journal support enabled */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_MULTILABEL = 2048, /* MAC support for objects */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_ACLS = 4096, /* ACL support enabled */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_NOATIME = 8192, /* dont update file access time */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_NOCLUSTERR = 16384, /* disable cluster read */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_NOCLUSTERW = 32768, /* disable cluster write */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_SUJ = 65536, /* using journaled soft updates */ - - // @@@DEPRECATED_2.091@@@ - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - MNT_AUTOMOUNTED = 131072 /* mounted by automountd(8) */ - } - - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - alias statfs = core.sys.freebsd.sys.mount.statfs; - - deprecated("Moved to core.sys.freebsd.sys.mount to correspond to C header file sys/mount.h") - alias fstatfs = core.sys.freebsd.sys.mount.fstatfs; - struct statvfs_t { fsblkcnt_t f_bavail; diff --git a/libphobos/libdruntime/core/sys/posix/sys/types.d b/libphobos/libdruntime/core/sys/posix/sys/types.d index 8e84ddb..abcea99 100644 --- a/libphobos/libdruntime/core/sys/posix/sys/types.d +++ b/libphobos/libdruntime/core/sys/posix/sys/types.d @@ -1103,7 +1103,14 @@ else version (DragonFlyBSD) alias void* pthread_key_t; alias void* pthread_mutex_t; alias void* pthread_mutexattr_t; - alias void* pthread_once_t; + + private struct pthread_once + { + int state; + pthread_mutex_t mutex; + } + alias pthread_once pthread_once_t; + alias void* pthread_rwlock_t; alias void* pthread_rwlockattr_t; alias void* pthread_t; diff --git a/libphobos/libdruntime/core/sys/solaris/stdlib.d b/libphobos/libdruntime/core/sys/solaris/stdlib.d new file mode 100644 index 0000000..0b6fffe --- /dev/null +++ b/libphobos/libdruntime/core/sys/solaris/stdlib.d @@ -0,0 +1,17 @@ +/** + * D header file for Solaris stdlib.h. + * + * Copyright: Copyright © 2021, The D Language Foundation + * License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. + * Authors: Iain Buclaw + */ +module core.sys.solaris.stdlib; +public import core.sys.posix.stdlib; + +version (Solaris): +extern (C): +nothrow: +@nogc: + +const(char)* getprogname(); +void setprogname(scope const char* name); diff --git a/libphobos/libdruntime/core/thread/osthread.d b/libphobos/libdruntime/core/thread/osthread.d index d81e0aa..defdc95 100644 --- a/libphobos/libdruntime/core/thread/osthread.d +++ b/libphobos/libdruntime/core/thread/osthread.d @@ -1461,14 +1461,6 @@ in (fn) fn(sp); } -version (Solaris) -{ - import core.sys.solaris.sys.priocntl; - import core.sys.solaris.sys.types; - import core.sys.posix.sys.wait : idtype_t; -} - - version (Windows) private extern (D) void scanWindowsOnly(scope ScanAllThreadsTypeFn scan, ThreadBase _t) nothrow { diff --git a/libphobos/libdruntime/core/vararg.d b/libphobos/libdruntime/core/vararg.d index a02ffea..935b2bd 100644 --- a/libphobos/libdruntime/core/vararg.d +++ b/libphobos/libdruntime/core/vararg.d @@ -17,3 +17,125 @@ module core.vararg; public import core.stdc.stdarg; + + +version (GNU) { /* TypeInfo-based va_arg overload unsupported */ } +else: + +version (ARM) version = ARM_Any; +version (AArch64) version = ARM_Any; +version (MIPS32) version = MIPS_Any; +version (MIPS64) version = MIPS_Any; +version (PPC) version = PPC_Any; +version (PPC64) version = PPC_Any; + +version (ARM_Any) +{ + // Darwin uses a simpler varargs implementation + version (OSX) {} + else version (iOS) {} + else version (TVOS) {} + else version (WatchOS) {} + else: + + version (ARM) version = AAPCS32; + version (AArch64) version = AAPCS64; +} + + +/// +alias va_arg = core.stdc.stdarg.va_arg; + + +/** + * Retrieve and store through parmn the next value that is of TypeInfo ti. + * Used when the static type is not known. + */ +void va_arg()(ref va_list ap, TypeInfo ti, void* parmn) +{ + version (X86) + { + // Wait until everyone updates to get TypeInfo.talign + //auto talign = ti.talign; + //auto p = cast(void*)(cast(size_t)ap + talign - 1) & ~(talign - 1); + auto p = ap; + auto tsize = ti.tsize; + ap = cast(va_list) (p + tsize.alignUp); + parmn[0..tsize] = p[0..tsize]; + } + else version (Win64) + { + version (LDC) enum isLDC = true; + else enum isLDC = false; + + // Wait until everyone updates to get TypeInfo.talign + //auto talign = ti.talign; + //auto p = cast(void*)(cast(size_t)ap + talign - 1) & ~(talign - 1); + auto p = ap; + auto tsize = ti.tsize; + void* q; + if (isLDC && tsize == 16 && cast(TypeInfo_Array) ti) + { + q = p; + ap = cast(va_list) (p + tsize); + } + else + { + q = (tsize > size_t.sizeof || (tsize & (tsize - 1)) != 0) ? *cast(void**) p : p; + ap = cast(va_list) (p + size_t.sizeof); + } + parmn[0..tsize] = q[0..tsize]; + } + else version (X86_64) + { + static import core.internal.vararg.sysv_x64; + core.internal.vararg.sysv_x64.va_arg(ap, ti, parmn); + } + else version (AAPCS32) + { + const tsize = ti.tsize; + if (ti.talign >= 8) + ap.__ap = ap.__ap.alignUp!8; + auto p = ap.__ap; + version (BigEndian) + p = adjustForBigEndian(p, tsize); + ap.__ap += tsize.alignUp; + parmn[0..tsize] = p[0..tsize]; + } + else version (AAPCS64) + { + static import core.internal.vararg.aarch64; + core.internal.vararg.aarch64.va_arg(ap, ti, parmn); + } + else version (ARM_Any) + { + const tsize = ti.tsize; + auto p = cast(void*) ap; + version (BigEndian) + p = adjustForBigEndian(p, tsize); + ap += tsize.alignUp; + parmn[0..tsize] = p[0..tsize]; + } + else version (PPC_Any) + { + if (ti.talign >= 8) + ap = ap.alignUp!8; + const tsize = ti.tsize; + auto p = cast(void*) ap; + version (BigEndian) + p = adjustForBigEndian(p, tsize); + ap += tsize.alignUp; + parmn[0..tsize] = p[0..tsize]; + } + else version (MIPS_Any) + { + const tsize = ti.tsize; + auto p = cast(void*) ap; + version (BigEndian) + p = adjustForBigEndian(p, tsize); + ap += tsize.alignUp; + parmn[0..tsize] = p[0..tsize]; + } + else + static assert(0, "Unsupported platform"); +} diff --git a/libphobos/libdruntime/core/volatile.d b/libphobos/libdruntime/core/volatile.d new file mode 100644 index 0000000..1703450 --- /dev/null +++ b/libphobos/libdruntime/core/volatile.d @@ -0,0 +1,67 @@ +/** + * This module declares intrinsics for volatile operations. + * + * Copyright: Copyright © 2019, The D Language Foundation + * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) + * Authors: Walter Bright, Ernesto Castellotti + * Source: $(DRUNTIMESRC core/volatile.d) + */ + +module core.volatile; + +nothrow: +@safe: +@nogc: + +/************************************* + * Read/write value from/to the memory location indicated by ptr. + * + * These functions are recognized by the compiler, and calls to them are guaranteed + * to not be removed (as dead assignment elimination or presumed to have no effect) + * or reordered in the same thread. + * + * These reordering guarantees are only made with regards to other + * operations done through these functions; the compiler is free to reorder regular + * loads/stores with regards to loads/stores done through these functions. + * + * This is useful when dealing with memory-mapped I/O (MMIO) where a store can + * have an effect other than just writing a value, or where sequential loads + * with no intervening stores can retrieve + * different values from the same location due to external stores to the location. + * + * These functions will, when possible, do the load/store as a single operation. In + * general, this is possible when the size of the operation is less than or equal to + * $(D (void*).sizeof), although some targets may support larger operations. If the + * load/store cannot be done as a single operation, multiple smaller operations will be used. + * + * These are not to be conflated with atomic operations. They do not guarantee any + * atomicity. This may be provided by coincidence as a result of the instructions + * used on the target, but this should not be relied on for portable programs. + * Further, no memory fences are implied by these functions. + * They should not be used for communication between threads. + * They may be used to guarantee a write or read cycle occurs at a specified address. + */ + +ubyte volatileLoad(ubyte * ptr); +ushort volatileLoad(ushort* ptr); /// ditto +uint volatileLoad(uint * ptr); /// ditto +ulong volatileLoad(ulong * ptr); /// ditto + +void volatileStore(ubyte * ptr, ubyte value); /// ditto +void volatileStore(ushort* ptr, ushort value); /// ditto +void volatileStore(uint * ptr, uint value); /// ditto +void volatileStore(ulong * ptr, ulong value); /// ditto + +@system unittest +{ + alias TT(T...) = T; + + foreach (T; TT!(ubyte, ushort, uint, ulong)) + { + T u; + T* p = &u; + volatileStore(p, 1); + T r = volatileLoad(p); + assert(r == u); + } +} diff --git a/libphobos/libdruntime/rt/lifetime.d b/libphobos/libdruntime/rt/lifetime.d index 95f0ff5..6a6eb50 100644 --- a/libphobos/libdruntime/rt/lifetime.d +++ b/libphobos/libdruntime/rt/lifetime.d @@ -44,17 +44,9 @@ private } } -private immutable bool callStructDtorsDuringGC; - extern (C) void lifetime_init() { // this is run before static ctors, so it is safe to modify immutables - import rt.config; - string s = rt_configOption("callStructDtorsDuringGC"); - if (s != null) - cast() callStructDtorsDuringGC = s[0] == '1' || s[0] == 'y' || s[0] == 'Y'; - else - cast() callStructDtorsDuringGC = true; } /** @@ -214,9 +206,6 @@ inout(TypeInfo) unqualify(inout(TypeInfo) cti) pure nothrow @nogc // size used to store the TypeInfo at the end of an allocation for structs that have a destructor size_t structTypeInfoSize(const TypeInfo ti) pure nothrow @nogc { - if (!callStructDtorsDuringGC) - return 0; - if (ti && typeid(ti) is typeid(TypeInfo_Struct)) // avoid a complete dynamic type cast { auto sti = cast(TypeInfo_Struct)cast(void*)ti; @@ -975,7 +964,7 @@ extern (C) void[] _d_newarrayT(const TypeInfo ti, size_t length) pure nothrow */ extern (C) void[] _d_newarrayiT(const TypeInfo ti, size_t length) pure nothrow { - import core.internal.traits : TypeTuple; + import core.internal.traits : AliasSeq; void[] result = _d_newarrayU(ti, length); auto tinext = unqualify(ti.next); @@ -985,7 +974,7 @@ extern (C) void[] _d_newarrayiT(const TypeInfo ti, size_t length) pure nothrow switch (init.length) { - foreach (T; TypeTuple!(ubyte, ushort, uint, ulong)) + foreach (T; AliasSeq!(ubyte, ushort, uint, ulong)) { case T.sizeof: (cast(T*)result.ptr)[0 .. size * length / T.sizeof] = *cast(T*)init.ptr; @@ -2539,33 +2528,30 @@ unittest delete arr1; assert(dtorCount == 7); - if (callStructDtorsDuringGC) - { - dtorCount = 0; - S1* s2 = new S1; - GC.runFinalizers((cast(char*)(typeid(S1).xdtor))[0..1]); - assert(dtorCount == 1); - GC.free(s2); + dtorCount = 0; + S1* s2 = new S1; + GC.runFinalizers((cast(char*)(typeid(S1).xdtor))[0..1]); + assert(dtorCount == 1); + GC.free(s2); - dtorCount = 0; - const(S1)* s3 = new const(S1); - GC.runFinalizers((cast(char*)(typeid(S1).xdtor))[0..1]); - assert(dtorCount == 1); - GC.free(cast(void*)s3); + dtorCount = 0; + const(S1)* s3 = new const(S1); + GC.runFinalizers((cast(char*)(typeid(S1).xdtor))[0..1]); + assert(dtorCount == 1); + GC.free(cast(void*)s3); - dtorCount = 0; - shared(S1)* s4 = new shared(S1); - GC.runFinalizers((cast(char*)(typeid(S1).xdtor))[0..1]); - assert(dtorCount == 1); - GC.free(cast(void*)s4); + dtorCount = 0; + shared(S1)* s4 = new shared(S1); + GC.runFinalizers((cast(char*)(typeid(S1).xdtor))[0..1]); + assert(dtorCount == 1); + GC.free(cast(void*)s4); - dtorCount = 0; - const(S1)[] carr1 = new const(S1)[5]; - BlkInfo blkinf1 = GC.query(carr1.ptr); - GC.runFinalizers((cast(char*)(typeid(S1).xdtor))[0..1]); - assert(dtorCount == 5); - GC.free(blkinf1.base); - } + dtorCount = 0; + const(S1)[] carr1 = new const(S1)[5]; + BlkInfo blkinf1 = GC.query(carr1.ptr); + GC.runFinalizers((cast(char*)(typeid(S1).xdtor))[0..1]); + assert(dtorCount == 5); + GC.free(blkinf1.base); dtorCount = 0; S1[] arr2 = new S1[10]; @@ -2573,14 +2559,11 @@ unittest arr2.assumeSafeAppend; assert(dtorCount == 4); // destructors run explicitely? - if (callStructDtorsDuringGC) - { - dtorCount = 0; - BlkInfo blkinf = GC.query(arr2.ptr); - GC.runFinalizers((cast(char*)(typeid(S1).xdtor))[0..1]); - assert(dtorCount == 6); - GC.free(blkinf.base); - } + dtorCount = 0; + BlkInfo blkinf = GC.query(arr2.ptr); + GC.runFinalizers((cast(char*)(typeid(S1).xdtor))[0..1]); + assert(dtorCount == 6); + GC.free(blkinf.base); // associative arrays import rt.aaA : entryDtor; @@ -2590,36 +2573,27 @@ unittest S1[int] aa1; aa1[0] = S1(0); aa1[1] = S1(1); - if (callStructDtorsDuringGC) - { - dtorCount = 0; - aa1 = null; - GC.runFinalizers((cast(char*)(&entryDtor))[0..1]); - assert(dtorCount == 2); - } + dtorCount = 0; + aa1 = null; + GC.runFinalizers((cast(char*)(&entryDtor))[0..1]); + assert(dtorCount == 2); int[S1] aa2; aa2[S1(0)] = 0; aa2[S1(1)] = 1; aa2[S1(2)] = 2; - if (callStructDtorsDuringGC) - { - dtorCount = 0; - aa2 = null; - GC.runFinalizers((cast(char*)(&entryDtor))[0..1]); - assert(dtorCount == 3); - } + dtorCount = 0; + aa2 = null; + GC.runFinalizers((cast(char*)(&entryDtor))[0..1]); + assert(dtorCount == 3); S1[2][int] aa3; aa3[0] = [S1(0),S1(2)]; aa3[1] = [S1(1),S1(3)]; - if (callStructDtorsDuringGC) - { - dtorCount = 0; - aa3 = null; - GC.runFinalizers((cast(char*)(&entryDtor))[0..1]); - assert(dtorCount == 4); - } + dtorCount = 0; + aa3 = null; + GC.runFinalizers((cast(char*)(&entryDtor))[0..1]); + assert(dtorCount == 4); } // test class finalizers exception handling @@ -2661,9 +2635,6 @@ unittest debug(SENTINEL) {} else unittest { - if (!callStructDtorsDuringGC) - return; - bool test(E)() { import core.exception; diff --git a/libphobos/src/MERGE b/libphobos/src/MERGE index 1d8f8df..6de04b4 100644 --- a/libphobos/src/MERGE +++ b/libphobos/src/MERGE @@ -1,4 +1,4 @@ -3dd5df6864b3849450d3657e219b90909663a513 +9d575282edeccecbc061e615bf2486fd07e8c084 The first line of this file holds the git revision number of the last merge done from the dlang/phobos repository. diff --git a/libphobos/src/std/conv.d b/libphobos/src/std/conv.d index 743d203..31cc651 100644 --- a/libphobos/src/std/conv.d +++ b/libphobos/src/std/conv.d @@ -3148,8 +3148,6 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum { version (CRuntime_Microsoft) ld1 = 0x1.FFFFFFFFFFFFFFFEp-16382L; // strtold currently mapped to strtod - else version (CRuntime_Bionic) - ld1 = 0x1.FFFFFFFFFFFFFFFEp-16382L; // strtold currently mapped to strtod else ld1 = strtold(s.ptr, null); } diff --git a/libphobos/src/std/datetime/systime.d b/libphobos/src/std/datetime/systime.d index 0b11ed9..b229191 100644 --- a/libphobos/src/std/datetime/systime.d +++ b/libphobos/src/std/datetime/systime.d @@ -7,6 +7,15 @@ +/ module std.datetime.systime; +version (OSX) + version = Darwin; +else version (iOS) + version = Darwin; +else version (TVOS) + version = Darwin; +else version (WatchOS) + version = Darwin; + import core.time; import std.datetime.date; import std.datetime.timezone; @@ -161,18 +170,19 @@ public: static import core.stdc.time; enum hnsecsToUnixEpoch = unixTimeToStdTime(0); - version (OSX) + version (Darwin) { static if (clockType == ClockType.second) return unixTimeToStdTime(core.stdc.time.time(null)); else { import core.sys.posix.sys.time : gettimeofday, timeval; - timeval tv; - if (gettimeofday(&tv, null) != 0) - throw new TimeException("Call to gettimeofday() failed"); + timeval tv = void; + // Posix gettimeofday called with a valid timeval address + // and a null second parameter doesn't fail. + gettimeofday(&tv, null); return convert!("seconds", "hnsecs")(tv.tv_sec) + - convert!("usecs", "hnsecs")(tv.tv_usec) + + tv.tv_usec * 10 + hnsecsToUnixEpoch; } } @@ -188,9 +198,16 @@ public: else static if (clockType == ClockType.normal) alias clockArg = CLOCK_REALTIME; else static if (clockType == ClockType.precise) alias clockArg = CLOCK_REALTIME; else static assert(0, "Previous static if is wrong."); - timespec ts; - if (clock_gettime(clockArg, &ts) != 0) - throw new TimeException("Call to clock_gettime() failed"); + timespec ts = void; + immutable error = clock_gettime(clockArg, &ts); + // Posix clock_gettime called with a valid address and valid clock_id is only + // permitted to fail if the number of seconds does not fit in time_t. If tv_sec + // is long or larger overflow won't happen before 292 billion years A.D. + static if (ts.tv_sec.max < long.max) + { + if (error) + throw new TimeException("Call to clock_gettime() failed"); + } return convert!("seconds", "hnsecs")(ts.tv_sec) + ts.tv_nsec / 100 + hnsecsToUnixEpoch; @@ -205,9 +222,16 @@ public: else static if (clockType == ClockType.precise) alias clockArg = CLOCK_REALTIME_PRECISE; else static if (clockType == ClockType.second) alias clockArg = CLOCK_SECOND; else static assert(0, "Previous static if is wrong."); - timespec ts; - if (clock_gettime(clockArg, &ts) != 0) - throw new TimeException("Call to clock_gettime() failed"); + timespec ts = void; + immutable error = clock_gettime(clockArg, &ts); + // Posix clock_gettime called with a valid address and valid clock_id is only + // permitted to fail if the number of seconds does not fit in time_t. If tv_sec + // is long or larger overflow won't happen before 292 billion years A.D. + static if (ts.tv_sec.max < long.max) + { + if (error) + throw new TimeException("Call to clock_gettime() failed"); + } return convert!("seconds", "hnsecs")(ts.tv_sec) + ts.tv_nsec / 100 + hnsecsToUnixEpoch; @@ -218,12 +242,38 @@ public: return unixTimeToStdTime(core.stdc.time.time(null)); else { - import core.sys.posix.sys.time : gettimeofday, timeval; - timeval tv; - if (gettimeofday(&tv, null) != 0) - throw new TimeException("Call to gettimeofday() failed"); - return convert!("seconds", "hnsecs")(tv.tv_sec) + - convert!("usecs", "hnsecs")(tv.tv_usec) + + import core.sys.netbsd.time : clock_gettime, CLOCK_REALTIME; + timespec ts = void; + immutable error = clock_gettime(CLOCK_REALTIME, &ts); + // Posix clock_gettime called with a valid address and valid clock_id is only + // permitted to fail if the number of seconds does not fit in time_t. If tv_sec + // is long or larger overflow won't happen before 292 billion years A.D. + static if (ts.tv_sec.max < long.max) + { + if (error) + throw new TimeException("Call to clock_gettime() failed"); + } + return convert!("seconds", "hnsecs")(ts.tv_sec) + + ts.tv_nsec / 100 + + hnsecsToUnixEpoch; + } + } + else version (OpenBSD) + { + static if (clockType == ClockType.second) + return unixTimeToStdTime(core.stdc.time.time(null)); + else + { + import core.sys.openbsd.time : clock_gettime, CLOCK_REALTIME; + static if (clockType == ClockType.coarse) alias clockArg = CLOCK_REALTIME; + else static if (clockType == ClockType.normal) alias clockArg = CLOCK_REALTIME; + else static if (clockType == ClockType.precise) alias clockArg = CLOCK_REALTIME; + else static assert(0, "Previous static if is wrong."); + timespec ts; + if (clock_gettime(clockArg, &ts) != 0) + throw new TimeException("Call to clock_gettime() failed"); + return convert!("seconds", "hnsecs")(ts.tv_sec) + + ts.tv_nsec / 100 + hnsecsToUnixEpoch; } } @@ -236,9 +286,16 @@ public: else static if (clockType == ClockType.precise) alias clockArg = CLOCK_REALTIME_PRECISE; else static if (clockType == ClockType.second) alias clockArg = CLOCK_SECOND; else static assert(0, "Previous static if is wrong."); - timespec ts; - if (clock_gettime(clockArg, &ts) != 0) - throw new TimeException("Call to clock_gettime() failed"); + timespec ts = void; + immutable error = clock_gettime(clockArg, &ts); + // Posix clock_gettime called with a valid address and valid clock_id is only + // permitted to fail if the number of seconds does not fit in time_t. If tv_sec + // is long or larger overflow won't happen before 292 billion years A.D. + static if (ts.tv_sec.max < long.max) + { + if (error) + throw new TimeException("Call to clock_gettime() failed"); + } return convert!("seconds", "hnsecs")(ts.tv_sec) + ts.tv_nsec / 100 + hnsecsToUnixEpoch; @@ -254,9 +311,16 @@ public: else static if (clockType == ClockType.normal) alias clockArg = CLOCK_REALTIME; else static if (clockType == ClockType.precise) alias clockArg = CLOCK_REALTIME; else static assert(0, "Previous static if is wrong."); - timespec ts; - if (clock_gettime(clockArg, &ts) != 0) - throw new TimeException("Call to clock_gettime() failed"); + timespec ts = void; + immutable error = clock_gettime(clockArg, &ts); + // Posix clock_gettime called with a valid address and valid clock_id is only + // permitted to fail if the number of seconds does not fit in time_t. If tv_sec + // is long or larger overflow won't happen before 292 billion years A.D. + static if (ts.tv_sec.max < long.max) + { + if (error) + throw new TimeException("Call to clock_gettime() failed"); + } return convert!("seconds", "hnsecs")(ts.tv_sec) + ts.tv_nsec / 100 + hnsecsToUnixEpoch; diff --git a/libphobos/src/std/datetime/timezone.d b/libphobos/src/std/datetime/timezone.d index 7ae1902..9b744ff 100644 --- a/libphobos/src/std/datetime/timezone.d +++ b/libphobos/src/std/datetime/timezone.d @@ -14,6 +14,15 @@ import std.exception : enforce; import std.range.primitives; import std.traits : isIntegral, isSomeString, Unqual; +version (OSX) + version = Darwin; +else version (iOS) + version = Darwin; +else version (TVOS) + version = Darwin; +else version (WatchOS) + version = Darwin; + version (Windows) { import core.stdc.time : time_t; @@ -296,7 +305,7 @@ public: else version (NetBSD) enum utcZone = "UTC"; else version (DragonFlyBSD) enum utcZone = "UTC"; else version (linux) enum utcZone = "UTC"; - else version (OSX) enum utcZone = "UTC"; + else version (Darwin) enum utcZone = "UTC"; else version (Solaris) enum utcZone = "UTC"; else static assert(0, "The location of the UTC timezone file on this Posix platform must be set."); @@ -671,7 +680,11 @@ public: @safe unittest { - assert(LocalTime().dstName !is null); + // tzname, called from dstName, isn't set by default for Musl. + version (CRuntime_Musl) + assert(LocalTime().dstName is null); + else + assert(LocalTime().dstName !is null); version (Posix) { diff --git a/libphobos/src/std/exception.d b/libphobos/src/std/exception.d index 73afadc..56133c9 100644 --- a/libphobos/src/std/exception.d +++ b/libphobos/src/std/exception.d @@ -1478,10 +1478,13 @@ private bool isUnionAliasedImpl(T)(size_t offset) static assert( isUnionAliased!(S.A5, 1)); //a5.b1; } +version (CRuntime_Glibc) version = GNU_STRERROR; +version (CRuntime_UClibc) version = GNU_STRERROR; + package string errnoString(int errno) nothrow @trusted { import core.stdc.string : strlen; - version (CRuntime_Glibc) + version (GNU_STRERROR) { import core.stdc.string : strerror_r; char[1024] buf = void; diff --git a/libphobos/src/std/experimental/allocator/building_blocks/region.d b/libphobos/src/std/experimental/allocator/building_blocks/region.d index 835d093..53f5ef9 100644 --- a/libphobos/src/std/experimental/allocator/building_blocks/region.d +++ b/libphobos/src/std/experimental/allocator/building_blocks/region.d @@ -5,6 +5,15 @@ import std.experimental.allocator.building_blocks.null_allocator; import std.experimental.allocator.common; import std.typecons : Flag, Yes, No; +version (OSX) + version = Darwin; +else version (iOS) + version = Darwin; +else version (TVOS) + version = Darwin; +else version (WatchOS) + version = Darwin; + /** A $(D Region) allocator allocates memory straight from one contiguous chunk. There is no deallocation, and once the region is full, allocation requests @@ -580,14 +589,26 @@ struct InSituRegion(size_t size, size_t minAlign = platformAlignment) assert(a.length == 2001); } -version(CRuntime_Musl) +version (CRuntime_Musl) { // sbrk and brk are disabled in Musl: // https://git.musl-libc.org/cgit/musl/commit/?id=7a995fe706e519a4f55399776ef0df9596101f93 // https://git.musl-libc.org/cgit/musl/commit/?id=863d628d93ea341b6a32661a1654320ce69f6a07 -} else: -private extern(C) void* sbrk(long); -private extern(C) int brk(shared void*); +} +version (DragonFlyBSD) +{ + // sbrk is deprecated in favor of mmap (we could implement a mmap + MAP_NORESERVE + PROT_NONE version) + // brk has been removed + // https://www.dragonflydigest.com/2019/02/22/22586.html + // http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/dc676eaefa61b0f47bbea1c53eab86fd5ccd78c6 + // http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/4b5665564ef37dc939a3a9ffbafaab9894c18885 + // http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/8618d94a0e2ff8303ad93c123a3fa598c26a116e +} +else +{ + private extern(C) void* sbrk(long) nothrow @nogc; + private extern(C) int brk(shared void*) nothrow @nogc; +} /** @@ -599,11 +620,14 @@ that uncontrolled calls to $(D brk) and $(D sbrk) may affect the workings of $(D SbrkRegion) adversely. */ +version (CRuntime_Musl) {} else +version (DragonFlyBSD) {} else version (Posix) struct SbrkRegion(uint minAlign = platformAlignment) { import core.sys.posix.pthread : pthread_mutex_init, pthread_mutex_destroy, pthread_mutex_t, pthread_mutex_lock, pthread_mutex_unlock, - PTHREAD_MUTEX_INITIALIZER; + + PTHREAD_MUTEX_INITIALIZER; private static shared pthread_mutex_t sbrkMutex = PTHREAD_MUTEX_INITIALIZER; import std.typecons : Ternary; @@ -763,7 +787,9 @@ version (Posix) struct SbrkRegion(uint minAlign = platformAlignment) } } -version (Posix) @system unittest +version (CRuntime_Musl) {} else +version (DragonFlyBSD) {} else +version (Posix) @system nothrow @nogc unittest { // Let's test the assumption that sbrk(n) returns the old address const p1 = sbrk(0); @@ -775,7 +801,9 @@ version (Posix) @system unittest sbrk(-4096); } -version (Posix) @system unittest +version (CRuntime_Musl) {} else +version (DragonFlyBSD) {} else +version (Posix) @system nothrow @nogc unittest { import std.typecons : Ternary; alias alloc = SbrkRegion!(8).instance; @@ -786,7 +814,7 @@ version (Posix) @system unittest assert(alloc.owns(a) == Ternary.yes); assert(alloc.owns(b) == Ternary.yes); // reducing the brk does not work on OSX - version (OSX) {} else + version (Darwin) {} else { assert(alloc.deallocate(b)); assert(alloc.deallocateAll); diff --git a/libphobos/src/std/experimental/allocator/mmap_allocator.d b/libphobos/src/std/experimental/allocator/mmap_allocator.d index 945859b..e07d444 100644 --- a/libphobos/src/std/experimental/allocator/mmap_allocator.d +++ b/libphobos/src/std/experimental/allocator/mmap_allocator.d @@ -46,6 +46,21 @@ struct MmapAllocator if (b.ptr) munmap(b.ptr, b.length) == 0 || assert(0); return true; } + + // Anonymous mmap might be zero-filled on all Posix systems but + // not all commit to this in the documentation. + version (linux) + // http://man7.org/linux/man-pages/man2/mmap.2.html + package alias allocateZeroed = allocate; + else version (NetBSD) + // http://netbsd.gw.com/cgi-bin/man-cgi?mmap+2+NetBSD-current + package alias allocateZeroed = allocate; + else version (Solaris) + // https://docs.oracle.com/cd/E88353_01/html/E37841/mmap-2.html + package alias allocateZeroed = allocate; + else version (AIX) + // https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/com.ibm.aix.basetrf1/mmap.htm + package alias allocateZeroed = allocate; } else version (Windows) { @@ -67,6 +82,8 @@ struct MmapAllocator { return b.ptr is null || VirtualFree(b.ptr, 0, MEM_RELEASE) != 0; } + + package alias allocateZeroed = allocate; } } diff --git a/libphobos/src/std/file.d b/libphobos/src/std/file.d index 380ecfc..13a3db0 100644 --- a/libphobos/src/std/file.d +++ b/libphobos/src/std/file.d @@ -1490,6 +1490,15 @@ if (isInputRange!R && !isInfinite!R && isSomeChar!(ElementEncodingType!R)) // vfs.timestamp_precision sysctl to a value greater than zero. // - OS X, where the native filesystem (HFS+) stores filesystem // timestamps with 1-second precision. +// +// Note: on linux systems, although in theory a change to a file date +// can be tracked with precision of 4 msecs, this test waits 20 msecs +// to prevent possible problems relative to the CI services the dlang uses, +// as they may have the HZ setting that controls the software clock set to 100 +// (instead of the more common 250). +// see https://man7.org/linux/man-pages/man7/time.7.html +// https://stackoverflow.com/a/14393315, +// https://issues.dlang.org/show_bug.cgi?id=21148 version (FreeBSD) {} else version (DragonFlyBSD) {} else version (OSX) {} else @@ -1508,7 +1517,7 @@ version (OSX) {} else remove(deleteme); assert(time != lastTime); lastTime = time; - Thread.sleep(10.msecs); + Thread.sleep(20.msecs); } } @@ -2757,15 +2766,27 @@ else version (NetBSD) buffer.length *= 2; } } + else version (DragonFlyBSD) + { + import core.sys.dragonflybsd.sys.sysctl : sysctl, CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME; + import std.exception : errnoEnforce, assumeUnique; + + int[4] mib = [CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1]; + size_t len; + + auto result = sysctl(mib.ptr, mib.length, null, &len, null, 0); // get the length of the path + errnoEnforce(result == 0); + + auto buffer = new char[len - 1]; + result = sysctl(mib.ptr, mib.length, buffer.ptr, &len, null, 0); + errnoEnforce(result == 0); + + return buffer.assumeUnique; + } else version (FreeBSD) { + import core.sys.freebsd.sys.sysctl : sysctl, CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME; import std.exception : errnoEnforce, assumeUnique; - enum - { - CTL_KERN = 1, - KERN_PROC = 14, - KERN_PROC_PATHNAME = 12 - } int[4] mib = [CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1]; size_t len; @@ -2781,11 +2802,58 @@ else version (NetBSD) } else version (NetBSD) { - return readLink("/proc/self/exe"); + import core.sys.netbsd.sys.sysctl : sysctl, CTL_KERN, KERN_PROC_ARGS, KERN_PROC_PATHNAME; + import std.exception : errnoEnforce, assumeUnique; + + int[4] mib = [CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME]; + size_t len; + + auto result = sysctl(mib.ptr, mib.length, null, &len, null, 0); // get the length of the path + errnoEnforce(result == 0); + + auto buffer = new char[len - 1]; + result = sysctl(mib.ptr, mib.length, buffer.ptr, &len, null, 0); + errnoEnforce(result == 0); + + return buffer.assumeUnique; } - else version (DragonFlyBSD) + else version (OpenBSD) { - return readLink("/proc/curproc/file"); + import core.sys.openbsd.sys.sysctl : sysctl, CTL_KERN, KERN_PROC_ARGS, KERN_PROC_ARGV; + import core.sys.posix.unistd : getpid; + import std.conv : to; + import std.exception : enforce, errnoEnforce; + import std.process : searchPathFor; + + int[4] mib = [CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV]; + size_t len; + + auto result = sysctl(mib.ptr, mib.length, null, &len, null, 0); + errnoEnforce(result == 0); + + auto argv = new char*[len - 1]; + result = sysctl(mib.ptr, mib.length, argv.ptr, &len, null, 0); + errnoEnforce(result == 0); + + auto argv0 = argv[0]; + if (*argv0 == '/' || *argv0 == '.') + { + import core.sys.posix.stdlib : realpath; + auto absolutePath = realpath(argv0, null); + scope (exit) + { + if (absolutePath) + free(absolutePath); + } + errnoEnforce(absolutePath); + return to!(string)(absolutePath); + } + else + { + auto absolutePath = searchPathFor(to!string(argv0)); + errnoEnforce(absolutePath); + return absolutePath; + } } else version (Solaris) { diff --git a/libphobos/src/std/math.d b/libphobos/src/std/math.d index 3d18cfa..ff368b7 100644 --- a/libphobos/src/std/math.d +++ b/libphobos/src/std/math.d @@ -167,19 +167,14 @@ version (SystemZ) version = IBMZ_Any; version (RISCV32) version = RISCV_Any; version (RISCV64) version = RISCV_Any; -version (D_InlineAsm_X86) -{ - version = InlineAsm_X86_Any; -} -else version (D_InlineAsm_X86_64) -{ - version = InlineAsm_X86_Any; -} +version (D_InlineAsm_X86) version = InlineAsm_X86_Any; +version (D_InlineAsm_X86_64) version = InlineAsm_X86_Any; -version (CRuntime_Microsoft) +version (InlineAsm_X86_Any) version = InlineAsm_X87; +version (InlineAsm_X87) { - version (InlineAsm_X86_Any) - version = MSVC_InlineAsm; + static assert(real.mant_dig == 64); + version (CRuntime_Microsoft) version = InlineAsm_X87_MSVC; } version (X86_64) version = StaticallyHaveSSE; @@ -3610,7 +3605,7 @@ real log1p(real x) @safe pure nothrow @nogc real log2(real x) @safe pure nothrow @nogc { version (INLINE_YL2X) - return core.math.yl2x(x, 1); + return core.math.yl2x(x, 1.0L); else { // Special cases are the same as for log. @@ -4586,19 +4581,21 @@ real round(real x) @trusted nothrow @nogc * If the fractional part of x is exactly 0.5, the return value is rounded * away from zero. * - * $(BLUE This function is Posix-Only.) + * $(BLUE This function is not implemented for Digital Mars C runtime.) */ long lround(real x) @trusted nothrow @nogc { - version (Posix) - return core.stdc.math.llroundl(x); - else + version (CRuntime_DigitalMars) assert(0, "lround not implemented"); + else + return core.stdc.math.llroundl(x); } -version (Posix) +/// +@safe nothrow @nogc unittest { - @safe nothrow @nogc unittest + version (CRuntime_DigitalMars) {} + else { assert(lround(0.49) == 0); assert(lround(0.5) == 1); diff --git a/libphobos/src/std/parallelism.d b/libphobos/src/std/parallelism.d index 64fa2f9..43a1ba5 100644 --- a/libphobos/src/std/parallelism.d +++ b/libphobos/src/std/parallelism.d @@ -40,6 +40,15 @@ License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0) */ module std.parallelism; +version (OSX) + version = Darwin; +else version (iOS) + version = Darwin; +else version (TVOS) + version = Darwin; +else version (WatchOS) + version = Darwin; + /// @system unittest { @@ -86,107 +95,82 @@ import std.meta; import std.range.primitives; import std.traits; -version (OSX) -{ - version = useSysctlbyname; -} -else version (FreeBSD) -{ - version = useSysctlbyname; -} -else version (DragonFlyBSD) -{ - version = useSysctlbyname; -} -else version (NetBSD) -{ - version = useSysctlbyname; -} +/* +(For now public undocumented with reserved name.) +A lazily initialized global constant. The underlying value is a shared global +statically initialized to `outOfBandValue` which must not be a legit value of +the constant. Upon the first call the situation is detected and the global is +initialized by calling `initializer`. The initializer is assumed to be pure +(even if not marked as such), i.e. return the same value upon repeated calls. +For that reason, no special precautions are taken so `initializer` may be called +more than one time leading to benign races on the cached value. -version (Windows) -{ - // BUGS: Only works on Windows 2000 and above. - shared static this() - { - import core.sys.windows.windows : SYSTEM_INFO, GetSystemInfo; - import std.algorithm.comparison : max; +In the quiescent state the cost of the function is an atomic load from a global. - SYSTEM_INFO si; - GetSystemInfo(&si); - totalCPUs = max(1, cast(uint) si.dwNumberOfProcessors); - } +Params: + T = The type of the pseudo-constant (may be qualified) + outOfBandValue = A value that cannot be valid, it is used for initialization + initializer = The function performing initialization; must be `nothrow` -} -else version (linux) -{ - shared static this() - { - import core.sys.posix.unistd : _SC_NPROCESSORS_ONLN, sysconf; - totalCPUs = cast(uint) sysconf(_SC_NPROCESSORS_ONLN); - } -} -else version (Solaris) -{ - shared static this() - { - import core.sys.posix.unistd : _SC_NPROCESSORS_ONLN, sysconf; - totalCPUs = cast(uint) sysconf(_SC_NPROCESSORS_ONLN); - } -} -else version (useSysctlbyname) +Returns: + The lazily initialized value +*/ +@property pure +T __lazilyInitializedConstant(T, alias outOfBandValue, alias initializer)() +if (is(Unqual!T : T) + && is(typeof(initializer()) : T) + && is(typeof(outOfBandValue) : T)) { - extern(C) int sysctlbyname( - const char *, void *, size_t *, void *, size_t - ); - - shared static this() - { - version (OSX) - { - auto nameStr = "machdep.cpu.core_count\0".ptr; - } - else version (FreeBSD) + static T impl() nothrow + { + // Thread-local cache + static Unqual!T tls = outOfBandValue; + auto local = tls; + // Shortest path, no atomic operations + if (local != outOfBandValue) return local; + // Process-level cache + static shared Unqual!T result = outOfBandValue; + // Initialize both process-level cache and tls + local = atomicLoad(result); + if (local == outOfBandValue) { - auto nameStr = "hw.ncpu\0".ptr; + local = initializer(); + atomicStore(result, local); } - else version (DragonFlyBSD) - { - auto nameStr = "hw.ncpu\0".ptr; - } - else version (NetBSD) - { - auto nameStr = "hw.ncpu\0".ptr; - } - - uint ans; - size_t len = uint.sizeof; - sysctlbyname(nameStr, &ans, &len, null, 0); - totalCPUs = ans; + tls = local; + return local; } + import std.traits : SetFunctionAttributes; + alias Fun = SetFunctionAttributes!(typeof(&impl), "D", + functionAttributes!(typeof(&impl)) | FunctionAttribute.pure_); + auto purified = (() @trusted => cast(Fun) &impl)(); + return purified(); } -else -{ - static assert(0, "Don't know how to get N CPUs on this OS."); -} -immutable size_t cacheLineSize; -shared static this() +// Returns the size of a cache line. +alias cacheLineSize = + __lazilyInitializedConstant!(immutable(size_t), size_t.max, cacheLineSizeImpl); + +private size_t cacheLineSizeImpl() @nogc nothrow @trusted { + size_t result = 0; import core.cpuid : datacache; - size_t lineSize = 0; - foreach (cachelevel; datacache) + foreach (ref const cachelevel; datacache) { - if (cachelevel.lineSize > lineSize && cachelevel.lineSize < uint.max) + if (cachelevel.lineSize > result && cachelevel.lineSize < uint.max) { - lineSize = cachelevel.lineSize; + result = cachelevel.lineSize; } } - - cacheLineSize = lineSize; + return result; } +@nogc @safe nothrow unittest +{ + assert(cacheLineSize == cacheLineSizeImpl); +} /* Atomics code. These forward to core.atomic, but are written like this for two reasons: @@ -957,7 +941,81 @@ if (is(typeof(fun(args))) && isSafeTask!F) The total number of CPU cores available on the current machine, as reported by the operating system. */ -immutable uint totalCPUs; +alias totalCPUs = + __lazilyInitializedConstant!(immutable(uint), uint.max, totalCPUsImpl); + +uint totalCPUsImpl() @nogc nothrow @trusted +{ + version (Windows) + { + // BUGS: Only works on Windows 2000 and above. + import core.sys.windows.winbase : SYSTEM_INFO, GetSystemInfo; + import std.algorithm.comparison : max; + SYSTEM_INFO si; + GetSystemInfo(&si); + return max(1, cast(uint) si.dwNumberOfProcessors); + } + else version (linux) + { + import core.sys.linux.sched : CPU_COUNT, cpu_set_t, sched_getaffinity; + import core.sys.posix.unistd : _SC_NPROCESSORS_ONLN, sysconf; + + cpu_set_t set = void; + if (sched_getaffinity(0, cpu_set_t.sizeof, &set) == 0) + { + int count = CPU_COUNT(&set); + if (count > 0) + return cast(uint) count; + } + return cast(uint) sysconf(_SC_NPROCESSORS_ONLN); + } + else version (Darwin) + { + import core.sys.darwin.sys.sysctl : sysctlbyname; + uint result; + size_t len = result.sizeof; + sysctlbyname("hw.physicalcpu", &result, &len, null, 0); + return result; + } + else version (DragonFlyBSD) + { + import core.sys.dragonflybsd.sys.sysctl : sysctlbyname; + uint result; + size_t len = result.sizeof; + sysctlbyname("hw.ncpu", &result, &len, null, 0); + return result; + } + else version (FreeBSD) + { + import core.sys.freebsd.sys.sysctl : sysctlbyname; + uint result; + size_t len = result.sizeof; + sysctlbyname("hw.ncpu", &result, &len, null, 0); + return result; + } + else version (NetBSD) + { + import core.sys.netbsd.sys.sysctl : sysctlbyname; + uint result; + size_t len = result.sizeof; + sysctlbyname("hw.ncpu", &result, &len, null, 0); + return result; + } + else version (Solaris) + { + import core.sys.posix.unistd : _SC_NPROCESSORS_ONLN, sysconf; + return cast(uint) sysconf(_SC_NPROCESSORS_ONLN); + } + else version (OpenBSD) + { + import core.sys.posix.unistd : _SC_NPROCESSORS_ONLN, sysconf; + return cast(uint) sysconf(_SC_NPROCESSORS_ONLN); + } + else + { + static assert(0, "Don't know how to get N CPUs on this OS."); + } +} /* This class serves two purposes: @@ -3302,11 +3360,7 @@ terminating the main thread. }()); } -private shared uint _defaultPoolThreads; -shared static this() -{ - atomicStore(_defaultPoolThreads, totalCPUs - 1); -} +private shared uint _defaultPoolThreads = uint.max; /** These properties get and set the number of worker threads in the $(D TaskPool) @@ -3316,7 +3370,8 @@ number of worker threads in the instance returned by $(D taskPool). */ @property uint defaultPoolThreads() @trusted { - return atomicLoad(_defaultPoolThreads); + const local = atomicLoad(_defaultPoolThreads); + return local < uint.max ? local : totalCPUs - 1; } /// Ditto diff --git a/libphobos/src/std/socket.d b/libphobos/src/std/socket.d index a4ba39c..ecb2c8b 100644 --- a/libphobos/src/std/socket.d +++ b/libphobos/src/std/socket.d @@ -146,6 +146,8 @@ class SocketException: Exception mixin basicExceptionCtors; } +version (CRuntime_Glibc) version = GNU_STRERROR; +version (CRuntime_UClibc) version = GNU_STRERROR; /* * Needs to be public so that SocketOSException can be thrown outside of @@ -159,7 +161,7 @@ string formatSocketError(int err) @trusted { char[80] buf; const(char)* cs; - version (CRuntime_Glibc) + version (GNU_STRERROR) { cs = strerror_r(err, buf.ptr, buf.length); } diff --git a/libphobos/src/std/stdio.d b/libphobos/src/std/stdio.d index c59bc4c..bbf7857 100644 --- a/libphobos/src/std/stdio.d +++ b/libphobos/src/std/stdio.d @@ -79,6 +79,10 @@ else version (NetBSD) { version = GENERIC_IO; } +else version (OpenBSD) +{ + version = GENERIC_IO; +} else version (DragonFlyBSD) { version = GENERIC_IO; @@ -93,12 +97,11 @@ version (Windows) { private alias FSChar = wchar; } -else version (Posix) +else { private alias FSChar = char; } -else - static assert(0); + version (Windows) { diff --git a/libphobos/src/std/system.d b/libphobos/src/std/system.d index e0b3dee..353d692 100644 --- a/libphobos/src/std/system.d +++ b/libphobos/src/std/system.d @@ -30,6 +30,9 @@ immutable win64, /// Microsoft 64 bit Windows systems linux, /// All Linux Systems, except for Android osx, /// Mac OS X + iOS, /// iOS + tvOS, /// tvOS + watchOS, /// watchOS freeBSD, /// FreeBSD netBSD, /// NetBSD dragonFlyBSD, /// DragonFlyBSD @@ -44,6 +47,9 @@ immutable else version (Android) OS os = OS.android; else version (linux) OS os = OS.linux; else version (OSX) OS os = OS.osx; + else version (iOS) OS os = OS.iOS; + else version (tvOS) OS os = OS.tvOS; + else version (watchOS) OS os = OS.watchOS; else version (FreeBSD) OS os = OS.freeBSD; else version (NetBSD) OS os = OS.netBSD; else version (DragonFlyBSD) OS os = OS.dragonFlyBSD; diff --git a/libphobos/testsuite/libphobos.allocations/tls_gc_integration.d b/libphobos/testsuite/libphobos.allocations/tls_gc_integration.d index 44eb40c..7c084ab 100644 --- a/libphobos/testsuite/libphobos.allocations/tls_gc_integration.d +++ b/libphobos/testsuite/libphobos.allocations/tls_gc_integration.d @@ -1,4 +1,4 @@ -import core.memory, core.thread, core.bitop; +import core.memory, core.thread, core.volatile; /* * This test repeatedly performs operations on GC-allocated objects which |