/*1* Copyright 2010 Tilera Corporation. All Rights Reserved.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public License5* as published by the Free Software Foundation, version 2.6*7* This program is distributed in the hope that it will be useful, but8* WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or10* NON INFRINGEMENT. See the GNU General Public License for11* more details.12*/1314#include <linux/types.h>15#include <linux/string.h>16#include <linux/module.h>1718#undef strlen1920size_t strlen(const char *s)21{22/* Get an aligned pointer. */23const uintptr_t s_int = (uintptr_t) s;24const uint32_t *p = (const uint32_t *)(s_int & -4);2526/* Read the first word, but force bytes before the string to be nonzero.27* This expression works because we know shift counts are taken mod 32.28*/29uint32_t v = *p | ((1 << (s_int << 3)) - 1);3031uint32_t bits;32while ((bits = __insn_seqb(v, 0)) == 0)33v = *++p;3435return ((const char *)p) + (__insn_ctz(bits) >> 3) - s;36}37EXPORT_SYMBOL(strlen);383940