summaryrefslogtreecommitdiff
path: root/src/main/java/com/seaofnodes/simple/node/RoundF32Node.java
blob: 65f10a793a480b6d5920f606064502e917ae2153 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.seaofnodes.simple.node;


import com.seaofnodes.simple.type.Type;
import com.seaofnodes.simple.type.TypeFloat;


public class RoundF32Node extends Node {
    public RoundF32Node(Node lhs) { super(null, lhs); }
    @Override public Tag serialTag() { return Tag.RoundF32; }

    @Override protected String format() { return "((f32)%1)"; }

    @Override
    public Type compute() {
        if (in(1)._type instanceof TypeFloat i0 && i0.isConstant() )
            return TypeFloat.constant((float)i0.value());
        if( in(1)._type==TypeFloat.F64 ) return TypeFloat.F32;
        return in(1)._type;
    }

    @Override
    public Node idealize() {
        Node lhs = in(1);
        Type t1 = lhs._type;

        // RoundF32 of float
        if( t1 instanceof TypeFloat tf && tf._sz==32 )
            return lhs;

        return null;
    }
}