Giter Site home page Giter Site logo

Comments (7)

aarlt avatar aarlt commented on June 1, 2024

I just noticed that the unit-tests are just not working for release builds.

cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
build/test/intx-unittests

If a non-release build is done (e.g. not defining -DCMAKE_BUILD_TYPE=Release) all unit-tests can be executed successfuly.

from intx.

chfast avatar chfast commented on June 1, 2024

This is the repro. Can someone built it with XCode 14.3.1 with -O3 and send us the assembly (-S)?

using u64 = unsigned long long;

[[gnu::noinline]] static auto neg(const u64 y[3])
{
    u64 k = 0;
    __builtin_subcll(0, y[0], k, &k);
    __builtin_subcll(0, y[1], k, &k);
    return __builtin_subcll(0, y[2], k, &k);
}

int main()
{
    const u64 y[] = {1, 0, 0};
    if (neg(y) != ~u64(0))
        return 1;
    return 0;
}

https://godbolt.org/z/fE97oEhfP

from intx.

aarlt avatar aarlt commented on June 1, 2024

I just saw this. I used Apple clang version 14.0.3 (clang-1403.0.22.14.1) (this seem to be the version that was bundled with Xcode 14.3.1) I compiled it with clang bla.cpp -std=c++14 -O3 -S. Assembly output:

	.section	__TEXT,__text,regular,pure_instructions
	.build_version macos, 13, 0	sdk_version 13, 3
	.globl	_main                           ; -- Begin function main
	.p2align	2
_main:                                  ; @main
	.cfi_startproc
; %bb.0:
	stp	x29, x30, [sp, #-16]!           ; 16-byte Folded Spill
	.cfi_def_cfa_offset 16
	mov	x29, sp
	.cfi_def_cfa w29, 16
	.cfi_offset w30, -8
	.cfi_offset w29, -16
Lloh0:
	adrp	x0, l___const.main.y@PAGE
Lloh1:
	add	x0, x0, l___const.main.y@PAGEOFF
	bl	__ZL3negPKy
	cmn	x0, #1
	cset	w0, ne
	ldp	x29, x30, [sp], #16             ; 16-byte Folded Reload
	ret
	.loh AdrpAdd	Lloh0, Lloh1
	.cfi_endproc
                                        ; -- End function
	.p2align	2                               ; -- Begin function _ZL3negPKy
__ZL3negPKy:                            ; @_ZL3negPKy
	.cfi_startproc
; %bb.0:
	ldp	x8, x9, [x0]
	cmp	xzr, x8
	ngcs	xzr, x9
	cset	w8, hs
	sbfx	x8, x8, #0, #1
	ldr	x9, [x0, #16]
	sub	x0, x8, x9
	ret
	.cfi_endproc
                                        ; -- End function
	.section	__TEXT,__const
	.p2align	3                               ; @__const.main.y
l___const.main.y:
	.quad	1                               ; 0x1
	.quad	0                               ; 0x0
	.quad	0                               ; 0x0

.subsections_via_symbols

from intx.

chfast avatar chfast commented on June 1, 2024

Thanks @aarlt. To confirm, does this program return 1?

from intx.

chfast avatar chfast commented on June 1, 2024

Wrong assembly:

	ldp	x8, x9, [x0]
	cmp	xzr, x8
	ngcs	xzr, x9
	cset	w8, hs
	sbfx	x8, x8, #0, #1
	ldr	x9, [x0, #16]
	sub	x0, x8, x9
	ret

Correct assembly from later XCode:

	ldp	x8, x9, [x0]
	orr	x8, x9, x8
	cmp	x8, #0
	csetm	x8, ne
	ldr	x9, [x0, #16]
	sub	x0, x8, x9
	ret

from intx.

aarlt avatar aarlt commented on June 1, 2024

Thanks @aarlt. To confirm, does this program return 1?

yep it returns 1.

from intx.

chfast avatar chfast commented on June 1, 2024

Fixed in #294.
Released in https://github.com/chfast/intx/releases/tag/v0.10.1.

from intx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.