MCPcopy Create free account
hub / github.com/SeaOfNodes/Simple / zsMask

Method zsMask

chapter14/src/main/java/com/seaofnodes/simple/Parser.java:726–741  ·  view source on GitHub ↗
(Node val, Type t )

Source from the content-addressed store, hash-verified

724 // zero/sign extend. "i" is limited to either classic unsigned (min==0) or
725 // classic signed (min=minus-power-of-2); max=power-of-2-minus-1.
726 private Node zsMask(Node val, Type t ) {
727 if( !(val._type instanceof TypeInteger tval && t instanceof TypeInteger t0 && !tval.isa(t0)) ) {
728 if( !(val._type instanceof TypeFloat tval && t instanceof TypeFloat t0 && !tval.isa(t0)) )
729 return val;
730 // Float rounding
731 return new RoundF32Node(val).peephole();
732 }
733 if( t0._min==0 ) // Unsigned
734 return new AndNode(val,new ConstantNode(TypeInteger.constant(t0._max)).peephole()).peephole();
735 // Signed extension
736 int shift = Long.numberOfLeadingZeros(t0._max)-1;
737 Node shf = new ConstantNode(TypeInteger.constant(shift)).peephole();
738 if( shf._type==TypeInteger.ZERO )
739 return val;
740 return new SarNode(new ShlNode(val,shf.keep()).peephole(),shf.unkeep()).peephole();
741 }
742
743
744 /**

Callers 2

parsePostfixMethod · 0.95

Calls 5

constantMethod · 0.95
keepMethod · 0.95
unkeepMethod · 0.95
isaMethod · 0.45
peepholeMethod · 0.45

Tested by

no test coverage detected