<commit_before>/**
* Lightweight wrappers around AltiVec for 32-bit operations
* (C) 2009 <NAME>
*
* Distributed under the terms of the Botan license
*/

#ifndef BOTAN_SIMD_ALTIVEC_H__
#define BOTAN_SIMD_ALTIVEC_H__

#include <botan/loadstor.h>
#include <altivec.h>
#undef vector

namespace Botan {

class SIMD_Altivec
   {
   public:

      SIMD_Altivec(const u32bit B[4])
         {
         reg = (__vector unsigned int){B[0], B[1], B[2], B[3]};
         }

      SIMD_Altivec(u32bit B0, u32bit B1, u32bit B2, u32bit B3)
         {
         reg = (__vector unsigned int){B0, B1, B2, B3};
         }

      SIMD_Altivec(u32bit B)
         {
         reg = (__vector unsigned int){B, B, B, B};
         }

      static SIMD_Altivec load_le(const void* in)
         {
         const u32bit* in_32 = static_cast<const u32bit*>(in);

         __vector unsigned int R0 = vec_ld(0, in_32);
         __vector unsigned int R1 = vec_ld(12, in_32);

         __vector unsigned char perm = vec_lvsl(0, in_32);

         perm = vec_xor(perm, vec_splat_u8(3));

         R0 = vec_perm(R0, R1, perm);

         return SIMD_Altivec(R0);
         }

      static SIMD_Altivec load_be(const void* in)
         {
         const u32bit* in_32 = static_cast<const u32bit*>(in);

         __vector unsigned int R0 = vec_ld(0, in_32);
         __vector unsigned int R1 = vec_ld(12, in_32);

         __vector unsigned char perm = vec_lvsl(0, in_32);

         R0 = vec_perm(R0, R1, perm);

         return SIMD_Altivec(R0);
         }

      void store_le(byte out[]) const
         {
         u32bit* out_32 = reinterpret_cast<u32bit*>(out);

         __vector unsigned char perm = vec_lvsl(0, (int*)0);

         perm = vec_xor(perm, vec_splat_u8(3));

         __vector unsigned int swapped = vec_perm(reg, reg, perm);

         vec_st(swapped, 0, out_32);
         }

      void store_be(byte out[]) const
         {
         u32bit* out_32 = reinterpret_cast<u32bit*>(out);
         vec_st(reg, 0, out_32);
         }

      void rotate_left(u32bit rot)
         {<commit_msg>Use register writes in the Altivec code for stores because Altivec's handling for unaligned writes is messy as hell.<commit_after>/**
* Lightweight wrappers around AltiVec for 32-bit operations
* (C) 2009 <NAME>
*
* Distributed under the terms of the Botan license
*/

#ifndef BOTAN_SIMD_ALTIVEC_H__
#define BOTAN_SIMD_ALTIVEC_H__

#include <botan/loadstor.h>
#include <altivec.h>
#undef vector

namespace Botan {

class SIMD_Altivec
   {
   public:

      SIMD_Altivec(const u32bit B[4])
         {
         reg = (__vector unsigned int){B[0], B[1], B[2], B[3]};
         }

      SIMD_Altivec(u32bit B0, u32bit B1, u32bit B2, u32bit B3)
         {
         reg = (__vector unsigned int){B0, B1, B2, B3};
         }

      SIMD_Altivec(u32bit B)
         {
         reg = (__vector unsigned int){B, B, B, B};
         }

      static SIMD_Altivec load_le(const void* in)
         {
         const u32bit* in_32 = static_cast<const u32bit*>(in);

         __vector unsigned int R0 = vec_ld(0, in_32);
         __vector unsigned int R1 = vec_ld(12, in_32);

         __vector unsigned char perm = vec_lvsl(0, in_32);

         perm = vec_xor(perm, vec_splat_u8(3));

         R0 = vec_perm(R0, R1, perm);

         return SIMD_Altivec(R0);
         }

      static SIMD_Altivec load_be(const void* in)
         {
         const u32bit* in_32 = static_cast<const u32bit*>(in);

         __vector unsigned int R0 = vec_ld(0, in_32);
         __vector unsigned int R1 = vec_ld(12, in_32);

         __vector unsigned char perm = vec_lvsl(0, in_32);

         R0 = vec_perm(R0, R1, perm);

         return SIMD_Altivec(R0);
         }

      void store_le(byte out[]) const
         {
         __vector unsigned char perm = vec_lvsl(0, (u32bit*)0);

         perm = vec_xor(perm, vec_splat_u8(3));

         union {
            __vector unsigned int V;
            u32bit R[4];
            } vec;

         vec.V = vec_perm(reg, reg, perm);

         Botan::store_be(out, vec.R[0], vec.R[1], vec.R[2], vec.R[3]);
         }

      void store_be(byte out[]) const
         {
         union {
            __vector unsigned int V;
            u32bit R[4];
            } vec;

         vec.V = reg;

         Botan::store_be(out, vec.R[0], vec.R[1], vec.R[2], vec.R[3]);
         }

      void rotate_left(u32bit rot)
         {
{'fraction_non_alphanumeric': 0.11187214611872145, 'fraction_numerical': 0.045662100456621, 'mean_word_length': 2.08738548273432, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '906784', 'n_tokens_mistral': 1708, 'n_tokens_neox': 1566, 'n_words': 387}