#include "sha256_base.h"

// Intel SHA-NI (SHA Extensions) implementation
#if defined(__x86_64__) || defined(_M_X64)
#include <cpuid.h>
#include <immintrin.h>

// TODO: Full SHA-NI implementation using:
// _mm_sha256msg1_epu32, _mm_sha256msg2_epu32 for message schedule
// _mm_sha256rnds2_epu32 for rounds
// For now, falls back to generic (implementation placeholder)

static void transform_sha_ni(uint32_t* state, const uint8_t* data) {
    // Placeholder: full implementation would use SHA-NI intrinsics
    // This requires message scheduling with sha256msg1/sha256msg2
    // and rounds with sha256rnds2
    transform_generic(state, data);
}

TransformFunc detect_x86_transform(void) {
    // Fix: Return nullptr until real SHA-NI implementation exists
    // The placeholder transform_sha_ni() just calls transform_generic(),
    // which would falsely report "SHA-NI" when it's actually generic.
    // 
    // TODO: Implement real SHA-NI using:
    //   _mm_sha256msg1_epu32, _mm_sha256msg2_epu32 for message schedule
    //   _mm_sha256rnds2_epu32 for rounds
    // Then enable this detection.
    (void)transform_sha_ni;  // Suppress unused function warning
    return nullptr;
    
    /* Full implementation when ready:
    unsigned int eax, ebx, ecx, edx;
    if (__get_cpuid(7, &eax, &ebx, &ecx, &edx)) {
        if (ebx & (1 << 29)) {  // SHA bit
            return transform_sha_ni;
        }
    }
    return nullptr;
    */
}

#else // No x86 support

TransformFunc detect_x86_transform(void) { return nullptr; }

#endif
