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

Method zsMask

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

Source from the content-addressed store, hash-verified

830 // zero/sign extend. "i" is limited to either classic unsigned (min==0) or
831 // classic signed (min=minus-power-of-2); max=power-of-2-minus-1.
832 private Node zsMask(Node val, Type t ) {
833 if( !(val._type instanceof TypeInteger tval && t instanceof TypeInteger t0 && !tval.isa(t0)) ) {
834 if( !(val._type instanceof TypeFloat tval && t instanceof TypeFloat t0 && !tval.isa(t0)) )
835 return val;
836 // Float rounding
837 return new RoundF32Node(val).peephole();
838 }
839 if( t0._min==0 ) // Unsigned
840 return new AndNode(val,con(t0._max)).peephole();
841 // Signed extension
842 int shift = Long.numberOfLeadingZeros(t0._max)-1;
843 Node shf = con(shift);
844 if( shf._type==TypeInteger.ZERO )
845 return val;
846 return new SarNode(new ShlNode(val,shf.keep()).peephole(),shf.unkeep()).peephole();
847 }
848
849
850 /**

Callers 2

parsePostfixMethod · 0.95

Calls 5

conMethod · 0.95
keepMethod · 0.95
unkeepMethod · 0.95
isaMethod · 0.45
peepholeMethod · 0.45

Tested by

no test coverage detected