aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/image/geom.go
diff options
context:
space:
mode:
authorGiuliano Belinassi <giuliano.belinassi@usp.br>2020-08-22 17:43:43 -0300
committerGiuliano Belinassi <giuliano.belinassi@usp.br>2020-08-22 17:43:43 -0300
commita926878ddbd5a98b272c22171ce58663fc04c3e0 (patch)
tree86af256e5d9a9c06263c00adc90e5fe348008c43 /libgo/go/image/geom.go
parent542730f087133690b47e036dfd43eb0db8a650ce (diff)
parent07cbaed8ba7d1b6e4ab3a9f44175502a4e1ecdb1 (diff)
downloadgcc-devel/autopar_devel.zip
gcc-devel/autopar_devel.tar.gz
gcc-devel/autopar_devel.tar.bz2
Merge branch 'autopar_rebase2' into autopar_develdevel/autopar_devel
Quickly commit changes in the rebase branch.
Diffstat (limited to 'libgo/go/image/geom.go')
-rw-r--r--libgo/go/image/geom.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/libgo/go/image/geom.go b/libgo/go/image/geom.go
index 8bb249c..78e9e49 100644
--- a/libgo/go/image/geom.go
+++ b/libgo/go/image/geom.go
@@ -6,6 +6,7 @@ package image
import (
"image/color"
+ "math/bits"
"strconv"
)
@@ -272,3 +273,37 @@ func Rect(x0, y0, x1, y1 int) Rectangle {
}
return Rectangle{Point{x0, y0}, Point{x1, y1}}
}
+
+// mul3NonNeg returns (x * y * z), unless at least one argument is negative or
+// if the computation overflows the int type, in which case it returns -1.
+func mul3NonNeg(x int, y int, z int) int {
+ if (x < 0) || (y < 0) || (z < 0) {
+ return -1
+ }
+ hi, lo := bits.Mul64(uint64(x), uint64(y))
+ if hi != 0 {
+ return -1
+ }
+ hi, lo = bits.Mul64(lo, uint64(z))
+ if hi != 0 {
+ return -1
+ }
+ a := int(lo)
+ if (a < 0) || (uint64(a) != lo) {
+ return -1
+ }
+ return a
+}
+
+// add2NonNeg returns (x + y), unless at least one argument is negative or if
+// the computation overflows the int type, in which case it returns -1.
+func add2NonNeg(x int, y int) int {
+ if (x < 0) || (y < 0) {
+ return -1
+ }
+ a := x + y
+ if a < 0 {
+ return -1
+ }
+ return a
+}