SIMD high performace xorcpy in C
In my current project I need a high performace xorcpy implemented in C. Here is my implementation to share and it is tested on my Xeon E5-2680 PC, it reaches almost 1.7GB/s.
#include <emmintrin.h>
...
__forceinline unsigned char* xorcpy(unsigned char* dst, const unsigned char* src, unsigned block_size)
{
// Do the bulk of the copy a __m128i at a time, for faster speed
__m128i* mto = (__m128i*)dst;
const __m128i* mfrom = (__m128i*)(src);
for(int i=(block_size / sizeof(__m128i) - 1); i>=0; i--)
{
__m128i xmm1 = _mm_loadu_si128(mto);
__m128i xmm2 = _mm_loadu_si128(mfrom);
xmm1 = _mm_xor_si128(xmm1, xmm2); // XOR 16 bytes
_mm_storeu_si128(mto, xmm1);
++mto;
++mfrom;
}
// The rest bytes we have to do a byte a time though
unsigned char* cto = (unsigned char*) mto;
const unsigned char* cfrom = (const unsigned char*)mfrom;
for(int i=(block_size % sizeof(__m128i)) - 1; i>=0; i--)
{
*cto++ ^= (*cfrom++);
}
return dst;
}
2015 AGE Gaming show
Actually, this is my 10th years to attend AGE gaming show. Noting is very exciting, but game, Britney spears, is very impressive. The game is specially designed for curve screen to suit physical curve, and the chair has stereo surrounding sound system, and event it can shake up when reel spinning stops.
Share Brother HL-2130 through Lenovo Iomega EZ Media & Backup Center USB port
Recently I bought a Lenovo® EZ Media and Backup Center to share video and photos within my home network. I also have a Brother HL-2130 Mono Laser long time back which is connected to my PC USB port. Every time, when I want to print something, I have to keep my PC on. I am thinking is there a way to connect my Brother HL-2130 Mono Laser to Lenovo® EZ Media and Backup Center USB port, and sharing HL-2130 within my home network. I can print from any devices even from my iPad, Andaroid phone.
After few hours trying, I finally successfully share HL-2130 through Lenovo NAS USB port. This is the post I found from internet, and it gives the detailed steps.
http://forum.nas-central.org/viewtopic.php?f=279&t=8679
Here are the steps I followed to install HL-2130:
- In PC’s browser, go to http://lenovoez/manage/login.html?pg=/manage/diagnostics.html. Enable SSH login (default password: soho+[password]
- Download putty, and login your Lenovo NAS through SSH
- Connect HL-2130 to Lenovo NAS USB Port
- Issue command “/etc/init.d/cups start” to start CUPS service
- In PC’s browser, go to http://lenovoez:631/admin
- Click “Add Printer” and find Brother_HL-2130_series printer from local printers.
- In “Printers” tab, you will find Brother_HL-2130_series. Actually, the address for HL-2130 is http://lenovoez:631/printers/Brother_HL-2130_series
- Download latest HL-2130 Windows OS printer driver from http://support.brother.com/g/b/downloadtop.aspx?c=us_ot&lang=en&prod=hl2130_all
- Go back to PC, and Add new printer, give the printer address http://lenovoez:631/printers/Brother_HL-2130_series
- Click “Have a disk” and install HL-2130 printer driver.
- Follow the steps in the post to make cups to run every time the box reloads.
Convert DIB or BMP into JPEG in memory (diskless) using Windows GDIPlus
#include
#include
using namespace Gdiplus;
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
...
IStream* pJpegStream = NULL; //declare a memory stream
CreateStreamOnHGlobal(NULL, TRUE, (LPSTREAM*)&pJpegStream);
GpBitmap* pBitmap = NULL;
unsigned char* dib = GetDib(); //get DIB or BMP data buffer
DllExports::GdipCreateBitmapFromGdiDib((LPBITMAPINFO)dib, dib + sizeof(BITMAPINFOHEADER), &pBitmap);
CLSID imageCLSID;
GetEncoderClsid(L"image/jpeg", &imageCLSID);
int jpegQuality = 100;
EncoderParameters encoderParams; //setup jpeg encoder parameters
encoderParams.Count = 1;
encoderParams.Parameter[0].NumberOfValues = 1;
encoderParams.Parameter[0].Guid = EncoderQuality;
encoderParams.Parameter[0].Type = EncoderParameterValueTypeLong;
encoderParams.Parameter[0].Value = &jpegQuality;
//save jpeg into memory stream
DllExports::GdipSaveImageToStream(pBitmap, pJpegStream, &imageCLSID, &encoderParams);
LARGE_INTEGER lnOffset;
lnOffset.QuadPart = 0;
ULARGE_INTEGER ulnSize;
//determine memory stream length
pJpegStream->Seek(lnOffset, STREAM_SEEK_END, &ulnSize);
pJpegStream->Seek(lnOffset, STREAM_SEEK_SET, NULL);
int encodedBytes = ulnSize.QuadPart;
//store jpeg memory stream into jpeg data buffer
pJpegStream->Read(racBuf_, ulnSize.QuadPart, NULL);
...
GdiplusShutdown(gdiplusToken);
2015 Go Ski!!!!!!
Last two days, we went to Perisher and had a fun ski weekend.
This is my achievement, 3106 vertical meters in 1.5 day, 23 lift rides.
This is my ski boots
Mt Perisher
Top of the Mt Perisher
ABO 2015 all finished, see you next year (June 7-12 2016)!
Programmably dislable Windows Firewall in C/C++
// firewall.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
/********************************************************************++
Copyright (C) Microsoft. All Rights Reserved.
Abstract:
This C++ file includes sample code for disabling Windows Firewall
per profile using the Microsoft Windows Firewall APIs.
--********************************************************************/
#include
#include
#include
#pragma comment( lib, "ole32.lib" )
// Forward declarations
HRESULT WFCOMInitialize(INetFwPolicy2** ppNetFwPolicy2);
int __cdecl main()
{
HRESULT hrComInit = S_OK;
HRESULT hr = S_OK;
INetFwPolicy2 *pNetFwPolicy2 = NULL;
// Initialize COM.
hrComInit = CoInitializeEx(
0,
COINIT_APARTMENTTHREADED
);
// Ignore RPC_E_CHANGED_MODE; this just means that COM has already been
// initialized with a different mode. Since we don't care what the mode is,
// we'll just use the existing mode.
if (hrComInit != RPC_E_CHANGED_MODE)
{
if (FAILED(hrComInit))
{
printf("CoInitializeEx failed: 0x%08lxn", hrComInit);
goto Cleanup;
}
}
// Retrieve INetFwPolicy2
hr = WFCOMInitialize(&pNetFwPolicy2);
if (FAILED(hr))
{
goto Cleanup;
}
// Disable Windows Firewall for the Domain profile
hr = pNetFwPolicy2->put_FirewallEnabled(NET_FW_PROFILE2_DOMAIN, FALSE);
if (FAILED(hr))
{
printf("put_FirewallEnabled failed for Domain: 0x%08lxn", hr);
goto Cleanup;
}
// Disable Windows Firewall for the Private profile
hr = pNetFwPolicy2->put_FirewallEnabled(NET_FW_PROFILE2_PRIVATE, FALSE);
if (FAILED(hr))
{
printf("put_FirewallEnabled failed for Private: 0x%08lxn", hr);
goto Cleanup;
}
// Disable Windows Firewall for the Public profile
hr = pNetFwPolicy2->put_FirewallEnabled(NET_FW_PROFILE2_PUBLIC, FALSE);
if (FAILED(hr))
{
printf("put_FirewallEnabled failed for Public: 0x%08lxn", hr);
goto Cleanup;
}
Cleanup:
// Release INetFwPolicy2
if (pNetFwPolicy2 != NULL)
{
pNetFwPolicy2->Release();
}
// Uninitialize COM.
if (SUCCEEDED(hrComInit))
{
CoUninitialize();
}
return 0;
}
// Instantiate INetFwPolicy2
HRESULT WFCOMInitialize(INetFwPolicy2** ppNetFwPolicy2)
{
HRESULT hr = S_OK;
hr = CoCreateInstance(
__uuidof(NetFwPolicy2),
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(INetFwPolicy2),
(void**)ppNetFwPolicy2);
if (FAILED(hr))
{
printf("CoCreateInstance for INetFwPolicy2 failed: 0x%08lxn", hr);
goto Cleanup;
}
Cleanup:
return hr;
}
Australian Badminton Open is coming
Some good source of online news TV Live streaming
Sky News
France 24
ABC News 24
CCTV America
Taiwan CTITV News
華視新聞Live Channel
台灣民視新聞HD直播