Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fastest way to single hex digit => decimal

Name: Anonymous 2012-01-06 8:46

char hexchartodec_map[256] = {
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  0,  0,  0,  0,  0,  0,
        0,  10, 11, 12, 13, 14, 15, 0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  10, 11, 12, 13, 14, 15, 0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
        0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
};

char hexchartodec(char i) {
        return hexchartodec_map[i];
}

Name: Anonymous 2012-01-07 18:52

>>80 why?

Name: Anonymous 2012-01-07 18:54

ITT shitty C programmer who haven't read their standard library


long int dec = strtol(hex_string,null,16);

Name: Anonymous 2012-01-07 19:04

>>82
ITT shitty C programmer who haven't read the whole thread
>>75
>>78

Name: Anonymous 2012-01-07 19:08

>>34 already proposed strtol

Name: Anonymous 2012-01-07 19:18

>>69
java
games
Fuck off, ``cubicle monkey".

Name: Anonymous 2012-01-07 19:24

>>85
Why would you tell Notch to fuck off?

Name: Anonymous 2012-01-07 19:52

>>76
>ruby
SLOW AS FUCK

Name: Anonymous 2012-01-07 21:49

>>84
pronounced ``stir-tall''

Name: Anonymous 2012-01-07 22:08

>>88

I pronounce it as stir-toll, as in toilet or toll road.

Name: Anonymous 2012-01-08 0:56

>>89
Rhymes with Adderall.

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 2:39

/*
C:\Program Files\dmc8.50\dmc\dm\bin\code>hex
hexchartodec Chars:1,15,13,5 time:474 cycles
hexchartodec2 Chars:1,15,13,5 time:1195 cycles
hexchartodec3 Chars:1,15,13,5 time:85 cycles
hexchartodec4 Chars:1,15,13,5 time:2024 cycles
hex2dec Chars:1,15,13,5 time:7266 cycles
hexchartodec3m Chars:1,15,13,5 time:190 cycles
hexToDec Chars:1,15,13,5 time:1904 cycles
hexchartodec3m2 Chars:1,15,13,5 time:97 cycles
hexToDecChar Chars:1,15,13,5 time:1622 cycles
macroHexToDecChar Chars:1,15,13,5 time:656 cycles
strtoldec Chars:1,15,13,5 time:7642 cycles
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#define u1 unsigned char
#define u2 unsigned short
#define u4 unsigned int
#define u8 unsigned long long
#define s1 signed char
#define s2 signed short
#define s4 signed int
#define s8 signed long long
#define f2 short float
#define f4 float
#define f8 double
#define f10 long double
#define hexchartodec3(x) (((x>>6)+((x>>6)<<3))+(x&0xf))
#define hexchartodec3m(x) ((((x&64)>>3)+((x&64)>>6)+x)&15)
unsigned int
hexToDec(unsigned char x)
{
    return ( (x & 0xf)      * ((x & 0x10) >> 4))
         + (((x & 0xf) + 9) * ((x & 0x40) >> 6));
}

char hexToDecChar(char x)
{
    return ( (x & 0xf)      * ((x & 0x10) >> 4))
         + (((x & 0xf) + 9) * ((x & 0x40) >> 6));
}
#define macroHexToDecChar(x) ( (x & 0xf)      * ((x & 0x10) >> 4))   + (((x & 0xf) + 9) * ((x & 0x40) >> 6))
#define hexchartodec3m2(x) ((((x>>6)<<3)+(x>>6)+x)&15)
#define timefunc(F)  ;start=rdtsc();n1=F('1');n2=F('f');n3=F('d');n4=F('5');end=rdtsc();printf("%s Chars:%d,%d,%d,%d time:%llu cycles\n",#F,n1,n2,n3,n4,(end-start));

int hex2dec(int c) {
    static const char *s = "0123456789ABCDEF";
    char *p;
    if (p = memchr(s, toupper(c), 16))
        return p - s;
    else {
        errno = EDOM;
        return -1;
    }
}

long int strtoldec(char c){
return strtol(&c,NULL,16);
}




u8 inline rdtsc(){__asm{RDTSC}}
char hexchartodec_map[256] = {
            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
            0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  0,  0,  0,  0,  0,  0,
            0,  10, 11, 12, 13, 14, 15, 0,  0,  0,  0,  0,  0,  0,  0,  0,
            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
            0,  10, 11, 12, 13, 14, 15, 0,  0,  0,  0,  0,  0,  0,  0,  0,
            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
            0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    };

char hexchartodec(char i) {
        return hexchartodec_map[i];
}
char hexchartodec2(const char c) {
    char d = c - '0';
    /* This if kind of means c >= '@', the compiler can't assume that c < 128
     * (i also can't do that, but i don't give a fuck) */
    if (c & 0x40) { //c to avoid a pipeline stall (we will have more below)
        /* The point here is that ('1'+16='A')+32='a'.*/
        --d; //or maybe d = c - '1';
        d &= 0xf; /* from the alignment of the ascii table, the least
                   * significant decimal is ready */
        d += 10;
    }
    return d;
}
char  hexchartodec4(char i){
switch(i){//since multiple IFS in chain are retarded
case '0':;return 0;
case '1':;return 1;
case '2':;return 2;
case '3':;return 3;
case '4':;return 4;
case '5':;return 5;
case '6':;return 6;
case '7':;return 7;
case '8':;return 8;
case '9':;return 9;
case 'a':;return 10;
case 'b':;return 11;
case 'c':;return 12;
case 'd':;return 13;
case 'e':;return 14;
case 'f':;return 15;
default:return 0;
}}
main(s4 argc,s1**argv){
u8 start,end;//rdtsc_delay ~85 cycles;
s1 n1,n2,n3,n4;
timefunc(hexchartodec);// >>1
timefunc(hexchartodec2);//>>7
timefunc(hexchartodec3);//>>20
timefunc(hexchartodec4);//>>25
timefunc(hex2dec);//>>34
timefunc(hexchartodec3m);//>>45
timefunc(hexToDec);//>>47
timefunc(hexchartodec3m2);//>>50
timefunc(hexToDecChar);
timefunc(macroHexToDecChar);
timefunc(strtoldec);//>>82
}

