1// run
2
3// Copyright 2021 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7package main
8
9import (
10	"fmt"
11	"math"
12)
13
14//go:noinline
15func fcmplt(a, b float64, x uint64) uint64 {
16	if a < b {
17		x = 0
18	}
19	return x
20}
21
22//go:noinline
23func fcmple(a, b float64, x uint64) uint64 {
24	if a <= b {
25		x = 0
26	}
27	return x
28}
29
30//go:noinline
31func fcmpgt(a, b float64, x uint64) uint64 {
32	if a > b {
33		x = 0
34	}
35	return x
36}
37
38//go:noinline
39func fcmpge(a, b float64, x uint64) uint64 {
40	if a >= b {
41		x = 0
42	}
43	return x
44}
45
46//go:noinline
47func fcmpeq(a, b float64, x uint64) uint64 {
48	if a == b {
49		x = 0
50	}
51	return x
52}
53
54//go:noinline
55func fcmpne(a, b float64, x uint64) uint64 {
56	if a != b {
57		x = 0
58	}
59	return x
60}
61
62func main() {
63	type fn func(a, b float64, x uint64) uint64
64
65	type testCase struct {
66		f       fn
67		a, b    float64
68		x, want uint64
69	}
70	NaN := math.NaN()
71	for _, t := range []testCase{
72		{fcmplt, 1.0, 1.0, 123, 123},
73		{fcmple, 1.0, 1.0, 123, 0},
74		{fcmpgt, 1.0, 1.0, 123, 123},
75		{fcmpge, 1.0, 1.0, 123, 0},
76		{fcmpeq, 1.0, 1.0, 123, 0},
77		{fcmpne, 1.0, 1.0, 123, 123},
78
79		{fcmplt, 1.0, 2.0, 123, 0},
80		{fcmple, 1.0, 2.0, 123, 0},
81		{fcmpgt, 1.0, 2.0, 123, 123},
82		{fcmpge, 1.0, 2.0, 123, 123},
83		{fcmpeq, 1.0, 2.0, 123, 123},
84		{fcmpne, 1.0, 2.0, 123, 0},
85
86		{fcmplt, 2.0, 1.0, 123, 123},
87		{fcmple, 2.0, 1.0, 123, 123},
88		{fcmpgt, 2.0, 1.0, 123, 0},
89		{fcmpge, 2.0, 1.0, 123, 0},
90		{fcmpeq, 2.0, 1.0, 123, 123},
91		{fcmpne, 2.0, 1.0, 123, 0},
92
93		{fcmplt, 1.0, NaN, 123, 123},
94		{fcmple, 1.0, NaN, 123, 123},
95		{fcmpgt, 1.0, NaN, 123, 123},
96		{fcmpge, 1.0, NaN, 123, 123},
97		{fcmpeq, 1.0, NaN, 123, 123},
98		{fcmpne, 1.0, NaN, 123, 0},
99
100		{fcmplt, NaN, 1.0, 123, 123},
101		{fcmple, NaN, 1.0, 123, 123},
102		{fcmpgt, NaN, 1.0, 123, 123},
103		{fcmpge, NaN, 1.0, 123, 123},
104		{fcmpeq, NaN, 1.0, 123, 123},
105		{fcmpne, NaN, 1.0, 123, 0},
106
107		{fcmplt, NaN, NaN, 123, 123},
108		{fcmple, NaN, NaN, 123, 123},
109		{fcmpgt, NaN, NaN, 123, 123},
110		{fcmpge, NaN, NaN, 123, 123},
111		{fcmpeq, NaN, NaN, 123, 123},
112		{fcmpne, NaN, NaN, 123, 0},
113	} {
114		got := t.f(t.a, t.b, t.x)
115		if got != t.want {
116			panic(fmt.Sprintf("want %v, got %v", t.want, got))
117		}
118	}
119}
120