File: swizzle_amd64.s

package info (click to toggle)
golang-golang-x-exp 0.0~git20230522.2e198f4-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 6,404 kB
  • sloc: ansic: 1,900; objc: 276; sh: 272; asm: 48; makefile: 26
file content (76 lines) | stat: -rw-r--r-- 1,310 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include "textflag.h"

// func haveSSSE3() bool
TEXT ·haveSSSE3(SB),NOSPLIT,$0
	MOVQ	$1, AX
	CPUID
	SHRQ	$9, CX
	ANDQ	$1, CX
	MOVB	CX, ret+0(FP)
	RET

// func bgra16(p []byte)
TEXT ·bgra16(SB),NOSPLIT,$0-24
	MOVQ	p+0(FP), SI
	MOVQ	len+8(FP), DI

	// Sanity check that len is a multiple of 16.
	MOVQ	DI, AX
	ANDQ	$15, AX
	JNZ	done

	// Make the shuffle control mask (16-byte register X0) look like this,
	// where the low order byte comes first:
	//
	// 02 01 00 03  06 05 04 07  0a 09 08 0b  0e 0d 0c 0f
	//
	// Load the bottom 8 bytes into X0, the top into X1, then interleave them
	// into X0.
	MOVQ	$0x0704050603000102, AX
	MOVQ	AX, X0
	MOVQ	$0x0f0c0d0e0b08090a, AX
	MOVQ	AX, X1
	PUNPCKLQDQ	X1, X0

	ADDQ	SI, DI
loop:
	CMPQ	SI, DI
	JEQ	done

	MOVOU	(SI), X1
	PSHUFB	X0, X1
	MOVOU	X1, (SI)

	ADDQ	$16, SI
	JMP	loop
done:
	RET

// func bgra4(p []byte)
TEXT ·bgra4(SB),NOSPLIT,$0-24
	MOVQ	p+0(FP), SI
	MOVQ	len+8(FP), DI

	// Sanity check that len is a multiple of 4.
	MOVQ	DI, AX
	ANDQ	$3, AX
	JNZ	done

	ADDQ	SI, DI
loop:
	CMPQ	SI, DI
	JEQ	done

	MOVB	0(SI), AX
	MOVB	2(SI), BX
	MOVB	BX, 0(SI)
	MOVB	AX, 2(SI)

	ADDQ	$4, SI
	JMP	loop
done:
	RET