11.8Srillig/* $NetBSD: byte_swap.h,v 1.8 2021/04/17 20:12:55 rillig Exp $ */ 21.1Sfvdl 31.1Sfvdl/*- 41.7Sjoerg * Copyright (c) 1998, 2010 The NetBSD Foundation, Inc. 51.1Sfvdl * All rights reserved. 61.1Sfvdl * 71.1Sfvdl * This code is derived from software contributed to The NetBSD Foundation 81.1Sfvdl * by Charles M. Hannum. 91.1Sfvdl * 101.1Sfvdl * Redistribution and use in source and binary forms, with or without 111.1Sfvdl * modification, are permitted provided that the following conditions 121.1Sfvdl * are met: 131.1Sfvdl * 1. Redistributions of source code must retain the above copyright 141.1Sfvdl * notice, this list of conditions and the following disclaimer. 151.1Sfvdl * 2. Redistributions in binary form must reproduce the above copyright 161.1Sfvdl * notice, this list of conditions and the following disclaimer in the 171.1Sfvdl * documentation and/or other materials provided with the distribution. 181.1Sfvdl * 191.1Sfvdl * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Sfvdl * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Sfvdl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Sfvdl * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Sfvdl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Sfvdl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Sfvdl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Sfvdl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Sfvdl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Sfvdl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Sfvdl * POSSIBILITY OF SUCH DAMAGE. 301.1Sfvdl */ 311.1Sfvdl 321.1Sfvdl/* 331.1Sfvdl * Copy of the i386 version. 64 bit versions may be added later. 341.1Sfvdl */ 351.1Sfvdl 361.1Sfvdl#ifndef _AMD64_BYTE_SWAP_H_ 371.1Sfvdl#define _AMD64_BYTE_SWAP_H_ 381.1Sfvdl 391.6Smrg#ifdef __x86_64__ 401.6Smrg 411.4Sdsl#ifdef __GNUC__ 421.1Sfvdl#include <sys/types.h> 431.4Sdsl__BEGIN_DECLS 441.1Sfvdl 451.7Sjoerg#define __BYTE_SWAP_U64_VARIABLE __byte_swap_u64_variable 461.7Sjoergstatic __inline uint64_t __byte_swap_u64_variable(uint64_t); 471.7Sjoergstatic __inline uint64_t 481.7Sjoerg__byte_swap_u64_variable(uint64_t x) 491.7Sjoerg{ 501.7Sjoerg __asm volatile ( "bswap %1" : "=r" (x) : "0" (x)); 511.7Sjoerg return (x); 521.7Sjoerg} 531.7Sjoerg 541.4Sdsl#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable 551.4Sdslstatic __inline uint32_t __byte_swap_u32_variable(uint32_t); 561.4Sdslstatic __inline uint32_t 571.4Sdsl__byte_swap_u32_variable(uint32_t x) 581.1Sfvdl{ 591.2Sperry __asm volatile ( "bswap %1" : "=r" (x) : "0" (x)); 601.1Sfvdl return (x); 611.1Sfvdl} 621.1Sfvdl 631.4Sdsl#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable 641.4Sdslstatic __inline uint16_t __byte_swap_u16_variable(uint16_t); 651.4Sdslstatic __inline uint16_t 661.4Sdsl__byte_swap_u16_variable(uint16_t x) 671.1Sfvdl{ 681.8Srillig __asm volatile ("rorw $8, %w1" : "=r" (x) : "0" (x)); 691.1Sfvdl return (x); 701.1Sfvdl} 711.1Sfvdl 721.4Sdsl__END_DECLS 731.4Sdsl#endif 741.1Sfvdl 751.6Smrg#else /* __x86_64__ */ 761.6Smrg 771.6Smrg#include <i386/byte_swap.h> 781.6Smrg 791.6Smrg#endif /* __x86_64__ */ 801.6Smrg 811.1Sfvdl#endif /* !_AMD64_BYTE_SWAP_H_ */ 82