Skip to content

Commit

Permalink
Bug #26568748: MAIN.FUNC_BITWISE_OPS DIES WITH UNALIGNED ACCESS
Browse files Browse the repository at this point in the history
Fix uint8korr() and related macros so that they explicitly do unaligned
accesses, even on x86. In the process, there's no more distinction between
x86 versus everything else anymore; it's all just big versus little endian.

Change-Id: I479d7572585d4a1682705258bbbb1e9dfbb920a3
  • Loading branch information
Steinar H. Gunderson committed Aug 7, 2017
1 parent 53a4a44 commit 536ea31
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 214 deletions.
103 changes: 102 additions & 1 deletion include/big_endian.h
@@ -1,4 +1,4 @@
/* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -15,10 +15,111 @@

/**
@file include/big_endian.h
Endianness-independent definitions (little_endian.h contains optimized
versions if you know you are on a little-endian platform).
*/

// IWYU pragma: private, include "my_byteorder.h"

#ifndef MY_BYTEORDER_INCLUDED
#error This file should never be #included directly; use my_byteorder.h.
#endif

#include <string.h>

#include "my_inttypes.h"

static inline int16 sint2korr(const uchar *A)
{
return
(int16) (((int16) (A[0])) +
((int16) (A[1]) << 8))
;
}

static inline int32 sint4korr(const uchar *A)
{
return
(int32) (((int32) (A[0])) +
(((int32) (A[1]) << 8)) +
(((int32) (A[2]) << 16)) +
(((int32) (A[3]) << 24)))
;
}

static inline uint16 uint2korr(const uchar *A)
{
return
(uint16) (((uint16) (A[0])) +
((uint16) (A[1]) << 8))
;
}

static inline uint32 uint4korr(const uchar *A)
{
return
(uint32) (((uint32) (A[0])) +
(((uint32) (A[1])) << 8) +
(((uint32) (A[2])) << 16) +
(((uint32) (A[3])) << 24))
;
}

static inline ulonglong uint8korr(const uchar *A)
{
return
((ulonglong)(((uint32) (A[0])) +
(((uint32) (A[1])) << 8) +
(((uint32) (A[2])) << 16) +
(((uint32) (A[3])) << 24)) +
(((ulonglong) (((uint32) (A[4])) +
(((uint32) (A[5])) << 8) +
(((uint32) (A[6])) << 16) +
(((uint32) (A[7])) << 24))) <<
32))
;
}

static inline longlong sint8korr(const uchar *A)
{
return (longlong) uint8korr(A);
}

static inline void int2store(uchar *T, uint16 A)
{
uint def_temp= A ;
*(T)= (uchar)(def_temp);
*(T+1)= (uchar)(def_temp >> 8);
}

static inline void int4store(uchar *T, uint32 A)
{
*(T)= (uchar) (A);
*(T+1)=(uchar) (A >> 8);
*(T+2)=(uchar) (A >> 16);
*(T+3)=(uchar) (A >> 24);
}

static inline void int7store(uchar *T, ulonglong A)
{
*(T)= (uchar) (A);
*(T+1)=(uchar) (A >> 8);
*(T+2)=(uchar) (A >> 16);
*(T+3)=(uchar) (A >> 24);
*(T+4)=(uchar) (A >> 32);
*(T+5)=(uchar) (A >> 40);
*(T+6)=(uchar) (A >> 48);
}

static inline void int8store(uchar *T, ulonglong A)
{
uint def_temp= (uint) A,
def_temp2= (uint) (A >> 32);
int4store(T, def_temp);
int4store(T+4,def_temp2);
}

/*
Data in big-endian format.
*/
Expand Down
112 changes: 0 additions & 112 deletions include/byte_order_generic.h

This file was deleted.

83 changes: 0 additions & 83 deletions include/byte_order_generic_x86.h

This file was deleted.

0 comments on commit 536ea31

Please sign in to comment.