| 1 |
// compile |
| 2 |
|
| 3 |
//go:build amd64 && goexperiment.simd |
| 4 |
|
| 5 |
// Copyright 2025 The Go Authors. All rights reserved. |
| 6 |
// Use of this source code is governed by a BSD-style |
| 7 |
// license that can be found in the LICENSE file. |
| 8 |
|
| 9 |
// Test case for rematerialization ignoring the register constraint |
| 10 |
// during regalloc's shuffle phase. |
| 11 |
|
| 12 |
package p |
| 13 |
|
| 14 |
import ( |
| 15 |
"simd/archsimd" |
| 16 |
) |
| 17 |
|
| 18 |
func PackComplex(b bool) { |
| 19 |
for { |
| 20 |
if b { |
| 21 |
var indices [4]uint32 |
| 22 |
archsimd.Uint32x4{}.ShiftAllRight(20).Store(&indices) |
| 23 |
_ = indices[indices[0]] |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
func PackComplex2(x0 uint16, src [][4]float32, b, b2 bool) { |
| 29 |
var out [][4]byte |
| 30 |
if b2 { |
| 31 |
for y := range x0 { |
| 32 |
row := out[:x0] |
| 33 |
for x := range row { |
| 34 |
px := &src[y] |
| 35 |
if b { |
| 36 |
var indices [4]uint32 |
| 37 |
fu := archsimd.LoadFloat32x4(px).AsUint32x4() |
| 38 |
fu.ShiftAllRight(0).Store(nil) |
| 39 |
entry := archsimd.LoadUint32x4(&[4]uint32{ |
| 40 |
toSrgbTable[indices[0]], |
| 41 |
}) |
| 42 |
var res [4]uint32 |
| 43 |
entry.ShiftAllRight(19).Store(nil) |
| 44 |
row[x] = [4]uint8{ |
| 45 |
uint8(res[0]), |
| 46 |
uint8(res[1]), |
| 47 |
uint8(res[2]), |
| 48 |
} |
| 49 |
} else { |
| 50 |
row[x] = [4]uint8{ |
| 51 |
float32ToSrgb8(0), |
| 52 |
float32ToSrgb8(1), |
| 53 |
float32ToSrgb8(2), |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
out = out[len(out):] |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
var toSrgbTable = [4]uint32{} |
| 63 |
|
| 64 |
func float32ToSrgb8(f float32) uint8 { |
| 65 |
f = min(0, f) |
| 66 |
fu := uint32(f) |
| 67 |
entry := toSrgbTable[fu] |
| 68 |
return uint8(entry * fu) |
| 69 |
} |