view dcrypt/misc/Bitwise.d @ 30:21847420b1ac

Changed Hash's update method to a more optimized variant. Changed the code style for the entire misc package (completely forgot about it). Further changes for D2 compatibility. It appears as if full compatibility won't be possibledue to D2's handling of void[], but the number of changes to obtain compatibility can be minimized in the least.
author Thomas Dixon <reikon@reikon.us>
date Mon, 11 May 2009 15:32:00 -0400
parents 6428dfd7fede
children
line wrap: on
line source

/**
 * This file is part of the dcrypt project.
 *
 * Copyright: Copyright (C) dcrypt contributors 2009. All rights reserved.
 * License:   MIT
 * Authors:   Thomas Dixon
 */

module dcrypt.misc.Bitwise;

/** Common bitwise operations */
struct Bitwise
{
    
    static uint rotateLeft(uint x, int y)
    {
        return (x << y) | (x >> (32-y));
    }
    
    static uint rotateLeft(uint x, uint y)
    {
        return (x << y) | (x >> (32u-y));
    }
    
    static ulong rotateLeft(ulong x, int y)
    {
        return (x << y) | (x >> (64-y));
    }
    
    static ulong rotateLeft(ulong x, uint y)
    {
        return (x << y) | (x >> (64u-y));
    }
    
    static uint rotateRight(uint x, int y)
    {
        return (x >> y) | (x << (32-y));  
    }
    
    static uint rotateRight(uint x, uint y)
    {
        return (x >> y) | (x << (32u-y));    
    }
    
    static ulong rotateRight(ulong x, int y)
    {
        return (x >> y) | (x << (64-y));    
    }
    
    static ulong rotateRight(ulong x, uint y)
    {
        return (x >> y) | (x << (64u-y));    
    }
}