From d061f13d34a35a16c4d51df0ae985d1b28eb4ef9 Mon Sep 17 00:00:00 2001 From: Andrei Alexandrescu Date: Sun, 1 May 2011 12:11:46 -0500 Subject: [PATCH] https://github.com/D-Programming-Language/phobos/pull/23 --- index.d | 3 - posix.mak | 18 ++--- std/array.d | 4 +- std/bitmanip.d | 2 +- std/c/windows/winsock.d | 2 +- std/intrinsic.d | 163 ++-------------------------------------- std/numeric.d | 12 ++- std/range.d | 3 +- std/stream.d | 2 +- std/zip.d | 2 +- unittest.d | 1 - win32.mak | 12 +-- 12 files changed, 34 insertions(+), 190 deletions(-) diff --git a/index.d b/index.d index 8e738bcb1..46a88fbe7 100644 --- a/index.d +++ b/index.d @@ -160,9 +160,6 @@ D language compiler. Also, check out the
std.gc
Control the garbage collector. -
std.intrinsic -
Compiler built in intrinsic functions -
std.math
Include all the usual math functions like sin, cos, atan, etc. diff --git a/posix.mak b/posix.mak index cb37cf2d5..0d4ca707f 100644 --- a/posix.mak +++ b/posix.mak @@ -152,15 +152,15 @@ endif MAIN = $(ROOT)/emptymain.d # Stuff in std/ -STD_MODULES = $(addprefix std/, algorithm array base64 bigint bitmanip \ - compiler complex concurrency container contracts conv cpuid \ - cstream ctype date datetime datebase dateparse demangle \ - encoding exception file format functional getopt gregorian \ - intrinsic json loader math mathspecial md5 metastrings mmfile \ - numeric outbuffer parallelism path perf process random range \ - regex regexp signals socket socketstream stdint stdio stdiobase \ - stream string syserror system traits typecons typetuple uni uri \ - utf variant xml zip zlib) +STD_MODULES = $(addprefix std/, algorithm array base64 bigint \ + bitmanip compiler complex concurrency container contracts \ + conv cpuid cstream ctype date datetime datebase dateparse \ + demangle encoding exception file format functional getopt \ + gregorian json loader math mathspecial md5 metastrings mmfile \ + numeric outbuffer parallelism path perf process random range \ + regex regexp signals socket socketstream stdint stdio \ + stdiobase stream string syserror system traits typecons \ + typetuple uni uri utf variant xml zip zlib) STD_NET_MODULES = $(addprefix std/net/, isemail) diff --git a/std/array.d b/std/array.d index 3fc436aeb..c764f24e1 100644 --- a/std/array.d +++ b/std/array.d @@ -12,9 +12,9 @@ Source: $(PHOBOSSRC std/_array.d) */ module std.array; -import core.memory; +import core.memory, core.bitop; import std.algorithm, std.conv, std.ctype, std.encoding, std.exception, - std.intrinsic, std.range, std.string, std.traits, std.typecons, std.utf; + std.range, std.string, std.traits, std.typecons, std.utf; import std.c.string : memcpy; version(unittest) import core.exception, std.stdio, std.typetuple; diff --git a/std/bitmanip.d b/std/bitmanip.d index efb620456..bd90b7530 100644 --- a/std/bitmanip.d +++ b/std/bitmanip.d @@ -23,7 +23,7 @@ module std.bitmanip; //debug = bitarray; // uncomment to turn on debugging printf's -private import std.intrinsic; +import core.bitop; string myToStringx(ulong n) { enum s = "0123456789"; diff --git a/std/c/windows/winsock.d b/std/c/windows/winsock.d index 391c320d2..d5577d139 100644 --- a/std/c/windows/winsock.d +++ b/std/c/windows/winsock.d @@ -316,7 +316,7 @@ version(BigEndian) } else version(LittleEndian) { - private import std.intrinsic; + private import core.bitop; uint16_t htons(uint16_t x) diff --git a/std/intrinsic.d b/std/intrinsic.d index e5b91877b..97f61b729 100644 --- a/std/intrinsic.d +++ b/std/intrinsic.d @@ -3,7 +3,11 @@ // www.digitalmars.com // Placed into the public domain -/** These functions are built-in intrinsics to the compiler. +/** + * $(RED This module has been deprecated. Use $(LINK2 core_bitop.html, + * core.bitop) instead.) + * + * These functions are built-in intrinsics to the compiler. * Intrinsic functions are functions built in to the compiler, usually to take advantage of specific CPU features that @@ -23,160 +27,9 @@ module std.intrinsic; -nothrow: +deprecated: -/** - * Scans the bits in v starting with bit 0, looking - * for the first set bit. - * Returns: - * The bit number of the first bit set. - * The return value is undefined if v is zero. - */ -pure int bsf(size_t v); - -/** - * Scans the bits in v from the most significant bit - * to the least significant bit, looking - * for the first set bit. - * Returns: - * The bit number of the first bit set. - * The return value is undefined if v is zero. - * Example: - * --- - * import std.stdio; - * import std.intrinsic; - * - * int main() - * { - * uint v; - * int x; - * - * v = 0x21; - * x = bsf(v); - * writefln("bsf(x%x) = %d", v, x); - * x = bsr(v); - * writefln("bsr(x%x) = %d", v, x); - * return 0; - * } - * --- - * Output: - * bsf(x21) = 0
- * bsr(x21) = 5 - */ -pure int bsr(size_t v); - -/** - * Tests the bit. - */ -pure int bt(in size_t* p, size_t bitnum); - -/** - * Tests and complements the bit. - */ -int btc(size_t* p, size_t bitnum); - -/** - * Tests and resets (sets to 0) the bit. - */ -int btr(size_t* p, size_t bitnum); - -/** - * Tests and sets the bit. - * Params: - * p = a non-NULL pointer to an array of size_ts. - * index = a bit number, starting with bit 0 of p[0], - * and progressing. It addresses bits like the expression: ---- -p[index / (size_t.sizeof*8)] & (1 << (index & ((size_t.sizeof*8) - 1))) ---- - * Returns: - * A non-zero value if the bit was set, and a zero - * if it was clear. - * - * Example: - * --- -import std.stdio; -import std.intrinsic; - -int main() -{ - size_t array[2]; - - array[0] = 2; - array[1] = 0x100; - - writefln("btc(array, 35) = %d", btc(array, 35)); - writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]); - - writefln("btc(array, 35) = %d", btc(array, 35)); - writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]); - - writefln("bts(array, 35) = %d", bts(array, 35)); - writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]); - - writefln("btr(array, 35) = %d", btr(array, 35)); - writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]); - - writefln("bt(array, 1) = %d", bt(array, 1)); - writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]); - - return 0; -} - * --- - * Output: -
-btc(array, 35) = 0
-array = [0]:x2, [1]:x108
-btc(array, 35) = -1
-array = [0]:x2, [1]:x100
-bts(array, 35) = 0
-array = [0]:x2, [1]:x108
-btr(array, 35) = -1
-array = [0]:x2, [1]:x100
-bt(array, 1) = -1
-array = [0]:x2, [1]:x100
-
- */ -int bts(size_t* p, size_t bitnum); - - -/** - * 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. - */ -pure uint bswap(uint v); - - -/** - * Reads I/O port at port_address. - */ -ubyte inp(uint port_address); - -/** - * ditto - */ -ushort inpw(uint port_address); - -/** - * ditto - */ -uint inpl(uint port_address); - - -/** - * Writes and returns value to I/O port at port_address. - */ -ubyte outp(uint port_address, ubyte value); - -/** - * ditto - */ -ushort outpw(uint port_address, ushort value); - -/** - * ditto - */ -uint outpl(uint port_address, uint value); +pragma(msg, "std.intrinsic has been moved. Please import core.bitop instead."); +public import core.bitop; diff --git a/std/numeric.d b/std/numeric.d index cf75a39b1..8f3584b13 100644 --- a/std/numeric.d +++ b/std/numeric.d @@ -37,9 +37,9 @@ import std.range; import std.c.stdlib; import std.functional; import std.typetuple; -import std.intrinsic; import std.complex; +import core.bitop; import core.memory; import core.exception; @@ -95,8 +95,8 @@ public enum CustomFloatFlags { none = 0 } -// 64-bit version of std.intrinsic.bsr -private int bsr(ulong value) { +// 64-bit version of core.bitop.bsr +private int bsr64(ulong value) { union Ulong { ulong raw; struct { @@ -106,7 +106,7 @@ private int bsr(ulong value) { } Ulong v; v.raw = value; - return v.high==0 ? std.intrinsic.bsr(v.low) : std.intrinsic.bsr(v.high) + 32; + return v.high==0 ? core.bitop.bsr(v.low) : core.bitop.bsr(v.high) + 32; } /** @@ -237,7 +237,7 @@ struct CustomFloat( // Convert denormalized form to normalized form ((flags&Flags.allowDenorm)&&(exp==0)) ){ if(sig > 0) { - auto shift2 = precision - bsr(sig); + auto shift2 = precision - bsr64(sig); exp -= shift2-1; shift += shift2; } else { // value = 0.0 @@ -2624,8 +2624,6 @@ void slowFourier4(Ret, R)(R range, Ret buf) { } bool isPowerOfTwo(size_t num) { - // BUGS: std.intrinsic takes a uint, not a size_t. Therefore, this - // won't work on 64-bit unless std.intrinsic is fixed. return bsr(num) == bsf(num); } diff --git a/std/range.d b/std/range.d index 9390877f9..7e7916c9c 100644 --- a/std/range.d +++ b/std/range.d @@ -23,7 +23,8 @@ fantascienza.net/leonardo/so/, Leonardo Maffi). module std.range; public import std.array; -import std.algorithm, std.conv, std.exception, std.functional, std.intrinsic, +import core.bitop; +import std.algorithm, std.conv, std.exception, std.functional, std.random, std.traits, std.typecons, std.typetuple; // For testing only. This code is included in a string literal to be included diff --git a/std/stream.d b/std/stream.d index 850b8f1ba..533f03cf5 100644 --- a/std/stream.d +++ b/std/stream.d @@ -75,8 +75,8 @@ private { import std.conv; import std.format; import std.system; // for Endian enumeration - import std.intrinsic; // for bswap import std.utf; + import core.bitop; // for bswap import core.vararg; } diff --git a/std/zip.d b/std/zip.d index 071ebc01e..7972ec8b5 100644 --- a/std/zip.d +++ b/std/zip.d @@ -34,7 +34,7 @@ module std.zip; import std.zlib; import std.datetime; -import std.intrinsic; +import core.bitop; import std.conv; //debug=print; diff --git a/unittest.d b/unittest.d index aeea0a7f1..ccb76d19c 100644 --- a/unittest.d +++ b/unittest.d @@ -28,7 +28,6 @@ public import std.demangle; public import std.file; public import std.format; public import std.getopt; -public import std.intrinsic; public import std.loader; public import std.math; public import std.mathspecial; diff --git a/win32.mak b/win32.mak index 60de06173..281a71bd8 100644 --- a/win32.mak +++ b/win32.mak @@ -115,7 +115,7 @@ SRCS_2 = std\math.d std\complex.d std\numeric.d std\bigint.d \ std\encoding.d std\xml.d \ std\random.d std\regexp.d \ std\contracts.d std\exception.d \ - std\intrinsic.d std\compiler.d std\cpuid.d \ + std\compiler.d std\cpuid.d \ std\process.d std\system.d std\concurrency.d SRCS_3 = std\variant.d \ @@ -199,7 +199,6 @@ DOCS= $(DOC)\object.html \ $(DOC)\std_gc.html \ $(DOC)\std_getopt.html \ $(DOC)\std_gregorian.html \ - $(DOC)\std_intrinsic.html \ $(DOC)\std_json.html \ $(DOC)\std_math.html \ $(DOC)\std_mathspecial.html \ @@ -258,7 +257,7 @@ SRC_STD= std\zlib.d std\zip.d std\stdint.d std\container.d std\conv.d std\utf.d std\ctype.d std\file.d std\compiler.d std\system.d \ std\outbuffer.d std\md5.d std\base64.d \ std\dateparse.d std\mmfile.d \ - std\intrinsic.d std\syserror.d \ + std\syserror.d \ std\regexp.d std\random.d std\stream.d std\process.d \ std\socket.d std\socketstream.d std\loader.d std\stdarg.d std\format.d \ std\stdio.d std\perf.d std\uni.d \ @@ -475,7 +474,7 @@ outbuffer.obj : std\outbuffer.d parallelism.obj : std\parallelism.d $(DMD) -c $(DFLAGS) std\parallelism.d - + path.obj : std\path.d $(DMD) -c $(DFLAGS) std\path.d @@ -748,9 +747,6 @@ $(DOC)\std_getopt.html : $(STDDOC) std\getopt.d $(DOC)\std_gregorian.html : $(STDDOC) std\gregorian.d $(DMD) -c -o- $(DFLAGS) -Df$(DOC)\std_gregorian.html $(STDDOC) std\gregorian.d -$(DOC)\std_intrinsic.html : $(STDDOC) std\intrinsic.d - $(DMD) -c -o- $(DFLAGS) -Df$(DOC)\std_intrinsic.html $(STDDOC) std\intrinsic.d - $(DOC)\std_json.html : $(STDDOC) std\json.d $(DMD) -c -o- $(DFLAGS) -Df$(DOC)\std_json.html $(STDDOC) std\json.d @@ -777,7 +773,7 @@ $(DOC)\std_outbuffer.html : $(STDDOC) std\outbuffer.d $(DOC)\std_parallelism.html : $(STDDOC) std\parallelism.d $(DMD) -c -o- $(DFLAGS) -Df$(DOC)\std_parallelism.html $(STDDOC) std\parallelism.d - + $(DOC)\std_path.html : $(STDDOC) std\path.d $(DMD) -c -o- $(DFLAGS) -Df$(DOC)\std_path.html $(STDDOC) std\path.d