mirror of
https://github.com/intel/isa-l.git
synced 2024-12-12 17:33:50 +01:00
mem: Remove unaligned loads in base function
Change-Id: I8fb0f2e2e372485c864d5c60f816b661a865b707 Signed-off-by: Roy Oursler <roy.j.oursler@intel.com>
This commit is contained in:
parent
5be1ba2215
commit
a3169750b5
@ -51,5 +51,10 @@ static inline uint64_t load_u64(uint8_t * buf) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline uintmax_t load_umax(uint8_t * buf) {
|
||||||
|
uintmax_t ret;
|
||||||
|
memcpy(&ret, buf, sizeof(ret));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,22 +29,22 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include "unaligned.h"
|
||||||
|
|
||||||
int mem_zero_detect_base(void *buf, size_t n)
|
int mem_zero_detect_base(void *buf, size_t n)
|
||||||
{
|
{
|
||||||
unsigned char *c;
|
uint8_t *c = buf;
|
||||||
uintmax_t a = 0, *p = buf;
|
uintmax_t a = 0;
|
||||||
|
|
||||||
// Check buffer in native machine width comparisons
|
// Check buffer in native machine width comparisons
|
||||||
while (n >= sizeof(*p)) {
|
while (n >= sizeof(uintmax_t)) {
|
||||||
n -= sizeof(*p);
|
n -= sizeof(uintmax_t);
|
||||||
if (*p++ != 0)
|
if (load_umax(c) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
c += sizeof(uintmax_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check remaining bytes
|
// Check remaining bytes
|
||||||
c = (unsigned char *)p;
|
|
||||||
|
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case 7:
|
case 7:
|
||||||
a |= *c++; // fall through to case 6,5,4
|
a |= *c++; // fall through to case 6,5,4
|
||||||
@ -53,12 +53,12 @@ int mem_zero_detect_base(void *buf, size_t n)
|
|||||||
case 5:
|
case 5:
|
||||||
a |= *c++; // fall through to case 4
|
a |= *c++; // fall through to case 4
|
||||||
case 4:
|
case 4:
|
||||||
a |= *((unsigned int *)c);
|
a |= load_u32(c);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
a |= *c++; // fall through to case 2
|
a |= *c++; // fall through to case 2
|
||||||
case 2:
|
case 2:
|
||||||
a |= *((unsigned short *)c);
|
a |= load_u16(c);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
a |= *c;
|
a |= *c;
|
||||||
|
Loading…
Reference in New Issue
Block a user