<commit_before>// Copyright © 2014, <NAME> <<EMAIL>>
//
// 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.
//! Utility functions to detect presence of `rdrand` and `rdseed` instruction support.

#![allow(dead_code)]

pub use self::imp::*;

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod imp {
    #[inline]
    fn cpuid(ain : u32, cin : u32) -> (u32, u32, u32, u32) {
        let (a, b, c, d);
        unsafe {
            asm!("cpuid"
                :"={eax}"(a), "={ebx}"(b), "={ecx}"(c), "={edx}"(d)
                :"{eax}"(ain), "{ecx}"(cin)
                );
        }
        (a, b, c, d)
    }

    #[inline]
    pub fn is_intel() -> bool {
        let (_, b, c, d) = cpuid(0, 0);
        // GenuineIntel
        return b == 0x756E6547 && d == 0x49656e69 && c == 0x6C65746E;
    }

    #[inline]
    pub fn has_rdrand() -> bool {
        const FLAG : u32 = 1 << 30;
        let (_, _, c, _) = cpuid(1, 0);
        return c & FLAG == FLAG;
    }

    #[inline]
    pub fn has_rdseed() -> bool {
        const FLAG : u32 = 1 << 18;
        let (_, b, _, _) = cpuid(7, 0);
        return b & FLAG == FLAG;
    }
}

#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
mod imp {
    #[inline]
    pub fn is_intel() -> bool {
        false
    }

    #[inline]
    pub fn has_rdrand() -> bool {
        false
    }

    #[inline]
    pub fn has_rdseed() -> bool {
        false
    }
}
<commit_msg>Remove some redundancy in cpuid wrapper<commit_after>// Copyright © 2014, <NAME> <<EMAIL>>
//
// 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.
//! Utility functions to detect presence of `rdrand` and `rdseed` instruction support.

#![allow(dead_code)]

pub use self::imp::*;

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod imp {
    #[inline]
    fn cpuid(mut a: u32, mut c: u32) -> (u32, u32, u32, u32) {
        let (b, d);
        unsafe {
            asm!("cpuid"
                :"+{eax}"(a), "={ebx}"(b), "+{ecx}"(c), "={edx}"(d)
                );
        }
        (a, b, c, d)
    }

    #[inline]
    pub fn is_intel() -> bool {
        let (_, b, c, d) = cpuid(0, 0);
        // GenuineIntel
        return b == 0x756E6547 && d == 0x49656e69 && c == 0x6C65746E;
    }

    #[inline]
    pub fn has_rdrand() -> bool {
        const FLAG : u32 = 1 << 30;
        let (_, _, c, _) = cpuid(1, 0);
        return c & FLAG == FLAG;
    }

    #[inline]
    pub fn has_rdseed() -> bool {
        const FLAG : u32 = 1 << 18;
        let (_, b, _, _) = cpuid(7, 0);
        return b & FLAG == FLAG;
    }
}

#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
mod imp {
    #[inline]
    pub fn is_intel() -> bool {
        false
    }

    #[inline]
    pub fn has_rdrand() -> bool {
        false
    }

    #[inline]
    pub fn has_rdseed() -> bool {
        false
    }
}

{'fraction_non_alphanumeric': 0.14114832535885166, 'fraction_numerical': 0.03205741626794258, 'mean_word_length': 2.3182539682539685, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2036608', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1375, 'n_words': 491}