Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
add core.simd
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Jan 11, 2012
1 parent 0ec3aa8 commit 9eff7cd
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
4 changes: 4 additions & 0 deletions posix.mak
Expand Up @@ -58,6 +58,7 @@ MANIFEST= \
src/core/math.d \
src/core/memory.d \
src/core/runtime.d \
src/core/simd.d \
src/core/thread.d \
src/core/threadasm.S \
src/core/time.d \
Expand Down Expand Up @@ -252,6 +253,7 @@ SRC_D_MODULES = \
core/math \
core/memory \
core/runtime \
core/simd \
core/thread \
core/time \
core/vararg \
Expand Down Expand Up @@ -379,6 +381,7 @@ DOCS=\
$(DOCDIR)/core_math.html \
$(DOCDIR)/core_memory.html \
$(DOCDIR)/core_runtime.html \
$(DOCDIR)/core_simd.html \
$(DOCDIR)/core_thread.html \
$(DOCDIR)/core_time.html \
$(DOCDIR)/core_vararg.html \
Expand All @@ -400,6 +403,7 @@ IMPORTS=\
$(IMPDIR)/core/math.di \
$(IMPDIR)/core/memory.di \
$(IMPDIR)/core/runtime.di \
$(IMPDIR)/core/simd.di \
$(IMPDIR)/core/thread.di \
$(IMPDIR)/core/time.di \
$(IMPDIR)/core/vararg.di \
Expand Down
80 changes: 80 additions & 0 deletions src/core/simd.d
@@ -0,0 +1,80 @@
// Written in the D programming language.

/**
* Builtin SIMD intrinsics
*
* Source: $(DRUNTIMESRC core/_simd.d)
*
* Copyright: Copyright Digital Mars 2012.
* License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
* Authors: $(WEB digitalmars.com, Walter Bright),
*/

module core.simd;

pure:
nothrow:
@safe:

/*******************************
* Create a vector type.
*
* Parameters:
* T = one of double[2], float[4], void[16], byte[16], ubyte[16],
* short[8], ushort[8], int[4], uint[4], long[2], ulong[2]
*/

template Vector(T)
{
/* __vector is compiler magic, hide it behind a template.
* The compiler will reject T's that don't work.
*/
alias __vector(T) Vector;
}

/** Handy aliases
*/
alias Vector!(void[16]) void16; ///
alias Vector!(double[2]) double2; ///
alias Vector!(float[4]) float4; ///
alias Vector!(byte[16]) byte16; ///
alias Vector!(ubyte[16]) ubyte16; ///
alias Vector!(short[8]) short8; ///
alias Vector!(ushort[8]) ushort8; ///
alias Vector!(int[4]) int4; ///
alias Vector!(uint[4]) uint4; ///
alias Vector!(long[2]) long2; ///

enum XMM
{
// Need to add in all the rest
PCMPEQW = 0x660F75,
}

/**
* Generate two operand instruction with XMM 128 bit operands.
* Parameters:
* opcode any of the XMM opcodes
* op1 first operand
* op2 second operand
* Returns:
* result of opcode
*/
void16 simd(XMM opcode, void16 op1, void16 op2);

/* The following use overloading to ensure correct typing.
* Compile with inlining on for best performance.
*/

short8 pcmpeq()(short8 v1, short8 v2)
{
return simd(XMM.PCMPEQW, v1, v2);
}

ushort8 pcmpeq()(ushort8 v1, ushort8 v2)
{
return simd(XMM.PCMPEQW, v1, v2);
}



10 changes: 10 additions & 0 deletions win32.mak
Expand Up @@ -37,6 +37,7 @@ MANIFEST= \
src\core\math.d \
src\core\memory.d \
src\core\runtime.d \
src\core\simd.d \
src\core\thread.d \
src\core\threadasm.S \
src\core\time.d \
Expand Down Expand Up @@ -232,6 +233,7 @@ SRCS= \
src\core\math.d \
src\core\memory.d \
src\core\runtime.d \
src\core\simd.d \
src\core\thread.d \
src\core\time.d \
src\core\vararg.d \
Expand Down Expand Up @@ -358,6 +360,7 @@ DOCS=\
$(DOCDIR)\core_math.html \
$(DOCDIR)\core_memory.html \
$(DOCDIR)\core_runtime.html \
$(DOCDIR)\core_simd.html \
$(DOCDIR)\core_thread.html \
$(DOCDIR)\core_time.html \
$(DOCDIR)\core_vararg.html \
Expand All @@ -379,6 +382,7 @@ IMPORTS=\
$(IMPDIR)\core\math.di \
$(IMPDIR)\core\memory.di \
$(IMPDIR)\core\runtime.di \
$(IMPDIR)\core\simd.di \
$(IMPDIR)\core\thread.di \
$(IMPDIR)\core\time.di \
$(IMPDIR)\core\vararg.di \
Expand Down Expand Up @@ -494,6 +498,9 @@ $(DOCDIR)\core_memory.html : src\core\memory.d
$(DOCDIR)\core_runtime.html : src\core\runtime.d
$(DMD) -c -d -o- -Isrc -Iimport -Df$@ $(DOCFMT) $**

$(DOCDIR)\core_simd.html : src\core\simd.d
$(DMD) -c -d -o- -Isrc -Iimport -Df$@ $(DOCFMT) $**

$(DOCDIR)\core_thread.html : src\core\thread.d
$(DMD) -c -d -o- -Isrc -Iimport -Df$@ $(DOCFMT) $**

Expand Down Expand Up @@ -552,6 +559,9 @@ $(IMPDIR)\core\memory.di : src\core\memory.d
$(IMPDIR)\core\runtime.di : src\core\runtime.d
$(DMD) -c -d -o- -Isrc -Iimport -Hf$@ $**

$(IMPDIR)\core\simd.di : src\core\simd.d
$(DMD) -c -d -o- -Isrc -Iimport -Hf$@ $**

$(IMPDIR)\core\thread.di : src\core\thread.d
$(DMD) -c -d -o- -Isrc -Iimport -Hf$@ $**

Expand Down

0 comments on commit 9eff7cd

Please sign in to comment.