ObjFW  Check-in [0272a8686f]

Overview
Comment:Don't use the lahf instruction.
Some early AMD64 CPUs don't support it.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0272a8686f7caa0b0653164cae6048adf81e16d92c5607aa797d08159bceb278
User & Date: js on 2010-12-05 21:32:28
Other Links: manifest | tags
Context
2010-12-06
13:24
Add -[description] to OFNumber. check-in: b965dad5f8 user: js tags: trunk
2010-12-05
21:32
Don't use the lahf instruction.
Some early AMD64 CPUs don't support it.
check-in: 0272a8686f user: js tags: trunk
12:32
Make subclassing OFTCPSocket easier. check-in: efa6d95aad user: js tags: trunk
Changes

Modified src/atomic.h from [9f0732f9a3] to [c57a56dcf7].

495
496
497
498
499
500
501

502
503
504

505
506
507
508



509
510
511
512
513
514
515
495
496
497
498
499
500
501
502
503
504

505




506
507
508
509
510
511
512
513
514
515







+


-
+
-
-
-
-
+
+
+







	}

	return NO;
#elif defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
	int r;

	__asm__ (
	    "xorl	%0, %0\n\t"
	    "lock\n\t"
	    "cmpxchg	%2, %3\n\t"
	    "lahf\n\t"
	    "jne	.1\n\t"
	    "andb	$64, %%ah\n\t"
	    "shrb	$6, %%ah\n\t"
	    "movzx	%%ah, %0\n\t"
	    : "=a"(r)
	    "incl	%0\n"
	    ".1:"
	    : "=&r"(r)
	    : "a"(o), "r"(n), "m"(*p)
	);

	return r;
#elif defined(OF_HAVE_GCC_ATOMIC_OPS)
	return __sync_bool_compare_and_swap(p, o, n);
#elif defined(OF_HAVE_OSATOMIC)
524
525
526
527
528
529
530
531

532
533

534
535
536

537
538
539
540



541
542
543
544
545
546
547
524
525
526
527
528
529
530

531
532
533
534
535
536

537




538
539
540
541
542
543
544
545
546
547







-
+


+


-
+
-
-
-
-
+
+
+







	if (*p == o) {
		*p = n;
		return YES;
	}

	return NO;
#elif defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
	uint32_t r;
	int r;

	__asm__ (
	    "xorl	%0, %0\n\t"
	    "lock\n\t"
	    "cmpxchg	%2, %3\n\t"
	    "lahf\n\t"
	    "jne	.1\n\t"
	    "andb	$64, %%ah\n\t"
	    "shrb	$6, %%ah\n\t"
	    "movzx	%%ah, %0\n\t"
	    : "=a"(r)
	    "incl	%0\n"
	    ".1:"
	    : "=&r"(r)
	    : "a"(o), "r"(n), "m"(*p)
	);

	return r;
#elif defined(OF_HAVE_GCC_ATOMIC_OPS)
	return __sync_bool_compare_and_swap(p, o, n);
#elif defined(OF_HAVE_OSATOMIC)
556
557
558
559
560
561
562
563

564
565

566
567
568

569
570
571
572
573




574
575
576
577
578
579
580
581
582
556
557
558
559
560
561
562

563
564
565
566
567
568

569





570
571
572
573
574
575
576
577
578
579
580
581
582







-
+


+


-
+
-
-
-
-
-
+
+
+
+









	if (*p == o) {
		*p = n;
		return YES;
	}

	return NO;
#elif defined(OF_X86_ASM) || defined(OF_AMD64_ASM)
	uint32_t r;
	int r;

	__asm__ (
	    "xorl	%0, %0\n\t"
	    "lock\n\t"
	    "cmpxchg	%2, %3\n\t"
	    "lahf\n\t"
	    "jne	.1\n\t"
	    "andb	$64, %%ah\n\t"
	    "shrb	$6, %%ah\n\t"
	    "movzx	%%ah, %0\n\t"
	    : "=a"(r)
	    : "a"(o), "q"(n), "m"(*p)
	    "incl	%0\n"
	    ".1:"
	    : "=&r"(r)
	    : "a"(o), "r"(n), "m"(*p)
	);

	return r;
#elif defined(OF_HAVE_GCC_ATOMIC_OPS)
	return __sync_bool_compare_and_swap(p, o, n);
#elif defined(OF_HAVE_OSATOMIC)
	return OSAtomicCompareAndSwapPtrBarrier(o, n, p);
#endif
}