1. Список говнокодов пользователя j123123

    Всего: 344

  2. Си / Говнокод #13492

    +122

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    #if defined(REG_R1) && !defined(NO_GLOBAL_REG_DECLS)
    GLOBAL_REG_DECL(StgUnion,R1,REG_R1)
    #else
    # define R1 (BaseReg->rR1)
    #endif
    
    #if defined(REG_R2) && !defined(NO_GLOBAL_REG_DECLS)
    GLOBAL_REG_DECL(StgUnion,R2,REG_R2)
    #else
    # define R2 (BaseReg->rR2)
    #endif
    
    #if defined(REG_R3) && !defined(NO_GLOBAL_REG_DECLS)
    GLOBAL_REG_DECL(StgUnion,R3,REG_R3)
    #else
    # define R3 (BaseReg->rR3)
    #endif
    
    #if defined(REG_R4) && !defined(NO_GLOBAL_REG_DECLS)
    GLOBAL_REG_DECL(StgUnion,R4,REG_R4)
    #else
    # define R4 (BaseReg->rR4)
    #endif
    
    #if defined(REG_R5) && !defined(NO_GLOBAL_REG_DECLS)
    GLOBAL_REG_DECL(StgUnion,R5,REG_R5)
    #else
    # define R5 (BaseReg->rR5)
    #endif
    
    #if defined(REG_R6) && !defined(NO_GLOBAL_REG_DECLS)
    GLOBAL_REG_DECL(StgUnion,R6,REG_R6)
    #else
    # define R6 (BaseReg->rR6)
    #endif
    
    #if defined(REG_R7) && !defined(NO_GLOBAL_REG_DECLS)
    GLOBAL_REG_DECL(StgUnion,R7,REG_R7)
    #else
    # define R7 (BaseReg->rR7)
    #endif
    
    ...

    Исходник GHC
    https://github.com/ghc/ghc/blob/master/includes/stg/Regs.h#L147

    j123123, 27 Июля 2013

    Комментарии (39)
  3. Куча / Говнокод #13491

    +125

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    slowCallPattern (P: P: P: P: P: P: _) = (fsLit "stg_ap_pppppp", 6)
    slowCallPattern (P: P: P: P: P: _) = (fsLit "stg_ap_ppppp", 5)
    slowCallPattern (P: P: P: P: _) = (fsLit "stg_ap_pppp", 4)
    slowCallPattern (P: P: P: V: _) = (fsLit "stg_ap_pppv", 4)
    slowCallPattern (P: P: P: _) = (fsLit "stg_ap_ppp", 3)
    slowCallPattern (P: P: V: _) = (fsLit "stg_ap_ppv", 3)
    slowCallPattern (P: P: _) = (fsLit "stg_ap_pp", 2)
    slowCallPattern (P: V: _) = (fsLit "stg_ap_pv", 2)
    slowCallPattern (P: _) = (fsLit "stg_ap_p", 1)
    slowCallPattern (V: _) = (fsLit "stg_ap_v", 1)
    slowCallPattern (N: _) = (fsLit "stg_ap_n", 1)
    slowCallPattern (F: _) = (fsLit "stg_ap_f", 1)
    slowCallPattern (D: _) = (fsLit "stg_ap_d", 1)
    slowCallPattern (L: _) = (fsLit "stg_ap_l", 1)
    slowCallPattern (V16: _) = (fsLit "stg_ap_v16", 1)
    slowCallPattern [] = (fsLit "stg_ap_0", 0)

    Исходник GHC
    https://github.com/ghc/ghc/blob/master/compiler/codeGen/StgCmmArgRep.hs#L120

    j123123, 27 Июля 2013

    Комментарии (5)
  4. Си / Говнокод #13461

    +134

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    #include <stdio.h>
    #include <stdint.h>
    #include <string.h>
    #include <inttypes.h>
    
    union Str
    {
       uint64_t a;
       char  str[8];
    };
    
    int main(void)
    {
      union Str str;
      memcpy( &str.str, "12345678", sizeof(str.a));
    
    
    str.a = ((str.a & 0x0F000F000F000F00)>>8) +
            ((str.a & 0x000F000F000F000F)*10);
    
    str.a = 1000000 * ((str.a >> 0 ) & 0xFF) +
              10000 * ((str.a >> 16) & 0xFF) +
                100 * ((str.a >> 32) & 0xFF) +
                      ((str.a >> 48) & 0xFF);
    //little-endian only. Можно переделать под big-endian
    
    printf("%"PRIu64, str.a);
    
    return 0;
    }

    Байтоебское преобразование строки из 8 цифр(в виде ascii символов) в число

    j123123, 21 Июля 2013

    Комментарии (10)
  5. Си / Говнокод #13443

    +138

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    uint32_t multiply (uint16_t a, uint16_t b)
    {
      return ((a &  ( (int16_t)( ( b & (1 << 0) ) << 15 ) ) / ( 1 << 15) ) << 0 ) +
             ((a &  ( (int16_t)( ( b & (1 << 1) ) << 14 ) ) / ( 1 << 15) ) << 1 ) +
             ((a &  ( (int16_t)( ( b & (1 << 2) ) << 13 ) ) / ( 1 << 15) ) << 2 ) +
             ((a &  ( (int16_t)( ( b & (1 << 3) ) << 12 ) ) / ( 1 << 15) ) << 3 ) +
             ((a &  ( (int16_t)( ( b & (1 << 4) ) << 11 ) ) / ( 1 << 15) ) << 4 ) +
             ((a &  ( (int16_t)( ( b & (1 << 5) ) << 10 ) ) / ( 1 << 15) ) << 5 ) +
             ((a &  ( (int16_t)( ( b & (1 << 6) ) << 9  ) ) / ( 1 << 15) ) << 6 ) +
             ((a &  ( (int16_t)( ( b & (1 << 7) ) << 8  ) ) / ( 1 << 15) ) << 7 ) +
             ((a &  ( (int16_t)( ( b & (1 << 8) ) << 7  ) ) / ( 1 << 15) ) << 8 ) +
             ((a &  ( (int16_t)( ( b & (1 << 9) ) << 6  ) ) / ( 1 << 15) ) << 9 ) +
             ((a &  ( (int16_t)( ( b & (1 <<10) ) << 5  ) ) / ( 1 << 15) ) << 10) +
             ((a &  ( (int16_t)( ( b & (1 <<11) ) << 4  ) ) / ( 1 << 15) ) << 11) +
             ((a &  ( (int16_t)( ( b & (1 <<12) ) << 3  ) ) / ( 1 << 15) ) << 12) +
             ((a &  ( (int16_t)( ( b & (1 <<13) ) << 2  ) ) / ( 1 << 15) ) << 13) +
             ((a &  ( (int16_t)( ( b & (1 <<14) ) << 1  ) ) / ( 1 << 15) ) << 14) +
             ((a &  ( (int16_t)( ( b & (1 <<15) ) << 0  ) ) / ( 1 << 15) ) << 15);
    }

    Умножение двух чисел через битовые маски и сдвиги без условных переходов. Компилятор переведет деление инта на сдвинутую единчку в арифметический сдвиг
    Использование ">>" применительно к signed типам - implementation defined http://stackoverflow.com/questions/4009885/arithmetic-bit-shift-on-a-signed-integer/4009922

    j123123, 18 Июля 2013

    Комментарии (18)