| | |
| |
|
| | |
| | |
| | |
| |
|
| | package codegen |
| |
|
| | func cmovint(c int) int { |
| | x := c + 4 |
| | if x < 0 { |
| | x = 182 |
| | } |
| | |
| | |
| | |
| | |
| | return x |
| | } |
| |
|
| | func cmovchan(x, y chan int) chan int { |
| | if x != y { |
| | x = y |
| | } |
| | |
| | |
| | |
| | |
| | return x |
| | } |
| |
|
| | func cmovuintptr(x, y uintptr) uintptr { |
| | if x < y { |
| | x = -y |
| | } |
| | |
| | |
| | |
| | |
| | return x |
| | } |
| |
|
| | func cmov32bit(x, y uint32) uint32 { |
| | if x < y { |
| | x = -y |
| | } |
| | |
| | |
| | |
| | |
| | return x |
| | } |
| |
|
| | func cmov16bit(x, y uint16) uint16 { |
| | if x < y { |
| | x = -y |
| | } |
| | |
| | |
| | |
| | |
| | return x |
| | } |
| |
|
| | |
| | |
| | func cmovfloateq(x, y float64) int { |
| | a := 128 |
| | if x == y { |
| | a = 256 |
| | } |
| | |
| | |
| | |
| | |
| | return a |
| | } |
| |
|
| | func cmovfloatne(x, y float64) int { |
| | a := 128 |
| | if x != y { |
| | a = 256 |
| | } |
| | |
| | |
| | |
| | |
| | return a |
| | } |
| |
|
| | |
| | func frexp(f float64) (frac float64, exp int) { |
| | return 1.0, 4 |
| | } |
| |
|
| | |
| | func ldexp(frac float64, exp int) float64 { |
| | return 1.0 |
| | } |
| |
|
| | |
| | func cmovfloatint2(x, y float64) float64 { |
| | yfr, yexp := 4.0, 5 |
| |
|
| | r := x |
| | for r >= y { |
| | rfr, rexp := frexp(r) |
| | if rfr < yfr { |
| | rexp = rexp - 42 |
| | } |
| | |
| | |
| | |
| | |
| | r = r - ldexp(y, rexp-yexp) |
| | } |
| | return r |
| | } |
| |
|
| | func cmovloaded(x [4]int, y int) int { |
| | if x[2] != 0 { |
| | y = x[2] |
| | } else { |
| | y = y >> 2 |
| | } |
| | |
| | |
| | |
| | |
| | return y |
| | } |
| |
|
| | func cmovuintptr2(x, y uintptr) uintptr { |
| | a := x * 2 |
| | if a == 0 { |
| | a = 256 |
| | } |
| | |
| | |
| | |
| | |
| | return a |
| | } |
| |
|
| | |
| | func cmovfloatmove(x, y int) float64 { |
| | a := 1.0 |
| | if x <= y { |
| | a = 2.0 |
| | } |
| | |
| | |
| | |
| | |
| | return a |
| | } |
| |
|
| | |
| | |
| | var gsink int64 |
| | var gusink uint64 |
| |
|
| | func cmovinvert1(x, y int64) int64 { |
| | if x < gsink { |
| | y = -y |
| | } |
| | |
| | return y |
| | } |
| | func cmovinvert2(x, y int64) int64 { |
| | if x <= gsink { |
| | y = -y |
| | } |
| | |
| | return y |
| | } |
| | func cmovinvert3(x, y int64) int64 { |
| | if x == gsink { |
| | y = -y |
| | } |
| | |
| | return y |
| | } |
| | func cmovinvert4(x, y int64) int64 { |
| | if x != gsink { |
| | y = -y |
| | } |
| | |
| | return y |
| | } |
| | func cmovinvert5(x, y uint64) uint64 { |
| | if x > gusink { |
| | y = -y |
| | } |
| | |
| | return y |
| | } |
| | func cmovinvert6(x, y uint64) uint64 { |
| | if x >= gusink { |
| | y = -y |
| | } |
| | |
| | return y |
| | } |
| |
|
| | func cmovload(a []int, i int, b bool) int { |
| | if b { |
| | i += 42 |
| | } |
| | |
| | |
| | return a[i] |
| | } |
| |
|
| | func cmovstore(a []int, i int, b bool) { |
| | if b { |
| | i += 42 |
| | } |
| | |
| | a[i] = 7 |
| | } |
| |
|
| | var r0, r1, r2, r3, r4, r5 int |
| |
|
| | func cmovinc(cond bool, a, b, c int) { |
| | var x0, x1 int |
| |
|
| | if cond { |
| | x0 = a |
| | } else { |
| | x0 = b + 1 |
| | } |
| | |
| | r0 = x0 |
| |
|
| | if cond { |
| | x1 = b + 1 |
| | } else { |
| | x1 = a |
| | } |
| | |
| | r1 = x1 |
| |
|
| | if cond { |
| | c++ |
| | } |
| | |
| | r2 = c |
| | } |
| |
|
| | func cmovinv(cond bool, a, b int) { |
| | var x0, x1 int |
| |
|
| | if cond { |
| | x0 = a |
| | } else { |
| | x0 = ^b |
| | } |
| | |
| | r0 = x0 |
| |
|
| | if cond { |
| | x1 = ^b |
| | } else { |
| | x1 = a |
| | } |
| | |
| | r1 = x1 |
| | } |
| |
|
| | func cmovneg(cond bool, a, b, c int) { |
| | var x0, x1 int |
| |
|
| | if cond { |
| | x0 = a |
| | } else { |
| | x0 = -b |
| | } |
| | |
| | r0 = x0 |
| |
|
| | if cond { |
| | x1 = -b |
| | } else { |
| | x1 = a |
| | } |
| | |
| | r1 = x1 |
| | } |
| |
|
| | func cmovsetm(cond bool, x int) { |
| | var x0, x1 int |
| |
|
| | if cond { |
| | x0 = -1 |
| | } else { |
| | x0 = 0 |
| | } |
| | |
| | r0 = x0 |
| |
|
| | if cond { |
| | x1 = 0 |
| | } else { |
| | x1 = -1 |
| | } |
| | |
| | r1 = x1 |
| | } |
| |
|
| | func cmovFcmp0(s, t float64, a, b int) { |
| | var x0, x1, x2, x3, x4, x5 int |
| |
|
| | if s < t { |
| | x0 = a |
| | } else { |
| | x0 = b + 1 |
| | } |
| | |
| | r0 = x0 |
| |
|
| | if s <= t { |
| | x1 = a |
| | } else { |
| | x1 = ^b |
| | } |
| | |
| | r1 = x1 |
| |
|
| | if s > t { |
| | x2 = a |
| | } else { |
| | x2 = -b |
| | } |
| | |
| | r2 = x2 |
| |
|
| | if s >= t { |
| | x3 = -1 |
| | } else { |
| | x3 = 0 |
| | } |
| | |
| | r3 = x3 |
| |
|
| | if s == t { |
| | x4 = a |
| | } else { |
| | x4 = b + 1 |
| | } |
| | |
| | r4 = x4 |
| |
|
| | if s != t { |
| | x5 = a |
| | } else { |
| | x5 = b + 1 |
| | } |
| | |
| | r5 = x5 |
| | } |
| |
|
| | func cmovFcmp1(s, t float64, a, b int) { |
| | var x0, x1, x2, x3, x4, x5 int |
| |
|
| | if s < t { |
| | x0 = b + 1 |
| | } else { |
| | x0 = a |
| | } |
| | |
| | r0 = x0 |
| |
|
| | if s <= t { |
| | x1 = ^b |
| | } else { |
| | x1 = a |
| | } |
| | |
| | r1 = x1 |
| |
|
| | if s > t { |
| | x2 = -b |
| | } else { |
| | x2 = a |
| | } |
| | |
| | r2 = x2 |
| |
|
| | if s >= t { |
| | x3 = 0 |
| | } else { |
| | x3 = -1 |
| | } |
| | |
| | r3 = x3 |
| |
|
| | if s == t { |
| | x4 = b + 1 |
| | } else { |
| | x4 = a |
| | } |
| | |
| | r4 = x4 |
| |
|
| | if s != t { |
| | x5 = b + 1 |
| | } else { |
| | x5 = a |
| | } |
| | |
| | r5 = x5 |
| | } |
| |
|
| | func cmovzero1(c bool) int { |
| | var x int |
| | if c { |
| | x = 182 |
| | } |
| | |
| | return x |
| | } |
| |
|
| | func cmovzero2(c bool) int { |
| | var x int |
| | if !c { |
| | x = 182 |
| | } |
| | |
| | return x |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | func cmovzeroreg0(a, b int) int { |
| | x := 0 |
| | if a == b { |
| | x = a |
| | } |
| | |
| | return x |
| | } |
| |
|
| | func cmovzeroreg1(a, b int) int { |
| | x := a |
| | if a == b { |
| | x = 0 |
| | } |
| | |
| | return x |
| | } |
| |
|
| | func cmovmathadd(a uint, b bool) uint { |
| | if b { |
| | a++ |
| | } |
| | |
| | |
| | |
| | |
| | return a |
| | } |
| |
|
| | func cmovmathsub(a uint, b bool) uint { |
| | if b { |
| | a-- |
| | } |
| | |
| | |
| | |
| | |
| | return a |
| | } |
| |
|
| | func cmovmathdouble(a uint, b bool) uint { |
| | if b { |
| | a *= 2 |
| | } |
| | |
| | |
| | |
| | |
| | return a |
| | } |
| |
|
| | func cmovmathhalvei(a int, b bool) int { |
| | if b { |
| | |
| | |
| | |
| | a /= 2 |
| | } |
| | |
| | |
| | return a |
| | } |
| |
|
| | func cmovmathhalveu(a uint, b bool) uint { |
| | if b { |
| | a /= 2 |
| | } |
| | |
| | |
| | |
| | |
| | return a |
| | } |
| |
|
| | func branchlessBoolToUint8(b bool) (r uint8) { |
| | if b { |
| | r = 1 |
| | } |
| | return |
| | } |
| |
|
| | func cmovFromMulFromFlags64(x uint64, b bool) uint64 { |
| | |
| | r := uint64(branchlessBoolToUint8(b)) |
| | |
| | return x * r |
| | } |
| | func cmovFromMulFromFlags64sext(x int64, b bool) int64 { |
| | |
| | r := int64(int8(branchlessBoolToUint8(b))) |
| | |
| | return x * r |
| | } |
| |
|