mirror of
https://github.com/dlang/phobos.git
synced 2025-04-26 05:00:35 +03:00
This commit is contained in:
parent
1acd1b5dbc
commit
d061f13d34
12 changed files with 34 additions and 190 deletions
3
index.d
3
index.d
|
@ -160,9 +160,6 @@ D language compiler. Also, check out the
|
|||
<dt><a href="std_gc.html"><b>std.gc</b></a>
|
||||
<dd>Control the garbage collector.
|
||||
|
||||
<dt><a href="std_intrinsic.html"><b>std.intrinsic</b></a>
|
||||
<dd>Compiler built in intrinsic functions
|
||||
|
||||
<dt><a href="std_math.html"><b>std.math</b></a>
|
||||
<dd>Include all the usual math functions like sin, cos, atan, etc.
|
||||
|
||||
|
|
18
posix.mak
18
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)
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -316,7 +316,7 @@ version(BigEndian)
|
|||
}
|
||||
else version(LittleEndian)
|
||||
{
|
||||
private import std.intrinsic;
|
||||
private import core.bitop;
|
||||
|
||||
|
||||
uint16_t htons(uint16_t x)
|
||||
|
|
163
std/intrinsic.d
163
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<br>
|
||||
* 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", <b>btc</b>(array, 35));
|
||||
writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]);
|
||||
|
||||
writefln("btc(array, 35) = %d", <b>btc</b>(array, 35));
|
||||
writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]);
|
||||
|
||||
writefln("bts(array, 35) = %d", <b>bts</b>(array, 35));
|
||||
writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]);
|
||||
|
||||
writefln("btr(array, 35) = %d", <b>btr</b>(array, 35));
|
||||
writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]);
|
||||
|
||||
writefln("bt(array, 1) = %d", <b>bt</b>(array, 1));
|
||||
writefln("array = [0]:x%x, [1]:x%x", array[0], array[1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
* ---
|
||||
* Output:
|
||||
<pre>
|
||||
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
|
||||
</pre>
|
||||
*/
|
||||
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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ module std.zip;
|
|||
|
||||
import std.zlib;
|
||||
import std.datetime;
|
||||
import std.intrinsic;
|
||||
import core.bitop;
|
||||
import std.conv;
|
||||
|
||||
//debug=print;
|
||||
|
|
|
@ -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;
|
||||
|
|
12
win32.mak
12
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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue