-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement a SIMD version of drawFillOver
- Loading branch information
Showing
6 changed files
with
336 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package nucular | ||
|
||
import "image" | ||
|
||
func drawFillOver_SIMD_internal(base *uint8, i0, i1 int, stride, n int, adivm, sr, sg, sb, sa uint32) | ||
|
||
func drawFillOver(dst *image.RGBA, r image.Rectangle, sr, sg, sb, sa uint32) { | ||
const m = 1<<16 - 1 | ||
a := (m - sa) * 0x101 | ||
adivm := a / m | ||
i0 := dst.PixOffset(r.Min.X, r.Min.Y) | ||
i1 := i0 + r.Dx()*4 | ||
drawFillOver_SIMD_internal(&dst.Pix[0], i0, i1, dst.Stride, r.Max.Y-r.Min.Y, adivm, sr, sg, sb, sa) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "textflag.h" | ||
|
||
GLOBL drawFillOver_SIMD_shufflemap<>(SB), (NOPTR+RODATA), $4 | ||
DATA drawFillOver_SIMD_shufflemap<>+0x00(SB)/4, $0x0d090501 | ||
|
||
TEXT ·drawFillOver_SIMD_internal(SB),0,$0-60 | ||
// base+0(FP) | ||
// i0+8(FP) | ||
// i1+16(FP) | ||
// stride+24(FP) | ||
// n+32(FP) | ||
// adivm+40(FP) | ||
// sr+44(FP) | ||
// sg+48(FP) | ||
// sb+52(FP) | ||
// sa+56(FP) | ||
|
||
// DX row index | ||
// CX column index | ||
// AX pointer to current pixel | ||
// R14 i0 | ||
// R15 i1 | ||
|
||
// X0 zeroed register | ||
// X1 current pixel | ||
// X3 source pixel | ||
// X4 is the shuffle map to do the >> 8 and pack everything back into a single 32bit value | ||
|
||
MOVSS drawFillOver_SIMD_shufflemap<>(SB), X4 | ||
|
||
PXOR X0, X0 | ||
MOVQ i0+8(FP), R14 | ||
MOVQ i1+16(FP), R15 | ||
|
||
// load adivm to X2, fill all uint32s with it | ||
MOVSS advim+40(FP), X2 | ||
VBROADCASTSS X2, X2 | ||
|
||
// load source pixel to X3 | ||
VMOVDQU sr+44(FP), X3 | ||
|
||
MOVQ $0, DX | ||
row_loop: | ||
CMPQ DX, n+32(FP) | ||
JGE row_loop_end | ||
|
||
MOVQ R14, CX | ||
MOVQ base+0(FP), AX | ||
LEAQ (AX)(CX*1), AX | ||
column_loop: | ||
CMPQ CX, R15 | ||
JGE column_loop_end | ||
|
||
// load current pixel to X1, unpack twice to get uint32s | ||
MOVSS (AX), X1 | ||
PUNPCKLBW X0, X1 | ||
VPUNPCKLWD X0, X1, X1 | ||
|
||
VPMULLD X2, X1, X1 // component * a/m | ||
VPADDD X3, X1, X1 // (component * a/m) + source_component | ||
|
||
VPSHUFB X4, X1, X1 // get the second byte of every 32bit word and pack it into the lowest word of X1 | ||
MOVSS X1, (AX) // write back to memory | ||
|
||
ADDQ $4, CX | ||
ADDQ $4, AX | ||
JMP column_loop | ||
|
||
column_loop_end: | ||
ADDQ stride+24(FP), R14 | ||
ADDQ stride+24(FP), R15 | ||
INCQ DX | ||
JMP row_loop | ||
|
||
row_loop_end: | ||
|
||
RET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// +build !amd64 | ||
|
||
package nucular | ||
|
||
import ( | ||
"image" | ||
) | ||
|
||
func drawFillOver(dst *image.RGBA, r image.Rectangle, sr, sg, sb, sa uint32) { | ||
fmt.Printf("fucked up!\n") | ||
const m = 1<<16 - 1 | ||
// The 0x101 is here for the same reason as in drawRGBA. | ||
a := (m - sa) * 0x101 | ||
i0 := dst.PixOffset(r.Min.X, r.Min.Y) | ||
i1 := i0 + r.Dx()*4 | ||
for y := r.Min.Y; y != r.Max.Y; y++ { | ||
for i := i0; i < i1; i += 4 { | ||
dr := &dst.Pix[i+0] | ||
dg := &dst.Pix[i+1] | ||
db := &dst.Pix[i+2] | ||
da := &dst.Pix[i+3] | ||
|
||
*dr = uint8((uint32(*dr)*a/m + sr) >> 8) | ||
*dg = uint8((uint32(*dg)*a/m + sg) >> 8) | ||
*db = uint8((uint32(*db)*a/m + sb) >> 8) | ||
*da = uint8((uint32(*da)*a/m + sa) >> 8) | ||
} | ||
i0 += dst.Stride | ||
i1 += dst.Stride | ||
} | ||
} |
Oops, something went wrong.