Fix link order in cosmopolitan.a

It turned out that the linker was doing the wrong with the amalgamation
library concerning weak stubs. A regression test has been added and new
binaries have been uploaded to https://justine.lol/cosmopolitan/

Ideally this should be fixed by building a tool that turns multiple .a
files into a single .a file with deduplication. As a workaround for now
the cosmopolitan.a build is restructured to not include LIBC_STUBS which
meant technical debt needed to be paid off where non-stub interfaces
were moved to LIBC_INTRIN and LIBC_NEXGEN32E.

Thank @PerfectProductions in #31 for the report!
This commit is contained in:
Justine Tunney 2021-01-16 12:05:41 -08:00
parent 04f1d89f84
commit 9f68d6eee9
121 changed files with 302 additions and 381 deletions

40
libc/intrin/addvdi3.S Normal file
View file

@ -0,0 +1,40 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 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/macros.h"
.source __FILE__
.privileged
.alignfunc
/ Returns 𝑥+𝑦, aborting on overflow.
/
/ @param rdi is int64 𝑥
/ @param rsi is int64 𝑦
/ @return rax is 𝑥+𝑦
/ @see -ftrapv
__addvdi3:
mov %rdi,%rax
add %rsi,%rax
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __addvdi3,globl

40
libc/intrin/addvsi3.S Normal file
View file

@ -0,0 +1,40 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 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/macros.h"
.source __FILE__
.privileged
.alignfunc
/ Returns 𝑥+𝑦, aborting on overflow.
/
/ @param edi is int32 𝑥
/ @param esi is int32 𝑦
/ @return eax is 𝑥+𝑦
/ @see -ftrapv
__addvsi3:
mov %edi,%eax
add %esi,%eax
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __addvsi3,globl

42
libc/intrin/addvti3.S Normal file
View file

@ -0,0 +1,42 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 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/macros.h"
.source __FILE__
.privileged
.alignfunc
/ Returns 𝑥+𝑦, aborting on overflow.
/
/ @param rdi:rsi is int128 𝑥
/ @param rdx:rcx is int128 𝑦
/ @return rdx:rax is 𝑥+𝑦
/ @see -ftrapv
__addvti3:
mov %rdi,%rax
add %rdx,%rax
mov %rsi,%rdx
adc %rcx,%rdx
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __addvti3,globl

View file

