summaryrefslogtreecommitdiff
path: root/src/main/java/com/seaofnodes/simple/codegen/RegMaskRW.java
blob: 1da9a3b1dfb82f82e332fa20d0cea5f537c9d2b2 (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
34
35
36
package com.seaofnodes.simple.codegen;

// Mutable regmask(writable)
public class RegMaskRW extends RegMask {
    public RegMaskRW(long x, long y) { super(x,y);  }
    // clears bit at position r. Returns true if the mask is still not empty.
    public boolean clr(int r) {
        if( r < 64 ) _bits0 &= ~(1L<<(r   ));
        else         _bits1 &= ~(1L<<(r-64));
        return _bits0!=0 || _bits1!=0;
    }
    // sets bit at position r.
    public void set(int r) {
        if( r < 64 ) _bits0 |= (1L<<(r   ));
        else         _bits1 |= (1L<<(r-64));
    }
    @Override RegMaskRW and( RegMask mask ) {
        if( mask==null ) return this;
        _bits0 &= mask._bits0;
        _bits1 &= mask._bits1;
        return this;
    }
    @Override RegMaskRW sub( RegMask mask ) {
        if( mask==null ) return this;
        _bits0 &= ~mask._bits0;
        _bits1 &= ~mask._bits1;
        return this;
    }
    public RegMaskRW or( RegMask mask ) {
        if( mask!=null ) {
            _bits0 |= mask._bits0;
            _bits1 |= mask._bits1;
        }
        return this;
    }
}