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.dialect;
26 
27 import jdk.incubator.code.CopyContext;
28 import jdk.incubator.code.TypeElement;
29 import jdk.incubator.code.Value;
30 
31 import java.util.List;
32 import java.util.Map;
33 
34 public abstract class HATF16BinaryOp extends HATF16Op {
35 
36     protected final TypeElement elementType;
37     protected final OpType operationType;
38     protected final List<Boolean> references;
39     protected final byte f32;
40 
41     public static final byte FIRST_OP = 0x01;
42     public static final byte LAST_OP = 0x10;
43 
44     public enum OpType {
45         ADD("+"),
46         SUB("-"),
47         MUL("*"),
48         DIV("/");
49 
50         String symbol;
51 
52         OpType(String symbol) {
53             this.symbol = symbol;
54         }
55 
56         public String symbol() {
57             return symbol;
58         }
59     }
60 
61     public HATF16BinaryOp(TypeElement typeElement, OpType operationType, List<Boolean> references, byte f32, List<Value> operands) {
62         super("", operands);
63         this.elementType = typeElement;
64         this.operationType = operationType;
65         this.references = references;
66         this.f32 = f32;
67     }
68 
69     public HATF16BinaryOp(HATF16BinaryOp op, CopyContext copyContext) {
70         super(op, copyContext);
71         this.elementType = op.elementType;
72         this.operationType = op.operationType;
73         this.references = op.references;
74         this.f32 = op.f32;
75     }
76 
77     @Override
78     public TypeElement resultType() {
79         return this.elementType;
80     }
81 
82     @Override
83     public Map<String, Object> externalize() {
84         return Map.of("hat.dialect.fp16." + varName(), operationType.symbol());
85     }
86 
87     public OpType operationType() {
88         return operationType;
89     }
90 
91     public List<Boolean> references() {
92         return references;
93     }
94 
95     public byte getF32() {
96         return f32;
97     }
98 
99 }