1. Си / Говнокод #28056

    +1

    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
    static char *cast_table[][11] = {
      // i8   i16     i32     i64     u8     u16     u32     u64     f32     f64     f80
      {NULL,  NULL,   NULL,   i32i64, i32u8, i32u16, NULL,   i32i64, i32f32, i32f64, i32f80}, // i8
      {i32i8, NULL,   NULL,   i32i64, i32u8, i32u16, NULL,   i32i64, i32f32, i32f64, i32f80}, // i16
      {i32i8, i32i16, NULL,   i32i64, i32u8, i32u16, NULL,   i32i64, i32f32, i32f64, i32f80}, // i32
      {i32i8, i32i16, NULL,   NULL,   i32u8, i32u16, NULL,   NULL,   i64f32, i64f64, i64f80}, // i64
    
      {i32i8, NULL,   NULL,   i32i64, NULL,  NULL,   NULL,   i32i64, i32f32, i32f64, i32f80}, // u8
      {i32i8, i32i16, NULL,   i32i64, i32u8, NULL,   NULL,   i32i64, i32f32, i32f64, i32f80}, // u16
      {i32i8, i32i16, NULL,   u32i64, i32u8, i32u16, NULL,   u32i64, u32f32, u32f64, u32f80}, // u32
      {i32i8, i32i16, NULL,   NULL,   i32u8, i32u16, NULL,   NULL,   u64f32, u64f64, u64f80}, // u64
    
      {f32i8, f32i16, f32i32, f32i64, f32u8, f32u16, f32u32, f32u64, NULL,   f32f64, f32f80}, // f32
      {f64i8, f64i16, f64i32, f64i64, f64u8, f64u16, f64u32, f64u64, f64f32, NULL,   f64f80}, // f64
      {f80i8, f80i16, f80i32, f80i64, f80u8, f80u16, f80u32, f80u64, f80f32, f80f64, NULL},   // f80
    };

    красивое

    Запостил: kcalbCube, 26 Февраля 2022

    Комментарии (2) RSS

    • // The table for type casts
      static char i32i8[] = "movsbl %al, %eax";
      static char i32u8[] = "movzbl %al, %eax";
      static char i32i16[] = "movswl %ax, %eax";
      static char i32u16[] = "movzwl %ax, %eax";
      static char i32f32[] = "cvtsi2ssl %eax, %xmm0";
      static char i32i64[] = "movsxd %eax, %rax";
      static char i32f64[] = "cvtsi2sdl %eax, %xmm0";
      static char i32f80[] = "mov %eax, -4(%rsp); fildl -4(%rsp)";
      
      static char u32f32[] = "mov %eax, %eax; cvtsi2ssq %rax, %xmm0";
      static char u32i64[] = "mov %eax, %eax";
      static char u32f64[] = "mov %eax, %eax; cvtsi2sdq %rax, %xmm0";
      static char u32f80[] = "mov %eax, %eax; mov %rax, -8(%rsp); fildll -8(%rsp)";
      
      static char i64f32[] = "cvtsi2ssq %rax, %xmm0";
      static char i64f64[] = "cvtsi2sdq %rax, %xmm0";
      static char i64f80[] = "movq %rax, -8(%rsp); fildll -8(%rsp)";
      
      static char u64f32[] = "cvtsi2ssq %rax, %xmm0";
      static char u64f64[] =
        "test %rax,%rax; js 1f; pxor %xmm0,%xmm0; cvtsi2sd %rax,%xmm0; jmp 2f; "
        "1: mov %rax,%si; and $1,%eax; pxor %xmm0,%xmm0; shr %si; "
        "or %rax,%si; cvtsi2sd %si,%xmm0; addsd %xmm0,%xmm0; 2:";
      static char u64f80[] =
        "mov %rax, -8(%rsp); fildq -8(%rsp); test %rax, %rax; jns 1f;"
        "mov $1602224128, %eax; mov %eax, -4(%rsp); fadds -4(%rsp); 1:";
      
      static char f32i8[] = "cvttss2sil %xmm0, %eax; movsbl %al, %eax";
      static char f32u8[] = "cvttss2sil %xmm0, %eax; movzbl %al, %eax";
      static char f32i16[] = "cvttss2sil %xmm0, %eax; movswl %ax, %eax";
      static char f32u16[] = "cvttss2sil %xmm0, %eax; movzwl %ax, %eax";
      static char f32i32[] = "cvttss2sil %xmm0, %eax";
      static char f32u32[] = "cvttss2siq %xmm0, %rax";
      static char f32i64[] = "cvttss2siq %xmm0, %rax";
      static char f32u64[] = "cvttss2siq %xmm0, %rax";
      static char f32f64[] = "cvtss2sd %xmm0, %xmm0";
      static char f32f80[] = "movss %xmm0, -4(%rsp); flds -4(%rsp)";
      ...
      Ответить
    • Да ты поехавший!
      Ответить

    Добавить комментарий