1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have
  23  * questions.
  24  */
  25 package jdk.incubator.vector;
  26 
  27 /**
  28  * Operations on vectors that are not intrinsic candidates
  29  */
  30 @SuppressWarnings("cast")
  31 public final class $abstractvectortype$Helper {
  32 
  33     private $abstractvectortype$Helper() {}
  34 
  35     public interface BinaryOp {
  36         $type$ apply(int i, $type$ a, $type$ b);
  37     }
  38 
  39     public interface UnaryOp {
  40         $type$ apply(int i, $type$ a);
  41     }
  42 
  43     public static 
  44     $abstractvectortype$ map($abstractvectortype$ va, $abstractvectortype$ vb, BinaryOp op) {
  45         return va.bOp(vb, (i, a, b) -> op.apply(i, a, b));
  46     }
  47 
  48     public static 
  49     $abstractvectortype$ map($abstractvectortype$ va, $abstractvectortype$ vb, Vector.Mask<$Boxtype$> m, BinaryOp op) {
  50         return va.bOp(vb, m, (i, a, b) -> op.apply(i, a, b));
  51     }
  52 
  53     public static 
  54     $abstractvectortype$ map($abstractvectortype$ va, UnaryOp op) {
  55         return va.uOp((i, a) -> op.apply(i, a));
  56     }
  57 
  58     public static 
  59     $abstractvectortype$ map($abstractvectortype$ va, Vector.Mask<$Boxtype$> m, UnaryOp op) {
  60         return va.uOp(m, (i, a) -> op.apply(i, a));
  61     }
  62 
  63 #if[BITWISE]
  64     public static 
  65     $abstractvectortype$ div($abstractvectortype$ va, $abstractvectortype$ vb) {
  66         return va.bOp(vb, (i, a, b) -> ($type$) (a / b));
  67     }
  68 
  69     public static 
  70     $abstractvectortype$ div($abstractvectortype$ va, $abstractvectortype$ vb, Vector.Mask<$Boxtype$> m) {
  71         return va.bOp(vb, m, (i, a, b) -> ($type$) (a / b));
  72     }
  73 
  74     public static 
  75     $abstractvectortype$ mod($abstractvectortype$ va, $abstractvectortype$ vb) {
  76         return va.bOp(vb, (i, a, b) -> ($type$) (a % b));
  77     }
  78 
  79     public static 
  80     $abstractvectortype$ mod($abstractvectortype$ va, $abstractvectortype$ vb, Vector.Mask<$Boxtype$> m) {
  81         return va.bOp(vb, m, (i, a, b) -> ($type$) (a % b));
  82     }
  83 #end[BITWISE]
  84 
  85 #if[intOrLong]
  86     public static 
  87     $abstractvectortype$ addExact($abstractvectortype$ va, $abstractvectortype$ vb) {
  88         return va.bOp(vb, (i, a, b) -> Math.addExact(a, b));
  89     }
  90 
  91     public static 
  92     $abstractvectortype$ addExact($abstractvectortype$ va, $abstractvectortype$ vb, Vector.Mask<$Boxtype$> m) {
  93         return va.bOp(vb, m, (i, a, b) -> Math.addExact(a, b));
  94     }
  95 
  96     public static 
  97     $abstractvectortype$ decrementExact($abstractvectortype$ va) {
  98         return va.uOp((i, a) -> Math.decrementExact(a));
  99     }
 100 
 101     public static 
 102     $abstractvectortype$ decrementExact($abstractvectortype$ va, Vector.Mask<$Boxtype$> m) {
 103         return va.uOp(m, (i, a) -> Math.decrementExact(a));
 104     }
 105 
 106     public static 
 107     $abstractvectortype$ incrementExact($abstractvectortype$ va) {
 108         return va.uOp((i, a) -> Math.incrementExact(a));
 109     }
 110 
 111     public static 
 112     $abstractvectortype$ incrementExact($abstractvectortype$ va, Vector.Mask<$Boxtype$> m) {
 113         return va.uOp(m, (i, a) -> Math.incrementExact(a));
 114     }
 115 
 116     public static 
 117     $abstractvectortype$ multiplyExact($abstractvectortype$ va, $abstractvectortype$ vb) {
 118         return va.bOp(vb, (i, a, b) -> Math.multiplyExact(a, b));
 119     }
 120 
 121     public static 
 122     $abstractvectortype$ multiplyExact($abstractvectortype$ va, $abstractvectortype$ vb, Vector.Mask<$Boxtype$> m) {
 123         return va.bOp(vb, m, (i, a, b) -> Math.multiplyExact(a, b));
 124     }
 125 
 126     public static 
 127     $abstractvectortype$ negateExact($abstractvectortype$ va) {
 128         return va.uOp((i, a) -> Math.negateExact(a));
 129     }
 130 
 131     public static 
 132     $abstractvectortype$ negateExact($abstractvectortype$ va, Vector.Mask<$Boxtype$> m) {
 133         return va.uOp(m, (i, a) -> Math.negateExact(a));
 134     }
 135 
 136     public static 
 137     $abstractvectortype$ subtractExtract($abstractvectortype$ va, $abstractvectortype$ vb) {
 138         return va.bOp(vb, (i, a, b) -> Math.subtractExact(a, b));
 139     }
 140 
 141     public static 
 142     $abstractvectortype$ subtractExtract($abstractvectortype$ va, $abstractvectortype$ vb, Vector.Mask<$Boxtype$> m) {
 143         return va.bOp(vb, m, (i, a, b) -> Math.subtractExact(a, b));
 144     }
 145 #end[intOrLong]
 146 
 147 #if[FP]
 148     public static 
 149     $abstractvectortype$ ceil($abstractvectortype$ va) {
 150         return va.uOp((i, a) -> ($type$) Math.ceil((double) a));
 151     }
 152 
 153     public static 
 154     $abstractvectortype$ ceil($abstractvectortype$ va, Vector.Mask<$Boxtype$> m) {
 155         return va.uOp(m, (i, a) -> ($type$) Math.ceil((double) a));
 156     }
 157 
 158     public static 
 159     $abstractvectortype$ copySign($abstractvectortype$ va, $abstractvectortype$ vb) {
 160         return va.bOp(vb, (i, a, b) -> ($type$) Math.copySign((double) a, (double) b));
 161     }
 162 
 163     public static 
 164     $abstractvectortype$ copySign($abstractvectortype$ va, $abstractvectortype$ vb, Vector.Mask<$Boxtype$> m) {
 165         return va.bOp(vb, m, (i, a, b) -> ($type$) Math.copySign((double) a, (double) b));
 166     }
 167 
 168     public static 
 169     $abstractvectortype$ floor($abstractvectortype$ va) {
 170         return va.uOp((i, a) -> ($type$) Math.floor((double) a));
 171     }
 172 
 173     public static 
 174     $abstractvectortype$ floor($abstractvectortype$ va, Vector.Mask<$Boxtype$> m) {
 175         return va.uOp(m, (i, a) -> ($type$) Math.floor((double) a));
 176     }
 177 
 178     public static 
 179     $abstractvectortype$ getExponent($abstractvectortype$ va) {
 180         return va.uOp((i, a) -> ($type$) Math.getExponent((double) a));
 181     }
 182 
 183     public static 
 184     $abstractvectortype$ getExponent($abstractvectortype$ va, Vector.Mask<$Boxtype$> m) {
 185         return va.uOp(m, (i, a) -> ($type$) Math.getExponent((double) a));
 186     }
 187 
 188     public static 
 189     $abstractvectortype$ IEEEremainder($abstractvectortype$ va, $abstractvectortype$ vb) {
 190         return va.bOp(vb, (i, a, b) -> ($type$) Math.IEEEremainder((double) a, (double) b));
 191     }
 192 
 193     public static 
 194     $abstractvectortype$ IEEEremainder($abstractvectortype$ va, $abstractvectortype$ vb, Vector.Mask<$Boxtype$> m) {
 195         return va.bOp(vb, m, (i, a, b) -> ($type$) Math.IEEEremainder((double) a, (double) b));
 196     }
 197 
 198     public static 
 199     $abstractvectortype$ nextAfter($abstractvectortype$ va, $abstractvectortype$ vb) {
 200         return va.bOp(vb, (i, a, b) -> ($type$) Math.nextAfter((double) a, (double) b));
 201     }
 202 
 203     public static 
 204     $abstractvectortype$ nextAfter($abstractvectortype$ va, $abstractvectortype$ vb, Vector.Mask<$Boxtype$> m) {
 205         return va.bOp(vb, m, (i, a, b) -> ($type$) Math.nextAfter((double) a, (double) b));
 206     }
 207 
 208     public static 
 209     $abstractvectortype$ nextDown($abstractvectortype$ va) {
 210         return va.uOp((i, a) -> ($type$) Math.nextDown((double) a));
 211     }
 212 
 213     public static 
 214     $abstractvectortype$ nextDown($abstractvectortype$ va, Vector.Mask<$Boxtype$> m) {
 215         return va.uOp(m, (i, a) -> ($type$) Math.nextDown((double) a));
 216     }
 217 
 218     public static 
 219     $abstractvectortype$ nextUp($abstractvectortype$ va) {
 220         return va.uOp((i, a) -> ($type$) Math.nextUp((double) a));
 221     }
 222 
 223     public static 
 224     $abstractvectortype$ nextUp($abstractvectortype$ va, Vector.Mask<$Boxtype$> m) {
 225         return va.uOp(m, (i, a) -> ($type$) Math.nextUp((double) a));
 226     }
 227 
 228     public static 
 229     $abstractvectortype$ rint($abstractvectortype$ va) {
 230         return va.uOp((i, a) -> ($type$) Math.rint((double) a));
 231     }
 232 
 233     public static 
 234     $abstractvectortype$ rint($abstractvectortype$ va, Vector.Mask<$Boxtype$> m) {
 235         return va.uOp(m, (i, a) -> ($type$) Math.rint((double) a));
 236     }
 237 
 238     public static 
 239     $abstractvectortype$ round($abstractvectortype$ va) {
 240         return va.uOp((i, a) -> ($type$) Math.round((double) a));
 241     }
 242 
 243     public static 
 244     $abstractvectortype$ round($abstractvectortype$ va, Vector.Mask<$Boxtype$> m) {
 245         return va.uOp(m, (i, a) -> ($type$) Math.round((double) a));
 246     }
 247 
 248     public static 
 249     $abstractvectortype$ scalb(Vector<Integer> o) {
 250         throw  new UnsupportedOperationException("Scalb not implemented yet.");
 251     }
 252 
 253     public static 
 254     $abstractvectortype$ scalb(Vector<Integer> o, Vector.Mask<$Boxtype$> m) {
 255         throw  new UnsupportedOperationException("Scalb not implemented yet.");
 256     }
 257 
 258     public static 
 259     $abstractvectortype$ signum($abstractvectortype$ va) {
 260         return va.uOp((i, a) -> ($type$) Math.signum((double) a));
 261     }
 262 
 263     public static 
 264     $abstractvectortype$ signum($abstractvectortype$ va, Vector.Mask<$Boxtype$> m) {
 265         return va.uOp(m, (i, a) -> ($type$) Math.signum((double) a));
 266     }
 267 
 268     public static 
 269     $abstractvectortype$ toDegrees($abstractvectortype$ va) {
 270         return va.uOp((i, a) -> ($type$) Math.toDegrees((double) a));
 271     }
 272 
 273     public static 
 274     $abstractvectortype$ toDegrees($abstractvectortype$ va, Vector.Mask<$Boxtype$> m) {
 275         return va.uOp(m, (i, a) -> ($type$) Math.toDegrees((double) a));
 276     }
 277 
 278     public static 
 279     $abstractvectortype$ toRadians($abstractvectortype$ va) {
 280         return va.uOp((i, a) -> ($type$) Math.toRadians((double) a));
 281     }
 282 
 283     public static 
 284     $abstractvectortype$ toRadians($abstractvectortype$ va, Vector.Mask<$Boxtype$> m) {
 285         return va.uOp(m, (i, a) -> ($type$) Math.toRadians((double) a));
 286     }
 287 
 288     public static 
 289     $abstractvectortype$ ulp($abstractvectortype$ va) {
 290         return va.uOp((i, a) -> ($type$) Math.ulp((double) a));
 291     }
 292 
 293     public static 
 294     $abstractvectortype$ ulp($abstractvectortype$ va, Vector.Mask<$Boxtype$> m) {
 295         return va.uOp(m, (i, a) -> ($type$) Math.ulp((double) a));
 296     }
 297 #end[FP]
 298 
 299 }