require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_ARM_BYTE_SWAP_H_)) {
    eval 'sub _ARM_BYTE_SWAP_H_ () {1;}' unless defined(&_ARM_BYTE_SWAP_H_);
    if(defined(&_LOCORE)) {
	if(defined(&_ARM_ARCH_6) || defined(&_ARM_ARCH_7)) {
	    eval 'sub BSWAP16 {
	        my($_src, $_dst, $_tmp) = @_;
    		eval q( &rev16 $_dst, $_src);
	    }' unless defined(&BSWAP16);
	    eval 'sub BSWAP32 {
	        my($_src, $_dst, $_tmp) = @_;
    		eval q( &rev $_dst, $_src);
	    }' unless defined(&BSWAP32);
	} else {
	    eval 'sub BSWAP16 {
	        my($_src, $_dst, $_tmp) = @_;
    		eval q( &mov $_tmp, $_src,  &ror 8;  &orr $_tmp, $_tmp, $_tmp,  &lsr 16;  &bic $_dst, $_tmp, $_tmp,  &lsl 16);
	    }' unless defined(&BSWAP16);
	    eval 'sub BSWAP32 {
	        my($_src, $_dst, $_tmp) = @_;
    		eval q( &eor $_tmp, $_src, $_src,  &ror 16;  &bic $_tmp, $_tmp, 0xff0000 ;  &mov $_dst, $_src,  &ror 8;  &eor $_dst, $_dst, $_tmp,  &lsr 8);
	    }' unless defined(&BSWAP32);
	}
    } else {
	if(defined(&__GNUC__)) {
	    require 'sys/types.ph';
	    eval 'sub __BYTE_SWAP_U32_VARIABLE () { &__byte_swap_u32_variable;}' unless defined(&__BYTE_SWAP_U32_VARIABLE);
# some #ifdef were dropped here -- fill in the blanks
	    eval 'sub __byte_swap_u32_variable {
	        my($v) = @_;
    		eval q({  &uint32_t  &t1;  &t1 = $v ^ (($v << 16) | ($v >> 16));  &t1 &= 0xff00ffff; $v = ($v >> 8) | ($v << 24); $v ^= ( &t1 >> 8); $v; });
	    }' unless defined(&__byte_swap_u32_variable);
	    eval 'sub __BYTE_SWAP_U16_VARIABLE () { &__byte_swap_u16_variable;}' unless defined(&__BYTE_SWAP_U16_VARIABLE);
# some #ifdef were dropped here -- fill in the blanks
	    eval 'sub __byte_swap_u16_variable {
	        my($v) = @_;
    		eval q({ $v &= 0xffff; $v = ( &uint16_t)(($v >> 8) | ($v << 8)); $v; });
	    }' unless defined(&__byte_swap_u16_variable);
	}
    }
}
1;
