Skip to main content
Commonmark migration
Source Link

#x86_64 machine language for Linux, 15 19 17 16 bytes

x86_64 machine language for Linux, 15 19 17 16 bytes

#x86_64 machine language for Linux, 15 19 17 16 bytes

x86_64 machine language for Linux, 15 19 17 16 bytes

replace `lea` with `add`
Source Link
ceilingcat
  • 7.7k
  • 2
  • 30
  • 30

#x86_64 machine language for Linux, 15 19 17 1716 bytes

L1:
48 0f c7 f0             rdrand %rax
f3 48 0f b8 c0          popcnt %rax,%rax
3c 1a                   cmp    $0x1a,%al
7d f3                   jge    L1
8d 4004 41                lea   add 0x41(%rax)   $0x41,%eax%al
c3                      retq
#include<stdio.h>
#define TEST "\x48\xf\xc7\xf0\xf3\x48\xf\xb8\xc0\x3c\x1a\x7d\xf3\x8d\x40\x41\xc3""\x48\xf\xc7\xf0\xf3\x48\xf\xb8\xc0\x3c\x1a\x7d\xf3\4\x41\xc3"
int main(){
  int hist[26]={0};
  for(int i=0;i<10000000;i++){
    hist[ ((int(*)())TEST)() - 'A' ]++;
  }
  for(int i=0;i<26;i++){
    printf("%c %d\n", 'A'+i, hist[i] );
  }
}

#x86_64 machine language for Linux, 15 19 17 bytes

L1:
48 0f c7 f0             rdrand %rax
f3 48 0f b8 c0          popcnt %rax,%rax
3c 1a                   cmp    $0x1a,%al
7d f3                   jge    L1
8d 40 41                lea    0x41(%rax),%eax
c3                      retq
#include<stdio.h>
#define TEST "\x48\xf\xc7\xf0\xf3\x48\xf\xb8\xc0\x3c\x1a\x7d\xf3\x8d\x40\x41\xc3"
int main(){
  int hist[26]={0};
  for(int i=0;i<10000000;i++){
    hist[ ((int(*)())TEST)() - 'A' ]++;
  }
  for(int i=0;i<26;i++){
    printf("%c %d\n", 'A'+i, hist[i] );
  }
}

#x86_64 machine language for Linux, 15 19 17 16 bytes

L1:
48 0f c7 f0             rdrand %rax
f3 48 0f b8 c0          popcnt %rax,%rax
3c 1a                   cmp    $0x1a,%al
7d f3                   jge    L1
04 41                   add    $0x41,%al
c3                      retq
#include<stdio.h>
#define TEST "\x48\xf\xc7\xf0\xf3\x48\xf\xb8\xc0\x3c\x1a\x7d\xf3\4\x41\xc3"
int main(){
  int hist[26]={0};
  for(int i=0;i<10000000;i++){
    hist[ ((int(*)())TEST)() - 'A' ]++;
  }
  for(int i=0;i<26;i++){
    printf("%c %d\n", 'A'+i, hist[i] );
  }
}
edited body
Source Link
ceilingcat
  • 7.7k
  • 2
  • 30
  • 30
#include<stdio.h>
#define TEST "\x48\xf\xc7\xf0\xf3\x48\xf\xb8\xc0\x3c\x1a\x7d\xf1\x8d\x40\x43\xc3""\x48\xf\xc7\xf0\xf3\x48\xf\xb8\xc0\x3c\x1a\x7d\xf3\x8d\x40\x41\xc3"
int main(){
  int hist[26]={0};
  for(int i=0;i<10000000;i++){
    hist[ ((int(*)())TEST)() - 'A' ]++;
  }
  for(int i=0;i<26;i++){
    printf("%c %d\n", 'A'+i, hist[i] );
  }
}
#include<stdio.h>
#define TEST "\x48\xf\xc7\xf0\xf3\x48\xf\xb8\xc0\x3c\x1a\x7d\xf1\x8d\x40\x43\xc3"
int main(){
  int hist[26]={0};
  for(int i=0;i<10000000;i++){
    hist[ ((int(*)())TEST)() - 'A' ]++;
  }
  for(int i=0;i<26;i++){
    printf("%c %d\n", 'A'+i, hist[i] );
  }
}
#include<stdio.h>
#define TEST "\x48\xf\xc7\xf0\xf3\x48\xf\xb8\xc0\x3c\x1a\x7d\xf3\x8d\x40\x41\xc3"
int main(){
  int hist[26]={0};
  for(int i=0;i<10000000;i++){
    hist[ ((int(*)())TEST)() - 'A' ]++;
  }
  for(int i=0;i<26;i++){
    printf("%c %d\n", 'A'+i, hist[i] );
  }
}
"cmp $0x1a,%rax -> cmp $0x1a,%al" saves two bytes
Source Link
ceilingcat
  • 7.7k
  • 2
  • 30
  • 30
Loading
"cmp $0x1a,%rax -> cmp $0x1a,%al" saves two bytes
Source Link
ceilingcat
  • 7.7k
  • 2
  • 30
  • 30
Loading
"cmp $0x1a,%rax -> cmp $0x1a,%eax" saves one byte
Source Link
ceilingcat
  • 7.7k
  • 2
  • 30
  • 30
Loading
added analytical derivation
Source Link
ceilingcat
  • 7.7k
  • 2
  • 30
  • 30
Loading
added analytical derivation
Source Link
ceilingcat
  • 7.7k
  • 2
  • 30
  • 30
Loading
added analytical derivation
Source Link
ceilingcat
  • 7.7k
  • 2
  • 30
  • 30
Loading
added 421 characters in body
Source Link
ceilingcat
  • 7.7k
  • 2
  • 30
  • 30
Loading
added 294 characters in body
Source Link
ceilingcat
  • 7.7k
  • 2
  • 30
  • 30
Loading
Source Link
ceilingcat
  • 7.7k
  • 2
  • 30
  • 30
Loading