1 /*
 2  * Copyright (c) 2025, 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 any
23  * questions.
24  */
25 package hat.types;
26 import optkl.IfaceValue;
27 import jdk.incubator.code.dialect.java.JavaType;
28 
29 public interface F32x4 extends IfaceValue.Vector{
30     Shape shape = Shape.of( JavaType.FLOAT,4);
31 
32     float x();
33     float y();
34     float z();
35     float w();
36 
37     static F32x4 of(float x, float y, float z, float w) {
38         record Impl(float x, float y, float z, float w) implements F32x4 {
39         }
40         return new Impl(x, y, z, w);
41     }
42 
43     static F32x4 add(F32x4 lhs, F32x4 rhs) {
44         return of(lhs.x()+rhs.x(), lhs.y()+rhs.y(),lhs.z()+rhs.z(),lhs.w()+rhs.w());
45     }
46 
47     static F32x4 sub(F32x4 lhs, F32x4 rhs) {
48         return of(lhs.x()+rhs.x(), lhs.y()+rhs.y(),lhs.z()+rhs.z(),lhs.w()+rhs.w());
49     }
50 
51     static F32x4 mul(F32x4 lhs, F32x4 rhs) {
52         return of(lhs.x()+rhs.x(), lhs.y()+rhs.y(),lhs.z()+rhs.z(),lhs.w()+rhs.w());
53     }
54 
55     static F32x4 div(F32x4 lhs, F32x4 rhs) {
56        return of(lhs.x()/rhs.x(), lhs.y()/rhs.y(),lhs.z()/rhs.z(),lhs.w()/rhs.w());
57     }
58 
59 
60     static F32x4 add(F32x4 lhs, float scalarRhs) {
61         return of(lhs.x()+scalarRhs,lhs.y()+scalarRhs, lhs.z()+scalarRhs,lhs.w()+scalarRhs);
62     }
63     static F32x4 sub(F32x4 lhs, float scalarRhs) {
64         return of(lhs.x()-scalarRhs,lhs.y()-scalarRhs, lhs.z()-scalarRhs,lhs.w()-scalarRhs);
65     }
66     static F32x4 mul(F32x4 lhs, float scalarRhs) {
67         return of(lhs.x()*scalarRhs,lhs.y()*scalarRhs, lhs.z()*scalarRhs,lhs.w()*scalarRhs);
68     }
69     static F32x4 sqr(F32x4 f32x4) {
70         return F32x4.mul(f32x4,f32x4);
71     }
72 
73     default F32x4 add(F32x4 rhs) {
74         return F32x4.add(this, rhs);
75     }
76     default F32x4 add(float scalarRhs) {
77         return F32x4.add(this, scalarRhs);
78     }
79     default F32x4 sqr() {
80         return F32x4.sqr(this);
81     }
82     default F32x4 sub(F32x4 rhs) {
83         return F32x4.sub(this, rhs);
84     }
85     default F32x4 sub(float scalarRhs) {
86         return F32x4.sub(this, scalarRhs);
87     }
88     default F32x4 mul(F32x4 rhs) {
89         return F32x4.mul(this, rhs);
90     }
91     default F32x4 mul(float scalarRhs) {
92         return F32x4.mul(this, scalarRhs);
93     }
94     default F32x4 div(F32x4 rhs) {
95         return F32x4.div(this, rhs);
96     }
97 }