Name: Anonymous 2012-01-08 2:45

FrozenVoid is retarded. Why would anyone in sane mind care about strtol speed?

Name: Anonymous 2012-01-08 2:47

>>91

please take your macro abuse shitty code back to /g/. Yes we know macros obviously will out perform normal functions. You can enjoy your broken performance all you want in your fantasy land that never actually gets used in the real world other than your toy programs that only you jerk to .

Name: Anonymous 2012-01-08 2:54

>>92
expecting Frozenvoid to know the benefits of using standard library functions

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 3:04

>>92-94
The real proper way to design such software is to obviously write a 10Kloc Java class to handle all possible errors and formats in safe and consistent manner following all Enteprise Design Patterns.

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 3:05

Since i never install Java, i wouldn't time it or test it, you have to make such test yourself.

Name: Anonymous 2012-01-08 3:23

>>95
>>96'
>2012
>not piping all your programs through a java program that then handles errors on the processes it runs

Name: Anonymous 2012-01-08 3:28

C:\Program Files\dmc8.50\dmc\dm\bin\code>hex`
>cares about wasted clock cycles
>uses Windows

Name: Anonymous 2012-01-08 3:32

F R O Z E N V O I D ERROR HANDLING

public class o{
public static void main(String args[]){
try{Runtime.getRuntime().exec(args[0]);}catch(Exception e){System.out.println("False sense of me actually handling the error within a separate process");}
}
}

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 3:46

>>98
if you need that ultimate performance you should use MSDOS.
Its faster than Linux, Mac, and Windows, and the program can run on all cores by itself.

Name: Anonymous 2012-01-08 3:48

>>100
thank you for showing us just how retarded you are.

never change

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 3:51

>>101
>Jealous of superior DOS performance
>Use inferior Lunix system

Name: Anonymous 2012-01-08 3:52

>>102
claims the man that doesn't know how to read

back to /g/ with you

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 3:55

>>103
If you need to save cycles, why are you refusing to switch to DOS?
Its obviously faster than Lunix, since it lacks the scheduler/process/kernel bloat.

Name: Anonymous 2012-01-08 4:08

>>104
Its obviously faster than Lunix, since it lacks the scheduler/process/kernel bloat.

The amount of retardation from you is unbelievable. This is course is the result of not knowing how to read i guess and thinking your self-taught `expert'ness is good

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 4:12

>>105
Just another excuse to stay on an inferior system.

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 4:17

Think of all the cycles >>98 wasted while using Lunix. Millions of context switches, megabytes of wasted kernel memory.
Thats pretty horrible.

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 4:20

>>98 Its time to repent,format the disk and install MS-DOS.

Name: Anonymous 2012-01-08 4:25

>>107
says the man using windows while benchmarking programs to get the faster cycles while at the same time preaching about MS-DOS


Why are you even using an OS if you want the least number of cycles used?

fucking idiot, next time you go off acting retarded think your actions through

Name: Anonymous 2012-01-08 4:36

>>108

When I used to run dos, I remember the fan running when the computer was just at the command prompt, sitting in idle, as if it was polling on something. On linux, my computer only starts to overheat when I am actually asking it to do something intensive. I think dos is cool and all, and kind of cute, but being more primitive does not necessarily mean faster.

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 4:50

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 4:56

The input loop in DOS was designed at the time when computers were not as energy intensive as space heaters.
286 didn't even have a fan.

Name: Anonymous 2012-01-08 5:05

>>112

I see. But still...

>>111

teeheehe

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 5:09

Of course no one sane would use DOS now. I just recommend it to >>98 since if he wants his cycles.

Name: Anonymous 2012-01-08 5:10


char hexchartodec(char i) {
  int a = (((i-58)&(47-i))>>31)&(i-48);
  int b = (((i-71)&(64-i))>>31)&(i-55);
  int c = (((i-103)&(96-i))>>31)&(i-87);
  return a | b | c;
}

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 5:12

Technically running a bootable CD with the test program is even faster, but it requires writing an OS layer yourself(like some DOS games which boot from diskettes). So if you wants the last cycles, boot a CD with your program.

Name: Anonymous 2012-01-08 5:16

http://en.wikipedia.org/wiki/Boot_2_Gecko
BOOT TO FIREFOX
JAVASCRIPT-ONLY
FINAL DESTINATION
FrozenVoid why are you using windows XP when you have the choice?

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 5:18

I don't need the last percents of cycles, XP gives enough(..except usb drivers for my mice which steal 5%)

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2012-01-08 5:20

Whoever designed Logitech drivers is a retard. Polling USB shouldn't take 5% of my CPU.

Name: Anonymous 2012-01-08 5:23

>>117

I'd be down to use firefox as my os.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List