From 54465b08f1ad0695bc01f27cb4d923314dd652b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Manuel=20de=20Morais=20Santos=20Costa?= Date: Tue, 20 Oct 2009 10:03:10 +0100 Subject: [PATCH] support ISO extension popcount/1 --- C/arith1.c | 40 ++++++++++++++++++++++++++++++++++++++++ H/eval.h | 1 + docs/yap.tex | 8 ++++++-- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/C/arith1.c b/C/arith1.c index f0e8b22ef..be765abe0 100644 --- a/C/arith1.c +++ b/C/arith1.c @@ -184,6 +184,26 @@ lsb(Int inp) /* calculate the least significant bit for an integer */ return out; } +static Int +popcount(Int inp) /* calculate the least significant bit for an integer */ +{ + /* the obvious solution: do it by using binary search */ + Int c = 0, j = 0, m = 1L; + + if (inp < 0) { + return Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, MkIntegerTerm(inp), + "popcount/1 received %d", inp); + } + if (inp==0) + return 0L; + for(j=0,c=0; j