Hi,
speed is usually paid for by size. This is just suggestion how to exclude/bypass parameters passing, cycles logic,.... probably it is faster, you can test.
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
//**********************************************************************
//global variables to do not send parameter to function
volatile unsigned int value;
volatile unsigned char *pvH=(unsigned char*)(&value);
volatile unsigned char *pvL=(unsigned char*) ( ( (unsigned char*)(&value) ) +1);
//**********************************************************************
unsigned char find1(void)
{
if(*pvH)
{
if(*pvH & 0B11110000)
{
if(*pvH & 0B11000000)
{
if(*pvH & 0B10000000)
{
return 15; //1000 0000
}
else
{
return 14; //0100 0000
}
}
else
{
if(*pvH & 0B00100000)
{
return 13; //0010 0000
}
else
{
return 12; //0001 0000
}
}
}
else
{
if(*pvH & 0B00001100)
{
if(*pvH & 0B00001000)
{
return 11; //1000 0000
}
else
{
return 10; //0100 0000
}
}
else
{
if(*pvH & 0B00000010)
{
return 9; //0010 0000
}
else
{
return 8; //0001 0000
}
}
}
}
else
{
if(*pvL & 0B11110000)
{
if(*pvL & 0B11000000)
{
if(*pvL & 0B10000000)
{
return 7; //1000 0000
}
else
{
return 6; //0100 0000
}
}
else
{
if(*pvL & 0B00100000)
{
return 5; //0010 0000
}
else
{
return 4; //0001 0000
}
}
}
else
{
if(*pvL & 0B00001100)
{
if(*pvL & 0B00001000)
{
return 3; //1000 0000
}
else
{
return 2; //0100 0000
}
}
else
{
if(*pvL & 0B00000010)
{
return 1; //0010 0000
}
else
{
return 0; //0001 0000
}
}
}
}
return 55;
}
//**********************************************************************
void main(void)
{
static unsigned char pos;
for(;;)
{
for(value=0; value < 0xFFFF; value++)
{
if (value != 0)
pos = find1();
}
}
}