require '_h2ph_pre.ph';

no warnings 'redefine';

unless(defined(&_RASOPS_MASKS_H_)) {
    eval 'sub _RASOPS_MASKS_H_ () {1;}' unless defined(&_RASOPS_MASKS_H_);
    require 'sys/types.ph';
    require 'machine/endian.ph';
    eval 'sub MBL {
        my($x,$y) = @_;
	    eval q((($y) > 31? 0: ($x) >> ($y)));
    }' unless defined(&MBL);
    eval 'sub MBR {
        my($x,$y) = @_;
	    eval q((($y) > 31? 0: ($x) << ($y)));
    }' unless defined(&MBR);
    if((defined(&BYTE_ORDER) ? &BYTE_ORDER : 0) == (defined(&BIG_ENDIAN) ? &BIG_ENDIAN : 0)) {
	eval 'sub MBE {
	    my($x) = @_;
    	    eval q(($x));
	}' unless defined(&MBE);
    } else {
	eval 'sub MBE {
	    my($x) = @_;
    	    eval q(({  &u_int32_t  &tmp = ($x);  &tmp = (( &tmp >> 1) & 0x55555555) | (( &tmp << 1) & 0xaaaaaaaa);  &tmp = (( &tmp >> 2) & 0x33333333) | (( &tmp << 2) & 0xcccccccc);  &tmp = (( &tmp >> 4) & 0xf0f0f0f) | (( &tmp << 4) & 0xf0f0f0f0);  &tmp = (( &tmp >> 8) & 0xff00ff) | (( &tmp << 8) & 0xff00ff00);  &tmp = (( &tmp >> 16) & 0xffff) | (( &tmp << 16) & 0xffff0000);  &tmp; }));
	}' unless defined(&MBE);
    }
    eval 'sub GETBITS {
        my($sp, $x, $w, $dw) = @_;
	    eval q( &do { $dw =  &MBL(*($sp), ($x));  &if ((($x) + ($w)) > 32) $dw |= ( &MBR(($sp)[1], 32- ($x))); }  &while(0););
    }' unless defined(&GETBITS);
    eval 'sub PUTBITS {
        my($sw, $x, $w, $dp) = @_;
	    eval q( &do { \'int\'  &n = ($x) + ($w) - 32;  &if ( &n <= 0) {  &n =  $rasops_pmask[$x & 31][$w & 31]; *($dp) = (*($dp) & ~ &n) | ( &MBR($sw, $x) &  &n); }  &else { *($dp) = (*($dp) &  $rasops_rmask[$x]) | ( &MBR(($sw), $x)); ($dp)[1] = (($dp)[1] &  $rasops_rmask[ &n]) | ( &MBL($sw, 32-($x)) &  $rasops_lmask[ &n]); } }  &while(0););
    }' unless defined(&PUTBITS);
    if((defined(&BYTE_ORDER) ? &BYTE_ORDER : 0) == (defined(&BIG_ENDIAN) ? &BIG_ENDIAN : 0)) {
	eval 'sub rasops_masks_init () {
	    eval q( &do { }  &while (0));
	}' unless defined(&rasops_masks_init);
    } else {
    }
}
1;
