| 1626 | // zero/sign extend. "i" is limited to either classic unsigned (min==0) or |
| 1627 | // classic signed (min=minus-power-of-2); max=power-of-2-minus-1. |
| 1628 | private Node zsMask(Node val, Type t ) { |
| 1629 | if( !(val._type instanceof TypeInteger tval && t instanceof TypeInteger t0 && !tval.isa(t0)) ) { |
| 1630 | if( !(val._type instanceof TypeFloat tval && t instanceof TypeFloat t0 && !tval.isa(t0)) ) |
| 1631 | return val; |
| 1632 | // Float rounding |
| 1633 | return peep(new RoundF32Node(val)); |
| 1634 | } |
| 1635 | if( t0._min==0 ) // Unsigned |
| 1636 | return peep(new AndNode(null,val,con(t0._max))); |
| 1637 | // Signed extension |
| 1638 | int shift = Long.numberOfLeadingZeros(t0._max)-1; |
| 1639 | Node shf = con(shift); |
| 1640 | if( shf._type==TypeInteger.ZERO ) |
| 1641 | return val; |
| 1642 | return peep(new SarNode(null,peep(new ShlNode(null,val,shf.keep())),shf.unkeep())); |
| 1643 | } |
| 1644 | |
| 1645 | /** |
| 1646 | * Parse a function body; the caller will parse the surrounding "{}" |