mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Add more sorting algorithms
This commit is contained in:
parent
b7bf052a4b
commit
7c9ef924bf
17 changed files with 49004 additions and 5 deletions
23
third_party/vqsort/README.cosmo
vendored
Normal file
23
third_party/vqsort/README.cosmo
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
DESCRIPTION
|
||||
|
||||
vqsort implements vectorized quicksort using avx2. this is the fastest
|
||||
way to sort integers. this goes as fast as djbsort for 32-bit integers
|
||||
except it supports 64-bit integers too, which go just as fast: about a
|
||||
gigabyte of memory sorted per second. It's 3x faster than simple radix
|
||||
sort. It's 5x faster than simple quicksort. It's 10x faster than qsort
|
||||
|
||||
LICENSE
|
||||
|
||||
Apache 2.o
|
||||
|
||||
ORIGIN
|
||||
|
||||
https://github.com/google/highway/
|
||||
commit 50331e0523bbf5f6c94b94263a91680f118e0986
|
||||
Author: Jan Wassenberg <janwas@google.com>
|
||||
Date: Wed Apr 26 11:20:33 2023 -0700
|
||||
Faster vqsort for small arrays (7x speedup! for N=100)
|
||||
|
||||
LOCAL CHANGES
|
||||
|
||||
Precompiled beacuse upstream codebase is slow, gigantic, and hairy.
|
20
third_party/vqsort/vqsort.h
vendored
Normal file
20
third_party/vqsort/vqsort.h
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef COSMOPOLITAN_THIRD_PARTY_VQSORT_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_VQSORT_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
void vqsort_int64(int64_t *, size_t);
|
||||
void vqsort_int64_avx2(int64_t *, size_t);
|
||||
void vqsort_int64_sse4(int64_t *, size_t);
|
||||
void vqsort_int64_ssse3(int64_t *, size_t);
|
||||
void vqsort_int64_sse2(int64_t *, size_t);
|
||||
|
||||
void vqsort_int32(int32_t *, size_t);
|
||||
void vqsort_int32_avx2(int32_t *, size_t);
|
||||
void vqsort_int32_sse4(int32_t *, size_t);
|
||||
void vqsort_int32_ssse3(int32_t *, size_t);
|
||||
void vqsort_int32_sse2(int32_t *, size_t);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_VQSORT_H_ */
|
52
third_party/vqsort/vqsort.mk
vendored
Normal file
52
third_party/vqsort/vqsort.mk
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
|
||||
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
|
||||
|
||||
PKGS += THIRD_PARTY_VQSORT
|
||||
|
||||
THIRD_PARTY_VQSORT_ARTIFACTS += THIRD_PARTY_VQSORT_A
|
||||
THIRD_PARTY_VQSORT = $(THIRD_PARTY_VQSORT_A_DEPS) $(THIRD_PARTY_VQSORT_A)
|
||||
THIRD_PARTY_VQSORT_A = o/$(MODE)/third_party/vqsort/vqsort.a
|
||||
THIRD_PARTY_VQSORT_A_FILES := $(wildcard third_party/vqsort/*)
|
||||
THIRD_PARTY_VQSORT_A_HDRS = $(filter %.h,$(THIRD_PARTY_VQSORT_A_FILES))
|
||||
THIRD_PARTY_VQSORT_A_SRCS_C = $(filter %.c,$(THIRD_PARTY_VQSORT_A_FILES))
|
||||
THIRD_PARTY_VQSORT_A_SRCS_S = $(filter %.S,$(THIRD_PARTY_VQSORT_A_FILES))
|
||||
THIRD_PARTY_VQSORT_A_SRCS = $(THIRD_PARTY_VQSORT_A_SRCS_C) $(THIRD_PARTY_VQSORT_A_SRCS_S)
|
||||
THIRD_PARTY_VQSORT_A_OBJS_C = $(THIRD_PARTY_VQSORT_A_SRCS_C:%.c=o/$(MODE)/%.o)
|
||||
THIRD_PARTY_VQSORT_A_OBJS_S = $(THIRD_PARTY_VQSORT_A_SRCS_S:%.S=o/$(MODE)/%.o)
|
||||
THIRD_PARTY_VQSORT_A_OBJS = $(THIRD_PARTY_VQSORT_A_OBJS_C) $(THIRD_PARTY_VQSORT_A_OBJS_S)
|
||||
|
||||
THIRD_PARTY_VQSORT_A_CHECKS = \
|
||||
$(THIRD_PARTY_VQSORT_A).pkg \
|
||||
$(THIRD_PARTY_VQSORT_A_HDRS:%=o/$(MODE)/%.ok)
|
||||
|
||||
THIRD_PARTY_VQSORT_A_DIRECTDEPS = \
|
||||
LIBC_INTRIN \
|
||||
LIBC_MEM \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
THIRD_PARTY_COMPILER_RT
|
||||
|
||||
THIRD_PARTY_VQSORT_A_DEPS := \
|
||||
$(call uniq,$(foreach x,$(THIRD_PARTY_VQSORT_A_DIRECTDEPS),$($(x))))
|
||||
|
||||
$(THIRD_PARTY_VQSORT_A): \
|
||||
third_party/vqsort/ \
|
||||
$(THIRD_PARTY_VQSORT_A).pkg \
|
||||
$(THIRD_PARTY_VQSORT_A_OBJS)
|
||||
|
||||
$(THIRD_PARTY_VQSORT_A).pkg: \
|
||||
$(THIRD_PARTY_VQSORT_A_OBJS) \
|
||||
$(foreach x,$(THIRD_PARTY_VQSORT_A_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
THIRD_PARTY_VQSORT_LIBS = $(foreach x,$(THIRD_PARTY_VQSORT_ARTIFACTS),$($(x)))
|
||||
THIRD_PARTY_VQSORT_SRCS = $(foreach x,$(THIRD_PARTY_VQSORT_ARTIFACTS),$($(x)_SRCS))
|
||||
THIRD_PARTY_VQSORT_HDRS = $(foreach x,$(THIRD_PARTY_VQSORT_ARTIFACTS),$($(x)_HDRS))
|
||||
THIRD_PARTY_VQSORT_CHECKS = $(foreach x,$(THIRD_PARTY_VQSORT_ARTIFACTS),$($(x)_CHECKS))
|
||||
THIRD_PARTY_VQSORT_OBJS = $(foreach x,$(THIRD_PARTY_VQSORT_ARTIFACTS),$($(x)_OBJS))
|
||||
$(THIRD_PARTY_VQSORT_OBJS): $(BUILD_FILES) third_party/vqsort/vqsort.mk
|
||||
|
||||
.PHONY: o/$(MODE)/third_party/vqsort
|
||||
o/$(MODE)/third_party/vqsort: $(THIRD_PARTY_VQSORT_CHECKS)
|
24732
third_party/vqsort/vqsort_i32a.S
vendored
Normal file
24732
third_party/vqsort/vqsort_i32a.S
vendored
Normal file
File diff suppressed because it is too large
Load diff
23679
third_party/vqsort/vqsort_i64a.S
vendored
Normal file
23679
third_party/vqsort/vqsort_i64a.S
vendored
Normal file
File diff suppressed because it is too large
Load diff
29
third_party/vqsort/vqsort_int32.c
vendored
Normal file
29
third_party/vqsort/vqsort_int32.c
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "third_party/vqsort/vqsort.h"
|
||||
|
||||
void vqsort_int32(int32_t *A, size_t n) {
|
||||
if (X86_HAVE(AVX2)) {
|
||||
vqsort_int32_avx2(A, n);
|
||||
} else {
|
||||
radix_sort_int32(A, n);
|
||||
}
|
||||
}
|
29
third_party/vqsort/vqsort_int64.c
vendored
Normal file
29
third_party/vqsort/vqsort_int64.c
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "third_party/vqsort/vqsort.h"
|
||||
|
||||
void vqsort_int64(int64_t *A, size_t n) {
|
||||
if (X86_HAVE(AVX2)) {
|
||||
vqsort_int64_avx2(A, n);
|
||||
} else {
|
||||
radix_sort_int64(A, n);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue