Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

32 bit + AVX issues #567

Closed
nilsholland opened this issue Nov 7, 2016 · 4 comments
Closed

32 bit + AVX issues #567

nilsholland opened this issue Nov 7, 2016 · 4 comments
Assignees
Milestone

Comments

@nilsholland
Copy link

I'm running a 32 bit system that has a processor with AVX support, and it seems that this section

#       if GLM_ARCH & GLM_ARCH_AVX_BIT
        template <>
        GLM_FUNC_QUALIFIER int bitCount(uint32 x)
        {
                return _mm_popcnt_u32(x);
        }

        template <>
        GLM_FUNC_QUALIFIER int bitCount(uint64 x)
        {
                return static_cast<int>(_mm_popcnt_u64(x));
        }
#       endif

from /usr/include/glm/detail/func_integer_simd.inl is giving me headaches, namely in the form of:

/usr/include/glm/detail/func_integer_simd.inl: In function ‘int glm::bitCount(genType) [with genType = long long unsigned int]’:
/usr/include/glm/detail/func_integer_simd.inl:60:43: error: ‘_mm_popcnt_u64’ was not declared in this scope
return static_cast(_mm_popcnt_u64(x));

My compiler is gcc 5.4.0, and when I manually try something like

#include <smmintrin.h>
#include <stdio.h>

int main(void) {
        int res = _mm_popcnt_u64(0);
        printf("Result res should be 0: %d\n", res);
}

it also fails with

test.c: In function ‘main’:
test.c:5:12: warning: implicit declaration of function ‘_mm_popcnt_u64’ [-Wimplicit-function-declaration]
int res = _mm_popcnt_u64(0);
^
/tmp/ccaMYiyR.o: In function main': test.c:(.text+0x17): undefined reference to _mm_popcnt_u64'
collect2: error: ld returned 1 exit status

while

#include <smmintrin.h>
#include <stdio.h>

int main(void) {
        int res = _mm_popcnt_u32(0);
        printf("Result res should be 0: %d\n", res);
}

builds successfully.

I'm sorry that I don't have much more of a clue but only these observation, but if _mm_popcnt_u64 is indeed not supposed to be there on 32 bit, then /usr/include/glm/detail/func_integer_simd.inl would probably have to be changed in a way so that it doesn't get used when a 32 bit processor that supports AVX is present. Indeed, commenting out the code quoted above fix my original build errors.

@Groovounet
Copy link
Member

Hi,

Are you using GCC?
According to MSDN https://msdn.microsoft.com/en-us/library/bb531475(v=vs.120).aspx, _mm_popcnt_u64 is only available on x86_64.

Thanks for reporting, I'll fix it,
Christophe

@Groovounet Groovounet self-assigned this Nov 8, 2016
@Groovounet Groovounet added this to the GLM 0.9.8 milestone Nov 8, 2016
@nilsholland
Copy link
Author

Hi Christophe,

thanks for looking into this! Yes, I'm using GCC (version 5.4.0) and stumbled upon the issue when I was building libreoffice (which uses glm) on two of my Gentoo Linux systems. Both are 32 bit, one uses an older Intel processor without AVX, and the other one a newer AMD processor with AVX, and my build was consistently succeeding on the first, but failing on the second system. ;-)

@Groovounet
Copy link
Member

This issue should be fixed in master and 0.9.8 branches for GLM 0.9.8.3. It could be great if you could double check the issue is fixed for you.

Thanks for reporting!
Christophe

@nilsholland
Copy link
Author

Yes, I've checked out master and gave it a little test, and it seems to fix the issue just fine.

Thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants