jacob navia <jacob@nospam.c omwrites:
I'd first align and then use that. You may get a trap with unaligned
access even on machine where unaligned access doesn't normally trap if you
stump on a page boundary with the next page not mapped in memory. And some
machine allows unaligned access but at a performance penality, which would
be against the goal of using that trick.
Yours,
--
Jean-Marc
#include <stdio.h>
#include <string.h>
#define H 0x8080808080808 080ULL
#define L 0x0101010101010 101ULL
size_t myStrlen(char *s)
{
unsigned long long t;
char *save = s;
>
while (1) {
// This supposes that the input string is aligned
// or that the machine doesn't trap when reading
// a 8 byte integer at a random position like the
// x86
t = *(unsigned long long *)s;
if (H & (t - L) & ~t)
break;
s += sizeof(long long);
}
#include <string.h>
#define H 0x8080808080808 080ULL
#define L 0x0101010101010 101ULL
size_t myStrlen(char *s)
{
unsigned long long t;
char *save = s;
>
while (1) {
// This supposes that the input string is aligned
// or that the machine doesn't trap when reading
// a 8 byte integer at a random position like the
// x86
t = *(unsigned long long *)s;
if (H & (t - L) & ~t)
break;
s += sizeof(long long);
}
access even on machine where unaligned access doesn't normally trap if you
stump on a page boundary with the next page not mapped in memory. And some
machine allows unaligned access but at a performance penality, which would
be against the goal of using that trick.
Yours,
--
Jean-Marc
Comment