Implementing Endian.h little endian functions in IRIX
#1
Implementing Endian.h little endian functions in IRIX
So I've been holding off on this for libxg, my attempt to add modern functions to IRIX, due to really not getting the most efficient methods to do this. 

As libxg is BSD-licensed, please do not give me GNU examples. I don't want to potentially infringe on GPL code.

Currently, our endian.h only implements htobe functions (which require nothing, as IRIX is already eb). 

Here's the current version (derived from NetBSD). Some of these includes are probably not necessary at all, but I didn't want to take chances. 

Code:
#ifndef _ENDIAN_H_
#define _ENDIAN_H_

#include <standards.h>
#include <sys/endian.h>
#include <netinet/in.h>
#include <inttypes.h>
/*
* Dummy host-to-be macros. Honestly this shouldn't be a major issue
* to exclude htole functions, but we'll see
*/

#define htobe16(x)    (x)
#define htobe32(x)    (x)
#define htobe64(x)    (x)
#define HTOBE16(x)    (void, (x))
#define HTOBE32(x)    (void, (x))
#define HTOBE64(x)    (void, (x))
#define be16toh(x)    htobe16(x)
#define be32toh(x)    htobe32(x)
#define be64toh(x)    htobe64(x)
#define BE16TOH(x)    HTOBE16(x)
#define BE32TOH(x)    HTOBE32(x)
#define BE64TOH(x)    HTOBE64(x)
#endif


The NetBSD guys have their code to do the bswap functions in sys/bswap.h - and the relevant functions that they correspond to are here:

Code:
#define    __byte_swap_u64_constant(x) \
    (__CAST(uint64_t, \
     ((((x) & 0xff00000000000000ull) >> 56) | \
      (((x) & 0x00ff000000000000ull) >> 40) | \
      (((x) & 0x0000ff0000000000ull) >> 24) | \
      (((x) & 0x000000ff00000000ull) >>  8) | \
      (((x) & 0x00000000ff000000ull) <<  8) | \
      (((x) & 0x0000000000ff0000ull) << 24) | \
      (((x) & 0x000000000000ff00ull) << 40) | \
      (((x) & 0x00000000000000ffull) << 56))))

#define    __byte_swap_u32_constant(x) \
    (__CAST(uint32_t, \
    ((((x) & 0xff000000) >> 24) | \
     (((x) & 0x00ff0000) >>  8) | \
     (((x) & 0x0000ff00) <<  8) | \
     (((x) & 0x000000ff) << 24))))

#define    __byte_swap_u16_constant(x) \
    (__CAST(uint16_t, \
    ((((x) & 0xff00) >> 8) | \
     (((x) & 0x00ff) << 8))))


Clearly, these are bitwise math functions. My questions are as follows:

1. Are these functions efficient to port into IRIX? If not, what's a better way to do this?
2. Is this close to how GNULib does it? I can't quite go and /look/ at their code to do this since I'm not wanting to do that. 
3. Other than removing things like __CAST from the functions, are there any problematic bits that I could encounter by using these?

I'm the system admin of this site. Private security technician, licensed locksmith, hack of a c developer and vintage computer enthusiast. 

https://contrib.irixnet.org/raion/ -- contributions and pieces that I'm working on currently. 

https://codeberg.org/SolusRaion -- Code repos I control

Technical problems should be sent my way.
Raion
Chief IRIX Officer

Trade Count: (9)
Posts: 4,240
Threads: 533
Joined: Nov 2017
Location: Eastern Virginia
Website Find Reply
04-18-2021, 08:04 PM
#2
RE: Implementing Endian.h little endian functions in IRIX
(04-18-2021, 08:04 PM)Raion Wrote:  2. Is this close to how GNULib does it? I can't quite go and /look/ at their code to do this since I'm not wanting to do that. 

It's almost identical.  There's really only one way to swap bytes.  There's nothing unique or proprietary about the algorithm.

SGI:  Indigo, Indigo2, Octane, Origin 300
Sun:  SPARCstation 20 (x4), Ultra 2, Blade 2500, T5240
HP:  9000/380, 425e, C8000
Digital: DECstation 5000/125, PWS 600au
jpstewart
Developer

Trade Count: (1)
Posts: 444
Threads: 6
Joined: May 2018
Location: SW Ontario, CA
Find Reply
04-19-2021, 12:19 AM
#3
RE: Implementing Endian.h little endian functions in IRIX
Gotcha. So this is indeed the best way to do this. Thank you.

I'm the system admin of this site. Private security technician, licensed locksmith, hack of a c developer and vintage computer enthusiast. 

https://contrib.irixnet.org/raion/ -- contributions and pieces that I'm working on currently. 

https://codeberg.org/SolusRaion -- Code repos I control

Technical problems should be sent my way.
Raion
Chief IRIX Officer

Trade Count: (9)
Posts: 4,240
Threads: 533
Joined: Nov 2017
Location: Eastern Virginia
Website Find Reply
04-19-2021, 02:04 AM
#4
RE: Implementing Endian.h little endian functions in IRIX
Implemented. Will make it a point to have someone test this eventually.

I'm the system admin of this site. Private security technician, licensed locksmith, hack of a c developer and vintage computer enthusiast. 

https://contrib.irixnet.org/raion/ -- contributions and pieces that I'm working on currently. 

https://codeberg.org/SolusRaion -- Code repos I control

Technical problems should be sent my way.
Raion
Chief IRIX Officer

Trade Count: (9)
Posts: 4,240
Threads: 533
Joined: Nov 2017
Location: Eastern Virginia
Website Find Reply
04-19-2021, 06:49 PM


Forum Jump:


Users browsing this thread: 1 Guest(s)