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(&__aarch64__)) {
	if(defined(&_LOCORE)) {
	    eval 'sub BSWAP16 {
	        my($_src, $_dst) = @_;
    		eval q( &rev16 $_dst, $_src);
	    }' unless defined(&BSWAP16);
	    eval 'sub BSWAP32 {
	        my($_src, $_dst) = @_;
    		eval q( &rev $_dst, $_src);
	    }' unless defined(&BSWAP32);
	    eval 'sub BSWAP64 {
	        my($_src, $_dst) = @_;
    		eval q( &rev $_dst, $_src);
	    }' unless defined(&BSWAP64);
	} else {
	    if(defined(&__GNUC__)) {
		require 'sys/types.ph';
		eval 'sub __BYTE_SWAP_U64_VARIABLE () { &__byte_swap_u64_variable;}' unless defined(&__BYTE_SWAP_U64_VARIABLE);
		eval 'sub __byte_swap_u64_variable {
		    my($v) = @_;
    		    eval q({  &if (! &__builtin_constant_p($v)) {  &__asm(\\"rev\\\\t%x0, %x1\\" : \\"=r\\" ($v) : \\"0\\" ($v)); $v; } $v = (($v & 0xff) << (56- 0)) | (($v >> (56- 0)) & 0xff) | (($v & 0xff00) << (48- 8)) | (($v >> (48- 8)) & 0xff00) | (($v & 0xff0000) << (40- 16)) | (($v >> (40- 16)) & 0xff0000) | (($v & 0xff000000) << (32- 24)) | (($v >> (32- 24)) & 0xff000000); $v; });
		}' unless defined(&__byte_swap_u64_variable);
		eval 'sub __BYTE_SWAP_U32_VARIABLE () { &__byte_swap_u32_variable;}' unless defined(&__BYTE_SWAP_U32_VARIABLE);
		eval 'sub __byte_swap_u32_variable {
		    my($v) = @_;
    		    eval q({  &if (! &__builtin_constant_p($v)) {  &__asm(\\"rev\\\\t%w0, %w1\\" : \\"=r\\" ($v) : \\"0\\" ($v)); $v; } $v = (($v & 0xff) << (24- 0)) | (($v >> (24- 0)) & 0xff) | (($v & 0xff00) << (16- 8)) | (($v >> (16- 8)) & 0xff00); $v; });
		}' unless defined(&__byte_swap_u32_variable);
		eval 'sub __BYTE_SWAP_U16_VARIABLE () { &__byte_swap_u16_variable;}' unless defined(&__BYTE_SWAP_U16_VARIABLE);
		eval 'sub __byte_swap_u16_variable {
		    my($v) = @_;
    		    eval q({  &if (! &__builtin_constant_p($v)) {  &uint32_t  &v32 = $v;  &__asm(\\"rev16\\\\t%w0, %w1\\" : \\"=r\\" ( &v32) : \\"0\\" ( &v32)); ( &uint16_t) &v32; } $v &= 0xffff; $v = ( &uint16_t)(($v >> 8) | ($v << 8)); $v; });
		}' unless defined(&__byte_swap_u16_variable);
	    }
	}
    }
 elsif(defined(&__arm__)) {
	require 'arm/asm.ph';
    }
}
1;
