require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_SYS_BSWAP_H_)) {
    eval 'sub _SYS_BSWAP_H_ () {1;}' unless defined(&_SYS_BSWAP_H_);
    unless(defined(&_LOCORE)) {
	require 'sys/stdint.ph';
	require 'machine/bswap.ph';
	if(defined(&_KERNEL) || defined(&_STANDALONE) || !defined(&__BSWAP_RENAME)) {
	} else {
	}
	if(defined(&__GNUC__)  && !defined(&__lint__)) {
	    unless(defined(&__BYTE_SWAP_U64_VARIABLE)) {
		eval 'sub __BYTE_SWAP_U64_VARIABLE () { &bswap64;}' unless defined(&__BYTE_SWAP_U64_VARIABLE);
	    }
	    unless(defined(&__BYTE_SWAP_U32_VARIABLE)) {
		eval 'sub __BYTE_SWAP_U32_VARIABLE () { &bswap32;}' unless defined(&__BYTE_SWAP_U32_VARIABLE);
	    }
	    unless(defined(&__BYTE_SWAP_U16_VARIABLE)) {
		eval 'sub __BYTE_SWAP_U16_VARIABLE () { &bswap16;}' unless defined(&__BYTE_SWAP_U16_VARIABLE);
	    }
	    eval 'sub __byte_swap_u64_constant {
	        my($x) = @_;
    		eval q(( &__CAST( &uint64_t, (((($x) & 0xff00000000000000) >> 56) | ((($x) & 0xff000000000000) >> 40) | ((($x) & 0xff0000000000) >> 24) | ((($x) & 0xff00000000) >> 8) | ((($x) & 0xff000000) << 8) | ((($x) & 0xff0000) << 24) | ((($x) & 0xff00) << 40) | ((($x) & 0xff) << 56)))));
	    }' unless defined(&__byte_swap_u64_constant);
	    eval 'sub __byte_swap_u32_constant {
	        my($x) = @_;
    		eval q(( &__CAST( &uint32_t, (((($x) & 0xff000000) >> 24) | ((($x) & 0xff0000) >> 8) | ((($x) & 0xff00) << 8) | ((($x) & 0xff) << 24)))));
	    }' unless defined(&__byte_swap_u32_constant);
	    eval 'sub __byte_swap_u16_constant {
	        my($x) = @_;
    		eval q(( &__CAST( &uint16_t, (((($x) & 0xff00) >> 8) | ((($x) & 0xff) << 8)))));
	    }' unless defined(&__byte_swap_u16_constant);
	    eval 'sub bswap64 {
	        my($x) = @_;
    		eval q( &__CAST( &uint64_t,  &__builtin_constant_p(($x)) ?  &__byte_swap_u64_constant($x) :  &__BYTE_SWAP_U64_VARIABLE($x)));
	    }' unless defined(&bswap64);
	    eval 'sub bswap32 {
	        my($x) = @_;
    		eval q( &__CAST( &uint32_t,  &__builtin_constant_p(($x)) ?  &__byte_swap_u32_constant($x) :  &__BYTE_SWAP_U32_VARIABLE($x)));
	    }' unless defined(&bswap32);
	    eval 'sub bswap16 {
	        my($x) = @_;
    		eval q( &__CAST( &uint16_t,  &__builtin_constant_p(($x)) ?  &__byte_swap_u16_constant($x) :  &__BYTE_SWAP_U16_VARIABLE($x)));
	    }' unless defined(&bswap16);
	}
    }
}
1;