@ -16,7 +16,6 @@ LIBC_INTRIN_A_FILES := \
$(wildcard libc/intrin/*)
LIBC_INTRIN_A_OBJS = \
$(LIBC_INTRIN_A_SRCS:%=o/$(MODE)/%.zip.o) \
$(LIBC_INTRIN_A_SRCS_S:%.S=o/$(MODE)/%.o) \
$(LIBC_INTRIN_A_SRCS_C:%.c=o/$(MODE)/%.o)

40
libc/intrin/mulvdi3.S Normal file
View file

@ -0,0 +1,40 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 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/macros.h"
.source __FILE__
.privileged
.alignfunc
/ Returns 𝑥*𝑦, aborting on overflow.
/
/ @param rdi is int64 𝑥
/ @param rdi is int64 𝑦
/ @return rax is 𝑥*𝑦
/ @see -ftrapv
__mulvdi3:
mov %rdi,%rax
imul %rsi
jc 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __mulvdi3,globl

40
libc/intrin/mulvsi3.S Normal file
View file

@ -0,0 +1,40 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 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/macros.h"
.source __FILE__
.privileged
.alignfunc
/ Returns 𝑥*𝑦, aborting on overflow.
/
/ @param edi is int32 𝑥
/ @param esi is int32 𝑦
/ @return eax is 𝑥*𝑦
/ @see -ftrapv
__mulvsi3:
mov %edi,%eax
imul %esi
jc 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __mulvsi3,globl

135
libc/intrin/mulvti3.S Normal file
View file

@ -0,0 +1,135 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 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/macros.h"
.source __FILE__
.privileged
.alignfunc
/ Returns 𝑥*𝑦, aborting on overflow.
/
/ @param rdi:rsi is int128 𝑥
/ @param rdx:rcx is int128 𝑦
/ @return rdx:rax is 𝑥*𝑦
/ @see -ftrapv
__mulvti3:
push %rbp
mov %rsp,%rbp
push %rbx
push %rbx
push %r12
push %r13
push %r14
push %r15
mov %rdx,%r10
mov %rdi,%rdx
xor %r11d,%r11d
mov %r10,%rax
sar $63,%rdx
sar $63,%rax
cmp %rsi,%rdx
jne 4f
cmp %rcx,%rax
jne 5f
mov %rdi,%rax
imul %r10
mov %rax,%r14
mov %rdx,%r8
jmp 2f
5: mov %r10,%r12
mov %rcx,%r13
mov %rcx,%r8
mov %rdi,%rbx
jmp 6f
4: cmp %rcx,%rax
jne 7f
mov %rdi,%r12
mov %rsi,%r13
mov %rsi,%r8
mov %r10,%rbx
6: mov %rdi,%rax
mul %r10
mov %rax,%r14
mov %rbx,%rax
mov %rdx,%r15
mul %r8
test %r8,%r8
jns 8f
xor %r8d,%r8d
sub %r8,%rax
sbb %rbx,%rdx
8: test %rbx,%rbx
jns 9f
sub %r12,%rax
sbb %r13,%rdx
9: mov %r15,%r8
xor %r9d,%r9d
add %rax,%r8
adc %rdx,%r9
mov %r8,%rdx
sar $63,%rdx
cmp %r9,%rdx
je 2f
imul %r10,%rsi
mov %rdi,%rax
imul %rdi,%rcx
mul %r10
lea (%rsi,%rcx),%r8
add %rdx,%r8
mov %rax,%r14
jmp 3f
7: mov %rsi,%r8
mov %rcx,%rdx
mov %rdi,%rax
imul %rdi,%rdx
imul %r10,%r8
add %rdx,%r8
mul %r10
mov %rax,%r14
lea 1(%rsi),%rax
add %rdx,%r8
cmp $1,%rax
ja 3f
lea 1(%rcx),%rax
cmp $1,%rax
ja 3f
cmp %rcx,%rsi
jne 11f
cmp %r14,%r11
mov %r11,%rax
sbb %r8,%rax
jl 2f
jmp 3f
11: test %r8,%r8
js 2f
3: mov $1,%r11d
2: test %r11,%r11
je 1f
mov %r8,-8(%rbp)
call __on_arithmetic_overflow
mov -8(%rbp),%r8
1: mov %r14,%rax
mov %r8,%rdx
pop %r15
pop %r14
pop %r13
pop %r12
pop %rbx
leave
ret
.endfn __mulvti3,globl

39
libc/intrin/negvdi2.S Normal file
View file

@ -0,0 +1,39 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 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/macros.h"
.source __FILE__
.privileged
.alignfunc
/ Returns -𝑥, aborting on overflow (two's complement bane).
/
/ @param rdi is int64 𝑥
/ @return rax is -𝑥
/ @see -ftrapv
__negvdi2:
mov %rdi,%rax
neg %rax
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __negvdi2,globl

39
libc/intrin/negvsi2.S Normal file
View file

@ -0,0 +1,39 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 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/macros.h"
.source __FILE__
.privileged
.alignfunc
/ Returns -𝑥, aborting on overflow (two's complement bane).
/
/ @param edi is int32 𝑥
/ @return eax is -𝑥
/ @see -ftrapv
__negvsi2:
mov %edi,%eax
neg %eax
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __negvsi2,globl

43
libc/intrin/negvti2.S Normal file
View file

@ -0,0 +1,43 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 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/macros.h"
.source __FILE__
.privileged
.alignfunc
/ Returns -𝑥, aborting on overflow.
/
/ @param rdi:rsi is int128 𝑥
/ @return rdx:rax is -𝑥
/ @see -ftrapv
__negvti2:
mov %rdi,%rax
mov %rsi,%rdx
neg %rax
not %rdx
cmc
adc $0,%rdx
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __negvti2,globl

View file

@ -0,0 +1,30 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 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/macros.h"
.privileged
.source __FILE__
/ Arithmetic overflow handler.
/ @see -ftrapv
__on_arithmetic_overflow:
push %rbp
mov %rsp,%rbp
int3
call abort
.endfn __on_arithmetic_overflow,weak

40
libc/intrin/subvdi3.S Normal file
View file

@ -0,0 +1,40 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 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/macros.h"
.source __FILE__
.privileged
.alignfunc
/ Returns 𝑥-𝑦, aborting on overflow.
/
/ @param rdi is int64 𝑥
/ @param rsi is int64 𝑦
/ @return rax is 𝑥-𝑦
/ @see -ftrapv
__subvdi3:
mov %rdi,%rax
sub %rsi,%rax
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __subvdi3,globl

39
libc/intrin/subvsi3.S Normal file
View file

@ -0,0 +1,39 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 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/macros.h"
.source __FILE__
.privileged
.alignfunc
/ Returns 𝑥-𝑦, aborting on overflow.
/
/ @param edi is int32 𝑥
/ @param esi is int32 𝑦
/ @see -ftrapv
__subvsi3:
mov %edi,%eax
sub %esi,%eax
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __subvsi3,globl

42
libc/intrin/subvti3.S Normal file
View file

@ -0,0 +1,42 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 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/macros.h"
.source __FILE__
.privileged
.alignfunc
/ Returns 𝑥-𝑦, aborting on overflow.
/
/ @param rdi:rsi is int128 𝑥
/ @param rdx:rcx is int128 𝑦
/ @return rdx:rax is 𝑥-𝑦
/ @see -ftrapv
__subvti3:
mov %rdi,%rax
sub %rdx,%rax
mov %rsi,%rdx
sbb %rcx,%rdx
jo 1f
ret
1: push %rbp
mov %rsp,%rbp
call __on_arithmetic_overflow
pop %rbp
ret
.endfn __subvti3,globl